23#ifndef VCL_ALGORITHMS_MESH_INTERSECTION_H
24#define VCL_ALGORITHMS_MESH_INTERSECTION_H
26#include <vclib/algorithms/core/intersection/element.h>
27#include <vclib/mesh/requirements.h>
80 EdgeMeshConcept EdgeMesh,
81 FaceMeshConcept MeshType,
82 PlaneConcept PlaneType>
85 using VertexType = MeshType::VertexType;
86 using FaceType = MeshType::FaceType;
87 using CoordType = VertexType::CoordType;
91 std::vector<double>
qH(
m.vertexContainerSize());
93 for (
const VertexType& v :
m.vertices())
94 qH[
m.index(v)] =
pl.dist(v.coord());
96 for (
const FaceType& f :
m.faces()) {
97 std::vector<CoordType>
ptVec;
98 std::vector<CoordType>
nmVec;
99 for (uint
j = 0;
j < f.vertexNumber(); ++
j) {
100 if (
qH[
m.index(f.vertex(
j))] == 0) {
101 ptVec.push_back(f.vertex(
j)->coord());
103 if (isPerVertexNormalAvailable(
m)) {
104 nmVec.push_back(f.vertex(
j)->normal());
109 (
qH[
m.index(f.vertex(
j))] *
qH[
m.index(f.vertexMod(
j + 1))]) <
111 const CoordType& p0 = f.vertex(
j)->coord();
112 const CoordType& p1 = f.vertexMod(
j + 1)->coord();
114 float q0 =
qH[
m.index(f.vertex(
j))];
115 float q1 =
qH[
m.index(f.vertexMod(
j + 1))];
117 std::pair<CoordType, CoordType>
seg(p0, p1);
118 CoordType
pp =
pl.segmentIntersection(
seg);
121 if (isPerVertexNormalAvailable(
m)) {
122 using NormalType = VertexType::NormalType;
123 const NormalType&
n0 = f.vertex(
j)->normal();
124 const NormalType&
n1 = f.vertexMod(
j + 1)->normal();
132 if (
ptVec.size() >= 2) {
133 uint
eid =
em.addEdge();
134 uint
v0 =
em.addVertices(2);
137 em.vertex(v1).coord() =
ptVec[1];
139 em.edge(
eid).setVertex(1, v1);
142 if (isPerVertexNormalAvailable(
m) &&
143 isPerVertexNormalAvailable(
em)) {
145 em.vertex(v1).normal() =
nmVec[1];
189template<FaceMeshConcept MeshType,
typename SScalar>
195 using VertexType = MeshType::VertexType;
196 using CoordType = VertexType::CoordType;
197 using ScalarType = CoordType::ScalarType;
198 using FaceType = MeshType::FaceType;
207 while (
i <
res.faceContainerSize()) {
208 FaceType& f =
res.face(
i);
211 std::pair<ScalarType, ScalarType>
ires(0, 0);
214 for (
const auto* v : f.vertices()) {
219 uint
v0 =
res.addVertices(3);
222 uint
fi =
res.addFaces(4);
224 FaceType& f =
res.face(
i);
226 res.vertex(
v0).importFrom(*f.vertex(0),
false);
227 res.vertex(
v0).coord() =
228 (f.vertex(0)->coord() + f.vertex(1)->coord()) / 2;
229 res.vertex(v1).importFrom(*f.vertex(1),
false);
230 res.vertex(v1).coord() =
231 (f.vertex(1)->coord() + f.vertex(2)->coord()) / 2;
232 res.vertex(v2).importFrom(*f.vertex(2),
false);
233 res.vertex(v2).coord() =
234 (f.vertex(2)->coord() + f.vertex(0)->coord()) / 2;
236 res.face(
fi).importFrom(f,
false);
237 res.face(
fi).setVertices(
238 f.vertex(0), &
res.vertex(
v0), &
res.vertex(v2));
241 res.face(
fi).importFrom(f,
false);
242 res.face(
fi).setVertices(
243 f.vertex(1), &
res.vertex(v1), &
res.vertex(
v0));
246 res.face(
fi).importFrom(f,
false);
247 res.face(
fi).setVertices(
248 &
res.vertex(
v0), &
res.vertex(v1), &
res.vertex(v2));
251 res.face(
fi).importFrom(f,
false);
252 res.face(
fi).setVertices(
253 &
res.vertex(v2), &
res.vertex(v1), f.vertex(2));
258 if (
ires.first > 0.0) {
275template<FaceMeshConcept MeshType,
typename SScalar>
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Concept that checks if a Mesh has the per Vertex Normal component.
Definition per_vertex.h:128
bool intersect(const FaceType &f, const Box< PointType > &box)
Checks if a face intersects a box.
Definition element.h:57
std::optional< typename SegmentType::PointType > intersection(const PlaneType &plane, const SegmentType &segment)
Returns the intersection point between a plane and a segment, if it exists.
Definition misc.h:368
auto faceArea(const FaceType &f)
Computes the area of a face. Works both for triangle and polygonal faces, and it is optimized in case...
Definition geometry.h:101