00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkKLMSegmentationBorder.h,v $ 00005 Language: C++ 00006 Date: $Date: 2004/11/04 20:40:40 $ 00007 Version: $Revision: 1.9 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef _itkKLMSegmentationBorder_h 00018 #define _itkKLMSegmentationBorder_h 00019 00020 #include "itkObject.h" 00021 #include "itkSegmentationBorder.h" 00022 00023 #include "itkKLMSegmentationRegion.h" 00024 #include "itkExceptionObject.h" 00025 00026 #include "vnl/vnl_math.h" 00027 #include "vnl/vnl_vector.h" 00028 00029 namespace itk 00030 { 00031 00041 template <class TBorder> 00042 class KLMDynamicBorderArray 00043 { 00044 public: 00052 bool operator> (const KLMDynamicBorderArray<TBorder>& rhs) const 00053 { 00054 if( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() ) 00055 { 00056 if( m_Pointer->GetLambda() < 0 ) 00057 { 00058 return ( m_Pointer > rhs.m_Pointer ); 00059 } 00060 else 00061 { 00062 // The purpose of this comparison is to not let any one region 00063 // get more borders than another region. In the degenerate 00064 // case of an image where the Lambdas are always equal to some 00065 // constant C, allowing a single region to be repeatedly 00066 // merged so that it gains many borders will result in 00067 // pathologically slow behavior. 00068 unsigned int v1 = vnl_math_max( 00069 m_Pointer->GetRegion1()->GetRegionBorderSize(), 00070 m_Pointer->GetRegion2()->GetRegionBorderSize() ); 00071 00072 unsigned int v2 = vnl_math_max( 00073 rhs.m_Pointer->GetRegion1()->GetRegionBorderSize(), 00074 rhs.m_Pointer->GetRegion2()->GetRegionBorderSize() ); 00075 00076 return ( v1 > v2 ); 00077 } 00078 } 00079 return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() ); 00080 } 00081 00082 bool operator> (const KLMDynamicBorderArray<TBorder>* rhs) const 00083 { 00084 if( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() ) 00085 { 00086 if( m_Pointer->GetLambda() < 0 ) 00087 { 00088 return ( m_Pointer > rhs.m_Pointer ); 00089 } 00090 else 00091 { 00092 // The purpose of this comparison is to not let any one region 00093 // get more borders than another region. In the degenerate 00094 // case of an image where the Lambdas are always equal to some 00095 // constant C, allowing a single region to be repeatedly 00096 // merged so that it gains many borders will result in 00097 // pathologically slow behavior. 00098 unsigned int v1 = vnl_math_max( 00099 m_Pointer->GetRegion1()->GetRegionBorderSize(), 00100 m_Pointer->GetRegion2()->GetRegionBorderSize() ); 00101 00102 unsigned int v2 = vnl_math_max( 00103 rhs.m_Pointer->GetRegion1()->GetRegionBorderSize(), 00104 rhs.m_Pointer->GetRegion2()->GetRegionBorderSize() ); 00105 00106 return ( v1 > v2 ); 00107 } 00108 } 00109 return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() ); 00110 } 00111 00112 TBorder *m_Pointer; 00113 }; 00114 00133 class KLMSegmentationRegion; 00134 00135 class ITKCommon_EXPORT KLMSegmentationBorder : public SegmentationBorder 00136 { 00137 00138 public: 00140 typedef KLMSegmentationBorder Self; 00141 typedef SegmentationBorder Superclass; 00142 typedef SmartPointer<Self> Pointer; 00143 typedef SmartPointer<const Self> ConstPointer; 00144 00146 itkNewMacro(Self); 00147 00149 itkTypeMacro(KLMSegmentationBorder,SegmentationBorder); 00150 00152 void SetRegion1(KLMSegmentationRegion *Region1); 00153 00155 KLMSegmentationRegion *GetRegion1(); 00156 00158 void SetRegion2(KLMSegmentationRegion *Region2); 00159 00161 KLMSegmentationRegion *GetRegion2(); 00162 00165 itkSetMacro(Lambda, double); 00166 itkGetConstReferenceMacro(Lambda, double); 00167 00169 void EvaluateLambda(); 00170 00172 void PrintBorderInfo(); 00173 00174 protected: 00176 KLMSegmentationBorder(); 00177 00179 ~KLMSegmentationBorder(); 00180 00182 void PrintSelf(std::ostream& os, Indent indent) const; 00183 00184 private: 00185 KLMSegmentationBorder(const Self&); //purposely not implemented 00186 void operator=(const Self&); //purposely not implemented 00187 00188 double m_Lambda; 00189 KLMSegmentationRegion *m_Region1; 00190 KLMSegmentationRegion *m_Region2; 00191 00192 }; // class KLMSegmentationBorder 00193 00194 00195 } // namespace itk 00196 00197 00198 #endif