KWStyle - itkKLMSegmentationBorder.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkKLMSegmentationBorder.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:40 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkKLMSegmentationBorder_h
18 DEF #define _itkKLMSegmentationBorder_h
19
20 #include "itkObject.h"
21 #include "itkSegmentationBorder.h"
22
23 #include "itkKLMSegmentationRegion.h"
24 #include "itkExceptionObject.h"
25
26 #include "vnl/vnl_math.h"
27 #include "vnl/vnl_vector.h"
28
29 namespace itk
30 {
31
32 /** \class KLMDynamicBorderArray
33  * \brief  Object maintaining a reference to a list of borders associated
34  * with a region.
35  *
36  * This is a tiny class similar to smart pointers that maintains a reference
37  * to a list of borders pointed by a region.
38  *
39  * \ingroup RegionGrowingSegmentation
40  */
41 template <class TBorder>
42 class KLMDynamicBorderArray
43 {
44 public:
45   /** Greater than operators defined to work with both static objects
46    * or pointer to objects.  In the degenerate
47    *  case of an image where all (or many) Lambda's are equal to some
48    *  constant value, this operator will ensure that the future
49    *  merged regions do not gain more borders than other regions,
50    *  thus avoiding pathologically slow behavior.
51    */
52   bool operator> (const KLMDynamicBorderArray<TBorder>& rhs) const
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         unsigned int v1 = vnl_math_max(
69           m_Pointer->GetRegion1()->GetRegionBorderSize(),
70 IND **********m_Pointer->GetRegion2()->GetRegionBorderSize() );
71
72         unsigned int v2 = vnl_math_max(
73           rhs.m_Pointer->GetRegion1()->GetRegionBorderSize(),
74 IND **********rhs.m_Pointer->GetRegion2()->GetRegionBorderSize() );
75
76         return ( v1 > v2 );
77         }
78       }
79     return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() );
80     }
81
82   bool operator> (const KLMDynamicBorderArray<TBorder>* rhs) const
83     {
84     if( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() )
85       {
86       if( m_Pointer->GetLambda() < 0 )
87         {
88         return ( m_Pointer > rhs.m_Pointer );
89         }
90       else
91         {
92         // The purpose of this comparison is to not let any one region
93         // get more borders than another region.  In the degenerate
94         // case of an image where the Lambdas are always equal to some
95         // constant C, allowing a single region to be repeatedly
96         // merged so that it gains many borders will result in
97         // pathologically slow behavior.
98         unsigned int v1 = vnl_math_max(
99           m_Pointer->GetRegion1()->GetRegionBorderSize(),
100 IND **********m_Pointer->GetRegion2()->GetRegionBorderSize() );
101
102         unsigned int v2 = vnl_math_max(
103           rhs.m_Pointer->GetRegion1()->GetRegionBorderSize(),
104 IND **********rhs.m_Pointer->GetRegion2()->GetRegionBorderSize() );
105
106         return ( v1 > v2 );
107         }
108       }
109     return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() );
110     }
111
112   TBorder *m_Pointer;
113 };
114
115 /** \class KLMSegmentationBorder
116  * \brief Base class for KLMSegmentationBorder object
117  *
118  * itkKLMSegmentationBorder is the base class for the KLMSegmentationBorder
119  * objects. It provides the basic function definitons that are inherent to a
120  * KLMSegmentationBorder objects.
121  *
122  * This class implements the border object that is used in particular with
123  * the KLM algorithm (see also KLMRegionGrowImageFilter). The border is
124  * defined by the adjacency of two regions. The parameter Lambda ascertains
125  * the importance of the border in defining the regions. The higher the
126  * values of Lambda the more dominant is its presence in the a region. In
127  * case of removal of a border during the region growing process the one with
128  * least Lambda value is eliminated.
129  *
130  * \ingroup RegionGrowingSegmentation
131  */
132
133 class KLMSegmentationRegion;
134
135 class ITKCommon_EXPORT KLMSegmentationBorder : public SegmentationBorder
136 {
137
138 public:
139   /** Standard class typedefs. */
140   typedef KLMSegmentationBorder   Self;
141 TDA   typedef SegmentationBorder Superclass;
142 TDA   typedef SmartPointer<Self>  Pointer;
143 TDA   typedef SmartPointer<const Self>  ConstPointer;
144
145   /** Method for creation through the object factory. */
146   itkNewMacro(Self);
147
148   /** Run-time type information (and related methods). */
149   itkTypeMacro(KLMSegmentationBorder,SegmentationBorder);
150
151   /** Set the region 1 associated with the border */
152   void SetRegion1(KLMSegmentationRegion *Region1);
153
154   /** Get the region 1 associated with the border. */
155   KLMSegmentationRegion *GetRegion1();
156
157   /** Set the region 2 associated with the border. */
158   void SetRegion2(KLMSegmentationRegion *Region2);
159
160   /** Get the region 2 associated with the border. */
161   KLMSegmentationRegion *GetRegion2();
162
163   /** Set/Get the Lambda parameter associate with the borders
164    * in the KLM algorithm */
165   itkSetMacro(Lambda, double);
166   itkGetConstReferenceMacro(Lambda, double);
167
168   /** Evaluate the Lambda for a given border. */
169   void EvaluateLambda();
170
171   /** Print the data associated with each border. */
172   void PrintBorderInfo();
173
174 protected:
175   /** Constructor. */
176   KLMSegmentationBorder();
177
178   /** Destructor. */
179   ~KLMSegmentationBorder();
180
181   /** Print self identity */
182   void PrintSelf(std::ostream& os, Indent indent) const;
183
184 private:
185   KLMSegmentationBorder(const Self&); //purposely not implemented
186   void operator=(const Self&); //purposely not implemented
187
188   double m_Lambda;
189   KLMSegmentationRegion *m_Region1;
190   KLMSegmentationRegion *m_Region2;
191
192 }; // class KLMSegmentationBorder
193
194
195 // namespace itk
196
197
198 #endif
199

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:18PM
© Kitware Inc.