]> Creatis software - clitk.git/commitdiff
Add clitkMeshToBinaryImage tool
authorVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Wed, 19 Oct 2011 09:28:40 +0000 (11:28 +0200)
committerVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Wed, 19 Oct 2011 09:28:40 +0000 (11:28 +0200)
- Add clitkMeshToBinaryImage tool based on the filter of the same name.

tools/CMakeLists.txt
tools/clitkMeshToBinaryImage.cxx [new file with mode: 0644]
tools/clitkMeshToBinaryImage.ggo [new file with mode: 0644]

index 8bf0cbc26cf5ebf2a0a443040fac459a03bc1f1e..5222f12b9650d8d0ba9e42fca6b5f3530d942d34 100644 (file)
@@ -346,6 +346,11 @@ IF (CLITK_BUILD_TOOLS)
     TARGET_LINK_LIBRARIES(clitkBinaryImageToMesh ${ITK_LIBRARIES} vtkCommon vtkRendering)
     SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBinaryImageToMesh)
 
+    WRAP_GGO(clitkMeshToBinaryImage_GGO_C clitkMeshToBinaryImage.ggo)
+    ADD_EXECUTABLE(clitkMeshToBinaryImage clitkMeshToBinaryImage.cxx ${clitkMeshToBinaryImage_GGO_C})
+    TARGET_LINK_LIBRARIES(clitkMeshToBinaryImage clitkCommon ${ITK_LIBRARIES} ${VTK_LIBRARIES})
+    SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMeshToBinaryImage)
+
     WRAP_GGO(clitkMeshViewer_GGO_C clitkMeshViewer.ggo)
     ADD_EXECUTABLE(clitkMeshViewer clitkMeshViewer.cxx ${clitkMeshViewer_GGO_C})
     TARGET_LINK_LIBRARIES(clitkMeshViewer vtkCommon vtkRendering)
diff --git a/tools/clitkMeshToBinaryImage.cxx b/tools/clitkMeshToBinaryImage.cxx
new file mode 100644 (file)
index 0000000..2c3d8cc
--- /dev/null
@@ -0,0 +1,94 @@
+/*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
+
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.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
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
+
+  It is distributed under dual licence
+
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================*/
+#include "clitkMeshToBinaryImage_ggo.h"
+#include "clitkMeshToBinaryImageFilter.h"
+#include "clitkCommon.h"
+#include "clitkImageCommon.h"
+
+#include <itkImageIOBase.h>
+#include <itkInvertIntensityImageFilter.h>
+
+#include <vtkOBJReader.h>
+
+#include <string>
+
+template <unsigned dim>
+void run(const args_info_clitkMeshToBinaryImage& argsInfo,
+         const itk::ImageIOBase * header)
+{
+  typedef itk::Image<unsigned char, dim> ImageType;
+  typename ImageType::Pointer like = ImageType::New();
+
+  typename ImageType::SizeType size;
+  for (unsigned i = 0; i < dim; ++i)
+    size[i] = header->GetDimensions(i);
+  typename ImageType::RegionType region;
+  region.SetSize(size);
+  like->SetRegions(region);
+
+  typename ImageType::SpacingType spacing;
+  for (unsigned i = 0; i < dim; ++i)
+    spacing[i] = header->GetSpacing(i);
+  like->SetSpacing(spacing);
+
+
+  typename ImageType::PointType origin;
+  for (unsigned i = 0; i < dim; ++i)
+    origin[i] = header->GetOrigin(i);
+  like->SetOrigin(origin);
+
+  vtkSmartPointer<vtkOBJReader> reader = vtkOBJReader::New();
+  reader->SetFileName(argsInfo.input_arg);
+  reader->Update();
+
+  typename clitk::MeshToBinaryImageFilter<ImageType>::Pointer filter =
+    clitk::MeshToBinaryImageFilter<ImageType>::New();
+  filter->SetExtrude(false);
+  filter->SetMesh(reader->GetOutput());
+  filter->SetLikeImage(like);
+  filter->Update();
+
+  typedef itk::InvertIntensityImageFilter<ImageType> InvertFilterType;
+  typename InvertFilterType::Pointer ifilter = InvertFilterType::New();
+  ifilter->SetInput(filter->GetOutput());
+  ifilter->SetMaximum(1);
+
+  clitk::writeImage(ifilter->GetOutput(), argsInfo.output_arg);
+}
+
+int main(int argc, char** argv)
+{
+  GGO(clitkMeshToBinaryImage, args_info);
+
+  itk::ImageIOBase::Pointer header =
+    clitk::readImageHeader(args_info.like_arg);
+  switch (header->GetNumberOfDimensions())
+  {
+    case 2:
+      run<2>(args_info, header);
+      break;
+    case 3:
+      run<3>(args_info, header);
+      break;
+    case 4:
+      run<4>(args_info, header);
+      break;
+  }
+
+  return EXIT_SUCCESS;
+}
diff --git a/tools/clitkMeshToBinaryImage.ggo b/tools/clitkMeshToBinaryImage.ggo
new file mode 100644 (file)
index 0000000..64577b3
--- /dev/null
@@ -0,0 +1,11 @@
+#File clitkBinaryImageToMesh.ggo
+package "clitkMeshToBinaryImage"
+version "1.0"
+purpose "Transform a vtk obj file into a binary mask"
+
+option "config"   - "Config file"   string  no
+option "verbose"  v     "Verbose"   flag  off
+
+option "input"      i "Input obj file"   string  yes
+option "output"     o "Output binary image"  string yes 
+option "like"       l "Output image will be like this one (size, spacing)"  string yes