ITK  4.13.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 "itkMath.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 = std::max(
71  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
72  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
74 
75  double v2 = std::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 = std::max(
102  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
103  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
104 
105  double v2 = std::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 
137 // Forward reference because of circular dependencies
138 class ITK_FORWARD_EXPORT KLMSegmentationRegion;
139 
140 class ITKKLMRegionGrowing_EXPORT KLMSegmentationBorder:public SegmentationBorder
141 {
142 public:
148 
150  itkNewMacro(Self);
151 
154 
156  void SetRegion1(KLMSegmentationRegion *Region1);
157 
159  KLMSegmentationRegion * GetRegion1();
160 
162  void SetRegion2(KLMSegmentationRegion *Region2);
163 
165  KLMSegmentationRegion * GetRegion2();
166 
169  itkSetMacro(Lambda, double);
170  itkGetConstReferenceMacro(Lambda, double);
172 
174  void EvaluateLambda();
175 
177  void PrintBorderInfo();
178 
179 protected:
182 
184  ~KLMSegmentationBorder() ITK_OVERRIDE;
185 
187  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
188 
189 private:
190  ITK_DISALLOW_COPY_AND_ASSIGN(KLMSegmentationBorder);
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:710
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.
class ITK_FORWARD_EXPORT KLMSegmentationBorder