]> Creatis software - clitk.git/commitdiff
read carina position into DB
authordsarrut <dsarrut>
Mon, 4 Oct 2010 07:54:45 +0000 (07:54 +0000)
committerdsarrut <dsarrut>
Mon, 4 Oct 2010 07:54:45 +0000 (07:54 +0000)
segmentation/clitkExtractLymphStations.cxx
segmentation/clitkExtractLymphStations.ggo
segmentation/clitkExtractLymphStationsFilter.h
segmentation/clitkExtractLymphStationsFilter.txx
segmentation/clitkExtractLymphStationsGenericFilter.txx

index cf392f8d399a8ea866a53e8d28f7c6e6f2ac5f24..ec41a4e5acac639048cf6b1508b9066d6d50279e 100644 (file)
@@ -33,10 +33,11 @@ int main(int argc, char * argv[])
   FilterType::Pointer filter = FilterType::New();
 
   filter->SetArgsInfo(args_info);
-  filter->Update();
-
-  if (filter->HasError()) {
-    std::cout << filter->GetLastError() << std::endl;
+  
+  try {
+    filter->Update();
+  } catch(std::runtime_error e) {
+    std::cout << e.what() << std::endl;
   }
 
   return EXIT_SUCCESS;
index 28d78f60cd2100a6ced760a30f030838e0eebf0d..3e493a1b46fc38bc1983d6e043fdb84968cb7976 100644 (file)
@@ -13,6 +13,7 @@ option "verboseWarningOff" -  "Do not display warning"    flag          off
 
 section "I/O"
 
+option "afdb"          a       "Input Anatomical Feature DB"     string        no
 option "mediastinum"   m       "Input mediastinum mask filename" string        yes
 option "trachea"       t       "Input trachea mask filename"     string        yes
 option "output"        o       "Output lungs mask filename"      string        yes
index e6b11a753f4630e33788b71e201f2c9745566e1c..6db26a222b138ee0c3fe4cdf24da968631a8f15b 100644 (file)
@@ -19,7 +19,9 @@
 #ifndef CLITKEXTRACTLYMPHSTATIONSFILTER_H
 #define CLITKEXTRACTLYMPHSTATIONSFILTER_H
 
+// clitk
 #include "clitkFilterBase.h"
+#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
 
 namespace clitk {
   
@@ -35,8 +37,9 @@ namespace clitk {
   
   template <class TImageType>
   class ITK_EXPORT ExtractLymphStationsFilter: 
-    public clitk::FilterBase, 
-    public itk::ImageToImageFilter<TImageType, TImageType> 
+    public virtual clitk::FilterBase, 
+    public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
+    public itk::ImageToImageFilter<TImageType, TImageType>
   {
 
   public:
@@ -61,6 +64,7 @@ namespace clitk {
     typedef typename ImageType::PixelType    ImagePixelType; 
     typedef typename ImageType::SizeType     ImageSizeType; 
     typedef typename ImageType::IndexType    ImageIndexType; 
+    typedef typename ImageType::PointType    ImagePointType; 
         
     /** Connect inputs */
     void SetInputMediastinumLabelImage(const TImageType * image, ImagePixelType bg=0);
@@ -85,9 +89,10 @@ namespace clitk {
     itkGetConstMacro(BackgroundValue, ImagePixelType);
     itkGetConstMacro(ForegroundValue, ImagePixelType);
 
-    itkSetMacro(CarenaZPositionInMM, double);
-    itkGetConstMacro(CarenaZPositionInMM, double);
-    GGO_DefineOption(carenaZposition, SetCarenaZPositionInMM, double);
+    //itkSetMacro(CarinaZPositionInMM, double);
+    void SetCarinaZPositionInMM(double d) { m_CarinaZPositionInMM = d; Modified(); m_CarinaZPositionInMMIsSet = true; }
+    itkGetConstMacro(CarinaZPositionInMM, double);
+    GGO_DefineOption(carenaZposition, SetCarinaZPositionInMM, double);
 
     itkSetMacro(MiddleLobeBronchusZPositionInMM, double);
     itkGetConstMacro(MiddleLobeBronchusZPositionInMM, double);
@@ -100,9 +105,7 @@ namespace clitk {
     itkSetMacro(FuzzyThreshold1, double);
     itkGetConstMacro(FuzzyThreshold1, double);
     GGO_DefineOption(fuzzy1, SetFuzzyThreshold1, double);
-
-
-
+    
   protected:
     ExtractLymphStationsFilter();
     virtual ~ExtractLymphStationsFilter() {}
@@ -125,7 +128,8 @@ namespace clitk {
     ImagePixelType m_BackgroundValue;
     ImagePixelType m_ForegroundValue;
     
-    double m_CarenaZPositionInMM;
+    double m_CarinaZPositionInMM;
+    bool   m_CarinaZPositionInMMIsSet;
     double m_MiddleLobeBronchusZPositionInMM; 
     double m_IntermediateSpacing;
     double m_FuzzyThreshold1;
index aab78d85c01730c9778c4be1cf81d99c28726728..919d4804f237418fd2c5ad4081766757c1362255 100644 (file)
@@ -44,6 +44,7 @@ template <class TImageType>
 clitk::ExtractLymphStationsFilter<TImageType>::
 ExtractLymphStationsFilter():
   clitk::FilterBase(),
+  clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
   itk::ImageToImageFilter<TImageType, TImageType>()
 {
   this->SetNumberOfRequiredInputs(1);
@@ -51,9 +52,9 @@ ExtractLymphStationsFilter():
   SetBackgroundValueTrachea(0);
   SetBackgroundValue(0);
   SetForegroundValue(1);
-
   SetIntermediateSpacing(6);
-  SetFuzzyThreshold1(0.6);
+  SetFuzzyThreshold1(0.6);  
+  m_CarinaZPositionInMMIsSet = false;
 }
 //--------------------------------------------------------------------
 
@@ -64,11 +65,7 @@ void
 clitk::ExtractLymphStationsFilter<TImageType>::
 SetInputMediastinumLabelImage(const TImageType * image, ImagePixelType bg) {
   this->SetNthInput(0, const_cast<TImageType *>(image));
-  m_BackgroundValueMediastinum = bg;
-  SetCarenaZPositionInMM(image->GetOrigin()[2]+image->GetLargestPossibleRegion().GetSize()[2]*image->GetSpacing()[2]);
-  SetMiddleLobeBronchusZPositionInMM(image->GetOrigin()[2]);
-  // DD(m_CarenaZPositionInMM);
-//   DD(m_MiddleLobeBronchusZPositionInMM);
+  SetBackgroundValueMediastinum(bg);
 }
 //--------------------------------------------------------------------
 
@@ -79,7 +76,7 @@ void
 clitk::ExtractLymphStationsFilter<TImageType>::
 SetInputTracheaLabelImage(const TImageType * image, ImagePixelType bg) {
   this->SetNthInput(1, const_cast<TImageType *>(image));
-  m_BackgroundValueTrachea = bg;
+  SetBackgroundValueTrachea(bg);
 }
 //--------------------------------------------------------------------
 
@@ -95,11 +92,12 @@ SetArgsInfo(ArgsInfoType mArgsInfo)
   SetVerboseStep_GGO(mArgsInfo);
   SetWriteStep_GGO(mArgsInfo);
   SetVerboseWarningOff_GGO(mArgsInfo);
-  SetCarenaZPositionInMM_GGO(mArgsInfo);
+  SetAFDBFilename_GGO(mArgsInfo);
+  SetCarinaZPositionInMM_GGO(mArgsInfo);
+  m_CarinaZPositionInMMIsSet = false;
   SetMiddleLobeBronchusZPositionInMM_GGO(mArgsInfo);
   SetIntermediateSpacing_GGO(mArgsInfo);
   SetFuzzyThreshold1_GGO(mArgsInfo);
-  //SetBackgroundValueMediastinum_GGO(mArgsInfo);
 }
 //--------------------------------------------------------------------
 
@@ -114,7 +112,17 @@ GenerateOutputInformation() {
   // Get input
   m_mediastinum = dynamic_cast<const TImageType*>(itk::ProcessObject::GetInput(0));
   m_trachea = dynamic_cast<const TImageType*>(itk::ProcessObject::GetInput(1));
-    
+
+  // Get landmarks information
+  if (!m_CarinaZPositionInMMIsSet) {
+    ImagePointType carina;
+    LoadAFDB();
+    GetAFDB()->GetPoint3D("Carena", carina);
+    DD(carina);
+    m_CarinaZPositionInMM = carina[2];
+  }
+  DD(m_CarinaZPositionInMM);
+
   // ----------------------------------------------------------------
   // ----------------------------------------------------------------
   // Superior limit = carena
@@ -123,10 +131,10 @@ GenerateOutputInformation() {
   ImageRegionType region = m_mediastinum->GetLargestPossibleRegion(); DD(region);
   ImageSizeType size = region.GetSize();
   ImageIndexType index = region.GetIndex();
-  DD(m_CarenaZPositionInMM);
+  DD(m_CarinaZPositionInMM);
   DD(m_MiddleLobeBronchusZPositionInMM);
   index[2] = floor((m_MiddleLobeBronchusZPositionInMM - m_mediastinum->GetOrigin()[2]) / m_mediastinum->GetSpacing()[2]);
-  size[2] = ceil((m_CarenaZPositionInMM-m_MiddleLobeBronchusZPositionInMM) / m_mediastinum->GetSpacing()[2]);
+  size[2] = ceil((m_CarinaZPositionInMM-m_MiddleLobeBronchusZPositionInMM) / m_mediastinum->GetSpacing()[2]);
   region.SetSize(size);
   region.SetIndex(index);
   DD(region);
@@ -227,7 +235,7 @@ GenerateOutputInformation() {
   sliceRelPosFilter->SetInput(m_working_image);
   sliceRelPosFilter->SetInputObject(temp);
   sliceRelPosFilter->SetDirection(2);
-  sliceRelPosFilter->SetFuzzyThreshold(0.5);
+  sliceRelPosFilter->SetFuzzyThreshold(0.6);
   sliceRelPosFilter->SetOrientationType(SliceRelPosFilterType::RelPosFilterType::RightTo);
   sliceRelPosFilter->Update();
   m_working_image = sliceRelPosFilter->GetOutput();
@@ -247,7 +255,7 @@ GenerateOutputInformation() {
   sliceRelPosFilter->SetInput(m_working_image);
   sliceRelPosFilter->SetInputObject(temp);
   sliceRelPosFilter->SetDirection(2);
-  sliceRelPosFilter->SetFuzzyThreshold(0.5);
+  sliceRelPosFilter->SetFuzzyThreshold(0.6);
   sliceRelPosFilter->SetOrientationType(SliceRelPosFilterType::RelPosFilterType::LeftTo);
   sliceRelPosFilter->Update();
   m_working_image = sliceRelPosFilter->GetOutput();
index 2644c1fc99153a50c7694150e8c91dabcc39de35..fb6d4dae8705c385ae83a03c13daf96e938efcd9 100644 (file)
@@ -81,14 +81,17 @@ void clitk::ExtractLymphStationsGenericFilter<ArgsInfoType>::UpdateWithInputImag
   filter->SetArgsInfo(mArgsInfo);
 
   // Go !
-  filter->Update();
+  // try {
+    filter->Update();
+  // }
+  // catch(std::runtime_error e) {
   
-  // Check if error
-  if (filter->HasError()) {
-    SetLastError(filter->GetLastError());
-    // No output
-    return;
-  }
+  // // Check if error
+  // if (filter->HasError()) {
+  //   SetLastError(filter->GetLastError());
+  //   // No output
+  //   return;
+  // }
 
   // Write/Save results
   typename ImageType::Pointer output = filter->GetOutput();