]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of /home/dsarrut/clitk3.server
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Mon, 26 Sep 2011 15:18:48 +0000 (17:18 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Mon, 26 Sep 2011 15:18:48 +0000 (17:18 +0200)
12 files changed:
CMakeLists.txt
tests/tools/CMakeLists.txt
tests/tools/toolTestRunner.cxx
tools/CMakeLists.txt
tools/clitkPadImage.cxx
tools/clitkPadImage.ggo
tools/clitkPadImageGenericFilter.cxx [new file with mode: 0644]
tools/clitkPadImageGenericFilter.h [new file with mode: 0644]
vv/CMakeLists.txt
vv/vvMainWindow.cxx
vv/vvSegmentationDialog.cxx
vv/vvToolStructureSetManager.cxx

index 48f125772db517ac6d22b08b3a8ba6169fcf6f14..a8b6c0f6a837dbf1a4c13b10905c0f9b164398a2 100644 (file)
@@ -122,6 +122,10 @@ SET(SCRIPTS
   scripts/create_midP_masks.sh  
   scripts/create_midP_masks-2.0.sh  
   scripts/pts_to_landmarks.sh
+  scripts/create_mhd_3D.sh
+  scripts/create_sequence.sh
+  scripts/dcm_sort_by_field.sh
+  scripts/dicom_info.sh
 )
 
 INSTALL (FILES ${SCRIPTS} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
index 3d5e87f63900a6220e18e2f8eaa380113fada321..5e1165b1900180ad44c1e481758cdfdcf2fe1ae8 100644 (file)
@@ -19,7 +19,6 @@ ADD_EXECUTABLE(toolTestRunner ${srcs})
 TARGET_LINK_LIBRARIES(toolTestRunner vvLib ${vvExternalLibs})
 SET(exe ${EXECUTABLE_OUTPUT_PATH}/toolTestRunner) 
 SET(p ${CLITK_TEST_DATA_PATH})
-SET(tmpFile "feve51zd")
 #=========================================================
 # clitkImageInfo
 ADD_TEST(clitkImageInfo_4d    ${exe} clitkImageInfo ${p}Deformation4D.mhd ${p}Deformation4D_ref.info)
@@ -44,7 +43,50 @@ ADD_TEST(clitkGetDirection_3d ${exe} clitkGetDirection -i ${p}Lung3D.mhd     ${p}Lu
 # clitkBinarize
 ADD_TEST(clitkBinarizeBGl0.1356_4d ${exe} clitkBinarizeImage -i ${p}Deformation4D.mhd --mode BG -l 0.1356 -o Deformation4D_ref.binarizeBGl0.1356.mhd ${p}Deformation4D_ref.binarizeBGl0.1356)
 ADD_TEST(clitkBinarizeFGl0.1556_3d ${exe} clitkBinarizeImage -i ${p}Lung3D.mhd        --mode FG -l 0.1556 -o Lung3D_ref.binarizeFGl0.1556.mhd ${p}Lung3D_ref.binarizeFGl0.1556)
+#=========================================================
+# clitkImageArithm
+ADD_TEST(clitkImageArithm0_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 0 -o Lung3D_ref.arithm0.mhd ${p}Lung3D_ref.arithm0.mhd)
+ADD_TEST(clitkImageArithm1_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 1 -o Lung3D_ref.arithm1.mhd ${p}Lung3D_ref.arithm1.mhd)
+ADD_TEST(clitkImageArithm2_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 2 -o Lung3D_ref.arithm2.mhd ${p}Lung3D_ref.arithm2.mhd)
+ADD_TEST(clitkImageArithm3_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 3 -o Lung3D_ref.arithm3.mhd ${p}Lung3D_ref.arithm3.mhd)
+ADD_TEST(clitkImageArithm4_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 4 -o Lung3D_ref.arithm4.mhd ${p}Lung3D_ref.arithm4.mhd)
+ADD_TEST(clitkImageArithm5_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 5 -o Lung3D_ref.arithm5.mhd ${p}Lung3D_ref.arithm5.mhd)
+ADD_TEST(clitkImageArithm6_3d ${exe} clitkImageArithm -i ${p}Lung3D.mhd -j ${p}Lung3D.mhd -t 6 -o Lung3D_ref.arithm6.mhd ${p}Lung3D_ref.arithm6.mhd)
+
+ADD_TEST(clitkImageArithm0_4d ${exe} clitkImageArithm -i ${p}Deformation4D.mhd -j ${p}Deformation4D.mhd -t 0 -o Deformation4D_ref.arithm0.mhd ${p}Deformation4D_ref.arithm0.mhd)
+ADD_TEST(clitkImageArithm2_4d ${exe} clitkImageArithm -i ${p}Deformation4D.mhd -j ${p}Deformation4D.mhd -t 2 -o Deformation4D_ref.arithm2.mhd ${p}Deformation4D_ref.arithm2.mhd)
+#=========================================================
+# clitkCropImage
+ADD_TEST(clitkCropImage_3d ${exe} clitkCropImage -i ${p}Lung3D.mhd -b 1,4,0,2,2,3 -o Lung3D_ref.cropImage.1.4.0.2.2.3.mhd ${p}Lung3D_ref.cropImage.1.4.0.2.2.3.mhd)
+#=========================================================
+#clitkMorphoMath
+ADD_TEST(clitkMorphoMath0_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t0.mhd ${p}Lung3D_ref.morphoMath.t0.mhd)
+ADD_TEST(clitkMorphoMath1_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t1.mhd ${p}Lung3D_ref.morphoMath.t1.mhd)
+ADD_TEST(clitkMorphoMath2_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t2.mhd ${p}Lung3D_ref.morphoMath.t2.mhd)
+ADD_TEST(clitkMorphoMath3_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t3.mhd ${p}Lung3D_ref.morphoMath.t3.mhd)
+ADD_TEST(clitkMorphoMath4_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t4.mhd ${p}Lung3D_ref.morphoMath.t4.mhd)
+ADD_TEST(clitkMorphoMath5_3d ${exe} clitkMorphoMath -i ${p}Lung3D.mhd -o Lung3D_ref.morphoMath.t5.mhd ${p}Lung3D_ref.morphoMath.t5.mhd)
+
+ADD_TEST(clitkMorphoMath0_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t0.mhd ${p}Deformation4D_ref.morphoMath.t0.mhd)
+ADD_TEST(clitkMorphoMath1_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t1.mhd ${p}Deformation4D_ref.morphoMath.t1.mhd)
+ADD_TEST(clitkMorphoMath2_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t2.mhd ${p}Deformation4D_ref.morphoMath.t2.mhd)
+ADD_TEST(clitkMorphoMath3_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t3.mhd ${p}Deformation4D_ref.morphoMath.t3.mhd)
+ADD_TEST(clitkMorphoMath4_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t4.mhd ${p}Deformation4D_ref.morphoMath.t4.mhd)
+ADD_TEST(clitkMorphoMath5_4d ${exe} clitkMorphoMath -i ${p}Deformation4D.mhd -o Deformation4D_ref.morphoMath.t5.mhd ${p}Deformation4D_ref.morphoMath.t5.mhd)
+
+
+#=========================================================
+
+
+
+
+
+
+
+
+
+
 
-UNSET(tmpFile)
 UNSET(exe)
-UNSET(p)
\ No newline at end of file
+UNSET(p)
+
index 42226b781d9634bc1919c97d16391b3bd0da49e5..753aa37bcef992c0bccf53ff922ae6c3724aab86 100644 (file)
@@ -57,6 +57,65 @@ void assertFalse(int fail, const std::string &message=""){
     exit(1);
   }
 }
+bool isLineToIgnore(const std::string line){
+       if(std::string::npos == line.find_first_of("ITK_InputFilterName")){
+               return true;
+       }
+       return false;
+}
+bool mhdCmp(const std::string &file, const std::string &refFile){
+       bool sameFiles = true;
+       std::ifstream in(file.c_str());
+       std::ifstream ref(file.c_str());
+       std::string line;
+       std::string refLine;
+       while ( in.good() && ref.good()){
+               getline (in,line);
+               //does the line begins by an attribute to ignore
+               if(isLineToIgnore(line)){
+                       continue;
+               }
+               
+               getline(ref,refLine);
+               while(isLineToIgnore(refLine)){
+                       getline(ref,refLine);
+               }
+               if(line!=refLine){
+                       sameFiles = false;
+                       break;
+               }
+       }
+       in.close();
+       ref.close();
+       //check files same length
+       return sameFiles;
+}
+
+#ifdef _WIN32
+void dosToUnixFile(std::string dosFile, std::string unixedFile){
+               
+       std::ifstream ifile(dosFile.c_str(),std::ios::binary);
+       ifile.seekg(0,std::ios_base::end);
+       long s=ifile.tellg();
+       char *buffer=new char[s];
+       ifile.seekg(0);
+       ifile.read(buffer,s);
+       ifile.close();
+       std::string txt(buffer,s);
+       delete[] buffer;
+       size_t off=0;
+       while ((off=txt.find("\r\n",off))!=std::string::npos)
+               txt.replace(off,sizeof("\r\n")-1,"\n");
+       std::ofstream ofile(unixedFile.c_str());
+       ofile.write(txt.c_str(),txt.size());
+       
+}
+#endif
+
+std::string mhdToRawName(const std::string &mhdName){
+       int found = mhdName.find_last_of(".");
+  return mhdName.substr(0, found)+".raw";
+}
 /**
  * argv
  * [1] executable
@@ -69,7 +128,8 @@ void assertFalse(int fail, const std::string &message=""){
 int main(int argc, char** argv){
   //reference file must exist or we fail
   char* refFile = argv[argc-1];
-  assertFalse(!(itksys::SystemTools::FileExists(refFile, true)), "refFile "+std::string(refFile)+" doesn't exist");
+       std::string strRefFile = std::string(refFile);
+  assertFalse(!(itksys::SystemTools::FileExists(refFile, true)), "refFile "+strRefFile+" doesn't exist");
   
   std::ostringstream cmd_line;
   cmd_line<<CLITK_TEST_TOOLS_PATH;
@@ -91,17 +151,21 @@ int main(int argc, char** argv){
   //run the command line
   system(cmd_line.str().c_str());
   
-  //compare source files
-  assertFalse((itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile)), "Source Files are different");
-  
-  //eventually raw files associated
-  //should be passed as a boolean to check also for raw or not
   
-  std::string refRawFile = std::string(refFile)+".raw";
+       //compare source files
+#ifdef _WIN32
+       std::string unixedOutFile= getTmpFileName();
+       //replace \r\n
+       dosToUnixFile(outFile, unixedOutFile);
+       assertFalse(!mhdCmp(unixedOutFile, refFile), "Generated mhd file != ref File");
+  remove(unixedOutFile.c_str());
+#else
+  assertFalse(!mhdCmp(outFile.c_str(), refFile), "Generated mhd file != ref File");
+#endif
   
+  std::string refRawFile = mhdToRawName(strRefFile);
+  std::string rawFile = mhdToRawName(outFile);
   
-  int found=outFile.find_last_of(".");
-  std::string rawFile = outFile.substr(0, found)+".raw";
   if((itksys::SystemTools::FileExists(refRawFile.c_str(), true))){
     //compare the raw stuff
     if((itksys::SystemTools::FileExists(rawFile.c_str(), true))){
@@ -117,3 +181,5 @@ int main(int argc, char** argv){
   //success
   return 0;
 }
+
+
index 45a06acd30c6367b0e0843f75df310179d9ae7b9..f5a62b443880ceb3c3c4dc18575b5f73d3a4e710 100644 (file)
@@ -325,7 +325,7 @@ IF (CLITK_BUILD_TOOLS)
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkJacobianImage)
   
   WRAP_GGO(clitkPadImage_GGO_C clitkPadImage.ggo)
-  ADD_EXECUTABLE(clitkPadImage clitkPadImage.cxx ${clitkPadImage_GGO_C})
+  ADD_EXECUTABLE(clitkPadImage clitkPadImage.cxx clitkPadImageGenericFilter.cxx ${clitkPadImage_GGO_C})
   TARGET_LINK_LIBRARIES(clitkPadImage clitkCommon ${ITK_LIBRARIES})
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkPadImage)
 
index ad93eaa4b56e160c6ce1a58a52eb43c523d52bac..94d8ab672c42701a0f8e500f938edfa0e0dad113 100644 (file)
-#include "itkImage.h"
-#include "itkImageFileReader.h"
-#include "itkImageFileWriter.h"
-#include "itkConstantPadImageFilter.h"
 #include "clitkCommon.h"
 #include "clitkPadImage_ggo.h"
-#include <string>
-#include "itkMath.h"
+#include "clitkPadImageGenericFilter.h"
 
-enum
-{
-  ERR_SUCCESS = 0,
-  ERR_NOT_SAME_SPACING = -1,
-  ERR_NOT_LIKE_LARGER = -2
-};
-
-typedef unsigned int DimType;
-
-template <class ImageType, class PadBoundType, DimType dim>
-int pad_like(typename ImageType::Pointer input, const std::string& likeFile, PadBoundType* padLower, PadBoundType* padUpper)
-{
-  typedef typename ImageType::SpacingType SpacingType;
-  typedef typename ImageType::RegionType RegionType;
-  typedef typename ImageType::SizeType SizeType;
-  typedef typename ImageType::IndexType IndexType;
-  typedef typename ImageType::PointType PointType;
-  typedef typename ImageType::PointValueType PointValueType;
-
-  typedef itk::ImageFileReader<ImageType> ImageReaderType;
-  typename ImageReaderType::Pointer reader = ImageReaderType::New();
-  reader->SetFileName(likeFile);
-  reader->Update();
-  
-  typename ImageType::Pointer like_image = reader->GetOutput();
-
-  SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); 
-  if (spacing != like_spacing) {
-    std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl;
-    return ERR_NOT_SAME_SPACING;
-  }
-  
-  SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize();
-  PointType origin = input->GetOrigin(), like_origin = like_image->GetOrigin();
-  
-  PointType lower_bound, like_lower_bound;
-  PointType upper_bound, like_upper_bound;
-  PointValueType auxl = 0, auxu = 0;
-  for (DimType i = 0; i < dim; i++) {
-    lower_bound[i] = origin[i];
-    like_lower_bound[i] = like_origin[i];
-    auxl = itk::Math::Round<PointValueType>(((lower_bound[i] - like_lower_bound[i])/spacing[i]));
-    
-    upper_bound[i] = (lower_bound[i] + size[i]*spacing[i]);
-    like_upper_bound[i] = (like_lower_bound[i] + like_size[i]*spacing[i]);
-    auxu = itk::Math::Round<PointValueType>(((like_upper_bound[i] - upper_bound[i])/spacing[i]));
-
-    if (auxl < 0 || auxu < 0) {
-      std::cerr << "Like-image's bounding box must be larger than input's" << std::endl;
-      return ERR_NOT_LIKE_LARGER;
-    }
-
-    padLower[i] = (PadBoundType)auxl;
-    padUpper[i] = (PadBoundType)auxu;
-  }
-  
-  return ERR_SUCCESS;
-}
+// template <class ImageType, class PadBoundType, unsigned int dim>
+// int pad_like(typename ImageType::Pointer input, const std::string& likeFile, PadBoundType* padLower, PadBoundType* padUpper)
+// {
+//   typedef typename ImageType::SpacingType SpacingType;
+//   typedef typename ImageType::RegionType RegionType;
+//   typedef typename ImageType::SizeType SizeType;
+//   typedef typename ImageType::IndexType IndexType;
+//   typedef typename ImageType::PointType PointType;
+//   typedef typename ImageType::PointValueType PointValueType;
+// 
+//   typedef itk::ImageFileReader<ImageType> ImageReaderType;
+//   typename ImageReaderType::Pointer reader = ImageReaderType::New();
+//   reader->SetFileName(likeFile);
+//   reader->Update();
+//   
+//   typename ImageType::Pointer like_image = reader->GetOutput();
+// 
+//   SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); 
+//   if (spacing != like_spacing) {
+//     std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl;
+//     return ERR_NOT_SAME_SPACING;
+//   }
+//   
+//   SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize();
+//   PointType origin = input->GetOrigin(), like_origin = like_image->GetOrigin();
+//   
+//   PointType lower_bound, like_lower_bound;
+//   PointType upper_bound, like_upper_bound;
+//   PointValueType auxl = 0, auxu = 0;
+//   for (unsigned int i = 0; i < dim; i++) {
+//     lower_bound[i] = origin[i];
+//     like_lower_bound[i] = like_origin[i];
+//     auxl = itk::Math::Round<PointValueType>(((lower_bound[i] - like_lower_bound[i])/spacing[i]));
+//     
+//     upper_bound[i] = (lower_bound[i] + size[i]*spacing[i]);
+//     like_upper_bound[i] = (like_lower_bound[i] + like_size[i]*spacing[i]);
+//     auxu = itk::Math::Round<PointValueType>(((like_upper_bound[i] - upper_bound[i])/spacing[i]));
+// 
+//     if (auxl < 0 || auxu < 0) {
+//       std::cerr << "Like-image's bounding box must be larger than input's" << std::endl;
+//       return ERR_NOT_LIKE_LARGER;
+//     }
+// 
+//     padLower[i] = (PadBoundType)auxl;
+//     padUpper[i] = (PadBoundType)auxu;
+//   }
+//   
+//   return ERR_SUCCESS;
+// }
 
 int main(int argc, char** argv)
 {
-  const DimType dim = 3;
+/*  const DimType dim = 3;
   typedef short PixelType;
   typedef itk::Image<PixelType, dim> ImageType;
   typedef itk::ImageFileReader<ImageType> ImageReaderType;
   typedef itk::ImageFileWriter<ImageType> ImageWriterType;
   typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
-  typedef PadFilterType::SizeValueType PadBoundType;
+  typedef PadFilterType::SizeValueType PadBoundType;*/
   
   GGO(clitkPadImage, args_info);
-  
-  ImageReaderType::Pointer reader = ImageReaderType::New();
-  reader->SetFileName(args_info.input_arg);
-  reader->Update();
-  
-  PadBoundType pad_lower[dim], pad_upper[dim];
-  ImageType::Pointer input = reader->GetOutput();
-  if (args_info.like_given) {
-    int err = pad_like<ImageType, PadBoundType, dim>(input, args_info.like_arg, pad_lower, pad_upper);
-    if (err) {
-      std::cerr << "Error processing like image." << std::endl;
-      return err;
-    }
-  }
-  else {
-    for (DimType i = 0; i < dim; i++) {
-      pad_lower[i] = args_info.lower_arg[i];
-      pad_upper[i] = args_info.upper_arg[i];
-    }
+
+  // Filter
+  typedef clitk::PadImageGenericFilter FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+
+  try { 
+    filter->Update();
+  } catch(std::runtime_error e) {
+    std::cout << e.what() << std::endl;
   }
   
-  PadFilterType::Pointer filter = PadFilterType::New();
-  filter->SetPadLowerBound(pad_lower);
-  filter->SetPadUpperBound(pad_upper);
-  filter->SetInput(input);
-  filter->SetConstant(args_info.value_arg);
-  filter->Update();
-  
-  ImageType::Pointer output = filter->GetOutput();
-  ImageWriterType::Pointer writer = ImageWriterType::New();
-  writer->SetInput(output);
-  writer->SetFileName(args_info.output_arg);
-  writer->Update();
+//   ImageReaderType::Pointer reader = ImageReaderType::New();
+//   reader->SetFileName(args_info.input_arg);
+//   reader->Update();
+//   
+//   PadBoundType pad_lower[dim], pad_upper[dim];
+//   ImageType::Pointer input = reader->GetOutput();
+//   if (args_info.like_given) {
+//     int err = pad_like<ImageType, PadBoundType, dim>(input, args_info.like_arg, pad_lower, pad_upper);
+//     if (err) {
+//       std::cerr << "Error processing like image." << std::endl;
+//       return err;
+//     }
+//   }
+//   else {
+//     for (DimType i = 0; i < dim; i++) {
+//       pad_lower[i] = args_info.lower_arg[i];
+//       pad_upper[i] = args_info.upper_arg[i];
+//     }
+//   }
+//   
+//   PadFilterType::Pointer filter = PadFilterType::New();
+//   filter->SetPadLowerBound(pad_lower);
+//   filter->SetPadUpperBound(pad_upper);
+//   filter->SetInput(input);
+//   filter->SetConstant(args_info.value_arg);
+//   filter->Update();
+//   
+//   ImageType::Pointer output = filter->GetOutput();
+//   ImageWriterType::Pointer writer = ImageWriterType::New();
+//   writer->SetInput(output);
+//   writer->SetFileName(args_info.output_arg);
+//   writer->Update();
   
-  return ERR_SUCCESS;
+  return EXIT_SUCCESS;
 }
 
index 6f21563a4e98c59ec5a7a6b2cd04091178f64929..c83dfff55060f73b8b006788562387175573f1d9 100644 (file)
@@ -1,5 +1,5 @@
-#File clitkCropImage.ggo
-package "clitkCropImage"
+#File clitkPadImage.ggo
+package "clitkPadImage"
 version "1.0"
 purpose "Pad an image according to a given extends or like another image"
 
diff --git a/tools/clitkPadImageGenericFilter.cxx b/tools/clitkPadImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..49d4075
--- /dev/null
@@ -0,0 +1,191 @@
+/*=========================================================================
+  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 clitkPadImageGenericFilter_cxx
+#define clitkPadImageGenericFilter_cxx
+
+/* =================================================
+ * @file   clitkPadImageGenericFilter.cxx
+ * @author 
+ * @date   
+ * 
+ * @brief 
+ * 
+ ===================================================*/
+
+#include "clitkPadImageGenericFilter.h"
+
+// itk
+#include <itkConstantPadImageFilter.h>
+
+
+namespace clitk
+{
+
+
+  //-----------------------------------------------------------
+  // Constructor
+  //-----------------------------------------------------------
+  PadImageGenericFilter::PadImageGenericFilter():
+    ImageToImageGenericFilter<Self>("PadImage")
+  {
+    cmdline_parser_clitkPadImage_init(&mArgsInfo);
+    InitializeImageType<2>();
+    InitializeImageType<3>();
+    //InitializeImageType<4>();
+  }
+
+  //--------------------------------------------------------------------
+  template<unsigned int Dim>
+  void PadImageGenericFilter::InitializeImageType()
+  {
+    ADD_DEFAULT_IMAGE_TYPES(Dim);
+    //ADD_IMAGE_TYPE(Dim, uchar);
+    //ADD_IMAGE_TYPE(Dim, short);
+    // ADD_IMAGE_TYPE(Dim, uint);
+    //  ADD_IMAGE_TYPE(Dim, ulong);
+    // ADD_IMAGE_TYPE(Dim, int);
+    // ADD_IMAGE_TYPE(Dim, float);
+  }
+  //--------------------------------------------------------------------
+
+  //--------------------------------------------------------------------
+  void PadImageGenericFilter::SetArgsInfo(const args_info_type& a) 
+  {
+    mArgsInfo=a;
+    SetIOVerbose(mArgsInfo.verbose_flag);
+    if (mArgsInfo.input_given)   AddInputFilename(mArgsInfo.input_arg);
+    if (mArgsInfo.output_given)  AddOutputFilename(mArgsInfo.output_arg);
+  }
+  //--------------------------------------------------------------------
+
+  //--------------------------------------------------------------------
+  // Update with the number of dimensions and the pixeltype
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  void PadImageGenericFilter::UpdateWithInputImageType() 
+  { 
+    typedef itk::ConstantPadImageFilter<ImageType, ImageType> PadFilterType;
+    typedef typename PadFilterType::SizeValueType PadBoundType;
+
+    // Reading input
+    typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
+
+    const unsigned int dim = ImageType::ImageDimension;
+    PadBoundType pad_lower[dim], pad_upper[dim];
+    if (mArgsInfo.like_given) {
+      int err = PadLike<ImageType, PadBoundType, ImageType::ImageDimension>(input, pad_lower, pad_upper);
+      if (err) {
+        std::cerr << "Error processing like image." << std::endl;
+        return;
+      }
+    }
+    else {
+      if (mArgsInfo.lower_given != dim || mArgsInfo.upper_given != dim)
+      {
+        std::cerr << "The number of lower and upper padding parameters must be equal to the image dimension." << std::endl;
+        return;
+      }
+      
+      for (unsigned int i = 0; i < dim; i++) {
+        pad_lower[i] = mArgsInfo.lower_arg[i];
+        pad_upper[i] = mArgsInfo.upper_arg[i];
+      }
+    }
+    
+    typename PadFilterType::Pointer filter = PadFilterType::New();
+    filter->SetPadLowerBound(pad_lower);
+    filter->SetPadUpperBound(pad_upper);
+    filter->SetInput(input);
+    filter->SetConstant(mArgsInfo.value_arg);
+    filter->Update();
+
+    // Prepare output
+    typename ImageType::Pointer output;
+    output = filter->GetOutput();
+      
+    // Write/Save results
+    this->template SetNextOutput<ImageType>(output); 
+  }
+  //--------------------------------------------------------------------
+
+  //--------------------------------------------------------------------
+  // Update with the number of dimensions and the pixeltype
+  //--------------------------------------------------------------------
+  template <class ImageType, class PadBoundType, unsigned int dim>
+  int PadImageGenericFilter::PadLike(typename ImageType::Pointer input, PadBoundType* padLower, PadBoundType* padUpper) 
+  { 
+    if (mArgsInfo.verbose_flag)
+      std::cout << "PadLike - IN" << std::endl;
+    
+    typedef typename ImageType::SpacingType SpacingType;
+    typedef typename ImageType::RegionType RegionType;
+    typedef typename ImageType::SizeType SizeType;
+    typedef typename ImageType::IndexType IndexType;
+    typedef typename ImageType::PointType PointType;
+    typedef typename ImageType::PointValueType PointValueType;
+
+    if (mArgsInfo.verbose_flag)
+      std::cout << "Reading like image: " << mArgsInfo.like_arg << ::endl;
+    
+    typedef itk::ImageFileReader<ImageType> ImageReaderType;
+    typename ImageReaderType::Pointer reader = ImageReaderType::New();
+    reader->SetFileName(mArgsInfo.like_arg);
+    reader->Update();
+    
+    typename ImageType::Pointer like_image = reader->GetOutput();
+
+    if (mArgsInfo.verbose_flag)
+      std::cout << "Calculating padding." << std::endl;
+    
+    SpacingType spacing = input->GetSpacing(), like_spacing = like_image->GetSpacing(); 
+    if (spacing != like_spacing) {
+      std::cerr << "Like-image must have same spacing as input: " << spacing << " " << like_spacing << std::endl;
+      return ERR_NOT_SAME_SPACING;
+    }
+    
+    SizeType size = input->GetLargestPossibleRegion().GetSize(), like_size = like_image->GetLargestPossibleRegion().GetSize();
+    PointType origin = input->GetOrigin(), like_origin = like_image->GetOrigin();
+    
+    PointType lower_bound, like_lower_bound;
+    PointType upper_bound, like_upper_bound;
+    PointValueType auxl = 0, auxu = 0;
+    for (unsigned int i = 0; i < dim; i++) {
+      lower_bound[i] = origin[i];
+      like_lower_bound[i] = like_origin[i];
+      auxl = itk::Math::Round<PointValueType>(((lower_bound[i] - like_lower_bound[i])/spacing[i]));
+      
+      upper_bound[i] = (lower_bound[i] + size[i]*spacing[i]);
+      like_upper_bound[i] = (like_lower_bound[i] + like_size[i]*spacing[i]);
+      auxu = itk::Math::Round<PointValueType>(((like_upper_bound[i] - upper_bound[i])/spacing[i]));
+
+      if (auxl < 0 || auxu < 0) {
+        std::cerr << "Like-image's bounding box must be larger than input's" << std::endl;
+        return ERR_NOT_LIKE_LARGER;
+      }
+
+      padLower[i] = (PadBoundType)auxl;
+      padUpper[i] = (PadBoundType)auxu;
+    }
+    
+    if (mArgsInfo.verbose_flag)
+      std::cout << "PadLike - OUT" << std::endl;
+    return ERR_SUCCESS;
+  }
+} //end clitk
+
+#endif  //#define clitkPadImageGenericFilter_cxx
diff --git a/tools/clitkPadImageGenericFilter.h b/tools/clitkPadImageGenericFilter.h
new file mode 100644 (file)
index 0000000..3aa9318
--- /dev/null
@@ -0,0 +1,77 @@
+/*=========================================================================
+  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 CLITKPADIMAGEGENERICFILTER_H
+#define CLITKPADIMAGEGENERICFILTER_H
+
+// clitk
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+#include "clitkPadImage_ggo.h"
+
+
+//--------------------------------------------------------------------
+namespace clitk
+{
+
+  class ITK_EXPORT PadImageGenericFilter:
+    public ImageToImageGenericFilter<PadImageGenericFilter>
+  {
+  public:
+    enum
+    {
+      ERR_SUCCESS = 0,
+      ERR_NOT_SAME_SPACING = -1,
+      ERR_NOT_LIKE_LARGER = -2
+    };
+
+    //--------------------------------------------------------------------
+    PadImageGenericFilter();
+
+    //--------------------------------------------------------------------
+    typedef PadImageGenericFilter   Self;
+    typedef ImageToImageGenericFilter<PadImageGenericFilter> Superclass;
+    typedef itk::SmartPointer<Self>       Pointer;
+    typedef itk::SmartPointer<const Self> ConstPointer;
+    typedef args_info_clitkPadImage       args_info_type;
+
+    //--------------------------------------------------------------------
+    itkNewMacro(Self);
+    itkTypeMacro( PadImageGenericFilter, LightObject );
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type& a);
+
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class ImageType>
+    void UpdateWithInputImageType();
+
+  protected:
+    template<unsigned int Dim> void InitializeImageType();
+
+    template <class ImageType, class PadBoundType, unsigned int dim>
+    int PadLike(typename ImageType::Pointer input, PadBoundType* padLower, PadBoundType* padUpper);
+    
+    args_info_type mArgsInfo;
+
+  };// end class
+  //--------------------------------------------------------------------
+} // end namespace clitk
+
+#endif // #define CLITKPADIMAGEGENERICFILTER_H
index ec1529e310227620d5390e5aba827a9690530242..3198e7edbbf147c6e44d2b055b3ff872c5d6e8eb 100644 (file)
@@ -19,7 +19,7 @@ SET(vv_TOOLS
   vvToolResample
 #   vvToolExtractPatient
 #  vvToolExtractLung
-#vvToolStructureSetManager
+  vvToolStructureSetManager
   vvToolMIP
   vvToolConvert ## with dummy vvToolConvert.ui
   
@@ -93,7 +93,7 @@ SET(vv_SRCS
   vvThreadedFilter.cxx
   vvImageContour.cxx
   vvBinaryImageOverlayActor.cxx
-  #vvStructureSetActor.cxx
+  vvStructureSetActor.cxx
   vvROIActor.cxx
   vvBlendImageActor.cxx
   vvToolManager.cxx
@@ -112,7 +112,7 @@ QT4_WRAP_CPP(vv_SRCS
   vvQDicomSeriesSelector.h 
   vvSlicerManager.h
   vvThreadedFilter.h
-  #vvStructureSetActor.h
+  vvStructureSetActor.h
   vvROIActor.h
   vvToolCreatorBase.h
   )
index 1c2230f57160a8aa43e904f4e40734ed6233211a..596e6af969f9859f0520de3e3f70ab8eb61af613 100644 (file)
@@ -2200,6 +2200,7 @@ void vvMainWindow::SaveAs()
   OutputListeFormat.clear();
   if (dimension == 1) {
     OutputListeFormat.push_back(".mhd");
+    OutputListeFormat.push_back(".mha");
   }
   if (dimension == 2) {
     OutputListeFormat.push_back(".bmp");
index 53fd8d21a60f538b73b9ab9a10325360bac56360..888375eefbb2449001e80dd5300998298e421894 100644 (file)
@@ -513,20 +513,24 @@ void vvSegmentationDialog::Save()
     int dimension = mManager->GetDimension();
     if (dimension == 1) {
       OutputListeFormat.push_back(".mhd");
+      OutputListeFormat.push_back(".mha");
     }
     if (dimension == 2) {
       OutputListeFormat.push_back(".bmp");
       OutputListeFormat.push_back(".png");
       OutputListeFormat.push_back(".jpeg");
       OutputListeFormat.push_back(".tif");
+      OutputListeFormat.push_back(".mha");
       OutputListeFormat.push_back(".mhd");
       OutputListeFormat.push_back(".hdr");
       OutputListeFormat.push_back(".vox");
     } else if (dimension == 3) {
+      OutputListeFormat.push_back(".mha");
       OutputListeFormat.push_back(".mhd");
       OutputListeFormat.push_back(".hdr");
       OutputListeFormat.push_back(".vox");
     } else if (dimension == 4) {
+      OutputListeFormat.push_back(".mha");
       OutputListeFormat.push_back(".mhd");
     }
     QString Extensions = "AllFiles(*.*)";
index 151435faaf2c4d8f7f8480eaa79101029c431ba5..b4243596907338d5b1ccdff5ece3e6950a9e5a9f 100644 (file)
@@ -248,7 +248,7 @@ void vvToolStructureSetManager::OpenBinaryImage()
   mCurrentStructureSetActor = mStructureSetActorsList[index].data();
   mCurrentStructureSetIndex = index;
   // Open images
-  QString Extensions = "Images files ( *.mhd *.hdr *.his)";
+  QString Extensions = "Images files ( *.mha *.mhd *.hdr *.his)";
   Extensions += ";;All Files (*)";
   QStringList filename =
     QFileDialog::getOpenFileNames(this,tr("Open binary image"),