DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImplicitBall.h
1 
17 #pragma once
18 
31 #if defined(ImplicitBall_RECURSES)
32 #error Recursive header files inclusion detected in ImplicitBall.h
33 #else // defined(ImplicitBall_RECURSES)
34 
35 #define ImplicitBall_RECURSES
36 
37 #if !defined ImplicitBall_h
38 
39 #define ImplicitBall_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/kernel/NumberTraits.h"
46 #include "DGtal/shapes/implicit/CImplicitFunction.h"
48 
49 namespace DGtal
50 {
51 
53 
63  template <typename TSpace>
65  {
66 
67  public:
69  typedef TSpace Space;
70  typedef typename Space::RealPoint RealPoint;
71  typedef typename Space::Integer Integer;
72  typedef double Value;
73 
81  ImplicitBall(const RealPoint &aCenter, const double &aRadius): myCenter(aCenter),
82  myRadius(aRadius)
83  {};
84 
89  ~ImplicitBall();
90 
91 
92  // ----------------------- Interface --------------------------------------
93  public:
94 
95  inline
96  Value operator()(const RealPoint &aPoint) const
97  {
98  return NumberTraits<Integer>::castToDouble((const DGtal::int32_t)myRadius) - (aPoint - myCenter ).norm();
99  }
100 
101  inline
102  bool isInside(const RealPoint &aPoint) const
103  {
104  return (this->operator()(aPoint) > 0.0);
105  }
106 
107  inline
108  Orientation orientation(const RealPoint &aPoint) const
109  {
110  if (this->operator()(aPoint) > 0.0)
111  return INSIDE;
112  else
113  if (this->operator()(aPoint) < 0.0)
114  return OUTSIDE;
115  else
116  return ON;
117  }
118 
119  inline
121  {
122  return (myCenter - RealPoint::diagonal(myRadius));
123  }
124 
125  inline
127  {
128  return (myCenter + RealPoint::diagonal(myRadius));
129  }
130 
131 
132 
133  // ----------------------- Interface --------------------------------------
134  public:
135 
140  void selfDisplay ( std::ostream & out ) const;
141 
146  bool isValid() const;
147 
148  // ------------------------- Protected Datas ------------------------------
149  private:
150  // ------------------------- Private Datas --------------------------------
151  private:
152 
155 
157  double myRadius;
158 
159  // ------------------------- Hidden services ------------------------------
160  protected:
161 
166  ImplicitBall();
167 
168  private:
169 
176  ImplicitBall & operator= ( const ImplicitBall & other );
177 
178 
179  }; // end of class ImplicitBall
180 
181 
188  template <typename T>
189  std::ostream&
190  operator<< ( std::ostream & out, const ImplicitBall<T> & object );
191 
192 } // namespace DGtal
193 
194 
196 // Includes inline functions.
197 #include "DGtal/shapes/implicit/ImplicitBall.ih"
198 
199 // //
201 
202 #endif // !defined ImplicitBall_h
203 
204 #undef ImplicitBall_RECURSES
205 #endif // else defined(ImplicitBall_RECURSES)