114 template<
typename ContainerT>
123 template<
typename ContainerT,
typename TransformFunc>
124 PointCurve(
const ContainerT& container, TransformFunc func );
139 template<
typename T2>
140 void add(
const T2& point );
191 agx::UInt maxNumIterations = 100ul )
const;
210 template<
typename ContainerT>
213 m_points.resize( container.size() );
214 for (
agx::UInt i = 0; i < m_points.size(); ++i )
219 template<
typename ContainerT,
typename TransformFunc>
222 m_points.resize( container.size() );
223 std::transform( container.begin(), container.end(), m_points.begin(), func );
227 template<
typename T2>
230 if ( !m_time.empty() )
239 if ( m_points.size() < 2 ) {
244 if ( m_points.size() != m_time.size() ) {
250 auto index = findIndex( time );
252 if ( index + 1 == m_points.size() ) {
258 segment.begin = m_points[ index ];
259 segment.end = m_points[ index + 1 ];
261 segment.localTime = ( time - m_time[ index ] ) / ( m_time[ index + 1 ] - m_time[ index ] );
271 for (
agx::UInt i = 1; i < m_points.size(); ++i )
280 m_time.resize( m_points.size(),
agx::Real( 0 ) );
282 const auto totalLength = calculateLength();
287 m_time.front() = accumulatedTime;
288 for (
agx::UInt i = 1; i < m_points.size(); ++i ) {
289 accumulatedTime += ((
agx::Vec3)m_points[ i - 1 ]).distance( (
agx::Vec3)m_points[ i ] ) / totalLength;
290 m_time[ i ] = accumulatedTime;
294 return m_time.size() > 1;
300 for (
agx::UInt i = 0; i < m_points.size(); ++i )
301 callback( m_points[ i ] );
309 for (
agx::UInt i = 1; i < m_points.size(); ++i )
310 callback( Segment{ m_points[ i - 1 ], m_points[ i ] },
313 i + 1 == m_points.size() ?
323 const auto totalLength = calculateLength();
327 const agx::Real dt = segmentLength / totalLength;
330 auto prev = evaluate( prevT );
334 auto curr = evaluate( currT );
335 agx::Real prevToCurrDist = prev.point.distance( curr.point );
336 while ( !
agx::equivalent( prevToCurrDist, segmentLength, tolerance ) ) {
337 const agx::Real overshoot = prevToCurrDist - segmentLength;
338 currT -= overshoot / totalLength;
339 curr = evaluate( currT );
340 prevToCurrDist = prev.point.distance( curr.point );
346 curr.point.distance( (
agx::Vec3)m_points.back() ) <
agx::Real( 0.5 ) * segmentLength );
351 callback( prev, curr, type );
370 if ( numSegments < 1 )
373 const auto totalLength = calculateLength();
382 const auto&
self = *
this;
392 ePrev += errorFunction(
self, p1, p2, type );
397 eCurr += errorFunction(
self, p1, p2, type );
402 eNext += errorFunction(
self, p1, p2, type );
405 if ( eCurr < bestResult.
error ) {
407 bestResult.
error = eCurr;
421 result.
error += errorFunction(
self, p1, p2, type );
424 done = std::abs( result.
error ) <= maxError;
436 return std::max( m_points.size(), (
typename container_type::size_type)1 ) - 1;
438 auto it = std::lower_bound( m_time.begin(), m_time.end(), time );
442 return it - m_time.begin() - 1;