From: David Sarrut Date: Tue, 21 May 2013 06:50:16 +0000 (+0200) Subject: Merge branch 'master' of git.creatis.insa-lyon.fr:clitk X-Git-Tag: v1.4.0~231 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0255ca419966ffe3fd22609cdc8693673e3e4cff;hp=b5bdc1984fefe2d79ebd5d791daa363c52c0f19b;p=clitk.git Merge branch 'master' of git.creatis.insa-lyon.fr:clitk --- diff --git a/common/clitkTransformUtilities.h b/common/clitkTransformUtilities.h index 3bdf220..cbc30b9 100644 --- a/common/clitkTransformUtilities.h +++ b/common/clitkTransformUtilities.h @@ -23,7 +23,8 @@ #include "itkPoint.h" #include "clitkImageCommon.h" #include "clitkCommon.h" - +#include +#include namespace clitk { @@ -278,6 +279,29 @@ namespace clitk return matrix; } + inline vtkMatrix4x4* ReadVTKMatrix3D(std::string fileName) { + // read input matrix + std::ifstream is; + openFileForReading(is, fileName); + std::vector nb; + double x; + skipComment(is); + is >> x; + while (!is.eof()) { + nb.push_back(x); + skipComment(is); + is >> x; + } + + vtkSmartPointer matrix = vtkSmartPointer::New(); + unsigned int index=0; + for (unsigned int i=0;i<4;i++) + for (unsigned int j=0;j<4;j++) + matrix->SetElement(i,j, nb[index++]); + + return matrix; + } + inline itk::Matrix ReadMatrix2D(std::string fileName) { // read input matrix diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 862148a..e9f8f1e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -220,7 +220,7 @@ IF (CLITK_BUILD_TOOLS) WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo) ADD_EXECUTABLE(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C}) - TARGET_LINK_LIBRARIES(clitkTransformLandmarks clitkCommon ${ITK_LIBRARIES}) + TARGET_LINK_LIBRARIES(clitkTransformLandmarks clitkCommon ${ITK_LIBRARIES} ${VTK_LIBRARIES}) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkTransformLandmarks) WRAP_GGO(clitkMaskLandmarks_GGO_C clitkMaskLandmarks.ggo) 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 diff --git a/tools/clitkTransformLandmarks.cxx b/tools/clitkTransformLandmarks.cxx index 86745a4..df5dbe8 100644 --- a/tools/clitkTransformLandmarks.cxx +++ b/tools/clitkTransformLandmarks.cxx @@ -23,6 +23,14 @@ #include #include +#include +#include +#include +#include "vtkPolyDataReader.h" +#include "vtkPolyDataWriter.h" +#include +#include + typedef itk::Matrix MatrixType; typedef itk::Point PointType; typedef std::vector PointArrayType; @@ -52,6 +60,32 @@ int main(int argc, char** argv) if (strcmp(args_info.type_arg, "txt") == 0) { read_points_txt(args_info.input_arg, inputPoints, data); } + else if (strcmp(args_info.type_arg, "vtk") == 0) { + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName(args_info.input_arg); + reader->Update(); + vtkSmartPointer writer = vtkSmartPointer::New(); + writer->SetFileName( args_info.output_arg ); + + if (args_info.matrix_given) { + vtkSmartPointer transformFilter = vtkSmartPointer::New(); + vtkSmartPointer transform = vtkSmartPointer::New(); + vtkMatrix4x4* matrix = clitk::ReadVTKMatrix3D(args_info.matrix_arg); + vtkSmartPointer matrixT = vtkSmartPointer::New(); + vtkMatrix4x4::Invert(matrix, matrixT); //not sure why, but this seems necessary for using the same .mat as when loading file with vv (probably due to the inversion trick performed in the vv reader...) + transform->SetMatrix(matrixT); + transformFilter->SetInputConnection(reader->GetOutputPort()); + transformFilter->SetTransform(transform); + writer->SetInputConnection(transformFilter->GetOutputPort()); + + } + else { //just write the output + writer->SetInputConnection( reader->GetOutputPort() ); + } + + writer->Write(); + return 0; + } else { read_points_pts(args_info.input_arg, inputPoints); } diff --git a/tools/clitkTransformLandmarks.ggo b/tools/clitkTransformLandmarks.ggo index c731c23..4772224 100644 --- a/tools/clitkTransformLandmarks.ggo +++ b/tools/clitkTransformLandmarks.ggo @@ -10,6 +10,6 @@ option "input" i "Input landmarks filename" string yes option "matrix" m "Input 4x4 matrix filename ('.mat' file)" string no option "spacing" s "If given, applies the given spacing (x,y,z) to the input points." double no multiple default="1" option "output" o "Output landmarks filename" string yes -option "type" t "Landmarks type ('pts' for Jef; 'txt' for VV)" string no default="txt" +option "type" t "Landmarks type ('pts' for Jef; 'txt' for VV ; 'vtk' for vtk meshes)" string no default="txt"