Visual Computing Library  devel
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/space/core.h>
27
28namespace vcl {
29
46template<Point3Concept PointType>
48 const PointType& p0,
49 const PointType& p1,
50 const PointType& p2,
51 const PointType& p)
52{
53 return (p1 - p0).cross(p2 - p0).dot(p - p0);
54}
55
69template<Triangle3Concept TriangleType, Point3Concept PointType>
70auto halfSpaceDeterminant(const TriangleType& triangle, const PointType& point)
71{
73 triangle.point(0), triangle.point(1), triangle.point(2), point);
74}
75
88template<Point3Concept PointType>
90 const PointType& p0,
91 const PointType& p1,
92 const PointType& p2,
93 const PointType& p3)
94{
95 return halfSpaceDeterminant(p0, p1, p2, p3) == 0;
96}
97
110template<Triangle3Concept TriangleType, Point3Concept PointType>
112 const TriangleType& triangle,
113 const PointType& point)
114{
115 return halfSpaceDeterminant(triangle, point) > 0;
116}
117
131template<Point3Concept PointType>
133 const PointType& p0,
134 const PointType& p1,
135 const PointType& p2,
136 const PointType& p)
137{
138 return halfSpaceDeterminant(p0, p1, p2, p) > 0;
139}
140
141} // namespace vcl
142
143#endif // VCL_ALGORITHMS_CORE_VISIBILITY_H
A class representing a box in N-dimensional space.
Definition box.h:46
auto halfSpaceDeterminant(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p)
Compute the determinant of the half-space defined by the triangle (p1, p2, p3) and the point p.
Definition visibility.h:47
bool arePointsCoplanar(const PointType &p0, const PointType &p1, const PointType &p2, const PointType &p3)
Checks if 4 points are coplanar.
Definition visibility.h:89
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:111