ITK  5.2.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  * http://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 
26 #include "itkMath.h"
27 #include "vnl/vnl_vector.h"
28 #include "itkMath.h"
29 
30 namespace itk
31 {
44 template <typename TBorder>
46 {
47 public:
55  bool
57  {
58  if (Math::ExactlyEquals(m_Pointer->GetLambda(), rhs.m_Pointer->GetLambda()))
59  {
60  if (m_Pointer->GetLambda() < 0)
61  {
62  return (m_Pointer > rhs.m_Pointer);
63  }
64  else
65  {
66  // The purpose of this comparison is to not let any one region
67  // get more borders than another region. In the degenerate
68  // case of an image where the Lambdas are always equal to some
69  // constant C, allowing a single region to be repeatedly
70  // merged so that it gains many borders will result in
71  // pathologically slow behavior.
72  double v1 = std::max(static_cast<double>(m_Pointer->GetRegion1()->GetRegionBorderSize()),
73  static_cast<double>(m_Pointer->GetRegion2()->GetRegionBorderSize()));
75 
76  double v2 = std::max(static_cast<double>(rhs.m_Pointer->GetRegion1()->GetRegionBorderSize()),
77  static_cast<double>(rhs.m_Pointer->GetRegion2()->GetRegionBorderSize()));
78 
79  return (v1 > v2);
80  }
81  }
82  return (m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda());
83  }
84 
85  bool
87  {
88  if (m_Pointer->GetLambda() == rhs->m_Pointer->GetLambda())
89  {
90  if (m_Pointer->GetLambda() < 0)
91  {
92  return (m_Pointer > rhs->m_Pointer);
93  }
94  else
95  {
96  // The purpose of this comparison is to not let any one region
97  // get more borders than another region. In the degenerate
98  // case of an image where the Lambdas are always equal to some
99  // constant C, allowing a single region to be repeatedly
100  // merged so that it gains many borders will result in
101  // pathologically slow behavior.
102  double v1 = std::max(static_cast<double>(m_Pointer->GetRegion1()->GetRegionBorderSize()),
103  static_cast<double>(m_Pointer->GetRegion2()->GetRegionBorderSize()));
104 
105  double v2 = std::max(static_cast<double>(rhs->m_Pointer->GetRegion1()->GetRegionBorderSize()),
106  static_cast<double>(rhs->m_Pointer->GetRegion2()->GetRegionBorderSize()));
107 
108  return (v1 > v2);
109  }
110  }
111  return (m_Pointer->GetLambda() > rhs->m_Pointer->GetLambda());
112  }
113 
114  TBorder * m_Pointer;
115 };
116 
137 // Forward reference because of circular dependencies
138 class ITK_FORWARD_EXPORT KLMSegmentationRegion;
139 
140 class ITKKLMRegionGrowing_EXPORT KLMSegmentationBorder : public SegmentationBorder
141 {
142 public:
143  ITK_DISALLOW_COPY_AND_MOVE(KLMSegmentationBorder);
144 
150 
152  itkNewMacro(Self);
153 
156 
158  void
159  SetRegion1(KLMSegmentationRegion * Region1);
160 
163  GetRegion1();
164 
166  void
167  SetRegion2(KLMSegmentationRegion * Region2);
168 
171  GetRegion2();
172 
175  itkSetMacro(Lambda, double);
176  itkGetConstReferenceMacro(Lambda, double);
178 
180  void
181  EvaluateLambda();
182 
184  void
185  PrintBorderInfo();
186 
187 protected:
190 
192  ~KLMSegmentationBorder() override;
193 
195  void
196  PrintSelf(std::ostream & os, Indent indent) const override;
197 
198 private:
199  double m_Lambda;
202 };
203 } // end namespace itk
204 
205 #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:86
itkKLMSegmentationRegion.h
itk::KLMSegmentationBorder::m_Region2
KLMSegmentationRegion * m_Region2
Definition: itkKLMSegmentationBorder.h:201
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:723
itk::SmartPointer< Self >
itk::KLMDynamicBorderArray::m_Pointer
TBorder * m_Pointer
Definition: itkKLMSegmentationBorder.h:114
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:59
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:56
itk::KLMSegmentationBorder::m_Region1
KLMSegmentationRegion * m_Region1
Definition: itkKLMSegmentationBorder.h:200
itk::KLMSegmentationBorder::m_Lambda
double m_Lambda
Definition: itkKLMSegmentationBorder.h:199
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkSegmentationBorder.h
itk::KLMDynamicBorderArray
Object maintaining a reference to a list of borders associated with a region.
Definition: itkKLMSegmentationBorder.h:45
itk::KLMSegmentationBorder
Base class for KLMSegmentationBorder object.
Definition: itkKLMSegmentationBorder.h:140
itkMath.h