]> Creatis software - clitk.git/blobdiff - segmentation/clitkExtractLymphStationsFilter.txx
correct bug when reload
[clitk.git] / segmentation / clitkExtractLymphStationsFilter.txx
index 7b2fd2ff91346aa16e10e96de0844af056ff999a..ea514a6d643924af6834d3c3a921b82b98411d05 100644 (file)
@@ -52,6 +52,15 @@ ExtractLymphStationsFilter():
   SetBackgroundValue(0);
   SetForegroundValue(1);
 
+  // Station 8
+  SetDistanceMaxToAnteriorPartOfTheSpine(10);
+  MaskImagePointType p;
+  p[0] = 15; p[1] = 2; p[2] = 1;
+  SetEsophagusDiltationForAnt(p);
+  p[0] = 5; p[1] = 10; p[2] = 1;
+  SetEsophagusDiltationForRight(p);
+  SetFuzzyThresholdForS8(0.5);
+
   // Station 7
   SetFuzzyThreshold(0.5);
   SetStation7Filename("station7.mhd");
@@ -59,17 +68,6 @@ ExtractLymphStationsFilter():
 //--------------------------------------------------------------------
 
 
-//--------------------------------------------------------------------
-template <class TImageType>
-template <class ArgsInfoType>
-void 
-clitk::ExtractLymphStationsFilter<TImageType>::
-SetArgsInfo(ArgsInfoType & argsinfo) {
-  DD("SetArgsInfo");
-}
-//--------------------------------------------------------------------
-
-
 //--------------------------------------------------------------------
 template <class TImageType>
 void 
@@ -78,28 +76,49 @@ GenerateOutputInformation() {
   // Get inputs
   LoadAFDB();
   m_Input = dynamic_cast<const ImageType*>(itk::ProcessObject::GetInput(0));
-  m_Support = GetAFDB()->template GetImage <MaskImageType>("mediastinum");
-  
-  //
-  typedef clitk::BooleanOperatorLabelImageFilter<MaskImageType> BFilter;
-  BFilter::Pointer merge = BFilter::New();  
+  m_Mediastinum = GetAFDB()->template GetImage <MaskImageType>("Mediastinum");
+
+  // Extract Station8
+  StartNewStep("Station 8");
+  StartSubStep(); 
+  ExtractStation_8();
+  StopSubStep();
+
+  // Compute some interesting points in trachea
+  // ( ALTERNATIVE -> SKELETON ANALYSIS ? 
+  //    Pb : not sufficient for mostXX points ... ) 
+
+  /* ==> todo (but why ???)
+     ComputeTracheaCentroidsAboveCarina();
+     ComputeBronchusExtremaPointsBelowCarina();
+  */
 
-  // Extract Station7
-  ExtractStation_7();
-  m_Output = m_Station7;
+  if (0) { // temporary suppress
+    // Extract Station7
+    StartNewStep("Station 7");
+    StartSubStep();
+    ExtractStation_7();
+    StopSubStep();
 
-  // Extract Station4RL
-  ExtractStation_4RL();
+    // Extract Station4RL
+    StartNewStep("Station 4RL");
+    StartSubStep();
+    //ExtractStation_4RL();
+    StopSubStep();
+  }
 
-  writeImage<MaskImageType>(m_Station4RL, "s4rl.mhd");
+
+  //
+  //  typedef clitk::BooleanOperatorLabelImageFilter<MaskImageType> BFilter;
+  //BFilter::Pointer merge = BFilter::New();  
   // writeImage<MaskImageType>(m_Output, "ouput.mhd");
   //writeImage<MaskImageType>(m_Working_Support, "ws.mhd");
   /*merge->SetInput1(m_Station7);
-  merge->SetInput2(m_Station4RL); // support
-  merge->SetOperationType(BFilter::AndNot); CHANGE OPERATOR
-  merge->SetForegroundValue(4);
-  merge->Update();
-  m_Output = merge->GetOutput();
+    merge->SetInput2(m_Station4RL); // support
+    merge->SetOperationType(BFilter::AndNot); CHANGE OPERATOR
+    merge->SetForegroundValue(4);
+    merge->Update();
+    m_Output = merge->GetOutput();
   */
 }
 //--------------------------------------------------------------------
