// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen // SPDX-License-Identifier: BSD-3-Clause #include "vtkLabeledContourMapper.h" #include "vtkActor.h" #include "vtkCamera.h" #include "vtkContourFilter.h" #include "vtkDEMReader.h" #include "vtkImageData.h" #include "vtkNew.h" #include "vtkPointData.h" #include "vtkPolyData.h" #include "vtkPolyDataMapper.h" #include "vtkRegressionTestImage.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkStripper.h" #include "vtkTestUtilities.h" #include "vtkTextProperty.h" #include "vtkTextPropertyCollection.h" #include "vtkTransform.h" //------------------------------------------------------------------------------ int TestLabeledContourMapperWithActorMatrix(int argc, char* argv[]) { char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/SainteHelens.dem"); vtkNew demReader; demReader->SetFileName(fname); delete[] fname; double range[2]; demReader->Update(); demReader->GetOutput()->GetPointData()->GetScalars()->GetRange(range); vtkNew contours; contours->SetInputConnection(demReader->GetOutputPort()); contours->GenerateValues(21, range[0], range[1]); vtkNew contourStripper; contourStripper->SetInputConnection(contours->GetOutputPort()); contourStripper->Update(); // Setup three text properties that will be rotated across the isolines: vtkNew tprops; vtkNew tprop1; tprop1->SetBold(1); tprop1->SetFontSize(12); tprop1->SetBackgroundColor(0.5, 0.5, 0.5); tprop1->SetBackgroundOpacity(0.25); tprop1->SetColor(1., 1., 1.); tprops->AddItem(tprop1); vtkNew tprop2; tprop2->ShallowCopy(tprop1); tprop2->SetColor(.8, .2, .3); tprops->AddItem(tprop2); vtkNew tprop3; tprop3->ShallowCopy(tprop1); tprop3->SetColor(.3, .8, .2); tprops->AddItem(tprop3); vtkNew mapper; mapper->GetPolyDataMapper()->ScalarVisibilityOff(); mapper->SetTextProperties(tprops); mapper->SetInputConnection(contourStripper->GetOutputPort()); vtkNew actor; actor->SetMapper(mapper); vtkNew xform; xform->Identity(); xform->Scale(0.5, 0.25, 10.); xform->RotateWXYZ(196, 0.0, 0.0, 1.0); xform->Translate(50, 50, 50); actor->SetUserTransform(xform); vtkNew ren; ren->AddActor(actor); vtkNew win; win->SetStencilCapable(1); // Needed for vtkLabeledContourMapper win->AddRenderer(ren); double bounds[6]; contourStripper->GetOutput()->GetBounds(bounds); win->SetSize(600, 600); ren->SetBackground(0.0, 0.0, 0.0); ren->GetActiveCamera()->SetViewUp(0, 1, 0); ren->GetActiveCamera()->SetPosition( (bounds[0] + bounds[1]) / 2., (bounds[2] + bounds[3]) / 2., 0); ren->GetActiveCamera()->SetFocalPoint( (bounds[0] + bounds[1]) / 2., (bounds[2] + bounds[3]) / 2., (bounds[4] + bounds[5]) / 2.); ren->ResetCamera(); ren->GetActiveCamera()->Dolly(6.5); ren->ResetCameraClippingRange(); win->SetMultiSamples(0); vtkNew iren; iren->SetRenderWindow(win); int retVal = vtkRegressionTestImage(win); if (retVal == vtkRegressionTester::DO_INTERACTOR) { iren->Start(); } return !retVal; }