]> Creatis software - clitk.git/blobdiff - itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / itk / clitkAddRelativePositionConstraintToLabelImageFilter.txx
index b73368f84324cb92dc60d5ed6530ded8791e86fc..a3759f49fa2f69606401d0d5289faaf96c70f3d3 100644 (file)
@@ -63,6 +63,9 @@ AddRelativePositionConstraintToLabelImageFilter():
   VerboseStepFlagOff();
   WriteStepFlagOff();
   FuzzyMapOnlyFlagOff();
+  FastFlagOff();
+  SetRadius(2.0);
+  SetK1(vcl_acos(-1.0)/2);
 }
 //--------------------------------------------------------------------
 
@@ -138,6 +141,8 @@ AddOrientationTypeString(std::string t)
   if (t == "NotSupTo") { AddOrientationType(SupTo); InverseOrientationFlagOn(); return; }
   if (t == "NotInfTo") { AddOrientationType(InfTo); InverseOrientationFlagOn(); return; }
 
+  if (t == "Angle") return;
+
   clitkExceptionMacro("Error, you must provide LeftTo,RightTo or AntTo,PostTo or SupTo,InfTo (or NotLeftTo, NotRightTo etc) but you give " << t);
 }
 //--------------------------------------------------------------------
@@ -177,15 +182,27 @@ GenerateInputRequestedRegion()
 template <class ImageType>
 void 
 clitk::AddRelativePositionConstraintToLabelImageFilter<ImageType>::
-AddAngles(double a, double b) 
+AddAnglesInRad(double a, double b) 
 {
-  AddOrientationTypeString("Angle");
+  m_OrientationTypeString.push_back("Angle");
+  m_OrientationType.push_back(Angle);
   m_Angle1.push_back(a);
   m_Angle2.push_back(b);
 }
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::AddRelativePositionConstraintToLabelImageFilter<ImageType>::
+AddAnglesInDeg(double a, double b) 
+{
+  AddAnglesInRad(clitk::deg2rad(a), clitk::deg2rad(b));
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 template <class ImageType>
 void 
@@ -342,14 +359,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);
@@ -366,13 +383,14 @@ GenerateData()
   for(int i=0; i<GetNumberOfAngles(); i++) {
     // Compute fuzzy map
     relPosFilter = RelPosFilterType::New();
+    relPosFilter->SetFast(GetFastFlag());
+    relPosFilter->SetRadius(GetRadius());
     relPosFilter->SetInput(working_image);
     relPosFilter->SetAlpha1(m_Angle1[i]); // xy plane
     relPosFilter->SetAlpha2(m_Angle2[i]);
-    relPosFilter->SetK1(M_PI/2.0); // Opening parameter, default = pi/2
-    relPosFilter->SetFast(true);
-    relPosFilter->SetRadius(1); // seems sufficient in this case
+    relPosFilter->SetK1(GetK1());// M_PI/2.0); // Opening parameter, default = pi/2
     // relPosFilter->SetVerboseProgress(true);
+
     relPosFilter->Update();
     relPos = relPosFilter->GetOutput();
 
@@ -412,6 +430,44 @@ GenerateData()
 
   relPos = m_FuzzyMap;
   StopCurrentStep<FloatImageType>(relPos);
+  if (GetFuzzyMapOnlyFlag()) {
+    // If the spacing is used, recompute fuzzy map with the input size/spacing
+    if (m_IntermediateSpacingFlag) {
+      StartNewStep("Resample FuzzyMap to come back to the same sampling than input");
+      typedef clitk::ResampleImageWithOptionsFilter<FloatImageType> ResampleFilterType;
+      typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New();
+      resampleFilter->SetDefaultPixelValue(0.0); //Default fuzzymap value FIXME
+      resampleFilter->SetInput(relPos);
+      resampleFilter->SetOutputSpacing(input->GetSpacing());
+      resampleFilter->SetGaussianFilteringEnabled(false);
+      resampleFilter->Update();
+      relPos = m_FuzzyMap = resampleFilter->GetOutput();
+      StopCurrentStep<FloatImageType>(relPos);
+
+      // Need to put exactly the same size
+      if (relPos->GetLargestPossibleRegion() != input->GetLargestPossibleRegion()) {
+        StartNewStep("Pad to get the same size than input");
+        typename FloatImageType::Pointer temp = FloatImageType::New();
+        temp->CopyInformation(input);
+        temp->SetRegions(input->GetLargestPossibleRegion()); // Do not forget !!
+        temp->Allocate();
+        temp->FillBuffer(0.0); // Default fuzzymap value FIXME
+        typename PasteFloatFilterType::Pointer padFilter2 = PasteFloatFilterType::New();
+        padFilter2->SetSourceImage(relPos);
+        padFilter2->SetDestinationImage(temp);
+        padFilter2->SetDestinationIndex(input->GetLargestPossibleRegion().GetIndex());
+        padFilter2->SetSourceRegion(relPos->GetLargestPossibleRegion());
+        padFilter2->Update();
+        relPos = padFilter2->GetOutput();
+        StopCurrentStep<FloatImageType>(relPos);
+        m_FuzzyMap = relPos;
+      }     
+    }
+    else {
+      StopCurrentStep<FloatImageType>(relPos);
+    }
+    return;
+  }
                
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------