本文整理汇总了C++中ConvexHull::addPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ ConvexHull::addPoint方法的具体用法?C++ ConvexHull::addPoint怎么用?C++ ConvexHull::addPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConvexHull
的用法示例。
在下文中一共展示了ConvexHull::addPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findConvexHull
ConvexHull findConvexHull(PointSet *pointSet) {
int pointCount = pointSet->getSize();
pointSet->sortPointsByAngle();
if (pointCount <= 3) { // The points are already a convex hull
ConvexHull hull;
for (int i = 0; i < pointCount; ++i) {
hull.addPoint(*pointSet->getPoint(i));
}
if (pointCount > 0) {
hull.addPoint(*pointSet->getPoint(0));
}
return hull;
}
std::stack<const Point *> candiates;
const Point *prev;
const Point *now;
candiates.push(pointSet->getLastPoint());
candiates.push(pointSet->getReferencePoint()); // Is always the first (idx 0)
// element in the point set
for (int i = 1; i < pointCount;) {
const Point *point = pointSet->getPoint(i);
now = candiates.top();
candiates.pop();
prev = candiates.top();
candiates.push(now);
if (isCCW(prev->pos(), now->pos(), point->pos())) {
if (point->pos() == now->pos() && USE_CUSTOM_ALGO_FIX) {
std::cout << "I saved your algorithm" << std::endl;
} else {
candiates.push(point);
}
++i;
} else {
candiates.pop();
}
}
ConvexHull hull(candiates);
return hull;
}
示例2: findConvexHullStep
HullState findConvexHullStep(PointSet *pointSet, int simulateUntilStep) {
int step = 0;
int pointCount = pointSet->getSize();
pointSet->sortPointsByAngle();
//++step;
if (step++ == simulateUntilStep) // sort done -> update numbers
{
return HullState::SortDone(step);
}
if (pointCount <= 3) { // The points are already a convex hull
ConvexHull hull;
for (int i = 0; i < pointCount; ++i) {
hull.addPoint(*pointSet->getPoint(i));
}
if (pointCount > 0) {
hull.addPoint(*pointSet->getPoint(0));
}
return HullState::HullFound(hull);
}
std::stack<const Point *> candiates;
const Point *prev;
const Point *now;
candiates.push(pointSet->getLastPoint());
candiates.push(pointSet->getReferencePoint()); // Is always the first (idx 0)
// element in the point set
//++step;
if (step++ == simulateUntilStep) // break print candidates
{
return HullState::CandidateAdded(candiates, step);
}
for (int i = 1; i < pointCount;) {
const Point *point = pointSet->getPoint(i);
now = candiates.top();
candiates.pop();
prev = candiates.top();
candiates.push(now);
if (isCCW(prev->pos(), now->pos(), point->pos())) {
candiates.push(point);
// std::cout << "adding " << i << std::endl;
++i;
//++step;
if (step++ == simulateUntilStep) // break print candidates
{
return HullState::CandidateAdded(candiates, step);
}
} else {
//++step;
if (step++ == simulateUntilStep) // break print candidates
{
return HullState::CandidatePoped(candiates, point, step);
}
// std::cout << "pop" << std::endl;
candiates.pop();
}
}
ConvexHull hull(candiates);
return HullState::HullFound(hull);
}