// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen // SPDX-License-Identifier: BSD-3-Clause #include "vtkImageActor.h" #include "vtkImageData.h" #include "vtkImageMandelbrotSource.h" #include "vtkImageMapToWindowLevelColors.h" #include "vtkImageMapper3D.h" #include "vtkImageShiftScale.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkSmartPointer.h" #include "vtkTextProperty.h" #include "vtkActor.h" #include "vtkCornerAnnotation.h" #include "vtkPolyDataMapper.h" #include "vtkRegressionTestImage.h" int TestCornerAnnotation(int argc, char* argv[]) { vtkSmartPointer imageSource = vtkSmartPointer::New(); vtkSmartPointer imageCast = vtkSmartPointer::New(); imageCast->SetInputConnection(imageSource->GetOutputPort()); imageCast->SetScale(100); imageCast->SetShift(0); imageCast->SetOutputScalarTypeToShort(); imageCast->Update(); vtkSmartPointer imageWL = vtkSmartPointer::New(); imageWL->SetInputConnection(imageCast->GetOutputPort()); imageWL->SetWindow(10000); imageWL->SetLevel(5000); vtkSmartPointer imageActor = vtkSmartPointer::New(); imageActor->GetMapper()->SetInputConnection(imageWL->GetOutputPort()); // Visualize vtkSmartPointer renderer = vtkSmartPointer::New(); vtkSmartPointer renderWindow = vtkSmartPointer::New(); renderWindow->AddRenderer(renderer); renderWindow->SetSize(800, 600); vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); renderWindowInteractor->SetRenderWindow(renderWindow); renderer->AddActor(imageActor); // Annotate the image with window/level and mouse over pixel information vtkSmartPointer cornerAnnotation = vtkSmartPointer::New(); cornerAnnotation->SetImageActor(imageActor); cornerAnnotation->SetWindowLevel(imageWL); cornerAnnotation->SetLinearFontScaleFactor(2); cornerAnnotation->SetNonlinearFontScaleFactor(1); cornerAnnotation->SetMaximumFontSize(20); cornerAnnotation->SetText(vtkCornerAnnotation::LowerLeft, "LL ()"); cornerAnnotation->SetText(vtkCornerAnnotation::LowerRight, "LR ()"); cornerAnnotation->SetText(vtkCornerAnnotation::UpperLeft, "UL ()"); cornerAnnotation->SetText(vtkCornerAnnotation::UpperRight, "UR ()"); cornerAnnotation->SetText(vtkCornerAnnotation::UpperEdge, "T ()"); cornerAnnotation->SetText(vtkCornerAnnotation::LowerEdge, "B ()"); cornerAnnotation->SetText(vtkCornerAnnotation::LeftEdge, "L ()"); cornerAnnotation->SetText(vtkCornerAnnotation::RightEdge, "R ()"); cornerAnnotation->GetTextProperty()->SetColor(1, 0, 0); renderer->AddViewProp(cornerAnnotation); renderWindow->Render(); int retVal = vtkRegressionTestImage(renderWindow); if (retVal == vtkRegressionTester::DO_INTERACTOR) { renderWindowInteractor->Start(); } return !retVal; }