]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorDavid Sarrut <david.sarrut@gmail.com>
Thu, 28 Jun 2012 05:36:48 +0000 (07:36 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Thu, 28 Jun 2012 05:36:48 +0000 (07:36 +0200)
15 files changed:
itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx
itk/clitkLabelImageOverlapMeasureFilter.txx
itk/clitkSegmentationUtils.h
itk/clitkSegmentationUtils.txx
itk/clitkSliceBySliceRelativePositionFilter.h
itk/clitkSliceBySliceRelativePositionFilter.txx
segmentation/clitkAnatomicalFeatureDatabase.h
segmentation/clitkAnatomicalFeatureDatabase.txx
segmentation/clitkFilterWithAnatomicalFeatureDatabaseManagement.cxx
segmentation/clitkFilterWithAnatomicalFeatureDatabaseManagement.h
segmentation/clitkRelativePositionList.txx
segmentation/clitkStructuresExtractionFilter.txx
vv/vvImageContour.cxx
vv/vvROIActor.cxx
vv/vvToolBinarize.cxx

index 6d536186fbf5084da969d0750e05a4cc8cd3c8fb..ddcad0e16c445959381f5b197d7b94cce3f35ece 100644 (file)
@@ -358,14 +358,14 @@ GenerateData()
   //--------------------------------------------------------------------
   // Step 1 : resample
   if (m_IntermediateSpacingFlag) {
-    StartNewStep("Resample object to intermediate spacing");  
+    StartNewStep("Resample object to intermediate spacing (" + toString(m_IntermediateSpacing) + ")");  
     typedef clitk::ResampleImageWithOptionsFilter<ImageType> ResampleFilterType;
     typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New();
     resampleFilter->SetInput(working_image);
     resampleFilter->SetDefaultPixelValue(0);
     resampleFilter->SetOutputIsoSpacing(m_IntermediateSpacing);
     resampleFilter->SetGaussianFilteringEnabled(false);
-    //    resampleFilter->SetVerboseOptions(true);
+    //resampleFilter->SetVerboseOptions(true);
     resampleFilter->Update();
     working_image = resampleFilter->GetOutput();
     StopCurrentStep<ImageType>(working_image);
index f4aabfc673647d28e66d25c3a05c81eb1e75da9d..57516bb41634db8996e3822aa0d91ad748b2c110 100644 (file)
@@ -51,7 +51,6 @@ void
 clitk::LabelImageOverlapMeasureFilter<ImageType>::
 GenerateInputRequestedRegion() 
 {
-  // DD("GenerateInputRequestedRegion");
   // Call default
   itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
   // Get input pointers and set requested region to common region
@@ -87,6 +86,8 @@ GenerateData()
   // Resize like the union
   ImagePointer input1 = clitk::ResizeImageLike<ImageType>(m_Input1, bbo, GetBackgroundValue());
   ImagePointer input2 = clitk::ResizeImageLike<ImageType>(m_Input2, bbo, GetBackgroundValue());
+  //DD(input1->GetLargestPossibleRegion());
+  //DD(input2->GetLargestPossibleRegion());
 
   // Compute overlap image
   ImagePointer image_union = clitk::Clone<ImageType>(input1);
@@ -94,8 +95,8 @@ GenerateData()
   clitk::Or<ImageType>(image_union, input2, GetBackgroundValue());
   clitk::And<ImageType>(image_intersection, input2, GetBackgroundValue());
   
-  // writeImage<ImageType>(image_union, "union.mha");
-  // writeImage<ImageType>(image_intersection, "intersection.mha");
+  //writeImage<ImageType>(image_union, "union.mha");
+  //writeImage<ImageType>(image_intersection, "intersection.mha");
   
   // Compute size
   typedef itk::LabelStatisticsImageFilter<ImageType, ImageType> StatFilterType;
@@ -120,7 +121,8 @@ GenerateData()
   statFilter->Update();
   int in2 = statFilter->GetCount(GetLabel1());
 
-  std::cout << in1 << " " << in2 << " " << inter << " " << u << " " << 2.0*(double)inter/(double)(in1+in2) << std::endl;
+  std::cout << in1 << " " << in2 << " " << inter << " " << u << " " 
+            << 2.0*(double)inter/(double)(in1+in2) << std::endl;
 }
 //--------------------------------------------------------------------
 
index 6972d154ab8f4436a672247090da66efff9eb331..6389ad135c4c3202701b3eaed5c50729d082d365 100644 (file)
@@ -28,6 +28,7 @@
 // itk
 #include <itkBoundingBox.h>
 #include <itkJoinSeriesImageFilter.h>
+#include <itkChangeInformationImageFilter.h>
 
 /*
   According to 
@@ -486,7 +487,12 @@ namespace clitk {
                       typename ImageType::PixelType & BG);
   //--------------------------------------------------------------------
   
-
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  RemoveNegativeIndexFromRegion(ImageType * input);
+  //--------------------------------------------------------------------
+  
 
 } // end clitk namespace
 
index 6171030d9109807f0c2d2a9cf80782087c7c8279..b7a5de50693c5f078b19ea2245076f3c384c4657 100644 (file)
@@ -1392,6 +1392,30 @@ namespace clitk {
   //--------------------------------------------------------------------
      
 
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  RemoveNegativeIndexFromRegion(ImageType * input) {
+    typedef itk::ChangeInformationImageFilter< ImageType > InfoFilterType; 
+    typename InfoFilterType::Pointer indexChangeFilter = InfoFilterType::New(); 
+    indexChangeFilter->ChangeRegionOn(); 
+    // The next line is commented because not exist in itk 3
+    // typename InfoFilterType::OutputImageOffsetValueType indexShift[3];
+    long indexShift[3];
+    typename ImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex();
+    for(uint i=0;i<ImageType::ImageDimension; i++)
+      indexShift[i] = (index[i]<0 ? -index[i]:0);
+    typename ImageType::PointType origin;
+    for(uint i=0;i<ImageType::ImageDimension; i++)
+    origin[i] = input->GetOrigin()[i] - indexShift[i]*input->GetSpacing()[i];
+    indexChangeFilter->SetOutputOffset( indexShift ); 
+    indexChangeFilter->SetInput(input); 
+    indexChangeFilter->SetOutputOrigin(origin);
+    indexChangeFilter->ChangeOriginOn();
+    indexChangeFilter->Update();
+    return indexChangeFilter->GetOutput();
+  }
+  //--------------------------------------------------------------------
 
 
 } // end of namespace
index 90a1b2567e8cb4779bd8d9f21bfeeed15478b09e..ba59467f5ece21cc3b7538ba47ce40c19153297a 100644 (file)
@@ -98,6 +98,10 @@ namespace clitk {
     itkSetMacro(ObjectCCLSelectionIgnoreSingleCCLFlag, bool);
     itkBooleanMacro(ObjectCCLSelectionIgnoreSingleCCLFlag);
 
+    itkGetConstMacro(VerboseSlicesFlag, bool);
+    itkSetMacro(VerboseSlicesFlag, bool);
+    itkBooleanMacro(VerboseSlicesFlag);
+
   protected:
     SliceBySliceRelativePositionFilter();
     virtual ~SliceBySliceRelativePositionFilter() {}
@@ -118,6 +122,7 @@ namespace clitk {
     int          m_ObjectCCLSelectionDimension;
     int          m_ObjectCCLSelectionDirection;
     bool         m_ObjectCCLSelectionIgnoreSingleCCLFlag;
+    bool         m_VerboseSlicesFlag;
 
   private:
     SliceBySliceRelativePositionFilter(const Self&); //purposely not implemented
index eff331daa9e6d99269629f4ba6f112aca2fcec96..db3c677c0e8701c2a424676fcd72117e26576b12 100644 (file)
@@ -42,6 +42,7 @@ SliceBySliceRelativePositionFilter():
   SetObjectCCLSelectionDimension(0);
   SetObjectCCLSelectionDirection(1);
   ObjectCCLSelectionIgnoreSingleCCLFlagOff();
+  VerboseSlicesFlagOff();
 }
 //--------------------------------------------------------------------
 
@@ -182,6 +183,11 @@ GenerateOutputInformation()
                                                          m_working_input, 
                                                          this->GetObjectBackgroundValue());
     
+    // Index can be negative in some cases, and lead to problem with
+    // some filter. So we correct it.
+    m_working_input = clitk::RemoveNegativeIndexFromRegion<ImageType>(m_working_input);
+    m_working_object = clitk::RemoveNegativeIndexFromRegion<ImageType>(m_working_object);
+
     // End
     this->template StopCurrentStep<ImageType>(m_working_input);  
   }
@@ -286,6 +292,10 @@ GenerateOutputInformation()
         typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
         typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
         relPosFilter->VerboseStepFlagOff();
+        if (GetVerboseSlicesFlag()) {
+          std::cout << "Slice " << i << std::endl;
+          relPosFilter->VerboseStepFlagOn();
+        }
         relPosFilter->WriteStepFlagOff();
         // relPosFilter->VerboseMemoryFlagOn();
         relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()+"-"+toString(i));        
index 59e8decc07e2008c71996d3f7d3c237495035518..c1ed4fd17ea1c4407ac272e71619dcd28fee293c 100644 (file)
@@ -65,11 +65,17 @@ namespace clitk {
 
     // Set Get image
     void SetImageFilename(TagType tag, std::string f);
-    template<class ImageType>
+    
+    template<class ImageType> 
     typename ImageType::Pointer GetImage(TagType tag, bool reload=false);
-    template<class ImageType>
+    
+    template<class ImageType> 
+    bool CheckImage(TagType tag); 
+    
+    template<class ImageType> 
     void  SetImage(TagType tag, std::string f, typename ImageType::Pointer image, bool write=false);
-    template<class ImageType>
+    
+    template<class ImageType> 
     void ReleaseImage(TagType tag);
     
     // Set Get Double
index c155d44084c2581a6940e03069fee49f7bc9de03..72e9dcdd06b9293742aa70dac935eb9d58ff4421 100644 (file)
@@ -47,6 +47,39 @@ GetImage(std::string tag, bool reload)
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+template<class ImageType>
+bool AnatomicalFeatureDatabase::
+CheckImage(std::string tag)
+{
+  if (m_MapOfTag.find(tag) == m_MapOfTag.end()) {
+    return false;
+  }
+  else {
+    typename ImageType::Pointer image;
+    if (m_MapOfImage[tag]) {
+      image = static_cast<ImageType *>(m_MapOfImage[tag]);
+    }
+    else {
+      std::string s = m_MapOfTag[tag];
+      // Read the file
+      std::string n = GetPath()+"/"+s;
+      //      image = readImage<ImageType>();
+      typedef itk::ImageFileReader<ImageType> ReaderType;
+      typename ReaderType::Pointer reader = ReaderType::New();
+      reader->SetFileName(n.c_str());
+      try {
+        reader->Update();
+      } catch(itk::ExceptionObject & err) {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 template<class ImageType>
 void AnatomicalFeatureDatabase::
index 6db7c4b934dee61ba449fc65164c4838159a09c8..9732057817f0dab2de41c59a2a49c96810c62c8d 100644 (file)
@@ -26,6 +26,7 @@ FilterWithAnatomicalFeatureDatabaseManagement()
   m_AFDB = NULL; 
   SetAFDBFilename("default.afdb");
   SetAFDBPath("./");
+  DisplayUsedStructuresOnlyFlagOff();
 }
 //--------------------------------------------------------------------
 
@@ -63,3 +64,25 @@ clitk::AnatomicalFeatureDatabase::Pointer clitk::FilterWithAnatomicalFeatureData
   return m_AFDB;
 }
 //--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void clitk::FilterWithAnatomicalFeatureDatabaseManagement::
+AddUsedStructures(std::string station, std::string structure)
+{
+  if (!GetDisplayUsedStructuresOnlyFlag()) return;
+  std::cout << station << "\t" << structure;
+  bool founded = true;
+  bool tag = GetAFDB()->TagExist(structure);
+  if (tag) {
+    typedef typename itk::Image<uchar, 3> ImageType;
+    founded = GetAFDB()->CheckImage<ImageType>(structure);
+    if (!founded) { 
+      std::cout << " \t Image not exist in DB ";
+      std::cout << "<" << GetAFDB()->GetTagValue(structure) << "> ";
+    }
+  }
+  if (!tag) std::cout << " \t Tag not found in DB";
+  std::cout << std::endl;
+}
+//--------------------------------------------------------------------
index a1f9f29f54d35e023c3c5d988e0193d6524894a4..a44405b7a1ff677db47d7f4745aa72ce2b9fe0fb 100644 (file)
@@ -41,24 +41,15 @@ namespace clitk {
     // Run-time type information (and related methods)
     itkTypeMacro(FilterWithAnatomicalFeatureDatabaseManagement, Object);
 
-    // Set/Get filename 
-    // itkBooleanMacro(AFDBFilenameGivenFlag);
-    // itkSetMacro(AFDBFilenameGivenFlag, bool);
-    // itkGetConstMacro(AFDBFilenameGivenFlag, bool);
-    // GGO_DefineOption_Flag(afdb, SetAFDBFilenameGivenFlag);
-
-    // itkBooleanMacro(AFDBPathGivenFlag);
-    // itkSetMacro(AFDBPathGivenFlag, bool);
-    // itkGetConstMacro(AFDBPathGivenFlag, bool);
-    // GGO_DefineOption_Flag(afdb_path, SetAFDBPathGivenFlag);
-
     itkSetMacro(AFDBFilename, std::string);
     itkGetConstMacro(AFDBFilename, std::string);
-    // GGO_DefineOption_WithTest(afdb, SetAFDBFilename, std::string, AFDBFilenameGivenFlag);
 
     itkSetMacro(AFDBPath, std::string);
     itkGetConstMacro(AFDBPath, std::string);
-    // GGO_DefineOption_WithTest(afdb_path, SetAFDBPath, std::string, AFDBPathGivenFlag);
+
+    itkGetConstMacro(DisplayUsedStructuresOnlyFlag, bool);
+    itkSetMacro(DisplayUsedStructuresOnlyFlag, bool);
+    itkBooleanMacro(DisplayUsedStructuresOnlyFlag);
 
     void WriteAFDB();
     void LoadAFDB();
@@ -71,11 +62,14 @@ namespace clitk {
     virtual ~FilterWithAnatomicalFeatureDatabaseManagement() {}    
     
     std::string m_AFDBFilename;
-    // bool m_AFDBFilenameGivenFlag;
     std::string m_AFDBPath;
-    // bool m_AFDBPathGivenFlag;
     clitk::AnatomicalFeatureDatabase::Pointer m_AFDB;
 
+    // For debug: display used structures but do not perform
+    // segmentation
+    bool m_DisplayUsedStructuresOnlyFlag;
+    void AddUsedStructures(std::string station, std::string structure);    
+
   private:
     FilterWithAnatomicalFeatureDatabaseManagement(const Self&); //purposely not implemented
     void operator=(const Self&); //purposely not implemented
index 39cc272cd1156253b4578efa45b30f1a0789d0b0..4f4702b981c809b6705f1102bd1b4cebc32ac95d 100644 (file)
 //--------------------------------------------------------------------
 template <class TImageType>
 clitk::RelativePositionList<TImageType>::
-RelativePositionList() {
+RelativePositionList():  
+  clitk::FilterBase(),
+  clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+  itk::ImageToImageFilter<TImageType, TImageType>()
+{
   ComputeOverlapFlagOff();
 }
 //--------------------------------------------------------------------
@@ -154,10 +158,20 @@ GenerateOutputInformation() {
 
   // Get input
   m_working_input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  std::string s = GetInputName();
+
+  // Debug
+  if (GetDisplayUsedStructuresOnlyFlag()) {
+    for(uint i=0; i<mArgsInfoList.size(); i++) {
+      // Check if we only want to display structure name
+      AddUsedStructures(s, mArgsInfoList[i].object_arg);
+    }
+    return;
+  }
 
   // Loop on RelativePositionList of operations
-  std::string s = GetInputName();
   for(uint i=0; i<mArgsInfoList.size(); i++) {
+
     // clitk::PrintMemory(true, "Start"); 
     std::string text = "["+s+"] limits ";
     if (mArgsInfoList[i].orientation_given) text += std::string(mArgsInfoList[i].orientation_arg[0])+" ";
@@ -271,3 +285,5 @@ SetFilterOptions(typename RelPosFilterType::Pointer filter, ArgsInfoType & optio
   filter->SetAutoCropFlag(!options.noAutoCrop_flag); 
 }
 //--------------------------------------------------------------------
+
+
index 9559d4c2702ab9fe7cbff3cf21d632460a6f0aff..d78586169849f9288b087fab88e2bb3f07f6071e 100644 (file)
@@ -52,6 +52,7 @@ ApplyRelativePositionList(std::string name, MaskImageType * input, bool overlap)
   // Create all RelativePositionList
   for(unsigned int i=0; i<mListOfRelativePositionListFilename.size(); i++) {
     RelPosListPointer rpl = RelPosListType::New();
+    rpl->SetDisplayUsedStructuresOnlyFlag(this->GetDisplayUsedStructuresOnlyFlag());
     rpl->SetAFDB(GetAFDB());
     rpl->Read(mListOfRelativePositionListFilename[i]);
     std::string s = rpl->GetInputName();
@@ -71,9 +72,9 @@ ApplyRelativePositionList(std::string name, MaskImageType * input, bool overlap)
     relpos->SetCurrentStepNumber(GetCurrentStepNumber());
     relpos->SetWriteStepFlag(GetWriteStepFlag());
     relpos->SetInput(input);
-    if (overlap) {
-      std::string n = name.substr(8,2);
-      MaskImagePointer ref = this->GetAFDB()->template GetImage <MaskImageType>("S"+n+"_Ref");
+    if (!this->GetDisplayUsedStructuresOnlyFlag() && overlap) {
+      std::string n = name.substr(8,3);
+      MaskImagePointer ref = this->GetAFDB()->template GetImage <MaskImageType>(n+"_Ref");
       relpos->SetReferenceImageForOverlapMeasure(ref);
     }
     relpos->Update();
index 813624892fbe72bd12b8cb1415ccc4609cfa5af4..aa7b8d7c852e37dfe0c757faa6c136a256840c29 100644 (file)
@@ -154,10 +154,9 @@ void vvImageContour::ShowActors() {
 //------------------------------------------------------------------------------
 void vvImageContour::SetDepth(double d) 
 { 
-  mDepth = d+0.5; // FIXME to not be equal to overlay 
   // Move the actor to be visible
   double position[3] = {0, 0, 0};
- int orientation = ComputeCurrentOrientation();
 int orientation = ComputeCurrentOrientation();
   position[orientation] = -mDepth;
 
   for(unsigned int i=0; i<mSquaresActorList.size(); i++)
index 9243431949b3b822082a48dca9a26476552f1e1c..88ce28160aff5aafcae5b6c4e33561c1da3caf4d 100644 (file)
@@ -169,7 +169,7 @@ void vvROIActor::Initialize(double depth, bool IsVisible) {
       mImageContour[i]->SetColor(mContourColor[0], mContourColor[1], mContourColor[2]);
       mImageContour[i]->SetLineWidth(mContourWidth);
       mImageContour[i]->SetPreserveMemoryModeEnabled(true);
-      mImageContour[i]->SetDepth(mDepth);
+      mImageContour[i]->SetDepth(mDepth+0.5);
       mImageContour[i]->HideActors();
       
       mOverlayActors.push_back(vvBinaryImageOverlayActor::New());
@@ -207,7 +207,7 @@ void vvROIActor::SetDepth(double d)
   if (!mSlicerManager) return;
   for(int i=0; i<mSlicerManager->GetNumberOfSlicers(); i++) {  
     mOverlayActors[i]->SetDepth(d);
-    mImageContour[i]->SetDepth(d);
+    mImageContour[i]->SetDepth(d+0.5);
   }
   Update(true);
 }
index fa22daad122e54bb2337d1feb1700f40bbd152e0..9859d01adcc101812cd644e4e15b966fbc657f9c 100644 (file)
@@ -214,9 +214,11 @@ void vvToolBinarize::InputIsSelected(vvSlicerManager * m)
     mImageContour.push_back(vvImageContour::New());
     mImageContour[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
     mImageContour[i]->SetColor(1.0, 0.0, 0.0);
+    mImageContour[i]->SetDepth(100); // to be in front of (whe used with ROI tool)
     mImageContourLower.push_back(vvImageContour::New());
     mImageContourLower[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
     mImageContourLower[i]->SetColor(0.0, 0.0, 1.0);
+    mImageContourLower[i]->SetDepth(100); // to be in front of (whe used with ROI tool)
   }
   valueChangedT1(mThresholdSlider1->GetValue());