ITK  6.0.0
Insight Toolkit
itkKLMSegmentationBorder.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkKLMSegmentationBorder_h
19 #define itkKLMSegmentationBorder_h
20 
21 #include "itkSegmentationBorder.h"
23 #include "itkMacro.h"
24 #include "ITKKLMRegionGrowingExport.h"
25 #include "itkMath.h"
26 #include "vnl/vnl_vector.h"
27 
28 namespace itk
29 {
42 template <typename TBorder>
44 {
45 public:
53  bool
55  {
56  if (Math::ExactlyEquals(m_Pointer->GetLambda(), rhs.m_Pointer->GetLambda()))
57  {
58  if (m_Pointer->GetLambda() < 0)
59  {
60  return (m_Pointer > rhs.m_Pointer);
61  }
62  else
63  {
64  // The purpose of this comparison is to not let any one region
65  // get more borders than another region. In the degenerate
66  // case of an image where the Lambdas are always equal to some
67  // constant C, allowing a single region to be repeatedly
68  // merged so that it gains many borders will result in
69  // pathologically slow behavior.
70  double v1 = std::max(static_cast<double>(m_Pointer->GetRegion1()->GetRegionBorderSize()),
71  static_cast<double>(m_Pointer->GetRegion2()->GetRegionBorderSize()));
74  double v2 = std::max(static_cast<double>(rhs.m_Pointer->GetRegion1()->GetRegionBorderSize()),
75  static_cast<double>(rhs.m_Pointer->GetRegion2()->GetRegionBorderSize()));
76 
77  return (v1 > v2);
78  }
79  }
80  return (m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda());
81  }
82 
83  bool
85  {
86  if (m_Pointer->GetLambda() == rhs->m_Pointer->GetLambda())
87  {
88  if (m_Pointer->GetLambda() < 0)
89  {
90  return (m_Pointer > rhs->m_Pointer);
91  }
92  else
93  {
94  // The purpose of this comparison is to not let any one region
95  // get more borders than another region. In the degenerate
96  // case of an image where the Lambdas are always equal to some
97  // constant C, allowing a single region to be repeatedly
98  // merged so that it gains many borders will result in
99  // pathologically slow behavior.
100  double v1 = std::max(static_cast<double>(m_Pointer->GetRegion1()->GetRegionBorderSize()),
101  static_cast<double>(m_Pointer->GetRegion2()->GetRegionBorderSize()));
102 
103  double v2 = std::max(static_cast<double>(rhs->m_Pointer->GetRegion1()->GetRegionBorderSize()),
104  static_cast<double>(rhs->m_Pointer->GetRegion2()->GetRegionBorderSize()));
105 
106  return (v1 > v2);
107  }
108  }
109  return (m_Pointer->GetLambda() > rhs->m_Pointer->GetLambda());
110  }
111 
112  TBorder * m_Pointer;
113 };
114 
135 // Forward reference because of circular dependencies
136 class ITK_FORWARD_EXPORT KLMSegmentationRegion;
137 
138 class ITKKLMRegionGrowing_EXPORT KLMSegmentationBorder : public SegmentationBorder
139 {
140 public:
141  ITK_DISALLOW_COPY_AND_MOVE(KLMSegmentationBorder);
142 
148 
150  itkNewMacro(Self);
151 
153  itkOverrideGetNameOfClassMacro(KLMSegmentationBorder);
154 
156  void
157  SetRegion1(KLMSegmentationRegion * Region1);
158 
161  GetRegion1();
162 
164  void
165  SetRegion2(KLMSegmentationRegion * Region2);
166 
169  GetRegion2();
170 
173  itkSetMacro(Lambda, double);
174  itkGetConstReferenceMacro(Lambda, double);
178  void
179  EvaluateLambda();
180 
182  void
183  PrintBorderInfo();
184 
185 protected:
188 
190  ~KLMSegmentationBorder() override;
191 
193  void
194  PrintSelf(std::ostream & os, Indent indent) const override;
195 
196 private:
197  double m_Lambda{};
198  KLMSegmentationRegion * m_Region1{};
199  KLMSegmentationRegion * m_Region2{};
200 };
201 } // end namespace itk
202 
203 #endif
itk::KLMSegmentationRegion
Base class for KLMSegmentationRegion object.
Definition: itkKLMSegmentationRegion.h:93
itk::KLMDynamicBorderArray::operator>
bool operator>(const KLMDynamicBorderArray< TBorder > *rhs) const
Definition: itkKLMSegmentationBorder.h:84
itkKLMSegmentationRegion.h
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:722
itk::SmartPointer< Self >
itk::KLMDynamicBorderArray::m_Pointer
TBorder * m_Pointer
Definition: itkKLMSegmentationBorder.h:112
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::KLMSegmentationBorder
class ITK_FORWARD_EXPORT KLMSegmentationBorder
Definition: itkKLMSegmentationRegion.h:91
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkMacro.h
itk::SegmentationBorder
Base class for SegmentationBorder object.
Definition: itkSegmentationBorder.h:47
itk::KLMDynamicBorderArray::operator>
bool operator>(const KLMDynamicBorderArray< TBorder > &rhs) const
Definition: itkKLMSegmentationBorder.h:54
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkSegmentationBorder.h
itk::KLMDynamicBorderArray
Object maintaining a reference to a list of borders associated with a region.
Definition: itkKLMSegmentationBorder.h:43
itk::KLMSegmentationBorder
Base class for KLMSegmentationBorder object.
Definition: itkKLMSegmentationBorder.h:138
itkMath.h