]> Creatis software - clitk.git/blobdiff - segmentation/clitkExtractLymphStationsFilter.txx
Replace || by &&
[clitk.git] / segmentation / clitkExtractLymphStationsFilter.txx
index ea514a6d643924af6834d3c3a921b82b98411d05..1823e998c40cf228444cb29439c5adc760d5cd0e 100644 (file)
@@ -52,18 +52,12 @@ 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");
+  // Default values
+  ExtractStation_8_SetDefaultValues();
+  ExtractStation_3P_SetDefaultValues();
+  ExtractStation_2RL_SetDefaultValues();
+  ExtractStation_3A_SetDefaultValues();
+  ExtractStation_7_SetDefaultValues();
 }
 //--------------------------------------------------------------------
 
@@ -84,42 +78,37 @@ GenerateOutputInformation() {
   ExtractStation_8();
   StopSubStep();
 
-  // Compute some interesting points in trachea
-  // ( ALTERNATIVE -> SKELETON ANALYSIS ? 
-  //    Pb : not sufficient for mostXX points ... ) 
+  // Extract Station3P
+  StartNewStep("Station 3P");
+  StartSubStep(); 
+  ExtractStation_3P();
+  StopSubStep();
 
-  /* ==> todo (but why ???)
-     ComputeTracheaCentroidsAboveCarina();
-     ComputeBronchusExtremaPointsBelowCarina();
-  */
+  // Extract Station2RL
+  StartNewStep("Station 2RL");
+  StartSubStep(); 
+  ExtractStation_2RL();
+  StopSubStep();
 
-  if (0) { // temporary suppress
-    // Extract Station7
-    StartNewStep("Station 7");
-    StartSubStep();
-    ExtractStation_7();
-    StopSubStep();
+  // Extract Station3A
+  StartNewStep("Station 3A");
+  StartSubStep(); 
+  ExtractStation_3A();
+  StopSubStep();
+
+  // Extract Station7
+  StartNewStep("Station 7");
+  StartSubStep();
+  ExtractStation_7();
+  StopSubStep();
 
+  if (0) { // temporary suppress
     // Extract Station4RL
     StartNewStep("Station 4RL");
     StartSubStep();
     //ExtractStation_4RL();
     StopSubStep();
   }
-
-
-  //
-  //  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();
-  */
 }
 //--------------------------------------------------------------------
 
@@ -129,7 +118,7 @@ template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
 GenerateInputRequestedRegion() {
-  DD("GenerateInputRequestedRegion (nothing?)");
+  //DD("GenerateInputRequestedRegion (nothing?)");
 }
 //--------------------------------------------------------------------
 
@@ -139,8 +128,6 @@ template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
 GenerateData() {
-  DD("GenerateData, graft output");
-
   // Final Step -> graft output (if SetNthOutput => redo)
   this->GraftOutput(m_ListOfStations["8"]);
 }
@@ -149,21 +136,55 @@ GenerateData() {
 
 //--------------------------------------------------------------------
 template <class TImageType>
-void 
+bool 
 clitk::ExtractLymphStationsFilter<TImageType>::
-ExtractStation_8() {
+CheckForStation(std::string station) 
+{
+  // Compute Station name
+  std::string s = "Station"+station;
+  
 
-  // 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"];
+  // Check if station already exist in DB
+  bool found = false;
+  if (GetAFDB()->TagExist(s)) {
+    m_ListOfStations[station] = GetAFDB()->template GetImage<MaskImageType>(s);
+    found = true;
   }
-  else m_Working_Support = m_Mediastinum;
 
-  ExtractStation_8_SI_Limits();
-  ExtractStation_8_AP_Limits();
-  // ExtractStation_8_LR_Limits();
+  // Define the starting support 
+  if (found && GetComputeStation(station)) {
+    std::cout << "Station " << station << " already exists, but re-computation forced." << std::endl;
+  }
+  if (!found || GetComputeStation(station)) {
+    m_Working_Support = m_Mediastinum = GetAFDB()->template GetImage<MaskImageType>("Mediastinum", true);
+    return true;
+  }
+  else {
+    std::cout << "Station " << station << " found. I used it" << std::endl;
+    return false;
+  }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+bool
+clitk::ExtractLymphStationsFilter<TImageType>::
+GetComputeStation(std::string station) 
+{
+  return (m_ComputeStationMap.find(station) != m_ComputeStationMap.end());
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+void
+clitk::ExtractLymphStationsFilter<TImageType>::
+AddComputeStation(std::string station) 
+{
+  m_ComputeStationMap[station] = true;
 }
 //--------------------------------------------------------------------
 
@@ -172,15 +193,113 @@ ExtractStation_8() {
 template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
-ExtractStation_7() {
-  if (m_ListOfStations["7"]) {
-    DD("Station 7 support already exist -> use it");
-    m_Working_Support = m_ListOfStations["7"];
+ExtractStation_8() 
+{
+  if (CheckForStation("8")) {
+    ExtractStation_8_SI_Limits();
+    ExtractStation_8_Post_Limits();
+    ExtractStation_8_Ant_Sup_Limits();
+    ExtractStation_8_Ant_Inf_Limits();
+    ExtractStation_8_LR_1_Limits();
+    ExtractStation_8_LR_2_Limits();
+    ExtractStation_8_LR_Limits();
+    ExtractStation_8_Ant_Injected_Limits();
+    ExtractStation_8_Single_CCL_Limits();
+    ExtractStation_8_Remove_Structures();
+    // Store image filenames into AFDB 
+    writeImage<MaskImageType>(m_ListOfStations["8"], "seg/Station8.mhd");
+    GetAFDB()->SetImageFilename("Station8", "seg/Station8.mhd");  
+    WriteAFDB();
   }
-  else m_Working_Support = m_Mediastinum;
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+ExtractStation_3P()
+{
+  if (CheckForStation("3P")) {
+    ExtractStation_3P_SI_Limits();
+    ExtractStation_3P_Ant_Limits();
+    ExtractStation_3P_Post_Limits();
+    ExtractStation_3P_LR_sup_Limits();
+    //    ExtractStation_3P_LR_sup_Limits_2();
+    ExtractStation_3P_LR_inf_Limits();
+    ExtractStation_8_Single_CCL_Limits(); // YES 8 !
+    ExtractStation_3P_Remove_Structures(); // after CCL
+    // Store image filenames into AFDB 
+    writeImage<MaskImageType>(m_ListOfStations["3P"], "seg/Station3P.mhd");
+    GetAFDB()->SetImageFilename("Station3P", "seg/Station3P.mhd"); 
+    WriteAFDB(); 
+  }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+ExtractStation_7() {
+  if (CheckForStation("7")) {
   ExtractStation_7_SI_Limits();
   ExtractStation_7_RL_Limits();
   ExtractStation_7_Posterior_Limits();
+  //  ExtractStation_8_Single_CCL_Limits(); // Yes the same than 8
+  ExtractStation_7_Remove_Structures();
+  // Store image filenames into AFDB 
+  writeImage<MaskImageType>(m_ListOfStations["7"], "seg/Station7.mhd");
+  GetAFDB()->SetImageFilename("Station7", "seg/Station7.mhd");  
+  WriteAFDB();
+  }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+ExtractStation_3A()
+{
+  if (CheckForStation("3A")) {
+    ExtractStation_3A_SI_Limits();
+    ExtractStation_3A_Ant_Limits();
+    ExtractStation_3A_Post_Limits();
+    // Store image filenames into AFDB 
+    writeImage<MaskImageType>(m_ListOfStations["3A"], "seg/Station3A.mhd");
+    GetAFDB()->SetImageFilename("Station3A", "seg/Station3A.mhd"); 
+    WriteAFDB(); 
+  }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class TImageType>
+void 
+clitk::ExtractLymphStationsFilter<TImageType>::
+ExtractStation_2RL()
+{
+  if (CheckForStation("2RL")) {
+    ExtractStation_2RL_SI_Limits();
+    ExtractStation_2RL_Post_Limits();
+    ExtractStation_2RL_Ant_Limits2();
+    ExtractStation_2RL_Ant_Limits(); 
+    ExtractStation_2RL_LR_Limits(); 
+    ExtractStation_2RL_Remove_Structures(); 
+    ExtractStation_2RL_SeparateRL(); 
+    
+    // Store image filenames into AFDB 
+    writeImage<MaskImageType>(m_ListOfStations["2R"], "seg/Station2R.mhd");
+    writeImage<MaskImageType>(m_ListOfStations["2L"], "seg/Station2L.mhd");
+    GetAFDB()->SetImageFilename("Station2R", "seg/Station2R.mhd"); 
+    GetAFDB()->SetImageFilename("Station2L", "seg/Station2L.mhd"); 
+    WriteAFDB(); 
+  }
 }
 //--------------------------------------------------------------------
 
@@ -190,6 +309,8 @@ template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
 ExtractStation_4RL() {
+  DD("TODO");
+  exit(0);
   /*
     WARNING ONLY 4R FIRST !!! (not same inf limits)
   */    
@@ -200,73 +321,56 @@ ExtractStation_4RL() {
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::ExtractLymphStationsFilter<ImageType>::
+Remove_Structures(std::string station, std::string s)
+{
+  try {
+    StartNewStep("[Station"+station+"] Remove "+s);  
+    MaskImagePointer Structure = GetAFDB()->template GetImage<MaskImageType>(s);
+    clitk::AndNot<MaskImageType>(m_Working_Support, Structure, GetBackgroundValue());
+  }
+  catch(clitk::ExceptionObject e) {
+    std::cout << s << " not found, skip." << std::endl;
+  }
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 template <class TImageType>
 void 
 clitk::ExtractLymphStationsFilter<TImageType>::
-FindExtremaPointsInBronchus(MaskImagePointer input, 
-                           int direction,
-                           double distance_max_from_center_point, 
-                           ListOfPointsType & LR, 
-                           ListOfPointsType & Ant, 
-                           ListOfPointsType & Post)
+SetFuzzyThreshold(std::string station, std::string tag, double value)
 {
+  m_FuzzyThreshold[station][tag] = value;
+}
+//--------------------------------------------------------------------
 
-  // 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);
-    }
+//--------------------------------------------------------------------
+template <class TImageType>
+double 
+clitk::ExtractLymphStationsFilter<TImageType>::
+GetFuzzyThreshold(std::string station, std::string tag)
+{
+  if (m_FuzzyThreshold.find(station) == m_FuzzyThreshold.end()) {
+    clitkExceptionMacro("Could not find options for station "+station+" in the list (while searching for tag "+tag+").");
+    return 0.0;
+  }
+
+  if (m_FuzzyThreshold[station].find(tag) == m_FuzzyThreshold[station].end()) {
+    clitkExceptionMacro("Could not find options "+tag+" in the list of FuzzyThreshold for station "+station+".");
+    return 0.0;
   }
-} 
+  
+  return m_FuzzyThreshold[station][tag]; 
+}
 //--------------------------------------------------------------------
 
+
+
+
 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX