1 #include <vtkAutoInit.h> 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkRenderingFreeType); 4 VTK_MODULE_INIT(vtkInteractionStyle); 5 6 #include <vtkSmartPointer.h> 7 #include <vtkMarchingCubes.h> 8 #include <vtkContourFilter.h> 9 #include <vtkVoxelModeller.h> 10 #include <vtkSphereSource.h> 11 #include <vtkImageData.h> 12 #include <vtkMetaImageReader.h> 13 #include <vtkInteractorStyleImage.h> 14 #include <vtkActor.h> 15 #include <vtkPolyDataMapper.h> 16 #include <vtkRenderWindowInteractor.h> 17 #include <vtkRenderWindow.h> 18 #include <vtkRenderer.h> 19 #include <vtkImageActor.h> 20 #include <vtkProperty.h> 21 22 //测试:../data/HeadMRVolume.mhd 200 23 int main(int argc, char *argv[]) 24 { 25 vtkSmartPointer<vtkMetaImageReader> reader = 26 vtkSmartPointer<vtkMetaImageReader>::New(); 27 reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\HeadMRVolume.mhd"); 28 reader->Update(); 29 30 double isoValue = atof("200");//设置等值面值为200 31 32 vtkSmartPointer<vtkMarchingCubes> surface = 33 vtkSmartPointer<vtkMarchingCubes>::New(); 34 surface->SetInputData(reader->GetOutput()); 35 surface->ComputeNormalsOn(); 36 surface->SetValue(0, isoValue); 37 //surface->GenerateValues(5, 150,200); 38 39 /*vtkSmartPointer<vtkContourFilter> surface = 40 vtkSmartPointer<vtkContourFilter>::New(); 41 surface->SetInput(reader->GetOutput()); 42 surface->ComputeNormalsOn(); 43 surface->SetValue(0, isoValue);*/ 44 45 vtkSmartPointer<vtkPolyDataMapper> surfMapper = 46 vtkSmartPointer<vtkPolyDataMapper>::New(); 47 surfMapper->SetInputConnection(surface->GetOutputPort()); 48 surfMapper->ScalarVisibilityOff(); 49 50 vtkSmartPointer<vtkActor> surfActor = 51 vtkSmartPointer<vtkActor>::New(); 52 surfActor->SetMapper(surfMapper); 53 surfActor->GetProperty()->SetColor(1.0, 0.0, 0.0); 54 55 vtkSmartPointer<vtkRenderer> renderer = 56 vtkSmartPointer<vtkRenderer>::New(); 57 renderer->AddActor(surfActor); 58 renderer->SetBackground(1.0, 1.0, 1.0); 59 60 vtkSmartPointer<vtkRenderWindow> renderWindow = 61 vtkSmartPointer<vtkRenderWindow>::New(); 62 renderWindow->AddRenderer(renderer); 63 renderWindow->SetSize(640, 480); 64 renderWindow->Render(); 65 renderWindow->SetWindowName("PolyDataMarchingCubes"); 66 renderWindow->Render(); 67 68 vtkSmartPointer<vtkRenderWindowInteractor> interactor = 69 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 70 interactor->SetRenderWindow(renderWindow); 71 72 renderWindow->Render(); 73 interactor->Start(); 74 75 return EXIT_SUCCESS; 76 }标签:vtkSmartPointer,等值,VTK,surface,60,reader,renderWindow,New,include From: https://www.cnblogs.com/ybqjymy/p/17632974.html