24 const typename DataPoint::Scalar _radius,
25 const typename DataPoint::VectorType _vCenter,
26 const bool _bAddPositionNoise =
true,
27 const bool _bAddNormalNoise =
true,
28 const bool _bReverseNormals =
false
30 typedef typename DataPoint::Scalar Scalar;
31 typedef typename DataPoint::VectorType VectorType;
33 VectorType vNormal = VectorType::Random().normalized();
34 VectorType vPosition = _vCenter + vNormal * _radius;
36 if(_bAddPositionNoise)
38 vPosition = vPosition + VectorType::Random().normalized() *
39 Eigen::internal::random<Scalar>(Scalar(0.), Scalar(1. - MIN_NOISE));
40 vNormal = (vPosition - _vCenter).normalized();
45 VectorType vTempPos = vPosition + VectorType::Random().normalized() *
46 Eigen::internal::random<Scalar>(Scalar(0.), Scalar(1. - MIN_NOISE));
47 vNormal = (vTempPos - _vCenter).normalized();
51 const float reverse = Eigen::internal::random<float>(0.f, 1.f);
56 return DataPoint(vPosition, vNormal);
62 typename VectorType::Scalar _radius,
65 using Scalar =
typename VectorType::Scalar;
67 double theta = Eigen::internal::random<Scalar>(0,2.*EIGEN_PI);
70 double r = _radius * std::sqrt(Eigen::internal::random<Scalar>(0,1));
73 VectorType p = _vCenter;
74 p.x() += r * std::cos(theta);
75 p.y() += r * std::sin(theta);
83 const typename DataPoint::VectorType& _vPosition,
84 const typename DataPoint::VectorType& ,
85 const typename DataPoint::Scalar& _width,
86 const typename DataPoint::Scalar& _height,
87 const typename DataPoint::VectorType& _localxAxis,
88 const typename DataPoint::VectorType& _localyAxis,
89 const bool _bAddPositionNoise =
true
91 typedef typename DataPoint::Scalar Scalar;
92 typedef typename DataPoint::VectorType VectorType;
94 const Scalar u = Eigen::internal::random<Scalar>(
95 -_width /Scalar(2), _width /Scalar(2) );
96 const Scalar v = Eigen::internal::random<Scalar>(
97 -_height/Scalar(2), _height/Scalar(2) );
99 VectorType vRandomPosition = _vPosition + u*_localxAxis + v*_localyAxis;
101 if(_bAddPositionNoise)
103 vRandomPosition = vRandomPosition +
104 VectorType::Random().normalized() *
105 Eigen::internal::random<Scalar>(0., 1. - MIN_NOISE);
108 return DataPoint(vRandomPosition);
114 const typename DataPoint::VectorType _vPosition,
115 const typename DataPoint::VectorType _vNormal,
116 const typename DataPoint::Scalar _radius,
117 const bool _bAddPositionNoise =
true,
118 const bool _bAddNormalNoise =
true,
119 const bool _bReverseNormals =
false
121 typedef typename DataPoint::Scalar Scalar;
122 typedef typename DataPoint::VectorType VectorType;
123 typedef Eigen::Quaternion<Scalar> QuaternionType;
126 VectorType vRandomDirection = VectorType::Zero();
127 VectorType vRandomPoint = VectorType::Zero();
128 VectorType vLocalUp = _vNormal;
132 vRandom = VectorType::Random().normalized();
133 vRandomDirection = vRandom.cross(vLocalUp);
135 while(vRandomDirection == VectorType::Zero());
137 vRandomDirection = vRandomDirection.normalized();
138 vRandomPoint = vRandomDirection * _radius;
139 vRandomPoint += _vPosition;
141 if(_bAddPositionNoise)
143 vRandomPoint = vRandomPoint + VectorType::Random().normalized() *
144 Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
149 VectorType vLocalLeft = vLocalUp.cross(vRandomDirection);
150 VectorType vLocalFront = vLocalLeft.cross(vLocalUp);
152 Scalar rotationAngle = Eigen::internal::random<Scalar>(Scalar(-M_PI / 16.), Scalar(M_PI / 16.));
153 VectorType vRotationAxis = vLocalLeft;
154 QuaternionType qRotation = QuaternionType(Eigen::AngleAxis<Scalar>(rotationAngle, vRotationAxis));
155 qRotation = qRotation.normalized();
156 vLocalUp = qRotation * vLocalUp;
158 rotationAngle = Eigen::internal::random<Scalar>(Scalar(-M_PI / 16.), Scalar(M_PI / 16.));
159 vRotationAxis = vLocalFront;
160 qRotation = QuaternionType(Eigen::AngleAxis<Scalar>(rotationAngle, vRotationAxis));
161 qRotation = qRotation.normalized();
162 vLocalUp = qRotation * vLocalUp;
167 const float reverse = Eigen::internal::random<float>(0.f, 1.f);
169 vLocalUp = -vLocalUp;
173 return DataPoint(vRandomPoint, vLocalUp);
178 template<
typename Scalar>
185 return _a*_x*_x + _b*_y*_y;
189 template<
typename Scalar>
190 [[nodiscard]]
inline Scalar
200 return _a*_x*_x + _b*_y*_y + _c*_x*_y + _d*_x + _e*_y + _f;
204 template<
typename VectorType>
206 const VectorType& in,
207 const typename VectorType::Scalar _a,
208 const typename VectorType::Scalar _b
210 return VectorType((_a * in.x()), (_b * in.y()), -1.).normalized();;
212 template<
typename DataPo
int>
213 inline typename std::enable_if<Ponca::hasNormal<DataPoint>::value,
void>::type
215 typename DataPoint::Scalar _a,
216 typename DataPoint::Scalar _b,
217 typename DataPoint::Scalar _c,
218 typename DataPoint::Scalar _d,
219 typename DataPoint::Scalar _e,
220 typename DataPoint::Scalar _f)
222 static constexpr typename DataPoint::Scalar two {2};
223 auto& pos = in.pos();
224 in.normal() =
typename DataPoint::VectorType(two*_a * pos.x() + _c*pos.y() + _d,
225 two*_b * pos.y() + _c*pos.x() + _d,
229 template<
typename DataPo
int>
230 inline typename std::enable_if<! Ponca::hasNormal<DataPoint>::value,
void>::type
232 typename DataPoint::Scalar _a,
233 typename DataPoint::Scalar _b,
234 typename DataPoint::Scalar _c,
235 typename DataPoint::Scalar _d,
236 typename DataPoint::Scalar _e,
237 typename DataPoint::Scalar _f)
247 const typename DataPoint::Scalar _a,
248 const typename DataPoint::Scalar _b,
249 const typename DataPoint::Scalar _s,
250 const bool _bAddNoise =
true
252 typedef typename DataPoint::Scalar Scalar;
253 typedef typename DataPoint::VectorType VectorType;
256 VectorType vPosition;
258 const Scalar x = Eigen::internal::random<Scalar>(-_s, _s),
259 y = Eigen::internal::random<Scalar>(-_s, _s);
265 vPosition += VectorType::Random().normalized() * Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
267 return DataPoint(vPosition, vNormal);
276 typename DataPoint::Scalar _b,
277 typename DataPoint::Scalar _c,
278 typename DataPoint::Scalar _d,
279 typename DataPoint::Scalar _e,
280 typename DataPoint::Scalar _f,
281 typename DataPoint::Scalar _s,
282 bool _bAddNoise =
true)
284 typedef typename DataPoint::Scalar Scalar;
285 typedef typename DataPoint::VectorType VectorType;
298 out.pos() += VectorType::Random().normalized() * Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
311 return getPointOnParaboloid<DataPoint>(_params(0), _params(1), _params(2),
312 _params(3), _params(4), _params(5), _s, _bAddNoise);
318 typedef typename DataPoint::VectorType VectorType;
319 typedef typename DataPoint::Scalar Scalar;
320 const VectorType n = VectorType::Random().normalized();
321 const VectorType p = n * Eigen::internal::random<Scalar>(MIN_NOISE, MAX_NOISE);
322 return {p, (n + VectorType::Random()*Scalar(0.1)).normalized()};
DataPoint getPointOnPlane(const typename DataPoint::VectorType _vPosition, const typename DataPoint::VectorType _vNormal, const typename DataPoint::Scalar _radius, const bool _bAddPositionNoise=true, const bool _bAddNormalNoise=true, const bool _bReverseNormals=false)
Generate points on a plane.
DataPoint getPointOnParaboloid(const typename DataPoint::Scalar _a, const typename DataPoint::Scalar _b, const typename DataPoint::Scalar _s, const bool _bAddNoise=true)
Generate point samples on the primitive z = ax^2 + by^2.
DataPoint getPointOnSphere(const typename DataPoint::Scalar _radius, const typename DataPoint::VectorType _vCenter, const bool _bAddPositionNoise=true, const bool _bAddNormalNoise=true, const bool _bReverseNormals=false)
Generate points on a sphere.
DataPoint getPointOnRectangularPlane(const typename DataPoint::VectorType &_vPosition, const typename DataPoint::VectorType &, const typename DataPoint::Scalar &_width, const typename DataPoint::Scalar &_height, const typename DataPoint::VectorType &_localxAxis, const typename DataPoint::VectorType &_localyAxis, const bool _bAddPositionNoise=true)
Generate points on a plane without normals.