From: rblanc Date: Tue, 2 Apr 2013 14:34:33 +0000 (+0200) Subject: updated clitkBinaryImageToMesh, added the possibility to write a vtkPolyData output... X-Git-Tag: v1.4.0~236^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c87aea23e51e5e688cb7754ae570d888ab5445ba;hp=--cc;p=clitk.git updated clitkBinaryImageToMesh, added the possibility to write a vtkPolyData output file + fixed documentation --- c87aea23e51e5e688cb7754ae570d888ab5445ba diff --git a/tools/clitkBinaryImageToMesh.cxx b/tools/clitkBinaryImageToMesh.cxx index 4e00f7e..220d033 100644 --- a/tools/clitkBinaryImageToMesh.cxx +++ b/tools/clitkBinaryImageToMesh.cxx @@ -32,6 +32,8 @@ #include "itksys/SystemTools.hxx" +#include "vtkPolyDataWriter.h" + void run(const args_info_clitkBinaryImageToMesh& argsInfo); int main(int argc, char** argv) @@ -60,17 +62,17 @@ void run(const args_info_clitkBinaryImageToMesh& argsInfo) psurface->SetInputConnection(pcontour->GetOutputPort()); vtkSmartPointer skinMapper = vtkPolyDataMapper::New(); - skinMapper->SetInputConnection(psurface->GetOutputPort()); - skinMapper->ScalarVisibilityOff(); - + skinMapper->SetInputConnection(psurface->GetOutputPort()); + skinMapper->ScalarVisibilityOff(); + vtkSmartPointer skin = vtkActor::New(); - skin->SetMapper(skinMapper); - + skin->SetMapper(skinMapper); + vtkSmartPointer aCamera = vtkCamera::New(); - aCamera->SetViewUp (0, 0, -1); - aCamera->SetPosition (0, 1, 0); - aCamera->SetFocalPoint (0, 0, 0); - aCamera->ComputeViewPlaneNormal(); + aCamera->SetViewUp (0, 0, -1); + aCamera->SetPosition (0, 1, 0); + aCamera->SetFocalPoint (0, 0, 0); + aCamera->ComputeViewPlaneNormal(); aCamera->Dolly(1.5); vtkSmartPointer aRenderer = vtkRenderer::New(); @@ -81,32 +83,50 @@ void run(const args_info_clitkBinaryImageToMesh& argsInfo) aRenderer->ResetCameraClippingRange (); vtkSmartPointer renWin = vtkRenderWindow::New(); - renWin->AddRenderer(aRenderer); + renWin->AddRenderer(aRenderer); renWin->SetSize(640, 480); - - vtkSmartPointer pwriter2 = vtkOBJExporter::New(); - pwriter2->SetRenderWindow(renWin); - + std::string output; - if (argsInfo.output_given) { - output = argsInfo.output_arg; - if (itksys::SystemTools::FileIsDirectory(output.c_str())) { - file = itksys::SystemTools::GetFilenameName(file.c_str()); - file = itksys::SystemTools::GetFilenameWithoutExtension(file.c_str()); - file = itksys::SystemTools::CollapseFullPath(file.c_str(), output.c_str()); - } - else { - file = output; + if (argsInfo.output_given) { output = argsInfo.output_arg; } + + bool writeVTK = false; + if (output.length()>4) { + if (output.compare(output.length()-4, 4, ".vtk")==0) { + writeVTK=true; } } - else { - file = itksys::SystemTools::GetFilenameWithoutExtension(file); + if (writeVTK) { + vtkSmartPointer wr = vtkSmartPointer::New(); + wr->SetInputConnection(psurface->GetOutputPort()); + wr->SetFileName(output.c_str()); + wr->Update(); + wr->Write(); + } + else { + vtkSmartPointer pwriter2 = vtkOBJExporter::New(); + pwriter2->SetRenderWindow(renWin); + + if (argsInfo.output_given) { + output = argsInfo.output_arg; + if (itksys::SystemTools::FileIsDirectory(output.c_str())) { + file = itksys::SystemTools::GetFilenameName(file.c_str()); + file = itksys::SystemTools::GetFilenameWithoutExtension(file.c_str()); + file = itksys::SystemTools::CollapseFullPath(file.c_str(), output.c_str()); + } + else { + file = output; + } + } + else { + file = itksys::SystemTools::GetFilenameWithoutExtension(file); + } + pwriter2->SetFilePrefix(file.c_str()); + pwriter2->Write(); } - pwriter2->SetFilePrefix(file.c_str()); - pwriter2->Write(); + vtkSmartPointer iren = vtkRenderWindowInteractor::New(); - iren->SetRenderWindow(renWin); + iren->SetRenderWindow(renWin); skinMapper->Update(); bool interact = argsInfo.view_flag; diff --git a/tools/clitkBinaryImageToMesh.ggo b/tools/clitkBinaryImageToMesh.ggo index d04462d..3381298 100644 --- a/tools/clitkBinaryImageToMesh.ggo +++ b/tools/clitkBinaryImageToMesh.ggo @@ -1,11 +1,11 @@ #File clitkBinaryImageToMesh.ggo package "clitkBinaryImageToMesh" version "1.0" -purpose "Get the HU profile along the given line. Output to stdout." +purpose "Converts a binary image into a mesh object." option "config" - "Config file" string no option "verbose" v "Verbose" flag off option "input" i "Input image" string yes -option "output" o "Output mesh file prefix (if empty, use input file's base name as prefix; if a directoy, output to it using input file's base name as prefix; otherwise, use given name as prefix" string no +option "output" o "Output mesh file prefix (if empty, use input file's base name as prefix; if a directoy, output to it using input file's base name as prefix; otherwise, use given name as prefix ; if names ends with .vtk the output is written as a vtkPolyData file" string no option "view" - "View result" flag off