+//--------------------------------------------------------------------
+template <class ImageType>
+void
+clitk::ExtractLymphStationsFilter<ImageType>::
+Support_Post_S1_S3P()
+{
+ StartNewStep("[Support] If S1RL and S3P have Sup-Inf overlap, define S1RL posterior limits with S3P anterior limits (post wall trachea)");
+
+ // Get current supports
+ MaskImagePointer S1R = m_ListOfSupports["S1R"];
+ MaskImagePointer S1L = m_ListOfSupports["S1L"];
+
+ // Find extrema ant positions for 3P
+ std::vector<MaskImagePointType> A;
+ std::vector<MaskImagePointType> B;
+
+ // Crop S3P like S1R
+ MaskImagePointer S3P = clitk::Clone<MaskImageType>(m_ListOfSupports["S3P"]);
+ S3P = clitk::ResizeImageLike<MaskImageType>(S3P, S1R, GetBackgroundValue());
+
+ // Slice by slice, build the separation line
+ clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(S3P,
+ GetBackgroundValue(), 2,
+ 1, true, // Ant-Post
+ 0, // Horizontal line
+ 0, // margins
+ A, B);
+
+ // clitk::WriteListOfLandmarks<MaskImageType>(A, "A-S1S3P.txt");
+ // clitk::WriteListOfLandmarks<MaskImageType>(B, "B-S1S3P.txt");
+
+ // Cut post to this line
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(S1R, A, B,
+ GetBackgroundValue(),
+ 1, -10);
+
+ // Crop S3P like S1L (Redo for S1L)
+ S3P = clitk::Clone<MaskImageType>(m_ListOfSupports["S3P"]);
+ S3P = clitk::ResizeImageLike<MaskImageType>(S3P, S1L, GetBackgroundValue());
+
+ // Slice by slice, build the separation line
+ A.clear();
+ B.clear();
+ clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(S3P,
+ GetBackgroundValue(), 2,
+ 1, true, // Ant-Post
+ 0, // Horizontal line
+ 0, // margins
+ A, B);
+ // Cut post to this line
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(S1L, A, B,
+ GetBackgroundValue(),
+ 1, -10);
+
+ // Crop both images
+ S1R = clitk::AutoCrop<MaskImageType>(S1R, GetBackgroundValue());
+ S1L = clitk::AutoCrop<MaskImageType>(S1L, GetBackgroundValue());
+
+ StopCurrentStep<MaskImageType>(S1R);
+
+ m_ListOfSupports["S1R"] = S1R;
+ m_ListOfSupports["S1L"] = S1L;
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void
+clitk::ExtractLymphStationsFilter<ImageType>::
+Support_Post_S1_Ant_S2RL()
+{
+ StartNewStep("[Support] Define S1RL posterior limits with S2RL anterior limits when overlap");
+
+ // Get RightLung
+ MaskImagePointer RightLung = this->GetAFDB()->template GetImage<MaskImageType>("RightLung");
+
+ // Find common area between S1 and S2
+ MaskImagePointType p_min;
+ MaskImagePointType p_max;
+ clitk::FindExtremaPointInAGivenDirection<MaskImageType>(m_ListOfSupports["S2R"],
+ GetBackgroundValue(), 2, false, p_max);
+ clitk::FindExtremaPointInAGivenDirection<MaskImageType>(m_ListOfSupports["S1R"],
+ GetBackgroundValue(), 2, true, p_min);
+ p_min[2] -= RightLung->GetSpacing()[2]; // consider the slice below (remove lower or equal)
+ p_max[2] += RightLung->GetSpacing()[2]; // consider the slice abov (remove greater or equal)
+
+ if (p_min[2] > p_max[2]) {
+
+ // Crop RightLung
+ RightLung = clitk::Clone<MaskImageType>(RightLung);
+ RightLung = clitk::ResizeImageLike<MaskImageType>(RightLung, m_ListOfSupports["S1R"], GetBackgroundValue());
+ RightLung = clitk::CropImageRemoveLowerThan<MaskImageType>(RightLung, 2, p_min[2], true, GetBackgroundValue());
+ RightLung = clitk::CropImageRemoveGreaterThan<MaskImageType>(RightLung, 2, p_max[2], true, GetBackgroundValue());
+
+ // Find extrema ant positions for RightLung
+ std::vector<MaskImagePointType> A;
+ std::vector<MaskImagePointType> B;
+ clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(RightLung,
+ GetBackgroundValue(), 2,
+ 1, true, // Ant-Post
+ 0, // Horizontal line
+ 0, // margins
+ A, B);
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_ListOfSupports["S1R"],
+ A, B,
+ GetBackgroundValue(),
+ 1, -10);
+ // I add one pixel to abupt S2R to S1R
+ for(int i=0; i<A.size(); i++) {
+ A[i][1] -= RightLung->GetSpacing()[1];
+ B[i][1] -= RightLung->GetSpacing()[1];
+ }
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_ListOfSupports["S2R"],
+ A, B,
+ GetBackgroundValue(),
+ 1, 10);
+ }
+
+ // Get LeftLung, crop
+ MaskImagePointer LeftLung = this->GetAFDB()->template GetImage<MaskImageType>("LeftLung");
+ clitk::FindExtremaPointInAGivenDirection<MaskImageType>(m_ListOfSupports["S2L"],
+ GetBackgroundValue(), 2, false, p_max);
+ clitk::FindExtremaPointInAGivenDirection<MaskImageType>(m_ListOfSupports["S1L"],
+ GetBackgroundValue(), 2, true, p_min);
+ p_min[2] -= LeftLung->GetSpacing()[2]; // consider the slice below (remove lower or equal)
+ p_max[2] += LeftLung->GetSpacing()[2]; // consider the slice abov (remove greater or equal)
+
+ if (p_min[2] > p_max[2]) {
+ LeftLung = clitk::ResizeImageLike<MaskImageType>(LeftLung, m_ListOfSupports["S1L"], GetBackgroundValue());
+ LeftLung = clitk::CropImageRemoveLowerThan<MaskImageType>(LeftLung, 2, p_min[2], true, GetBackgroundValue());
+ LeftLung = clitk::CropImageRemoveGreaterThan<MaskImageType>(LeftLung, 2, p_max[2], true, GetBackgroundValue());
+
+ // Find extrema ant positions for LeftLung
+ std::vector<MaskImagePointType> A;
+ std::vector<MaskImagePointType> B;
+ clitk::SliceBySliceBuildLineSegmentAccordingToExtremaPosition<MaskImageType>(LeftLung,
+ GetBackgroundValue(), 2,
+ 1, true, // Ant-Post
+ 0, // Horizontal line
+ 0, // margins
+ A, B);
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_ListOfSupports["S1L"],
+ A, B,
+ GetBackgroundValue(),
+ 1, -10);
+ // I add one pixel to abupt S2R to S1R
+ for(int i=0; i<A.size(); i++) {
+ A[i][1] -= LeftLung->GetSpacing()[1];
+ B[i][1] -= LeftLung->GetSpacing()[1];
+ }
+ clitk::SliceBySliceSetBackgroundFromLineSeparation<MaskImageType>(m_ListOfSupports["S2L"],
+ A, B,
+ GetBackgroundValue(),
+ 1, 10);
+ }
+}
+//--------------------------------------------------------------------