OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
CutSurface.cpp File Reference
#include "CutSurface.hpp"
#include "libslic3r/Emboss.hpp"
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh/Surface_mesh.h>
#include "libslic3r/Point.hpp"
#include "libslic3r/ExPolygon.hpp"
#include <cstdint>
#include <limits>
#include <string>
#include <utility>
#include "libslic3r/BoundingBox.hpp"
#include <cstddef>
#include "libslic3r/Polygon.hpp"
#include <cassert>
#include <array>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <queue>
#include <CGAL/enum.h>
#include <CGAL/Kernel/global_functions_3.h>
#include <CGAL/Named_function_parameters.h>
#include "libslic3r/AABBTreeIndirect.hpp"
#include <cstdlib>
#include "libslic3r/libslic3r.h"
#include <boost/property_map/property_map.hpp>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_traits_3.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <iterator>
#include <optional>
#include <CGAL/Surface_mesh/IO/OFF.h>
#include "ExPolygonsIndex.hpp"
#include <boost/next_prior.hpp>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Exact_integer.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Cartesian_converter.h>
#include <tbb/parallel_for.h>
#include "TriangleMesh.hpp"
#include "Utils.hpp"
#include "ClipperUtils.hpp"
#include "libslic3r/AABBTreeLines.hpp"
#include "libslic3r/Line.hpp"
#include <CGAL/Polygon_mesh_processing/clip.h>
Include dependency graph for CutSurface.cpp:

Go to the source code of this file.

Classes

struct  priv::IntersectingElement
 IntersectingElement. More...
struct  priv::SurfacePatch
struct  priv::ModelCutId
class  priv::ModelCut2index
 Keep conversion from VCutAOIs to Index and vice versa Model_index .. contour(or hole) poin from ExPolygons Index .. continous number. More...
struct  priv::ProjectionDistance
 To select surface near projection distance. More...
struct  priv::Visitor
 Track source of intersection Help for anotate inner and outer faces. More...
struct  priv::ClosePoint
struct  priv::SearchData
struct  priv::Source
struct  priv::IntersectionSources
 Corefine visitor Store intersection source for vertices of constrained edge of tm1 Must be used with corefine flag no modification of tm2. More...
struct  priv::SurfacePatchEx

Namespaces

namespace  priv

Typedefs

using priv::Project = Emboss::IProjection
using priv::Project3d = Emboss::IProject3d
using priv::EpicKernel = CGAL::Exact_predicates_inexact_constructions_kernel
using priv::CutMesh = CGAL::Surface_mesh<EpicKernel::Point_3>
using priv::CutMeshes = std::vector<CutMesh>
using priv::VI = CGAL::SM_Vertex_index
using priv::HI = CGAL::SM_Halfedge_index
using priv::EI = CGAL::SM_Edge_index
using priv::FI = CGAL::SM_Face_index
using priv::P3 = CGAL::Epick::Point_3
using priv::EdgeShapeMap = CutMesh::Property_map<EI, IntersectingElement>
using priv::FaceShapeMap = CutMesh::Property_map<FI, IntersectingElement>
using priv::VertexShapeMap = CutMesh::Property_map<VI, const IntersectingElement *>
using priv::FaceTypeMap = CutMesh::Property_map<FI, FaceType>
using priv::CvtVI2VI = CutMesh::Property_map<VI, VI>
using priv::ReductionMap = CvtVI2VI
using priv::EdgeBoolMap = CutMesh::Property_map<EI, bool>
using priv::CutAOI = std::pair<std::vector<FI>, std::vector<HI>>
using priv::CutAOIs = std::vector<CutAOI>
using priv::VCutAOIs = std::vector<CutAOIs>
using priv::Loop = std::vector<VI>
using priv::Loops = std::vector<Loop>
using priv::SurfacePatches = std::vector<SurfacePatch>
using priv::ProjectionDistances = std::vector<ProjectionDistance>
using priv::VDistances = std::vector<ProjectionDistances>
using priv::PointNormal = std::pair<Vec3d, Vec3d>
using priv::PointNormals = std::array<PointNormal, 4>
using priv::IsOnSides = std::vector<std::array<bool, 4>>
using priv::Sources = std::vector<Source>
using priv::VertexSourceMap = CutMesh::Property_map<VI, Source>
using priv::SurfacePatchesEx = std::vector<SurfacePatchEx>
using priv::BBS = std::vector<BoundingBoxf3>
using priv::Primitive = CGAL::AABB_face_graph_triangle_primitive<CutMesh>
using priv::Traits = CGAL::AABB_traits_3<EpicKernel, Primitive>
using priv::Ray = EpicKernel::Ray_3
using priv::Tree = CGAL::AABB_tree<Traits>
using priv::Trees = std::vector<Tree>

