23#ifndef VCL_MESH_ELEM_ALGORITHMS_INTERSECTION_H
24#define VCL_MESH_ELEM_ALGORITHMS_INTERSECTION_H
26#include <vclib/mesh/elements.h>
28#include <vclib/algorithms/core.h>
29#include <vclib/space/core.h>
53template<FaceConcept FaceType, Po
intConcept Po
intType>
59 f.vertex(0)->position(),
60 f.vertex(1)->position(),
61 f.vertex(2)->position()),
68 for (uint
i = 0;
i <
tris.size() && !
b;
i += 3) {
71 f.vertex(
tris[
i])->position(),
72 f.vertex(
tris[
i + 1])->position(),
73 f.vertex(
tris[
i + 2])->position()),
85template<Po
intConcept Po
intType, FaceConcept FaceType>
111template<FaceConcept FaceType, Po
intConcept Po
intType,
typename SScalar>
116 std::pair<SScalar, SScalar>&
res)
121 f.vertex(0)->position(),
122 f.vertex(1)->position(),
123 f.vertex(2)->position()),
129 if (f.vertexCount() == 3) {
132 f.vertex(0)->position(),
133 f.vertex(1)->position(),
134 f.vertex(2)->position()),
140 res.first = std::numeric_limits<SScalar>::max();
141 std::pair<SScalar, SScalar>
r;
147 for (uint
i = 0;
i <
tris.size() && !
b;
i += 3) {
150 f.vertex(
tris[
i])->position(),
151 f.vertex(
tris[
i + 1])->position(),
152 f.vertex(
tris[
i + 2])->position()),
157 if (
r.first <
res.first) {
182template<FaceConcept FaceType,
typename SScalar>
186 std::pair<SScalar, SScalar>
res;
195template<
typename SScalar, FaceConcept FaceType>
227template<Ray3Concept RayType, FaceConcept FaceType>
230 const FaceType& face,
231 std::optional<std::reference_wrapper<typename RayType::ScalarType>> t = {})
232 requires std::same_as<
233 typename RayType::ScalarType,
234 typename FaceType::VertexType::PositionType::ScalarType>
236 using PointType =
typename RayType::PointType;
237 using ScalarType =
typename PointType::ScalarType;
239 auto triangleIntersection = [](
const FaceType& f,
241 auto t) -> std::optional<PointType> {
245 f.vertex(0)->position(),
246 f.vertex(1)->position(),
247 f.vertex(2)->position()),
251 if constexpr (TriangleFaceConcept<FaceType>) {
252 return triangleIntersection(face, ray, t);
255 if (face.vertexCount() == 3) {
256 return triangleIntersection(face, ray, t);
259 std::vector<uint> tris =
earCut(face);
260 for (uint i = 0; i < tris.size(); i += 3) {
264 face.vertex(tris[i])->position(),
265 face.vertex(tris[i + 1])->position(),
266 face.vertex(tris[i + 2])->position()),
297template<Ray3Concept RayType, FaceConcept FaceType>
308template<FaceConcept FaceType, Ray3Concept RayType>
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
The TriangleWrapper class is a wrapper around a N-Dimensional triangle.
Definition triangle_wrapper.h:54
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
std::vector< uint > earCut(Iterator begin, Iterator end)
Triangulates a simple polygon with no holes using the ear-cutting algorithm.
Definition ear_cut.h:90