From 46df890b27e7d340b52be7f67947bc570db4b05f Mon Sep 17 00:00:00 2001 From: =?utf8?q?U-PC-de-R=E9mi=5CR=E9mi?= Date: Tue, 7 May 2013 18:04:50 +0200 Subject: [PATCH] Made the mesh decimation optional, and tunable. If on, the resulting mesh may have problems and can be unreadable by transformix --- tools/clitkBinaryImageToMesh.cxx | 19 ++++++++++++++----- tools/clitkBinaryImageToMesh.ggo | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/clitkBinaryImageToMesh.cxx b/tools/clitkBinaryImageToMesh.cxx index 220d033..0eb5db6 100644 --- a/tools/clitkBinaryImageToMesh.cxx +++ b/tools/clitkBinaryImageToMesh.cxx @@ -33,6 +33,7 @@ #include "itksys/SystemTools.hxx" #include "vtkPolyDataWriter.h" +#include "vtkSmoothPolyDataFilter.h" void run(const args_info_clitkBinaryImageToMesh& argsInfo); @@ -57,12 +58,20 @@ void run(const args_info_clitkBinaryImageToMesh& argsInfo) vtkSmartPointer pcontour = vtkContourFilter::New(); pcontour->SetValue(0, 0.5); pcontour->SetInputConnection(pbmp_reader->GetOutputPort()); - - vtkSmartPointer psurface = vtkDecimatePro::New(); - psurface->SetInputConnection(pcontour->GetOutputPort()); + vtkAlgorithmOutput *data = pcontour->GetOutputPort(); + + if ( (argsInfo.decimate_arg>=0) && (argsInfo.decimate_arg<=1) ) { + vtkSmartPointer psurface = vtkDecimatePro::New(); + psurface->SetInputConnection(pcontour->GetOutputPort()); + psurface->SetTargetReduction(argsInfo.decimate_arg); + + data = psurface->GetOutputPort(); + } + + vtkSmartPointer skinMapper = vtkPolyDataMapper::New(); - skinMapper->SetInputConnection(psurface->GetOutputPort()); + skinMapper->SetInputConnection(data); //psurface->GetOutputPort() skinMapper->ScalarVisibilityOff(); vtkSmartPointer skin = vtkActor::New(); @@ -97,7 +106,7 @@ void run(const args_info_clitkBinaryImageToMesh& argsInfo) } if (writeVTK) { vtkSmartPointer wr = vtkSmartPointer::New(); - wr->SetInputConnection(psurface->GetOutputPort()); + wr->SetInputConnection(data); //psurface->GetOutputPort() wr->SetFileName(output.c_str()); wr->Update(); wr->Write(); diff --git a/tools/clitkBinaryImageToMesh.ggo b/tools/clitkBinaryImageToMesh.ggo index 3381298..8c6c7e4 100644 --- a/tools/clitkBinaryImageToMesh.ggo +++ b/tools/clitkBinaryImageToMesh.ggo @@ -8,4 +8,5 @@ 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 ; if names ends with .vtk the output is written as a vtkPolyData file" string no -option "view" - "View result" flag off +option "decimate" d "Decimate mesh (value in [0-1] is the target reduction percentage, outside this range means NO decimation)" double no default="-1" +option "view" - "View result" flag off -- 2.47.1