Visual Computing Library
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/mesh/requirements.h>
27#include <vclib/types.h>
28
29namespace vcl {
30
45template<FaceMeshConcept MeshType>
47{
48public:
49 using VertexType = MeshType::VertexType;
50 using FaceType = MeshType::FaceType;
51
52 VertexType* v[2]; // Pointer to the two (ordered) vertices of the edge
53 FaceType* f; // Pointer to the face of the edge
54 int e; // Index of the edge inside the face
55
56 MeshEdgeUtil() : v {nullptr, nullptr}, f(nullptr), e(-1) {}
57
58 MeshEdgeUtil(FaceType& pf, uint ne)
59 {
60 v[0] = pf.vertex(ne);
61 v[1] = pf.vertexMod(ne + 1);
62 assert(v[0] != v[1]);
63
64 if (v[0] > v[1])
65 std::swap(v[0], v[1]);
66 f = &pf;
67 e = ne;
68 }
69
70 bool operator<(const MeshEdgeUtil& pe) const
71 {
72 if (v[0] < pe.v[0])
73 return true;
74 else if (v[0] > pe.v[0])
75 return false;
76 else
77 return v[1] < pe.v[1];
78 }
79
80 bool operator==(const MeshEdgeUtil& pe) const
81 {
82 return v[0] == pe.v[0] && v[1] == pe.v[1];
83 }
84
85 bool operator!=(const MeshEdgeUtil& pe) const
86 {
87 return v[0] != pe.v[0] || v[1] != pe.v[1];
88 }
89};
90
91template<FaceMeshConcept MeshType>
93{
94public:
95 using VertexType = MeshType::VertexType;
96 using FaceType = MeshType::FaceType;
97
98 const VertexType* v[2]; // Pointer to the two (ordered) vertices of the edge
99 const FaceType* f; // Pointer to the face of the edge
100 int e; // Index of the edge inside the face
101
102 ConstMeshEdgeUtil() : v {nullptr, nullptr}, f(nullptr), e(-1) {}
103
104 ConstMeshEdgeUtil(const FaceType& pf, uint ne)
105 {
106 v[0] = pf.vertex(ne);
107 v[1] = pf.vertexMod(ne + 1);
108 assert(v[0] != v[1]);
109
110 if (v[0] > v[1])
111 std::swap(v[0], v[1]);
112 f = &pf;
113 e = ne;
114 }
115
116 bool operator<(const ConstMeshEdgeUtil& pe) const
117 {
118 if (v[0] < pe.v[0])
119 return true;
120 else if (v[0] > pe.v[0])
121 return false;
122 else
123 return v[1] < pe.v[1];
124 }
125
126 bool operator==(const ConstMeshEdgeUtil& pe) const
127 {
128 return v[0] == pe.v[0] && v[1] == pe.v[1];
129 }
130
131 bool operator!=(const ConstMeshEdgeUtil& pe) const
132 {
133 return v[0] != pe.v[0] || v[1] != pe.v[1];
134 }
135};
136
137} // namespace vcl
138
139#endif // VCL_SPACE_COMPLEX_MESH_EDGE_UTIL_H
Definition mesh_edge_util.h:93
Utility class that represents a edge in a Mesh.
Definition mesh_edge_util.h:47
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43