Visual Computing Library  devel
Loading...
Searching...
No Matches
adjacent_edges.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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_COMPONENTS_ADJACENT_EDGES_H
24#define VCL_MESH_COMPONENTS_ADJACENT_EDGES_H
25
26#include "base/predicates.h"
27#include "base/reference_container_component.h"
28
29#include <vclib/base.h>
30
31namespace vcl::comp {
32
79template<
80 bool STORE_INDICES,
81 typename Edge,
82 int N,
83 bool TTVC,
84 typename ParentElemType = void,
85 bool VERT = false,
86 bool OPT = false>
88 public ReferenceContainerComponent<
89 STORE_INDICES,
90 AdjacentEdges<
91 STORE_INDICES,
92 Edge,
93 N,
94 TTVC,
95 ParentElemType,
96 VERT,
97 OPT>,
98 CompId::ADJACENT_EDGES,
99 Edge,
100 N,
101 ParentElemType,
102 VERT,
103 OPT,
104 TTVC>
105{
106 using Base = ReferenceContainerComponent<
109 CompId::ADJACENT_EDGES,
110 Edge,
111 N,
113 VERT,
114 OPT,
115 TTVC>;
116
117public:
122
123 /* Iterator Types declaration */
124
125 using AdjacentEdgeIterator = Base::Iterator;
126 using ConstAdjacentEdgeIterator = Base::ConstIterator;
127 using ConstAdjacentEdgeIndexIterator = Base::ConstIndexIterator;
128
134 static const int ADJ_EDGE_COUNT = Base::SIZE;
135
136 /* Constructors */
137
144 AdjacentEdges() = default;
145
146 /* Member functions */
147
152 uint adjEdgeCount() const { return Base::size(); }
153
161 Edge* adjEdge(uint i) { return Base::element(i); }
162
169 const Edge* adjEdge(uint i) const { return Base::element(i); }
170
177 uint adjEdgeIndex(uint i) const { return Base::elementIndex(i); }
178
199 Edge* adjEdgeMod(int i) { return Base::elementMod(i); }
200
209 const Edge* adjEdgeMod(int i) const { return Base::elementMod(i); }
210
231
238 void setAdjEdge(uint i, Edge* e) { Base::setElement(i, e); }
239
247 void setAdjEdge(uint i, uint ei) { Base::setElement(i, ei); }
248
255 void setAdjEdge(ConstAdjacentEdgeIterator it, Edge* e)
256 {
257 Base::setElement(it, e);
258 }
259
266 void setAdjEdge(ConstAdjacentEdgeIterator it, uint ei)
267 {
268 Base::setElement(it, ei);
269 }
270
277 void setAdjEdge(ConstAdjacentEdgeIndexIterator it, Edge* e)
278 {
279 Base::setElement(it, e);
280 }
281
288 void setAdjEdge(ConstAdjacentEdgeIndexIterator it, uint ei)
289 {
290 Base::setElement(it, ei);
291 }
292
312 void setAdjEdgeMod(int i, Edge* e) { Base::setElementMod(i, e); }
313
334
346 template<Range Rng>
348 {
350 }
351
363 template<Range Rng>
365 {
367 }
368
377 bool containsAdjEdge(const Edge* e) const
378 {
379 return Base::containsElement(e);
380 }
381
391
401 uint indexOfAdjEdge(const Edge* e) const { return Base::indexOfElement(e); }
402
413
414 /* Member functions specific for dynamic vector of adjacent edges */
415
422 void resizeAdjEdges(uint n) requires (N < 0 && !TTVC) { Base::resize(n); }
423
431 void pushAdjEdge(Edge* e) requires (N < 0 && !TTVC) { Base::pushBack(e); }
432
440 void pushAdjEdge(uint ei) requires (N < 0 && !TTVC) { Base::pushBack(ei); }
441
452 void insertAdjEdge(uint i, Edge* e) requires (N < 0 && !TTVC)
453 {
454 Base::insert(i, e);
455 }
456
466 void insertAdjEdge(uint i, uint ei) requires (N < 0 && !TTVC)
467 {
468 Base::insert(i, ei);
469 }
470
479 void eraseAdjEdge(uint i) requires (N < 0 && !TTVC) { Base::erase(i); }
480
486 void clearAdjEdges() requires (N < 0 && !TTVC) { Base::clear(); }
487
488 /* Iterator Member functions */
489
496 AdjacentEdgeIterator adjEdgeBegin() { return Base::elementBegin(); }
497
504 AdjacentEdgeIterator adjEdgeEnd() { return Base::elementEnd(); }
505
512 ConstAdjacentEdgeIterator adjEdgeBegin() const
513 {
514 return Base::elementBegin();
515 }
516
523 ConstAdjacentEdgeIterator adjEdgeEnd() const { return Base::elementEnd(); }
524
531 ConstAdjacentEdgeIndexIterator adjEdgeIndexBegin() const
532 {
534 }
535
541 ConstAdjacentEdgeIndexIterator adjEdgeIndexEnd() const
542 {
543 return Base::elementIndexEnd();
544 }
545
562 View<AdjacentEdgeIterator> adjEdges() { return Base::elements(); }
563
581 {
582 return Base::elements();
583 }
584
605
606protected:
607 // Component interface functions
608 template<typename Element>
609 void importFrom(const Element& e, bool importRefs = true);
610
611 void serialize(std::ostream& os) const
612 {
613 // regardless of the type of the container (indices or pointers), the
614 // serialization is always done using the indices
615 if constexpr (N < 0) {
616 vcl::serialize(os, adjEdgeCount());
617 }
618 for (uint i = 0; i < adjEdgeCount(); ++i) {
619 vcl::serialize(os, adjEdgeIndex(i));
620 }
621 }
622
623 void deserialize(std::istream& is)
624 {
625 if constexpr (N < 0) {
626 uint n;
627 vcl::deserialize(is, n);
628 Base::resize(n);
629 }
630 for (uint i = 0; i < adjEdgeCount(); ++i) {
631 uint aei;
632 vcl::deserialize(is, aei);
633 setAdjEdge(i, aei);
634 }
635 }
636
637private:
638 template<typename Element>
639 void importIndicesFrom(const Element& e)
640 {
641 for (uint i = 0; i < e.adjEdgeCount(); ++i) {
642 setAdjEdge(i, e.adjEdgeIndex(i));
643 }
644 }
645};
646
647/* concepts */
648
666template<typename T>
668 BTIBTBB::IsDerivedFromSpecializationOfV<T, AdjacentEdges>;
669
680template<typename T>
684
696template<typename T>
699 RemoveRef<T>::VERTEX_COUNT == RemoveRef<T>::ADJ_EDGE_COUNT;
700
713template<typename T>
716
717/* importFrom function */
718
719template<
720 bool STORE_INDICES,
721 typename Edge,
722 int N,
723 bool TTVC,
724 typename ParentElemType,
725 bool VERT,
726 bool OPT>
727template<typename Element>
728void AdjacentEdges<STORE_INDICES, Edge, N, TTVC, ParentElemType, VERT, OPT>::
729 importFrom(const Element& e, bool importRefs)
730{
731 if (importRefs) {
732 if constexpr (HasAdjacentEdges<Element>) {
733 if (isAdjacentEdgesAvailableOn(e)) {
734 if constexpr (N > 0) {
735 // same static size
736 if constexpr (N == Element::ADJ_EDGE_COUNT) {
737 importIndicesFrom(e);
738 }
739 // from dynamic to static, but dynamic size == static size
740 else if constexpr (Element::ADJ_EDGE_COUNT < 0) {
741 if (e.adjEdgeCount() == N) {
742 importIndicesFrom(e);
743 }
744 }
745 else {
746 // do not import in this case: cannot import from
747 // dynamic size != static size
748 }
749 }
750 else {
751 // from static/dynamic to dynamic size: need to resize
752 // first, then import
753 Base::resize(e.adjEdgeCount());
754 importIndicesFrom(e);
755 }
756 }
757 }
758 }
759}
760
761/* Detector function to check if a class has AdjacentEdges available */
762
773bool isAdjacentEdgesAvailableOn(const auto& element)
774{
776}
777
778} // namespace vcl::comp
779
780#endif // VCL_MESH_COMPONENTS_ADJACENT_EDGES_H
The Edge class represents an Edge element of the vcl::Mesh class.
Definition edge.h:47
The Element class.
Definition element.h:75
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
Segment()
Default constructor. Creates a segment with endpoints at the origin.
Definition segment.h:66
The AdjacentEdges class is a container of Edge indices or pointers. It could be used by any Element t...
Definition adjacent_edges.h:105
uint indexOfAdjEdge(uint ei) const
Returns the index of the adjacent edge with the given index in the container of the element....
Definition adjacent_edges.h:412
AdjacentEdgeIterator adjEdgeBegin()
Returns an iterator to the first adjacent edge in the container of this component.
Definition adjacent_edges.h:496
void setAdjEdge(ConstAdjacentEdgeIterator it, Edge *e)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:255
AdjacentEdgeIterator adjEdgeEnd()
Returns an iterator to the end of the container of this component.
Definition adjacent_edges.h:504
bool containsAdjEdge(uint ei) const
Returns true if the container of adjacent edges contains the given index, false otherwise.
Definition adjacent_edges.h:390
void clearAdjEdges()
Clears the container of adjacent edges, making it empty.
Definition adjacent_edges.h:486
AdjacentEdges()=default
Empty constructor.
uint indexOfAdjEdge(const Edge *e) const
Returns the index of the given adjacent edge in the container of the element. If the given adjacent e...
Definition adjacent_edges.h:401
View< ConstAdjacentEdgeIndexIterator > adjEdgeIndices() const
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_edges.h:601
void setAdjEdges(Rng &&r)
Sets all the adjacent edges of the element.
Definition adjacent_edges.h:364
void setAdjEdge(ConstAdjacentEdgeIndexIterator it, Edge *e)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:277
static const int ADJ_EDGE_COUNT
Static size of the container. If the container is dynamic, this value will be negative and you should...
Definition adjacent_edges.h:134
View< AdjacentEdgeIterator > adjEdges()
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_edges.h:562
const Edge * adjEdge(uint i) const
Returns a const pointer to the i-th adjacent edge of the element.
Definition adjacent_edges.h:169
void setAdjEdgeMod(int i, uint ei)
Sets the i-th adjacent edge of the element, but using as index the module between i and the number of...
Definition adjacent_edges.h:333
const Edge * adjEdgeMod(int i) const
Same of adjEdgeMod, but returns a const Pointer to the adjacent edge.
Definition adjacent_edges.h:209
ConstAdjacentEdgeIndexIterator adjEdgeIndexEnd() const
Returns an iterator to the end of the container of this component.
Definition adjacent_edges.h:541
void setAdjEdge(uint i, Edge *e)
Sets the i-th adjacent edge of the element.
Definition adjacent_edges.h:238
uint adjEdgeCount() const
Returns the number of adjacent edges of this element.
Definition adjacent_edges.h:152
ConstAdjacentEdgeIterator adjEdgeBegin() const
Returns a const iterator to the first adjacent edge in the container of this component.
Definition adjacent_edges.h:512
void setAdjEdges(Rng &&r)
Sets all the adjacent edges of the element.
Definition adjacent_edges.h:347
void insertAdjEdge(uint i, Edge *e)
Inserts the given adjacent edge in the container at the given position.
Definition adjacent_edges.h:452
bool containsAdjEdge(const Edge *e) const
Returns true if the container of adjacent edges contains the given edge, false otherwise.
Definition adjacent_edges.h:377
uint adjEdgeIndex(uint i) const
Returns the index in the edge container of the i-th adjacent edge of the element.
Definition adjacent_edges.h:177
ConstAdjacentEdgeIterator adjEdgeEnd() const
Returns a const iterator to the end of the container of this component.
Definition adjacent_edges.h:523
void resizeAdjEdges(uint n)
Resize the container of the adjacent edges to the given size.
Definition adjacent_edges.h:422
void setAdjEdge(uint i, uint ei)
Sets the i-th adjacent edge of the element.
Definition adjacent_edges.h:247
Edge * adjEdge(uint i)
Returns the pointer to the i-th adjacent edge of the element.
Definition adjacent_edges.h:161
void setAdjEdgeMod(int i, Edge *e)
Sets the i-th adjacent edge of the element, but using as index the module between i and the number of...
Definition adjacent_edges.h:312
Edge * adjEdgeMod(int i)
Returns the pointer to the i-th adjacent edge of the element but using as index the module between i ...
Definition adjacent_edges.h:199
void pushAdjEdge(uint ei)
Pushes in the back of the container the given adjacent edge.
Definition adjacent_edges.h:440
void setAdjEdge(ConstAdjacentEdgeIterator it, uint ei)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:266
void pushAdjEdge(Edge *e)
Pushes in the back of the container the given adjacent edge.
Definition adjacent_edges.h:431
View< ConstAdjacentEdgeIterator > adjEdges() const
Returns a lightweight const view object that stores the begin and end iterators of the container of a...
Definition adjacent_edges.h:580
void eraseAdjEdge(uint i)
Removes the adjacent edge at the given position from the container.
Definition adjacent_edges.h:479
void insertAdjEdge(uint i, uint ei)
Inserts the adjacent edge with the given index in the container at the given position.
Definition adjacent_edges.h:466
uint adjEdgeIndexMod(int i) const
Returns the index in the edge container of the i-th adjacent edge of the element, but using as index ...
Definition adjacent_edges.h:230
ConstAdjacentEdgeIndexIterator adjEdgeIndexBegin() const
Returns an iterator to the first adjacent edge index in the container of this component.
Definition adjacent_edges.h:531
void setAdjEdge(ConstAdjacentEdgeIndexIterator it, uint ei)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:288
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:99
A concept that checks whether a type T (that should be a Element) has the AdjacentEdges component (in...
Definition adjacent_edges.h:667
A concept that checks whether a type T (that should be a Element) has the AdjacentEdges component (in...
Definition adjacent_edges.h:681
HasRightNumberOfAdjacentEdges concept.
Definition adjacent_edges.h:697
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74
Evaluates to true if the type T is tied to the number of vertices in the face.
Definition component.h:126
SanityCheckAdjacentEdges concept.
Definition adjacent_edges.h:714