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 <vtkRenderWindow.h> 8 #include <vtkRenderWindowInteractor.h> 9 #include <vtkInteractorStyleImage.h> 10 #include <vtkRenderer.h> 11 #include <vtkImageActor.h> 12 #include <vtkBMPReader.h> 13 #include <vtkImageLuminance.h> 14 15 //测试图像:../data/lena.bmp 16 int main(int argc, char* argv[]) 17 { 18 vtkSmartPointer<vtkBMPReader> reader = 19 vtkSmartPointer<vtkBMPReader>::New(); 20 reader->SetFileName ( "lena.bmp" ); 21 22 vtkSmartPointer<vtkImageLuminance> luminanceFilter = 23 vtkSmartPointer<vtkImageLuminance>::New(); 24 luminanceFilter->SetInputConnection(reader->GetOutputPort()); 25 luminanceFilter->Update(); 26 27 vtkSmartPointer<vtkImageActor> originalActor = 28 vtkSmartPointer<vtkImageActor>::New(); 29 originalActor->SetInputData(reader->GetOutput()); 30 31 vtkSmartPointer<vtkImageActor> shiftscaleActor = 32 vtkSmartPointer<vtkImageActor>::New(); 33 shiftscaleActor->SetInputData(luminanceFilter->GetOutput()); 34 35 double originalViewport[4] = {0.0, 0.0, 0.5, 1.0}; 36 double shiftscaleViewport[4] = {0.5, 0.0, 1.0, 1.0}; 37 38 vtkSmartPointer<vtkRenderer> originalRenderer = 39 vtkSmartPointer<vtkRenderer>::New(); 40 originalRenderer->SetViewport(originalViewport); 41 originalRenderer->AddActor(originalActor); 42 originalRenderer->ResetCamera(); 43 originalRenderer->SetBackground(1.0, 1.0, 1.0); 44 45 vtkSmartPointer<vtkRenderer> shiftscaleRenderer = 46 vtkSmartPointer<vtkRenderer>::New(); 47 shiftscaleRenderer->SetViewport(shiftscaleViewport); 48 shiftscaleRenderer->AddActor(shiftscaleActor); 49 shiftscaleRenderer->ResetCamera(); 50 shiftscaleRenderer->SetBackground(1.0, 1.0, 1.0); 51 52 vtkSmartPointer<vtkRenderWindow> renderWindow = 53 vtkSmartPointer<vtkRenderWindow>::New(); 54 renderWindow->AddRenderer(originalRenderer); 55 renderWindow->AddRenderer(shiftscaleRenderer); 56 renderWindow->SetSize( 640, 320 ); 57 renderWindow->Render(); 58 renderWindow->SetWindowName("Color2GrayImageExample"); 59 60 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 61 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 62 vtkSmartPointer<vtkInteractorStyleImage> style = 63 vtkSmartPointer<vtkInteractorStyleImage>::New(); 64 65 renderWindowInteractor->SetInteractorStyle(style); 66 renderWindowInteractor->SetRenderWindow(renderWindow); 67 renderWindowInteractor->Initialize(); 68 69 renderWindowInteractor->Start(); 70 71 return EXIT_SUCCESS; 72 }标签:26,1.0,shiftscaleRenderer,vtkSmartPointer,灰度,图像,renderWindow,New,include From: https://www.cnblogs.com/ybqjymy/p/17630874.html