Visual Computing Library
Loading...
Searching...
No Matches
adjacent_edges.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_COMPONENTS_ADJACENT_EDGES_H
24#define VCL_MESH_COMPONENTS_ADJACENT_EDGES_H
25
26#include "bases/reference_container_component.h"
27
28#include <vclib/concepts/mesh/components/adjacent_edges.h>
29#include <vclib/types/view.h>
30
31namespace vcl::comp {
32
79template<
80 bool STORE_INDICES,
81 typename Edge,
82 int N,
83 bool TTVN,
84 typename ParentElemType = void,
85 bool VERT = false,
86 bool OPT = false>
89 STORE_INDICES,
90 AdjacentEdges<
91 STORE_INDICES,
92 Edge,
93 N,
94 TTVN,
95 ParentElemType,
96 VERT,
97 OPT>,
98 CompId::ADJACENT_EDGES,
99 Edge,
100 N,
101 ParentElemType,
102 VERT,
103 OPT,
104 TTVN>
105{
109 CompId::ADJACENT_EDGES,
110 Edge,
111 N,
113 VERT,
114 OPT,
115 TTVN>;
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_NUMBER = Base::SIZE;
135
136 /* Constructors */
137
144 AdjacentEdges() = default;
145
146 /* Member functions */
147
152 uint adjEdgesNumber() 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 uint adjEdgeIndexMod(int i) const { return Base::elementIndexMod(i); }
232
239 void setAdjEdge(uint i, Edge* e) { Base::setElement(i, e); }
240
248 void setAdjEdge(uint i, uint ei) { Base::setElement(i, ei); }
249
256 void setAdjEdge(ConstAdjacentEdgeIterator it, Edge* e)
257 {
258 Base::setElement(it, e);
259 }
260
267 void setAdjEdge(ConstAdjacentEdgeIterator it, uint ei)
268 {
269 Base::setElement(it, ei);
270 }
271
278 void setAdjEdge(ConstAdjacentEdgeIndexIterator it, Edge* e)
279 {
280 Base::setElement(it, e);
281 }
282
289 void setAdjEdge(ConstAdjacentEdgeIndexIterator it, uint ei)
290 {
291 Base::setElement(it, ei);
292 }
293
313 void setAdjEdgeMod(int i, Edge* e) { Base::setElementMod(i, e); }
314
334 void setAdjEdgeMod(int i, uint ei) { Base::setElementMod(i, ei); }
335
347 template<Range Rng>
349 {
350 Base::setElements(r);
351 }
352
364 template<Range Rng>
366 {
367 Base::setElements(r);
368 }
369
378 bool containsAdjEdge(const Edge* e) const
379 {
380 return Base::containsElement(e);
381 }
382
391 bool containsAdjEdge(uint ei) const { return Base::containsElement(ei); }
392
402 uint indexOfAdjEdge(const Edge* e) const { return Base::indexOfElement(e); }
403
413 uint indexOfAdjEdge(uint ei) const { return Base::indexOfElement(ei); }
414
415 /* Member functions specific for dynamic vector of adjacent edges */
416
423 void resizeAdjEdges(uint n) requires (N < 0 && !TTVN) { Base::resize(n); }
424
432 void pushAdjEdge(Edge* e) requires (N < 0 && !TTVN) { Base::pushBack(e); }
433
441 void pushAdjEdge(uint ei) requires (N < 0 && !TTVN) { Base::pushBack(ei); }
442
453 void insertAdjEdge(uint i, Edge* e) requires (N < 0 && !TTVN)
454 {
455 Base::insert(i, e);
456 }
457
467 void insertAdjEdge(uint i, uint ei) requires (N < 0 && !TTVN)
468 {
469 Base::insert(i, ei);
470 }
471
480 void eraseAdjEdge(uint i) requires (N < 0 && !TTVN) { Base::erase(i); }
481
487 void clearAdjEdges() requires (N < 0 && !TTVN) { Base::clear(); }
488
489 /* Iterator Member functions */
490
497 AdjacentEdgeIterator adjEdgeBegin() { return Base::elementBegin(); }
498
505 AdjacentEdgeIterator adjEdgeEnd() { return Base::elementEnd(); }
506
513 ConstAdjacentEdgeIterator adjEdgeBegin() const
514 {
515 return Base::elementBegin();
516 }
517
524 ConstAdjacentEdgeIterator adjEdgeEnd() const { return Base::elementEnd(); }
525
532 ConstAdjacentEdgeIndexIterator adjEdgeIndexBegin() const
533 {
534 return Base::elementIndexBegin();
535 }
536
542 ConstAdjacentEdgeIndexIterator adjEdgeIndexEnd() const
543 {
544 return Base::elementIndexEnd();
545 }
546
563 View<AdjacentEdgeIterator> adjEdges() { return Base::elements(); }
564
582 {
583 return Base::elements();
584 }
585
603 {
604 return Base::elementIndices();
605 }
606
607protected:
608 // Component interface functions
609 template<typename Element>
610 void importFrom(const Element& e, bool importRefs = true)
611 {
612 if (importRefs) {
613 if constexpr (HasAdjacentEdges<Element>) {
614 if (isAdjacentEdgesAvailableOn(e)) {
615 if constexpr (N > 0) {
616 // same static size
617 if constexpr (N == Element::ADJ_EDGE_NUMBER) {
618 importIndicesFrom(e);
619 }
620 // from dynamic to static, but dynamic size == static
621 // size
622 else if constexpr (Element::ADJ_EDGE_NUMBER < 0) {
623 if (e.adjEdgesNumber() == N) {
624 importIndicesFrom(e);
625 }
626 }
627 else {
628 // do not import in this case: cannot import from
629 // dynamic size != static size
630 }
631 }
632 else {
633 // from static/dynamic to dynamic size: need to resize
634 // first, then import
635 Base::resize(e.adjEdgesNumber());
636 importIndicesFrom(e);
637 }
638 }
639 }
640 }
641 }
642
643 void serialize(std::ostream& os) const
644 {
645 // regardless of the type of the container (indices or pointers), the
646 // serialization is always done using the indices
647 if constexpr (N < 0) {
648 vcl::serialize(os, adjEdgesNumber());
649 }
650 for (uint i = 0; i < adjEdgesNumber(); ++i) {
651 vcl::serialize(os, adjEdgeIndex(i));
652 }
653 }
654
655 void deserialize(std::istream& is)
656 {
657 if constexpr (N < 0) {
658 uint n;
659 vcl::deserialize(is, n);
660 Base::resize(n);
661 }
662 for (uint i = 0; i < adjEdgesNumber(); ++i) {
663 uint aei;
664 vcl::deserialize(is, aei);
665 setAdjEdge(i, aei);
666 }
667 }
668
669private:
670 template<typename Element>
671 void importIndicesFrom(const Element& e)
672 {
673 for (uint i = 0; i < e.adjEdgesNumber(); ++i) {
674 setAdjEdge(i, e.adjEdgeIndex(i));
675 }
676 }
677};
678
679/* Detector function to check if a class has AdjacentEdges available */
680
692bool isAdjacentEdgesAvailableOn(const ElementConcept auto& element)
693{
694 return isComponentAvailableOn<CompId::ADJACENT_EDGES>(element);
695}
696
697} // namespace vcl::comp
698
699#endif // VCL_MESH_COMPONENTS_ADJACENT_EDGES_H
The Edge class represents an Edge element of the vcl::Mesh class.
Definition edge.h:48
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The AdjacentEdges class is a container of Edge indices or pointers. It could be used by any Element t...
Definition adjacent_edges.h:105
void setAdjEdge(ConstAdjacentEdgeIndexIterator it, uint ei)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:289
ConstAdjacentEdgeIndexIterator adjEdgeIndexBegin() const
Returns an iterator to the first adjacent edge index in the container of this component.
Definition adjacent_edges.h:532
AdjacentEdges()=default
Empty constructor.
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 setAdjEdge(uint i, uint ei)
Sets the i-th adjacent edge of the element.
Definition adjacent_edges.h:248
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
const Edge * adjEdgeMod(int i) const
Same of adjEdgeMod, but returns a const Pointer to the adjacent edge.
Definition adjacent_edges.h:209
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:467
void eraseAdjEdge(uint i)
Removes the adjacent edge at the given position from the container.
Definition adjacent_edges.h:480
ConstAdjacentEdgeIterator adjEdgeBegin() const
Returns a const iterator to the first adjacent edge in the container of this component.
Definition adjacent_edges.h:513
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 setAdjEdges(Rng &&r)
Sets all the adjacent edges of the element.
Definition adjacent_edges.h:348
View< AdjacentEdgeIterator > adjEdges()
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_edges.h:563
bool containsAdjEdge(uint ei) const
Returns true if the container of adjacent edges contains the given index, false otherwise.
Definition adjacent_edges.h:391
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:602
void pushAdjEdge(uint ei)
Pushes in the back of the container the given adjacent edge.
Definition adjacent_edges.h:441
void resizeAdjEdges(uint n)
Resize the container of the adjacent edges to the given size.
Definition adjacent_edges.h:423
AdjacentEdgeIterator adjEdgeBegin()
Returns an iterator to the first adjacent edge in the container of this component.
Definition adjacent_edges.h:497
ConstAdjacentEdgeIterator adjEdgeEnd() const
Returns a const iterator to the end of the container of this component.
Definition adjacent_edges.h:524
bool containsAdjEdge(const Edge *e) const
Returns true if the container of adjacent edges contains the given edge, false otherwise.
Definition adjacent_edges.h:378
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:581
static const int ADJ_EDGE_NUMBER
Static size of the container. If the container is dynamic, this value will be negative and you should...
Definition adjacent_edges.h:134
Edge * adjEdge(uint i)
Returns the pointer to the i-th adjacent edge of the element.
Definition adjacent_edges.h:161
void pushAdjEdge(Edge *e)
Pushes in the back of the container the given adjacent edge.
Definition adjacent_edges.h:432
void setAdjEdge(ConstAdjacentEdgeIterator it, Edge *e)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:256
void clearAdjEdges()
Clears the container of adjacent edges, making it empty.
Definition adjacent_edges.h:487
void setAdjEdges(Rng &&r)
Sets all the adjacent edges of the element.
Definition adjacent_edges.h:365
void setAdjEdge(ConstAdjacentEdgeIterator it, uint ei)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:267
uint adjEdgesNumber() const
Returns the number of adjacent edges of this element.
Definition adjacent_edges.h:152
void setAdjEdge(ConstAdjacentEdgeIndexIterator it, Edge *e)
Sets the adjacent edge pointed by the iterator.
Definition adjacent_edges.h:278
ConstAdjacentEdgeIndexIterator adjEdgeIndexEnd() const
Returns an iterator to the end of the container of this component.
Definition adjacent_edges.h:542
AdjacentEdgeIterator adjEdgeEnd()
Returns an iterator to the end of the container of this component.
Definition adjacent_edges.h:505
void insertAdjEdge(uint i, Edge *e)
Inserts the given adjacent edge in the container at the given position.
Definition adjacent_edges.h:453
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:413
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:231
void setAdjEdge(uint i, Edge *e)
Sets the i-th adjacent edge of the element.
Definition adjacent_edges.h:239
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:313
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:402
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:334
The ReferenceContainerComponent is a class that inherits from the IndexContainerComponent or PointerC...
Definition reference_container_component.h:99
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:89
HasAdjacentEdges concept is satisfied only if a Element class provides the types and member functions...
Definition adjacent_edges.h:51