X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractLymphStationsFilter.txx;h=98768b278bfdaf105662efb118684db4d5c2713d;hb=7f7c290c75d4917446f8751856ae7d450f58a6f0;hp=9051ec154df9cf5c8a8cc94cb640556a27f73819;hpb=42e050104aebe7830f2111d096f0dd6673987d1e;p=clitk.git diff --git a/segmentation/clitkExtractLymphStationsFilter.txx b/segmentation/clitkExtractLymphStationsFilter.txx index 9051ec1..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"); @@ -126,24 +133,25 @@ GenerateOutputInformation() { } // Extract Stations + ExtractStation_1RL(); + ExtractStation_2RL(); ExtractStation_3P(); ExtractStation_3A(); - ExtractStation_2RL(); - ExtractStation_1RL(); - ExtractStation_4RL(); + ExtractStation_4R(); + ExtractStation_4L(); ExtractStation_5(); ExtractStation_6(); - // ---------- TODO ----------------------- + // ---------- todo ----------------------- // Extract Station8 - ExtractStation_8(); + // ExtractStation_8(); // Extract Station7 - this->StartNewStep("Station 7"); - this->StartSubStep(); - ExtractStation_7(); - this->StopSubStep(); + //this->StartNewStep("Station 7"); + //this->StartSubStep(); + //ExtractStation_7(); + //this->StopSubStep(); } //-------------------------------------------------------------------- @@ -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); @@ -988,8 +1019,8 @@ FindAntPostVesselsOLD() binarizedContour = clitk::CropImageAlongOneAxis(binarizedContour, 2, inf, sup, false, GetBackgroundValue()); // Update the AFDB - writeImage(binarizedContour, "seg/AntPostVesselsSeparation.mhd"); - this->GetAFDB()->SetImageFilename("AntPostVesselsSeparation", "seg/AntPostVesselsSeparation.mhd"); + writeImage(binarizedContour, "seg/AntPostVesselsSeparation.mha"); + this->GetAFDB()->SetImageFilename("AntPostVesselsSeparation", "seg/AntPostVesselsSeparation.mha"); this->WriteAFDB(); return binarizedContour; @@ -1076,10 +1107,10 @@ FindAntPostVessels2() typedef std::map::iterator MapIter; MapOfStructures["BrachioCephalicArtery"] = this->GetAFDB()->template GetImage("BrachioCephalicArtery"); MapOfStructures["BrachioCephalicVein"] = this->GetAFDB()->template GetImage("BrachioCephalicVein"); - MapOfStructures["CommonCarotidArteryLeft"] = this->GetAFDB()->template GetImage("CommonCarotidArteryLeft"); - MapOfStructures["CommonCarotidArteryRight"] = this->GetAFDB()->template GetImage("CommonCarotidArteryRight"); - MapOfStructures["SubclavianArteryLeft"] = this->GetAFDB()->template GetImage("SubclavianArteryLeft"); - MapOfStructures["SubclavianArteryRight"] = this->GetAFDB()->template GetImage("SubclavianArteryRight"); + MapOfStructures["CommonCarotidArteryLeft"] = this->GetAFDB()->template GetImage("LeftCommonCarotidArtery"); + MapOfStructures["CommonCarotidArteryRight"] = this->GetAFDB()->template GetImage("RightCommonCarotidArtery"); + MapOfStructures["SubclavianArteryLeft"] = this->GetAFDB()->template GetImage("LeftSubclavianArtery"); + MapOfStructures["SubclavianArteryRight"] = this->GetAFDB()->template GetImage("RightSubclavianArtery"); MapOfStructures["Thyroid"] = this->GetAFDB()->template GetImage("Thyroid"); MapOfStructures["Aorta"] = this->GetAFDB()->template GetImage("Aorta"); MapOfStructures["Trachea"] = this->GetAFDB()->template GetImage("Trachea"); @@ -1347,8 +1378,8 @@ FindAntPostVessels2() false, GetBackgroundValue()); // Update the AFDB - writeImage(binarizedContour, "seg/AntPostVesselsSeparation.mhd"); - this->GetAFDB()->SetImageFilename("AntPostVesselsSeparation", "seg/AntPostVesselsSeparation.mhd"); + writeImage(binarizedContour, "seg/AntPostVesselsSeparation.mha"); + this->GetAFDB()->SetImageFilename("AntPostVesselsSeparation", "seg/AntPostVesselsSeparation.mha"); this->WriteAFDB(); return binarizedContour; @@ -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 +