WeightFunc.h
Go to the documentation of this file.
1 #ifndef __GfxTL_WEIGHTFUNC_HEADER__
2 #define __GfxTL_WEIGHTFUNC_HEADER__
3 #include <iterator>
4 #include <GfxTL/MathHelper.h>
5 
6 namespace GfxTL
7 {
8 
9  template< class ScalarT >
11  {
12  public:
13  typedef ScalarT ScalarType;
14 
16  {
17  _r = r;
18  _f = ScalarType(1.5) / r;
19  }
20 
22  {
23  if (dist >= _r)
24  {
25  return 0;
26  }
27  return EvalBSpline(_f * dist);
28  }
29 
30  private:
31  ScalarType EvalBSpline(ScalarType t) const
32  {
33  //B-spline (degree = 2)
34  if (t < ScalarType(0.5))
35  {
36  return -t * t + ScalarType(0.75);
37  }
38  else
39  return ScalarType(0.5) * (ScalarType(1.5) - t)
40  * (ScalarType(1.5) - t);
41  /*ScalarType x = t + (ScalarType)1.5; // shifted value
42  if(((ScalarType)-1.5 <= t) && (t < (ScalarType)-0.5))
43  return (ScalarType)0.5 * x * x;
44  if(((ScalarType)-0.5 <= t) && (t < (ScalarType)0.5))
45  return (ScalarType)-1.0 * x * x + (ScalarType)3.0 * x
46  - (ScalarType)(3.0 / 2.0);
47  if(((ScalarType)0.5 <= t) && (t < (ScalarType)1.5))
48  return (ScalarType)0.5 * x * x - (ScalarType)3.0 * x
49  + (ScalarType)(9.0 / 2.0);
50  return (ScalarType)0.0; // bspline zero*/
51  }
52 
53  private:
54  ScalarType _f;
55  ScalarType _r;
56  };
57 
58  template< class Point >
60  {
61  public:
62  typedef Point PointType;
63  typedef typename Point::ScalarType ScalarType;
64 
65  double Weight(const Point&)
66  {
67  return (double)1;
68  }
69 
70  double operator()(const Point&)
71  {
72  return (double)1;
73  }
74  };
75 
77  {
78  public:
79  typedef unsigned int value_type;
80  typedef unsigned int* pointer;
81  typedef unsigned int& reference;
82  typedef std::forward_iterator_tag iterator_category;
83  typedef size_t difference_type;
84 
85  const unsigned int operator*() const
86  {
87  return 1;
88  }
89 
91  {
92  return *this;
93  }
94  };
95 
96  template< class PointT >
98  {
99  public:
100  typedef PointT PointType;
101  typedef typename PointType::ScalarType ScalarType;
102 
104  ScalarType radius)
105  : _center(center)
106  , _radius(radius)
107  {}
108 
110  {
111  ScalarType d = (p - _center).Length();
112  return operator()(d);
113  }
114 
116  {
117  ScalarType a = Math< ScalarType >::Max(_radius - d, 0)
118  / (_radius * d);
119  return a * a;
120  }
121 
122  private:
123  PointType _center;
124  ScalarType _radius;
125  };
126 
127  template< class PointT >
129  {
130  public:
131  typedef PointT PointType;
132  typedef typename PointType::ScalarType ScalarType;
133 
135  ScalarType sqrRadius)
136  : _center(center)
137  {
138  _scale = ScalarType(11.38335808) / sqrRadius;
139  }
140 
142  {
143  _center.Zero();
144  _scale = 1;
145  }
146 
148  {
149  return operator()(_center.SqrDistance(p));
150  }
151 
153  {
154  sqrDist *= _scale;
155  return std::exp(-sqrDist) / sqrDist;
156  }
157 
158  bool WeightAndDerivative(const PointType& x, ScalarType* weight,
159  PointType* derivative)
160  {
161  ScalarType sqrDist = _scale * _center.SqrDistance(x);
162  if (sqrDist < 1e-6)
163  {
164  return false;
165  }
166  *weight = std::exp(-sqrDist) / sqrDist;
167  for (unsigned int i = 0; i < PointType::Dim; ++i)
168  {
169  (*derivative)[i] = *weight * (2 * (x[i] - _center[i]));
170  (*derivative)[i] += (*derivative)[i] / sqrDist;
171  }
172  return true;
173  }
174 
175  private:
176  PointType _center;
177  ScalarType _scale;
178  };
179 
180  template< class PointT >
182  {
183  public:
184  typedef PointT PointType;
185  typedef typename PointType::ScalarType ScalarType;
186 
188  : _radius(radius)
189  , _sqrRadius(_radius * _radius)
190  , _cbcRadius(_sqrRadius * _radius)
191  {}
192 
194  ScalarType radius)
195  : _center(center)
196  , _radius(radius)
197  , _sqrRadius(_radius * _radius)
198  , _cbcRadius(_sqrRadius * _radius)
199  {}
200 
202  {
203  return operator()((p - _center).Length());
204  }
205 
207  {
208  ScalarType sqrDist = dist * dist;
209  return 2 * sqrDist * dist / _cbcRadius -
210  3 * sqrDist / _sqrRadius + 1;
211  }
212 
213  bool WeightAndDerivative(const PointType& x, ScalarType* weight,
214  PointType* derivative)
215  {
216  return false;
217  }
218 
219  private:
220  ScalarType _radius, _sqrRadius, _cbcRadius;
221  PointType _center;
222  };
223 };
224 
225 #endif
GfxTL::CubicGaussApproximationWeightFunc::operator()
ScalarType operator()(ScalarType dist) const
Definition: WeightFunc.h:206
GfxTL::UnitWeightFunc::Weight
double Weight(const Point &)
Definition: WeightFunc.h:65
GfxTL::CubicGaussApproximationWeightFunc::ScalarType
PointType::ScalarType ScalarType
Definition: WeightFunc.h:185
GfxTL::CubicGaussApproximationWeightFunc::WeightAndDerivative
bool WeightAndDerivative(const PointType &x, ScalarType *weight, PointType *derivative)
Definition: WeightFunc.h:213
GfxTL::InterpolatingExponentialWeightFunc::InterpolatingExponentialWeightFunc
InterpolatingExponentialWeightFunc(const PointType &center, ScalarType sqrRadius)
Definition: WeightFunc.h:134
GfxTL::UnitWeightFunc::PointType
Point PointType
Definition: WeightFunc.h:62
GfxTL::InverseDistanceSingularWeightFunc::InverseDistanceSingularWeightFunc
InverseDistanceSingularWeightFunc(const PointType &center, ScalarType radius)
Definition: WeightFunc.h:103
GfxTL::BSplineWeightFunc::BSplineWeightFunc
BSplineWeightFunc(ScalarType r)
Definition: WeightFunc.h:15
GfxTL::CubicGaussApproximationWeightFunc::CubicGaussApproximationWeightFunc
CubicGaussApproximationWeightFunc(PointType center, ScalarType radius)
Definition: WeightFunc.h:193
GfxTL::InterpolatingExponentialWeightFunc::operator()
ScalarType operator()(ScalarType sqrDist) const
Definition: WeightFunc.h:152
Point::ScalarType
float ScalarType
Definition: PointCloud.h:24
GfxTL::InverseDistanceSingularWeightFunc::ScalarType
PointType::ScalarType ScalarType
Definition: WeightFunc.h:101
GfxTL::UnitWeightFunc::operator()
double operator()(const Point &)
Definition: WeightFunc.h:70
GfxTL::UnitWeightIterator::reference
unsigned int & reference
Definition: WeightFunc.h:81
GfxTL::InterpolatingExponentialWeightFunc::PointType
PointT PointType
Definition: WeightFunc.h:131
GfxTL::InverseDistanceSingularWeightFunc
Definition: WeightFunc.h:97
GfxTL::InverseDistanceSingularWeightFunc::operator()
ScalarType operator()(const PointType &p) const
Definition: WeightFunc.h:109
GfxTL::InterpolatingExponentialWeightFunc
Definition: WeightFunc.h:128
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
GfxTL::CubicGaussApproximationWeightFunc::operator()
ScalarType operator()(const PointType &p) const
Definition: WeightFunc.h:201
GfxTL::InterpolatingExponentialWeightFunc::operator()
ScalarType operator()(const PointType &p) const
Definition: WeightFunc.h:147
Point
Definition: PointCloud.h:21
GfxTL::InterpolatingExponentialWeightFunc::InterpolatingExponentialWeightFunc
InterpolatingExponentialWeightFunc()
Definition: WeightFunc.h:141
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:28
GfxTL::BSplineWeightFunc::ScalarType
ScalarT ScalarType
Definition: WeightFunc.h:13
GfxTL::UnitWeightIterator::operator*
const unsigned int operator*() const
Definition: WeightFunc.h:85
GfxTL::UnitWeightFunc::ScalarType
Point::ScalarType ScalarType
Definition: WeightFunc.h:63
GfxTL
Definition: AABox.h:8
GfxTL::UnitWeightIterator::operator++
UnitWeightIterator operator++() const
Definition: WeightFunc.h:90
GfxTL::BSplineWeightFunc::operator()
ScalarType operator()(ScalarType dist) const
Definition: WeightFunc.h:21
GfxTL::UnitWeightIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: WeightFunc.h:82
GfxTL::InverseDistanceSingularWeightFunc::operator()
ScalarType operator()(ScalarType d) const
Definition: WeightFunc.h:115
GfxTL::InverseDistanceSingularWeightFunc::PointType
PointT PointType
Definition: WeightFunc.h:100
GfxTL::InterpolatingExponentialWeightFunc::ScalarType
PointType::ScalarType ScalarType
Definition: WeightFunc.h:132
GfxTL::CubicGaussApproximationWeightFunc::CubicGaussApproximationWeightFunc
CubicGaussApproximationWeightFunc(ScalarType radius)
Definition: WeightFunc.h:187
GfxTL::CubicGaussApproximationWeightFunc::PointType
PointT PointType
Definition: WeightFunc.h:184
GfxTL::UnitWeightIterator::value_type
unsigned int value_type
Definition: WeightFunc.h:79
GfxTL::CubicGaussApproximationWeightFunc
Definition: WeightFunc.h:181
GfxTL::UnitWeightFunc
Definition: WeightFunc.h:59
GfxTL::UnitWeightIterator::difference_type
size_t difference_type
Definition: WeightFunc.h:83
GfxTL::InterpolatingExponentialWeightFunc::WeightAndDerivative
bool WeightAndDerivative(const PointType &x, ScalarType *weight, PointType *derivative)
Definition: WeightFunc.h:158
GfxTL::Math::Max
static ScalarT Max(ScalarT a, ScalarT b)
Definition: MathHelper.h:49
GfxTL::UnitWeightIterator::pointer
unsigned int * pointer
Definition: WeightFunc.h:80
MathHelper.h
GfxTL::UnitWeightIterator
Definition: WeightFunc.h:76
GfxTL::BSplineWeightFunc
Definition: WeightFunc.h:10