]> Creatis software - clitk.git/blobdiff - itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx
remove debug, new orientation option
[clitk.git] / itk / clitkAddRelativePositionConstraintToLabelImageFilter.txx
index 2b159bf9e9a98874f2a5f167ad41cdd5a27850e9..83993831fa4f2f86606b89025378ea27b1bed884 100644 (file)
@@ -49,7 +49,8 @@ AddRelativePositionConstraintToLabelImageFilter():
   SetOrientationType(LeftTo);
   ResampleBeforeRelativePositionFilterOn();
   SetIntermediateSpacing(10);
-  AutoCropOn();
+  AutoCropFlagOn();
+  NotFlagOff();
 }
 //--------------------------------------------------------------------
 
@@ -78,6 +79,23 @@ SetInputObject(const ImageType * image)
 //--------------------------------------------------------------------
   
 
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::AddRelativePositionConstraintToLabelImageFilter<ImageType>::
+SetOrientationTypeString(std::string t) 
+{
+  SetOrientationType(Angle);
+  if (t[0] == 'L') SetOrientationType(LeftTo);
+  if (t[0] == 'R') SetOrientationType(RightTo);
+  if (t[0] == 'A') SetOrientationType(AntTo);
+  if (t[0] == 'P') SetOrientationType(PostTo);
+  if (t[0] == 'S') SetOrientationType(SupTo);
+  if (t[0] == 'I') SetOrientationType(InfTo);
+}
+//--------------------------------------------------------------------
+  
+
 //--------------------------------------------------------------------
 template <class ImageType>
 void 
@@ -166,6 +184,18 @@ void
 clitk::AddRelativePositionConstraintToLabelImageFilter<ImageType>::
 GenerateData() 
 {
+  // Print Option
+  /*
+    DD(GetFuzzyThreshold());
+    DD((int)GetBackgroundValue());
+    DD((int)GetObjectBackgroundValue());
+    DD(GetOrientationType());
+    DD(GetResampleBeforeRelativePositionFilter());
+    DD(GetIntermediateSpacing());
+    DD(GetAutoCropFlag());
+    DD(GetNotFlag());
+  */
+
   // Get input pointer
   input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
   object = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(1));
@@ -308,22 +338,26 @@ GenerateData()
     // resampleFilter->SetVerboseOptions(true);
     resampleFilter->Update();
     working_image = resampleFilter->GetOutput();
-  StopCurrentStep<ImageType>(working_image);
+    StopCurrentStep<ImageType>(working_image);
   }
 
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   // Pre Step 6: pad if not the same size : it can occur when downsample and upsample
+  // DD(working_image->GetLargestPossibleRegion());
+  // DD(input->GetLargestPossibleRegion());
+  //if (!HaveSameSizeAndSpacing(working_image, input)) {
   if (working_image->GetLargestPossibleRegion() != input->GetLargestPossibleRegion()) {
     StartNewStep("Pad to get the same size than input");
     typename ImageType::Pointer temp = ImageType::New();
     temp->CopyInformation(input);
     temp->SetRegions(input->GetLargestPossibleRegion()); // Do not forget !!
     temp->Allocate();
-    temp->FillBuffer(m_BackgroundValue);
-    typename PadFilterType::Pointer padFilter2 = PadFilterType::New(); // if yes : redo relpos
+    temp->FillBuffer(m_BackgroundValue); 
+    typename PadFilterType::Pointer padFilter2 = PadFilterType::New();
     padFilter2->SetSourceImage(working_image);
     padFilter2->SetDestinationImage(temp);
+    // DD(input->GetLargestPossibleRegion().GetIndex());
     padFilter2->SetDestinationIndex(input->GetLargestPossibleRegion().GetIndex());
     padFilter2->SetSourceRegion(working_image->GetLargestPossibleRegion());
     padFilter2->Update();
@@ -340,20 +374,20 @@ GenerateData()
   StartNewStep("Combine with initial input (boolean And)");
   typedef clitk::BooleanOperatorLabelImageFilter<ImageType> BoolFilterType;
   typename BoolFilterType::Pointer combineFilter = BoolFilterType::New();
-  writeImage<ImageType>(input, "i.mhd");
-  writeImage<ImageType>(working_image, "w.mhd");
   combineFilter->SetBackgroundValue(m_BackgroundValue);
   combineFilter->SetBackgroundValue1(m_BackgroundValue);
   combineFilter->SetBackgroundValue2(m_BackgroundValue);
   combineFilter->SetForegroundValue(m_BackgroundValue+1);
   combineFilter->SetInput1(input);
   combineFilter->SetInput2(working_image);
-  combineFilter->SetOperationType(BoolFilterType::And);
+  if (GetNotFlag())
+    combineFilter->SetOperationType(BoolFilterType::AndNot);
+  else
+    combineFilter->SetOperationType(BoolFilterType::And);
   combineFilter->InPlaceOn();
   combineFilter->Update(); 
   working_image = combineFilter->GetOutput();
-  // writeImage<ImageType>(working_image, "res.mhd");
+
   combineFilter = BoolFilterType::New();
   combineFilter->SetInput1(working_image);
   combineFilter->SetInput2(object);
@@ -367,7 +401,7 @@ GenerateData()
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   // Step 7: autocrop
-  if (GetAutoCrop()) {
+  if (GetAutoCropFlag()) {
     StartNewStep("Final AutoCrop");
     typedef clitk::AutoCropFilter<ImageType> CropFilterType;
     typename CropFilterType::Pointer cropFilter = CropFilterType::New();
@@ -383,6 +417,7 @@ GenerateData()
   
   // Final Step -> set output
   this->SetNthOutput(0, working_image);
+  //  this->GraftOutput(working_image);
   return;
 }
 //--------------------------------------------------------------------