@@ -123,17 +142,42 @@ GenerateData() {
   DD("GenerateData, graft output");
 
   // Final Step -> graft output (if SetNthOutput => redo)
-  this->GraftOutput(m_Output);
+  this->GraftOutput(m_ListOfStations["8"]);
 }
 //--------------------------------------------------------------------
   
 
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+ExtractStation_8() {
+
+  // Check if m_ListOfStations["8"] exist. If yes -> use it as initial
+  // support instead of m_Mediastinum
+  if (m_ListOfStations["8"]) {
+    DD("Station 8 support already exist -> use it");
+    m_Working_Support = m_ListOfStations["8"];
+  }
+  else m_Working_Support = m_Mediastinum;
+
+  ExtractStation_8_SI_Limits();
+  ExtractStation_8_AP_Limits();
+  // ExtractStation_8_LR_Limits();
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
 ExtractStation_7() {
-  DD("ExtractStation_7");
+  if (m_ListOfStations["7"]) {
+    DD("Station 7 support already exist -> use it");
+    m_Working_Support = m_ListOfStations["7"];
+  }
+  else m_Working_Support = m_Mediastinum;
   ExtractStation_7_SI_Limits();
   ExtractStation_7_RL_Limits();
   ExtractStation_7_Posterior_Limits();
@@ -146,19 +190,83 @@ template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
 ExtractStation_4RL() {
-  DD("ExtractStation_4RL");
-  writeImage<MaskImageType>(m_Support, "essai.mhd"); // OK
-
   /*
     WARNING ONLY 4R FIRST !!! (not same inf limits)
-   */
-    
+  */    
   ExtractStation_4RL_SI_Limits();
   ExtractStation_4RL_LR_Limits();
-
+  ExtractStation_4RL_AP_Limits();
 }
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+FindExtremaPointsInBronchus(MaskImagePointer input, 
+                           int direction,
+                           double distance_max_from_center_point, 
+                           ListOfPointsType & LR, 
+                           ListOfPointsType & Ant, 
+                           ListOfPointsType & Post)
+{
+
+  // Other solution ==> with auto bounding box ! (but pb to prevent to
+  // be too distant from the center point
+
+  // Extract slices
+  std::vector<typename MaskSliceType::Pointer> slices;
+  clitk::ExtractSlices<MaskImageType>(input, 2, slices);
+  
+  // Loop on slices
+  bool found;
+  for(uint i=0; i<slices.size(); i++) {
+    /*
+    // Keep main CCL
+    slices[i] = Labelize<MaskSliceType>(slices[i], 0, true, 10);
+    slices[i] = KeepLabels<MaskSliceType>(slices[i], 
+                                         GetBackgroundValue(), 
+                                         GetForegroundValue(), 1, 1, true);
+    */
+
+    // ------- Find rightmost or leftmost point  ------- 
+    MaskSliceType::PointType LRMost;
+    found = 
+      clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i], 
+                                                              GetBackgroundValue(), 
+                                                              0, // axis XY
+                                                              (direction==0?false:true),  // right or left according to direction
+                                                              LRMost);
+    // ------- Find postmost point  ------- 
+    MaskSliceType::PointType postMost;
+    found = 
+      clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i], 
+                                                              GetBackgroundValue(), 
+                                                              1, false, LRMost, 
+                                                              distance_max_from_center_point, 
+                                                              postMost);
+    // ------- Find antmost point  ------- 
+    MaskSliceType::PointType antMost;
+    found = 
+      clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i], 
+                                                              GetBackgroundValue(), 
+                                                              1, true, LRMost, 
+                                                              distance_max_from_center_point, 
+                                                              antMost);
+    // Only add point if found
+    if (found)  {
+      // ------- Convert 2D to 3D points --------
+      MaskImageType::PointType p;
+      clitk::PointsUtils<MaskImageType>::Convert2DTo3D(LRMost, input, i, p);
+      LR.push_back(p); 
+      clitk::PointsUtils<MaskImageType>::Convert2DTo3D(antMost, input, i, p);
+      Ant.push_back(p);
+      clitk::PointsUtils<MaskImageType>::Convert2DTo3D(postMost, input, i, p);
+      Post.push_back(p);
+    }
+  }
+} 
+//--------------------------------------------------------------------
 
 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX