00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkKLMSegmentationBorder.h,v $ 00005 Language: C++ 00006 Date: $Date: 2007/12/29 13:14:32 $ 00007 Version: $Revision: 1.14 $ 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 #include "itkKLMSegmentationRegion.h" 00023 #include "itkExceptionObject.h" 00024 00025 #include "vnl/vnl_math.h" 00026 #include "vnl/vnl_vector.h" 00027 00028 namespace itk 00029 { 00030 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 double v1 = vnl_math_max( 00069 static_cast< double>(m_Pointer->GetRegion1()->GetRegionBorderSize()), 00070 static_cast< double>(m_Pointer->GetRegion2()->GetRegionBorderSize() )); 00072 00073 double v2 = vnl_math_max( 00074 static_cast< double>(rhs.m_Pointer->GetRegion1()->GetRegionBorderSize()), 00075 static_cast< double>(rhs.m_Pointer->GetRegion2()->GetRegionBorderSize()) ); 00076 00077 return ( v1 > v2 ); 00078 } 00079 } 00080 return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() ); 00081 } 00082 00083 bool operator> (const KLMDynamicBorderArray<TBorder>* rhs) const 00084 { 00085 if( m_Pointer->GetLambda() == rhs.m_Pointer->GetLambda() ) 00086 { 00087 if( m_Pointer->GetLambda() < 0 ) 00088 { 00089 return ( m_Pointer > rhs.m_Pointer ); 00090 } 00091 else 00092 { 00093 // The purpose of this comparison is to not let any one region 00094 // get more borders than another region. In the degenerate 00095 // case of an image where the Lambdas are always equal to some 00096 // constant C, allowing a single region to be repeatedly 00097 // merged so that it gains many borders will result in 00098 // pathologically slow behavior. 00099 double v1 = vnl_math_max( 00100 static_cast< double>(m_Pointer->GetRegion1()->GetRegionBorderSize()), 00101 static_cast< double>(m_Pointer->GetRegion2()->GetRegionBorderSize() )); 00102 00103 double v2 = vnl_math_max( 00104 static_cast< double>(rhs.m_Pointer->GetRegion1()->GetRegionBorderSize()), 00105 static_cast< double>(rhs.m_Pointer->GetRegion2()->GetRegionBorderSize()) ); 00106 00107 return ( v1 > v2 ); 00108 } 00109 } 00110 return(m_Pointer->GetLambda() > rhs.m_Pointer->GetLambda() ); 00111 } 00112 00113 TBorder *m_Pointer; 00114 }; 00115 00134 class KLMSegmentationRegion; 00135 00136 class ITKCommon_EXPORT KLMSegmentationBorder : public SegmentationBorder 00137 { 00138 00139 public: 00141 typedef KLMSegmentationBorder Self; 00142 typedef SegmentationBorder Superclass; 00143 typedef SmartPointer<Self> Pointer; 00144 typedef SmartPointer<const Self> ConstPointer; 00145 00147 itkNewMacro(Self); 00148 00150 itkTypeMacro(KLMSegmentationBorder,SegmentationBorder); 00151 00153 void SetRegion1(KLMSegmentationRegion *Region1); 00154 00156 KLMSegmentationRegion *GetRegion1(); 00157 00159 void SetRegion2(KLMSegmentationRegion *Region2); 00160 00162 KLMSegmentationRegion *GetRegion2(); 00163 00166 itkSetMacro(Lambda, double); 00167 itkGetConstReferenceMacro(Lambda, double); 00169 00171 void EvaluateLambda(); 00172 00174 void PrintBorderInfo(); 00175 00176 protected: 00178 KLMSegmentationBorder(); 00179 00181 ~KLMSegmentationBorder(); 00182 00184 void PrintSelf(std::ostream& os, Indent indent) const; 00185 00186 private: 00187 KLMSegmentationBorder(const Self&); //purposely not implemented 00188 void operator=(const Self&); //purposely not implemented 00189 00190 double m_Lambda; 00191 KLMSegmentationRegion *m_Region1; 00192 KLMSegmentationRegion *m_Region2; 00193 00194 }; 00195 00196 00197 } // end namespace itk 00198 00199 00200 #endif 00201