Visual Computing Library
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 "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::mesh {
34
49template<VertexConcept T>
51{
52 template<VertexConcept U>
53 friend class VertexContainer;
54
57
58public:
59 using Vertex = T;
60 using VertexType = T;
61 using VertexIterator = Base::ElementIterator;
62 using ConstVertexIterator = Base::ConstElementIterator;
63
67 VertexContainer() = default;
68
80 const VertexType& vertex(uint i) const { return Base::element(i); }
81
92 VertexType& vertex(uint i) { return Base::element(i); }
93
103 uint vertexNumber() const { return Base::elementNumber(); }
104
114 uint vertexContainerSize() const { return Base::elementContainerSize(); }
115
122 uint deletedVertexNumber() const { return Base::deletedElementNumber(); }
123
134 uint addVertex() { return Base::addElement(); }
135
147 uint addVertex(const typename T::CoordType& p)
148 {
149 uint vid = addVertex();
150 vertex(vid).coord() = p; // set the coordinate to the vertex
151 return vid;
152 }
153
168 uint addVertices(uint n) { return Base::addElements(n); }
169
192 template<typename... VC>
193 uint addVertices(const typename T::CoordType& p, const VC&... v)
194 {
196 // reserve the new number of vertices
197 reserveVertices(vid + sizeof...(VC) + 1);
198 addVertex(p);
199 // pack expansion: will be translated at compile time as an addVertex()
200 // call for each argument of the addVertices member function
201 (addVertex(v), ...);
202 return vid;
203 }
204
216 template<vcl::Range R>
218 {
220 reserveVertices(vid + std::ranges::size(range));
221 for (const auto& v : range) {
222 addVertex(v);
223 }
224 return vid;
225 }
226
243 void clearVertices() { Base::clearElements(); }
244
273 void resizeVertices(uint n) { Base::resizeElements(n); }
274
293 void reserveVertices(uint n) { Base::reserveElements(n); }
294
301 void compactVertices() { Base::compactElements(); }
302
315 void deleteVertex(uint i) { Base::deleteElement(i); }
316
330 void deleteVertex(const VertexType* v) { Base::deleteElement(v); }
331
346 {
347 return Base::elementIndexIfCompact(i);
348 }
349
361 std::vector<uint> vertexCompactIndices() const
362 {
363 return Base::elementCompactIndices();
364 }
365
390 void updateVertexIndices(const std::vector<uint>& newIndices)
391 {
392 Base::updateElementIndices(newIndices);
393 }
394
406 VertexIterator vertexBegin(bool jumpDeleted = true)
407 {
408 return Base::elementBegin(jumpDeleted);
409 }
410
415 VertexIterator vertexEnd() { return Base::elementEnd(); }
416
428 ConstVertexIterator vertexBegin(bool jumpDeleted = true) const
429 {
430 return Base::elementBegin(jumpDeleted);
431 }
432
437 ConstVertexIterator vertexEnd() const { return Base::elementEnd(); }
438
462 auto vertices(bool jumpDeleted = true)
463 {
464 return Base::elements(jumpDeleted);
465 }
466
490 auto vertices(bool jumpDeleted = true) const
491 {
492 return Base::elements(jumpDeleted);
493 }
494
500 {
501 Base::enableAllOptionalComponents();
502 }
503
509 {
510 Base::disableAllOptionalComponents();
511 }
512
513 // Adjacent Edges
514
524 requires vert::HasOptionalAdjacentEdges<T>
525 {
526 return Base::template isOptionalComponentEnabled<
527 typename T::AdjacentEdges>();
528 }
529
537 requires vert::HasOptionalAdjacentEdges<T>
538 {
540 }
541
549 requires vert::HasOptionalAdjacentEdges<T>
550 {
552 }
553
554 // Adjacent Faces
555
565 requires vert::HasOptionalAdjacentFaces<T>
566 {
567 return Base::template isOptionalComponentEnabled<
568 typename T::AdjacentFaces>();
569 }
570
578 requires vert::HasOptionalAdjacentFaces<T>
579 {
581 }
582
590 requires vert::HasOptionalAdjacentFaces<T>
591 {
593 }
594
595 // Adjacent Vertices
596
608 requires vert::HasOptionalAdjacentVertices<T>
609 {
610 return Base::template isOptionalComponentEnabled<
611 typename T::AdjacentVertices>();
612 }
613
621 requires vert::HasOptionalAdjacentVertices<T>
622 {
624 }
625
633 requires vert::HasOptionalAdjacentVertices<T>
634 {
636 }
637
638 // Color
639
648 bool isPerVertexColorEnabled() const requires vert::HasOptionalColor<T>
649 {
650 return Base::template isOptionalComponentEnabled<typename T::Color>();
651 }
652
659 void enablePerVertexColor() requires vert::HasOptionalColor<T>
660 {
661 return Base::template enableOptionalComponent<typename T::Color>();
662 }
663
670 void disablePerVertexColor() requires vert::HasOptionalColor<T>
671 {
673 }
674
675 // Mark
676
685 bool isPerVertexMarkEnabled() const requires vert::HasOptionalMark<T>
686 {
687 return Base::template isOptionalComponentEnabled<typename T::Mark>();
688 }
689
696 void enablePerVertexMark() requires vert::HasOptionalMark<T>
697 {
699 }
700
708 void disablePerVertexMark() requires vert::HasOptionalMark<T>
709 {
711 }
712
713 // Normal
714
723 bool isPerVertexNormalEnabled() const requires vert::HasOptionalNormal<T>
724 {
726 }
727
734 void enablePerVertexNormal() requires vert::HasOptionalNormal<T>
735 {
737 }
738
745 void disablePerVertexNormal() requires vert::HasOptionalNormal<T>
746 {
748 }
749
750 // PrincipalCurvature
751
762 requires vert::HasOptionalPrincipalCurvature<T>
763 {
764 return Base::template isOptionalComponentEnabled<
765 typename T::PrincipalCurvature>();
766 }
767
775 requires vert::HasOptionalPrincipalCurvature<T>
776 {
777 Base::template enableOptionalComponent<
778 typename T::PrincipalCurvature>();
779 }
780
788 requires vert::HasOptionalPrincipalCurvature<T>
789 {
790 Base::template disableOptionalComponent<
791 typename T::PrincipalCurvature>();
792 }
793
794 // Quality
795
804 bool isPerVertexQualityEnabled() const requires vert::HasOptionalQuality<T>
805 {
807 }
808
815 void enablePerVertexQuality() requires vert::HasOptionalQuality<T>
816 {
818 }
819
826 void disablePerVertexQuality() requires vert::HasOptionalQuality<T>
827 {
829 }
830
831 // TexCoord
832
842 requires vert::HasOptionalTexCoord<T>
843 {
844 return Base::template isOptionalComponentEnabled<
845 typename T::TexCoord>();
846 }
847
854 void enablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
855 {
857 }
858
865 void disablePerVertexTexCoord() requires vert::HasOptionalTexCoord<T>
866 {
868 }
869
870 // Custom Components
871
884 bool hasPerVertexCustomComponent(const std::string& name) const
886 {
887 return Base::hasElemCustomComponent(name);
888 }
889
900 std::vector<std::string> perVertexCustomComponentNames() const
902 {
903 return Base::elemCustomComponentNames();
904 }
905
929 template<typename K>
930 bool isPerVertexCustomComponentOfType(const std::string& name) const
932 {
933 return Base::template isElemCustomComponentOfType<K>(name);
934 }
935
951 std::type_index perVertexCustomComponentType(const std::string& name) const
953 {
954 return Base::elemComponentType(name);
955 }
956
976 template<typename K>
979 {
980 return Base::template elemCustomComponentNamesOfType<K>();
981 }
982
993 template<typename K>
994 void addPerVertexCustomComponent(const std::string& name)
996 {
997 Base::template addElemCustomComponent<K>(name);
998 }
999
1012 void deletePerVertexCustomComponent(const std::string& name)
1014 {
1015 Base::deleteElemCustomComponent(name);
1016 }
1017
1059 template<typename K>
1061 const std::string& name) requires vert::HasCustomComponents<T>
1062 {
1063 return Base::template customComponentVectorHandle<K>(name);
1064 }
1065
1110 template<typename K>
1112 const std::string& name) const requires vert::HasCustomComponents<T>
1113 {
1114 return Base::template customComponentVectorHandle<K>(name);
1115 }
1116};
1117
1118} // namespace vcl::mesh
1119
1120#endif // VCL_MESH_CONTAINERS_VERTEX_CONTAINER_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition element.h:44
The Vertex Container class, will be used when the template argument given to the Mesh is a Vertex.
Definition vertex_container.h:51
uint addVertices(R &&range)
Add an arbitrary number of vertices with the coordinates contained in the given range,...
Definition vertex_container.h:217
void disablePerVertexPrincipalCurvature()
Disables the Optional PrincipalCurvature of the vertex.
Definition vertex_container.h:787
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:390
void disablePerVertexTexCoord()
Disables the Optional TexCoord of the vertex.
Definition vertex_container.h:865
auto vertices(bool jumpDeleted=true)
Returns a small utility object that allows to iterate over the vertices of the containers,...
Definition vertex_container.h:462
bool isPerVertexColorEnabled() const
Checks if the vertex Optional Color is enabled.
Definition vertex_container.h:648
void enablePerVertexAdjacentEdges()
Enables the Optional Adjacent Edges of the vertex.
Definition vertex_container.h:536
void deleteVertex(uint i)
Marks as deleted the vertex with the given id.
Definition vertex_container.h:315
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:92
void clearVertices()
Clears the Vertex container of the Mesh, deleting all the vertices.
Definition vertex_container.h:243
bool isPerVertexQualityEnabled() const
Checks if the vertex Optional Quality is enabled.
Definition vertex_container.h:804
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:490
uint addVertex(const typename T::CoordType &p)
Add a new vertex with the given coordinate into the vertex container, returning the id of the added v...
Definition vertex_container.h:147
void disablePerVertexQuality()
Disables the Optional Quality of the vertex.
Definition vertex_container.h:826
ConstVertexIterator vertexEnd() const
Returns a const iterator to the end of the container.
Definition vertex_container.h:437
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:900
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:1111
void disablePerVertexAdjacentFaces()
Disables the Optional Adjacent Faces of the vertex.
Definition vertex_container.h:589
void disablePerVertexNormal()
Checks if the vertex Optional PrincipalCurvature is enabled.
Definition vertex_container.h:745
uint addVertices(const typename T::CoordType &p, const VC &... v)
Add an arbitrary number of vertices with the given coordinates, returning the id of the first added v...
Definition vertex_container.h:193
void resizeVertices(uint n)
Resizes the Vertex container to contain n vertices.
Definition vertex_container.h:273
void compactVertices()
Compacts the Vertex Container, removing all the vertices marked as deleted. Vertices indices will cha...
Definition vertex_container.h:301
bool hasPerVertexCustomComponent(const std::string &name) const
Checks if vertices have a custom component with the given name.
Definition vertex_container.h:884
void deletePerVertexCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Vertex Element.
Definition vertex_container.h:1012
void enablePerVertexColor()
Enables the Optional Color of the vertex.
Definition vertex_container.h:659
uint vertexNumber() const
Returns the number of non-deleted vertices contained in the Vertex container of the Mesh.
Definition vertex_container.h:103
ConstVertexIterator vertexBegin(bool jumpDeleted=true) const
Returns a const iterator to the beginning of the container.
Definition vertex_container.h:428
void addPerVertexCustomComponent(const std::string &name)
Adds a custom component of type K to the Vertex, having the given name.
Definition vertex_container.h:994
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:345
void disableAllPerVertexOptionalComponents()
Disables all the optional components associated to the Vertex type contained in the VertexContainer.
Definition vertex_container.h:508
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:1060
uint addVertices(uint n)
Add an arbitrary number of n vertices, returning the id of the first added vertex.
Definition vertex_container.h:168
bool isPerVertexAdjacentVerticesEnabled() const
Checks if the vertex Optional Adjacent Vertices component is enabled.
Definition vertex_container.h:607
void enablePerVertexPrincipalCurvature()
Enables the Optional PrincipalCurvature of the vertex.
Definition vertex_container.h:774
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:951
uint addVertex()
Add a new vertex into the vertex container, returning the index of the added vertex.
Definition vertex_container.h:134
bool isPerVertexPrincipalCurvatureEnabled() const
Checks if the vertex Optional PrincipalCurvature is enabled.
Definition vertex_container.h:761
void enablePerVertexTexCoord()
Enables the Optional TexCoord of the vertex.
Definition vertex_container.h:854
void enablePerVertexAdjacentVertices()
Enables the Optional Adjacent Vertices of the vertex.
Definition vertex_container.h:620
bool isPerVertexAdjacentEdgesEnabled() const
Checks if the vertex Optional Adjacent Edges component is enabled.
Definition vertex_container.h:523
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:977
void enablePerVertexNormal()
Enables the Optional Normal of the vertex.
Definition vertex_container.h:734
uint vertexContainerSize() const
Returns the number of vertices (also deleted) contained in the Vertex container of the Mesh.
Definition vertex_container.h:114
void disablePerVertexAdjacentEdges()
Disables the Optional Adjacent Edges of the vertex.
Definition vertex_container.h:548
void enablePerVertexMark()
Enables the Optional Mark of the vertex.
Definition vertex_container.h:696
VertexIterator vertexBegin(bool jumpDeleted=true)
Returns an iterator to the beginning of the container.
Definition vertex_container.h:406
bool isPerVertexAdjacentFacesEnabled() const
Checks if the vertex Optional Adjacent Faces component is enabled.
Definition vertex_container.h:564
void enablePerVertexAdjacentFaces()
Enables the Optional Adjacent Faces of the vertex.
Definition vertex_container.h:577
void disablePerVertexAdjacentVertices()
Disables the Optional Adjacent Vertices of the vertex.
Definition vertex_container.h:632
void disablePerVertexMark()
Container::disableVertexMark disables the Optional Mark of the vertex.
Definition vertex_container.h:708
void disablePerVertexColor()
Disables the Optional Color of the vertex.
Definition vertex_container.h:670
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:293
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:841
void enableAllPerVertexOptionalComponents()
Enables all the optional components associated to the Vertex type contained in the VertexContainer.
Definition vertex_container.h:499
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:930
VertexIterator vertexEnd()
Returns an iterator to the end of the container.
Definition vertex_container.h:415
bool isPerVertexNormalEnabled() const
Checks if the vertex Optional Normal is enabled.
Definition vertex_container.h:723
bool isPerVertexMarkEnabled() const
Checks if the vertex Optional Mark is enabled.
Definition vertex_container.h:685
uint deletedVertexNumber() const
Returns the number of deleted vertices in the Vertex container, that is vertexContainerSize() - verte...
Definition vertex_container.h:122
void enablePerVertexQuality()
Enables the Optional Quality of the vertex.
Definition vertex_container.h:815
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:361
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:80
void deleteVertex(const VertexType *v)
Marks as deleted the given vertex, before asserting that the vertex belongs to this container.
Definition vertex_container.h:330
Utility concept that is evaluated true the Range R has a value_type that is exactly T.
Definition range.h:66
Definition per_mesh.h:39
Definition vertex.h:66