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 <vtkImageIdealHighPass.h> 8 #include <vtkImageActor.h> 9 #include <vtkRenderWindow.h> 10 #include <vtkRenderWindowInteractor.h> 11 #include <vtkRenderer.h> 12 #include <vtkJPEGReader.h> 13 #include <vtkImageFFT.h> 14 #include <vtkImageRFFT.h> 15 #include <vtkImageExtractComponents.h> 16 #include <vtkImageCast.h> 17 18 //测试图像:../data/lena-gray.jpg 19 int main(int argc, char* argv[]) 20 { 21 vtkSmartPointer<vtkJPEGReader> reader = 22 vtkSmartPointer<vtkJPEGReader>::New(); 23 reader->SetFileName("lena-gray.jpg"); 24 reader->Update(); 25 26 vtkSmartPointer<vtkImageFFT> fftFilter = 27 vtkSmartPointer<vtkImageFFT>::New(); 28 fftFilter->SetInputConnection(reader->GetOutputPort()); 29 fftFilter->Update(); 30 31 vtkSmartPointer<vtkImageIdealHighPass> highPassFilter = 32 vtkSmartPointer<vtkImageIdealHighPass>::New(); 33 highPassFilter->SetInputConnection(fftFilter->GetOutputPort()); 34 highPassFilter->SetXCutOff(0.1); 35 highPassFilter->SetYCutOff(0.1); 36 highPassFilter->Update(); 37 38 vtkSmartPointer<vtkImageRFFT> rfftFilter = 39 vtkSmartPointer<vtkImageRFFT>::New(); 40 rfftFilter->SetInputConnection(highPassFilter->GetOutputPort()); 41 rfftFilter->Update(); 42 43 vtkSmartPointer<vtkImageExtractComponents> ifftExtractReal = 44 vtkSmartPointer<vtkImageExtractComponents>::New(); 45 ifftExtractReal->SetInputConnection(rfftFilter->GetOutputPort()); 46 ifftExtractReal->SetComponents(0); 47 48 vtkSmartPointer<vtkImageCast> castFilter = 49 vtkSmartPointer<vtkImageCast>::New(); 50 castFilter->SetInputConnection(ifftExtractReal->GetOutputPort()); 51 castFilter->SetOutputScalarTypeToUnsignedChar(); 52 castFilter->Update(); 53 54 vtkSmartPointer<vtkImageActor> originalActor = 55 vtkSmartPointer<vtkImageActor>::New(); 56 originalActor->SetInputData(reader->GetOutput()); 57 58 vtkSmartPointer<vtkImageActor> erodedActor = 59 vtkSmartPointer<vtkImageActor>::New(); 60 erodedActor->SetInputData(castFilter->GetOutput()); 61 62 double leftViewport[4] = {0.0, 0.0, 0.5, 1.0}; 63 double rightViewport[4] = {0.5, 0.0, 1.0, 1.0}; 64 65 vtkSmartPointer<vtkRenderWindow> renderWindow = 66 vtkSmartPointer<vtkRenderWindow>::New(); 67 renderWindow->SetSize(640, 320); 68 renderWindow->Render(); 69 renderWindow->SetWindowName("IdealHighPassExample"); 70 71 vtkSmartPointer<vtkRenderWindowInteractor> interactor = 72 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 73 interactor->SetRenderWindow(renderWindow); 74 75 vtkSmartPointer<vtkRenderer> leftRenderer = 76 vtkSmartPointer<vtkRenderer>::New(); 77 renderWindow->AddRenderer(leftRenderer); 78 leftRenderer->SetViewport(leftViewport); 79 leftRenderer->SetBackground(1.0, 1.0, 1.0); 80 81 vtkSmartPointer<vtkRenderer> rightRenderer = 82 vtkSmartPointer<vtkRenderer>::New(); 83 renderWindow->AddRenderer(rightRenderer); 84 rightRenderer->SetViewport(rightViewport); 85 rightRenderer->SetBackground(1.0, 1.0, 1.0); 86 87 leftRenderer->AddActor(originalActor); 88 rightRenderer->AddActor(erodedActor); 89 90 leftRenderer->ResetCamera(); 91 rightRenderer->ResetCamera(); 92 93 renderWindow->Render(); 94 interactor->Start(); 95 96 return EXIT_SUCCESS; 97 }标签:1.0,47,VTK,频域,vtkSmartPointer,renderWindow,New,include,leftRenderer From: https://www.cnblogs.com/ybqjymy/p/17631075.html