1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 5 #include <vtkSmartPointer.h> 6 #include <vtkMath.h> 7 #include <vtkImageData.h> 8 #include <vtkImageCanvasSource2D.h> 9 #include <vtkImageLogic.h> 10 #include <vtkRenderWindow.h> 11 #include <vtkRenderWindowInteractor.h> 12 #include <vtkInteractorStyleImage.h> 13 #include <vtkRenderer.h> 14 #include <vtkImageActor.h> 15 16 int main(int, char *[]) 17 { 18 vtkSmartPointer<vtkImageCanvasSource2D> imageSource1 = 19 vtkSmartPointer<vtkImageCanvasSource2D>::New(); 20 imageSource1->SetScalarTypeToUnsignedChar(); 21 imageSource1->SetNumberOfScalarComponents(1); 22 imageSource1->SetExtent(0, 100, 0, 100, 0, 0); 23 imageSource1->SetDrawColor(0.0); 24 imageSource1->FillBox(0,100,0,100); 25 imageSource1->SetDrawColor(255); 26 imageSource1->FillBox(20,60,20,60); 27 imageSource1->Update(); 28 29 vtkSmartPointer<vtkImageCanvasSource2D> imageSource2 = 30 vtkSmartPointer<vtkImageCanvasSource2D>::New(); 31 imageSource2->SetNumberOfScalarComponents(1); 32 imageSource2->SetScalarTypeToUnsignedChar(); 33 imageSource2->SetExtent(0, 100, 0, 100, 0, 0); 34 imageSource2->SetDrawColor(0.0); 35 imageSource2->FillBox(0,100,0,100); 36 imageSource2->SetDrawColor(255.0); 37 imageSource2->FillBox(40,80,40,80); 38 imageSource2->Update(); 39 40 vtkSmartPointer<vtkImageLogic> imageLogic = 41 vtkSmartPointer<vtkImageLogic>::New(); 42 imageLogic->SetInputData(imageSource1->GetOutput()); 43 imageLogic->SetInputData(imageSource2->GetOutput()); 44 imageLogic->SetOperationToXor(); 45 imageLogic->SetOutputTrueValue(128); 46 imageLogic->Update(); 47 48 vtkSmartPointer<vtkImageActor> originalActor1 = 49 vtkSmartPointer<vtkImageActor>::New(); 50 originalActor1->SetInputData(imageSource1->GetOutput()); 51 52 vtkSmartPointer<vtkImageActor> originalActor2 = 53 vtkSmartPointer<vtkImageActor>::New(); 54 originalActor2->SetInputData(imageSource2->GetOutput()); 55 56 vtkSmartPointer<vtkImageActor> logicActor = 57 vtkSmartPointer<vtkImageActor>::New(); 58 logicActor->SetInputData(imageLogic->GetOutput()); 59 60 double leftViewport[4] = {0.0, 0.0, 0.33, 1.0}; 61 double midViewport[4] = {0.33, 0.0, 0.66, 1.0}; 62 double rightViewport[4] = {0.66, 0.0, 1.0, 1.0}; 63 64 vtkSmartPointer<vtkRenderer> originalRenderer1 = 65 vtkSmartPointer<vtkRenderer>::New(); 66 originalRenderer1->SetViewport(leftViewport); 67 originalRenderer1->AddActor(originalActor1); 68 originalRenderer1->ResetCamera(); 69 originalRenderer1->SetBackground(1.0, 1.0, 1.0); 70 71 vtkSmartPointer<vtkRenderer> originalRenderer2 = 72 vtkSmartPointer<vtkRenderer>::New(); 73 originalRenderer2->SetViewport(midViewport); 74 originalRenderer2->AddActor(originalActor2); 75 originalRenderer2->ResetCamera(); 76 originalRenderer2->SetBackground(0.8, 0.8, 0.8); 77 78 vtkSmartPointer<vtkRenderer> logicRenderer = 79 vtkSmartPointer<vtkRenderer>::New(); 80 logicRenderer->SetViewport(rightViewport); 81 logicRenderer->AddActor(logicActor); 82 logicRenderer->ResetCamera(); 83 logicRenderer->SetBackground(0.6, 0.6, 0.6); 84 85 vtkSmartPointer<vtkRenderWindow> renderWindow = 86 vtkSmartPointer<vtkRenderWindow>::New(); 87 renderWindow->AddRenderer(originalRenderer1); 88 renderWindow->AddRenderer(originalRenderer2); 89 renderWindow->AddRenderer(logicRenderer); 90 renderWindow->SetSize(640, 320); 91 renderWindow->Render(); 92 renderWindow->SetWindowName("ImageLogicExample"); 93 94 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 95 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 96 vtkSmartPointer<vtkInteractorStyleImage> style = 97 vtkSmartPointer<vtkInteractorStyleImage>::New(); 98 99 renderWindowInteractor->SetInteractorStyle(style); 100 renderWindowInteractor->SetRenderWindow(renderWindow); 101 renderWindowInteractor->Initialize(); 102 renderWindowInteractor->Start(); 103 104 return EXIT_SUCCESS; 105 }标签:逻辑运算,VTK,imageSource1,35,vtkSmartPointer,imageSource2,New,100,include From: https://www.cnblogs.com/ybqjymy/p/17630949.html