From 5ef6fa9a2d0ed8ec37df89fb74f2a1860b7844f8 Mon Sep 17 00:00:00 2001 From: Vivien Delmon Date: Wed, 19 Oct 2011 11:28:40 +0200 Subject: [PATCH] Add clitkMeshToBinaryImage tool - Add clitkMeshToBinaryImage tool based on the filter of the same name. --- tools/CMakeLists.txt | 5 ++ tools/clitkMeshToBinaryImage.cxx | 94 ++++++++++++++++++++++++++++++++ tools/clitkMeshToBinaryImage.ggo | 11 ++++ 3 files changed, 110 insertions(+) create mode 100644 tools/clitkMeshToBinaryImage.cxx create mode 100644 tools/clitkMeshToBinaryImage.ggo diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8bf0cbc..5222f12 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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 index 0000000..2c3d8cc --- /dev/null +++ b/tools/clitkMeshToBinaryImage.cxx @@ -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 +#include + +#include + +#include + +template +void run(const args_info_clitkMeshToBinaryImage& argsInfo, + const itk::ImageIOBase * header) +{ + typedef itk::Image 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 reader = vtkOBJReader::New(); + reader->SetFileName(argsInfo.input_arg); + reader->Update(); + + typename clitk::MeshToBinaryImageFilter::Pointer filter = + clitk::MeshToBinaryImageFilter::New(); + filter->SetExtrude(false); + filter->SetMesh(reader->GetOutput()); + filter->SetLikeImage(like); + filter->Update(); + + typedef itk::InvertIntensityImageFilter 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 index 0000000..64577b3 --- /dev/null +++ b/tools/clitkMeshToBinaryImage.ggo @@ -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 -- 2.47.1