DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImplicitPolynomial3Shape.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 //-----------------------------------------------------------------------------
42 template <typename TSpace>
43 inline
45 {
46 }
47 //-----------------------------------------------------------------------------
48 template <typename TSpace>
49 inline
52 {
53  init( poly );
54 }
55 //-----------------------------------------------------------------------------
56 template <typename TSpace>
57 inline
61 {
62  if ( this != &other )
63  {
64  myPolynomial = other.myPolynomial;
65 
66  myFx= other.myFx;
67  myFy= other.myFy;
68  myFz= other.myFz;
69 
70  myFxx= other.myFxx;
71  myFxy= other.myFxy;
72  myFxz= other.myFxz;
73 
74  myFyx= other.myFyx;
75  myFyy= other.myFyy;
76  myFyz= other.myFyz;
77 
78  myFzx= other.myFzx;
79  myFzy= other.myFzy;
80  myFzz= other.myFzz;
81  }
82  return *this;
83 }
84 //-----------------------------------------------------------------------------
85 template <typename TSpace>
86 inline
87 void
89 init( const Polynomial3 & poly )
90 {
91  myPolynomial = poly;
92 
93  myFx= derivative<0>( poly );
94  myFy= derivative<1>( poly );
95  myFz= derivative<2>( poly );
96 
97  myFxx= derivative<0>( myFx );
98  myFxy= derivative<1>( myFx );
99  myFxz= derivative<2>( myFx);
100 
101  myFyx= derivative<0>( myFy );
102  myFyy= derivative<1>( myFy );
103  myFyz= derivative<2>( myFy );
104 
105  myFzx= derivative<0>( myFz );
106  myFzy= derivative<1>( myFz );
107  myFzz= derivative<2>( myFz );
108 
109  myUpPolynome = myFx*(myFx*myFxx+myFy*myFyx+myFz*myFzx)+
110  myFy*(myFx*myFxy+myFy*myFyy+myFz*myFzy)+
111  myFz*(myFx*myFxz+myFy*myFyz+myFz*myFzz)-
112  ( myFx*myFx +myFy*myFy+myFz*myFz )*(myFxx+myFyy+myFzz);
113 
114  myLowPolynome = myFx*myFx +myFy*myFy+myFz*myFz;
115 }
116 //-----------------------------------------------------------------------------
117 template <typename TSpace>
118 inline
119 double
121 operator()(const RealPoint &aPoint) const
122 {
123  return myPolynomial( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
124 }
125 //-----------------------------------------------------------------------------
126 template <typename TSpace>
127 inline
128 bool
130 isInside(const RealPoint &aPoint) const
131 {
132  return (this->operator()(aPoint) > (Ring)0);
133 }
134 //-----------------------------------------------------------------------------
135 template <typename TSpace>
136 inline
139 orientation(const RealPoint &aPoint) const
140 {
141  Ring v = this->operator()(aPoint);
142  if ( v > (Ring)0 )
143  return INSIDE;
144  else if ( v < (Ring)0 )
145  return OUTSIDE;
146  else
147  return ON;
148 }
149 //-----------------------------------------------------------------------------
150 template <typename TSpace>
151 inline
154 gradient( const RealPoint &aPoint ) const
155 {
156  // ISO C++ tells that an object created at return time will not be
157  // copied into the caller context, but will be already defined in
158  // the correct context.
159  return RealVector
160  ( myFx ( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] ),
161  myFy ( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] ),
162  myFz ( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] ) );
163 
164 }
165 
166 
167 // ------------------------------------------------------------ Added by Anis Benyoub
168 //-----------------------------------------------------------------------------
169 
178 template <typename TSpace>
179 inline
180 double
182 meanCurvature( const RealPoint &aPoint ) const
183 {
184  double temp= myLowPolynome( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
185  temp = sqrt(temp);
186  double downValue = 2*(temp*temp*temp);
187  double upValue = myUpPolynome( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
188 
189 
190  return -(upValue/downValue);
191 }
192 
193 
194 
195 //-----------------------------------------------------------------------------
196 template <typename TSpace>
197 inline
198 double
200 gaussianCurvature( const RealPoint &aPoint ) const
201 {
202 
203  double vFx= myFx( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
204  double vFy= myFy( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
205  double vFz= myFz( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
206 
207  double vFxx= myFxx( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
208  double vFxy= myFxy( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
209  double vFxz= myFxz( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
210 
211  //double vFyx= myFyx( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
212  double vFyy= myFyy( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
213  double vFyz= myFyz( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
214 
215 
216  /*double vFzx = myFzx( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
217  double vFzy = myFzy( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
218  */
219  double vFzz = myFzz( aPoint[ 0 ] )( aPoint[ 1 ] )( aPoint[ 2 ] );
220 
221 
222  double A = vFz*(vFxx*vFz-2.0*vFx*vFxz)+vFx*vFx*vFzz;
223 
224  double B = vFz*(vFyy*vFz-2.0*vFy*vFyz)+vFy*vFy*vFzz;
225 
226  double C = vFz*(-vFx*vFyz+vFxy*vFz-vFxz*vFy)+vFx*vFy*vFzz;
227 
228  double D = vFz*(vFx*vFx+vFy*vFy+vFz*vFz);
229 
230  double G= (A*B-C*C)/(D*D);
231 
232  return G;
233 
234 }
235 
236 
246 template <typename TSpace>
247 inline
250  const int maxIter, const double gamma ) const
251 {
252  RealPoint agradient= (*this).gradient(aPoint);
253  RealPoint X=aPoint;
254  int numberIter=0;
255  while((fabs((*this)(X))>=accuracy) && (numberIter<maxIter))
256  {
257  double norm=agradient.norm();
258  RealPoint normalizedGradient= RealPoint(agradient[0]/norm,agradient[1]/norm,agradient[2]/norm);
259  double alpha =gamma;
260  if((*this)(X)>0)
261  {
262  alpha=-alpha;
263  }
264  else
265  {
266 
267  }
268 
269  X=X+normalizedGradient*alpha;
270  agradient= (*this).gradient(X);
271  numberIter++;
272  }
273  return X;
274 }
275 
277 // Interface - public :
278 
283 template <typename TSpace>
284 inline
285 void
287 {
288  out << "[ImplicitPolynomial3Shape] P(x,y,z) = " << myPolynomial;
289 }
290 
295 template <typename TSpace>
296 inline
297 bool
299 {
300  return true;
301 }
302 
303 
304 
306 // Implementation of inline functions //
307 
308 template <typename TSpace>
309 inline
310 std::ostream&
311 DGtal::operator<< ( std::ostream & out,
312  const ImplicitPolynomial3Shape<TSpace> & object )
313 {
314  object.selfDisplay( out );
315  return out;
316 }
317 
318 // //
320 
321