]> Creatis software - clitk.git/blobdiff - vv/vvMesh.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvMesh.cxx
index d666a21f76a14bcc54a1e1120bb5c0e9fa9bfc0e..15be4a4bedc7e0696bd13ac0aa4441f66989eef7 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
+
+//std 
 #include <sstream>
 #include <cassert>
 #include <vector>
+
+// clitk
+#include "clitkCommon.h"
+
+// vv
+#include "vvMesh.h"
+
+// itk
+#include <itksys/SystemTools.hxx>
+
+// vtk
+#include <vtkVersion.h>
 #include <vtkSmartPointer.h>
 #include <vtkFloatArray.h>
 #include <vtkPointData.h>
 #include <vtkPolyDataReader.h>
 #include <vtkOBJReader.h>
 #include <vtkImageData.h>
-#include "clitkCommon.h"
-#include "vvMesh.h"
 #include <vtkImageStencil.h>
 #include <vtkLinearExtrusionFilter.h>
 #include <vtkPolyDataToImageStencil.h>
 #include <vtkMarchingCubes.h>
-#include <itksys/SystemTools.hxx>
-
 #include <vtkMetaImageWriter.h>
 
 vvMesh::vvMesh() :
@@ -49,7 +59,6 @@ void vvMesh::AddMesh(vtkPolyData* p)
 
 void vvMesh::ReadFromVTK(const char * filename)
 {
-  DD("hello!");
   std::string extension=itksys::SystemTools::GetFilenameLastExtension(std::string(filename));
   if (extension == ".vtk" || extension== ".VTK") {
     assert(GetNumberOfMeshes() == 0); ///We assume the object is empty
@@ -127,12 +136,15 @@ void vvMesh::ComputeMasks(vtkImageData* sample,bool extrude)
     double *bounds=mesh->GetBounds();
 
     vtkSmartPointer<vtkImageData> binary_image=vtkSmartPointer<vtkImageData>::New();
+#if VTK_MAJOR_VERSION <= 5
     binary_image->SetScalarTypeToUnsignedChar();
+#endif
     ///Use the smallest mask in which the mesh fits
     // Add two voxels on each side to make sure the mesh fits
     double * samp_origin=sample->GetOrigin();
     double * spacing=sample->GetSpacing();
     binary_image->SetSpacing(spacing);
+
     /// Put the origin on a voxel to avoid small skips
     binary_image->SetOrigin(floor((bounds[0]-samp_origin[0])/spacing[0]-2)*spacing[0]+samp_origin[0],
                             floor((bounds[2]-samp_origin[1])/spacing[1]-2)*spacing[1]+samp_origin[1],
@@ -141,7 +153,11 @@ void vvMesh::ComputeMasks(vtkImageData* sample,bool extrude)
     binary_image->SetExtent(0,ceil((bounds[1]-origin[0])/spacing[0]+4),
                             0,ceil((bounds[3]-origin[1])/spacing[1]+4),
                             0,ceil((bounds[5]-origin[2])/spacing[2])+4);
+#if VTK_MAJOR_VERSION <= 5
     binary_image->AllocateScalars();
+#else
+    binary_image->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
+#endif
     memset(binary_image->GetScalarPointer(),0,binary_image->GetDimensions()[0]*binary_image->GetDimensions()[1]*binary_image->GetDimensions()[2]*sizeof(unsigned char));
 
 
@@ -153,22 +169,43 @@ void vvMesh::ComputeMasks(vtkImageData* sample,bool extrude)
 
     if (extrude) {
       vtkSmartPointer<vtkLinearExtrusionFilter> extrude=vtkSmartPointer<vtkLinearExtrusionFilter>::New();
+#if VTK_MAJOR_VERSION <= 5
       extrude->SetInput(mesh);
+#else
+      extrude->SetInputData(mesh);
+#endif
       ///We extrude in the -slice_spacing direction to respect the FOCAL convention
       extrude->SetVector(0, 0, -slice_spacing);
+#if VTK_MAJOR_VERSION <= 5
       sts->SetInput(extrude->GetOutput());
-    } else
+#else
+      sts->SetInputConnection(extrude->GetOutputPort());
+#endif
+    } else {
+#if VTK_MAJOR_VERSION <= 5
       sts->SetInput(mesh);
+#else
+      sts->SetInputData(mesh);
+#endif
+   }
 
     vtkSmartPointer<vtkImageStencil> stencil=vtkSmartPointer<vtkImageStencil>::New();
+#if VTK_MAJOR_VERSION <= 5
     stencil->SetStencil(sts->GetOutput());
     stencil->SetInput(binary_image);
+#else
+    stencil->SetStencilConnection(sts->GetOutputPort());
+    stencil->SetInputData(binary_image);
+#endif
     stencil->Update();
     this->AddMask(stencil->GetOutput());
-    //vtkSmartPointer<vtkMetaImageWriter> w = vtkSmartPointer<vtkMetaImageWriter>::New();
-    //w->SetInput(stencil->GetOutput());
-    //w->SetFileName("binary.mhd");
-    //w->Write();
+
+    /*
+      vtkSmartPointer<vtkMetaImageWriter> w = vtkSmartPointer<vtkMetaImageWriter>::New();
+      w->SetInput(stencil->GetOutput());
+      w->SetFileName("binary.mhd");
+      w->Write();
+    */
   }
 }
 
@@ -177,7 +214,11 @@ void vvMesh::ComputeMeshes()
   this->RemoveMeshes();
   for (std::vector<vtkImageData*>::iterator i=masks.begin(); i!=masks.end(); i++) {
     vtkSmartPointer<vtkMarchingCubes> marching = vtkSmartPointer<vtkMarchingCubes>::New();
+#if VTK_MAJOR_VERSION <= 5
     marching->SetInput(*i);
+#else
+    marching->SetInputData(*i);
+#endif
     marching->SetValue(0,0.5);
     marching->Update();
     this->AddMesh(marching->GetOutput());