]> Creatis software - clitk.git/commitdiff
Add clitkExtrude tool
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 15 Oct 2018 10:08:35 +0000 (12:08 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 15 Oct 2018 10:08:35 +0000 (12:08 +0200)
With this tool, you can copy the image i N times along the last dimension

tools/CMakeLists.txt
tools/clitkExtrude.cxx [new file with mode: 0644]
tools/clitkExtrude.ggo [new file with mode: 0644]
tools/clitkExtrudeGenericFilter.h [new file with mode: 0644]
tools/clitkExtrudeGenericFilter.txx [new file with mode: 0644]

index 468bc36660a6597a14e1e7e8e7c9662ae6ad4ff4..4259e19439bc678a3e577ac95e1b46f1bb8f455f 100644 (file)
@@ -304,6 +304,11 @@ if(CLITK_BUILD_TOOLS)
   target_link_libraries(clitkSum clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkSum)
 
+  WRAP_GGO(clitkExtrude_GGO_C clitkExtrude.ggo)
+  add_executable(clitkExtrude clitkExtrude.cxx ${clitkExtrude_GGO_C})
+  target_link_libraries(clitkExtrude clitkCommon)
+  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkExtrude)
+
   WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo)
   add_executable(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C})
   target_link_libraries(clitkTransformLandmarks clitkCommon)
