23#ifndef VCL_ALGORITHMS_MESH_INTERSECTION_H
24#define VCL_ALGORITHMS_MESH_INTERSECTION_H
26#include <vclib/algorithms/core.h>
27#include <vclib/mesh.h>
81 FaceMeshConcept MeshType,
82 PlaneConcept PlaneType>
85 using VertexType = MeshType::VertexType;
86 using FaceType = MeshType::FaceType;
87 using PositionType = VertexType::PositionType;
91 std::vector<double>
qH(
m.vertexContainerSize());
93 for (
const VertexType& v :
m.vertices())
94 qH[
m.index(v)] =
pl.dist(v.position());
96 for (
const FaceType& f :
m.faces()) {
97 std::vector<PositionType>
ptVec;
98 std::vector<PositionType>
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)->position());
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 PositionType& p0 = f.vertex(
j)->position();
112 const PositionType& p1 = f.vertexMod(
j + 1)->position();
114 float q0 =
qH[
m.index(f.vertex(
j))];
115 float q1 =
qH[
m.index(f.vertexMod(
j + 1))];
117 std::pair<PositionType, PositionType>
seg(p0, p1);
118 PositionType
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();
133 uint
eid =
em.addEdge();
134 uint
v0 =
em.addVertices(2);
137 em.vertex(v1).position() =
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 PositionType = VertexType::PositionType;
197 using ScalarType = PositionType::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).position() =
228 (f.vertex(0)->position() + f.vertex(1)->position()) / 2;
229 res.vertex(v1).importFrom(*f.vertex(1),
false);
230 res.vertex(v1).position() =
231 (f.vertex(1)->position() + f.vertex(2)->position()) / 2;
232 res.vertex(v2).importFrom(*f.vertex(2),
false);
233 res.vertex(v2).position() =
234 (f.vertex(2)->position() + f.vertex(0)->position()) / 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 box in N-dimensional space.
Definition box.h:46
bool isInside(const PointT &p) const
Checks whether a given point is inside the box or not, bounds included.
Definition box.h:163
PointT size() const
Computes the size of the box.
Definition box.h:267
Concept that checks if a Mesh has the per Vertex Normal component.
Definition vertex_requirements.h:140
bool intersect(const PlaneType &plane, const BoxType &box)
Checks if a plane intersects with a box.
Definition intersect.h:258
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 intersect.h:364
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:108
EdgeMeshT< double, false > EdgeMesh
The EdgeMesh class is a specialization of the EdgeMeshT class that uses double as scalar and pointers...
Definition edge_mesh.h:174