ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkKLMSegmentationBorder.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkKLMSegmentationBorder_h
00019 #define __itkKLMSegmentationBorder_h
00020 
00021 #include "itkSegmentationBorder.h"
00022 #include "itkKLMSegmentationRegion.h"
00023 #include "itkMacro.h"
00024 
00025 #include "vnl/vnl_math.h"
00026 #include "vnl/vnl_vector.h"
00027 
00028 namespace itk
00029 {
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 
00135 class KLMSegmentationRegion;
00136 
00137 class ITK_EXPORT KLMSegmentationBorder:public SegmentationBorder
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 } // end namespace itk
00195 
00196 #endif
00197