ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkKLMSegmentationBorder.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 "vnl/vnl_math.h"
27 #include "vnl/vnl_vector.h"
28 #include "itkMath.h"
29 
30 namespace itk
31 {
43 template< typename TBorder >
45 {
46 public:
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 = vnl_math_max(
71  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
72  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
74 
75  double v2 = vnl_math_max(
76  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 
86  {
87  if ( m_Pointer->GetLambda() == rhs->m_Pointer->GetLambda() )
88  {
89  if ( m_Pointer->GetLambda() < 0 )
90  {
91  return ( m_Pointer > rhs->m_Pointer );
92  }
93  else
94  {
95  // The purpose of this comparison is to not let any one region
96  // get more borders than another region. In the degenerate
97  // case of an image where the Lambdas are always equal to some
98  // constant C, allowing a single region to be repeatedly
99  // merged so that it gains many borders will result in
100  // pathologically slow behavior.
101  double v1 = vnl_math_max(
102  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
103  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
104 
105  double v2 = vnl_math_max(
106  static_cast< double >( rhs->m_Pointer->GetRegion1()->GetRegionBorderSize() ),
107  static_cast< double >( rhs->m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
108 
109  return ( v1 > v2 );
110  }
111  }
112  return ( m_Pointer->GetLambda() > rhs->m_Pointer->GetLambda() );
113  }
114 
115  TBorder *m_Pointer;
116 };
117 
138 
139 class ITKKLMRegionGrowing_EXPORT KLMSegmentationBorder:public SegmentationBorder
140 {
141 public:
147 
149  itkNewMacro(Self);
150 
153 
155  void SetRegion1(KLMSegmentationRegion *Region1);
156 
158  KLMSegmentationRegion * GetRegion1();
159 
161  void SetRegion2(KLMSegmentationRegion *Region2);
162 
164  KLMSegmentationRegion * GetRegion2();
165 
168  itkSetMacro(Lambda, double);
169  itkGetConstReferenceMacro(Lambda, double);
171 
173  void EvaluateLambda();
174 
176  void PrintBorderInfo();
177 
178 protected:
181 
184 
186  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
187 
188 private:
189  KLMSegmentationBorder(const Self &) ITK_DELETE_FUNCTION;
190  void operator=(const Self &) ITK_DELETE_FUNCTION;
191 
192  double m_Lambda;
195 };
196 } // end namespace itk
197 
198 #endif
Base class for KLMSegmentationRegion object.
Light weight base class for most itk classes.
bool operator>(const KLMDynamicBorderArray< TBorder > &rhs) const
SmartPointer< const Self > ConstPointer
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:665
bool operator>(const KLMDynamicBorderArray< TBorder > *rhs) const
Base class for KLMSegmentationBorder object.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for SegmentationBorder object.
Object maintaining a reference to a list of borders associated with a region.