ITK  4.8.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 
29 namespace itk
30 {
42 template< typename TBorder >
44 {
45 public:
54  {
55  if ( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() )
56  {
57  if ( m_Pointer->GetLambda() < 0 )
58  {
59  return ( m_Pointer > rhs.m_Pointer );
60  }
61  else
62  {
63  // The purpose of this comparison is to not let any one region
64  // get more borders than another region. In the degenerate
65  // case of an image where the Lambdas are always equal to some
66  // constant C, allowing a single region to be repeatedly
67  // merged so that it gains many borders will result in
68  // pathologically slow behavior.
69  double v1 = vnl_math_max(
70  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
71  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
73 
74  double v2 = vnl_math_max(
75  static_cast< double >( rhs.m_Pointer->GetRegion1()->GetRegionBorderSize() ),
76  static_cast< double >( rhs.m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
77 
78  return ( v1 > v2 );
79  }
80  }
81  return ( m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() );
82  }
83 
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 = vnl_math_max(
101  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
102  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
103 
104  double v2 = vnl_math_max(
105  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 
138 class ITKKLMRegionGrowing_EXPORT KLMSegmentationBorder:public SegmentationBorder
139 {
140 public:
146 
148  itkNewMacro(Self);
149 
152 
154  void SetRegion1(KLMSegmentationRegion *Region1);
155 
157  KLMSegmentationRegion * GetRegion1();
158 
160  void SetRegion2(KLMSegmentationRegion *Region2);
161 
163  KLMSegmentationRegion * GetRegion2();
164 
167  itkSetMacro(Lambda, double);
168  itkGetConstReferenceMacro(Lambda, double);
170 
172  void EvaluateLambda();
173 
175  void PrintBorderInfo();
176 
177 protected:
180 
183 
185  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
186 
187 private:
188  KLMSegmentationBorder(const Self &); //purposely not implemented
189  void operator=(const Self &); //purposely not implemented
190 
191  double m_Lambda;
194 };
195 } // end namespace itk
196 
197 #endif
Base class for KLMSegmentationRegion object.
Light weight base class for most itk classes.
KLMSegmentationRegion * m_Region1
bool operator>(const KLMDynamicBorderArray< TBorder > &rhs) const
SmartPointer< const Self > ConstPointer
bool operator>(const KLMDynamicBorderArray< TBorder > *rhs) const
KLMSegmentationRegion * m_Region2
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.