X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractLymphStationsFilter.txx;h=64455a87a218b79c28d86ee391b7b4a4e5c784e8;hb=5a7da4aedae5c204bc55c187717193e5950f9a44;hp=6686923948dc086cbd368c54684457e12837d66a;hpb=aeb947ddd800ab06cf4916c9371bca3832056b4f;p=clitk.git diff --git a/segmentation/clitkExtractLymphStationsFilter.txx b/segmentation/clitkExtractLymphStationsFilter.txx index 6686923..64455a8 100644 --- a/segmentation/clitkExtractLymphStationsFilter.txx +++ b/segmentation/clitkExtractLymphStationsFilter.txx @@ -55,7 +55,9 @@ ExtractLymphStationsFilter(): this->SetNumberOfRequiredInputs(1); SetBackgroundValue(0); SetForegroundValue(1); - ComputeStationsSupportsFlagOn(); + ForceSupportsFlagOn(); + SetSupportLimitsFilename("none"); + CheckSupportFlagOff(); // Default values ExtractStation_3P_SetDefaultValues(); @@ -83,35 +85,43 @@ GenerateOutputInformation() { m_Input = dynamic_cast(itk::ProcessObject::GetInput(0)); m_Mediastinum = this->GetAFDB()->template GetImage ("Mediastinum"); + // DD(this->GetVerboseMemoryFlag()); + // clitk::PrintMemory(this->GetVerboseMemoryFlag(), "Start"); + // Clean some computer landmarks to force the recomputation + // FIXME -> to put elsewhere ? this->GetAFDB()->RemoveTag("AntPostVesselsSeparation"); - // Global supports for stations + // Must I compute the supports ? bool supportsExist = true; - try { - m_ListOfSupports["S1R"] = this->GetAFDB()->template GetImage("Support_S1R"); - m_ListOfSupports["S1L"] = this->GetAFDB()->template GetImage("Support_S1L"); - m_ListOfSupports["S2R"] = this->GetAFDB()->template GetImage("Support_S2R"); - m_ListOfSupports["S2L"] = this->GetAFDB()->template GetImage("Support_S2L"); - m_ListOfSupports["S4R"] = this->GetAFDB()->template GetImage("Support_S4R"); - m_ListOfSupports["S4L"] = this->GetAFDB()->template GetImage("Support_S4L"); - - m_ListOfSupports["S3A"] = this->GetAFDB()->template GetImage("Support_S3A"); - m_ListOfSupports["S3P"] = this->GetAFDB()->template GetImage("Support_S3P"); - m_ListOfSupports["S5"] = this->GetAFDB()->template GetImage("Support_S5"); - m_ListOfSupports["S6"] = this->GetAFDB()->template GetImage("Support_S6"); - m_ListOfSupports["S7"] = this->GetAFDB()->template GetImage("Support_S7"); - m_ListOfSupports["S8"] = this->GetAFDB()->template GetImage("Support_S8"); - m_ListOfSupports["S9"] = this->GetAFDB()->template GetImage("Support_S9"); - m_ListOfSupports["S10"] = this->GetAFDB()->template GetImage("Support_S10"); - m_ListOfSupports["S11"] = this->GetAFDB()->template GetImage("Support_S11"); - } catch(clitk::ExceptionObject o) { - supportsExist = false; + if (!GetForceSupportsFlag()) { + try { + m_ListOfSupports["S1R"] = this->GetAFDB()->template GetImage("Support_S1R"); + m_ListOfSupports["S1L"] = this->GetAFDB()->template GetImage("Support_S1L"); + m_ListOfSupports["S2R"] = this->GetAFDB()->template GetImage("Support_S2R"); + m_ListOfSupports["S2L"] = this->GetAFDB()->template GetImage("Support_S2L"); + m_ListOfSupports["S4R"] = this->GetAFDB()->template GetImage("Support_S4R"); + m_ListOfSupports["S4L"] = this->GetAFDB()->template GetImage("Support_S4L"); + + m_ListOfSupports["S3A"] = this->GetAFDB()->template GetImage("Support_S3A"); + m_ListOfSupports["S3P"] = this->GetAFDB()->template GetImage("Support_S3P"); + m_ListOfSupports["S5"] = this->GetAFDB()->template GetImage("Support_S5"); + m_ListOfSupports["S6"] = this->GetAFDB()->template GetImage("Support_S6"); + m_ListOfSupports["S7"] = this->GetAFDB()->template GetImage("Support_S7"); + m_ListOfSupports["S8"] = this->GetAFDB()->template GetImage("Support_S8"); + m_ListOfSupports["S9"] = this->GetAFDB()->template GetImage("Support_S9"); + m_ListOfSupports["S10"] = this->GetAFDB()->template GetImage("Support_S10"); + m_ListOfSupports["S11"] = this->GetAFDB()->template GetImage("Support_S11"); + } catch(clitk::ExceptionObject o) { + supportsExist = false; + } } - if (!supportsExist || GetComputeStationsSupportsFlag()) { + if (!supportsExist || GetForceSupportsFlag()) { this->StartNewStep("Supports for stations"); this->StartSubStep(); + + // FIXME : why should I remove theses tags ??? this->GetAFDB()->RemoveTag("CarinaZ"); this->GetAFDB()->RemoveTag("ApexOfTheChestZ"); this->GetAFDB()->RemoveTag("ApexOfTheChest"); @@ -130,11 +140,12 @@ GenerateOutputInformation() { ExtractStation_2RL(); ExtractStation_3P(); ExtractStation_3A(); - ExtractStation_4RL(); + ExtractStation_4R(); + ExtractStation_4L(); ExtractStation_5(); ExtractStation_6(); - // ---------- TODO ----------------------- + // ---------- todo ----------------------- // Extract Station8 // ExtractStation_8(); @@ -165,7 +176,7 @@ void clitk::ExtractLymphStationsFilter:: GenerateData() { // Final Step -> graft output (if SetNthOutput => redo) - this->GraftOutput(m_ListOfStations["8"]); + // this->GraftOutput(m_ListOfStations["8"]); } //-------------------------------------------------------------------- @@ -180,25 +191,29 @@ CheckForStation(std::string station) std::string s = "Station"+station; - // Check if station already exist in DB - bool found = false; - if (this->GetAFDB()->TagExist(s)) { - m_ListOfStations[station] = this->GetAFDB()->template GetImage(s); - found = true; - } - // Define the starting support - if (found && GetComputeStation(station)) { - std::cout << "Station " << station << " already exists, but re-computation forced." << std::endl; - } - if (!found || GetComputeStation(station)) { + // if (GetComputeStation(station)) { + // std::cout << "Station " << station << " already exists, but re-computation forced." << std::endl; + // } + if (GetComputeStation(station)) { m_Working_Support = m_Mediastinum = this->GetAFDB()->template GetImage("Mediastinum", true); return true; } - else { - std::cout << "Station " << station << " found. I used it" << std::endl; - return false; + else return false; + // else { + // std::cout << "Station " << station << " found. I used it" << std::endl; + // return false; + // } + + // Check if station already exist in DB + + // FIXME -> do nothing if not on the command line. Is it what I want ? + //bool found = false; + if (this->GetAFDB()->TagExist(s)) { + m_ListOfStations[station] = this->GetAFDB()->template GetImage(s); + //found = true; } + } //-------------------------------------------------------------------- @@ -471,6 +486,8 @@ FindApexOfTheChest() z = this->GetAFDB()->GetDouble("ApexOfTheChestZ"); } catch(clitk::ExceptionObject e) { + + /* //DD("FindApexOfTheChestPosition"); MaskImagePointer Lungs = this->GetAFDB()->template GetImage("Lungs"); MaskImagePointType p; @@ -486,6 +503,23 @@ FindApexOfTheChest() this->GetAFDB()->SetDouble("ApexOfTheChestZ", p[2]); this->WriteAFDB(); z = p[2]; + */ + + // the superior border becomes the more inferior of the two apices + MaskImagePointer RightLung = this->GetAFDB()->template GetImage("RightLung"); + MaskImagePointer LeftLung = this->GetAFDB()->template GetImage("LeftLung"); + MaskImagePointType pr; + MaskImagePointType pl; + clitk::FindExtremaPointInAGivenDirection(RightLung, GetBackgroundValue(), 2, false, pr); + clitk::FindExtremaPointInAGivenDirection(LeftLung, GetBackgroundValue(), 2, false, pl); + // We dont need Lungs structure from now + this->GetAFDB()->template ReleaseImage("RightLung"); + this->GetAFDB()->template ReleaseImage("LeftLung"); + // Put inside the AFDB + if (pr[2] < pl[2]) z = pr[2]; + else z = pl[2]; + this->GetAFDB()->SetDouble("ApexOfTheChestZ", z); + this->WriteAFDB(); } return z; } @@ -1383,6 +1417,65 @@ FindAntPostVessels2() } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void +clitk::ExtractLymphStationsFilter:: +WriteImageSupport(std::string support) +{ + writeImage(m_ListOfSupports[support], this->GetAFDBPath()+"/"+"seg/Support_"+support+".mha"); + this->GetAFDB()->SetImageFilename("Support_"+support, "seg/Support_"+support+".mha"); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractLymphStationsFilter:: +WriteImageStation(std::string station) +{ + writeImage(m_ListOfStations[station], GetAFDB()->GetPath()+"/seg/Station"+station+".mha"); + GetAFDB()->SetImageFilename("Station"+station, "seg/Station"+station+".mha"); + WriteAFDB(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractLymphStationsFilter:: +ComputeOverlapWithRef(std::string station) +{ + if (GetComputeStation(station)) { + MaskImagePointer ref = this->GetAFDB()->template GetImage ("Station"+station+"_Ref"); + typedef clitk::LabelImageOverlapMeasureFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + filter->SetInput(0, m_ListOfStations[station]); + filter->SetInput(1, ref); + filter->Update(); + } +} +//-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void +clitk::ExtractLymphStationsFilter:: +ReadSupportLimits(std::string filename) +{ + m_ListOfSupportLimits.clear(); + ifstream is; + openFileForReading(is, filename); + while (is) { + skipComment(is); + SupportLimitsType s; + s.Read(is); + if (is) m_ListOfSupportLimits.push_back(s); + } +} +//-------------------------------------------------------------------- #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX +