]> Creatis software - clitk.git/blobdiff - itk/clitkSliceBySliceRelativePositionFilter.txx
itkv4 Replace ITK_TYPENAME by typename
[clitk.git] / itk / clitkSliceBySliceRelativePositionFilter.txx
index e3801024bf389f93a0188ae367afb6ae168107a7..f2452d872ad2258528c20301f0515f606648e323 100644 (file)
@@ -32,7 +32,15 @@ SliceBySliceRelativePositionFilter():
 {
   SetDirection(2);
   UniqueConnectedComponentBySliceOff();
-  SetIgnoreEmptySliceObject(false);
+  SetIgnoreEmptySliceObjectFlag(false);
+  UseASingleObjectConnectedComponentBySliceFlagOn();
+  this->VerboseStepFlagOff();
+  this->WriteStepFlagOff();
+  this->SetCombineWithOrFlag(false);
+  CCLSelectionFlagOff();
+  SetCCLSelectionDimension(0);
+  SetCCLSelectionDirection(1);
+  CCLSelectionIgnoreSingleCCLFlagOff();
 }
 //--------------------------------------------------------------------
 
@@ -70,7 +78,7 @@ PrintOptions()
   DD(this->GetDirection());
   DD((int)this->GetObjectBackgroundValue());
   DDV(this->GetOrientationTypeString(), (uint)this->GetNumberOfAngles());
-  DD(this->GetResampleBeforeRelativePositionFilter());
+  DD(this->GetIntermediateSpacingFlag());
   DD(this->GetIntermediateSpacing());
   DD(this->GetFuzzyThreshold());
   DD(this->GetUniqueConnectedComponentBySlice());
@@ -172,18 +180,56 @@ GenerateOutputInformation()
   // Perform slice by slice relative position
   this->StartNewStep("Perform slice by slice relative position");
   for(unsigned int i=0; i<mInputSlices.size(); i++) {
-    // Select main CC in each object slice (required ?)
+    
+    // Count the number of CCL (allow to ignore empty slice)
     int nb=0;
     mObjectSlices[i] = LabelizeAndCountNumberOfObjects<SliceType>(mObjectSlices[i], 0, true, 1, nb);
-    if ((!GetIgnoreEmptySliceObject()) || (nb!=0)) {
-      mObjectSlices[i] = KeepLabels<SliceType>(mObjectSlices[i], 0, 1, 1, 1, true);
+    if ((!GetIgnoreEmptySliceObjectFlag()) || (nb!=0)) {
+
+      // Select or not a single CCL ?
+      if (GetUseASingleObjectConnectedComponentBySliceFlag()) {
+        mObjectSlices[i] = KeepLabels<SliceType>(mObjectSlices[i], 0, 1, 1, 1, true);
+      }
+
+      // Select a single according to a position if more than one CCL
+      if (GetCCLSelectionFlag()) {
+        // if several CCL, choose the most extrema according a direction, 
+        // if not -> should we consider this slice ? 
+        if (nb<2) {
+          if (GetCCLSelectionIgnoreSingleCCLFlag()) {
+            mObjectSlices[i] = SetBackground<SliceType, SliceType>(mObjectSlices[i], mObjectSlices[i], 
+                                                                   1, this->GetBackgroundValue(), 
+                                                                   true);
+          }
+        }
+        int dim = GetCCLSelectionDimension();
+        int direction = GetCCLSelectionDirection();
+        std::vector<typename SliceType::PointType> centroids;
+        ComputeCentroids<SliceType>(mObjectSlices[i], this->GetBackgroundValue(), centroids);
+        uint index=1;
+        for(uint j=1; j<centroids.size(); j++) {
+          if (direction == 1) {
+            if (centroids[j][dim] > centroids[index][dim]) index = j;
+          }
+          else {
+            if (centroids[j][dim] < centroids[index][dim]) index = j;
+          }
+        }
+        for(uint v=1; v<centroids.size(); v++) {
+          if (v != index) {
+            mObjectSlices[i] = SetBackground<SliceType, SliceType>(mObjectSlices[i], mObjectSlices[i], 
+                                                                   (char)v, this->GetBackgroundValue(), 
+                                                                   true);
+          }
+        }
+      } // end GetCCLSelectionFlag = true
 
       // Relative position
       typedef clitk::AddRelativePositionConstraintToLabelImageFilter<SliceType> RelPosFilterType;
       typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
+
       relPosFilter->VerboseStepFlagOff();
       relPosFilter->WriteStepFlagOff();
-      relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
       relPosFilter->SetBackgroundValue(this->GetBackgroundValue());
       relPosFilter->SetInput(mInputSlices[i]); 
       relPosFilter->SetInputObject(mObjectSlices[i]); 
@@ -194,7 +240,7 @@ GenerateOutputInformation()
       relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag());
       //relPosFilter->SetOrientationType(this->GetOrientationType());
       relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing());
-      relPosFilter->SetResampleBeforeRelativePositionFilter(this->GetResampleBeforeRelativePositionFilter());
+      relPosFilter->SetIntermediateSpacingFlag(this->GetIntermediateSpacingFlag());
       relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold());
       relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
       relPosFilter->SetCombineWithOrFlag(this->GetCombineWithOrFlag()); 
@@ -207,6 +253,15 @@ GenerateOutputInformation()
         mInputSlices[i] = KeepLabels<SliceType>(mInputSlices[i], 0, 1, 1, 1, true);
       }
 
+      /*
+      // Select unique CC according to the most in a given direction
+      if (GetUniqueConnectedComponentBySliceAccordingToADirection()) {
+        int nb;
+        mInputSlices[i] = LabelizeAndCountNumberOfObjects<SliceType>(mInputSlices[i], 0, true, 1, nb);
+        std::vector<typename ImageType::PointType> & centroids;
+        ComputeCentroids
+        }
+      */
     }
   }