本文整理汇总了C++中cclib::ReferenceCloud::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ ReferenceCloud::reserve方法的具体用法?C++ ReferenceCloud::reserve怎么用?C++ ReferenceCloud::reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cclib::ReferenceCloud
的用法示例。
在下文中一共展示了ReferenceCloud::reserve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ICP
//.........这里部分代码省略.........
std::vector<ScalarType> distances;
try
{
distances.resize(count);
}
catch (const std::bad_alloc&)
{
ccLog::Error("Not enough memory!");
return false;
}
for (unsigned i=0; i<count; ++i)
{
distances[i] = dataCloud->getPointScalarValue(i);
}
ParallelSort(distances.begin(), distances.end());
//now look for the max value at 'finalOverlapRatio+margin' percent
maxSearchDist = distances[static_cast<unsigned>(std::max(1.0,count*(finalOverlapRatio+s_overlapMarginRatio)))-1];
}
//evntually select the points with distance below 'maxSearchDist'
//(should roughly correspond to 'finalOverlapRatio + margin' percent)
{
CCLib::ReferenceCloud* refCloud = new CCLib::ReferenceCloud(dataCloud);
cloudGarbage.add(refCloud);
unsigned countBefore = dataCloud->size();
unsigned baseIncrement = static_cast<unsigned>(std::max(100.0,countBefore*finalOverlapRatio*0.05));
for (unsigned i=0; i<countBefore; ++i)
{
if (dataCloud->getPointScalarValue(i) <= maxSearchDist)
{
if ( refCloud->size() == refCloud->capacity()
&& !refCloud->reserve(refCloud->size() + baseIncrement) )
{
ccLog::Error("Not enough memory!");
return false;
}
refCloud->addPointIndex(i);
}
}
refCloud->resize(refCloud->size());
dataCloud = refCloud;
unsigned countAfter = dataCloud->size();
double keptRatio = static_cast<double>(countAfter)/countBefore;
ccLog::Print(QString("[ICP][Partial overlap] Selecting %1 points out of %2 (%3%) for registration").arg(countAfter).arg(countBefore).arg(static_cast<int>(100*keptRatio)));
//update the relative 'final overlap' ratio
finalOverlapRatio /= keptRatio;
}
}
//weights
CCLib::ScalarField* modelWeights = nullptr;
CCLib::ScalarField* dataWeights = nullptr;
{
if (!modelMesh && useModelSFAsWeights)
{
if (modelCloud == dynamic_cast<CCLib::GenericIndexedCloudPersist*>(model) && model->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pc = static_cast<ccPointCloud*>(model);
modelWeights = pc->getCurrentDisplayedScalarField();
if (!modelWeights)
ccLog::Warning("[ICP] 'useDataSFAsWeights' is true but model has no displayed scalar field!");
}
示例2: removeHiddenPoints
//.........这里部分代码省略.........
PointCoordinateType r2 = P.norm2();
if (maxRadius < r2)
maxRadius = r2;
}
//we add the view point (Cf. HPR)
*_pt_array++ = 0;
*_pt_array++ = 0;
*_pt_array++ = 0;
maxRadius = sqrt(maxRadius);
}
//apply spherical flipping
{
maxRadius *= 2.0f*pow(10.0f,fParam);
coordT* _pt_array = pt_array;
for (unsigned i=0; i<nbPoints; ++i)
{
CCVector3 P = *theCloud->getPoint(i) - viewPoint;
double r = (double)(maxRadius/P.norm()) - 1.0;
*_pt_array++ *= r;
*_pt_array++ *= r;
*_pt_array++ *= r;
}
}
//array to flag points on the convex hull
std::vector<bool> pointBelongsToCvxHull;
if (!qh_new_qhull(3,nbPoints+1,pt_array,False,(char*)"qhull QJ Qci",0,stderr))
{
try
{
pointBelongsToCvxHull.resize(nbPoints+1,false);
}
catch(std::bad_alloc)
{
//not enough memory!
delete[] pt_array;
return 0;
}
vertexT *vertex = 0,**vertexp = 0;
facetT *facet = 0;
FORALLfacets
{
//if (!facet->simplicial)
// error("convhulln: non-simplicial facet"); // should never happen with QJ
setT* vertices = qh_facet3vertex(facet);
FOREACHvertex_(vertices)
{
pointBelongsToCvxHull[qh_pointid(vertex->point)] = true;
}
qh_settempfree(&vertices);
}
}
delete[] pt_array;
pt_array=0;
qh_freeqhull(!qh_ALL);
//free long memory
int curlong, totlong;
qh_memfreeshort (&curlong, &totlong);
//free short memory and memory allocator
if (!pointBelongsToCvxHull.empty())
{
//compute the number of points belonging to the convex hull
unsigned cvxHullSize = 0;
{
for (unsigned i=0; i<nbPoints; ++i)
if (pointBelongsToCvxHull[i])
++cvxHullSize;
}
CCLib::ReferenceCloud* visiblePoints = new CCLib::ReferenceCloud(theCloud);
if (cvxHullSize!=0 && visiblePoints->reserve(cvxHullSize))
{
for (unsigned i=0; i<nbPoints; ++i)
if (pointBelongsToCvxHull[i])
visiblePoints->addPointIndex(i); //can't fail, see above
return visiblePoints;
}
else //not enough memory
{
delete visiblePoints;
visiblePoints=0;
}
}
return 0;
}
示例3: removeHiddenPoints
CCLib::ReferenceCloud* qHPR::removeHiddenPoints(CCLib::GenericIndexedCloudPersist* theCloud, float viewPoint[], float fParam)
{
assert(theCloud);
unsigned i,nbPoints = theCloud->size();
if (nbPoints==0)
return 0;
CCLib::ReferenceCloud* newCloud = new CCLib::ReferenceCloud(theCloud);
//less than 4 points ? no need for calculation, we return the whole cloud
if (nbPoints<4)
{
if (!newCloud->reserve(nbPoints)) //well, we never know ;)
{
//not enough memory!
delete newCloud;
return 0;
}
newCloud->addPointIndex(0,nbPoints);
return newCloud;
}
//view point
coordT Cx = viewPoint[0];
coordT Cy = viewPoint[1];
coordT Cz = viewPoint[2];
float* radius = new float[nbPoints];
if (!radius)
{
//not enough memory!
delete newCloud;
return 0;
}
float r,maxRadius = 0.0;
//table of points
coordT* pt_array = new coordT[(nbPoints+1)*3];
coordT* _pt_array = pt_array;
theCloud->placeIteratorAtBegining();
//#define BACKUP_PROJECTED_CLOUDS
#ifdef BACKUP_PROJECTED_CLOUDS
FILE* fp = fopen("output_centered.asc","wt");
#endif
double x,y,z;
for (i=0;i<nbPoints;++i)
{
const CCVector3* P = theCloud->getNextPoint();
*(_pt_array++)=x=coordT(P->x)-Cx;
*(_pt_array++)=y=coordT(P->y)-Cy;
*(_pt_array++)=z=coordT(P->z)-Cz;
//we pre-compute the radius ...
r = (float)sqrt(x*x+y*y+z*z);
//in order to determine the max radius
if (maxRadius<r)
maxRadius = r;
radius[i] = r;
#ifdef BACKUP_PROJECTED_CLOUDS
fprintf(fp,"%f %f %f %f\n",x,y,z,r);
#endif
}
//we add the view point (Cf. HPR)
*(_pt_array++)=0.0;
*(_pt_array++)=0.0;
*(_pt_array++)=0.0;
#ifdef BACKUP_PROJECTED_CLOUDS
fprintf(fp,"%f %f %f %f\n",0,0,0,0);
fclose(fp);
#endif
maxRadius *= 2.0f*pow(10.0f,fParam);
_pt_array = pt_array;
#ifdef BACKUP_PROJECTED_CLOUDS
fp = fopen("output_transformed.asc","wt");
#endif
for (i=0;i<nbPoints;++i)
{
//Spherical flipping
r = maxRadius/radius[i]-1.0f;
#ifndef BACKUP_PROJECTED_CLOUDS
*(_pt_array++) *= double(r);
*(_pt_array++) *= double(r);
*(_pt_array++) *= double(r);
#else
x = *_pt_array * double(r);
*(_pt_array++) = x;
y = *_pt_array * double(r);
*(_pt_array++) = y;
z = *_pt_array * double(r);
*(_pt_array++) = z;
fprintf(fp,"%f %f %f %f\n",x,y,z,r);
#endif
}
#ifdef BACKUP_PROJECTED_CLOUDS
fclose(fp);
#endif
//.........这里部分代码省略.........