DGtal  0.9.2
FunctorsLambdaMST.h
1
17 #pragma once
18
29 #if defined(FunctorsLambdaMST_RECURSES)
30 #error Recursive header files inclusion detected in FunctorsLambdaMST.h
31 #else // defined(FunctorsLambdaMST_RECURSES)
32
33 #define FunctorsLambdaMST_RECURSES
34
35 #if !defined FunctorsLambdaMST_h
36
37 #define FunctorsLambdaMST_h
38
40 // Inclusions
41 #include <functional>
42 #include "DGtal/base/Common.h"
43 #include "DGtal/base/CUnaryFunctor.h"
45
46 namespace DGtal
47 {
49
58 namespace functors
59 {
65  struct Lambda64Function : std::unary_function < double, double >
66  {
67  double operator() (double x) const
68  {
69  double e2 = x * x;
70  double e3 = e2 * x;
71  return 64.0 * ( -e3 * e3 + 3.0 * e3 * e2 - 3.0 * e2 * e2 + e3 );
72  }
73  };
79  struct LambdaSinFromPiFunction : std::unary_function < double, double >
80  {
81  double operator() (double x) const
82  {
83  return std::sin ( M_PI * x );
84  }
85  };
86
92  struct LambdaExponentialFunction : std::unary_function < double, double >
93  {
94  double operator() (double x) const
95  {
96  return 2.0 / ( std::exp ( 15.0 * ( x - 0.5 ) ) + std::exp ( -15.0 * ( x - 0.5 ) ) );
97  }
98  };
99 }
100
108 template<typename DSS, typename LambdaFunction>
110 {
112  // ----------------------- Types ------------------------------
113 public:
115  typedef DSS TDSS;
116
117  struct Value
118  {
119  RealVector first;
120  double second;
121  Value () : second ( 0. ) {}
122  Value & operator+= ( const Value & ch )
123  {
124  this->first += ch.first;
125  this->second += ch.second;
126  return *this;
127  }
128  };
129
130
131  // ----------------------- Interface --------------------------------------
132 public:
140  Value operator() ( const TDSS& aDSS, const int & indexOfPointInDSS, const int & dssLen ) const
141  {
142  Value result;
144  result.second = lambdaFunctor ( (double)indexOfPointInDSS / (double)dssLen );
145  result.first[0] = result.second * aDSS.b () / norm;
146  result.first[1] = result.second * aDSS.a () / norm;
147  return result;
148  }
149 private:
150  // ------------------------- Private Datas --------------------------------
151  LambdaFunction lambdaFunctor;
152 };
153
161 template<typename DSS, typename LambdaFunction>
163 {
165 public:
166  // ----------------------- Types ------------------------------
168  typedef DSS TDSS;
169  struct Value
170  {
171  RealVector first;
172  double second;
173  Value () : second ( 0. ) {}
174  Value & operator += ( const Value & ch )
175  {
176  this->first += ch.first;
177  this->second += ch.second;
178  return *this;
179  }
180  };
181
182  // ----------------------- Interface --------------------------------------
190  Value operator() ( const TDSS& aDSS, const int & indexOfPointInDSS, const int & dssLen ) const
191  {
192  Value result;
193  typename DSS::Point3d directionZ3;
194  RealVector direction;
195  typename DSS::PointR3d intercept;
196  typename DSS::PointR3d thikness;
197
198  aDSS.getParameters ( directionZ3, intercept, thikness );
199  direction[0] = directionZ3[0];
200  direction[1] = directionZ3[1];
201  direction[2] = directionZ3[2];
202
203  result.second = lambdaFunctor ( (double)indexOfPointInDSS / (double)dssLen );
204
205  double norm = direction.norm();
206  if ( norm != 0. )
207  direction /= norm;
208  result.first = direction * result.second;
209  return result;
210  }
211 private:
212  // ------------------------- Private Datas --------------------------------
214  LambdaFunction lambdaFunctor;
215 };
216
217 } // namespace DGtal
218
219 // //
221
222 #endif // !defined FunctorsLambdaMST_h
223
224 #undef FunctorsLambdaMST_RECURSES
225 #endif // else defined(FunctorsLambdaMST_RECURSES)
PointVector< 3, double > RealVector
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< LambdaFunction, double, double >))
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
Value operator()(const TDSS &aDSS, const int &indexOfPointInDSS, const int &dssLen) const
DGtal is the top-level namespace which contains all DGtal functions and types.
double norm(const NormType type=L_2) const
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< LambdaFunction, double, double >))
double operator()(double x) const
PointVector< 2, double > RealVector
Value operator()(const TDSS &aDSS, const int &indexOfPointInDSS, const int &dssLen) const