Enumerations

enum class  priv::FaceType { priv::inside , priv::outside , priv::not_constrained , priv::inside_processed }
 Flag for faces in CGAL mesh. More...

Functions

void priv::set_skip_for_out_of_aoi (std::vector< bool > &skip_indicies, const indexed_triangle_set &its, const Project &projection, const BoundingBox &shapes_bb)
 Set true for indices out of area of interest.
void priv::set_skip_by_angle (std::vector< bool > &skip_indicies, const indexed_triangle_set &its, const Project3d &projection, double max_angle=89.)
 Set true for indicies outward and almost parallel together. Note: internally calculate normals.
Vec3d priv::to_vec3d (const P3 &p)
CutMesh priv::to_cgal (const indexed_triangle_set &its, const std::vector< bool > &skip_indicies, bool flip=false)
 Convert triangle mesh model to CGAL Surface_mesh Filtrate out opposite triangles Add property map for source face index.
CutMesh priv::to_cgal (const ExPolygons &shapes, const Project &projection)
 Covert 2d shape (e.g. Glyph) to CGAL model NOTE: internaly create edge_shape_map .. Property map to store conversion from edge to contour face_shape_map .. Property map to store conversion from face to contour.
bool priv::exist_duplicit_vertex (const CutMesh &mesh)
void priv::create_reduce_map (ReductionMap &reduction_map, const CutMesh &meshes)
 Create map to reduce unnecesary triangles, Triangles are made by divided quad to two triangles on side of cutting shape mesh Note: also use from mesh (have to be created) face_type_map .. Type of shape inside / outside vert_shape_map .. Source of outline vertex.
CutAOIs priv::cut_from_model (CutMesh &cgal_model, const ExPolygons &shapes, CutMesh &cgal_shape, float projection_ratio, const ExPolygonsIndices &s2i)
 Create AOIs(area of interest) on model surface.
Loops priv::create_loops (const std::vector< HI > &outlines, const CutMesh &mesh)
 Create closed loops of contour vertices created from open half edges.
SurfacePatches priv::diff_models (VCutAOIs &cuts, CutMeshes &cut_models, CutMeshes &models, const Project3d &projection)
 Differenciate other models.
bool priv::is_over_whole_expoly (const CutAOI &cutAOI, const ExPolygon &shape, const CutMesh &mesh)
 Checking whether patch is uninterrupted cover of whole expolygon it belongs.
bool priv::is_over_whole_expoly (const SurfacePatch &patch, const ExPolygons &shapes, const VCutAOIs &cutAOIs, const CutMeshes &meshes)
 Checking whether patch is uninterrupted cover of whole expolygon it belongs.
Polygons priv::unproject_loops (const SurfacePatch &patch, const Project &projection, Vec2d &depth_range)
 Unptoject points from outline loops of patch.
ExPolygon priv::to_expoly (const SurfacePatch &patch, const Project &projection, Vec2d &depth_range)
 Unproject points from loops and create expolygons.
VDistances priv::calc_distances (const SurfacePatches &patches, const CutMeshes &models, const CutMesh &shapes_mesh, size_t count_shapes_points, float projection_ratio)
 Calculate distances for SurfacePatches outline points NOTE: each model has to have "vert_shape_map" .. Know source of new vertices.
ProjectionDistances priv::choose_best_distance (const VDistances &distances, const ExPolygons &shapes, const Point &start, const ExPolygonsIndices &s2i, const SurfacePatches &patches)
 Select distances in similar depth between expolygons.
