Visual Computing Library  devel
Loading...
Searching...
No Matches
vertex_container.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_MESH_CONTAINERS_VERTEX_CONTAINER_H
24#define VCL_MESH_CONTAINERS_VERTEX_CONTAINER_H
25
26#include "base/element_container.h"
27
28#include <vclib/mesh/elements/vertex.h>
29#include <vclib/mesh/elements/vertex_components.h>
30
31#include <typeindex>
32
33namespace vcl {
34namespace mesh {
35
50template<VertexConcept T>
52{
53 template<VertexConcept U>
54 friend class VertexContainer;
55
58
59public:
60 using Vertex = T;
61 using VertexType = T;
62 using VertexIterator = Base::ElementIterator;
63 using ConstVertexIterator = Base::ConstElementIterator;
64
68 VertexContainer() = default;
69
81 const VertexType& vertex(uint i) const { return Base::element(i); }
82
93 VertexType& vertex(uint i) { return Base::element(i); }
94
104 uint vertexNumber() const { return Base::elementNumber(); }
105
115 uint vertexContainerSize() const { return Base::elementContainerSize(); }
116
123 uint deletedVertexNumber() const { return Base::deletedElementNumber(); }
124
135 uint addVertex() { return Base::addElement(); }
136
148 uint addVertex(const typename T::PositionType& p)
149 {
150 uint vid = addVertex();
151 vertex(vid).position() = p; // set the position to the vertex
152 return vid;
153 }
154
169 uint addVertices(uint n) { return Base::addElements(n); }
170
193 template<typename... VC>
194 uint addVertices(const typename T::PositionType& p, const VC&... v)
195 {
197 // reserve the new number of vertices
198 reserveVertices(vid + sizeof...(VC) + 1);
199 addVertex(p);
200 // pack expansion: will be translated at compile time as an addVertex()
201 // call for each argument of the addVertices member function
202 (addVertex(v), ...);
203 return vid;
204 }
205
217 template<vcl::Range R>
219 {
221 reserveVertices(vid + std::ranges::size(range));
222 for (const auto& v : range) {
223 addVertex(v);
224 }
225 return vid;
226 }
227
244 void clearVertices() { Base::clearElements(); }
245
274 void resizeVertices(uint n) { Base::resizeElements(n); }
275
294 void reserveVertices(uint n) { Base::reserveElements(n); }
295
302 void compactVertices() { Base::compactElements(); }
303
316 void deleteVertex(uint i) { Base::deleteElement(i); }
317
331 void deleteVertex(const VertexType* v) { Base::deleteElement(v); }
332
347 {
348 return Base::elementIndexIfCompact(i);
349 }
350
362 std::vector<uint> vertexCompactIndices() const
363 {
364 return Base::elementCompactIndices();
365 }
366
391 void updateVertexReferences(const std::vector<uint>& newIndices)
392 {
393 Base::updateElementReferences(newIndices);
394 }
395
407 VertexIterator vertexBegin(bool jumpDeleted = true)
408 {
409 return Base::elementBegin(jumpDeleted);
410 }
411
416 VertexIterator vertexEnd() { return Base::elementEnd(); }
417
429 ConstVertexIterator vertexBegin(bool jumpDeleted = true) const
430 {
431 return Base::elementBegin(jumpDeleted);
432 }
433
438 ConstVertexIterator vertexEnd() const { return Base::elementEnd(); }
439
463 auto vertices(bool jumpDeleted = true)
464 {
465 return Base::elements(jumpDeleted);
466 }
467
492 auto vertices(uint begin, uint end = UINT_NULL)
493 {
494 return Base::elements(begin, end);
495 }
496
520 auto vertices(bool jumpDeleted = true) const
521 {
522 return Base::elements(jumpDeleted);
523 }
524
549 auto vertices(uint begin, uint end = UINT_NULL) const
550 {
551 return Base::elements(begin, end);
552 }
553
559 {
560 Base::enableAllOptionalComponents();
561 }
562
568 {
569 Base::disableAllOptionalComponents();
570 }
571
572 // Adjacent Edges
573
583 requires vert::HasOptionalAdjacentEdges<T>
584 {
585 return Base::template isOptionalComponentEnabled<
586 typename T::AdjacentEdges>();
587 }
588
596 requires vert::HasOptionalAdjacentEdges<T>
597 {
599 }
600
608 requires vert::HasOptionalAdjacentEdges<T>
609 {
611 }
612
613 // Adjacent Faces
614
624 requires vert::HasOptionalAdjacentFaces<T>
625 {
626 return Base::template isOptionalComponentEnabled<
627 typename T::AdjacentFaces>();
628 }
629
637 requires vert::HasOptionalAdjacentFaces<T>
638 {
640 }
641
649 requires vert::HasOptionalAdjacentFaces<T>
650 {
652 }
653
654 // Adjacent Vertices
655
667 requires vert::HasOptionalAdjacentVertices<T>
668 {
669 return Base::template isOptionalComponentEnabled<
670 typename T::AdjacentVertices>();
671 }
672
680 requires vert::HasOptionalAdjacentVertices<T>
681 {
683 }
684
692 requires vert::HasOptionalAdjacentVertices<T>
693 {
695 }
696
697 // Color
698
707 bool isPerVertexColorEnabled() const requires vert::HasOptionalColor<T>
708 {
709 return Base::template isOptionalComponentEnabled<typename T::Color>();
710 }
711
718 void enablePerVertexColor() requires vert::HasOptionalColor<T>
719 {
720 return Base::template enableOptionalComponent<typename T::Color>();
721 }
722
729 void disablePerVertexColor() requires vert::HasOptionalColor<T>
730 {
732 }
733
734 // Mark
735
744 bool isPerVertexMarkEnabled() const requires vert::HasOptionalMark<T>
745 {
746 return Base::template isOptionalComponentEnabled<typename T::Mark>();
747 }
748
755 void enablePerVertexMark() requires vert::HasOptionalMark<T>
756 {
758 }
759
767 void disablePerVertexMark() requires vert::HasOptionalMark<T>
768 {
770 }
771
772 // MaterialIndex
773
783 requires vert::HasOptionalMaterialIndex<T>
784 {
785 return Base::template isOptionalComponentEnabled<
786 typename T::MaterialIndex>();
787 }
788
796 requires vert::HasOptionalMaterialIndex<T>
797 {
799 }
800
809 requires vert::HasOptionalMaterialIndex<T>
810 {
812 }
813
814 // Normal
815
824 bool isPerVertexNormalEnabled() const requires vert::HasOptionalNormal<T>
825 {
827 }
828
835 void enablePerVertexNormal() requires vert::HasOptionalNormal<T>
836 {
838 }
839
846 void disablePerVertexNormal() requires vert::HasOptionalNormal<T>
847 {
849 }
850
851 // PrincipalCurvature
852
863 requires vert::HasOptionalPrincipalCurvature<T>
864 {
865 return Base::template isOptionalComponentEnabled<
866 typename T::PrincipalCurvature>();
867 }
868
876 requires vert::HasOptionalPrincipalCurvature<T>
877 {
878 Base::template enableOptionalComponent<
879 typename T::PrincipalCurvature>();
880 }
881
889 requires vert::HasOptionalPrincipalCurvature<T>
890 {
891 Base::template disableOptionalComponent<
892 typename T::PrincipalCurvature>();
893 }
894
895 // Quality
896
905 bool isPerVertexQualityEnabled() const requires vert::HasOptionalQuality<T>
906 {
908 }
909
916 void enablePerVertexQuality() requires vert::HasOptionalQuality<T>
917 {
919 }
920
927 void disablePerVertexQuality() requires vert::HasOptionalQuality<T>
928 {
930 }
931
932 // Tangent
933
942 bool isPerVertexTangentEnabled() const requires vert::HasOptionalTangent<T>
943 {
945 }
946
953 void enablePerVertexTangent() requires vert::HasOptionalTangent<T>
954 {
956 }
957
964 void disablePerVertexTangent() requires vert::HasOptionalTangent<T>
965 {
967 }
968
969 // TexCoord
970
980 requires vert::HasOptionalTexCoord<T>
981 {
982 return Base::template isOptionalComponentEnabled<
983 typename T::TexCoord>();
984 }
985
992 void enablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
993 {
995 }
996
1003 void disablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
1004 {
1006 }
1007
1008 // Custom Components
1009
1022 bool hasPerVertexCustomComponent(const std::string& name) const
1024 {
1025 return Base::hasElemCustomComponent(name);
1026 }
1027
1038 std::vector<std::string> perVertexCustomComponentNames() const
1040 {
1041 return Base::elemCustomComponentNames();
1042 }
1043
1067 template<typename K>
1068 bool isPerVertexCustomComponentOfType(const std::string& name) const
1070 {
1071 return Base::template isElemCustomComponentOfType<K>(name);
1072 }
1073
1089 std::type_index perVertexCustomComponentType(const std::string& name) const
1091 {
1092 return Base::elemComponentType(name);
1093 }
1094
1114 template<typename K>
1117 {
1118 return Base::template elemCustomComponentNamesOfType<K>();
1119 }
1120
1131 template<typename K>
1132 void addPerVertexCustomComponent(const std::string& name)
1134 {
1135 Base::template addElemCustomComponent<K>(name);
1136 }
1137
1150 void deletePerVertexCustomComponent(const std::string& name)
1152 {
1153 Base::deleteElemCustomComponent(name);
1154 }
1155
1197 template<typename K>
1199 const std::string& name) requires vert::HasCustomComponents<T>
1200 {
1201 return Base::template customComponentVectorHandle<K>(name);
1202 }
1203
1248 template<typename K>
1250 const std::string& name) const requires vert::HasCustomComponents<T>
1251 {
1252 return Base::template customComponentVectorHandle<K>(name);
1253 }
1254
1265 template<typename K>
1268 {
1270 }
1271
1282 template<typename K>
1288};
1289
1290/* Concepts */
1291
1304template<typename T>
1305concept HasVertexContainer = std::derived_from< // same type or derived type
1306 std::remove_cvref_t<T>,
1307 VertexContainer<typename RemoveRef<T>::VertexType>>;
1308
1309} // namespace mesh
1310
1345template<typename... Args>
1347
1348} // namespace vcl
1349
1350#endif // VCL_MESH_CONTAINERS_VERTEX_CONTAINER_H
A class representing a box in N-dimensional space.
Definition box.h:46
Definition element.h:64
The Vertex Container class, will be used when the template argument given to the Mesh is a Vertex.
Definition vertex_container.h:52
void deserializePerVertexCustomComponentsOfType(std::istream &is)
Deserializes in the given input stream all the custom components of the Vertex Element of type K.
Definition vertex_container.h:1283
void enablePerVertexTangent()
Enables the Optional Tangent of the vertex.
Definition vertex_container.h:953
void disablePerVertexPrincipalCurvature()
Disables the Optional PrincipalCurvature of the vertex.
Definition vertex_container.h:888
void disablePerVertexTexCoord()
Disables the Optional TexCoord of the vertex.
Definition vertex_container.h:1003
auto vertices(bool jumpDeleted=true)
Returns a small utility object that allows to iterate over the vertices of the containers,...
Definition vertex_container.h:463
bool isPerVertexColorEnabled() const
Checks if the vertex Optional Color is enabled.
Definition vertex_container.h:707
void enablePerVertexAdjacentEdges()
Enables the Optional Adjacent Edges of the vertex.
Definition vertex_container.h:595
void deleteVertex(uint i)
Marks as deleted the vertex with the given id.
Definition vertex_container.h:316
VertexType & vertex(uint i)
Returns a reference of the vertex at the i-th position in the Vertex Container of the Mesh,...
Definition vertex_container.h:93
void clearVertices()
Clears the Vertex container of the Mesh, deleting all the vertices.
Definition vertex_container.h:244
bool isPerVertexQualityEnabled() const
Checks if the vertex Optional Quality is enabled.
Definition vertex_container.h:905
auto vertices(bool jumpDeleted=true) const
Returns a small utility object that allows to iterate over the vertices of the containers,...
Definition vertex_container.h:520
bool isPerVertexTangentEnabled() const
Checks if the vertex Optional Tangent is enabled.
Definition vertex_container.h:942
void disablePerVertexQuality()
Disables the Optional Quality of the vertex.
Definition vertex_container.h:927
ConstVertexIterator vertexEnd() const
Returns a const iterator to the end of the container.
Definition vertex_container.h:438
std::vector< std::string > perVertexCustomComponentNames() const
Returns a vector containing all the names of the custom components of any type associated to the Vert...
Definition vertex_container.h:1038
ConstCustomComponentVectorHandle< K > perVertexCustomComponentVectorHandle(const std::string &name) const
Returns a const vector handle to the custom component having type K and the given name.
Definition vertex_container.h:1249
void disablePerVertexMaterialIndex()
Container::disableVertexMaterialIndex disables the Optional MaterialIndex of the vertex.
Definition vertex_container.h:808
void disablePerVertexAdjacentFaces()
Disables the Optional Adjacent Faces of the vertex.
Definition vertex_container.h:648
void disablePerVertexNormal()
Checks if the vertex Optional PrincipalCurvature is enabled.
Definition vertex_container.h:846
void resizeVertices(uint n)
Resizes the Vertex container to contain n vertices.
Definition vertex_container.h:274
void compactVertices()
Compacts the Vertex Container, removing all the vertices marked as deleted. Vertices indices will cha...
Definition vertex_container.h:302
bool hasPerVertexCustomComponent(const std::string &name) const
Checks if vertices have a custom component with the given name.
Definition vertex_container.h:1022
auto vertices(uint begin, uint end=UINT_NULL) const
Returns a view object that allows to iterate over the Vertices of the container in the given range:
Definition vertex_container.h:549
auto vertices(uint begin, uint end=UINT_NULL)
Returns a view object that allows to iterate over the Vertices of the container in the given range:
Definition vertex_container.h:492
void deletePerVertexCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Vertex Element.
Definition vertex_container.h:1150
void enablePerVertexMaterialIndex()
Enables the Optional MaterialIndex of the vertex.
Definition vertex_container.h:795
void enablePerVertexColor()
Enables the Optional Color of the vertex.
Definition vertex_container.h:718
uint vertexNumber() const
Returns the number of non-deleted vertices contained in the Vertex container of the Mesh.
Definition vertex_container.h:104
ConstVertexIterator vertexBegin(bool jumpDeleted=true) const
Returns a const iterator to the beginning of the container.
Definition vertex_container.h:429
void addPerVertexCustomComponent(const std::string &name)
Adds a custom component of type K to the Vertex, having the given name.
Definition vertex_container.h:1132
uint addVertex(const typename T::PositionType &p)
Add a new vertex with the given position into the vertex container, returning the id of the added ver...
Definition vertex_container.h:148
uint vertexIndexIfCompact(uint i) const
This is an utility member function that returns the index of an element if the container would be com...
Definition vertex_container.h:346
void disableAllPerVertexOptionalComponents()
Disables all the optional components associated to the Vertex type contained in the VertexContainer.
Definition vertex_container.h:567
CustomComponentVectorHandle< K > perVertexCustomComponentVectorHandle(const std::string &name)
Returns a vector handle to the custom component having the type K and the given name.
Definition vertex_container.h:1198
uint addVertices(uint n)
Add an arbitrary number of n vertices, returning the id of the first added vertex.
Definition vertex_container.h:169
bool isPerVertexMaterialIndexEnabled() const
Checks if the vertex Optional MaterialIndex is enabled.
Definition vertex_container.h:782
bool isPerVertexAdjacentVerticesEnabled() const
Checks if the vertex Optional Adjacent Vertices component is enabled.
Definition vertex_container.h:666
void enablePerVertexPrincipalCurvature()
Enables the Optional PrincipalCurvature of the vertex.
Definition vertex_container.h:875
std::type_index perVertexCustomComponentType(const std::string &name) const
Returns the std::type_index of the custom component of the Vertex Element having the given input name...
Definition vertex_container.h:1089
void disablePerVertexTangent()
Checks if the vertex Optional Tangent is enabled.
Definition vertex_container.h:964
uint addVertex()
Add a new vertex into the vertex container, returning the index of the added vertex.
Definition vertex_container.h:135
bool isPerVertexPrincipalCurvatureEnabled() const
Checks if the vertex Optional PrincipalCurvature is enabled.
Definition vertex_container.h:862
uint addVertices(const typename T::PositionType &p, const VC &... v)
Add an arbitrary number of vertices with the given positions, returning the id of the first added ver...
Definition vertex_container.h:194
void enablePerVertexTexCoord()
Enables the Optional TexCoord of the vertex.
Definition vertex_container.h:992
void enablePerVertexAdjacentVertices()
Enables the Optional Adjacent Vertices of the vertex.
Definition vertex_container.h:679
bool isPerVertexAdjacentEdgesEnabled() const
Checks if the vertex Optional Adjacent Edges component is enabled.
Definition vertex_container.h:582
void serializePerVertexCustomComponentsOfType(std::ostream &os) const
Serializes in the given output stream all the custom components of the Vertex Element of type K.
Definition vertex_container.h:1266
std::vector< std::string > perVertexCustomComponentNamesOfType() const
Returns a vector containing all the names of the custom components associated to the Vertex Element h...
Definition vertex_container.h:1115
void enablePerVertexNormal()
Enables the Optional Normal of the vertex.
Definition vertex_container.h:835
uint vertexContainerSize() const
Returns the number of vertices (also deleted) contained in the Vertex container of the Mesh.
Definition vertex_container.h:115
void disablePerVertexAdjacentEdges()
Disables the Optional Adjacent Edges of the vertex.
Definition vertex_container.h:607
void enablePerVertexMark()
Enables the Optional Mark of the vertex.
Definition vertex_container.h:755
VertexIterator vertexBegin(bool jumpDeleted=true)
Returns an iterator to the beginning of the container.
Definition vertex_container.h:407
bool isPerVertexAdjacentFacesEnabled() const
Checks if the vertex Optional Adjacent Faces component is enabled.
Definition vertex_container.h:623
void updateVertexReferences(const std::vector< uint > &newIndices)
Updates all the indices and pointers of the vertices of this container that are stored in any contain...
Definition vertex_container.h:391
void enablePerVertexAdjacentFaces()
Enables the Optional Adjacent Faces of the vertex.
Definition vertex_container.h:636
void disablePerVertexAdjacentVertices()
Disables the Optional Adjacent Vertices of the vertex.
Definition vertex_container.h:691
void disablePerVertexMark()
Container::disableVertexMark disables the Optional Mark of the vertex.
Definition vertex_container.h:767
uint addVertices(R &&range)
Add an arbitrary number of vertices with the positions contained in the given range,...
Definition vertex_container.h:218
void disablePerVertexColor()
Disables the Optional Color of the vertex.
Definition vertex_container.h:729
void reserveVertices(uint n)
Reserve a number of vertices in the container of Vertices. This is useful when you know (or you have ...
Definition vertex_container.h:294
VertexContainer()=default
Empty constructor that creates an empty container of Vertices.
bool isPerVertexTexCoordEnabled() const
Checks if the vertex Optional TexCoord is enabled.
Definition vertex_container.h:979
void enableAllPerVertexOptionalComponents()
Enables all the optional components associated to the Vertex type contained in the VertexContainer.
Definition vertex_container.h:558
bool isPerVertexCustomComponentOfType(const std::string &name) const
Checks if the custom component of the Vertex Element having the given name has the same type of the g...
Definition vertex_container.h:1068
VertexIterator vertexEnd()
Returns an iterator to the end of the container.
Definition vertex_container.h:416
bool isPerVertexNormalEnabled() const
Checks if the vertex Optional Normal is enabled.
Definition vertex_container.h:824
bool isPerVertexMarkEnabled() const
Checks if the vertex Optional Mark is enabled.
Definition vertex_container.h:744
uint deletedVertexNumber() const
Returns the number of deleted vertices in the Vertex container, that is vertexContainerSize() - verte...
Definition vertex_container.h:123
void enablePerVertexQuality()
Enables the Optional Quality of the vertex.
Definition vertex_container.h:916
std::vector< uint > vertexCompactIndices() const
Returns a vector that tells, for each actual vertex index, the new index that the vertex would have i...
Definition vertex_container.h:362
const VertexType & vertex(uint i) const
Returns a const reference of the vertex at the i-th position in the Vertex Container of the Mesh,...
Definition vertex_container.h:81
void deleteVertex(const VertexType *v)
Marks as deleted the given vertex, before asserting that the vertex belongs to this container.
Definition vertex_container.h:331
HasVertices concepts is satisfied when at least one of its types is (or inherits from) a vcl::mesh::V...
Definition vertex_container.h:1346
Utility concept that is evaluated true the Range R has a value_type that is exactly T.
Definition range.h:66
Definition mesh_components.h:51
A concept that checks whether a class has (inherits from) a VertexContainer class.
Definition vertex_container.h:1305
Definition vertex_components.h:87
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