Visual Computing Library
Loading...
Searching...
No Matches
adjacent_vertices.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_VERTICES_H
24#define VCL_MESH_COMPONENTS_ADJACENT_VERTICES_H
25
26#include "bases/reference_container_component.h"
27
28#include <vclib/concepts/mesh/components/adjacent_vertices.h>
29#include <vclib/types/view.h>
30
31namespace vcl::comp {
32
76template<
77 bool STORE_INDICES,
78 typename Vertex,
79 typename ParentElemType = void,
80 bool VERT = false,
81 bool OPT = false>
84 STORE_INDICES,
85 AdjacentVertices<STORE_INDICES, Vertex, ParentElemType, VERT, OPT>,
86 CompId::ADJACENT_VERTICES,
87 Vertex,
88 -1,
89 ParentElemType,
90 VERT,
91 OPT,
92 false>
93{
97 CompId::ADJACENT_VERTICES,
98 Vertex,
99 -1,
101 VERT,
102 OPT,
103 false>;
104
105public:
110
111 /* Iterator Types declaration */
112
113 using AdjacentVertexIterator = Base::Iterator;
114 using ConstAdjacentVertexIterator = Base::ConstIterator;
115 using ConstAdjacentVertexIndexIterator = Base::ConstIndexIterator;
116
117 /* Constructors */
118
124 AdjacentVertices() = default;
125
126 /* Member functions */
127
132 uint adjVerticesNumber() const { return Base::size(); }
133
141 Vertex* adjVertex(uint i) { return Base::element(i); }
142
150 const Vertex* adjVertex(uint i) const { return Base::element(i); }
151
158 uint adjVertexIndex(uint i) const { return Base::elementIndex(i); }
159
180 Vertex* adjVertexMod(int i) { return Base::elementMod(i); }
181
190 const Vertex* adjVertexMod(int i) const { return Base::elementMod(i); }
191
215 uint adjVertexIndexMod(int i) const { return Base::elementIndexMod(i); }
216
223 void setAdjVertex(uint i, Vertex* v) { Base::setElement(i, v); }
224
232 void setAdjVertex(uint i, uint vi) { Base::setElement(i, vi); }
233
240 void setAdjVertex(ConstAdjacentVertexIterator it, Vertex* v)
241 {
242 Base::setElement(it, v);
243 }
244
252 void setAdjVertex(ConstAdjacentVertexIterator it, uint vi)
253 {
254 Base::setElement(it, vi);
255 }
256
263 void setAdjVertex(ConstAdjacentVertexIndexIterator it, Vertex* v)
264 {
265 Base::setElement(it, v);
266 }
267
275 void setAdjVertex(ConstAdjacentVertexIndexIterator it, uint vi)
276 {
277 Base::setElement(it, vi);
278 }
279
299 void setAdjVertexMod(int i, Vertex* v) { Base::setElementMod(i, v); }
300
321 void setAdjVertexMod(int i, uint vi) { Base::setElementMod(i, vi); }
322
334 template<Range Rng>
336 {
337 Base::setElements(r);
338 }
339
351 template<Range Rng>
353 {
354 Base::setElements(r);
355 }
356
365 bool containsAdjVertex(const Vertex* v) const
366 {
367 return Base::containsElement(v);
368 }
369
378 bool containsAdjVertex(uint vi) const { return Base::containsElement(vi); }
379
390 {
391 return Base::indexOfElement(v);
392 }
393
403 uint indexOfAdjVertex(uint vi) const { return Base::indexOfElement(vi); }
404
411 void resizeAdjVertices(uint n) { Base::resize(n); }
412
420 void pushAdjVertex(Vertex* v) { Base::pushBack(v); }
421
429 void pushAdjVertex(uint vi) { Base::pushBack(vi); }
430
441 void insertAdjVertex(uint i, Vertex* v) { Base::insert(i, v); }
442
452 void insertAdjVertex(uint i, uint vi) { Base::insert(i, vi); }
453
462 void eraseAdjVertex(uint i) { Base::erase(i); }
463
469 void clearAdjVertices() { Base::clear(); }
470
471 /* Iterator Member functions */
472
479 AdjacentVertexIterator adjVertexBegin() { return Base::elementBegin(); }
480
486 AdjacentVertexIterator adjVertexEnd() { return Base::elementEnd(); }
487
494 ConstAdjacentVertexIterator adjVertexBegin() const
495 {
496 return Base::elementBegin();
497 }
498
505 ConstAdjacentVertexIterator adjVertexEnd() const
506 {
507 return Base::elementEnd();
508 }
509
516 ConstAdjacentVertexIndexIterator adjVertexIndexBegin() const
517 {
518 return Base::elementIndexBegin();
519 }
520
526 ConstAdjacentVertexIndexIterator adjVertexIndexEnd() const
527 {
528 return Base::elementIndexEnd();
529 }
530
547 View<AdjacentVertexIterator> adjVertices() { return Base::elements(); }
548
566 {
567 return Base::elements();
568 }
569
587 {
588 return Base::elementIndices();
589 }
590
591 // dummy member to discriminate between AdjacentVertices and
592 // VertexHalfEdgePointers
593 void __adjacentVertices() const {}
594
595protected:
596 // Component interface functions
597 template<typename Element>
598 void importFrom(const Element& e, bool importRefs = true)
599 {
600 if (importRefs) {
601 if constexpr (HasAdjacentVertices<Element>) {
602 if (isAdjacentVerticesAvailableOn(e)) {
603 // from static/dynamic to dynamic size: need to resize
604 // first, then import
605 resizeAdjVertices(e.adjVerticesNumber());
606 importIndicesFrom(e);
607 }
608 }
609 }
610 }
611
612 void serialize(std::ostream& os) const
613 {
614 // regardless of the type of the container (indices or pointers), the
615 // serialization is always done using the indices
616
617 vcl::serialize(os, adjVerticesNumber());
618 for (uint i = 0; i < adjVerticesNumber(); ++i) {
619 vcl::serialize(os, adjVertexIndex(i));
620 }
621 }
622
623 void deserialize(std::istream& is)
624 {
625 uint n;
626 vcl::deserialize(is, n);
628
629 for (uint i = 0; i < adjVerticesNumber(); ++i) {
630 uint aei;
631 vcl::deserialize(is, aei);
632 setAdjVertex(i, aei);
633 }
634 }
635
636private:
637 template<typename Element>
638 void importIndicesFrom(const Element& e)
639 {
640 for (uint i = 0; i < e.adjVerticesNumber(); ++i) {
641 setAdjVertex(i, e.adjVertexIndex(i));
642 }
643 }
644};
645
646/* Detector function to check if a class has AdjacentVertices available */
647
661bool isAdjacentVerticesAvailableOn(const ElementConcept auto& element)
662{
663 return isComponentAvailableOn<CompId::ADJACENT_VERTICES>(element);
664}
665
666} // namespace vcl::comp
667
668#endif // VCL_MESH_COMPONENTS_ADJACENT_VERTICES_H
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 Vertex class represents an Vertex element of the vcl::Mesh class.
Definition vertex.h:47
The AdjacentVertices class is a container of Vertex indices or pointers. It is a component that makes...
Definition adjacent_vertices.h:93
void insertAdjVertex(uint i, Vertex *v)
Inserts the given adjacent vertex in the container at the given position.
Definition adjacent_vertices.h:441
void setAdjVertex(ConstAdjacentVertexIndexIterator it, Vertex *v)
Sets the adjacent vertex pointed by the iterator.
Definition adjacent_vertices.h:263
void clearAdjVertices()
Clears the container of adjacent vertices, making it empty.
Definition adjacent_vertices.h:469
void insertAdjVertex(uint i, uint vi)
Inserts the given adjacent vertex in the container at the given position.
Definition adjacent_vertices.h:452
uint adjVertexIndex(uint i) const
Returns the index in the vertex container of the i-th adjacent vertex of the element.
Definition adjacent_vertices.h:158
ConstAdjacentVertexIterator adjVertexBegin() const
Returns a const iterator to the first adjacent vertex in the container of this component.
Definition adjacent_vertices.h:494
void eraseAdjVertex(uint i)
Removes the adjacent vertex at the given position from the container.
Definition adjacent_vertices.h:462
void resizeAdjVertices(uint n)
Resize the container of the adjacent vertices to the given size.
Definition adjacent_vertices.h:411
uint adjVertexIndexMod(int i) const
Returns the index in the vertex container of the i-th adjacent vertex of the element,...
Definition adjacent_vertices.h:215
View< ConstAdjacentVertexIndexIterator > adjVertexIndices() const
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_vertices.h:586
void setAdjVertex(uint i, Vertex *v)
Sets the i-th adjacent vertex of the element.
Definition adjacent_vertices.h:223
AdjacentVertexIterator adjVertexEnd()
Returns an iterator to the end of the container of this component.
Definition adjacent_vertices.h:486
ConstAdjacentVertexIterator adjVertexEnd() const
Returns a const iterator to the end of the container of this component.
Definition adjacent_vertices.h:505
void setAdjVertex(ConstAdjacentVertexIndexIterator it, uint vi)
Sets the adjacent vertex pointed by the iterator.
Definition adjacent_vertices.h:275
void setAdjVertexMod(int i, uint vi)
Sets the i-th adjacent vertex of the element, but using as index the module between i and the number ...
Definition adjacent_vertices.h:321
void setAdjVertex(uint i, uint vi)
Sets the i-th adjacent vertex of the element.
Definition adjacent_vertices.h:232
void pushAdjVertex(Vertex *v)
Pushes in the back of the container the given adjacent vertex.
Definition adjacent_vertices.h:420
Vertex * adjVertex(uint i)
Returns the pointer to the i-th adjacent vertex of an element.
Definition adjacent_vertices.h:141
uint indexOfAdjVertex(const Vertex *v) const
Returns the index of the given adjacent vertex in the container of the element. If the given adjacent...
Definition adjacent_vertices.h:389
bool containsAdjVertex(uint vi) const
Returns true if the container of adjacent vertices contains the given vertex, false otherwise.
Definition adjacent_vertices.h:378
uint indexOfAdjVertex(uint vi) const
Returns the index of the adjacent vertex with the given index in the container of the element....
Definition adjacent_vertices.h:403
void setAdjVertexMod(int i, Vertex *v)
Sets the i-th adjacent vertex of the element, but using as index the module between i and the number ...
Definition adjacent_vertices.h:299
void setAdjVertex(ConstAdjacentVertexIterator it, Vertex *v)
Sets the adjacent vertex pointed by the iterator.
Definition adjacent_vertices.h:240
void setAdjVertices(Rng &&r)
Sets all the adjacent vertices of this element.
Definition adjacent_vertices.h:352
uint adjVerticesNumber() const
Returns the number of adjacent vertices of the element.
Definition adjacent_vertices.h:132
const Vertex * adjVertex(uint i) const
Returns a const pointer to the i-th adjacent vertex of the element.
Definition adjacent_vertices.h:150
ConstAdjacentVertexIndexIterator adjVertexIndexEnd() const
Returns an iterator to the end of the container of this component.
Definition adjacent_vertices.h:526
Vertex * adjVertexMod(int i)
Returns the pointer to the i-th adjacent vertex of the element, but using as index the module between...
Definition adjacent_vertices.h:180
void setAdjVertices(Rng &&r)
Sets all the adjacent vertices of this element.
Definition adjacent_vertices.h:335
void setAdjVertex(ConstAdjacentVertexIterator it, uint vi)
Sets the adjacent vertex pointed by the iterator.
Definition adjacent_vertices.h:252
AdjacentVertices()=default
Empty constructor.
void pushAdjVertex(uint vi)
Pushes in the back of the container the given adjacent vertex..
Definition adjacent_vertices.h:429
ConstAdjacentVertexIndexIterator adjVertexIndexBegin() const
Returns an iterator to the first adjacent vertex index in the container of this component.
Definition adjacent_vertices.h:516
View< AdjacentVertexIterator > adjVertices()
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_vertices.h:547
const Vertex * adjVertexMod(int i) const
Same of adjVertexMod, but returns a const Pointer to the adjacent vertex.
Definition adjacent_vertices.h:190
View< ConstAdjacentVertexIterator > adjVertices() const
Returns a lightweight const view object that stores the begin and end iterators of the container of a...
Definition adjacent_vertices.h:565
AdjacentVertexIterator adjVertexBegin()
Returns an iterator to the first adjacent vertex in the container of this component.
Definition adjacent_vertices.h:479
bool containsAdjVertex(const Vertex *v) const
Returns true if the container of adjacent vertices contains the given vertex, false otherwise.
Definition adjacent_vertices.h:365
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