1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
18 #include "clitkBinaryImageToMesh_ggo.h"
19 #include "clitkImageToImageGenericFilter.h"
21 #include "vtkMetaImageReader.h"
22 #include "vtkContourFilter.h"
23 #include "vtkDecimatePro.h"
24 #include "vtkPolyDataMapper.h"
25 #include "vtkRenderer.h"
26 #include "vtkRenderWindow.h"
28 #include "vtkCamera.h"
29 #include "vtkOBJExporter.h"
30 #include "vtkRenderWindowInteractor.h"
31 #include "vtkSmartPointer.h"
33 #include "itksys/SystemTools.hxx"
35 void run(const args_info_clitkBinaryImageToMesh& argsInfo);
37 int main(int argc, char** argv)
39 GGO(clitkBinaryImageToMesh, args_info);
46 void run(const args_info_clitkBinaryImageToMesh& argsInfo)
48 std::string file = argsInfo.input_arg;
50 vtkSmartPointer<vtkMetaImageReader> pbmp_reader = vtkMetaImageReader::New();
51 pbmp_reader->SetFileName(file.c_str());
52 pbmp_reader->Update();
54 printf("Filtering...\n");
55 vtkSmartPointer<vtkContourFilter> pcontour = vtkContourFilter::New();
56 pcontour->SetValue(0, 0.5);
57 pcontour->SetInputConnection(pbmp_reader->GetOutputPort());
59 vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
60 psurface->SetInputConnection(pcontour->GetOutputPort());
62 vtkSmartPointer<vtkPolyDataMapper> skinMapper = vtkPolyDataMapper::New();
63 skinMapper->SetInputConnection(psurface->GetOutputPort());
64 skinMapper->ScalarVisibilityOff();
66 vtkSmartPointer<vtkActor> skin = vtkActor::New();
67 skin->SetMapper(skinMapper);
69 vtkSmartPointer<vtkCamera> aCamera = vtkCamera::New();
70 aCamera->SetViewUp (0, 0, -1);
71 aCamera->SetPosition (0, 1, 0);
72 aCamera->SetFocalPoint (0, 0, 0);
73 aCamera->ComputeViewPlaneNormal();
76 vtkSmartPointer<vtkRenderer> aRenderer = vtkRenderer::New();
77 aRenderer->AddActor(skin);
78 aRenderer->SetActiveCamera(aCamera);
79 aRenderer->ResetCamera ();
80 aRenderer->SetBackground(0,0,0);
81 aRenderer->ResetCameraClippingRange ();
83 vtkSmartPointer<vtkRenderWindow> renWin = vtkRenderWindow::New();
84 renWin->AddRenderer(aRenderer);
85 renWin->SetSize(640, 480);
87 vtkSmartPointer<vtkOBJExporter> pwriter2 = vtkOBJExporter::New();
88 pwriter2->SetRenderWindow(renWin);
91 if (argsInfo.output_given) {
92 output = argsInfo.output_arg;
93 if (itksys::SystemTools::FileIsDirectory(output.c_str())) {
94 file = itksys::SystemTools::GetFilenameName(file.c_str());
95 file = itksys::SystemTools::GetFilenameWithoutExtension(file.c_str());
96 file = itksys::SystemTools::CollapseFullPath(file.c_str(), output.c_str());
103 file = itksys::SystemTools::GetFilenameWithoutExtension(file);
105 pwriter2->SetFilePrefix(file.c_str());
108 vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkRenderWindowInteractor::New();
109 iren->SetRenderWindow(renWin);
111 skinMapper->Update();
112 bool interact = argsInfo.view_flag;