diff --git a/tools/clitkExtrude.cxx b/tools/clitkExtrude.cxx
new file mode 100644 (file)
index 0000000..f860f58
--- /dev/null
@@ -0,0 +1,45 @@
+/*=========================================================================
+  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
+===========================================================================**/
+
+// clitk
+#include "clitkExtrude_ggo.h"
+#include "clitkExtrudeGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkExtrude, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::ExtrudeGenericFilter<args_info_clitkExtrude> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+  try {
+    filter->Update();
+  } catch(std::runtime_error e) {
+    std::cout << e.what() << std::endl;
+  }
+
+  return EXIT_SUCCESS;
+}// end main
+
+//--------------------------------------------------------------------
diff --git a/tools/clitkExtrude.ggo b/tools/clitkExtrude.ggo
new file mode 100644 (file)
index 0000000..680d188
--- /dev/null
@@ -0,0 +1,13 @@
+#File clitkExtrude.ggo
+package "clitkExtrude"
+version "1.0"
+purpose "Extrude an image i along the last+1 dimension repeating the image N times. So the output has 1 dimension more than the input."
+
+option "config"   - "Config file"                   string  optional
+option "verbose"  v "Verbose"                       flag    off
+
+option "input"    i "Input image filename"          string  required
+option "output"   o "Output image filename"         string  required
+option "size"     N "Size in pixel of extrusion"    int     yes
+option "spacing"  s "Spacing of the new dimension"  double  no        default="1.0"
+option "origin"   - "Origin of the new dimension"   double  no        default="0.0"
diff --git a/tools/clitkExtrudeGenericFilter.h b/tools/clitkExtrudeGenericFilter.h
new file mode 100644 (file)
index 0000000..73f512f
--- /dev/null
@@ -0,0 +1,69 @@
+/*=========================================================================
+  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
+===========================================================================**/
+#ifndef clitkExtrudeGenericFilter_h
+#define clitkExtrudeGenericFilter_h
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+template<class args_info_type>
+class ITK_EXPORT ExtrudeGenericFilter:
+        public ImageToImageGenericFilter<ExtrudeGenericFilter<args_info_type> >
+{
+
+public:
+
+    //--------------------------------------------------------------------
+    ExtrudeGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef ExtrudeGenericFilter               Self;
+    typedef itk::SmartPointer<Self>            Pointer;
+    typedef itk::SmartPointer<const Self>      ConstPointer;
+
+    //--------------------------------------------------------------------
+    // Method for creation through the object factory
+    // and Run-time type information (and related methods)
+    itkNewMacro(Self);
+    itkTypeMacro(ExtrudeGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type & a);
+
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class InputImageType>
+    void UpdateWithInputImageType();
+
+protected:
+    template<unsigned int Dim> void InitializeImageType();
+    args_info_type mArgsInfo;
+
+}; // end class
+//--------------------------------------------------------------------
+
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkExtrudeGenericFilter.txx"
+#endif
+
+#endif // #define clitkExtrudeGenericFilter_h
diff --git a/tools/clitkExtrudeGenericFilter.txx b/tools/clitkExtrudeGenericFilter.txx
new file mode 100644 (file)
index 0000000..96c7dc1
--- /dev/null
@@ -0,0 +1,157 @@
+/*=========================================================================
+  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
+===========================================================================**/
+#ifndef clitkExtrudeGenericFilter_txx
+#define clitkExtrudeGenericFilter_txx
+
+// itk include
+#include <clitkCommon.h>
+
+namespace clitk
+{
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+ExtrudeGenericFilter<args_info_type>::ExtrudeGenericFilter():
+  ImageToImageGenericFilter<Self>("Extrude")
+{
+  InitializeImageType<2>();
+  InitializeImageType<3>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<unsigned int Dim>
+void ExtrudeGenericFilter<args_info_type>::InitializeImageType()
+{
+  ADD_DEFAULT_IMAGE_TYPES(Dim);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class args_info_type>
+void ExtrudeGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
+{
+  mArgsInfo=a;
+  this->SetIOVerbose(mArgsInfo.verbose_flag);
+
+  if (mArgsInfo.input_given) {
+    this->SetInputFilename(mArgsInfo.input_arg);
+  }
+  if (mArgsInfo.output_given) {
+    this->SetOutputFilename(mArgsInfo.output_arg);
+  }
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class args_info_type>
+template<class InputImageType>
+void
+ExtrudeGenericFilter<args_info_type>::UpdateWithInputImageType()
+{
+
+  // Reading input
+  typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+
+  // Main filter
+  typedef typename InputImageType::PixelType PixelType;
+  const int Dim = InputImageType::ImageDimension;
+  typedef itk::Image<PixelType,Dim> ImageType;
+  typedef itk::Image<PixelType,Dim+1> OutputImageType;
+
+  //Create the output
+  typename OutputImageType::IndexType start;
+  typename OutputImageType::SizeType size;
+  typename OutputImageType::PointType origin;
+  typename OutputImageType::SpacingType spacing;
+  typename OutputImageType::DirectionType direction;
+  typename OutputImageType::Pointer output = OutputImageType::New();
+
+  start.Fill(0);
+
+  int extrusionSize(1);
+  if (mArgsInfo.size_given) {
+    if (mArgsInfo.size_arg > 0)
+      extrusionSize = mArgsInfo.size_arg;
+    else {
+      std::cerr << "The size has to be > 0" << std::endl;
+      return;
+    }
+  }
+
+  for (unsigned int i=0; i<Dim; ++i)
+    size[i] = input->GetLargestPossibleRegion().GetSize()[i];
+  size[Dim] = extrusionSize;
+
+  for (unsigned int i=0; i<Dim; ++i)
+    origin[i] = input->GetOrigin()[i];
+  if (mArgsInfo.origin_given)
+    origin[Dim] = mArgsInfo.origin_arg;
+  else
+    origin[Dim] = 0;
+
+  for (unsigned int i=0; i<Dim; ++i)
+    spacing[i] = input->GetSpacing()[i];
+  if (mArgsInfo.spacing_given)
+    spacing[Dim] = mArgsInfo.spacing_arg;
+  else
+    spacing[Dim] = 1;
+
+  for (unsigned int i=0; i<Dim; ++i) {
+    for (unsigned int j=0; j<Dim; ++j)
+      direction[i][j] = input->GetDirection()[i][j];
+    direction[i][Dim] = 0;
+  }
+  for (unsigned int i=0; i<Dim; ++i)
+    direction[Dim][i] = 0;
+  direction[Dim][Dim] = 1;
+
+  typename OutputImageType::RegionType region(start, size);
+  output->SetRegions(region);
+  output->Allocate();
+  output->FillBuffer(0);
+  output->SetOrigin(origin);
+  output->SetSpacing(spacing);
+  output->SetDirection(direction);
+
+  itk::ImageRegionIteratorWithIndex<InputImageType> inputIterator(input, input->GetLargestPossibleRegion());
+  while(!inputIterator.IsAtEnd()) {
+    typename OutputImageType::IndexType pixelIndex;
+    for (unsigned int i=0; i<Dim; ++i)
+      pixelIndex[i] = inputIterator.GetIndex()[i];
+    for (unsigned int i=0; i<extrusionSize; ++i) {
+      pixelIndex[Dim] = i;
+      output->SetPixel(pixelIndex, inputIterator.Get());
+    }
+    ++inputIterator;
+  }
+
+  this->template SetNextOutput<OutputImageType>(output);
+
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif //#define clitkExtrudeGenericFilter_txx