ITK  4.6.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 
25 #include "vnl/vnl_math.h"
26 #include "vnl/vnl_vector.h"
27 
28 namespace itk
29 {
41 template< typename TBorder >
43 {
44 public:
53  {
54  if ( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() )
55  {
56  if ( m_Pointer->GetLambda() < 0 )
57  {
58  return ( m_Pointer > rhs.m_Pointer );
59  }
60  else
61  {
62  // The purpose of this comparison is to not let any one region
63  // get more borders than another region. In the degenerate
64  // case of an image where the Lambdas are always equal to some
65  // constant C, allowing a single region to be repeatedly
66  // merged so that it gains many borders will result in
67  // pathologically slow behavior.
68  double v1 = vnl_math_max(
69  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
70  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
72 
73  double v2 = vnl_math_max(
74  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 
84  {
85  if ( m_Pointer->GetLambda() == rhs->m_Pointer->GetLambda() )
86  {
87  if ( m_Pointer->GetLambda() < 0 )
88  {
89  return ( m_Pointer > rhs->m_Pointer );
90  }
91  else
92  {
93  // The purpose of this comparison is to not let any one region
94  // get more borders than another region. In the degenerate
95  // case of an image where the Lambdas are always equal to some
96  // constant C, allowing a single region to be repeatedly
97  // merged so that it gains many borders will result in
98  // pathologically slow behavior.
99  double v1 = vnl_math_max(
100  static_cast< double >( m_Pointer->GetRegion1()->GetRegionBorderSize() ),
101  static_cast< double >( m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
102 
103  double v2 = vnl_math_max(
104  static_cast< double >( rhs->m_Pointer->GetRegion1()->GetRegionBorderSize() ),
105  static_cast< double >( rhs->m_Pointer->GetRegion2()->GetRegionBorderSize() ) );
106 
107  return ( v1 > v2 );
108  }
109  }
110  return ( m_Pointer->GetLambda() > rhs->m_Pointer->GetLambda() );
111  }
112 
113  TBorder *m_Pointer;
114 };
115 
136 
138 {
139 public:
145 
147  itkNewMacro(Self);
148 
151 
153  void SetRegion1(KLMSegmentationRegion *Region1);
154 
157 
159  void SetRegion2(KLMSegmentationRegion *Region2);
160 
163 
166  itkSetMacro(Lambda, double);
167  itkGetConstReferenceMacro(Lambda, double);
169 
171  void EvaluateLambda();
172 
174  void PrintBorderInfo();
175 
176 protected:
179 
182 
184  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
185 
186 private:
187  KLMSegmentationBorder(const Self &); //purposely not implemented
188  void operator=(const Self &); //purposely not implemented
189 
190  double m_Lambda;
193 };
194 } // end namespace itk
195 
196 #endif
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
Base class for KLMSegmentationRegion object.
void SetRegion1(KLMSegmentationRegion *Region1)
Light weight base class for most itk classes.
KLMSegmentationRegion * m_Region1
bool operator>(const KLMDynamicBorderArray< TBorder > &rhs) const
void SetRegion2(KLMSegmentationRegion *Region2)
SmartPointer< const Self > ConstPointer
KLMSegmentationRegion * GetRegion1()
KLMSegmentationRegion * GetRegion2()
bool operator>(const KLMDynamicBorderArray< TBorder > *rhs) const
void operator=(const Self &)
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.