X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractLymphStationsFilter.txx;h=98768b278bfdaf105662efb118684db4d5c2713d;hb=7f7c290c75d4917446f8751856ae7d450f58a6f0;hp=ec93c098b3421ea3d8a9105f5677c1212771ed45;hpb=eb0518a3c989812b383a96856afd562c4ebb70a0;p=clitk.git diff --git a/segmentation/clitkExtractLymphStationsFilter.txx b/segmentation/clitkExtractLymphStationsFilter.txx index ec93c09..98768b2 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(); @@ -84,34 +86,39 @@ GenerateOutputInformation() { m_Mediastinum = this->GetAFDB()->template GetImage ("Mediastinum"); // 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 +137,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 +173,7 @@ void clitk::ExtractLymphStationsFilter:: GenerateData() { // Final Step -> graft output (if SetNthOutput => redo) - this->GraftOutput(m_ListOfStations["8"]); + // this->GraftOutput(m_ListOfStations["8"]); } //-------------------------------------------------------------------- @@ -180,25 +188,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; } + } //-------------------------------------------------------------------- @@ -438,7 +450,7 @@ FindCarina() z = this->GetAFDB()->GetDouble("CarinaZ"); } catch(clitk::ExceptionObject e) { - DD("FindCarinaSlicePosition"); + //DD("FindCarinaSlicePosition"); // Get Carina MaskImagePointer Carina = this->GetAFDB()->template GetImage("Carina"); @@ -471,7 +483,9 @@ FindApexOfTheChest() z = this->GetAFDB()->GetDouble("ApexOfTheChestZ"); } catch(clitk::ExceptionObject e) { - DD("FindApexOfTheChestPosition"); + + /* + //DD("FindApexOfTheChestPosition"); MaskImagePointer Lungs = this->GetAFDB()->template GetImage("Lungs"); MaskImagePointType p; p[0] = p[1] = p[2] = 0.0; // to avoid warning @@ -486,6 +500,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; } @@ -596,7 +627,7 @@ FindSuperiorBorderOfAorticArch() z = this->GetAFDB()->GetDouble("SuperiorBorderOfAorticArchZ"); } catch(clitk::ExceptionObject e) { - DD("FindSuperiorBorderOfAorticArch"); + // DD("FindSuperiorBorderOfAorticArch"); MaskImagePointer Aorta = this->GetAFDB()->template GetImage("Aorta"); MaskImagePointType p; p[0] = p[1] = p[2] = 0.0; // to avoid warning @@ -628,7 +659,7 @@ FindInferiorBorderOfAorticArch() z = this->GetAFDB()->GetDouble("InferiorBorderOfAorticArchZ"); } catch(clitk::ExceptionObject e) { - DD("FindInferiorBorderOfAorticArch"); + //DD("FindInferiorBorderOfAorticArch"); MaskImagePointer Aorta = this->GetAFDB()->template GetImage("Aorta"); std::vector slices; clitk::ExtractSlices(Aorta, 2, slices); @@ -1383,6 +1414,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 +