15#include "./concepts.h"
24 template <
typename DataPo
int>
26 const typename DataPoint::VectorType _vCenter,
27 const bool _bAddPositionNoise =
true,
const bool _bAddNormalNoise =
true,
28 const bool _bReverseNormals =
false)
30 using Scalar =
typename DataPoint::Scalar;
31 using VectorType =
typename DataPoint::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);
60 template <
typename VectorType>
61 [[nodiscard]] VectorType
getPointOnCircle(
typename VectorType::Scalar _radius, VectorType _vCenter)
63 using Scalar =
typename VectorType::Scalar;
65 const Scalar theta = Eigen::internal::random<Scalar>(0, Scalar(2. * EIGEN_PI));
68 const Scalar r = _radius * std::sqrt(Eigen::internal::random<Scalar>(0, 1));
71 VectorType p = _vCenter;
72 p.x() += r * std::cos(theta);
73 p.y() += r * std::sin(theta);
79 template <
typename DataPo
int>
81 const typename DataPoint::VectorType& ,
82 const typename DataPoint::Scalar& _width,
83 const typename DataPoint::Scalar& _height,
84 const typename DataPoint::VectorType& _localxAxis,
85 const typename DataPoint::VectorType& _localyAxis,
86 const bool _bAddPositionNoise =
true)
88 using Scalar =
typename DataPoint::Scalar;
89 using VectorType =
typename DataPoint::VectorType;
91 const Scalar u = Eigen::internal::random<Scalar>(-_width / Scalar(2), _width / Scalar(2));
92 const Scalar v = Eigen::internal::random<Scalar>(-_height / Scalar(2), _height / Scalar(2));
94 VectorType vRandomPosition = _vPosition + u * _localxAxis + v * _localyAxis;
96 if (_bAddPositionNoise)
98 vRandomPosition = vRandomPosition +
99 VectorType::Random().normalized() * Eigen::internal::random<Scalar>(0., 1. - MIN_NOISE);
102 return DataPoint(vRandomPosition);
106 template <
typename DataPo
int>
107 [[nodiscard]] DataPoint
getPointOnPlane(
const typename DataPoint::VectorType _vPosition,
108 const typename DataPoint::VectorType _vNormal,
109 const typename DataPoint::Scalar _radius,
110 const bool _bAddPositionNoise =
true,
const bool _bAddNormalNoise =
true,
111 const bool _bReverseNormals =
false)
113 using Scalar =
typename DataPoint::Scalar;
114 using VectorType =
typename DataPoint::VectorType;
115 using QuaternionType = Eigen::Quaternion<Scalar>;
118 VectorType vRandomDirection = VectorType::Zero();
119 VectorType vRandomPoint = VectorType::Zero();
120 VectorType vLocalUp = _vNormal;
124 vRandom = VectorType::Random().normalized();
125 vRandomDirection = vRandom.cross(vLocalUp);
126 }
while (vRandomDirection == VectorType::Zero());
128 vRandomDirection = vRandomDirection.normalized();
129 vRandomPoint = vRandomDirection * _radius;
130 vRandomPoint += _vPosition;
132 if (_bAddPositionNoise)
134 vRandomPoint = vRandomPoint + VectorType::Random().normalized() *
135 Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
138 if (_bAddNormalNoise)
140 VectorType vLocalLeft = vLocalUp.cross(vRandomDirection);
141 VectorType vLocalFront = vLocalLeft.cross(vLocalUp);
143 Scalar rotationAngle = Eigen::internal::random<Scalar>(Scalar(-M_PI / 16.), Scalar(M_PI / 16.));
144 VectorType vRotationAxis = vLocalLeft;
145 QuaternionType qRotation = QuaternionType(Eigen::AngleAxis<Scalar>(rotationAngle, vRotationAxis));
146 qRotation = qRotation.normalized();
147 vLocalUp = qRotation * vLocalUp;
149 rotationAngle = Eigen::internal::random<Scalar>(Scalar(-M_PI / 16.), Scalar(M_PI / 16.));
150 vRotationAxis = vLocalFront;
151 qRotation = QuaternionType(Eigen::AngleAxis<Scalar>(rotationAngle, vRotationAxis));
152 qRotation = qRotation.normalized();
153 vLocalUp = qRotation * vLocalUp;
156 if (_bReverseNormals)
158 const float reverse = Eigen::internal::random<float>(0.f, 1.f);
160 vLocalUp = -vLocalUp;
163 return DataPoint(vRandomPoint, vLocalUp);
169 template <
typename Scalar>
170 [[nodiscard]]
inline Scalar
getParaboloidZ(
const Scalar _x,
const Scalar _y,
const Scalar _a,
const Scalar _b)
172 return _a * _x * _x + _b * _y * _y;
176 template <
typename Scalar>
177 [[nodiscard]]
inline Scalar
getParaboloidZ(Scalar _x, Scalar _y, Scalar _a, Scalar _b, Scalar _c, Scalar _d,
178 Scalar _e, Scalar _f)
180 return _a * _x * _x + _b * _y * _y + _c * _x * _y + _d * _x + _e * _y + _f;
184 template <
typename VectorType>
185 [[nodiscard]]
inline VectorType
getParaboloidNormal(
const VectorType& in,
const typename VectorType::Scalar _a,
186 const typename VectorType::Scalar _b)
188 return VectorType((_a * in.x()), (_b * in.y()), -1.).normalized();
191 template <Prov
idesNormal DataPo
int>
192 inline void getParaboloidNormal(DataPoint& in,
typename DataPoint::Scalar _a,
typename DataPoint::Scalar _b,
193 typename DataPoint::Scalar _c,
typename DataPoint::Scalar _d,
194 typename DataPoint::Scalar _e,
typename DataPoint::Scalar _f)
196 static constexpr typename DataPoint::Scalar two{2};
197 auto& pos = in.pos();
198 in.normal() =
typename DataPoint::VectorType(two * _a * pos.x() + _c * pos.y() + _d,
199 two * _b * pos.y() + _c * pos.x() + _d, -1.)
208 template <
typename DataPo
int>
210 const typename DataPoint::Scalar _b,
211 const typename DataPoint::Scalar _s,
const bool _bAddNoise =
true)
213 using Scalar =
typename DataPoint::Scalar;
214 using VectorType =
typename DataPoint::VectorType;
217 VectorType vPosition;
219 const Scalar x = Eigen::internal::random<Scalar>(-_s, _s), y = Eigen::internal::random<Scalar>(-_s, _s);
226 VectorType::Random().normalized() * Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
228 return DataPoint(vPosition, vNormal);
234 template <
typename DataPo
int>
236 typename DataPoint::Scalar _c,
typename DataPoint::Scalar _d,
237 typename DataPoint::Scalar _e,
typename DataPoint::Scalar _f,
238 typename DataPoint::Scalar _s,
bool _bAddNoise =
true)
240 using Scalar =
typename DataPoint::Scalar;
241 using VectorType =
typename DataPoint::VectorType;
255 VectorType::Random().normalized() * Eigen::internal::random<Scalar>(Scalar(0), Scalar(1. - MIN_NOISE));
261 template <
typename DataPo
int,
typename Params>
262 [[nodiscard]] DataPoint
getPointOnParaboloid(
const Params& _params,
typename DataPoint::Scalar _s,
263 bool _bAddNoise =
true)
265 return getPointOnParaboloid<DataPoint>(_params(0), _params(1), _params(2), _params(3), _params(4), _params(5),
270 template <
typename DataPo
int>
273 using Scalar =
typename DataPoint::Scalar;
274 using VectorType =
typename DataPoint::VectorType;
275 const VectorType n = VectorType::Random().normalized();
276 const VectorType p = n * Eigen::internal::random<Scalar>(MIN_NOISE, MAX_NOISE);
277 return {p, (n + VectorType::Random() * Scalar(0.1)).normalized()};
VectorType getParaboloidNormal(const VectorType &in, const typename VectorType::Scalar _a, const typename VectorType::Scalar _b)
Generate z value using the equation z = ax^2 + by^2.
Scalar getParaboloidZ(const Scalar _x, const Scalar _y, const Scalar _a, const Scalar _b)
Generate z value using the equation z = ax^2 + by^2.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
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 getRandomPoint()
Generate a random points.
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.
VectorType getPointOnCircle(typename VectorType::Scalar _radius, VectorType _vCenter)
Sample points on a circle in the xy plane.