Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_edge_util.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_SPACE_COMPLEX_MESH_EDGE_UTIL_H
24#define VCL_SPACE_COMPLEX_MESH_EDGE_UTIL_H
25
26#include <vclib/base.h>
27#include <vclib/mesh.h>
28
29namespace vcl {
30
49template<FaceMeshConcept MeshType, bool CNST = false>
51{
52 using VertexType = std::conditional_t<
53 CNST,
54 const typename MeshType::VertexType,
55 typename MeshType::VertexType>;
56 using FaceType = std::conditional_t<
57 CNST,
58 const typename MeshType::FaceType,
59 typename MeshType::FaceType>;
60
61public:
62 VertexType* v[2]; // Pointer to the two (ordered) vertices of the edge
63 FaceType* f; // Pointer to the face of the edge
64 int e; // Index of the edge inside the face
65
66 MeshEdgeUtil() : v {nullptr, nullptr}, f(nullptr), e(-1) {}
67
69 VertexType* v0,
70 VertexType* v1,
71 FaceType* pf = nullptr,
72 int ne = -1) : f(pf), e(ne)
73 {
74 assert(v0 != v1);
75 if (v0 < v1) {
76 v[0] = v0;
77 v[1] = v1;
78 }
79 else {
80 v[0] = v1;
81 v[1] = v0;
82 }
83 }
84
85 MeshEdgeUtil(FaceType& pf, uint ne)
86 {
87 v[0] = pf.vertex(ne);
88 v[1] = pf.vertexMod(ne + 1);
89 assert(v[0] != v[1]);
90
91 if (v[0] > v[1])
92 std::swap(v[0], v[1]);
93 f = &pf;
94 e = ne;
95 }
96
97 bool operator<(const MeshEdgeUtil& pe) const
98 {
99 if (v[0] < pe.v[0])
100 return true;
101 else if (v[0] > pe.v[0])
102 return false;
103 else
104 return v[1] < pe.v[1];
105 }
106
107 bool operator==(const MeshEdgeUtil& pe) const
108 {
109 return v[0] == pe.v[0] && v[1] == pe.v[1];
110 }
111
112 bool operator!=(const MeshEdgeUtil& pe) const
113 {
114 return v[0] != pe.v[0] || v[1] != pe.v[1];
115 }
116};
117
123template<FaceMeshConcept MeshType>
125
126} // namespace vcl
127
128#endif // VCL_SPACE_COMPLEX_MESH_EDGE_UTIL_H
A class representing a box in N-dimensional space.
Definition box.h:46
Utility class that represents a edge in a Mesh having Vertices and Faces.
Definition mesh_edge_util.h:51