本文整理汇总了C++中clipperlib::Path::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Path::size方法的具体用法?C++ Path::size怎么用?C++ Path::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clipperlib::Path
的用法示例。
在下文中一共展示了Path::size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildMansardShape
void buildMansardShape(const utymap::meshing::Polygon& polygon, ClipperLib::Path& offsetShape, std::size_t index)
{
std::reverse(offsetShape.begin(), offsetShape.end());
// build top
utymap::meshing::Polygon topShape(offsetShape.size(), 0);
std::vector<utymap::meshing::Vector2> topShapeVertices;
topShapeVertices.reserve(offsetShape.size());
for (const auto& p : offsetShape) {
topShapeVertices.push_back(utymap::meshing::Vector2(p.X / Scale, p.Y/ Scale));
}
topShape.addContour(topShapeVertices);
auto topOptions = utymap::meshing::MeshBuilder::Options{ 0, 0, colorNoiseFreq_, height_, getColorGradient(), minHeight_ };
builderContext_.meshBuilder.addPolygon(meshContext_.mesh, topShape, topOptions);
// build sides
auto sideOptions = utymap::meshing::MeshBuilder::Options { 0, 0, colorNoiseFreq_, 0, getColorGradient(), 0 };
double topHeight = minHeight_ + height_;
auto size = polygon.points.size();
for (std::size_t i = 0; i < size; i += 2) {
auto topIndex = i;
auto bottomIndex = (index + i) % size;
auto nextTopIndex = (i + 2) % size;
auto nextBottomIndex = (index + i + 2) % size;
auto v0 = utymap::meshing::Vector3(polygon.points[bottomIndex], minHeight_, polygon.points[bottomIndex + 1]);
auto v1 = utymap::meshing::Vector3(polygon.points[nextBottomIndex], minHeight_, polygon.points[nextBottomIndex + 1]);
auto v2 = utymap::meshing::Vector3(topShape.points[nextTopIndex], topHeight, topShape.points[nextTopIndex + 1]);
auto v3 = utymap::meshing::Vector3(topShape.points[topIndex], topHeight, topShape.points[topIndex + 1]);
builderContext_.meshBuilder.addTriangle(meshContext_.mesh, v0, v2, v3, sideOptions, false);
builderContext_.meshBuilder.addTriangle(meshContext_.mesh, v2, v0, v1, sideOptions, false);
}
}
示例2: 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));
}
示例3:
void
ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input, T* output)
{
PROFILE_FUNC();
output->points.clear();
output->points.reserve(input.size());
for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit)
output->points.push_back(Slic3r::Point( (*pit).X, (*pit).Y ));
}
示例4: fromClipperPath
static GeometryCoordinates fromClipperPath(const ClipperLib::Path& path) {
GeometryCoordinates result;
result.reserve(path.size() + 1);
result.reserve(path.size());
for (const auto& p : path) {
using Coordinate = GeometryCoordinates::coordinate_type;
assert(p.x >= std::numeric_limits<Coordinate>::min());
assert(p.x <= std::numeric_limits<Coordinate>::max());
assert(p.y >= std::numeric_limits<Coordinate>::min());
assert(p.y <= std::numeric_limits<Coordinate>::max());
result.emplace_back(Coordinate(p.x), Coordinate(p.y));
}
// Clipper does not repeat initial point, but our geometry model requires it.
if (!result.empty()) {
result.push_back(result.front());
}
return result;
}
示例5: polygon_Convert
static void polygon_Convert( const ClipperLib::Path &aPath,
SEGMENTS &aOutSegment,
float aBiuTo3DunitsScale )
{
aOutSegment.resize( aPath.size() );
for( unsigned i = 0; i < aPath.size(); i++ )
{
aOutSegment[i].m_Start = SFVEC2F( (float) aPath[i].X * aBiuTo3DunitsScale,
(float)-aPath[i].Y * aBiuTo3DunitsScale );
}
unsigned int i;
unsigned int j = aOutSegment.size () - 1;
for( i = 0; i < aOutSegment.size (); j = i++ )
{
// Calculate constants for each segment
aOutSegment[i].m_inv_JY_minus_IY = 1.0f / ( aOutSegment[j].m_Start.y -
aOutSegment[i].m_Start.y );
aOutSegment[i].m_JX_minus_IX = (aOutSegment[j].m_Start.x - aOutSegment[i].m_Start.x);
}
}
示例6: Polygon2d_TestModule
void Polygon2d_TestModule()
{
// "This structure contains a sequence of IntPoint vertices defining a
// single contour"
ClipperLib::Path aPath;
SEGMENTS aSegments;
aPath.resize( 4 );
aPath[0] = ClipperLib::IntPoint( -2, -2 );
aPath[1] = ClipperLib::IntPoint( 2, -2 );
aPath[2] = ClipperLib::IntPoint( 2, 2 );
aPath[3] = ClipperLib::IntPoint( -2, 2 );
// It must be an outter polygon
wxASSERT( ClipperLib::Orientation( aPath ) );
polygon_Convert( aPath, aSegments, 1.0f );
wxASSERT( aPath.size() == aSegments.size() );
wxASSERT( aSegments[0].m_Start == SFVEC2F( -2.0f, 2.0f ) );
wxASSERT( aSegments[1].m_Start == SFVEC2F( 2.0f, 2.0f ) );
wxASSERT( aSegments[2].m_Start == SFVEC2F( 2.0f, -2.0f ) );
wxASSERT( aSegments[3].m_Start == SFVEC2F( -2.0f, -2.0f ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( 0.0f, 0.0f ) ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( -1.9f, -1.9f ) ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( -1.9f, 1.9f ) ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( 1.9f, 1.9f ) ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( 1.9f, -1.9f ) ) );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( -2.1f, -2.0f ) ) == false );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( -2.1f, 2.0f ) ) == false );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( 2.1f, 2.0f ) ) == false );
wxASSERT( polygon_IsPointInside( aSegments, SFVEC2F( 2.1f, -2.0f ) ) == false );
}
示例7: setCoordinates
inline void setCoordinates(T& t, const ClipperLib::Path& path) {
t.coordinates.reserve(path.size());
for (const auto& c : path) {
t.coordinates.push_back(GeoCoordinate(c.Y / Scale, c.X / Scale));
}
}
示例8: rebuildSegment
void BooleanTool::rebuildSegment(
ClipperLib::Path::size_type start_index,
ClipperLib::Path::size_type end_index,
bool sequence_increasing,
const ClipperLib::Path& polygon,
const PolyMap& polymap,
PathObject* object)
{
auto num_points = polygon.size();
object->getCoordinate(object->getCoordinateCount() - 1).setCurveStart(true);
if ((start_index + 1) % num_points == end_index)
{
// This could happen for a straight line or a very flat curve - take coords directly from original
rebuildTwoIndexSegment(start_index, end_index, sequence_increasing, polygon, polymap, object);
return;
}
// Get polygon point coordinates
const auto& start_point = polygon.at(start_index);
const auto& second_point = polygon.at((start_index + 1) % num_points);
const auto& second_last_point = polygon.at((end_index - 1) % num_points);
const auto& end_point = polygon.at(end_index);
// Try to find the middle coordinates in the same part
bool found = false;
PathCoordInfo second_info{ nullptr, nullptr };
PathCoordInfo second_last_info{ nullptr, nullptr };
for (auto second_it = polymap.find(second_point); second_it != polymap.end(); ++second_it)
{
for (auto second_last_it = polymap.find(second_last_point);
second_last_it != polymap.end() && second_last_it.key() == second_last_point;
++second_last_it)
{
if (second_it->first == second_last_it->first &&
second_it->second->index == second_last_it->second->index)
{
// Same part
found = true;
second_info = *second_it;
second_last_info = *second_last_it;
break;
}
}
if (found)
break;
}
if (!found)
{
// Need unambiguous path part information to find the original object with high probability
qDebug() << "BooleanTool::rebuildSegment: cannot identify original object!";
rebuildSegmentFromPathOnly(start_point, second_point, second_last_point, end_point, object);
return;
}
const PathPart* original_path = second_info.first;
// Try to find the outer coordinates in the same part
PathCoordInfo start_info{ nullptr, nullptr };
for (auto start_it = polymap.find(start_point);
start_it != polymap.end() && start_it.key() == start_point;
++start_it)
{
if (start_it->first == original_path)
{
start_info = *start_it;
break;
}
}
Q_ASSERT(!start_info.first || start_info.first == second_info.first);
PathCoordInfo end_info{ nullptr, nullptr };
for (auto end_it = polymap.find(end_point);
end_it != polymap.end() && end_it.key() == end_point;
++end_it)
{
if (end_it->first == original_path)
{
end_info = *end_it;
break;
}
}
Q_ASSERT(!end_info.first || end_info.first == second_info.first);
const PathObject* original = original_path->path;
auto edge_start = second_info.second->index;
if (edge_start == second_info.first->last_index)
edge_start = second_info.first->first_index;
// Find out start tangent
auto start_param = 0.0;
MapCoord start_coord = MapCoord(0.001 * start_point.X, 0.001 * start_point.Y);
MapCoord start_tangent;
MapCoord end_tangent;
MapCoord end_coord;
double start_error_sq, end_error_sq;
// Maximum difference in mm from reconstructed start and end coords to the
//.........这里部分代码省略.........
示例9: polygonToPathPart
void BooleanTool::polygonToPathPart(const ClipperLib::Path& polygon, const PolyMap& polymap, PathObject* object)
{
auto num_points = polygon.size();
if (num_points < 3)
return;
// Index of first used point in polygon
auto part_start_index = 0u;
auto cur_info = PathCoordInfo{ nullptr, nullptr };
// Check if we can find either an unknown intersection point
// or a path coord with parameter 0.
// This gives a starting point to search for curves to rebuild
// (because we cannot start in the middle of a curve)
for (; part_start_index < num_points; ++part_start_index)
{
auto current_point = polygon.at(part_start_index);
if (!polymap.contains(current_point))
break;
if (polymap.value(current_point).second->param == 0.0)
{
cur_info = polymap.value(current_point);
break;
}
}
if (part_start_index == num_points)
{
// Did not find a valid starting point. Return the part as a polygon.
for (auto i = 0u; i < num_points; ++i)
object->addCoordinate(MapCoord(0.001 * polygon.at(i).X, 0.001 * polygon.at(i).Y), (i == 0));
object->parts().back().setClosed(true, true);
return;
}
// Add the first point to the object
rebuildCoordinate(part_start_index, polygon, polymap, object, true);
// Index of first segment point in polygon
auto segment_start_index = part_start_index;
bool have_sequence = false;
bool sequence_increasing = false;
bool stop_before = false;
// Advance along the boundary and rebuild the curve for every sequence
// of path coord pointers with the same path and index.
auto i = part_start_index;
do
{
++i;
if (i >= num_points)
i = 0;
PathCoordInfo new_info{ nullptr, nullptr };
auto new_point = polygon.at(i);
if (polymap.contains(new_point))
new_info = polymap.value(new_point);
if (cur_info.first && cur_info.first == new_info.first)
{
// Same original part
auto cur_coord_index = cur_info.second->index;
MapCoord& cur_coord = cur_info.first->path->getCoordinate(cur_coord_index);
auto new_coord_index = new_info.second->index;
MapCoord& new_coord = new_info.first->path->getCoordinate(new_coord_index);
auto cur_coord_index_adjusted = cur_coord_index;
if (cur_coord_index_adjusted == new_info.first->first_index)
cur_coord_index_adjusted = new_info.first->last_index;
auto new_coord_index_adjusted = new_coord_index;
if (new_coord_index_adjusted == new_info.first->first_index)
new_coord_index_adjusted = new_info.first->last_index;
if (cur_coord_index == new_coord_index)
{
// Somewhere on a curve
bool param_increasing = new_info.second->param > cur_info.second->param;
if (!have_sequence)
{
have_sequence = true;
sequence_increasing = param_increasing;
}
else if (have_sequence && sequence_increasing != param_increasing)
{
stop_before = true;
}
}
else if (new_info.second->param == 0.0 &&
( (cur_coord.isCurveStart() && new_coord_index_adjusted == cur_coord_index + 3) ||
(!cur_coord.isCurveStart() && new_coord_index_adjusted == cur_coord_index + 1) ) )
{
// Original curve is from cur_coord_index to new_coord_index_adjusted.
if (!have_sequence)
{
have_sequence = true;
sequence_increasing = true;
//.........这里部分代码省略.........
示例10: update
void World::update(cv::Mat &homography)
{
this->m_world->Step(dt, 10, 10);
//check contacts
std::vector<MyContact>::iterator pos;
std::map<b2Body*, ClipperLib::Paths*> newBodyMap;
std::vector<b2Body*> removeBarrierList;
for(pos = this->m_contactListener->m_contacts.begin();
pos != this->m_contactListener->m_contacts.end();
++pos)
{
MyContact contact = *pos;
if ((contact.fixtureA == this->m_ballFixture || contact.fixtureB == this->m_ballFixture)
&& (contact.fixtureA->GetBody() != m_groundBody && contact.fixtureB->GetBody() != m_groundBody)
&& (contact.fixtureA->GetBody() != m_paddlesBody && contact.fixtureB->GetBody() != m_paddlesBody))
{
b2Fixture* objectFixture = contact.fixtureA == this->m_ballFixture ? contact.fixtureB : contact.fixtureA;
b2Body *objectBody = objectFixture->GetBody();
if (objectFixture->GetType() == b2Shape::e_edge)
{
cv::Point2f hitPoint = CVUtils::transformPoint(cv::Point2f(contact.contactPoint->x * PTM_RATIO, contact.contactPoint->y * PTM_RATIO), homography);
this->notifyBallHitObservers(hitPoint.x, hitPoint.y);
// change the shape of the fixture
// only go into processing if this body was not processed yet (possible ball hit two fixture of same body)
if (newBodyMap.find(objectBody) == newBodyMap.end())
{
ClipperLib::Paths* bodyPolygons = (ClipperLib::Paths*)objectBody->GetUserData();
b2Vec2* impactVelocity = contact.fixtureA == m_ballFixture ? contact.impactVelocityA : contact.impactVelocityB;
float ballAngle = atan2(impactVelocity->y, impactVelocity->x); // get the angle (in radians) the ball is moving to
float ballPower = impactVelocity->Length() * 0.5; // get the "power" of the ball movement vector
float openingStepInRadians = 10 * CV_PI / 180; // calculate the opening in radians
// create the clipping object/shape - a wedge from ball's center with 30 degree opening over ball direction (angle)
ClipperLib::Path clip;
clip.push_back(ClipperLib::IntPoint(contact.contactPoint->x * PTM_RATIO, contact.contactPoint->y * PTM_RATIO));
for(int step = 9; step > -10; step--)
{
float dx = cos(ballAngle + step * openingStepInRadians) * ballPower;
float dy = sin(ballAngle + step * openingStepInRadians) * ballPower;
clip.push_back(ClipperLib::IntPoint(contact.contactPoint->x * PTM_RATIO + dx, contact.contactPoint->y * PTM_RATIO + dy));
}
ClipperLib::Clipper clipper;
clipper.AddPaths((*bodyPolygons), ClipperLib::ptSubject, true);
clipper.AddPath(clip, ClipperLib::ptClip, true);
// the difference is the new polygon formed by the clipping (collision)
ClipperLib::Paths* newPolygons = new ClipperLib::Paths();
clipper.Execute(ClipperLib::ctDifference, (*newPolygons), ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd);
// Save the new polygons of this body
objectBody->SetUserData(newPolygons);
newBodyMap[objectBody] = newPolygons;
// now, find the intersection regions - these should be inpainted to the scene
ClipperLib::Paths destroyedParts;
clipper.Execute(ClipperLib::ctIntersection, destroyedParts, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd);
// paint the required areas to be coppied
for (size_t i = 0; i < destroyedParts.size(); i++)
{
cv::Point* points = new cv::Point[destroyedParts[i].size()];
for (size_t j = 0; j < destroyedParts[i].size(); j++)
{
points[j].x = (int)destroyedParts[i][j].X;
points[j].y = (int)destroyedParts[i][j].Y;
}
m_destroyedPolygons.push_back(points);
m_destroyedPolygonsPointCount.push_back((int)destroyedParts[i].size());
}
}
}
else if (objectFixture->GetType() == b2Shape::e_circle)
{
// this is a barrier - add it to the remove list
removeBarrierList.push_back(objectBody);
}
}
}
std::map<b2Body*, ClipperLib::Paths*>::iterator iter;
for(iter = newBodyMap.begin(); iter != newBodyMap.end(); iter++)
{
b2Body* objectBody = iter->first;
ClipperLib::Paths* newPolygons = iter->second;
// remove all the current fixtures from this body
for (b2Fixture* f = objectBody->GetFixtureList(); f; )
{
//.........这里部分代码省略.........