Visual Computing Library
Loading...
Searching...
No Matches
visibility.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_CORE_VISIBILITY_H
24#define VCL_ALGORITHMS_CORE_VISIBILITY_H
25
26#include <vclib/concepts/space/plane.h>
27#include <vclib/concepts/space/point.h>
28#include <vclib/concepts/space/triangle.h>
29#include <vclib/space/core/triangle_wrapper.h>
30
31namespace vcl {
32
46template<Triangle3Concept TriangleType, Point3Concept PointType>
47auto halfSpaceDeterminant(const TriangleType& triangle, const PointType& point)
48{
49 return (triangle.point(1) - triangle.point(0))
50 .cross(triangle.point(2) - triangle.point(0))
51 .dot(point - triangle.point(0));
52}
53
67template<FaceConcept FaceType, Point3Concept PointType>
68auto halfSpaceDeterminant(const FaceType& face, const PointType& point)
69{
70 // TODO: don't just check the first three vertices: first check if the face
71 // is a triangle, then:
72 // - if it is a triangle, keep the current implementation
73 // - if it is a polygon, use its normal to compute the determinant
75 face.vertex(0)->coord(),
76 face.vertex(1)->coord(),
77 face.vertex(2)->coord(),
78 point);
79}
80
97template<Point3Concept PointType>
99 const PointType& p1,
100 const PointType& p2,
101 const PointType& p3,
102 const PointType& p)
103{
105}
106
119template<Point3Concept PointType>
121 const PointType& p1,
122 const PointType& p2,
123 const PointType& p3,
124 const PointType& p4)
125{
126 return halfSpaceDeterminant(p1, p2, p3, p4) == 0;
127}
128
141template<Triangle3Concept TriangleType, Point3Concept PointType>
143 const TriangleType& triangle,
144 const PointType& point)
145{
146 return halfSpaceDeterminant(triangle, point) > 0;
147}
148
162template<Point3Concept PointType>
164 const PointType& p1,
165 const PointType& p2,
166 const PointType& p3,
167 const PointType& p)
168{
169 return halfSpaceDeterminant(p1, p2, p3, p) > 0;
170}
171
184template<FaceConcept FaceType, Point3Concept PointType>
185bool facePointVisibility(const FaceType& face, const PointType& point)
186{
187 return halfSpaceDeterminant(face, point) > 0;
188}
189
190} // namespace vcl
191
192#endif // VCL_ALGORITHMS_CORE_VISIBILITY_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The TriangleWrapper class is a wrapper around a N-Dimensional triangle.
Definition triangle_wrapper.h:54
bool facePointVisibility(const FaceType &face, const PointType &point)
Checks if a point is visible from a face, i.e., if the point is in the half-space defined by the face...
Definition visibility.h:185
auto halfSpaceDeterminant(const TriangleType &triangle, const PointType &point)
Compute the determinant of the half-space defined by the triangle and the point.
Definition visibility.h:47
bool trianglePointVisibility(const TriangleType &triangle, const PointType &point)
Checks if a point is visible from a triangle, i.e., if the point is in the half-space defined by the ...
Definition visibility.h:142
bool arePointsCoplanar(const PointType &p1, const PointType &p2, const PointType &p3, const PointType &p4)
Checks if 4 points are coplanar.
Definition visibility.h:120