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 updateVertexIndices(const std::vector<uint>& newIndices)
392 {
393 Base::updateElementIndices(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 // Normal
773
782 bool isPerVertexNormalEnabled() const requires vert::HasOptionalNormal<T>
783 {
785 }
786
793 void enablePerVertexNormal() requires vert::HasOptionalNormal<T>
794 {
796 }
797
804 void disablePerVertexNormal() requires vert::HasOptionalNormal<T>
805 {
807 }
808
809 // PrincipalCurvature
810
821 requires vert::HasOptionalPrincipalCurvature<T>
822 {
823 return Base::template isOptionalComponentEnabled<
824 typename T::PrincipalCurvature>();
825 }
826
834 requires vert::HasOptionalPrincipalCurvature<T>
835 {
836 Base::template enableOptionalComponent<
837 typename T::PrincipalCurvature>();
838 }
839
847 requires vert::HasOptionalPrincipalCurvature<T>
848 {
849 Base::template disableOptionalComponent<
850 typename T::PrincipalCurvature>();
851 }
852
853 // Quality
854
863 bool isPerVertexQualityEnabled() const requires vert::HasOptionalQuality<T>
864 {
866 }
867
874 void enablePerVertexQuality() requires vert::HasOptionalQuality<T>
875 {
877 }
878
885 void disablePerVertexQuality() requires vert::HasOptionalQuality<T>
886 {
888 }
889
890 // TexCoord
891
901 requires vert::HasOptionalTexCoord<T>
902 {
903 return Base::template isOptionalComponentEnabled<
904 typename T::TexCoord>();
905 }
906
913 void enablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
914 {
916 }
917
924 void disablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
925 {
927 }
928
929 // Custom Components
930
943 bool hasPerVertexCustomComponent(const std::string& name) const
945 {
946 return Base::hasElemCustomComponent(name);
947 }
948
959 std::vector<std::string> perVertexCustomComponentNames() const
961 {
962 return Base::elemCustomComponentNames();
963 }
964
988 template<typename K>
989 bool isPerVertexCustomComponentOfType(const std::string& name) const
991 {
992 return Base::template isElemCustomComponentOfType<K>(name);
993 }
994
1010 std::type_index perVertexCustomComponentType(const std::string& name) const
1012 {
1013 return Base::elemComponentType(name);
1014 }
1015
1035 template<typename K>
1038 {
1039 return Base::template elemCustomComponentNamesOfType<K>();
1040 }
1041
1052 template<typename K>
1053 void addPerVertexCustomComponent(const std::string& name)
1055 {
1056 Base::template addElemCustomComponent<K>(name);
1057 }
1058
1071 void deletePerVertexCustomComponent(const std::string& name)
1073 {
1074 Base::deleteElemCustomComponent(name);
1075 }
1076
1118 template<typename K>
1120 const std::string& name) requires vert::HasCustomComponents<T>
1121 {
1122 return Base::template customComponentVectorHandle<K>(name);
1123 }
1124
1169 template<typename K>
1171 const std::string& name) const requires vert::HasCustomComponents<T>
1172 {
1173 return Base::template customComponentVectorHandle<K>(name);
1174 }
1175
1186 template<typename K>
1189 {
1191 }
1192
1203 template<typename K>
1209};
1210
1211/* Concepts */
1212
1225template<typename T>
1226concept HasVertexContainer = std::derived_from< // same type or derived type
1227 std::remove_cvref_t<T>,
1228 VertexContainer<typename RemoveRef<T>::VertexType>>;
1229
1230} // namespace mesh
1231
1266template<typename... Args>
1268
1269} // namespace vcl
1270
1271#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:1204
void disablePerVertexPrincipalCurvature()
Disables the Optional PrincipalCurvature of the vertex.
Definition vertex_container.h:846
void updateVertexIndices(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 disablePerVertexTexCoord()
Disables the Optional TexCoord of the vertex.
Definition vertex_container.h:924
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:863
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
void disablePerVertexQuality()
Disables the Optional Quality of the vertex.
Definition vertex_container.h:885
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:959
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:1170
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:804
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:943
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:1071
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:1053
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:1119
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 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:833
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:1010
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:820
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:913
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:1187
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:1036
void enablePerVertexNormal()
Enables the Optional Normal of the vertex.
Definition vertex_container.h:793
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 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:900
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:989
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:782
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:874
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:1267
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:52
A concept that checks whether a class has (inherits from) a VertexContainer class.
Definition vertex_container.h:1226
Definition vertex_components.h:85
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