std::vector< bool > priv::select_patches (const ProjectionDistances &best_distances, const SurfacePatches &patches, const ExPolygons &shapes, const BoundingBox &shapes_bb, const ExPolygonsIndices &s2i, const VCutAOIs &cutAOIs, const CutMeshes &meshes, const Project &projection)
 Create mask for patches.
void priv::append (SurfaceCut &sc, SurfaceCut &&sc_add)
 Merge two surface cuts together Added surface cut will be consumed.
SurfaceCut priv::patch2cut (SurfacePatch &patch)
 Convert patch to indexed_triangle_set.
SurfaceCut priv::merge_patches (SurfacePatches &patches, const std::vector< bool > &mask)
 Merge masked patches to one surface cut.
bool priv::is_out_of (const Vec3d &v, const PointNormal &point_normal)
 Check.
bool priv::is_all_on_one_side (const Vec3i32 &t, const IsOnSides &is_on_sides)
 Check if triangle t has all vertices out of any plane.
bool priv::is_face_inside (HI hi, const CutMesh &mesh, const CutMesh &shape_mesh, const VertexShapeMap &vertex_shape_map, const ExPolygonsIndices &shape2index)
 Distiquish face type for half edge.
void priv::set_face_type (FaceTypeMap &face_type_map, const CutMesh &mesh, const VertexShapeMap &vertex_shape_map, const EdgeBoolMap &ecm, const CutMesh &shape_mesh, const ExPolygonsIndices &shape2index)
 Face with constrained edge are inside/outside by type of intersection Other set to not_constrained(still it could be inside/outside).
void priv::flood_fill_inner (const CutMesh &mesh, FaceTypeMap &face_type_map)
 Change FaceType from not_constrained to inside For neighbor(or neighbor of neighbor of ...) of inside triangles. Process only not_constrained triangles.
void priv::collect_surface_data (std::queue< FI > &process, std::vector< FI > &faces, std::vector< HI > &outlines, FaceTypeMap &face_type_map, const CutMesh &mesh)
 Collect connected inside faces Collect outline half edges.
CutAOIs priv::create_cut_area_of_interests (const CutMesh &mesh, const ExPolygons &shapes, FaceTypeMap &face_type_map)
 Create areas from mesh surface.
float priv::calc_distance (const P3 &p, uint32_t pi, const CutMesh &shapes_mesh, float projection_ratio)
 Calculate projection distance of point [in mm].
float priv::calc_size_sq (const Point &p)
SearchData priv::create_search_data (const ExPolygons &shapes, const std::vector< bool > &mask)
uint32_t priv::get_closest_point_index (const SearchData &sd, size_t line_idx, const Vec2d &hit_point, const ExPolygons &shapes, const ExPolygonsIndices &s2i)
uint32_t priv::find_closest_point_index (const Point &p, const ExPolygons &shapes, const ExPolygonsIndices &s2i, const std::vector< bool > &mask)
std::pair< uint32_t, uint32_t > priv::find_closest_point_pair (const ExPolygons &shapes, const std::vector< bool > &done_shapes, const ExPolygonsIndices &s2i, const std::vector< bool > &mask)
const ProjectionDistance * priv::get_closest_projection (const ProjectionDistances &distance, float wanted_distance)
void priv::fill_polygon_distances (const ProjectionDistance &pd, uint32_t index, const ExPolygonsIndex &id, ProjectionDistances &result, const ExPolygon &shape, const VDistances &distances)
void priv::fill_shape_distances (uint32_t start_index, const ProjectionDistance *start_pd, ProjectionDistances &result, const ExPolygonsIndices &s2i, const ExPolygon &shape, const VDistances &distances)
ClosePoint priv::find_close_point (const Point &p, ProjectionDistances &result, std::vector< bool > &finished_shapes, const ExPolygonsIndices &s2i, const ExPolygons &shapes)
const VI priv::default_vi (std::numeric_limits< uint32_t >::max())
void priv::create_face_types (FaceTypeMap &map, const CutMesh &tm1, const CutMesh &tm2, const EdgeBoolMap &ecm, const VertexSourceMap &sources)
 Create map1 and map2.
