1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 5 #include <vtkSmartPointer.h> 6 #include <vtkImageData.h> 7 #include <vtkImageCanvasSource2D.h> 8 #include <vtkImageShiftScale.h> 9 #include <vtkRenderWindow.h> 10 #include <vtkRenderWindowInteractor.h> 11 #include <vtkInteractorStyleImage.h> 12 #include <vtkRenderer.h> 13 #include <vtkImageActor.h> 14 #include <vtkJPEGReader.h> 15 #include <vtkImageLaplacian.h> 16 17 //测试图像:../data/lena-gray.jpg 18 int main(int argc, char* argv[]) 19 { 20 vtkSmartPointer<vtkJPEGReader> reader = 21 vtkSmartPointer<vtkJPEGReader>::New(); 22 reader->SetFileName("lena-gray.jpg"); 23 reader->Update(); 24 25 vtkSmartPointer<vtkImageLaplacian> lapFilter = 26 vtkSmartPointer<vtkImageLaplacian>::New(); 27 lapFilter->SetInputConnection(reader->GetOutputPort()); 28 lapFilter->SetDimensionality(2); 29 30 double range[2]; 31 lapFilter->GetOutput()->GetScalarRange(range); 32 33 vtkSmartPointer<vtkImageShiftScale> ShiftScale = 34 vtkSmartPointer<vtkImageShiftScale>::New(); 35 ShiftScale->SetOutputScalarTypeToUnsignedChar(); 36 ShiftScale->SetScale( 255 / (range[1]-range[0]) ); 37 ShiftScale->SetShift(-range[0]); 38 ShiftScale->SetInputConnection(lapFilter->GetOutputPort()); 39 ShiftScale->Update(); 40 41 vtkSmartPointer<vtkImageActor> originalActor = 42 vtkSmartPointer<vtkImageActor>::New(); 43 originalActor->SetInputData(reader->GetOutput()); 44 45 vtkSmartPointer<vtkImageActor> gradActor = 46 vtkSmartPointer<vtkImageActor>::New(); 47 gradActor->SetInputData(ShiftScale->GetOutput()); 48 49 double originalViewport[4] = {0.0, 0.0, 0.5, 1.0}; 50 double gradviewport[4] = {0.5, 0.0, 1.0, 1.0}; 51 52 vtkSmartPointer<vtkRenderer> originalRenderer = 53 vtkSmartPointer<vtkRenderer>::New(); 54 originalRenderer->SetViewport(originalViewport); 55 originalRenderer->AddActor(originalActor); 56 originalRenderer->ResetCamera(); 57 originalRenderer->SetBackground(1.0, 1.0, 1.0); 58 59 vtkSmartPointer<vtkRenderer> gradRenderer = 60 vtkSmartPointer<vtkRenderer>::New(); 61 gradRenderer->SetViewport(gradviewport); 62 gradRenderer->AddActor(gradActor); 63 gradRenderer->ResetCamera(); 64 gradRenderer->SetBackground(1.0, 1.0, 1.0); 65 66 vtkSmartPointer<vtkRenderWindow> renderWindow = 67 vtkSmartPointer<vtkRenderWindow>::New(); 68 renderWindow->AddRenderer(originalRenderer); 69 renderWindow->AddRenderer(gradRenderer); 70 renderWindow->SetSize(640, 320); 71 renderWindow->Render(); 72 renderWindow->SetWindowName("LaplacianExample"); 73 74 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 75 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 76 vtkSmartPointer<vtkInteractorStyleImage> style = 77 vtkSmartPointer<vtkInteractorStyleImage>::New(); 78 79 renderWindowInteractor->SetInteractorStyle(style); 80 renderWindowInteractor->SetRenderWindow(renderWindow); 81 renderWindowInteractor->Initialize(); 82 renderWindowInteractor->Start(); 83 84 return EXIT_SUCCESS; 85 }标签:ShiftScale,39,1.0,VTK,vtkSmartPointer,算子,renderWindow,New,include From: https://www.cnblogs.com/ybqjymy/p/17630966.html