23#ifndef VCL_MESH_MESH_H
24#define VCL_MESH_MESH_H
26#include "mesh_components.h"
27#include "mesh_containers.h"
29#include <vclib/concepts/mesh.h>
66template<
typename... Args>
69 static_assert(
HasVertices<Args...>,
"A Mesh must have a VertexContainer.");
71 template<
typename El,
bool b>
72 friend struct comp::detail::CustomComponentsData;
74 template<
typename El,
bool b>
75 friend struct comp::detail::ComponentData;
77 template<ElementConcept T>
80 template<
uint ELEM_ID,
typename MeshType,
typename... Comps>
85 template<u
int ELEM_ID>
101 template<ElementConcept El>
136 template<u
int ELEM_ID>
150 template<u
int ELEM_ID>
179 template<ElementConcept El>
202 template<u
int ELEM_ID>
226 template<u
int ELEM_ID, u
int COMP_ID>
251 template<u
int ELEM_ID, u
int COMP_ID>
255 HasPerElementOptionalComponent<
Mesh<Args...>, ELEM_ID,
COMP_ID>;
266 updateAllParentMeshPointers();
281 updateAllParentMeshPointers();
287 std::array<const void*, N_CONTAINERS>
othBases =
386 template<
typename OtherMeshType>
414 std::array<std::size_t, N_CONTAINERS>
sizes =
419 std::array<const void*, N_CONTAINERS>
bases =
444 template<
typename OtherMeshType>
453 (Args::importFrom(
m), ...);
456 updateAllParentMeshPointers();
481 using FaceContainer =
typename Mesh<Args...>::FaceContainer;
482 FaceContainer::manageImportTriFromPoly(
m);
492 Mesh<Args...>&
m1 = *
this;
500 std::array<const void*, N_CONTAINERS>
m1Bases =
502 std::array<const void*, N_CONTAINERS>
m2Bases =
509 (
swap((Args&)
m1, (Args&)
m2), ...);
512 m1.updateAllParentMeshPointers();
513 m2.updateAllParentMeshPointers();
556 template<ElementConcept El>
560 return Container::index(&e);
574 template<ElementConcept El>
578 return Container::index(e);
595 template<u
int ELEM_ID>
600 return Cont::element(
i);
617 template<u
int ELEM_ID>
622 return Cont::element(
i);
634 template<u
int ELEM_ID>
639 return Cont::elementNumber();
656 template<u
int ELEM_ID>
661 return Cont::elementContainerSize();
674 template<u
int ELEM_ID>
679 return Cont::deletedElementNumber();
696 template<u
int ELEM_ID>
701 return Cont::addElement();
719 template<u
int ELEM_ID>
724 return Cont::addElements(
n);
747 template<u
int ELEM_ID>
752 Cont::clearElements();
788 template<u
int ELEM_ID>
793 Cont::resizeElements(
n);
816 template<u
int ELEM_ID>
821 Cont::reserveElements(
n);
830 template<u
int ELEM_ID>
835 Cont::compactElements();
855 template<u
int ELEM_ID>
860 Cont::deleteElement(
i);
880 template<ElementConcept El>
884 return Cont::deleteElement(e);
904 template<ElementConcept El>
908 return Cont::deleteElement(&e);
928 template<u
int ELEM_ID>
934 return Cont::elementConpactIndices();
963 template<u
int ELEM_ID>
969 return Cont::updateElementIndices(
newIndices);
972 void serialize(std::ostream&
os)
const
979 void deserialize(std::istream& is)
981 (preDeserialization<Args>(is), ...);
983 (postDeserialization<Args>(is), ...);
1003 template<u
int ELEM_ID>
1022 template<u
int ELEM_ID>
1027 return Cont::elementEnd();
1047 template<u
int ELEM_ID>
1067 template<u
int ELEM_ID>
1072 return Cont::elementEnd();
1097 template<u
int ELEM_ID>
1127 template<u
int ELEM_ID>
1149 template<u
int ELEM_ID, u
int COMP_ID>
1169 template<u
int ELEM_ID, u
int COMP_ID>
1189 template<u
int ELEM_ID, u
int COMP_ID>
1214 template<u
int ELEM_ID>
1220 return Cont::hasElemCustomComponent(name);
1235 template<u
int ELEM_ID>
1241 return Cont::elemCustomComponentNames();
1258 template<u
int ELEM_ID,
typename K>
1280 template<u
int ELEM_ID>
1286 return Cont::elemCustomComponentType(name);
1302 template<u
int ELEM_ID,
typename K>
1323 template<u
int ELEM_ID,
typename K>
1343 template<u
int ELEM_ID>
1349 Cont::deleteElemCustomComponent(name);
1393 template<u
int ELEM_ID,
typename K>
1395 const std::string& name)
1444 template<u
int ELEM_ID,
typename K>
1446 const std::string& name)
const
1455 template<
typename Cont>
1456 bool isContainerCompact()
const
1459 return Cont::elementNumber() == Cont::elementContainerSize();
1475 template<
typename Cont>
1479 if (Cont::elementNumber() != Cont::elementContainerSize()) {
1480 Cont::compactElements();
1494 template<
typename Cont>
1498 Cont::enableAllOptionalComponents();
1511 template<
typename Cont>
1515 Cont::disableAllOptionalComponents();
1528 template<
typename Cont>
1532 Cont::clearElements();
1536 template<ElementConcept Element>
1544 template<
typename Element,
typename... A>
1545 void updateReferences(
const Element* oldBase, TypeWrapper<A...>)
1548 oldBase, TypeWrapper<A...>(), std::array<std::size_t, 0>(), 0);
1552 template<
typename Cont,
typename Element>
1553 void updateReferences(
const Element* oldBase)
1555 updateReferences<Cont>(oldBase, std::array<std::size_t, 0>(), 0);
1561 template<
typename Element, std::size_t N,
typename... A>
1562 void updateReferences(
1563 const Element* oldBase,
1565 const std::array<std::size_t, N>& sizes = std::array<std::size_t, 0>(),
1568 (updateReferences<A>(oldBase, sizes, offset), ...);
1571 template<
typename Cont,
typename Element, std::
size_t N>
1572 void updateReferences(
1573 const Element* oldBase,
1574 const std::array<std::size_t, N>& sizes = std::array<std::size_t, 0>(),
1577 if constexpr (mesh::ElementContainerConcept<Cont>) {
1578 if constexpr (N > 0) {
1580 constexpr uint I = IndexInTypes<Cont, Containers>::value;
1581 static_assert(I >= 0 && I !=
UINT_NULL);
1582 Cont::updateReferences(oldBase, sizes[I], offset);
1585 Cont::updateReferences(oldBase);
1590 template<ElementConcept Element>
1591 void updateAllReferences(
const std::vector<uint>& newIndices)
1593 (updateReferences<Args, Element>(newIndices), ...);
1596 template<
typename Cont,
typename Element>
1597 void updateReferences(
const std::vector<uint>& newIndices)
1599 if constexpr (mesh::ElementContainerConcept<Cont>) {
1600 Cont::template updateReferences<Element>(newIndices);
1608 bool isAvailable()
const {
return true; }
1612 template<
typename Cont,
typename OtherMeshType>
1615 if constexpr (mesh::ElementContainerConcept<Cont>) {
1616 Cont::enableOptionalComponentsOf(m);
1622 void updateAllParentMeshPointers() { (setParentMeshPointers<Args>(), ...); }
1624 template<
typename Cont>
1625 void setParentMeshPointers()
1627 if constexpr (mesh::ElementContainerConcept<Cont>) {
1628 Cont::setParentMeshPointers(
this);
1632 template<
typename Cont>
1633 void appendContainer(
const Mesh& m)
1635 if constexpr (mesh::ElementContainerConcept<Cont>) {
1636 Cont::append((
const Cont&) m);
1649 template<uint I,
typename Cont,
typename Array,
typename... A>
1656 static_assert(I >= 0 && I !=
UINT_NULL);
1657 bases[I] =
m.Cont::mElemVec.data();
1661 template<
typename... A>
1662 static auto getContainerBases(
const Mesh<A...>&
m)
1670 std::array<const void*, N_CONTAINERS>
bases;
1687 template<uint I,
typename Cont,
typename Array,
typename... A>
1694 static_assert(I >= 0 && I !=
UINT_NULL);
1695 sizes[I] =
m.Cont::mElemVec.size();
1699 template<
typename... A>
1700 static auto getContainerSizes(
const Mesh<A...>&
m)
1708 std::array<std::size_t, N_CONTAINERS>
sizes;
1742 template<
typename Cont,
typename Array,
typename... A>
1754 using ElType = Cont::ElementType;
1758 static_assert(I >= 0 && I !=
UINT_NULL);
1771 static void updateReferencesOfContainerTypeAfterAppend(
1783 using ElType = Cont::ElementType;
1787 static_assert(I >= 0 && I !=
UINT_NULL);
1803 template<
typename Cont>
1804 void preSerialization(std::ostream& os)
const
1806 if constexpr (mesh::ElementContainerConcept<Cont>) {
1807 Cont::serializeOptionalComponentsAndElementsNumber(os);
1811 template<
typename Cont>
1812 void postSerialization(std::ostream& os)
const
1814 if constexpr (mesh::ElementContainerConcept<Cont>) {
1815 Cont::serializeElements(os);
1819 Cont::serialize(os);
1823 template<
typename Cont>
1824 void preDeserialization(std::istream& is)
1826 if constexpr (mesh::ElementContainerConcept<Cont>) {
1827 Cont::deserializeOptionalComponentsAndElementsNumber(is);
1831 template<
typename Cont>
1832 void postDeserialization(std::istream& is)
1834 if constexpr (mesh::ElementContainerConcept<Cont>) {
1835 Cont::deserializeElements(is);
1839 Cont::deserialize(is);
1845 template<u
int ELEM_ID,
typename T>
1846 uint elementIndex(
const T* el)
const
1848 using Cont = ContainerOfElement<ELEM_ID>::type;
1849 using ElType = Cont::ElementType;
1850 return index(
static_cast<const ElType*
>(el));
1853 template<
typename El>
1854 auto& customComponents()
1856 using ElCont = ContainerOf<El>::type;
1858 return ElCont::mCustomCompVecMap;
1861 template<
typename El>
1862 const auto& customComponents()
const
1864 using ElCont = ContainerOf<El>::type;
1866 return ElCont::mCustomCompVecMap;
1869 template<
typename El>
1870 auto& verticalComponents()
1872 using ElCont = ContainerOf<El>::type;
1874 return ElCont::mVerticalCompVecTuple;
1877 template<
typename El>
1878 const auto& verticalComponents()
const
1880 using ElCont = ContainerOf<El>::type;
1882 return ElCont::mVerticalCompVecTuple;
The Array class is a dynamically allocated N-dimensional array stored in RowWise mode.
Definition array.h:64
The Element class.
Definition element.h:57
The Mesh class represents a generic 3D mesh. A mesh is composed of a generic number of containers of ...
Definition mesh.h:68
bool isCompact() const
Returns true if this mesh is compact, meaning that all its containers have no deleted elements (size ...
Definition mesh.h:318
auto elements(bool jumpDeleted=true) const
Definition mesh.h:1128
uint deletedNumber() const
Returns the number of deleted elements of the given type in this mesh.
Definition mesh.h:675
void deleteElement(uint i)
Marks as deleted the element at the given index from its container, deduced from the template index E...
Definition mesh.h:856
void deleteElement(const El &e) const
Marks as deleted the given element from its container.
Definition mesh.h:905
Mesh()
Empty constructor, constructs an empty mesh.
Definition mesh.h:263
Mesh(const Mesh &oth)
Copy constructor of the Mesh. Will create a deep copy of the given input mesh, taking care of copying...
Definition mesh.h:276
auto begin(bool jumpDeleted=true)
Returns an iterator to the begining of the container of the elements having ID ELEM_ID in the mesh.
Definition mesh.h:1004
CustomComponentVectorHandle< K > perElementCustomComponentVectorHandle(const std::string &name)
Returns a vector handle to the custom component of type K having the given name associated to the Ele...
Definition mesh.h:1394
std::type_index perElementCustomComponentType(const std::string &name) const
Returns the std::type_index of the custom component having the given name associated to the Element h...
Definition mesh.h:1281
void compactContainer()
Definition mesh.h:1476
auto elements(bool jumpDeleted=true)
Definition mesh.h:1098
void compactElements()
Compacts the Container of the given element, removing all the elements marked as deleted....
Definition mesh.h:831
void enableSameOptionalComponentsOf(const OtherMeshType &m)
Enables all the OptionalComponents of this mesh according to the Components available on the OtherMes...
Definition mesh.h:387
Mesh(Mesh &&oth)
Move constructor, moves the given mesh into this one, without any other resource acquisition.
Definition mesh.h:304
bool hasPerElementCustomComponent(const std::string &name) const
Returns true if the Element having ID ELEM_ID has a custom component with the given name.
Definition mesh.h:1215
std::vector< uint > compactIndices() const
Returns a vector that tells, for each element of the container of ELEM_ID in the mesh,...
Definition mesh.h:929
void deleteElement(const El *e) const
Marks as deleted the given element from its container.
Definition mesh.h:881
void disableAllOptionalComponents()
Disables all the optional components of the elements of the containers if the mesh.
Definition mesh.h:352
void addPerElementCustomComponent(const std::string &name)
Adds a custom component of type K having the given name to the Element having ID ELEM_ID.
Definition mesh.h:1324
void append(const Mesh &m)
Appends all the elements contained in the mesh m to this mesh.
Definition mesh.h:408
auto end()
Returns an iterator to the end of the container of the elements having ID ELEM_ID in the mesh.
Definition mesh.h:1023
void enableAllOptionalComponentsInContainer()
Definition mesh.h:1495
bool isPerElementCustomComponentOfType(const std::string &name) const
Returns true if the Element having ID ELEM_ID has a custom component of type K with the given name.
Definition mesh.h:1259
uint add()
Adds a new element of the given type into its container, returning the index of the added element in ...
Definition mesh.h:697
void clear()
Clears all the Elements contained in the mesh.
Definition mesh.h:329
uint add(uint n)
Adds n new elements of the given type into its container, returning the index of the first added elem...
Definition mesh.h:720
void swap(Mesh &m2)
Swaps this mesh with the other input Mesh m2.
Definition mesh.h:490
uint containerSize() const
Returns the size of the container of elements of the given type in this mesh.
Definition mesh.h:657
void clearElements()
Clears the container of ELEM_ID elements the Mesh, deleting all the Elements.
Definition mesh.h:748
void importFrom(const OtherMeshType &m)
Imports all the components that can be imported from another type of mesh.
Definition mesh.h:445
bool isPerElementComponentEnabled() const
Returns true if optional Component having ID COMP_ID is enabled for elements having ID ELEM_ID in the...
Definition mesh.h:1150
const auto & element(uint i) const
Returns the element of the given type at the given index inside its container of this mesh.
Definition mesh.h:596
void compact()
Compacts all the containers of the mesh.
Definition mesh.h:337
void updateIndices(const std::vector< uint > &newIndices)
Updates all the indices and pointers of the elements of the container of ELEM_ID in the mesh,...
Definition mesh.h:964
Mesh & operator=(Mesh oth)
Assignment operator of the Mesh.
Definition mesh.h:537
void clearContainer()
Definition mesh.h:1529
void deletePerElementCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Element having ID ELEM_ID.
Definition mesh.h:1344
void reserve(uint n)
Reserves a number of elements of the given type in its container. The function does not add any eleme...
Definition mesh.h:817
void resize(uint n)
Resizes the Element container to contain n Elements of type ELEM_ID.
Definition mesh.h:789
static void updateReferencesOfContainerType(Mesh< A... > &m, const Array &bases)
Definition mesh.h:1743
auto end() const
Returns a const iterator to the end of the container of the elements having ID ELEM_ID in the mesh.
Definition mesh.h:1068
void enableAllOptionalComponents()
Enables all the optional components of the elements of the containers if the mesh.
Definition mesh.h:343
std::vector< std::string > perElementCustomComponentNames() const
Returns a vector containing all the names of the custom components of any type associated to the Elem...
Definition mesh.h:1236
void disableAllOptionalComponentsInContainer()
Definition mesh.h:1512
static constexpr bool hasPerElementComponent()
Returns true if this Mesh has a container of elements having the same Element ID of the template ELEM...
Definition mesh.h:227
static void setContainerBase(const Mesh< A... > &m, Array &bases)
Definition mesh.h:1650
friend void swap(Mesh &a, Mesh &b)
Specializes the swap function to allow the swapping of two Mesh objects.
Definition mesh.h:529
FilterTypesByCondition< mesh::IsElementContainerPred, TypeWrapper< Args... > >::type Containers
Containers is a vcl::TypeWrapper that wraps all the types from which the Mesh inherits (Args) that ar...
Definition mesh.h:114
auto & element(uint i)
Returns the element of the given type at the given index inside its container of this mesh.
Definition mesh.h:618
void enablePerElementComponent()
Enables the optional Component having ID COMP_ID for elements having ID ELEM_ID in the mesh.
Definition mesh.h:1170
uint index(const El *e) const
Returns the index of the given element in its Container of the Mesh.
Definition mesh.h:575
void disablePerElementComponent()
Disables the optional Component having ID COMP_ID for elements having ID ELEM_ID in the mesh.
Definition mesh.h:1190
ConstCustomComponentVectorHandle< K > perElementCustomComponentVectorHandle(const std::string &name) const
Returns a const vector handle to the custom component of type K having the given name associated to t...
Definition mesh.h:1445
uint number() const
Returns the number of elements of the given type in this mesh.
Definition mesh.h:635
ContainerType< ELEM_ID >::ElementType ElementType
ElementType is an alias that exposes the type of the Element identified by the template parameter ELE...
Definition mesh.h:151
uint index(const El &e) const
Returns the index of the given element in its Container of the Mesh.
Definition mesh.h:557
auto begin(bool jumpDeleted=true) const
Returns a const iterator to the begining of the container of the elements having ID ELEM_ID in the me...
Definition mesh.h:1048
static constexpr bool hasPerElementOptionalComponent()
Returns true if this Mesh has a container of elements having the same Element ID of the template ELEM...
Definition mesh.h:252
static constexpr bool hasContainerOf()
Returns true if this Mesh has a container of elements having the same Element ID of the template Elem...
Definition mesh.h:180
std::vector< std::string > perElementCustomComponentNamesOfType() const
Returns a vector containing all the names of the custom components of type K associated to the Elemen...
Definition mesh.h:1303
static void setContainerSize(const Mesh< A... > &m, Array &sizes)
Definition mesh.h:1688
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
HasVertices concepts is satisfied when at least one of its types is (or inherits from) a vcl::mesh::V...
Definition vertex_container.h:130
ElementContainerConcept is a concept satisfied when the type T is an Element Container.
Definition element_container.h:36
The HasFaceContainer concept is satisfied only if a container class provides the types and member fun...
Definition face_container.h:44
Definition mesh_concept.h:40
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
The CompId struct enumerates the components that can compose a element or a mesh.
Definition mesh_components.h:50
Removes all types that do not satisfy a condition, and get them as a tuple.
Definition filter_types.h:72
Definition variadic_templates.h:128
The ContainerOf struct allows to get the Container of an Element on this Mesh.
Definition mesh.h:103
Definition variadic_templates.h:143
A simple structure that wraps a list of variadic templates, without instantiating anything....
Definition type_wrapper.h:41
The ContainerOfElement structure exposes the type of the container of the given MeshType having eleme...
Definition mesh_containers.h:107
Definition mesh_containers.h:146
Definition mesh_containers.h:138
The predicate IsElementContainerPred sets its bool value to true when the type T satisfies the Elemen...
Definition mesh_containers.h:81