Visual Computing Library
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 "element_container.h"
27
28#include <vclib/mesh/containers/custom_component_vector_handle.h>
29#include <vclib/mesh/elements/edge.h>
30#include <vclib/mesh/elements/edge_components.h>
31
32namespace vcl::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
455 auto edges(bool jumpDeleted = true) const
456 {
457 return Base::elements(jumpDeleted);
458 }
459
465 {
466 Base::enableAllOptionalComponents();
467 }
468
474 {
475 Base::disableAllOptionalComponents();
476 }
477
478 // AdjacentEdges
479
489 requires edge::HasOptionalAdjacentEdges<T>
490 {
491 return Base::template isOptionalComponentEnabled<
492 typename T::AdjacentEdges>();
493 }
494
501 void enablePerEdgeAdjacentEdges() requires edge::HasOptionalAdjacentEdges<T>
502 {
504 }
505
513 requires edge::HasOptionalAdjacentEdges<T>
514 {
516 }
517
518 // AdjacentFaces
519
529 requires edge::HasOptionalAdjacentFaces<T>
530 {
531 return Base::template isOptionalComponentEnabled<
532 typename T::AdjacentFaces>();
533 }
534
541 void enablePerEdgeAdjacentFaces() requires edge::HasOptionalAdjacentFaces<T>
542 {
544 }
545
553 requires edge::HasOptionalAdjacentFaces<T>
554 {
556 }
557
558 // Color
559
568 bool isPerEdgeColorEnabled() const requires edge::HasOptionalColor<T>
569 {
570 return Base::template isOptionalComponentEnabled<typename T::Color>();
571 }
572
579 void enablePerEdgeColor() requires edge::HasOptionalColor<T>
580 {
582 }
583
590 void disablePerEdgeColor() requires edge::HasOptionalColor<T>
591 {
593 }
594
595 // Mark
596
605 bool isPerEdgeMarkEnabled() const requires edge::HasOptionalMark<T>
606 {
607 return Base::template isOptionalComponentEnabled<typename T::Mark>();
608 }
609
616 void enablePerEdgeMark() requires edge::HasOptionalMark<T>
617 {
619 }
620
627 void disablePerEdgeMark() requires edge::HasOptionalMark<T>
628 {
630 }
631
632 // Quality
633
642 bool isPerEdgeQualityEnabled() const requires edge::HasOptionalQuality<T>
643 {
645 }
646
653 void enablePerEdgeQuality() requires edge::HasOptionalQuality<T>
654 {
656 }
657
664 void disablePerEdgeQuality() requires edge::HasOptionalQuality<T>
665 {
667 }
668
669 // Custom Components
670
683 bool hasPerEdgeCustomComponent(const std::string& name) const
685 {
686 return Base::hasElemCustomComponent(name);
687 }
688
699 std::vector<std::string> perEdgeCustomComponentNames() const
701 {
702 return Base::elemCustomComponentNames();
703 }
704
730 template<typename K>
731 bool isPerEdgeCustomComponentOfType(const std::string& name) const
733 {
734 return Base::template isElemCustomComponentOfType<K>(name);
735 }
736
752 std::type_index perEdgeCustomComponentType(const std::string& name) const
754 {
755 return Base::elemComponentType(name);
756 }
757
777 template<typename K>
778 std::vector<std::string> perEdgeCustomComponentNamesOfType() const
780 {
781 return Base::template elemCustomComponentNamesOfType<K>();
782 }
783
794 template<typename K>
795 void addPerEdgeCustomComponent(const std::string& name)
797 {
798 Base::template addElemCustomComponent<K>(name);
799 }
800
813 void deletePerEdgeCustomComponent(const std::string& name)
815 {
816 Base::deleteElemCustomComponent(name);
817 }
818
860 template<typename K>
862 const std::string& name) requires edge::HasCustomComponents<T>
863 {
864 return Base::template customComponentVectorHandle<K>(name);
865 }
866
909 template<typename K>
911 const std::string& name) const requires edge::HasCustomComponents<T>
912 {
913 return Base::template customComponentVectorHandle<K>(name);
914 }
915};
916
917} // namespace vcl::mesh
918
919#endif // VCL_MESH_CONTAINERS_EDGE_CONTAINER_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
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:731
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:699
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:455
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
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:473
bool isPerEdgeAdjacentFacesEnabled() const
Checks if the Edge Optional AdjacentFaces is enabled.
Definition edge_container.h:528
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:778
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 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:568
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:910
void enablePerEdgeColor()
Enable the Optional Color of the Edge.
Definition edge_container.h:579
void enablePerEdgeMark()
Enable the Optional Mark of the Edge.
Definition edge_container.h:616
void enableAllPerEdgeOptionalComponents()
Enables all the optional components associated to the Edge type contained in the EdgeContainer.
Definition edge_container.h:464
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:861
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:752
void disablePerEdgeAdjacentFaces()
Disables the Optional AdjacentFaces of the Edge.
Definition edge_container.h:552
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:590
void disablePerEdgeMark()
Disables the Optional Mark of the Edge.
Definition edge_container.h:627
void disablePerEdgeAdjacentEdges()
Disables the Optional AdjacentEdges of the Edge.
Definition edge_container.h:512
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:795
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:642
void enablePerEdgeAdjacentFaces()
Enable the Optional AdjacentFaces of the Edge.
Definition edge_container.h:541
bool hasPerEdgeCustomComponent(const std::string &name) const
Checks if Edges have a custom component with the given name.
Definition edge_container.h:683
bool isPerEdgeMarkEnabled() const
Checks if the Edge Optional Mark is enabled.
Definition edge_container.h:605
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:501
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:488
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:653
void disablePerEdgeQuality()
Disables the Optional Quality of the Edge.
Definition edge_container.h:664
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:813
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:44
Definition edge.h:62
Definition per_mesh.h:39