本文整理汇总了C++中PointArray::front方法的典型用法代码示例。如果您正苦于以下问题:C++ PointArray::front方法的具体用法?C++ PointArray::front怎么用?C++ PointArray::front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PointArray
的用法示例。
在下文中一共展示了PointArray::front方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplineInterpolate
static void SplineInterpolate( const PointArray& inPts, PointArray& outPts, unsigned int N )
{
int point_num = inPts.size();
// 闭合
bool isClose = IsPointEqual( inPts.back(), inPts.front() );
if( isClose )
{
point_num--;
}
// Creates all control points to create the curve of
Spline::ControlPoint* points = new Spline::ControlPoint[point_num];
for( int i = 0; i < point_num; i++ )
{
points[i].position.x = ( float )inPts[i].x;
points[i].position.y = ( float )inPts[i].y;
points[i].position.z = 0.0f;
}
// Creates the curve. First argument is a pointer to the control points.
// Second argument is the number of control points. The third is the curve type.
// 注:使用cardinal spline,类型为CARDINAL(默认系数为1)或 CATMULLROM(自动计算系数)
SplineWrapper* curve = new SplineWrapper( points, point_num, CATMULLROM );
// 偏移量(将个数放大1倍,更加细密一些)
//const int N = 1;
const float C = 0.8f;
float d = curve->getLength() / ( point_num * N - 1 );
// The SplineWrapper has a position which is a value between 0 and the total length
// of the curve. With the move(...) function you can increase or decrease this value
// to move on the curve. The getPosition() function returns the world position
// depending on how far you have moved on the curve.
while( !curve->isEndReached() )
{
// Get the world position
Position pos = curve->getPosition();
outPts.push_back( Position2DT_Point( pos ) );
// Travel 0.5 units on the curve each iteration
curve->move( d );
}
outPts.push_back( inPts[point_num - 1] );
delete curve;
// 删除点数组内存
delete [] points;
points = 0;
if( isClose )
{
outPts.push_back( inPts.front() );
}
}
示例2: SearchLabelPostion
// 采用近似估计的算法
// 如果是闭合等值线,则搜索整个多边形中最长的边
// 如果是开放等值线,则搜索20%--80%范围内的多边形中最长边
void SearchLabelPostion( const PointArray& cnpts, DT_Point& tpt, double& angle )
{
if( cnpts.empty() ) return;
// 通常情况下,等值线至少有3个点
int s = 0, t = cnpts.size();
if( !IsPointEqual( cnpts.front(), cnpts.back() ) )
{
s = cnpts.size() / 5;
t = cnpts.size() - s;
}
int pos = s;
double maxDist = Distance_2( cnpts[0], cnpts[1] );
for( int i = s; i < t - 1; i++ )
{
double dist = Distance_2( cnpts[i], cnpts[i + 1] );
if( dist > maxDist )
{
pos = i;
maxDist = dist;
}
}
tpt = MidPoint( cnpts[pos], cnpts[pos + 1] );
angle = Direction( cnpts[pos], cnpts[pos + 1] );
}
示例3: ApproximatePolygon
static void ApproximatePolygon( const PointArray& cnpts, PointArray& polygon, double tolerance )
{
if( cnpts.empty() ) return;
int n = cnpts.size();
// 是否封闭等值线???
if( IsPointEqual( cnpts.front(), cnpts.back() ) )
{
n--;
}
int minEdge = n + 1, k = n;
IntArray indexes;
for( int i = 0; i < ( int )cnpts.size(); i++ )
{
indexes.push_back( i );
}
while( k < minEdge )
{
minEdge = k;
int p = 0;
while( p < minEdge - ( n % 2 == 0 ? 3 : 2 ) )
{
double distance = GetPointDistanceToLine( cnpts[indexes[p + 1]], cnpts[indexes[p]], cnpts[indexes[p + 2]] );
if ( distance < tolerance )
{
indexes[p + 1] = -1;
k -= 1;
}
p += 2;
}
UpdateIndexes( indexes );
}
for( int i = 0; i < ( int )indexes.size(); i++ )
{
polygon.push_back( cnpts[indexes[i]] );
}
}