Visual Computing Library  devel
Loading...
Searching...
No Matches
edge_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_EDGE_CONTAINER_H
24#define VCL_MESH_CONTAINERS_EDGE_CONTAINER_H
25
26#include "base/element_container.h"
27
28#include <vclib/mesh/elements/edge.h>
29#include <vclib/mesh/elements/edge_components.h>
30
31namespace vcl {
32namespace mesh {
33
51template<EdgeConcept T>
53{
54 template<EdgeConcept U>
55 friend class EdgeContainer;
56
59
60public:
61 using Edge = T;
62 using EdgeType = T;
63 using EdgeIterator = Base::ElementIterator;
64 using ConstEdgeIterator = Base::ConstElementIterator;
65
69 EdgeContainer() = default;
70
82 const EdgeType& edge(uint i) const { return Base::element(i); }
83
95 EdgeType& edge(uint i) { return Base::element(i); }
96
106 uint edgeNumber() const { return Base::elementNumber(); }
107
117 uint edgeContainerSize() const { return Base::elementContainerSize(); }
118
125 uint deletedEdgeNumber() const { return Base::deletedElementNumber(); }
126
136 uint addEdge() { return Base::addElement(); }
137
151 {
152 uint eid = addEdge();
153 edge(eid).setVertex(0U, v0);
154 edge(eid).setVertex(1U, v1);
155 return eid;
156 }
157
170 uint addEdge(typename T::VertexType* v0, typename T::VertexType* v1)
171 {
172 uint eid = addEdge();
173 edge(eid).setVertex(0U, v0);
174 edge(eid).setVertex(1U, v1);
175 return eid;
176 }
177
192 uint addEdges(uint n) { return Base::addElements(n); }
193
210 void clearEdges() { Base::clearElements(); }
211
240 void resizeEdges(uint n) { Base::resizeElements(n); }
241
260 void reserveEdges(uint n) { Base::reserveElements(n); }
261
268 void compactEdges() { Base::compactElements(); }
269
282 void deleteEdge(uint i) { Base::deleteElement(i); }
283
297 void deleteEdge(const EdgeType* e) { Base::deleteElement(e); }
298
313 {
314 return Base::elementIndexIfCompact(i);
315 }
316
328 std::vector<uint> edgeCompactIndices() const
329 {
330 return Base::elementCompactIndices();
331 }
332
358 void updateEdgeIndices(const std::vector<uint>& newIndices)
359 {
360 Base::updateElementIndices(newIndices);
361 }
362
374 EdgeIterator edgeBegin(bool jumpDeleted = true)
375 {
376 return Base::elementBegin(jumpDeleted);
377 }
378
383 EdgeIterator edgeEnd() { return Base::elementEnd(); }
384
396 ConstEdgeIterator edgeBegin(bool jumpDeleted = true) const
397 {
398 return Base::elementBegin(jumpDeleted);
399 }
400
405 ConstEdgeIterator edgeEnd() const { return Base::elementEnd(); }
406
430 auto edges(bool jumpDeleted = true) { return Base::elements(jumpDeleted); }
431
456 auto edges(uint begin, uint end = UINT_NULL)
457 {
458 return Base::elements(begin, end);
459 }
460
484 auto edges(bool jumpDeleted = true) const
485 {
486 return Base::elements(jumpDeleted);
487 }
488
513 auto edges(uint begin, uint end = UINT_NULL) const
514 {
515 return Base::elements(begin, end);
516 }
517
523 {
524 Base::enableAllOptionalComponents();
525 }
526
532 {
533 Base::disableAllOptionalComponents();
534 }
535
536 // AdjacentEdges
537
547 requires edge::HasOptionalAdjacentEdges<T>
548 {
549 return Base::template isOptionalComponentEnabled<
550 typename T::AdjacentEdges>();
551 }
552
559 void enablePerEdgeAdjacentEdges() requires edge::HasOptionalAdjacentEdges<T>
560 {
562 }
563
571 requires edge::HasOptionalAdjacentEdges<T>
572 {
574 }
575
576 // AdjacentFaces
577
587 requires edge::HasOptionalAdjacentFaces<T>
588 {
589 return Base::template isOptionalComponentEnabled<
590 typename T::AdjacentFaces>();
591 }
592
599 void enablePerEdgeAdjacentFaces() requires edge::HasOptionalAdjacentFaces<T>
600 {
602 }
603
611 requires edge::HasOptionalAdjacentFaces<T>
612 {
614 }
615
616 // Color
617
626 bool isPerEdgeColorEnabled() const requires edge::HasOptionalColor<T>
627 {
628 return Base::template isOptionalComponentEnabled<typename T::Color>();
629 }
630
637 void enablePerEdgeColor() requires edge::HasOptionalColor<T>
638 {
640 }
641
648 void disablePerEdgeColor() requires edge::HasOptionalColor<T>
649 {
651 }
652
653 // Mark
654
663 bool isPerEdgeMarkEnabled() const requires edge::HasOptionalMark<T>
664 {
665 return Base::template isOptionalComponentEnabled<typename T::Mark>();
666 }
667
674 void enablePerEdgeMark() requires edge::HasOptionalMark<T>
675 {
677 }
678
685 void disablePerEdgeMark() requires edge::HasOptionalMark<T>
686 {
688 }
689
690 // Quality
691
700 bool isPerEdgeQualityEnabled() const requires edge::HasOptionalQuality<T>
701 {
703 }
704
711 void enablePerEdgeQuality() requires edge::HasOptionalQuality<T>
712 {
714 }
715
722 void disablePerEdgeQuality() requires edge::HasOptionalQuality<T>
723 {
725 }
726
727 // Custom Components
728
741 bool hasPerEdgeCustomComponent(const std::string& name) const
743 {
744 return Base::hasElemCustomComponent(name);
745 }
746
757 std::vector<std::string> perEdgeCustomComponentNames() const
759 {
760 return Base::elemCustomComponentNames();
761 }
762
788 template<typename K>
789 bool isPerEdgeCustomComponentOfType(const std::string& name) const
791 {
792 return Base::template isElemCustomComponentOfType<K>(name);
793 }
794
810 std::type_index perEdgeCustomComponentType(const std::string& name) const
812 {
813 return Base::elemComponentType(name);
814 }
815
835 template<typename K>
836 std::vector<std::string> perEdgeCustomComponentNamesOfType() const
838 {
839 return Base::template elemCustomComponentNamesOfType<K>();
840 }
841
852 template<typename K>
853 void addPerEdgeCustomComponent(const std::string& name)
855 {
856 Base::template addElemCustomComponent<K>(name);
857 }
858
871 void deletePerEdgeCustomComponent(const std::string& name)
873 {
874 Base::deleteElemCustomComponent(name);
875 }
876
918 template<typename K>
920 const std::string& name) requires edge::HasCustomComponents<T>
921 {
922 return Base::template customComponentVectorHandle<K>(name);
923 }
924
967 template<typename K>
969 const std::string& name) const requires edge::HasCustomComponents<T>
970 {
971 return Base::template customComponentVectorHandle<K>(name);
972 }
973
984 template<typename K>
990
1001 template<typename K>
1004 {
1006 }
1007};
1008
1009/* Concepts */
1010
1023template<typename T>
1024concept HasEdgeContainer = std::derived_from< // same type or derived type
1025 std::remove_cvref_t<T>,
1026 EdgeContainer<typename RemoveRef<T>::EdgeType>>;
1027
1028} // namespace mesh
1029
1063template<typename... Args>
1065
1066} // namespace vcl
1067
1068#endif // VCL_MESH_CONTAINERS_EDGE_CONTAINER_H
A class representing a box in N-dimensional space.
Definition box.h:46
The EdgeContainer class represents a container of Edge elements that can be used in a Mesh class.
Definition edge_container.h:53
bool isPerEdgeCustomComponentOfType(const std::string &name) const
Checks if the custom component of the Edge Element having the given name has the same type of the giv...
Definition edge_container.h:789
std::vector< std::string > perEdgeCustomComponentNames() const
Returns a vector containing all the names of the custom components of any type associated to the Edge...
Definition edge_container.h:757
EdgeIterator edgeEnd()
Returns an iterator to the end of the container.
Definition edge_container.h:383
auto edges(bool jumpDeleted=true) const
Returns a small view object that allows to iterate over the Edges of the containers,...
Definition edge_container.h:484
uint addEdge(uint v0, uint v1)
Add an Edge having the two given vertices to the container, returning its index.
Definition edge_container.h:150
void serializePerEdgeCustomComponentsOfType(std::ostream &os) const
Serializes in the given output stream all the custom components of the Edge Element of type K.
Definition edge_container.h:985
uint addEdge()
Add an Edge to the container, returning its index.
Definition edge_container.h:136
void disableAllPerEdgeOptionalComponents()
Disables all the optional components associated to the Edge type contained in the EdgeContainer.
Definition edge_container.h:531
bool isPerEdgeAdjacentFacesEnabled() const
Checks if the Edge Optional AdjacentFaces is enabled.
Definition edge_container.h:586
void clearEdges()
Clears the Edge container of the Mesh, deleting all the Edges.
Definition edge_container.h:210
auto edges(bool jumpDeleted=true)
Returns a small view object that allows to iterate over the Edges of the containers,...
Definition edge_container.h:430
std::vector< std::string > perEdgeCustomComponentNamesOfType() const
Returns a vector containing all the names of the custom components associated to the Edge Element hav...
Definition edge_container.h:836
const EdgeType & edge(uint i) const
Returns a const reference of the Edge at the i-th position in the Edge Container of the Mesh,...
Definition edge_container.h:82
void deserializePerEdgeCustomComponentsOfType(std::istream &is)
Deserializes in the given input stream all the custom components of the Edge Element of type K.
Definition edge_container.h:1002
void resizeEdges(uint n)
Resizes the Edge container to contain n Edges.
Definition edge_container.h:240
uint addEdge(typename T::VertexType *v0, typename T::VertexType *v1)
Add an Edge having the two given vertices to the container, returning its index.
Definition edge_container.h:170
bool isPerEdgeColorEnabled() const
Checks if the Edge Optional Color is enabled.
Definition edge_container.h:626
std::vector< uint > edgeCompactIndices() const
Returns a vector that tells, for each actual Edge index, the new index that the Edge would have in a ...
Definition edge_container.h:328
uint edgeContainerSize() const
Returns the number of Edges (also deleted) contained in the Edge container of the Mesh.
Definition edge_container.h:117
ConstCustomComponentVectorHandle< K > perEdgeCustomComponentVectorHandle(const std::string &name) const
Returns a const vector handle to the custom component having type K and the given name.
Definition edge_container.h:968
void enablePerEdgeColor()
Enable the Optional Color of the Edge.
Definition edge_container.h:637
void enablePerEdgeMark()
Enable the Optional Mark of the Edge.
Definition edge_container.h:674
void enableAllPerEdgeOptionalComponents()
Enables all the optional components associated to the Edge type contained in the EdgeContainer.
Definition edge_container.h:522
CustomComponentVectorHandle< K > perEdgeCustomComponentVectorHandle(const std::string &name)
Returns a vector handle to the custom component having the type K and the given name.
Definition edge_container.h:919
std::type_index perEdgeCustomComponentType(const std::string &name) const
Returns the std::type_index of the custom component of the Edge Element having the given input name.
Definition edge_container.h:810
void disablePerEdgeAdjacentFaces()
Disables the Optional AdjacentFaces of the Edge.
Definition edge_container.h:610
uint deletedEdgeNumber() const
Returns the number of deleted Edges in the Edge container, that is edgeContainerSize() - edgeNumber()...
Definition edge_container.h:125
void disablePerEdgeColor()
Disables the Optional Color of the Edge.
Definition edge_container.h:648
auto edges(uint begin, uint end=UINT_NULL)
Returns a view object that allows to iterate over the Edges of the container in the given range:
Definition edge_container.h:456
auto edges(uint begin, uint end=UINT_NULL) const
Returns a view object that allows to iterate over the Edges of the container in the given range:
Definition edge_container.h:513
void disablePerEdgeMark()
Disables the Optional Mark of the Edge.
Definition edge_container.h:685
void disablePerEdgeAdjacentEdges()
Disables the Optional AdjacentEdges of the Edge.
Definition edge_container.h:570
ConstEdgeIterator edgeEnd() const
Returns a const iterator to the end of the container.
Definition edge_container.h:405
void addPerEdgeCustomComponent(const std::string &name)
Adds a custom component of type K to the Edge, having the given name.
Definition edge_container.h:853
uint edgeNumber() const
Returns the number of non-deleted Edges contained in the Edge container of the Mesh.
Definition edge_container.h:106
void reserveEdges(uint n)
Reserve a number of Edges in the container of Edges. This is useful when you know (or you have an ide...
Definition edge_container.h:260
void deleteEdge(const EdgeType *e)
Marks as deleted the given Edge, before asserting that the Edge belongs to this container.
Definition edge_container.h:297
EdgeIterator edgeBegin(bool jumpDeleted=true)
Returns an iterator to the beginning of the container.
Definition edge_container.h:374
bool isPerEdgeQualityEnabled() const
Checks if the Edge Optional Quality is enabled.
Definition edge_container.h:700
void enablePerEdgeAdjacentFaces()
Enable the Optional AdjacentFaces of the Edge.
Definition edge_container.h:599
bool hasPerEdgeCustomComponent(const std::string &name) const
Checks if Edges have a custom component with the given name.
Definition edge_container.h:741
bool isPerEdgeMarkEnabled() const
Checks if the Edge Optional Mark is enabled.
Definition edge_container.h:663
ConstEdgeIterator edgeBegin(bool jumpDeleted=true) const
Returns a const iterator to the beginning of the container.
Definition edge_container.h:396
uint addEdges(uint n)
Add an arbitrary number of n Edges, returning the id of the first added Edge.
Definition edge_container.h:192
void enablePerEdgeAdjacentEdges()
Enable the Optional AdjacentEdges of the Edge.
Definition edge_container.h:559
void updateEdgeIndices(const std::vector< uint > &newIndices)
Updates all the indices and pointers of the Edges of this container that are stored in any container ...
Definition edge_container.h:358
uint edgeIndexIfCompact(uint i) const
This is an utility member function that returns the index of an element if the container would be com...
Definition edge_container.h:312
bool isPerEdgeAdjacentEdgesEnabled() const
Checks if the Edge Optional AdjacentEdges is enabled.
Definition edge_container.h:546
void deleteEdge(uint i)
Marks as deleted the Edge with the given id.
Definition edge_container.h:282
EdgeContainer()=default
Empty constructor that creates an empty container of Edges.
void enablePerEdgeQuality()
Enable the Optional Quality of the Edge.
Definition edge_container.h:711
void disablePerEdgeQuality()
Disables the Optional Quality of the Edge.
Definition edge_container.h:722
EdgeType & edge(uint i)
Returns a reference of the Edge at the i-th position in the Edge Container of the Mesh,...
Definition edge_container.h:95
void deletePerEdgeCustomComponent(const std::string &name)
Deletes the custom component of the given name from the Edge Element.
Definition edge_container.h:871
void compactEdges()
Compacts the EdgeContainer, removing all the Edges marked as deleted. Edges indices will change accor...
Definition edge_container.h:268
Definition element.h:64
HasEdges concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition edge_container.h:1064
Definition edge_components.h:77
Definition mesh_components.h:52
A concept that checks whether a class has (inherits from) an EdgeContainer class.
Definition edge_container.h:1024
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