Janitor : Avoid pointers to temporary objects

This commit is contained in:
Magne Sjaastad 2020-12-15 08:12:19 +01:00
parent 9f1c1264cf
commit 9bbb56ceee
2 changed files with 17 additions and 21 deletions

View File

@ -32,8 +32,6 @@ RiaPolyArcLineSampler::RiaPolyArcLineSampler( const cvf::Vec3d& sta
, m_maxSamplingsInterval( 0.15 )
, m_isResamplingLines( true )
, m_totalMD( 0.0 )
, m_points( nullptr )
, m_meshDs( nullptr )
{
}
@ -45,26 +43,24 @@ std::pair<std::vector<cvf::Vec3d>, std::vector<double>>
{
CVF_ASSERT( sampleInterval > 0.0 );
std::vector<cvf::Vec3d> points;
std::vector<double> mds;
m_maxSamplingsInterval = sampleInterval;
m_isResamplingLines = isResamplingLines;
m_points.clear();
m_meshDs.clear();
double startMD = 0.0;
std::vector<cvf::Vec3d> pointsNoDuplicates = RiaPolyArcLineSampler::pointsWithoutDuplicates( m_lineArcEndPoints );
if ( pointsNoDuplicates.size() < 2 ) return std::make_pair( points, mds );
if ( pointsNoDuplicates.size() < 2 ) return std::make_pair( m_points, m_meshDs );
m_points = &points;
m_meshDs = &mds;
m_totalMD = startMD;
cvf::Vec3d p1 = pointsNoDuplicates[0];
m_points->push_back( p1 );
m_meshDs->push_back( m_totalMD );
m_points.push_back( p1 );
m_meshDs.push_back( m_totalMD );
cvf::Vec3d t2 = m_startTangent;
@ -73,7 +69,7 @@ std::pair<std::vector<cvf::Vec3d>, std::vector<double>>
sampleSegment( t2, pointsNoDuplicates[pIdx], pointsNoDuplicates[pIdx + 1], &t2 );
}
return std::make_pair( points, mds );
return std::make_pair( m_points, m_meshDs );
}
//--------------------------------------------------------------------------------------------------
@ -132,15 +128,15 @@ void RiaPolyArcLineSampler::sampleLine( cvf::Vec3d p1, cvf::Vec3d p2, cvf::Vec3d
while ( mdInc < p1p2Length )
{
cvf::Vec3d ps = p1 + mdInc * tp1p2;
m_points->push_back( ps );
m_meshDs->push_back( m_totalMD + mdInc );
m_points.push_back( ps );
m_meshDs.push_back( m_totalMD + mdInc );
mdInc += m_maxSamplingsInterval;
}
}
m_totalMD += p1p2Length;
m_points->push_back( p2 );
m_meshDs->push_back( m_totalMD );
m_points.push_back( p2 );
m_meshDs.push_back( m_totalMD );
( *endTangent ) = p1p2.getNormalized();
}
@ -180,13 +176,13 @@ void RiaPolyArcLineSampler::sampleArc( cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec3d
C_to_incP.transformPoint( arcCS );
m_points->push_back( C_to_incP );
m_meshDs->push_back( m_totalMD + angle * radius );
m_points.push_back( C_to_incP );
m_meshDs.push_back( m_totalMD + angle * radius );
}
m_totalMD += arcAngle * radius;
m_points->push_back( p2 );
m_meshDs->push_back( m_totalMD );
m_points.push_back( p2 );
m_meshDs.push_back( m_totalMD );
( *endTangent ) = CS_rad.endTangent();
}

View File

@ -37,8 +37,8 @@ private:
void sampleArc( cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec3d p2, cvf::Vec3d* endTangent );
void sampleSegment( cvf::Vec3d t1, cvf::Vec3d p1, cvf::Vec3d p2, cvf::Vec3d* endTangent );
std::vector<cvf::Vec3d>* m_points; // Internal temporary pointers to collections being filled.
std::vector<double>* m_meshDs;
std::vector<cvf::Vec3d> m_points;
std::vector<double> m_meshDs;
double m_maxSamplingsInterval;
const double m_maxSamplingArcAngle = 0.07310818; // Angle from 6 deg dogleg on 10 m