1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3 VTK_MODULE_INIT(vtkRenderingFreeType);
4 VTK_MODULE_INIT(vtkInteractionStyle);
5
6 #include <vtkSmartPointer.h>
7 #include <vtkMetaImageReader.h>
8 #include <vtkImageData.h>
9 #include <vtkMarchingCubes.h>
10 #include <vtkPolyDataMapper.h>
11 #include <vtkActor.h>
12 #include <vtkProperty.h>
13 #include <vtkRenderer.h>
14 #include <vtkRenderWindow.h>
15 #include <vtkRenderWindowInteractor.h>
16 #include <vtkInteractorStyleImage.h>
17 #include <vtkVoxelModeller.h>
18 int main()
19 {
20 vtkSmartPointer<vtkMetaImageReader> reader =
21 vtkSmartPointer<vtkMetaImageReader>::New();
22 reader->SetFileName("HeadMRVolume.mhd");
23 reader->Update();
24
25 vtkSmartPointer<vtkMarchingCubes> surface =
26 vtkSmartPointer<vtkMarchingCubes>::New();
27 surface->SetInputData(reader->GetOutput());
28 surface->ComputeNormalsOn();
29 surface->SetValue(0, 100); //第0个等值面 值为:200
30 surface->Update();
31 //surface->GenerateValues(0, 150, 200);
32 ///
33 vtkSmartPointer<vtkPolyDataMapper> surfMapper =
34 vtkSmartPointer<vtkPolyDataMapper>::New();
35 surfMapper->SetInputConnection(surface->GetOutputPort());
36 vtkSmartPointer<vtkActor> surfActor =
37 vtkSmartPointer<vtkActor>::New();
38 surfActor->SetMapper(surfMapper);
39 surfActor->GetProperty()->SetColor(1, 0, 0);
40
41 vtkSmartPointer<vtkRenderer> surfRender =
42 vtkSmartPointer<vtkRenderer>::New();
43 surfRender->AddActor(surfActor);
44 surfRender->SetBackground(0, 0, 0);
45
46 vtkSmartPointer<vtkRenderWindow> rw =
47 vtkSmartPointer<vtkRenderWindow>::New();
48 rw->AddRenderer(surfRender);
49 rw->SetSize(640, 480);
50 rw->SetWindowName("PolyData MarchingCubes");
51 rw->Render();
52
53 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
54 vtkSmartPointer<vtkRenderWindowInteractor>::New();
55 vtkSmartPointer<vtkInteractorStyleImage> style =
56 vtkSmartPointer<vtkInteractorStyleImage>::New();
57 rwi->SetInteractorStyle(style);
58 rwi->SetRenderWindow(rw);
59 rwi->Initialize();
60 rwi->Start();
61
62 return 0;
63 }