ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLevelSetBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkLevelSetBase_h
20 #define itkLevelSetBase_h
21 
22 #include <utility>
23 
24 #include "itkIntTypes.h"
25 #include "itkCovariantVector.h"
26 #include "itkMatrix.h"
27 #include "itkNumericTraits.h"
28 #include "itkDataObject.h"
29 
30 namespace itk
31 {
42 template< typename TInput, unsigned int VDimension, typename TOutput, typename TDomain >
43 class ITK_TEMPLATE_EXPORT LevelSetBase : public DataObject
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetBase);
47 
48  using Self = LevelSetBase;
52 
54  itkTypeMacro ( LevelSetBase, DataObject );
55 
56  static constexpr unsigned int Dimension = VDimension;
57 
58  using InputType = TInput;
59  using OutputType = TOutput;
60  using DomainType = TDomain;
64 
67 
69  virtual OutputType Evaluate( const InputType& iP ) const = 0;
70 
72  virtual GradientType EvaluateGradient( const InputType& iP ) const = 0;
73 
75  virtual HessianType EvaluateHessian( const InputType& iP ) const = 0;
76 
77  virtual OutputRealType EvaluateLaplacian( const InputType& iP ) const = 0;
78  virtual OutputRealType EvaluateGradientNorm( const InputType& iP ) const;
79  virtual OutputRealType EvaluateMeanCurvature( const InputType& iP ) const = 0;
80 
88  template< typename T >
89  class ITK_TEMPLATE_EXPORT DataType
90  {
91  public:
92  DataType( std::string iName ) :
93  m_Name(std::move( iName )), m_Computed( false )
94  {}
95  DataType( const DataType& iData ) : m_Name( iData.m_Name ),
96  m_Value( iData.m_Value ), m_Computed( iData.m_Computed )
97  {}
98 
99  ~DataType() = default;
100 
101  std::string m_Name;
104 
105  void operator =( const DataType& iData )
106  {
107  this->m_Name = iData.m_Name;
108  this->m_Value = iData.m_Value;
109  this->m_Computed = iData.m_Computed;
110  }
111 
112  private:
113  DataType() = delete;
114  };
115 
121  {
122  LevelSetDataType() : Value( "Value" ), Gradient( "Gradient" ),
123  Hessian( "Hessian" ), Laplacian( "Laplacian" ),
124  GradientNorm( "GradientNorm" ), MeanCurvature( "MeanCurvature" ),
125  ForwardGradient( "ForwardGradient" ), BackwardGradient( "BackwardGradient" )
126  {
127  Value.m_Value = NumericTraits< OutputType >::ZeroValue();
128  Gradient.m_Value.Fill( NumericTraits< OutputRealType >::ZeroValue() );
129  Hessian.m_Value.Fill( NumericTraits< OutputRealType >::ZeroValue() );
130  Laplacian.m_Value = NumericTraits< OutputRealType >::ZeroValue();
131  GradientNorm.m_Value = NumericTraits< OutputRealType >::ZeroValue();
132  MeanCurvature.m_Value = NumericTraits< OutputRealType >::ZeroValue();
133  ForwardGradient.m_Value.Fill( NumericTraits< OutputRealType >::ZeroValue() );
134  BackwardGradient.m_Value.Fill( NumericTraits< OutputRealType >::ZeroValue() );
135  }
137 
138  LevelSetDataType( const LevelSetDataType& iData ) : Value( iData.Value ),
139  Gradient( iData.Gradient ), Hessian( iData.Hessian ),
140  Laplacian( iData.Laplacian ), GradientNorm( iData.GradientNorm ),
141  MeanCurvature( iData.MeanCurvature ), ForwardGradient( iData.ForwardGradient ),
142  BackwardGradient( iData.BackwardGradient ) {}
143 
144  ~LevelSetDataType() = default;
145 
146  void operator = ( const LevelSetDataType& iData )
147  {
148  Value = iData.Value;
149  Gradient = iData.Gradient;
150  Hessian = iData.Hessian;
151  Laplacian = iData.Laplacian;
152  GradientNorm = iData.GradientNorm;
153  MeanCurvature = iData.MeanCurvature;
154  ForwardGradient = iData.ForwardGradient;
155  BackwardGradient = iData.BackwardGradient;
156  }
157 
167  };
168 
169  virtual void Evaluate( const InputType& iP, LevelSetDataType& ioData ) const = 0;
170  virtual void EvaluateGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
171  virtual void EvaluateHessian( const InputType& iP, LevelSetDataType& ioData ) const = 0;
172  virtual void EvaluateLaplacian( const InputType& iP, LevelSetDataType& ioData ) const = 0;
173  virtual void EvaluateGradientNorm( const InputType& iP, LevelSetDataType& ioData ) const;
174  virtual void EvaluateMeanCurvature( const InputType& iP, LevelSetDataType& ioData ) const;
175  virtual void EvaluateForwardGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
176  virtual void EvaluateBackwardGradient( const InputType& iP, LevelSetDataType& ioData ) const = 0;
177 
179  virtual bool IsInside( const InputType& iP ) const;
180 
183  itkGetConstMacro(MaximumNumberOfRegions, RegionType);
184 
186  void Initialize() override;
187 
189  void UpdateOutputInformation() override;
190 
191  void SetRequestedRegionToLargestPossibleRegion() override;
192 
193  void CopyInformation(const DataObject *data) override;
194 
195  void Graft(const DataObject *data) override;
196 
197  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
198 
199  bool VerifyRequestedRegion() override;
200 
205  void SetRequestedRegion( const DataObject *data) override;
206 
208  virtual void SetRequestedRegion(const RegionType & region);
209 
210  itkGetConstMacro(RequestedRegion, RegionType);
211 
213  virtual void SetBufferedRegion(const RegionType & region);
214 
215  itkGetConstMacro(BufferedRegion, RegionType);
216 
217 protected:
218  LevelSetBase();
219  ~LevelSetBase() override = default;
220 
221  // If the RegionType is ITK_UNSTRUCTURED_REGION, then the following
222  // variables represent the maximum number of region that the data
223  // object can be broken into, which region out of how many is
224  // currently in the buffered region, and the number of regions and
225  // the specific region requested for the update. Data objects that
226  // do not support any division of the data can simply leave the
227  // MaximumNumberOfRegions as 1. The RequestedNumberOfRegions and
228  // RequestedRegion are used to define the currently requested
229  // region. The LargestPossibleRegion is always requested region = 0
230  // and number of regions = 1;
231  RegionType m_MaximumNumberOfRegions{0};
232  RegionType m_NumberOfRegions{0};
233  RegionType m_RequestedNumberOfRegions{0};
234  RegionType m_BufferedRegion{0};
235  RegionType m_RequestedRegion{0};
236 };
237 }
238 
239 #ifndef ITK_MANUAL_INSTANTIATION
240 #include "itkLevelSetBase.hxx"
241 #endif
242 
243 #endif // itkLevelSetBase_h
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:49
DataType(std::string iName)
Define numeric traits for std::vector.
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
DataType< OutputRealType > Laplacian
Abstract base class for the representation of a level-set function.
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:41
DataType< OutputRealType > GradientNorm
DataType< OutputRealType > MeanCurvature
DataType< GradientType > Gradient
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
Convenient data structure to cache computed characteristics.
LevelSetDataType(const LevelSetDataType &iData)
DataType(const DataType &iData)
Base class for templated image classes.
Definition: itkImageBase.h:105
DataType< GradientType > ForwardGradient
Base class for most ITK classes.
Definition: itkObject.h:60
Internal class used for one computed characteritic.
A templated class holding a n-Dimensional covariant vector.
DataType< GradientType > BackwardGradient
Base class for all data objects in ITK.