本文整理汇总了C++中clipperlib::Paths类的典型用法代码示例。如果您正苦于以下问题:C++ Paths类的具体用法?C++ Paths怎么用?C++ Paths使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paths类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toClipper
ClipperLib::Paths Clipper::toClipper(const std::vector<ofPolyline>& polylines,
ClipperLib::cInt scale)
{
ClipperLib::Paths paths;
for (auto& polyline: polylines) paths.push_back(toClipper(polyline, scale));
return paths;
}
示例2: pathObjectToPolygons
void BooleanTool::pathObjectToPolygons(
const PathObject* object,
ClipperLib::Paths& polygons,
PolyMap& polymap)
{
object->update();
polygons.reserve(polygons.size() + object->parts().size());
for (const auto& part : object->parts())
{
const PathCoordVector& path_coords = part.path_coords;
auto path_coords_end = path_coords.size();
if (part.isClosed())
--path_coords_end;
ClipperLib::Path polygon;
for (auto i = 0u; i < path_coords_end; ++i)
{
auto point = MapCoord { path_coords[i].pos };
polygon.push_back(ClipperLib::IntPoint(point.nativeX(), point.nativeY()));
polymap.insertMulti(polygon.back(), std::make_pair(&part, &path_coords[i]));
}
bool orientation = Orientation(polygon);
if ( (&part == &object->parts().front()) != orientation )
{
std::reverse(polygon.begin(), polygon.end());
}
// Push_back shall move the polygon.
static_assert(std::is_nothrow_move_constructible<ClipperLib::Path>::value, "ClipperLib::Path must be nothrow move constructible");
polygons.push_back(polygon);
}
}
示例3:
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input)
{
ClipperLib::Paths retval;
for (Polylines::const_iterator it = input.begin(); it != input.end(); ++it)
retval.emplace_back(Slic3rMultiPoint_to_ClipperPath(*it));
return retval;
}
示例4: build
void build(utymap::meshing::Polygon& polygon)
{
ClipperLib::ClipperOffset offset;
ClipperLib::Path path;
path.reserve(polygon.points.size() / 2);
auto lastPointIndex = polygon.points.size() - 2;
double min = std::numeric_limits<double>::max();
for (std::size_t i = 0; i < polygon.points.size(); i += 2) {
auto nextIndex = i == lastPointIndex ? 0 : i + 2;
utymap::meshing::Vector2 v1(polygon.points[i], polygon.points[i + 1]);
utymap::meshing::Vector2 v2(polygon.points[nextIndex], polygon.points[nextIndex + 1]);
min = std::min(min, utymap::meshing::Vector2::distance(v1, v2));
path.push_back(ClipperLib::IntPoint(static_cast<ClipperLib::cInt>(v1.x * Scale),
static_cast<ClipperLib::cInt>(v1.y * Scale)));
}
offset.AddPath(path, ClipperLib::JoinType::jtMiter, ClipperLib::EndType::etClosedPolygon);
ClipperLib::Paths solution;
// NOTE: use minimal side value as reference for offsetting.
offset.Execute(solution, -(min / 10) * Scale);
// NOTE: this is unexpected result for algorithm below, fallback to flat roof.
if (solution.size() != 1 || solution[0].size() != path.size()) {
return FlatRoofBuilder::build(polygon);
}
buildMansardShape(polygon, solution[0], findFirstIndex(solution[0][0], polygon));
}
示例5: convert
ClipperLib::Paths ClipperHelpers::convert(
const QVector<Path>& paths,
const PositiveLength& maxArcTolerance) noexcept {
ClipperLib::Paths p;
p.reserve(paths.size());
foreach (const Path& path, paths) {
p.push_back(convert(path, maxArcTolerance));
}
示例6:
T
ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input)
{
T retval;
for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it)
retval.push_back(ClipperPath_to_Slic3rMultiPoint<typename T::value_type>(*it));
return retval;
}
示例7: scaleClipperPolygons
void scaleClipperPolygons(ClipperLib::Paths &polygons)
{
PROFILE_FUNC();
for (ClipperLib::Paths::iterator it = polygons.begin(); it != polygons.end(); ++it)
for (ClipperLib::Path::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) {
pit->X <<= CLIPPER_OFFSET_POWER_OF_2;
pit->Y <<= CLIPPER_OFFSET_POWER_OF_2;
}
}
示例8:
void
scaleClipperPolygons(ClipperLib::Paths &polygons, const double scale)
{
for (ClipperLib::Paths::iterator it = polygons.begin(); it != polygons.end(); ++it) {
for (ClipperLib::Path::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) {
(*pit).X *= scale;
(*pit).Y *= scale;
}
}
}
示例9: unscaleClipperPolygons
void unscaleClipperPolygons(ClipperLib::Paths &polygons)
{
PROFILE_FUNC();
for (ClipperLib::Paths::iterator it = polygons.begin(); it != polygons.end(); ++it)
for (ClipperLib::Path::iterator pit = (*it).begin(); pit != (*it).end(); ++pit) {
pit->X += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA;
pit->Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA;
pit->X >>= CLIPPER_OFFSET_POWER_OF_2;
pit->Y >>= CLIPPER_OFFSET_POWER_OF_2;
}
}
示例10:
void
ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input, T* output)
{
PROFILE_FUNC();
output->clear();
output->reserve(input.size());
for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it) {
typename T::value_type p;
ClipperPath_to_Slic3rMultiPoint(*it, &p);
output->push_back(p);
}
}
示例11: double_polygon_to_path
void Grasp_Calculator::double_polygon_to_path(DPolygon2D double_polygon, ClipperLib::Paths &int_polygon)
{
ClipperLib::cInt factor = 100000;
ClipperLib::Path int_poly;
int_polygon.clear();
for (std::vector<DoublePoint2D>::iterator p2d = double_polygon.begin(); p2d != double_polygon.end(); ++p2d)
{
ClipperLib::IntPoint p;
p.X = (ClipperLib::cInt)(factor * p2d->x);
p.Y = (ClipperLib::cInt)(factor * p2d->y);
int_poly.push_back(p);
}
int_polygon.push_back(int_poly);
}
示例12:
std::vector<polygon> polygon::from(const ClipperLib::Paths& paths, base_int maxDenom)
{
std::vector<polygon> ret;
for(auto iter = paths.begin(); iter != paths.end(); iter++)
{
ret.push_back(polygon());
auto& polyRef = ret.back();
for(auto point = iter->begin(); point != iter->end(); point++)
{
polyRef.vertexes.push_back(vec2d(int_frac(point->X, maxDenom), int_frac(point->Y, maxDenom)));
}
}
return ret;
}
示例13: safety_offset
void safety_offset(ClipperLib::Paths* paths)
{
PROFILE_FUNC();
// scale input
scaleClipperPolygons(*paths);
// perform offset (delta = scale 1e-05)
ClipperLib::ClipperOffset co;
#ifdef CLIPPER_UTILS_DEBUG
if (clipper_export_enabled) {
static int iRun = 0;
export_clipper_input_polygons_bin(debug_out_path("safety_offset-polygons-%d", ++iRun).c_str(), *paths, ClipperLib::Paths());
}
#endif /* CLIPPER_UTILS_DEBUG */
ClipperLib::Paths out;
for (size_t i = 0; i < paths->size(); ++ i) {
ClipperLib::Path &path = (*paths)[i];
co.Clear();
co.MiterLimit = 2;
bool ccw = ClipperLib::Orientation(path);
if (! ccw)
std::reverse(path.begin(), path.end());
{
PROFILE_BLOCK(safety_offset_AddPaths);
co.AddPath((*paths)[i], ClipperLib::jtMiter, ClipperLib::etClosedPolygon);
}
{
PROFILE_BLOCK(safety_offset_Execute);
// offset outside by 10um
ClipperLib::Paths out_this;
co.Execute(out_this, ccw ? 10.f * float(CLIPPER_OFFSET_SCALE) : -10.f * float(CLIPPER_OFFSET_SCALE));
if (! ccw) {
// Reverse the resulting contours once again.
for (ClipperLib::Paths::iterator it = out_this.begin(); it != out_this.end(); ++ it)
std::reverse(it->begin(), it->end());
}
if (out.empty())
out = std::move(out_this);
else
std::move(std::begin(out_this), std::end(out_this), std::back_inserter(out));
}
}
*paths = std::move(out);
// unscale output
unscaleClipperPolygons(*paths);
}
示例14: void
DLL_PUBLIC void CDECL execute_offset(ClipperLib::ClipperOffset *ptr, double delta,
void* outputArray, void(*append)(void* outputArray, size_t polyIndex, ClipperLib::IntPoint point)) {
ClipperLib::Paths paths = ClipperLib::Paths();
try {
ptr->Execute(paths, delta);
} catch(ClipperLib::clipperException e) {
printf(e.what());
}
for (size_t i = 0; i < paths.size(); i++) {
for (auto &point: paths[i]) {
append(outputArray, i, point);
}
}
}
示例15: setObjectsToBeModeled
// Set the objects (defined by contour points) to be models in the world and scene.
void World::setObjectsToBeModeled(const std::vector<std::vector<cv::Point>> contours) {
int contourSize = (int)contours.size();
for(int i = 0; i < contourSize; i++ )
{
std::vector<cv::Point> currentShape = contours[i];
int numOfPoints = (int)currentShape.size();
b2Vec2 * vertices = new b2Vec2[numOfPoints];
ClipperLib::Paths* polygons = new ClipperLib::Paths();
ClipperLib::Path polygon;
for (int j = 0; j < numOfPoints; j++)
{
vertices[j].x = currentShape[j].x / PTM_RATIO;
vertices[j].y = currentShape[j].y / PTM_RATIO;
//cv::line(m_scene, currentShape[j], currentShape[(j + 1) % numOfPoints], cv::Scalar(0,0,255));
//std::cout << "[" << vertices[j].x << "," <<vertices[j].y << "]" << std::endl;
polygon.push_back(ClipperLib::IntPoint(currentShape[j].x, currentShape[j].y));
}
b2BodyDef objectBodyDef;
objectBodyDef.type = b2_staticBody;
b2Body *objectBody = m_world->CreateBody(&objectBodyDef);
objectBody->SetUserData(polygons);
polygons->push_back(polygon);
b2EdgeShape objectEdgeShape;
b2FixtureDef objectShapeDef;
objectShapeDef.shape = &objectEdgeShape;
for (int j = 0; j < numOfPoints - 1; j++)
{
objectEdgeShape.Set(vertices[j], vertices[j+1]);
objectBody->CreateFixture(&objectShapeDef);
}
objectEdgeShape.Set(vertices[numOfPoints - 1], vertices[0]);
objectBody->CreateFixture(&objectShapeDef);
m_objectBodies.push_back(objectBody);
delete[] vertices;
}
}