예제 #1
0
Slic3r::Polyline ClipperPath_to_Slic3rPolyline(const ClipperLib::Path &input)
{
    Polyline retval;
    for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit)
        retval.points.emplace_back(pit->X, pit->Y);
    return retval;
}
예제 #2
0
    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);
        }
    }
예제 #3
0
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);
	}
}
예제 #4
0
void
ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input, T &output)
{
    output.points.clear();
    for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit) {
        output.points.push_back(Slic3r::Point( (*pit).X, (*pit).Y ));
    }
}
예제 #5
0
void scaleClipperPolygon(ClipperLib::Path &polygon)
{
    PROFILE_FUNC();
    for (ClipperLib::Path::iterator pit = polygon.begin(); pit != polygon.end(); ++pit) {
        pit->X <<= CLIPPER_OFFSET_POWER_OF_2;
        pit->Y <<= CLIPPER_OFFSET_POWER_OF_2;
    }
}
예제 #6
0
T
ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input)
{
    T retval;
    for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit)
        retval.points.push_back(Point( (*pit).X, (*pit).Y ));
    return retval;
}
예제 #7
0
	DLL_PUBLIC double CDECL area(ClipperLib::IntPoint* path, size_t count) {
		ClipperLib::Path v = ClipperLib::Path();
		for(size_t i = 0; i < count; i++) {
			v.emplace(v.end(), path[i].X, path[i].Y);
		}

		return ClipperLib::Area(v);
	}
예제 #8
0
	//==============================================================
	// Static functions
	//==============================================================
	DLL_PUBLIC bool CDECL orientation(ClipperLib::IntPoint* path, size_t count) {
		ClipperLib::Path v = ClipperLib::Path();
		for(size_t i = 0; i < count; i++) {
			v.emplace(v.end(), path[i].X, path[i].Y);
		}

		return ClipperLib::Orientation(v);
	}
예제 #9
0
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 ));
}
예제 #10
0
void unscaleClipperPolygon(ClipperLib::Path &polygon)
{
    PROFILE_FUNC();
    for (ClipperLib::Path::iterator pit = polygon.begin(); pit != polygon.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;
    }
}
예제 #11
0
std::string
SVG::get_path_d(const ClipperLib::Path &path, double scale, bool closed) const
{
    std::ostringstream d;
    d << "M ";
    for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) {
        d << COORD(scale * p->X - origin.x) << " ";
        d << COORD(scale * p->Y - origin.y) << " ";
    }
    if (closed) d << "z";
    return d.str();
}
void Grasp_Calculator::path_to_double_polygon(DPolygon2D &double_polygon, ClipperLib::Path int_polygon)
{
    ClipperLib::cInt factor = 100000;
    double_polygon.clear();
    for (std::vector<IntPoint>::iterator ip = int_polygon.begin(); ip != int_polygon.end(); ++ip)
    {
        DoublePoint2D d2p;
        d2p.x = ((double)ip->X) / factor;
        d2p.y = ((double)ip->Y) / factor;
        double_polygon.push_back(d2p);
    }
}
예제 #13
0
	DLL_PUBLIC void CDECL add_offset_path(ClipperLib::ClipperOffset *ptr, ClipperLib::IntPoint* path, size_t count,
																				ClipperLib::JoinType joinType, ClipperLib::EndType endType) {
		ClipperLib::Path v = ClipperLib::Path();
		for(size_t i = 0; i < count; i++) {
			v.emplace(v.end(), path[i].X, path[i].Y);
		}

		try {
			ptr->AddPath(v, joinType, endType);
		} catch(ClipperLib::clipperException e) {
			printf(e.what());
		}
	}
예제 #14
0
	DLL_PUBLIC bool CDECL add_path(ClipperLib::Clipper *ptr, ClipperLib::IntPoint* path, size_t count, ClipperLib::PolyType polyType, bool closed) {
		ClipperLib::Path v = ClipperLib::Path();
		for(size_t i = 0; i < count; i++) {
			v.emplace(v.end(), path[i].X, path[i].Y);
		}

		bool result = false;

		try {
			result = ptr->AddPath(v, polyType, closed);
		} catch(ClipperLib::clipperException e) {
			printf(e.what());
		}

		return result;
	}
geo::Polygon<geo::Ring<Vector>> Environment::subtract(geo::Polygon<geo::Ring<Vector>> const& poly, geo::Ring<Vector> const& ring) {
	
	ClipperLib::Path subj;
  	ClipperLib::Paths solution;
  	
  	ClipperLib::Clipper c;
	
  	for (Vector const& v : poly.ering)
  		subj.push_back(ClipperLib::IntPoint((int)v.x, (int)v.y));
  	c.AddPath(subj, ClipperLib::ptSubject, true);

  	for (Ring const& ring : poly.irings) {
		subj.clear();
		for (Vector const& v : ring)
  			subj.push_back(ClipperLib::IntPoint((int)v.x, (int)v.y));
  	   	std::reverse(subj.begin(), subj.end());
  		c.AddPath(subj, ClipperLib::ptSubject, true);
  	}
	
	subj.clear();
  	for (Vector const& v : ring)
  		subj.push_back(ClipperLib::IntPoint((int)v.x, (int)v.y));
  	c.AddPath(subj, ClipperLib::ptClip, true);

    c.Execute(ClipperLib::ctDifference, solution);
    geo::Polygon<geo::Ring<Vector>> ans;
    for (ClipperLib::IntPoint const& pt : solution[0]) {
    	ans.ering.push_back({pt.X, pt.Y});
    }
    for (int i = 1; i < solution.size(); ++i) {
    	ClipperLib::Path const& path = solution[i];
    	geo::Ring<Vector> ring;
    	for (ClipperLib::IntPoint const& pt : path)
    		ring.push_back({pt.X, pt.Y});
    	ans.irings.push_back(ring);
    }
    geo::correct(ans);
	return ans;

}