40#ifndef GEOGRAM_MESH_MESH
41#define GEOGRAM_MESH_MESH
57 static constexpr index_t NO_VERTEX = NO_INDEX;
58 static constexpr index_t NO_EDGE = NO_INDEX;
59 static constexpr index_t NO_FACET = NO_INDEX;
60 static constexpr index_t NO_CELL = NO_INDEX;
61 static constexpr index_t NO_CORNER = NO_INDEX;
132 bool keep_attributes,
bool keep_memory =
false
150 resize_store(nb + nb_to_reserve);
161 if(nb_ + nb > attributes_.size()) {
164 new_capacity = std::max(
index_t(16),attributes_.size());
165 while(new_capacity < nb_ + nb) {
169 attributes_.reserve(new_capacity);
172 attributes_.resize(nb_);
183 if(attributes_.capacity() < nb_) {
185 std::max(
index_t(16),attributes_.capacity()*2);
186 attributes_.reserve(new_capacity);
188 attributes_.resize(nb_);
202 attributes_.resize(nb_);
216 bool copy_attributes =
true
219 if(copy_attributes) {
220 attributes_.copy(rhs.attributes_);
222 attributes_.clear(
false,
false);
223 attributes_.resize(rhs.attributes_.
size());
259 bool remove_isolated_vertices=
true
286 bool keep_attributes=
true,
bool keep_memory=
false
315 class MeshFacetCornersStore;
316 class MeshCellCornersStore;
345 return MeshSubElementsStore::create_sub_element();
360 coords < point_ptr(0) ||
361 coords >= point_ptr(0) + nb() * dimension()
363 index_t result = create_vertex();
364 for(
index_t c=0; c<dimension(); ++c) {
365 point_ptr(result)[c] = coords[c];
376 return MeshSubElementsStore::create_sub_elements(nb);
380 bool keep_attributes=
true,
bool keep_memory=
false
409 return point_fp32_.is_bound();
420 return point_.is_bound();
430 point_fp32_.dimension() :
441 if(single_precision()) {
442 point_fp32_.redim(dim);
458 return &point_[v*point_.dimension()];
471 return &point_[v*point_.dimension()];
486 return *(
vec3*)(&point_[v*point_.dimension()]);
500 return *(
const vec3*)(&point_[v*point_.dimension()]);
513 return &point_fp32_[v*point_fp32_.dimension()];
526 return &point_fp32_[v*point_fp32_.dimension()];
559 bool keep_attributes,
bool keep_memory =
false
564 void bind_point_attribute(
index_t dim,
bool single_precision=
false);
566 void copy(
const MeshVertices& rhs,
bool copy_attributes=
true) {
568 if(point_fp32_.is_bound()) {
569 point_fp32_.destroy();
571 if(point_.is_bound()) {
574 MeshSubElementsStore::copy(rhs, copy_attributes);
576 point_fp32_.bind_if_is_defined(attributes(),
"point_fp32");
577 if(!point_fp32_.is_bound()) {
578 point_fp32_.create_vector_attribute(
579 attributes(),
"point_fp32", dim
583 point_.bind_if_is_defined(attributes(),
"point");
584 if(!point_.is_bound()) {
585 point_.create_vector_attribute(
586 attributes(),
"point", dim
592 if(!copy_attributes) {
595 single_precision_point_ptr(0),
610 MeshFacetCornersStore& facet_corners_;
611 MeshCellCornersStore& cell_corners_;
612 Attribute<double> point_;
613 Attribute<float> point_fp32_;
616 friend class GeogramIOHandler;
640 return edge_vertex_[2*e+lv];
652 edge_vertex_[2*e+lv] = v;
664 return &(edge_vertex_[c]);
675 return &(edge_vertex_[c]);
683 return create_sub_element();
692 return create_sub_elements(nb);
701 index_t result = create_edge();
702 set_vertex(result,0,v1);
703 set_vertex(result,1,v2);
714 bool keep_attributes=
true,
bool keep_memory=
false
721 bool keep_attributes,
bool keep_memory =
false
727 edge_vertex_.push_back(NO_VERTEX);
728 edge_vertex_.push_back(NO_VERTEX);
729 return MeshSubElementsStore::create_sub_element();
733 edge_vertex_.resize(2*(nb()+nb_in),NO_VERTEX);
734 return MeshSubElementsStore::create_sub_elements(nb_in);
737 void copy(
const MeshEdges& rhs,
bool copy_attributes=
true) {
738 MeshSubElementsStore::copy(rhs, copy_attributes);
739 edge_vertex_ = rhs.edge_vertex_;
742 vector<index_t> edge_vertex_;
744 friend class GeogramIOHandler;
765 return (is_simplicial_ ? 3*f : facet_ptr_[f]);
776 return (is_simplicial_ ? 3*(f+1): facet_ptr_[f+1]);
786 return (is_simplicial_ ? 3 : facet_ptr_[f+1] - facet_ptr_[f]);
799 return corners_begin(f)+lv;
810 return is_simplicial_;
822 return &facet_ptr_[f];
827 bool keep_attributes,
bool keep_memory =
false
833 if(!is_simplicial_) {
834 facet_ptr_.push_back(NO_CORNER);
836 return MeshSubElementsStore::create_sub_element();
839 index_t create_sub_elements(index_t nb) {
840 if(!is_simplicial_) {
841 for(index_t i=0; i<nb; ++i) {
842 facet_ptr_.push_back(NO_CORNER);
845 return MeshSubElementsStore::create_sub_elements(nb);
848 void copy(
const MeshFacetsStore& rhs,
bool copy_attributes=
true) {
849 MeshSubElementsStore::copy(rhs,copy_attributes);
850 is_simplicial_ = rhs.is_simplicial_;
851 facet_ptr_ = rhs.facet_ptr_;
856 vector<index_t> facet_ptr_;
858 friend class GeogramIOHandler;
878 return corner_vertex_[c];
889 return corner_adjacent_facet_[c];
901 return &corner_adjacent_facet_[c];
914 return &corner_adjacent_facet_[c];
926 corner_vertex_[c] = v;
941 corner_vertex_[c] = v;
953 corner_adjacent_facet_[c] = f;
965 return &(corner_vertex_[c]);
977 return &(corner_vertex_[c]);
982 bool keep_attributes,
bool keep_memory =
false
988 corner_vertex_.push_back(v);
989 corner_adjacent_facet_.push_back(f);
990 return MeshSubElementsStore::create_sub_element();
995 corner_vertex_.push_back(NO_VERTEX);
997 for(index_t i=0; i<nb; ++i) {
998 corner_adjacent_facet_.push_back(NO_FACET);
1000 return MeshSubElementsStore::create_sub_elements(nb);
1004 const MeshFacetCornersStore& rhs,
bool copy_attributes=
true
1006 MeshSubElementsStore::copy(rhs, copy_attributes);
1007 corner_vertex_ = rhs.corner_vertex_;
1008 corner_adjacent_facet_ = rhs.corner_adjacent_facet_;
1012 MeshVertices& vertices_;
1013 MeshFacetsStore& facets_;
1014 vector<index_t> corner_vertex_;
1015 vector<index_t> corner_adjacent_facet_;
1017 friend class MeshFacets;
1019 friend class GeogramIOHandler;
1044 return nb_corners(f);
1055 return facet_corners_.vertex(corner(f,lv));
1066 facet_corners_.set_vertex(corner(f,lv),v);
1077 for(
index_t lv=0; lv<nb_vertices(f); ++lv) {
1078 if(vertex(f,lv) == v) {
1092 for(
index_t lv=0; lv<nb_vertices(f1); ++lv) {
1094 if(find_vertex(f2,v) != NO_VERTEX) {
1109 return facet_corners_.adjacent_facet(corner(f,le));
1120 for(
index_t le=0; le<nb_vertices(f); ++le) {
1121 if(adjacent(f,le) == f2) {
1136 facet_corners_.set_adjacent_facet(corner(f,le),f2);
1149 return c + 1 == corners_end(f) ? corners_begin(f) : c + 1;
1162 return c == corners_begin(f) ? corners_end(f) - 1 : c - 1;
1173 for(
index_t c1 = corners_begin(f); c1 != corners_end(f); ++c1) {
1174 index_t c2 = next_corner_around_facet(f,c1);
1176 facet_corners_.vertex(c1) == v1 &&
1177 facet_corners_.vertex(c2) == v2
1179 return c1 - corners_begin(f);
1187 bool remove_isolated_vertices=
true
1193 bool keep_attributes=
true,
bool keep_memory=
false
1206 if(nb_vertices_per_polygon != 3) {
1207 is_not_simplicial();
1211 index_t co = facet_corners_.nb();
1212 facet_corners_.create_sub_elements(
1213 nb_facets*nb_vertices_per_polygon
1215 index_t result = create_sub_elements(nb_facets);
1217 if(!is_simplicial_) {
1218 for(
index_t f=first_facet; f<=first_facet+nb_facets; ++f) {
1220 co += nb_vertices_per_polygon;
1234 facet_corners_.reserve_store(nb_to_reserve*3);
1235 this->reserve_store(nb_to_reserve);
1244 return create_facets(nb_triangles, 3);
1253 return create_facets(nb_quads, 4);
1265 facet_corners_.create_sub_element(v1);
1266 facet_corners_.create_sub_element(v2);
1267 facet_corners_.create_sub_element(v3);
1268 index_t result = create_sub_element();
1269 if(!is_simplicial_) {
1270 facet_ptr_[result+1] = facet_corners_.nb();
1283 is_not_simplicial();
1284 facet_corners_.create_sub_element(v1);
1285 facet_corners_.create_sub_element(v2);
1286 facet_corners_.create_sub_element(v3);
1287 facet_corners_.create_sub_element(v4);
1288 index_t result = create_sub_element();
1289 facet_ptr_[result+1] = facet_corners_.nb();
1301 if(nb_vertices != 3) {
1302 is_not_simplicial();
1304 for(
index_t i=0; i<nb_vertices; ++i) {
1305 facet_corners_.create_sub_element(NO_VERTEX);
1307 index_t result = create_sub_element();
1308 if(!is_simplicial_) {
1309 facet_ptr_[result+1] = facet_corners_.nb();
1323 if(nb_vertices != 3) {
1324 is_not_simplicial();
1326 for(
index_t i=0; i<nb_vertices; ++i) {
1327 facet_corners_.create_sub_element(vertices[i]);
1329 index_t result = create_sub_element();
1330 if(!is_simplicial_) {
1331 facet_ptr_[result+1] = facet_corners_.nb();
1345 return create_polygon(vertices.
size(), vertices.
data());
1408 void assign_triangle_mesh(
1434 if(!is_simplicial_) {
1435 is_simplicial_ =
true;
1436 facet_ptr_.resize(1);
1448 if(is_simplicial_) {
1449 is_simplicial_ =
false;
1450 facet_ptr_.resize(nb()+1);
1451 for(
index_t f=0; f<facet_ptr_.size(); ++f) {
1452 facet_ptr_[f] = 3*f;
1461 friend class GeogramIOHandler;
1475 MESH_NB_CELL_TYPES = 5
1520 namespace MeshCellDescriptors {
1550 return is_simplicial_;
1561 return is_simplicial_ ? MESH_TET : MeshCellType(cell_type_[c]);
1574 return is_simplicial_ ? MeshCellDescriptors::tet_descriptor :
1576 MeshCellDescriptors::cell_type_to_cell_descriptor[
1595 return *(MeshCellDescriptors::cell_type_to_cell_descriptor[t]);
1605 return descriptor(c).nb_vertices;
1616 return is_simplicial_ ? 4*c : cell_ptr_[c];
1627 return is_simplicial_ ? 4*(c+1) : cell_ptr_[c] + nb_corners(c);
1640#ifndef GEO_OS_WINDOWS
1643 return corners_begin(c) + lv;
1653 return descriptor(c).nb_facets;
1664 return is_simplicial_ ? 4*c : cell_ptr_[c];
1675 return is_simplicial_ ? 4*(c+1) : cell_ptr_[c] + nb_facets(c);
1687 return facets_begin(c) + lf;
1696 return descriptor(c).nb_edges;
1701 bool keep_attributes,
bool keep_memory =
false
1706 index_t create_sub_element(MeshCellType type) {
1707 if(!is_simplicial_) {
1708 cell_ptr_.push_back(NO_CORNER);
1711 return MeshSubElementsStore::create_sub_element();
1714 index_t create_sub_elements(index_t nb, MeshCellType type) {
1715 if(!is_simplicial_) {
1716 for(index_t i=0; i<nb; ++i) {
1717 cell_ptr_.push_back(NO_CORNER);
1718 cell_type_.push_back(Numeric::uint8(type));
1721 return MeshSubElementsStore::create_sub_elements(nb);
1725 const MeshCellsStore& rhs,
bool copy_attributes=
true
1727 MeshSubElementsStore::copy(rhs, copy_attributes);
1728 is_simplicial_ = rhs.is_simplicial_;
1729 cell_type_ = rhs.cell_type_;
1730 cell_ptr_ = rhs.cell_ptr_;
1734 bool is_simplicial_;
1735 vector<Numeric::uint8> cell_type_;
1736 vector<index_t> cell_ptr_;
1740 friend class GeogramIOHandler;
1760 return corner_vertex_[c];
1771 corner_vertex_[c] = v;
1783 return &(corner_vertex_[c]);
1795 return &(corner_vertex_[c]);
1800 bool keep_attributes,
bool keep_memory =
false
1806 corner_vertex_.push_back(v);
1807 return MeshSubElementsStore::create_sub_element();
1812 corner_vertex_.push_back(NO_VERTEX);
1814 return MeshSubElementsStore::create_sub_elements(nb);
1818 const MeshCellCornersStore& rhs,
bool copy_attributes=
true
1820 MeshSubElementsStore::copy(rhs, copy_attributes);
1821 corner_vertex_ = rhs.corner_vertex_;
1825 MeshVertices& vertices_;
1826 vector<index_t> corner_vertex_;
1828 friend class MeshCells;
1830 friend class GeogramIOHandler;
1855 return adjacent_cell_[f];
1868 adjacent_cell_[f] = c;
1879 return &adjacent_cell_[f];
1890 return &adjacent_cell_[f];
1895 bool keep_attributes,
bool keep_memory =
false
1901 adjacent_cell_.push_back(c);
1902 return MeshSubElementsStore::create_sub_element();
1907 adjacent_cell_.push_back(NO_CELL);
1909 return MeshSubElementsStore::create_sub_elements(nb);
1913 const MeshCellFacetsStore& rhs,
bool copy_attributes=
true
1915 MeshSubElementsStore::copy(rhs, copy_attributes);
1916 adjacent_cell_ = rhs.adjacent_cell_;
1920 MeshVertices& vertices_;
1921 MeshCellsStore& cells_;
1922 vector<index_t> adjacent_cell_;
1924 friend class MeshCells;
1926 friend class GeogramIOHandler;
1949 return nb_corners(c);
1959 return cell_corners_.vertex(corner(c,lv));
1969 cell_corners_.set_vertex(corner(c,lv),v);
1980 return cell_facets_.adjacent_cell(facet(c,lf));
1991 cell_facets_.set_adjacent_cell(facet(c,lf),c2);
2002 return descriptor(c).nb_vertices_in_facet[lf];
2015 return cell_corners_.vertex(
2016 corner(c, descriptor(c).facet_vertex[lf][lv])
2029 return corner(c, descriptor(c).facet_vertex[lf][lc]);
2043 return cell_corners_.vertex(
2044 corner(c,descriptor(c).edge_vertex[le][lv])
2061 return descriptor(c).edge_adjacent_facet[le][lf];
2078 bool keep_attributes=
true,
bool keep_memory=
false
2083 bool remove_isolated_vertices=
true
2103 if(type != MESH_TET) {
2104 is_not_simplicial();
2115 index_t co = cell_corners_.nb();
2117 cell_corners_.create_sub_elements(
2121 cell_facets_.create_sub_elements(
2125 index_t result = create_sub_elements(nb_cells, type);
2127 if(!is_simplicial_) {
2128 for(
index_t c=first_cell; c<=first_cell+nb_cells; ++c) {
2147 return create_cells(nb_tets, MESH_TET);
2156 return create_cells(nb_hexes, MESH_HEX);
2165 return create_cells(nb_prisms, MESH_PRISM);
2174 return create_cells(nb_pyramids, MESH_PYRAMID);
2192 cell_corners_.create_sub_element(v1);
2193 cell_corners_.create_sub_element(v2);
2194 cell_corners_.create_sub_element(v3);
2195 cell_corners_.create_sub_element(v4);
2196 cell_facets_.create_sub_element(adj1);
2197 cell_facets_.create_sub_element(adj2);
2198 cell_facets_.create_sub_element(adj3);
2199 cell_facets_.create_sub_element(adj4);
2200 index_t result = create_sub_element(MESH_TET);
2201 if(!is_simplicial_) {
2202 cell_ptr_[nb()] = cell_corners_.nb();
2227 is_not_simplicial();
2228 cell_corners_.create_sub_element(v1);
2229 cell_corners_.create_sub_element(v2);
2230 cell_corners_.create_sub_element(v3);
2231 cell_corners_.create_sub_element(v4);
2232 cell_corners_.create_sub_element(v5);
2233 cell_corners_.create_sub_element(v6);
2234 cell_corners_.create_sub_element(v7);
2235 cell_corners_.create_sub_element(v8);
2236 cell_facets_.create_sub_element(adj1);
2237 cell_facets_.create_sub_element(adj2);
2238 cell_facets_.create_sub_element(adj3);
2239 cell_facets_.create_sub_element(adj4);
2240 cell_facets_.create_sub_element(adj5);
2241 cell_facets_.create_sub_element(adj6);
2242 cell_facets_.create_sub_element(NO_CELL);
2243 cell_facets_.create_sub_element(NO_CELL);
2244 index_t result = create_sub_element(MESH_HEX);
2245 cell_ptr_[nb()] = cell_corners_.nb();
2269 is_not_simplicial();
2270 cell_corners_.create_sub_element(v1);
2271 cell_corners_.create_sub_element(v2);
2272 cell_corners_.create_sub_element(v3);
2273 cell_corners_.create_sub_element(v4);
2274 cell_corners_.create_sub_element(v5);
2275 cell_corners_.create_sub_element(v6);
2276 cell_facets_.create_sub_element(adj1);
2277 cell_facets_.create_sub_element(adj2);
2278 cell_facets_.create_sub_element(adj3);
2279 cell_facets_.create_sub_element(adj4);
2280 cell_facets_.create_sub_element(adj5);
2281 cell_facets_.create_sub_element(NO_CELL);
2282 index_t result = create_sub_element(MESH_PRISM);
2283 cell_ptr_[nb()] = cell_corners_.nb();
2305 is_not_simplicial();
2306 cell_corners_.create_sub_element(v1);
2307 cell_corners_.create_sub_element(v2);
2308 cell_corners_.create_sub_element(v3);
2309 cell_corners_.create_sub_element(v4);
2310 cell_corners_.create_sub_element(v5);
2311 cell_facets_.create_sub_element(adj1);
2312 cell_facets_.create_sub_element(adj2);
2313 cell_facets_.create_sub_element(adj3);
2314 cell_facets_.create_sub_element(adj4);
2315 cell_facets_.create_sub_element(adj5);
2316 index_t result = create_sub_element(MESH_PYRAMID);
2317 cell_ptr_[nb()] = cell_corners_.nb();
2340 is_not_simplicial();
2341 cell_corners_.create_sub_element(v1);
2342 cell_corners_.create_sub_element(v2);
2343 cell_corners_.create_sub_element(v3);
2344 cell_corners_.create_sub_element(v4);
2345 cell_facets_.create_sub_element(adj1);
2346 cell_facets_.create_sub_element(adj2);
2347 cell_facets_.create_sub_element(adj3);
2348 cell_facets_.create_sub_element(NO_CELL);
2349 index_t result = create_sub_element(MESH_CONNECTOR);
2350 cell_ptr_[nb()] = cell_corners_.nb();
2366 bool remove_trivial_slivers =
true,
bool verbose_if_OK=
false
2420 return cell_facets_.adjacent_cell_[4*t+lf];
2427 for(
index_t lf=0; lf<4; ++lf) {
2428 if(cell_facets_.adjacent_cell_[4*t+lf] == t2) {
2435 index_t tet_vertex(index_t t, index_t lv)
const {
2439 return cell_corners_.corner_vertex_[4*t+lv];
2442 index_t find_tet_vertex(index_t t, index_t v)
const {
2446 for(index_t lv=0; lv<4; ++lv) {
2447 if(cell_corners_.corner_vertex_[4*t+lv] == v) {
2471 return cell_corners_.vertex(
2472 4 * t + local_tet_facet_vertex_index(lf,lv)
2493 for(
index_t lf = 0; lf < 4; ++lf) {
2494 index_t w1 = tet_facet_vertex(t, lf, 0);
2495 index_t w2 = tet_facet_vertex(t, lf, 1);
2496 index_t w3 = tet_facet_vertex(t, lf, 2);
2498 (v1 == w1 && v2 == w2 && v3 == w3) ||
2499 (v1 == w2 && v2 == w3 && v3 == w1) ||
2500 (v1 == w3 && v2 == w1 && v3 == w2)
2519 return MeshCellDescriptors::tet_descriptor.facet_vertex[lf][lv];
2531 if(is_simplicial_) {
2532 is_simplicial_ =
false;
2533 cell_ptr_.resize(nb()+1);
2534 cell_type_.assign(nb(), MESH_TET);
2535 for(
index_t c=0; c<cell_ptr_.size(); ++c) {
2567 for(
index_t lv=0; lv<nb_vertices(c); ++lv) {
2568 if(vertex(c,lv) == v) {
2589 for(
index_t f1=0; f1<nb_facets(c1); ++f1) {
2590 if(facets_match(c1,f1,c2,f2)) {
2654 const std::vector< std::pair<index_t, index_t> >& matches
2668 friend class GeogramIOHandler;
2686 MESH_ALL_ELEMENTS = 15,
2687 MESH_FACET_CORNERS = 16,
2688 MESH_CELL_CORNERS = 32,
2689 MESH_CELL_FACETS = 64,
2690 MESH_ALL_SUBELEMENTS = 65
2735 void clear(
bool keep_attributes=
true,
bool keep_memory=
false);
2765 bool copy_attributes=
true,
2849 const std::string& name
2867 const std::string& full_attribute_name,
2869 std::string& attribute_name,
2882 const std::string& tag,
const std::string& subelement_name,
2903 const Mesh& operator=(
const Mesh& rhs);
#define geo_assert(x)
Verifies that a condition is met.
#define geo_debug_assert(x)
Verifies that a condition is met.
Generic mechanism for attributes.
Common include file, providing basic definitions. Should be included before anything else by all head...
Manages an attribute attached to a set of object.
Managers a set of attributes attached to an object.
index_t size() const
Gets the size.
Stores the cell facets of a mesh (low-level store)
index_t adjacent_cell(index_t f) const
Gets a cell adjacent to a facet.
void resize_store(index_t new_size) override
Resizes this MeshSubElementsStore.
index_t * adjacent_cell_ptr(index_t f)
Gets a pointer to a cell adjacent to a facet.
void clear_store(bool keep_attributes, bool keep_memory=false) override
Removes all the elements and attributes.
const index_t * adjacent_cell_ptr(index_t f) const
Gets a const pointer to a cell adjacent to a facet.
MeshCellFacetsStore(Mesh &mesh)
MeshCellFacetsStore constructor.
void set_adjacent_cell(index_t f, index_t c)
Sets a cell adjacent to a facet.
Stores the cells of a mesh (low-level store)
index_t facet(index_t c, index_t lf) const
Gets a facet of a cell by local facet index.
bool are_simplices() const
Tests whether all the cells are tetrahedra.
static const CellDescriptor & cell_type_to_cell_descriptor(MeshCellType t)
Gets a descriptor by cell type.
const CellDescriptor & descriptor(index_t c) const
Gets the descriptor of a cell.
index_t corner(index_t c, index_t lv) const
Gets a corner of a cell by local vertex index.
index_t nb_facets(index_t c) const
Gets the number of facets of a cell.
index_t corners_end(index_t c) const
Gets the upper limit for iterating over the corners of a cell.
MeshCellType type(index_t c) const
Gets the type of a cell.
index_t facets_end(index_t c) const
Gets the upper limit for iterating over the facets of a cell.
index_t nb_corners(index_t c) const
Gets the number of corners of a cell.
index_t corners_begin(index_t c) const
Gets the first element for iterating over the corners of a cell.
void resize_store(index_t new_size) override
Resizes this MeshSubElementsStore.
index_t nb_edges(index_t c) const
Gets the number of edges in a cell.
void clear_store(bool keep_attributes, bool keep_memory=false) override
Removes all the elements and attributes.
index_t facets_begin(index_t c) const
Gets the first element for iterating over the facets of a cell.
index_t create_cells(index_t nb_cells, MeshCellType type)
Creates a contiguous chunk of cells of the same type.
void pop() override
Removes the last element.
void compute_borders()
Replaces the surfacic part of this mesh with the borders of the volumetric part.
void set_vertex(index_t c, index_t lv, index_t v)
Sets a vertex of a cell by local vertex index.
index_t create_pyramids(index_t nb_pyramids)
Creates a contiguous chunk of pyramids.
void assign_tet_mesh(vector< index_t > &tets, bool steal_args)
Copies a tetrahedron mesh into this Mesh.
index_t adjacent(index_t c, index_t lf) const
Gets a cell adjacent to another one by local facet index.
void assign_tet_mesh(coord_index_t dim, vector< double > &vertices, vector< index_t > &tets, bool steal_args)
Copies a tetrahedron mesh into this Mesh.
bool triangular_facets_have_common_edge(index_t c1, index_t f1, index_t c2, index_t f2, index_t &e1, index_t &e2) const
Tests whether two triangular cell facets have a common edge.
bool facets_match(index_t c1, index_t f1, index_t c2, index_t f2) const
Tests whether two cell facets can be connected.
index_t create_connector(index_t v1, index_t v2, index_t v3, index_t v4, index_t adj1=NO_CELL, index_t adj2=NO_CELL, index_t adj3=NO_CELL)
Creates a connector.
index_t tet_facet_vertex(index_t t, index_t lf, index_t lv) const
Gets a vertex of a tetrahedron by local facet index and local vertex index in facet.
index_range corners(index_t c) const
Gets the corners of a cell.
MeshCells(Mesh &mesh)
MeshCells constructor.
index_t edge_vertex(index_t c, index_t le, index_t lv) const
Gets a cell vertex by local edge index and local vertex index in the edge.
void connect(bool remove_trivial_slivers=true, bool verbose_if_OK=false)
Connects the cells.
static index_t local_tet_facet_vertex_index(index_t lf, index_t lv)
Gives the local index of a vertex in a tetrahedron from its facet and vertex local indices.
index_t create_prism(index_t v1, index_t v2, index_t v3, index_t v4, index_t v5, index_t v6, index_t adj1=NO_CELL, index_t adj2=NO_CELL, index_t adj3=NO_CELL, index_t adj4=NO_CELL, index_t adj5=NO_CELL)
Creates a prism.
index_t nb_vertices(index_t c) const
Gets the number of vertices of a cell.
index_t facet_vertex(index_t c, index_t lf, index_t lv) const
Gets a vertex of a cell by local facet index and local vertex index in the facet.
void delete_elements(vector< index_t > &to_delete, bool remove_isolated_vertices=true) override
Deletes a set of elements.
index_t create_pyramid(index_t v1, index_t v2, index_t v3, index_t v4, index_t v5, index_t adj1=NO_CELL, index_t adj2=NO_CELL, index_t adj3=NO_CELL, index_t adj4=NO_CELL, index_t adj5=NO_CELL)
Creates a pyramid.
index_t find_tet_facet(index_t t, index_t v1, index_t v2, index_t v3) const
Finds the local index of a facet in a tetrahedron by the global indices of its vertices.
void permute_elements(vector< index_t > &permutation) override
Applies a permutation to the elements and their attributes.
void is_not_simplicial()
Indicates that the stored elements are no longer only tetrahedra.
index_t facet_corner(index_t c, index_t lf, index_t lc) const
Gets a corner of a cell by local facet index and local corner index in the facet.
index_t find_cell_vertex(index_t c, index_t v) const
Finds the local index of a vertex in a cell.
index_t create_hexes(index_t nb_hexes)
Creates a contiguous chunk of hexahedra.
index_t create_tets(index_t nb_tets)
Creates a contiguous chunk of tetrahedra.
index_t edge_adjacent_facet(index_t c, index_t le, index_t lf) const
Gets a cell local facet index by local edge index and local facet index in the edge.
void compute_borders(Attribute< index_t > &facet_cell)
Replaces the surfacic part of this mesh with the borders of the volumetric part.
bool create_connector(index_t c1, index_t lf1, const std::vector< std::pair< index_t, index_t > > &matches)
Creates a connector between a quadrandular facet and two triangular facets.
void set_adjacent(index_t c, index_t lf, index_t c2)
Sets a cell adjacent to another one by local facet index.
void clear(bool keep_attributes=true, bool keep_memory=false) override
Removes all the elements and attributes.
index_t create_prisms(index_t nb_prisms)
Creates a contiguous chunk of prisms.
index_t create_tet(index_t v1, index_t v2, index_t v3, index_t v4, index_t adj1=NO_CELL, index_t adj2=NO_CELL, index_t adj3=NO_CELL, index_t adj4=NO_CELL)
Creates a tetrahedron.
index_t create_hex(index_t v1, index_t v2, index_t v3, index_t v4, index_t v5, index_t v6, index_t v7, index_t v8, index_t adj1=NO_CELL, index_t adj2=NO_CELL, index_t adj3=NO_CELL, index_t adj4=NO_CELL, index_t adj5=NO_CELL, index_t adj6=NO_CELL)
Creates an hexahedron.
void connect_tets()
Optimized implementation of connect() used when the mesh is simplicial.
index_t facet_nb_vertices(index_t c, index_t lf) const
Gets the number of vertices in a cell facet.
bool triangular_facet_matches_quad_facet(index_t c1, index_t lf1, index_t c2, index_t lf2) const
Tests whether a triangular facet matches a quad facet.
index_t find_cell_facet(index_t c1, index_t c2, index_t f2) const
Finds the local index of a facet in a cell that can be connected to a facet of another cell.
index_t vertex(index_t c, index_t lv) const
Gets a vertex of a cell by local vertex index.
index_t vertex(index_t e, index_t lv) const
Gets the index of an edge vertex.
void clear_store(bool keep_attributes, bool keep_memory=false) override
Removes all the elements and attributes.
void pop() override
Removes the last element.
const index_t * vertex_index_ptr(index_t c) const
Gets a pointer to a vertex index by corner index.
void clear(bool keep_attributes=true, bool keep_memory=false) override
Removes all the elements and attributes.
index_t create_edge(index_t v1, index_t v2)
Creates a new edge.
index_t create_edge()
Creates a new edge.
void permute_elements(vector< index_t > &permutation) override
Applies a permutation to the elements and their attributes.
index_t create_edges(index_t nb)
Creates a batch of edges.
index_t * vertex_index_ptr(index_t c)
Gets a pointer to a vertex index by corner index.
void resize_store(index_t new_size) override
Resizes this MeshSubElementsStore.
void delete_elements(vector< index_t > &to_delete, bool remove_isolated_vertices=true) override
Deletes a set of elements.
void set_vertex(index_t e, index_t lv, index_t v)
Sets a vertex of an edge.
Base class for mesh elements.
virtual void delete_elements(vector< index_t > &to_delete, bool remove_isolated_vertices=true)=0
Deletes a set of elements.
static bool has_non_zero(const GEO::vector< index_t > &I)
Tests whether a vector contains a non-zero value.
virtual void clear(bool keep_attributes=true, bool keep_memory=false)=0
Removes all the elements and attributes.
virtual void pop()=0
Removes the last element.
virtual void permute_elements(vector< index_t > &permutation)=0
Applies a permutation to the elements and their attributes.
Stores the facets of a mesh (low-level store)
index_t corner(index_t f, index_t lv) const
Gets a corner by facet and local vertex index.
index_t corners_end(index_t f) const
Gets the upper limit for iterating over the corners of a facet.
index_t nb_corners(index_t f) const
Gets the number of corners in a facet.
const index_t * corners_begin_ptr(index_t f) const
Gets a pointer to the first element for iterating over the corners of a facet.
void clear_store(bool keep_attributes, bool keep_memory=false) override
Removes all the elements and attributes.
void resize_store(index_t new_size) override
Resizes this MeshSubElementsStore.
bool are_simplices() const
Tests whether all the facets are triangles.
index_t corners_begin(index_t f) const
Gets the first element for iterating over the corners of a facet.
index_t create_triangle(index_t v1, index_t v2, index_t v3)
Creates a triangle.
void compute_borders()
Replaces the edges of this mesh with the borders of the surfacic part.
void clear(bool keep_attributes=true, bool keep_memory=false) override
Removes all the elements and attributes.
index_t create_quad(index_t v1, index_t v2, index_t v3, index_t v4)
Creates a quad.
index_t create_polygon(const vector< index_t > &vertices)
Creates a polygonal facet.
void is_not_simplicial()
Indicates that the stored elements are no longer only triangles.
void triangulate()
Triangulates the facets.
MeshFacets(Mesh &mesh)
MeshFacets constructor.
friend void tessellate_facets(Mesh &M, index_t max_nb_vertices)
Subdivides the facets with more than nb_vertices.
index_t vertex(index_t f, index_t lv) const
Gets a vertex by facet and local vertex index.
index_t find_edge(index_t f, index_t v1, index_t v2)
Finds an edge by vertex indices.
void connect(index_t facets_begin, index_t facets_end)
Connects a contiguous sequence of facets.
void reserve(index_t nb_to_reserve)
Reserves space for new facets.
void permute_elements(vector< index_t > &permutation) override
Applies a permutation to the elements and their attributes.
index_t nb_vertices(index_t f) const
Gets the number of vertices of a facet.
void is_simplicial()
Indicates that the stored elements are only triangles.
void delete_elements(vector< index_t > &to_delete, bool remove_isolated_vertices=true) override
Deletes a set of elements.
void connect()
Connects the facets.
void flip(index_t f)
Flips a facet.
index_t create_polygon(index_t nb_vertices)
Creates a polygonal facet.
index_t create_polygon(index_t nb_vertices, const index_t *vertices)
Creates a polygonal facet.
void set_vertex(index_t f, index_t lv, index_t v)
Sets a vertex by facet and local vertex index.
index_t find_common_vertex(index_t f1, index_t f2) const
finds a common vertex shared by two facets
index_range corners(index_t f) const
Gets the corners of a facet.
void pop() override
Removes the last element.
index_t find_vertex(index_t f, index_t v) const
Gets the local index of a vertex in a facet.
index_t find_adjacent(index_t f, index_t f2) const
Gets the local index of a facet adjacent to another one.
index_t prev_corner_around_facet(index_t f, index_t c) const
Gets the predecessor of a corner around a facet.
void assign_triangle_mesh(coord_index_t dim, vector< double > &vertices, vector< index_t > &triangles, bool steal_args)
Copies a triangle mesh into this Mesh.
index_t create_quads(index_t nb_quads)
Creates a contiguous chunk of quads.
index_t create_facets(index_t nb_facets, index_t nb_vertices_per_polygon)
Creates a contiguous chunk of facets.
index_t adjacent(index_t f, index_t le) const
Gets an adjacent facet by facet and local edge index.
void set_adjacent(index_t f, index_t le, index_t f2)
Sets an adjacent facet by facet and local edge index.
index_t create_triangles(index_t nb_triangles)
Creates a contiguous chunk of triangles.
index_t next_corner_around_facet(index_t f, index_t c) const
Gets the successor of a corner around a facet.
Base class for mesh sub-element storage.
index_as_iterator begin() const
Used by range-based for.
virtual ~MeshSubElementsStore()
MeshElementStore destructor.
AttributesManager & attributes() const
Gets the attributes manager.
MeshSubElementsStore(Mesh &mesh)
Constructs a new MeshSubElementStore.
index_t create_sub_element()
Creates attributes for a sub-element.
virtual void clear_store(bool keep_attributes, bool keep_memory=false)
Removes all the elements and attributes.
index_t create_sub_elements(index_t nb)
Creates a contiguous chunk of attributes for sub-elements.
index_t nb() const
Gets the number of (sub-)elements.
void reserve_store(index_t nb_to_reserve)
Reserves space for new elements.
index_as_iterator end() const
Used by range-based for.
void copy(const MeshSubElementsStore &rhs, bool copy_attributes=true)
Copies a MeshSubElementsStore into this one.
void adjust_store()
Makes the size of the store tightly match the number of the elements.
virtual void resize_store(index_t new_size)
Resizes this MeshSubElementsStore.
void pop() override
Removes the last element.
void resize_store(index_t new_size) override
Resizes this MeshSubElementsStore.
void clear(bool keep_attributes=true, bool keep_memory=false) override
Removes all the elements and attributes.
index_t create_vertex(const double *coords)
Creates a new vertex.
void assign_points(const double *points, index_t dim, index_t nb_pts)
Assigns all the points.
const float * single_precision_point_ptr(index_t v) const
Gets a (single-precision) point.
const double * point_ptr(index_t v) const
Gets a point.
float * single_precision_point_ptr(index_t v)
Gets a (single-precision) point.
void remove_isolated()
Removes the vertices that have no mesh element incident to them.
void set_dimension(index_t dim)
Sets the dimension of the vertices.
void set_double_precision()
Sets double precision mode.
vec3 & point(index_t v)
Gets a point.
void clear_store(bool keep_attributes, bool keep_memory=false) override
Removes all the elements and attributes.
const vec3 & point(index_t v) const
Gets a point.
void permute_elements(vector< index_t > &permutation) override
Applies a permutation to the elements and their attributes.
void assign_points(vector< double > &points, index_t dim, bool steal_arg)
Assigns all the points.
bool double_precision() const
Tests whether vertices are stored in double-precision mode.
bool single_precision() const
Tests whether vertices are stored in single-precision mode.
index_t dimension() const
Gets the dimension of the vertices.
index_t create_vertices(index_t nb)
Creates a contiguous chunk of vertices.
void set_single_precision()
Sets single precision mode.
double * point_ptr(index_t v)
Gets a point.
index_t create_vertex()
Creates a new vertex.
void delete_elements(vector< index_t > &to_delete, bool remove_isolated_vertices=true) override
Deletes a set of elements.
Mesh(index_t dimension=3, bool single_precision=false)
Mesh constructor.
void copy(const Mesh &rhs, bool copy_attributes=true, MeshElementsFlags what=MESH_ALL_ELEMENTS)
Copies a mesh onto this one.
MeshElementsFlags
Indicates the mesh elements (vertices, facets or cells) present in a mesh.
MeshSubElementsStore & get_subelements_by_index(index_t i)
Gets a MeshSubElementsStore by index.
index_t nb_subelements_types() const
Gets the number of subelements types.
void assert_is_valid()
Does some validity checks.
static std::string subelements_type_to_name(MeshElementsFlags what)
Gets a subelement name by subelement type.
void clear(bool keep_attributes=true, bool keep_memory=false)
Removes all the elements and attributes of this mesh.
const MeshSubElementsStore & get_subelements_by_index(index_t i) const
Gets a MeshSubElementsStore by index.
virtual ~Mesh()
Mesh destructor.
std::string get_attributes() const
Gets the list of all attributes.
static bool parse_attribute_name(const std::string &full_attribute_name, MeshElementsFlags &where, std::string &attribute_name, index_t &component)
Extracts localisation, name and optional component from an attribute name.
void display_attributes(const std::string &tag, const std::string &subelement_name, const MeshSubElementsStore &subelements) const
Displays the list of attributes to the Logger.
const MeshSubElementsStore & get_subelements_by_type(MeshElementsFlags what) const
Gets a MeshSubElementsStore by subelements type.
MeshSubElementsStore & get_subelements_by_type(MeshElementsFlags what)
Gets a MeshSubElementsStore by subelements type.
std::string get_vector_attributes(index_t max_dim=0) const
Gets the list of all vector attributes.
std::string get_scalar_attributes() const
Gets the list of all scalar attributes.
static MeshElementsFlags name_to_subelements_type(const std::string &name)
Gets a subelement type by subelement name.
void show_stats(const std::string &tag="Mesh") const
Displays number of vertices, facets and borders.
Wraps an integer to be used with the range-based for construct.
A generic index_range bounded by two "non-iterators".
Vector with aligned memory allocation.
T * data()
Gets a pointer to the array of elements.
index_t size() const
Gets the number of elements.
Geometric functions in 2d and 3d.
void copy(void *to, const void *from, size_t size)
Copies a memory block.
CellDescriptor * cell_type_to_cell_descriptor[GEO::MESH_NB_CELL_TYPES]
Maps a cell type to the associated cell descriptor.
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
C++-20 like helpers for manipulating ranges of integers.
Lookup tables that describe the combinatorics of each cell type.
index_t nb_vertices_in_facet[6]
index_t facet_vertex[6][4]
index_t edge_adjacent_facet[12][2]
index_t edge_vertex[12][2]