]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Tue, 21 May 2013 06:50:16 +0000 (08:50 +0200)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Tue, 21 May 2013 06:50:16 +0000 (08:50 +0200)
common/clitkTransformUtilities.h
tools/CMakeLists.txt
tools/clitkBinaryImageToMesh.cxx
tools/clitkBinaryImageToMesh.ggo
tools/clitkTransformLandmarks.cxx
tools/clitkTransformLandmarks.ggo

index 3bdf22026ee0ab969a5fe8f6274db3a0fd4fa2e3..cbc30b97ac806aa0cd3c91d531dc4cac082bd2e8 100644 (file)
@@ -23,7 +23,8 @@
 #include "itkPoint.h"
 #include "clitkImageCommon.h"
 #include "clitkCommon.h"
+#include <vtkMatrix4x4.h>
+#include <vtkSmartPointer.h>
  
 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<double> nb;
+    double x;
+    skipComment(is);
+    is >> x;
+    while (!is.eof()) {
+      nb.push_back(x);
+      skipComment(is);
+      is >> x;
+    }
+
+    vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::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<double, 3, 3> ReadMatrix2D(std::string fileName)
   {
     // read input matrix
index 862148a10ee91817ef96abeae275f205147beb49..e9f8f1e28a77d200f8bf9c5c4fc93371ae70208c 100644 (file)
@@ -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)
index 220d033946908c4d7f490d358693eb62eb9a307c..0eb5db618af80b6ee894010c86112ea763f500ea 100644 (file)
@@ -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<vtkContourFilter> pcontour = vtkContourFilter::New();
     pcontour->SetValue(0, 0.5);
     pcontour->SetInputConnection(pbmp_reader->GetOutputPort());
-    
-    vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
-    psurface->SetInputConnection(pcontour->GetOutputPort());
 
+    vtkAlgorithmOutput *data = pcontour->GetOutputPort();
+
+    if ( (argsInfo.decimate_arg>=0) && (argsInfo.decimate_arg<=1) ) {
+      vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
+      psurface->SetInputConnection(pcontour->GetOutputPort());
+      psurface->SetTargetReduction(argsInfo.decimate_arg);
+
+      data = psurface->GetOutputPort();
+    }
+
+       
     vtkSmartPointer<vtkPolyDataMapper> skinMapper = vtkPolyDataMapper::New();
-    skinMapper->SetInputConnection(psurface->GetOutputPort());
+    skinMapper->SetInputConnection(data); //psurface->GetOutputPort()
     skinMapper->ScalarVisibilityOff();
       
     vtkSmartPointer<vtkActor> skin = vtkActor::New();
@@ -97,7 +106,7 @@ void run(const args_info_clitkBinaryImageToMesh& argsInfo)
     }
     if (writeVTK) {
       vtkSmartPointer<vtkPolyDataWriter> wr = vtkSmartPointer<vtkPolyDataWriter>::New();
-      wr->SetInputConnection(psurface->GetOutputPort());
+      wr->SetInputConnection(data); //psurface->GetOutputPort()
       wr->SetFileName(output.c_str());
       wr->Update();
       wr->Write();
index 3381298cfe8a5488903f12385bd10d7580e46ee4..8c6c7e45969b018048e4e0dc1820499328eaef1c 100644 (file)
@@ -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
index 86745a419363ad9d97194b0e9ccdf921c39ee39e..df5dbe8e390521e8705019f14dea0defd66db44c 100644 (file)
 #include <iostream>
 #include <fstream>
 
+#include <vtkSmartPointer.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+#include "vtkPolyDataReader.h"
+#include "vtkPolyDataWriter.h"
+#include <vtkTransform.h>
+#include <vtkTransformFilter.h>
+
 typedef itk::Matrix<double, 4, 4> MatrixType;
 typedef itk::Point<double, 4> PointType;
 typedef std::vector<PointType> 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<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
+    reader->SetFileName(args_info.input_arg);
+    reader->Update();
+    vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
+    writer->SetFileName( args_info.output_arg );
+
+    if (args_info.matrix_given) {
+      vtkSmartPointer<vtkTransformFilter> transformFilter = vtkSmartPointer<vtkTransformFilter>::New();
+      vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
+      vtkMatrix4x4* matrix = clitk::ReadVTKMatrix3D(args_info.matrix_arg);
+      vtkSmartPointer<vtkMatrix4x4> matrixT = vtkSmartPointer<vtkMatrix4x4>::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);
   }
index c731c23086539cfdecd138621afd6b8a6c0606a9..47722240c6d67134cfdc4f3a5eea100e44c2aa94 100644 (file)
@@ -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"