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 itkConicShellInteriorExteriorSpatialFunction_h
19 #define itkConicShellInteriorExteriorSpatialFunction_h
20 
21 #include "vnl/vnl_vector.h"
22 #include "itkInteriorExteriorSpatialFunction.h"
23 #include "itkCovariantVector.h"
24 
25 namespace itk
26 {
27 /**
28  * \class ConicShellInteriorExteriorSpatialFunction
29  * \brief Spatial function implementation of a conic shell
30  *
31  * We are creating search areas from BoundaryPoint1 in which to look for
32  * candidate BoundaryPoint2's with which to form core atoms.  Assume the
33  * "worst case" that BoundaryPoint2 is somewhere in that search area pointing
34  * directly at BoundaryPoint1.
35  *
36  * The search area (ConicShell?) from each BoundaryPoint1 has the following
37  * parameters:
38  *
39  * DistanceMax and DistanceMin from the location of the BoundaryPoint
40  *
41  * AngleMax from the line along the gradient at the boundary point.
42  * This is determined in n dimensions by taking the dot product of two vectors,
43  * (1) the normalized gradient at BoundaryPoint1 and
44  * (2) the normalized vector from BoundaryPoint1 to BoundaryPoint2.
45  *
46  * If the absolute value of that dot product is greater than (1 - epsilon)
47  * then you are in the ConicShell. This epsilon is the same one determining
48  * face-to-faceness in the IEEE TMI paper.
49  *
50  * The polarity indicates which direction along the gradient of BoundaryPoint1
51  * the function is to be evaluated.
52  *
53  * \ingroup SpatialFunctions
54  *
55  *
56  * \ingroup ITKCommon
57  */
58 
59 template< unsigned int VDimension = 3,
60           typename TInput = Point< double, VDimension > >
61 class ITK_TEMPLATE_EXPORT ConicShellInteriorExteriorSpatialFunction:
62   public InteriorExteriorSpatialFunction< VDimension, TInput >
63 {
64 public:
65   ITK_DISALLOW_COPY_AND_ASSIGN(ConicShellInteriorExteriorSpatialFunction);
66 
67   /** Standard class type aliases. */
68   using Self = ConicShellInteriorExteriorSpatialFunction;
69   using Superclass = InteriorExteriorSpatialFunction< VDimension, TInput >;
70   using Pointer = SmartPointer< Self >;
71   using ConstPointer = SmartPointer< const Self >;
72 
73   /** Run time information. */
74   itkTypeMacro(ConicShellInteriorExteriorSpatialFunction,
75                InteriorExteriorSpatialFunction);
76 
77   /** Method for creation through the object factory. */
78   itkNewMacro(Self);
79 
80   /** Input type for the function. */
81   using InputType = typename Superclass::InputType;
82 
83   /** Output type for the function. */
84   using OutputType = typename Superclass::OutputType;
85 
86   /** The type of vector used to store the gradient info. */
87   using GradientType = CovariantVector< double, VDimension >;
88 
89   /** Evaluates the function at a given position. */
90   OutputType Evaluate(const InputType & position) const override;
91 
92   /** Set/Get the origin of the function. */
93   itkGetConstMacro(Origin, InputType);
94   itkSetMacro(Origin, InputType);
95 
96   /** Set/Get the gradient at the origin of the function. */
GetOriginGradient()97   GradientType GetOriginGradient() { return m_OriginGradient; }
98   void SetOriginGradient(GradientType grad);
99 
100   /** Set/Get the minimum search distance. */
101   itkGetConstMacro(DistanceMin, double);
102   itkSetMacro(DistanceMin, double);
103 
104   /** Set/Get the maximum search distance. */
105   itkGetConstMacro(DistanceMax, double);
106   itkSetMacro(DistanceMax, double);
107 
108   /** Set/Get the tolerance of the in/out comparison. */
109   itkGetConstMacro(Epsilon, double);
110   itkSetMacro(Epsilon, double);
111 
112   /** Set/Get direction along the gradient to search.
113    * Set to true to use the direction that the gradient is pointing;
114    * set to false for the opposite direction. Default is Off. */
115   itkGetConstMacro(Polarity, bool);
116   itkSetMacro(Polarity, bool);
117   itkBooleanMacro(Polarity);
118 
119 protected:
120   ConicShellInteriorExteriorSpatialFunction();
121   ~ConicShellInteriorExteriorSpatialFunction() override = default;
122   void PrintSelf(std::ostream & os, Indent indent) const override;
123 
124 private:
125   InputType     m_Origin;
126   GradientType  m_OriginGradient;
127   double        m_DistanceMin{ 0.0 };
128   double        m_DistanceMax{ 0.0 };
129   double        m_Epsilon{ 0.0 };
130   bool          m_Polarity{ false };
131 };
132 } // end namespace itk
133 
134 #ifndef ITK_MANUAL_INSTANTIATION
135 #include "itkConicShellInteriorExteriorSpatialFunction.hxx"
136 #endif
137 
138 #endif
139