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_MESH_ELEM_ALGORITHMS_VISIBILITY_H
24#define VCL_MESH_ELEM_ALGORITHMS_VISIBILITY_H
25
26#include <vclib/mesh/elements.h>
27
28#include <vclib/algorithms/core.h>
29
30namespace vcl {
31
45template<FaceConcept FaceType, Point3Concept PointType>
46auto halfSpaceDeterminant(const FaceType& face, const PointType& point)
47{
48 // - if it is a triangle, compute the determinant using the triangle
49 // - if it is a polygon, use its normal to compute the determinant
50 if constexpr (TriangleFaceConcept<FaceType>) {
52 face.vertex(0)->position(),
53 face.vertex(1)->position(),
54 face.vertex(2)->position(),
55 point);
56 }
57 else {
58 if (face.vertexNumber() == 3) {
60 face.vertex(0)->position(),
61 face.vertex(1)->position(),
62 face.vertex(2)->position(),
63 point);
64 }
65 else {
66 PointType n = faceNormal(face);
67 return n.dot(point - face.vertex(0)->position());
68 }
69 }
70}
71
84template<FaceConcept FaceType, Point3Concept PointType>
85bool facePointVisibility(const FaceType& face, const PointType& point)
86{
87 return halfSpaceDeterminant(face, point) > 0;
88}
89
90} // namespace vcl
91
92#endif // VCL_MESH_ELEM_ALGORITHMS_VISIBILITY_H
A class representing a box in N-dimensional space.
Definition box.h:46
Definition face.h:305
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 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:85
FaceType::VertexType::PositionType faceNormal(const FaceType &f)
Computes the normal of a face, without modifying the face. Works both for triangle and polygonal face...
Definition geometry.h:46