ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLevelSetBase.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 
00019 #ifndef __itkLevelSetBase_h
00020 #define __itkLevelSetBase_h
00021 
00022 #include "itkIntTypes.h"
00023 #include "itkCovariantVector.h"
00024 #include "itkMatrix.h"
00025 #include "itkNumericTraits.h"
00026 #include "itkDataObject.h"
00027 
00028 namespace itk
00029 {
00040 template< class TInput,
00041           unsigned int VDimension,
00042           typename TOutput,
00043           class TDomain >
00044 class LevelSetBase : public DataObject
00045 {
00046 public:
00047   typedef LevelSetBase               Self;
00048   typedef DataObject                 Superclass;
00049   typedef SmartPointer< Self >       Pointer;
00050   typedef SmartPointer< const Self > ConstPointer;
00051 
00053   itkTypeMacro ( LevelSetBase, DataObject );
00054 
00055   itkStaticConstMacro ( Dimension, unsigned int, VDimension );
00056 
00057   typedef TInput                                           InputType;
00058   typedef TOutput                                          OutputType;
00059   typedef typename NumericTraits< OutputType >::RealType   OutputRealType;
00060   typedef CovariantVector< OutputRealType, VDimension >    GradientType;
00061   typedef Matrix< OutputRealType, VDimension, VDimension > HessianType;
00062 
00063   typedef TDomain DomainType;
00064 
00066   typedef IdentifierType RegionType;
00067 
00069   virtual OutputType    Evaluate( const InputType& iP ) const = 0;
00070 
00072   virtual GradientType  EvaluateGradient( const InputType& iP ) const = 0;
00073 
00075   virtual HessianType   EvaluateHessian( const InputType& iP ) const = 0;
00076 
00077   virtual OutputRealType EvaluateLaplacian( const InputType& iP ) const = 0;
00078   virtual OutputRealType EvaluateGradientNorm( const InputType& iP ) const;
00079   virtual OutputRealType EvaluateMeanCurvature( const InputType& iP ) const = 0;
00080 
00088   template< class T >
00089   class DataType
00090     {
00091     public:
00092       DataType( const std::string& iName ) :
00093         m_Name( iName ), m_Computed( false )
00094         {}
00095       DataType( const DataType& iData ) : m_Name( iData.m_Name ),
00096         m_Value( iData.m_Value ), m_Computed( iData.m_Computed )
00097       {}
00098 
00099       ~DataType() {}
00100 
00101       std::string m_Name;
00102       T           m_Value;
00103       bool        m_Computed;
00104 
00105       void operator =( const DataType& iData )
00106         {
00107         this->m_Name = iData.m_Name;
00108         this->m_Value = iData.m_Value;
00109         this->m_Computed = iData.m_Computed;
00110         }
00111 
00112     private:
00113       DataType();
00114     };
00115 
00120   struct LevelSetDataType
00121     {
00122     LevelSetDataType() : Value( "Value" ), Gradient( "Gradient" ),
00123       Hessian( "Hessian" ), Laplacian( "Laplacian" ),
00124       GradientNorm( "GradientNorm" ), MeanCurvature( "MeanCurvature" ),
00125       ForwardGradient( "ForwardGradient" ), BackwardGradient( "BackwardGradient" )
00126       {
00127       Value.m_Value = NumericTraits< OutputType >::Zero;
00128       Gradient.m_Value.Fill( NumericTraits< OutputRealType >::Zero );
00129       Hessian.m_Value.Fill( NumericTraits< OutputRealType >::Zero );
00130       Laplacian.m_Value = NumericTraits< OutputRealType >::Zero;
00131       GradientNorm.m_Value = NumericTraits< OutputRealType >::Zero;
00132       MeanCurvature.m_Value = NumericTraits< OutputRealType >::Zero;
00133       ForwardGradient.m_Value.Fill( NumericTraits< OutputRealType >::Zero );
00134       BackwardGradient.m_Value.Fill( NumericTraits< OutputRealType >::Zero );
00135       }
00137 
00138     LevelSetDataType( const LevelSetDataType& iData ) : Value( iData.Value ),
00139       Gradient( iData.Gradient ), Hessian( iData.Hessian ),
00140       Laplacian( iData.Laplacian ), GradientNorm( iData.GradientNorm ),
00141       MeanCurvature( iData.MeanCurvature ), ForwardGradient( iData.ForwardGradient ),
00142       BackwardGradient( iData.BackwardGradient ) {}
00143 
00144     ~LevelSetDataType() {}
00145 
00146     void operator = ( const LevelSetDataType& iData )
00147       {
00148       Value = iData.Value;
00149       Gradient = iData.Gradient;
00150       Hessian = iData.Hessian;
00151       Laplacian = iData.Laplacian;
00152       GradientNorm = iData.GradientNorm;
00153       MeanCurvature = iData.MeanCurvature;
00154       ForwardGradient = iData.ForwardGradient;
00155       BackwardGradient = iData.BackwardGradient;
00156       }
00157 
00159     DataType< OutputType >      Value;
00160     DataType< GradientType >    Gradient;
00161     DataType< HessianType >     Hessian;
00162     DataType< OutputRealType >  Laplacian;
00163     DataType< OutputRealType >  GradientNorm;
00164     DataType< OutputRealType >  MeanCurvature;
00165     DataType< GradientType >    ForwardGradient;
00166     DataType< GradientType >    BackwardGradient;
00167     };
00168 
00169   virtual void Evaluate( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00170   virtual void EvaluateGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00171   virtual void EvaluateHessian( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00172   virtual void EvaluateLaplacian( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00173   virtual void EvaluateGradientNorm( const InputType& iP, LevelSetDataType& ioData ) const;
00174   virtual void EvaluateMeanCurvature( const InputType& iP, LevelSetDataType& ioData ) const;
00175   virtual void EvaluateForwardGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00176   virtual void EvaluateBackwardGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
00177 
00179   virtual bool IsInside( const InputType& iP ) const;
00180 
00183   itkGetConstMacro(MaximumNumberOfRegions, RegionType);
00184 
00186   virtual void Initialize();
00187 
00189   virtual void UpdateOutputInformation();
00190 
00191   virtual void SetRequestedRegionToLargestPossibleRegion();
00192 
00193   virtual void CopyInformation(const DataObject *data);
00194 
00195   virtual void Graft(const DataObject *data);
00196 
00197   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00198 
00199   virtual bool VerifyRequestedRegion();
00200 
00205   virtual void SetRequestedRegion( const DataObject *data);
00206 
00208   virtual void SetRequestedRegion(const RegionType & region);
00209 
00210   itkGetConstMacro(RequestedRegion, RegionType);
00211 
00213   virtual void SetBufferedRegion(const RegionType & region);
00214 
00215   itkGetConstMacro(BufferedRegion, RegionType);
00216 
00217 
00218 protected:
00219   LevelSetBase();
00220   virtual ~LevelSetBase() {}
00221 
00222   // If the RegionType is ITK_UNSTRUCTURED_REGION, then the following
00223   // variables represent the maximum number of region that the data
00224   // object can be broken into, which region out of how many is
00225   // currently in the buffered region, and the number of regions and
00226   // the specific region requested for the update. Data objects that
00227   // do not support any division of the data can simply leave the
00228   // MaximumNumberOfRegions as 1. The RequestedNumberOfRegions and
00229   // RequestedRegion are used to define the currently requested
00230   // region. The LargestPossibleRegion is always requested region = 0
00231   // and number of regions = 1;
00232   RegionType m_MaximumNumberOfRegions;
00233   RegionType m_NumberOfRegions;
00234   RegionType m_RequestedNumberOfRegions;
00235   RegionType m_BufferedRegion;
00236   RegionType m_RequestedRegion;
00237 
00238 private:
00239   LevelSetBase( const Self& ); // purposely left unimplemented
00240   void operator = ( const Self& ); // purposely left unimplemented
00241 
00242 };
00243 }
00244 
00245 #ifndef ITK_MANUAL_INSTANTIATION
00246 #include "itkLevelSetBase.hxx"
00247 #endif
00248 
00249 #endif // __itkLevelSetBase_h
00250