]> Creatis software - clitk.git/commitdiff
add SliceBySliceBuildLineSegmentAccordingToExtremaPosition
authordsarrut <dsarrut>
Mon, 28 Mar 2011 14:52:58 +0000 (14:52 +0000)
committerdsarrut <dsarrut>
Mon, 28 Mar 2011 14:52:58 +0000 (14:52 +0000)
itk/clitkSegmentationUtils.h
itk/clitkSegmentationUtils.txx

index 468f9d891a6bc0a919a5d95a8de8a249f2c3c85f..6eecad0702cc6f104f05af4b448cb3ab280b30be 100644 (file)
@@ -362,6 +362,22 @@ namespace clitk {
   IsOnTheSameLineSide(PointType C, PointType A, PointType B, PointType like);
   //--------------------------------------------------------------------
 
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  void 
+  SliceBySliceBuildLineSegmentAccordingToExtremaPosition(const ImageType * input, 
+                                                         typename ImageType::PixelType BG, 
+                                                         int sliceDimension, 
+                                                         int extremaDirection, 
+                                                         bool extremaOppositeFlag, 
+                                                         int lineDirection,
+                                                         double margin,
+                                                         std::vector<typename ImageType::PointType> & A, 
+                                                         std::vector<typename ImageType::PointType> & B);  
+  //--------------------------------------------------------------------
+
+
 }
 
 #include "clitkSegmentationUtils.txx"
index 2b5f6853229a75b05d1e3fbdf23050079cd7dd72..00f3392f17a91477f3c4bc5790da0c97f05f95a0 100644 (file)
@@ -388,7 +388,7 @@ namespace clitk {
     /*
       loop over input pixels, store the index in the fg that is max
       according to the given direction. 
-    */
+    */    
     typedef itk::ImageRegionConstIteratorWithIndex<ImageType> IteratorType;
     IteratorType iter(input, input->GetLargestPossibleRegion());
     iter.GoToBegin();
@@ -902,5 +902,60 @@ namespace clitk {
   //--------------------------------------------------------------------
 
 
+  //--------------------------------------------------------------------
+  /* Consider an input object, for each slice, find the extrema
+     position according to a given direction and build a line segment
+     passing throught this point in a given direction.  Output is a
+     vector of line (from point A to B), for each slice;
+   */
+  template<class ImageType>
+  void 
+  SliceBySliceBuildLineSegmentAccordingToExtremaPosition(const ImageType * input, 
+                                                         typename ImageType::PixelType BG, 
+                                                         int sliceDimension, 
+                                                         int extremaDirection, 
+                                                         bool extremaOppositeFlag, 
+                                                         int lineDirection,
+                                                         double margin,
+                                                         std::vector<typename ImageType::PointType> & A, 
+                                                         std::vector<typename ImageType::PointType> & B)
+  {
+    // Type of a slice
+    typedef typename itk::Image<typename ImageType::PixelType, ImageType::ImageDimension-1> SliceType;
+    
+    // Build the list of slices
+    std::vector<typename SliceType::Pointer> slices;
+    clitk::ExtractSlices<ImageType>(input, sliceDimension, slices);
+
+    // Build the list of 2D points
+    std::map<int, typename SliceType::PointType> position2D;
+    for(uint i=0; i<slices.size(); i++) {
+      typename SliceType::PointType p;
+      bool found = 
+        clitk::FindExtremaPointInAGivenDirection<SliceType>(slices[i], BG, 
+                                                            extremaDirection, extremaOppositeFlag, p);
+      if (found) {
+        position2D[i] = p;
+      }    
+    }
+    
+    // Convert 2D points in slice into 3D points
+    clitk::PointsUtils<ImageType>::Convert2DTo3DList(position2D, input, A);
+    
+    // Create additional point just right to the previous ones, on the
+    // given lineDirection, in order to create a horizontal/vertical line.
+    for(uint i=0; i<A.size(); i++) {
+      typename ImageType::PointType p = A[i];
+      p[lineDirection] += 10;
+      B.push_back(p);
+      // Margins ?
+      A[i][1] += margin;
+      B[i][1] += margin;
+    }
+
+  }
+  //--------------------------------------------------------------------
+
+
 } // end of namespace