bool priv::clip_cut (SurfacePatch &cut, CutMesh clipper)
 Implement 'cut' Minus 'clipper', where clipper is reverse input Volume NOTE: clipper will be modified (corefined by cut) !!!
BoundingBoxf3 priv::bounding_box (const CutAOI &cut, const CutMesh &mesh)
BoundingBoxf3 priv::bounding_box (const CutMesh &mesh)
BoundingBoxf3 priv::bounding_box (const SurfacePatch &ecut)
SurfacePatch priv::create_surface_patch (const std::vector< FI > &fis, CutMesh &mesh, const ReductionMap *rmap=nullptr)
 Create patch.
BBS priv::create_bbs (const VCutAOIs &cuts, const CutMeshes &cut_models)
 Create bounding boxes for AOI.
Trees priv::create_trees (const CutMeshes &models)
 Create AABB trees for check when patch is whole inside of model.
bool priv::has_bb_intersection (const BoundingBoxf3 &bb, size_t model_index, const BBS &bbs, const ModelCut2index &m2i)
 Check whether bounding box has intersection with model.
bool priv::is_patch_inside_of_model (const SurfacePatch &patch, const Tree &tree, const Project3d &projection)
 Only for model without intersection Use ray (in projection direction) from a point from patch and count intersections: pair .. outside | odd .. inside.
uint32_t priv::get_shape_point_index (const CutAOI &cut, const CutMesh &model)
 Return some shape point index which identify shape NOTE: Used to find expolygon index.
SurfacePatch priv::separate_patch (const std::vector< FI > &fis, SurfacePatch &patch, const CvtVI2VI &cvt_from)
 Separate triangles singned with number n.
void priv::divide_patch (size_t i, SurfacePatchesEx &patches)
 Separate connected triangles into it's own patches new patches are added to back of input patches.
void priv::collect_open_edges (SurfacePatches &patches)
 Fill outline in patches by open edges.

Variables

const std::string priv::edge_shape_map_name = "e:IntersectingElement"
const std::string priv::face_shape_map_name = "f:IntersectingElement"
const std::string priv::vert_shape_map_name = "v:IntersectingElement"
const std::string priv::face_type_map_name = "f:side"
const std::string priv::patch_source_name = "v:patch_source"
const std::string priv::vertex_reduction_map_name = "v:reduction"
const std::string priv::is_constrained_edge_name = "e:is_constrained"
const std::string priv::vertex_source_map_name = "v:SourceIntersecting"

Class Documentation

◆ priv::SurfacePatch

struct priv::SurfacePatch
Collaboration diagram for priv::SurfacePatch:
Class Members
size_t aoi_id
BoundingBoxf3 bb
bool is_whole_aoi = true
Loops loops
CutMesh mesh
size_t model_id
size_t shape_id = 0

◆ priv::ModelCutId

struct priv::ModelCutId
Class Members
uint32_t cut_index
uint32_t model_index

◆ priv::ProjectionDistance

struct priv::ProjectionDistance

To select surface near projection distance.

Class Members
uint32_t aoi_index = std::numeric_limits<uint32_t>::max()
float distance = std::numeric_limits<float>::max()
uint32_t model_index = std::numeric_limits<uint32_t>::max()
uint32_t patch_index = std::numeric_limits<uint32_t>::max()

◆ priv::ClosePoint

struct priv::ClosePoint
Class Members
float dist_sq = std::numeric_limits<float>::max()
uint32_t index = std::numeric_limits<uint32_t>::max()

◆ priv::SearchData

struct priv::SearchData
Collaboration diagram for priv::SearchData:
Class Members
vector< size_t > cvt
vector< Linef > lines
Tree< 2, double > tree

◆ priv::Source

struct priv::Source
Class Members
HI hi
int sdim =0

◆ priv::SurfacePatchEx

struct priv::SurfacePatchEx
Collaboration diagram for priv::SurfacePatchEx:
Class Members
bool full_inside = false
bool just_cliped = false
SurfacePatch patch