mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Extended tesselation wrapper for other 3d and 2d point types.
This commit is contained in:
		
							parent
							
								
									4357c80793
								
							
						
					
					
						commit
						d0553ece0e
					
				
					 5 changed files with 63 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -22,6 +22,7 @@ typedef Point Vector;
 | 
			
		|||
// Vector types with a fixed point coordinate base type.
 | 
			
		||||
typedef Eigen::Matrix<coord_t,  2, 1, Eigen::DontAlign> Vec2crd;
 | 
			
		||||
typedef Eigen::Matrix<coord_t,  3, 1, Eigen::DontAlign> Vec3crd;
 | 
			
		||||
typedef Eigen::Matrix<int,      2, 1, Eigen::DontAlign> Vec2i;
 | 
			
		||||
typedef Eigen::Matrix<int,      3, 1, Eigen::DontAlign> Vec3i;
 | 
			
		||||
typedef Eigen::Matrix<int64_t,  2, 1, Eigen::DontAlign> Vec2i64;
 | 
			
		||||
typedef Eigen::Matrix<int64_t,  3, 1, Eigen::DontAlign> Vec3i64;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ public:
 | 
			
		|||
        gluDeleteTess(m_tesselator);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Pointf3s tesselate(const ExPolygon &expoly, double z_, bool flipped_)
 | 
			
		||||
    std::vector<Vec3d> tesselate3d(const ExPolygon &expoly, double z_, bool flipped_)
 | 
			
		||||
    {
 | 
			
		||||
        m_z = z_;
 | 
			
		||||
        m_flipped = flipped_;
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ public:
 | 
			
		|||
        return std::move(m_output_triangles);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Pointf3s tesselate(const ExPolygons &expolygons, double z_, bool flipped_)
 | 
			
		||||
    std::vector<Vec3d> tesselate3d(const ExPolygons &expolygons, double z_, bool flipped_)
 | 
			
		||||
    {
 | 
			
		||||
        m_z = z_;
 | 
			
		||||
        m_flipped = flipped_;
 | 
			
		||||
| 
						 | 
				
			
			@ -189,16 +189,60 @@ private:
 | 
			
		|||
    bool            m_flipped;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Pointf3s triangulate_expolygons_3df(const ExPolygon &poly, coordf_t z, bool flip)
 | 
			
		||||
std::vector<Vec3d> triangulate_expolygon_3d(const ExPolygon &poly, coordf_t z, bool flip)
 | 
			
		||||
{
 | 
			
		||||
    GluTessWrapper tess;
 | 
			
		||||
    return tess.tesselate(poly, z, flip);
 | 
			
		||||
    return tess.tesselate3d(poly, z, flip);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Pointf3s triangulate_expolygons_3df(const ExPolygons &polys, coordf_t z, bool flip)
 | 
			
		||||
std::vector<Vec3d> triangulate_expolygons_3d(const ExPolygons &polys, coordf_t z, bool flip)
 | 
			
		||||
{
 | 
			
		||||
	GluTessWrapper tess;
 | 
			
		||||
    return tess.tesselate(polys, z, flip);
 | 
			
		||||
    return tess.tesselate3d(polys, z, flip);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Vec2d> triangulate_expolygon_2d(const ExPolygon &poly, bool flip)
 | 
			
		||||
{
 | 
			
		||||
    GluTessWrapper tess;
 | 
			
		||||
    std::vector<Vec3d> triangles = tess.tesselate3d(poly, 0, flip);
 | 
			
		||||
    std::vector<Vec2d> out;
 | 
			
		||||
    out.reserve(triangles.size());
 | 
			
		||||
    for (const Vec3d &pt : triangles)
 | 
			
		||||
        out.emplace_back(pt.x(), pt.y());
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Vec2d> triangulate_expolygons_2d(const ExPolygons &polys, bool flip)
 | 
			
		||||
{
 | 
			
		||||
    GluTessWrapper tess;
 | 
			
		||||
    std::vector<Vec3d> triangles = tess.tesselate3d(polys, 0, flip);
 | 
			
		||||
    std::vector<Vec2d> out;
 | 
			
		||||
    out.reserve(triangles.size());
 | 
			
		||||
    for (const Vec3d &pt : triangles)
 | 
			
		||||
        out.emplace_back(pt.x(), pt.y());
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Vec2f> triangulate_expolygon_2f(const ExPolygon &poly, bool flip)
 | 
			
		||||
{
 | 
			
		||||
    GluTessWrapper tess;
 | 
			
		||||
    std::vector<Vec3d> triangles = tess.tesselate3d(poly, 0, flip);
 | 
			
		||||
    std::vector<Vec2f> out;
 | 
			
		||||
    out.reserve(triangles.size());
 | 
			
		||||
    for (const Vec3d &pt : triangles)
 | 
			
		||||
        out.emplace_back(float(pt.x()), float(pt.y()));
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Vec2f> triangulate_expolygons_2f(const ExPolygons &polys, bool flip)
 | 
			
		||||
{
 | 
			
		||||
    GluTessWrapper tess;
 | 
			
		||||
    std::vector<Vec3d> triangles = tess.tesselate3d(polys, 0, flip);
 | 
			
		||||
    std::vector<Vec2f> out;
 | 
			
		||||
    out.reserve(triangles.size());
 | 
			
		||||
    for (const Vec3d &pt : triangles)
 | 
			
		||||
        out.emplace_back(float(pt.x()), float(pt.y()));
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Slic3r
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,8 +10,12 @@ namespace Slic3r {
 | 
			
		|||
class ExPolygon;
 | 
			
		||||
typedef std::vector<ExPolygon> ExPolygons;
 | 
			
		||||
 | 
			
		||||
extern Pointf3s triangulate_expolygons_3df(const ExPolygon &poly, coordf_t z = 0, bool flip = false);
 | 
			
		||||
extern Pointf3s triangulate_expolygons_3df(const ExPolygons &polys, coordf_t z = 0, bool flip = false);
 | 
			
		||||
extern std::vector<Vec3d> triangulate_expolygon_3d (const ExPolygon  &poly,  coordf_t z = 0, bool flip = false);
 | 
			
		||||
extern std::vector<Vec3d> triangulate_expolygons_3d(const ExPolygons &polys, coordf_t z = 0, bool flip = false);
 | 
			
		||||
extern std::vector<Vec2d> triangulate_expolygon_2d (const ExPolygon  &poly,  bool flip = false);
 | 
			
		||||
extern std::vector<Vec2d> triangulate_expolygons_2d(const ExPolygons &polys, bool flip = false);
 | 
			
		||||
extern std::vector<Vec2f> triangulate_expolygon_2f (const ExPolygon  &poly,  bool flip = false);
 | 
			
		||||
extern std::vector<Vec2f> triangulate_expolygons_2f(const ExPolygons &polys, bool flip = false);
 | 
			
		||||
 | 
			
		||||
} // namespace Slic3r
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1781,7 +1781,7 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
 | 
			
		|||
        BOOST_LOG_TRIVIAL(trace) << "TriangleMeshSlicer::cut - triangulating upper part";
 | 
			
		||||
        ExPolygons section;
 | 
			
		||||
        this->make_expolygons_simple(upper_lines, §ion);
 | 
			
		||||
        Pointf3s triangles = triangulate_expolygons_3df(section, z, true);
 | 
			
		||||
        Pointf3s triangles = triangulate_expolygons_3d(section, z, true);
 | 
			
		||||
        stl_facet facet;
 | 
			
		||||
        facet.normal = stl_normal(0, 0, -1.f);
 | 
			
		||||
        for (size_t i = 0; i < triangles.size(); ) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1795,7 +1795,7 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower)
 | 
			
		|||
        BOOST_LOG_TRIVIAL(trace) << "TriangleMeshSlicer::cut - triangulating lower part";
 | 
			
		||||
        ExPolygons section;
 | 
			
		||||
        this->make_expolygons_simple(lower_lines, §ion);
 | 
			
		||||
        Pointf3s triangles = triangulate_expolygons_3df(section, z, false);
 | 
			
		||||
        Pointf3s triangles = triangulate_expolygons_3d(section, z, false);
 | 
			
		||||
        stl_facet facet;
 | 
			
		||||
        facet.normal = stl_normal(0, 0, -1.f);
 | 
			
		||||
        for (size_t i = 0; i < triangles.size(); ) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6833,20 +6833,20 @@ void GLCanvas3D::_render_sla_slices() const
 | 
			
		|||
            {
 | 
			
		||||
                // calculate model bottom cap
 | 
			
		||||
                if (bottom_obj_triangles.empty() && (it_min_z->second.model_slices_idx < model_slices.size()))
 | 
			
		||||
                    bottom_obj_triangles = triangulate_expolygons_3df(model_slices[it_min_z->second.model_slices_idx], min_z, true);
 | 
			
		||||
                    bottom_obj_triangles = triangulate_expolygons_3d(model_slices[it_min_z->second.model_slices_idx], min_z, true);
 | 
			
		||||
                // calculate support bottom cap
 | 
			
		||||
                if (bottom_sup_triangles.empty() && (it_min_z->second.support_slices_idx < support_slices.size()))
 | 
			
		||||
                    bottom_sup_triangles = triangulate_expolygons_3df(support_slices[it_min_z->second.support_slices_idx], min_z, true);
 | 
			
		||||
                    bottom_sup_triangles = triangulate_expolygons_3d(support_slices[it_min_z->second.support_slices_idx], min_z, true);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (it_max_z != index.end())
 | 
			
		||||
            {
 | 
			
		||||
                // calculate model top cap
 | 
			
		||||
                if (top_obj_triangles.empty() && (it_max_z->second.model_slices_idx < model_slices.size()))
 | 
			
		||||
                    top_obj_triangles = triangulate_expolygons_3df(model_slices[it_max_z->second.model_slices_idx], max_z, false);
 | 
			
		||||
                    top_obj_triangles = triangulate_expolygons_3d(model_slices[it_max_z->second.model_slices_idx], max_z, false);
 | 
			
		||||
                // calculate support top cap
 | 
			
		||||
                if (top_sup_triangles.empty() && (it_max_z->second.support_slices_idx < support_slices.size()))
 | 
			
		||||
					top_sup_triangles = triangulate_expolygons_3df(support_slices[it_max_z->second.support_slices_idx], max_z, false);
 | 
			
		||||
					top_sup_triangles = triangulate_expolygons_3d(support_slices[it_max_z->second.support_slices_idx], max_z, false);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue