OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::tex2color::cgalutils Namespace Reference

Typedefs

using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel
using CGALMesh = CGAL::Surface_mesh<Kernel::Point_3>

Functions

CGALMesh trimesh_to_cgal (const TriMesh &mesh)
TriMesh cgal_to_trimesh (const CGALMesh &cm)
bool is_mesh_halfedge_compatible (const TriMesh &mesh)
bool convert_trimesh_to_cgal (const TriMesh &mesh, CGALMesh &cgal_mesh)
bool convert_trimesh_to_cgal (const TriMesh &mesh, const std::vector< Vec2f > &vertex_uvs, CGALMesh &cgal_mesh, std::vector< Vec2f > &cgal_vertex_uvs)

Typedef Documentation

◆ CGALMesh

using Slic3r::tex2color::cgalutils::CGALMesh = CGAL::Surface_mesh<Kernel::Point_3>

◆ Kernel

using Slic3r::tex2color::cgalutils::Kernel = CGAL::Exact_predicates_inexact_constructions_kernel

Function Documentation

◆ cgal_to_trimesh()

TriMesh Slic3r::tex2color::cgalutils::cgal_to_trimesh ( const CGALMesh & cm)
inline
33 {
34 TriMesh mesh;
35 std::map<CGALMesh::Vertex_index, size_t> vmap;
36 size_t idx = 0;
37 for (auto v : cm.vertices()) {
38 if (!cm.is_valid(v) || cm.is_removed(v)) continue;
39 auto p = cm.point(v);
40 mesh.vertices.push_back(Vec3f((float)p.x(), (float)p.y(), (float)p.z()));
41 vmap[v] = idx++;
42 }
43 for (auto f : cm.faces()) {
44 if (!cm.is_valid(f) || cm.is_removed(f)) continue;
45 auto h = cm.halfedge(f);
46 auto v0 = cm.target(h);
47 auto v1 = cm.target(cm.next(h));
48 auto v2 = cm.target(cm.next(cm.next(h)));
49 mesh.indices.push_back(Vec3i32((int)vmap[v0], (int)vmap[v1], (int)vmap[v2]));
50 }
51 return mesh;
52}
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124
Eigen::Matrix< int32_t, 3, 1, Eigen::DontAlign > Vec3i32
Definition Point.hpp:59
Definition TriMesh.hpp:15

References Slic3r::f().

Referenced by Slic3r::tex2color::color_utils::smooth_region_labels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_trimesh_to_cgal() [1/2]

bool Slic3r::tex2color::cgalutils::convert_trimesh_to_cgal ( const TriMesh & mesh,
CGALMesh & cgal_mesh )
inline
141 {
142 cgal_mesh = trimesh_to_cgal(mesh);
143 return cgal_mesh.number_of_faces() > 0 || mesh.indices.empty();
144}
CGALMesh trimesh_to_cgal(const TriMesh &mesh)
Definition CgalUtils.hpp:22

References trimesh_to_cgal().

Referenced by Slic3r::tex2color::color_utils::get_components(), Slic3r::tex2color::color_utils::is_closed(), Slic3r::tex2color::color_utils::mesh_cluster(), Slic3r::tex2color::color_utils::remesh_mesh(), and Slic3r::tex2color::color_utils::smooth_region_labels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_trimesh_to_cgal() [2/2]

bool Slic3r::tex2color::cgalutils::convert_trimesh_to_cgal ( const TriMesh & mesh,
const std::vector< Vec2f > & vertex_uvs,
CGALMesh & cgal_mesh,
std::vector< Vec2f > & cgal_vertex_uvs )
inline
149{
150 cgal_mesh.clear();
151 std::vector<CGALMesh::Vertex_index> vmap(mesh.vertices.size());
152 cgal_vertex_uvs.clear();
153
154 for (size_t i = 0; i < mesh.vertices.size(); ++i) {
155 vmap[i] = cgal_mesh.add_vertex(Kernel::Point_3(
156 mesh.vertices[i].x(), mesh.vertices[i].y(), mesh.vertices[i].z()));
157 }
158
159 cgal_vertex_uvs.resize(cgal_mesh.num_vertices());
160 for (size_t i = 0; i < mesh.vertices.size(); ++i) {
161 if (i < vertex_uvs.size())
162 cgal_vertex_uvs[vmap[i]] = vertex_uvs[i];
163 else
164 cgal_vertex_uvs[vmap[i]] = Vec2f(0.f, 0.f);
165 }
166
167 for (const auto& f : mesh.indices)
168 cgal_mesh.add_face(vmap[f[0]], vmap[f[1]], vmap[f[2]]);
169
170 return true;
171}
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:64

References Slic3r::f().

Here is the call graph for this function:

◆ is_mesh_halfedge_compatible()

bool Slic3r::tex2color::cgalutils::is_mesh_halfedge_compatible ( const TriMesh & mesh)
inline
54 {
55 std::vector<std::unordered_set<std::size_t>> vtx_to_adj_faces(mesh.vertices.size());
56 std::size_t edge_id = 0;
57 std::vector<std::unordered_set<std::size_t>> edge_to_faces;
58 std::vector<std::unordered_set<std::size_t>> vtx_to_prev_vtxs(mesh.vertices.size());
59 std::vector<std::unordered_set<std::size_t>> vtx_to_next_vtxs(mesh.vertices.size());
60 std::vector<std::unordered_map<std::size_t, std::size_t>> vtx_vtx_to_edge(mesh.vertices.size());
61
62 for (std::size_t fid = 0; fid < mesh.indices.size(); ++fid) {
63 const TriFace& face = mesh.indices[fid];
64 if (face[0] == face[1] || face[1] == face[2] || face[2] == face[0]) {
65 return false;
66 }
67 for (std::size_t i = 0; i < 3; ++i) {
68 if (static_cast<std::size_t>(face[i]) >= mesh.vertices.size()) {
69 return false;
70 }
71 vtx_to_adj_faces[face[i]].insert(fid);
72
73 std::size_t prev_vtx = face[(i + 2) % 3];
74 std::size_t next_vtx = face[(i + 1) % 3];
75
76 if (vtx_to_prev_vtxs[face[i]].count(prev_vtx)) {
77 return false;
78 }
79 vtx_to_prev_vtxs[face[i]].insert(prev_vtx);
80
81 if (vtx_to_next_vtxs[face[i]].count(next_vtx)) {
82 return false;
83 }
84 vtx_to_next_vtxs[face[i]].insert(next_vtx);
85 }
86
87 for (std::size_t i = 0; i < 3; ++i) {
88 std::size_t va = face[i];
89 std::size_t vb = face[(i + 1) % 3];
90 if (!vtx_vtx_to_edge[va].count(vb)) {
91 vtx_vtx_to_edge[va][vb] = edge_id;
92 vtx_vtx_to_edge[vb][va] = edge_id;
93 ++edge_id;
94 edge_to_faces.emplace_back(std::unordered_set<std::size_t>());
95 }
96 edge_to_faces[vtx_vtx_to_edge[va][vb]].insert(fid);
97 }
98 }
99
100 for (std::size_t vid = 0; vid < mesh.vertices.size(); ++vid) {
101 if (vtx_to_adj_faces[vid].empty()) {
102 continue;
103 }
104 std::unordered_set<std::size_t> visited_faces;
105 std::queue<std::size_t> face_queue;
106 face_queue.push(*(vtx_to_adj_faces[vid].begin()));
107 visited_faces.insert(*(vtx_to_adj_faces[vid].begin()));
108 while (!face_queue.empty()) {
109 std::size_t fid = face_queue.front();
110 face_queue.pop();
111 const TriFace& face = mesh.indices[fid];
112 for (std::size_t i = 0; i < 3; ++i) {
113 if (static_cast<std::size_t>(face[i]) != vid) {
114 continue;
115 }
116 std::size_t v_next = face[(i + 1) % 3];
117 std::size_t v_prev = face[(i + 2) % 3];
118 for (std::size_t nbr : {v_next, v_prev}) {
119 std::size_t eid = vtx_vtx_to_edge[vid][nbr];
120 for (std::size_t adj_fid : edge_to_faces[eid]) {
121 if (!visited_faces.count(adj_fid) && vtx_to_adj_faces[vid].count(adj_fid)) {
122 visited_faces.insert(adj_fid);
123 face_queue.push(adj_fid);
124 }
125 }
126 }
127 break;
128 }
129 }
130
131 for (std::size_t fid : vtx_to_adj_faces[vid]) {
132 if (!visited_faces.count(fid)) {
133 return false;
134 }
135 }
136 }
137
138 return true;
139}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
stl_triangle_vertex_indices TriFace
Definition TriMesh.hpp:12
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References count, and Slic3r::empty().

Here is the call graph for this function:

◆ trimesh_to_cgal()

CGALMesh Slic3r::tex2color::cgalutils::trimesh_to_cgal ( const TriMesh & mesh)
inline
22 {
23 CGALMesh cm;
24 std::vector<CGALMesh::Vertex_index> vmap(mesh.vertices.size());
25 for (size_t i = 0; i < mesh.vertices.size(); ++i)
26 vmap[i] = cm.add_vertex(Kernel::Point_3(mesh.vertices[i].x(), mesh.vertices[i].y(), mesh.vertices[i].z()));
27 for (const auto& f : mesh.indices) {
28 cm.add_face(vmap[f[0]], vmap[f[1]], vmap[f[2]]);
29 }
30 return cm;
31}
CGAL::Surface_mesh< Kernel::Point_3 > CGALMesh
Definition CgalUtils.hpp:20

References Slic3r::f().

Referenced by convert_trimesh_to_cgal().

Here is the call graph for this function:
Here is the caller graph for this function: