Commit aaf6a693 authored by Cyril Poupon's avatar Cyril Poupon
Browse files

added setEquidistantCurve to Curve3d and LightCurve3d

parent f941389a
......@@ -335,6 +335,24 @@ gkg::Curve3d< T >::addPoints( const gkg::Matrix& matrix )
}
template < class T >
void gkg::Curve3d< T >::setEquidistantCurve( int32_t pointCount )
{
try
{
this->gkg::LightCurve3d< T >::setEquidistantCurve( pointCount );
this->updateHeader();
}
GKG_CATCH( "template < class T > "
"void "
"gkg::Curve3d< T >::setEquidistantCurve( int32_t pointCount )" );
}
template < class T >
void gkg::Curve3d< T >::removePoint( const int32_t& index )
{
......
......@@ -41,6 +41,8 @@ class Curve3d : public HeaderedObject, public LightCurve3d< T >
void addPoints( const std::vector< Vector3d< T > >& points );
void addPoints( const Matrix& matrix );
void setEquidistantCurve( int32_t pointCount );
void removePoint( const int32_t& index );
void removePoints( const std::set< int32_t >& indices );
void clear();
......
......@@ -338,6 +338,102 @@ gkg::LightCurve3d< T >::addPoints( const gkg::Matrix& matrix )
}
template < class T >
void gkg::LightCurve3d< T >::setEquidistantCurve( int32_t pointCount )
{
try
{
if ( pointCount < 2 )
{
throw std::runtime_error( "target point count should be at least two" );
}
// collecting old and new point count(s)
int32_t oldPointCount = ( int32_t )this->_points.size();
if ( oldPointCount < 2 )
{
throw std::runtime_error( "origin point count should be at least two" );
}
int32_t newPointCount = pointCount;
// allocating memory for old and new curve length(s)
std::vector< T > oldCurveLength( oldPointCount, ( T )0 );
std::vector< T > newCurveLength( newPointCount, ( T )0 );
// processing old curve length for each old point
int32_t p;
oldCurveLength[ 0 ] = 0;
for ( p = 1; p < oldPointCount; p++ )
{
oldCurveLength[ p ] = oldCurveLength[ p - 1 ] +
( this->_points[ p ] -
this->_points[ p - 1 ] ).getNorm();
}
// taking the curve length
T curveLength = oldCurveLength[ oldPointCount - 1 ];
// processing old curve length for each new point
for ( p = 0; p < newPointCount; p++ )
{
newCurveLength[ p ] = ( T )p * curveLength / ( T )( newPointCount - 1 );
}
// allocating new equidistant point vector
std::vector<gkg::Vector3d< T > > newPoints( newPointCount );
// processing new point(s)
newPoints[ 0 ] = _points[ 0 ];
newPoints[ newPointCount - 1 ] = _points[ oldPointCount - 1 ];
int32_t n;
for ( n = 1; n < newPointCount - 1; n++ )
{
for ( p = 1; p < oldPointCount; p++ )
{
if ( oldCurveLength[ p ] > newCurveLength[ n ] )
{
break;
}
}
newPoints[ n ] = ( this->_points[ p - 1 ] *
( oldCurveLength[ p ] - newCurveLength[ n ] ) +
this->_points[ p ] *
( newCurveLength[ n ] - oldCurveLength[ p - 1 ] ) ) /
( oldCurveLength[ p ] - oldCurveLength[ p - 1 ] );
}
// creating new equidistant curve
this->_points = newPoints;
}
GKG_CATCH( "template < class T > "
"void gkg::LightCurve3d< T >::setEquidistantCurve( "
"int32_t pointCount )" );
}
template < class T >
void gkg::LightCurve3d< T >::removePoint( const int32_t& index )
{
......@@ -711,12 +807,19 @@ gkg::LightCurve3d< T >::getEquidistantCurve( int32_t pointCount ) const
if ( pointCount < 2 )
{
throw std::runtime_error( "point count should be at least two" );
throw std::runtime_error( "target point count should be at least two" );
}
// collecting old and new point count(s)
int32_t oldPointCount = ( int32_t )this->_points.size();
if ( oldPointCount < 2 )
{
throw std::runtime_error( "origin point count should be at least two" );
}
int32_t newPointCount = pointCount;
// allocating memory for old and new curve length(s)
......
......@@ -69,6 +69,9 @@ class LightCurve3d
void addPoints( const std::vector< Vector3d< T > >& points );
void addPoints( const Matrix& matrix );
void setEquidistantCurve( int32_t pointCount );
void removePoint( const int32_t& index );
void removePoints( const std::set< int32_t >& indices );
void clear();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment