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 #ifndef itkGaussianDerivativeSpatialFunction_h
19 #define itkGaussianDerivativeSpatialFunction_h
20 
21 #include "itkSpatialFunction.h"
22 #include "itkFixedArray.h"
23 
24 namespace itk
25 {
26 /** \class GaussianDerivativeSpatialFunction
27  * \brief N-dimensional Gaussian spatial function class
28  *
29  * GaussianDerivativeSpatialFunction implements a standard derivative of Gaussian
30  * curve in N-d.
31  * m_Normalized determines whether or not the Derivative of the Gaussian
32  * is normalized (whether or not the sum over infinite space is 1.0).
33  *
34  * m_Scale scales the output of the Gaussian to span a range
35  * larger than 0->1, and is often set to the maximum value
36  * of the output data type (for instance, 255 for uchars).
37  *
38  * \ingroup SpatialFunctions
39  * \ingroup ITKCommon
40  */
41 template< typename TOutput = double,
42           unsigned int VImageDimension = 3,
43           typename TInput = Point< double, VImageDimension > >
44 class ITK_TEMPLATE_EXPORT GaussianDerivativeSpatialFunction:public SpatialFunction< TOutput, VImageDimension, TInput >
45 {
46 public:
47   ITK_DISALLOW_COPY_AND_ASSIGN(GaussianDerivativeSpatialFunction);
48 
49   /** Standard class type aliases. */
50   using Self = GaussianDerivativeSpatialFunction;
51   using Superclass = SpatialFunction< TOutput, VImageDimension, TInput >;
52   using Pointer = SmartPointer< Self >;
53   using ConstPointer = SmartPointer< const Self >;
54 
55   /** Method for creation through the object factory. */
56   itkNewMacro(Self);
57 
58   /** Run-time type information (and related methods). */
59   itkTypeMacro(GaussianDerivativeSpatialFunction, SpatialFunction);
60 
61   /** Input type for the function. */
62   using InputType = typename Superclass::InputType;
63 
64   /** Output type for the function. */
65   using OutputType = typename Superclass::OutputType;
66 
67   /** Type used to store derivatives parameters. */
68   using ArrayType = FixedArray< double, VImageDimension >;
69 
70   /** Type used to return the derivatives in each direction */
71   using VectorType = Vector< double, VImageDimension >;
72 
73   /** Evaluate the function at a given position and return the
74    *  value in the specific direction. SetDirection() should be used
75    *  to set the direction. */
76   OutputType Evaluate(const TInput & position) const override;
77 
78   /** Evaluate the function at a given position and return a vector */
79   VectorType EvaluateVector(const TInput & position) const;
80 
81   /** Gets and sets for gaussian parameters */
82   itkSetMacro(Scale, double);
83   itkGetConstMacro(Scale, double);
84   itkSetMacro(Normalized, bool);
85   itkGetConstMacro(Normalized, bool);
86   itkSetMacro(Sigma, ArrayType);
87   itkGetConstMacro(Sigma, ArrayType);
88   itkSetMacro(Mean, ArrayType);
89   itkGetConstMacro(Mean, ArrayType);
90   itkSetMacro(Direction, unsigned int);
91   itkGetConstMacro(Direction, unsigned int);
92 
93 protected:
94   GaussianDerivativeSpatialFunction();
95   ~GaussianDerivativeSpatialFunction() override = default;
96   void PrintSelf(std::ostream & os, Indent indent) const override;
97 
98 private:
99   /** Current direction */
100   mutable unsigned int m_Direction;
101 
102   /** The standard deviation in each direction. */
103   ArrayType m_Sigma;
104 
105   /** The mean in each direction. */
106   ArrayType m_Mean;
107 
108   /** A scale factor multiplied by the true value of the Gaussian. */
109   double m_Scale;
110 
111   /** Whether or not to normalize the Gaussian. */
112   bool m_Normalized;
113 };
114 } // end namespace itk
115 
116 #ifndef ITK_MANUAL_INSTANTIATION
117 #include "itkGaussianDerivativeSpatialFunction.hxx"
118 #endif
119 
120 #endif
121