Visual Computing Library  devel
Loading...
Searching...
No Matches
tri_poly_index_bimap.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_TRI_POLY_INDEX_BIMAP_H
24#define VCL_SPACE_COMPLEX_TRI_POLY_INDEX_BIMAP_H
25
26#include <vclib/base.h>
27
28#include <vector>
29
30namespace vcl {
31
50{
51 std::vector<uint> mTriToPoly;
52 std::vector<uint> mPolyToTri;
53 std::vector<uint> mPolyToTriNumber;
54
55public:
59 TriPolyIndexBiMap() = default;
60
68 uint polygon(uint triangleIndex) const
69 {
70 assert(triangleIndex < mTriToPoly.size());
71 return mTriToPoly[triangleIndex];
72 }
73
84 uint triangleBegin(uint polygonIndex) const
85 {
86 assert(polygonIndex < mPolyToTri.size());
87 return mPolyToTri[polygonIndex];
88 }
89
114 {
115 // be sure that the current polygon index is valid and the polygon
116 // has not been deleted in the mesh
117 assert(polygonIndex < mPolyToTri.size());
118 assert(polygonIndex < mPolyToTriNumber.size());
119 assert(mPolyToTri[polygonIndex] != UINT_NULL);
120
121 return mPolyToTriNumber[polygonIndex];
122 }
123
127 void clear()
128 {
129 mTriToPoly.clear();
130 mPolyToTri.clear();
131 mPolyToTriNumber.clear();
132 }
133
141 void reserve(uint nTriangles, uint nPolygons)
142 {
143 mTriToPoly.reserve(nTriangles);
144 mPolyToTri.reserve(nPolygons);
145 mPolyToTriNumber.reserve(nPolygons);
146 }
147
163 {
164 // resize the vectors if needed
165 if (triangleIndex >= mTriToPoly.size()) {
166 mTriToPoly.resize(triangleIndex + 1, UINT_NULL);
167 }
168 if (polygonIndex >= mPolyToTri.size()) {
169 mPolyToTri.resize(polygonIndex + 1, UINT_NULL);
170 mPolyToTriNumber.resize(polygonIndex + 1, 0);
171 }
172
173 // add the index of the polygon associated to the triangle
174 mTriToPoly[triangleIndex] = polygonIndex;
175
176 // update the number of triangles associated to the polygon
177 mPolyToTriNumber[polygonIndex]++;
178 // add the index of the triangle associated to the polygon,
179 // but only if it is the first triangle index of the polygon!
180 if (mPolyToTri[polygonIndex] == UINT_NULL ||
181 triangleIndex < mPolyToTri[polygonIndex])
182 mPolyToTri[polygonIndex] = triangleIndex;
183 }
184
189 uint triangleNumber() const { return mTriToPoly.size(); }
190
195 uint polygonNumber() const { return mPolyToTri.size(); }
196};
197
198} // namespace vcl
199
200#endif // VCL_SPACE_COMPLEX_TRI_POLY_INDEX_BIMAP_H
A class representing a box in N-dimensional space.
Definition box.h:46
PointT size() const
Computes the size of the box.
Definition box.h:267
The TriPolyIndexBiMap class allows to store a bidirectional mapping between a Polygon Mesh and a Tria...
Definition tri_poly_index_bimap.h:50
TriPolyIndexBiMap()=default
Creates an empty BiMap.
void reserve(uint nTriangles, uint nPolygons)
Reserves enogh memory for the BiMap. Allows fast insertions.
Definition tri_poly_index_bimap.h:141
uint triangleNumber() const
Returns the number of triangles stored in the BiMap.
Definition tri_poly_index_bimap.h:189
void insert(uint triangleIndex, uint polygonIndex)
Performs an insertion into the BiMap, and associates:
Definition tri_poly_index_bimap.h:162
void clear()
Clears the BiMap.
Definition tri_poly_index_bimap.h:127
uint polygon(uint triangleIndex) const
Returns the index of the polygon mapped to the triangle having the index given as input argument.
Definition tri_poly_index_bimap.h:68
uint triangleBegin(uint polygonIndex) const
Returns the smallest index of set of triangles mapped to the polygon having the index given as input ...
Definition tri_poly_index_bimap.h:84
uint polygonNumber() const
Returns the number of polygons stored in the BiMap.
Definition tri_poly_index_bimap.h:195
uint triangleNumber(uint polygonIndex) const
Returns the number of (consecutive index) triangles mapped to a polygon.
Definition tri_poly_index_bimap.h:113
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48