DGtal  1.1.0
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 <iterator>
43 #include <stdexcept>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/IteratorCirculatorTraits.h"
46 #include "DGtal/base/CUnaryFunctor.h"
48 
49 namespace DGtal
50 {
52 
61 namespace functors
62 {
69  {
70  double operator() (double x) const
71  {
72  double e2 = x * x;
73  double e3 = e2 * x;
74  return 64.0 * ( -e3 * e3 + 3.0 * e3 * e2 - 3.0 * e2 * e2 + e3 );
75  }
76  };
83  {
84  double operator() (double x) const
85  {
86  return std::sin ( M_PI * x );
87  }
88  };
89 
96  {
97  double operator() (double x) const
98  {
99  return 2.0 / ( std::exp ( 15.0 * ( x - 0.5 ) ) + std::exp ( -15.0 * ( x - 0.5 ) ) );
100  }
101  };
102 }
103 
111 template<typename DSS, typename LambdaFunction>
113 {
115  // ----------------------- Types ------------------------------
116 public:
118  typedef DSS TDSS;
119 
120  struct Value
121  {
123  double second;
124  Value () : second ( 0. ) {}
125  Value & operator+= ( const Value & ch )
126  {
127  this->first += ch.first;
128  this->second += ch.second;
129  return *this;
130  }
131  };
132 
133 
134  // ----------------------- Interface --------------------------------------
135 public:
143  Value operator() ( const TDSS& aDSS, const int & indexOfPointInDSS, const int & dssLen ) const
144  {
145  Value result;
146  double norm = std::sqrt ( aDSS.a() * aDSS.a() + aDSS.b() * aDSS.b() );
147  result.second = lambdaFunctor ( (double)indexOfPointInDSS / (double)dssLen );
148  if ( norm > 0. )
149  {
150  result.first[0] = result.second * aDSS.b() / norm;
151  result.first[1] = result.second * aDSS.a() / norm;
152  }
153  else
154  {
155  result.first[0] = 0.;
156  result.first[1] = 0.;
157  }
158  return result;
159  }
160 private:
161  // ------------------------- Private Datas --------------------------------
162  LambdaFunction lambdaFunctor;
163 };
164 
172 template<typename DSS, typename LambdaFunction>
174 {
176 public:
177  // ----------------------- Types ------------------------------
179  typedef DSS TDSS;
180  struct Value
181  {
183  double second;
184  Value () : second ( 0. ) {}
185  Value & operator += ( const Value & ch )
186  {
187  this->first += ch.first;
188  this->second += ch.second;
189  return *this;
190  }
191  };
192 
193  // ----------------------- Interface --------------------------------------
201  Value operator() ( const TDSS& aDSS, const unsigned int indexOfPointInDSS, const unsigned int dssLen ) const
202  {
203  Value result;
204  typename DSS::Point3d directionZ3;
205  RealVector direction;
206  typename DSS::PointR3d intercept;
207  typename DSS::PointR3d thikness;
208 
209  aDSS.getParameters ( directionZ3, intercept, thikness );
210  direction[0] = directionZ3[0];
211  direction[1] = directionZ3[1];
212  direction[2] = directionZ3[2];
213 
214  result.second = lambdaFunctor ( (double)indexOfPointInDSS / (double)dssLen );
215 
216  double norm = direction.norm();
217  if ( norm != 0. )
218  direction /= norm;
219  result.first = direction * result.second;
220  return result;
221  }
222 private:
223  // ------------------------- Private Datas --------------------------------
225  LambdaFunction lambdaFunctor;
226 };
227 
228 
234 template<typename DSS >
236 {
237 public:
238 // ----------------------- Types ------------------------------
239  typedef DSS DSSType;
241 
243  bool operator()( const DSSType & ) const
244  {
245  return false;
246  }
247 
249  bool admissibility ( const DSSType &, const Point & ) const
250  {
251  return false;
252  }
253 
255  long int position ( const DSSType &, const Point & ) const
256  {
257  throw std::runtime_error ( "You are not suppose to see this error!" );
258  }
259 };
260 
261 
268 template<typename DSS >
270 {
271 public:
272 // ----------------------- Types ------------------------------
273  typedef DSS DSSType;
275 
277 
281  void init ( double threshold )
282  {
283  if ( threshold < 0. )
284  throw std::runtime_error ( "The threshold has to be positive!" );
285  lenThreshold = threshold;
286  initThreshold = true;
287  }
288 
293  bool operator()( const DSSType & dss ) const
294  {
295  if (! initThreshold )
296  throw std::runtime_error ( "The filter has to be initialized!" );
297 
298  return std::distance ( dss.begin ( ), dss.end ( ) ) < lenThreshold;
299  }
300 
307  bool admissibility ( const DSSType & dss, const Point & p ) const
308  {
309  return ( p - *dss.begin ( ) ).norm ( ) <= lenThreshold || ( p - *( dss.end ( ) - 1 ) ).norm ( ) <= lenThreshold;
310  }
311 
319  long int position ( const DSSType & dss, const Point & p ) const
320  {
321  if ( ( p - *dss.begin ( ) ).norm ( ) <= lenThreshold )
322  return 1;
323  else if ( ( p - *( dss.end ( ) - 1 ) ).norm ( ) <= lenThreshold )
324  return std::distance ( dss.begin ( ), dss.end ( ) ) + 1;
325  else
326  throw std::runtime_error ( "The DSS and the point are not admissible!" );
327  }
328 
329 private:
330  double lenThreshold;
332 };
333 
334 } // namespace DGtal
335 
336 // //
338 
339 #endif // !defined FunctorsLambdaMST_h
340 
341 #undef FunctorsLambdaMST_RECURSES
342 #endif // else defined(FunctorsLambdaMST_RECURSES)
DGtal::DSSLengthLessEqualFilter::lenThreshold
double lenThreshold
Definition: FunctorsLambdaMST.h:330
DGtal::TangentFromDSS3DFunctor::RealVector
PointVector< 3, double > RealVector
Definition: FunctorsLambdaMST.h:178
DGtal::TangentFromDSS3DFunctor::Value::second
double second
Definition: FunctorsLambdaMST.h:183
DGtal::TangentFromDSS2DFunctor::Value::operator+=
Value & operator+=(const Value &ch)
Definition: FunctorsLambdaMST.h:125
DGtal::TangentFromDSS2DFunctor::Value::first
RealVector first
Definition: FunctorsLambdaMST.h:122
DGtal::functors::LambdaSinFromPiFunction
Definition: FunctorsLambdaMST.h:83
DGtal::TangentFromDSS3DFunctor::Value::operator+=
Value & operator+=(const Value &ch)
Definition: FunctorsLambdaMST.h:185
DGtal::DSSLengthLessEqualFilter::DSSType
DSS DSSType
Definition: FunctorsLambdaMST.h:273
ch
DGtal::MelkmanConvexHull< Point, Functor > ch
Definition: testConvexHull2DReverse.cpp:54
DGtal::DSSMuteFilter::position
long int position(const DSSType &, const Point &) const
When called always throws an exception.
Definition: FunctorsLambdaMST.h:255
DGtal::TangentFromDSS3DFunctor::Value::first
RealVector first
Definition: FunctorsLambdaMST.h:182
DGtal::TangentFromDSS3DFunctor::TDSS
DSS TDSS
Definition: FunctorsLambdaMST.h:179
DGtal::TangentFromDSS2DFunctor::TDSS
DSS TDSS
Definition: FunctorsLambdaMST.h:118
DGtal::DSSLengthLessEqualFilter::Point
IteratorCirculatorTraits< typename DSSType::ConstIterator >::Value Point
Definition: FunctorsLambdaMST.h:274
DGtal::TangentFromDSS3DFunctor::Value::Value
Value()
Definition: FunctorsLambdaMST.h:184
DGtal::DSSLengthLessEqualFilter::operator()
bool operator()(const DSSType &dss) const
Definition: FunctorsLambdaMST.h:293
DGtal::DSSLengthLessEqualFilter::position
long int position(const DSSType &dss, const Point &p) const
Definition: FunctorsLambdaMST.h:319
DGtal::DSSMuteFilter::Point
IteratorCirculatorTraits< typename DSSType::ConstIterator >::Value Point
Definition: FunctorsLambdaMST.h:240
DGtal::functors::Lambda64Function
Definition: FunctorsLambdaMST.h:69
DGtal::TangentFromDSS3DFunctor::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< LambdaFunction, double, double >))
DGtal::DSSLengthLessEqualFilter::admissibility
bool admissibility(const DSSType &dss, const Point &p) const
Definition: FunctorsLambdaMST.h:307
DGtal::TangentFromDSS2DFunctor::Value::second
double second
Definition: FunctorsLambdaMST.h:123
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::functors::LambdaExponentialFunction
Definition: FunctorsLambdaMST.h:96
DGtal::DSSLengthLessEqualFilter::initThreshold
bool initThreshold
Definition: FunctorsLambdaMST.h:331
DGtal::TangentFromDSS2DFunctor::operator()
Value operator()(const TDSS &aDSS, const int &indexOfPointInDSS, const int &dssLen) const
Definition: FunctorsLambdaMST.h:143
DGtal::DSSLengthLessEqualFilter::init
void init(double threshold)
Definition: FunctorsLambdaMST.h:281
DGtal::TangentFromDSS2DFunctor::RealVector
PointVector< 2, double > RealVector
Definition: FunctorsLambdaMST.h:117
DGtal::functors::LambdaSinFromPiFunction::operator()
double operator()(double x) const
Definition: FunctorsLambdaMST.h:84
DGtal::functors::LambdaExponentialFunction::operator()
double operator()(double x) const
Definition: FunctorsLambdaMST.h:97
DGtal::TangentFromDSS2DFunctor::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< LambdaFunction, double, double >))
DGtal::DSSMuteFilter::DSSType
DSS DSSType
Definition: FunctorsLambdaMST.h:239
DGtal::TangentFromDSS2DFunctor::Value
Definition: FunctorsLambdaMST.h:121
DGtal::TangentFromDSS3DFunctor::operator()
Value operator()(const TDSS &aDSS, const unsigned int indexOfPointInDSS, const unsigned int dssLen) const
Definition: FunctorsLambdaMST.h:201
DGtal::PointVector::norm
double norm(const NormType type=L_2) const
DGtal::DSSLengthLessEqualFilter::DSSLengthLessEqualFilter
DSSLengthLessEqualFilter()
Definition: FunctorsLambdaMST.h:276
DGtal::DSSMuteFilter
Definition: FunctorsLambdaMST.h:236
DGtal::functors::Lambda64Function::operator()
double operator()(double x) const
Definition: FunctorsLambdaMST.h:70
DGtal::TangentFromDSS3DFunctor::lambdaFunctor
LambdaFunction lambdaFunctor
Definition: FunctorsLambdaMST.h:225
DGtal::PointVector< 2, double >
DGtal::TangentFromDSS3DFunctor::Value
Definition: FunctorsLambdaMST.h:181
DGtal::DSSLengthLessEqualFilter
Definition: FunctorsLambdaMST.h:270
DGtal::DSSMuteFilter::operator()
bool operator()(const DSSType &) const
Always returns false.
Definition: FunctorsLambdaMST.h:243
DGtal::DSSMuteFilter::admissibility
bool admissibility(const DSSType &, const Point &) const
Always returns false.
Definition: FunctorsLambdaMST.h:249
DGtal::TangentFromDSS2DFunctor::Value::Value
Value()
Definition: FunctorsLambdaMST.h:124
DGtal::TangentFromDSS2DFunctor::lambdaFunctor
LambdaFunction lambdaFunctor
Definition: FunctorsLambdaMST.h:162
DGtal::concepts::CUnaryFunctor
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:90
DGtal::IteratorCirculatorTraits::Value
IC::value_type Value
Definition: IteratorCirculatorTraits.h:303
DGtal::TangentFromDSS3DFunctor
Definition: FunctorsLambdaMST.h:174
DGtal::TangentFromDSS2DFunctor
Definition: FunctorsLambdaMST.h:113