#include "itkPoint.h"
#include "clitkImageCommon.h"
#include "clitkCommon.h"
-
+#include <vtkMatrix4x4.h>
+#include <vtkSmartPointer.h>
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
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)
#include "itksys/SystemTools.hxx"
#include "vtkPolyDataWriter.h"
+#include "vtkSmoothPolyDataFilter.h"
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();
}
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();
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
#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;
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);
}
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"