DGtal  0.9.2
Point2ScalarFunctors.h
1 
17 #pragma once
18 
31 #if defined(Point2ScalarFunctors_RECURSES)
32 #error Recursive header files inclusion detected in Point2ScalarFunctors.h
33 #else // defined(Point2ScalarFunctors_RECURSES)
34 
35 #define Point2ScalarFunctors_RECURSES
36 
37 #if !defined Point2ScalarFunctors_h
38 
39 #define Point2ScalarFunctors_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
46 
47 namespace DGtal {
48  namespace functors {
49 
54  template <typename TPoint, typename TScalar>
56  typedef TPoint Point;
57  typedef TScalar Scalar;
58  typedef Point argument_type;
59  typedef Scalar value_type;
60 
61  Scalar myV0;
62  Scalar myV0OverR;
63  Scalar myR;
64  Scalar myR2;
65 
66  public:
67  HatPointFunction( Scalar v0, Scalar r )
68  : myV0( v0 ), myV0OverR( v0 / r ), myR( r ), myR2( r*r ) {}
69  Scalar operator()( const Point& p ) const
70  {
71  Scalar d = 0;
72  for ( typename Point::ConstIterator it = p.begin(), itE = p.end(); it != itE; ++it )
73  d += functions::square( (Scalar) *it );
74  if ( d >= myR2 ) return 0.0;
75  d = sqrt( d );
76  return myV0 - myV0OverR * d;
77  }
78  };
79 
84  template <typename TPoint, typename TScalar>
86  typedef TPoint Point;
87  typedef TScalar Scalar;
88  typedef Point argument_type;
89  typedef Scalar value_type;
90 
91  Scalar myV0;
92  Scalar myR2;
93 
94  public:
95  BallConstantPointFunction( Scalar v0, Scalar r )
96  : myV0( v0 ), myR2( r*r ) {}
97  Scalar operator()( const Point& p ) const
98  {
99  Scalar d = 0;
100  for ( typename Point::ConstIterator it = p.begin(), itE = p.end(); it != itE; ++it )
101  d += functions::square( (Scalar) *it );
102  return ( d > myR2 ) ? 0.0 : myV0;
103  }
104  };
105 
106  } // namespace functors
107 } // namespace DGtal
108 
109 
111 // Includes inline functions.
112 #include "DGtal/kernel/Point2ScalarFunctors.ih"
113 
114 // //
116 
117 #endif // !defined Point2ScalarFunctors_h
118 
119 #undef Point2ScalarFunctors_RECURSES
120 #endif // else defined(Point2ScalarFunctors_RECURSES)
Scalar operator()(const Point &p) const
DGtal is the top-level namespace which contains all DGtal functions and types.