Visual Computing Library
Loading...
Searching...
No Matches
adjacent_faces.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_FACES_H
24#define VCL_MESH_COMPONENTS_ADJACENT_FACES_H
25
26#include "bases/reference_container_component.h"
27
28#include <vclib/concepts/mesh/components/adjacent_faces.h>
29#include <vclib/types/view.h>
30
31namespace vcl::comp {
32
79template<
80 bool STORE_INDICES,
81 typename Face,
82 int N,
83 bool TTVN,
84 typename ParentElemType = void,
85 bool VERT = false,
86 bool OPT = false>
89 STORE_INDICES,
90 AdjacentFaces<
91 STORE_INDICES,
92 Face,
93 N,
94 TTVN,
95 ParentElemType,
96 VERT,
97 OPT>,
98 CompId::ADJACENT_FACES,
99 Face,
100 N,
101 ParentElemType,
102 VERT,
103 OPT,
104 TTVN>
105{
109 CompId::ADJACENT_FACES,
110 Face,
111 N,
113 VERT,
114 OPT,
115 TTVN>;
116
117public:
122
123 /* Iterator Types declaration */
124
125 using AdjacentFaceIterator = Base::Iterator;
126 using ConstAdjacentFaceIterator = Base::ConstIterator;
127 using ConstAdjacentFaceIndexIterator = Base::ConstIndexIterator;
128
134 static const int ADJ_FACE_NUMBER = Base::SIZE;
135
136 /* Constructors */
137
144 AdjacentFaces() = default;
145
146 /* Member functions */
147
152 uint adjFacesNumber() const { return Base::size(); }
153
161 Face* adjFace(uint i) { return Base::element(i); }
162
169 const Face* adjFace(uint i) const { return Base::element(i); }
170
177 uint adjFaceIndex(uint i) const { return Base::elementIndex(i); }
178
200 Face* adjFaceMod(int i) { return Base::elementMod(i); }
201
210 const Face* adjFaceMod(int i) const { return Base::elementMod(i); }
211
232 uint adjFaceIndexMod(int i) const { return Base::elementIndexMod(i); }
233
240 void setAdjFace(uint i, Face* f) { Base::setElement(i, f); }
241
248 void setAdjFace(uint i, uint fi) { Base::setElement(i, fi); }
249
256 void setAdjFace(ConstAdjacentFaceIterator it, Face* f)
257 {
258 Base::setElement(it, f);
259 }
260
267 void setAdjFace(ConstAdjacentFaceIterator it, uint fi)
268 {
269 Base::setElement(it, fi);
270 }
271
278 void setAdjFace(ConstAdjacentFaceIndexIterator it, Face* f)
279 {
280 Base::setElement(it, f);
281 }
282
289 void setAdjFace(ConstAdjacentFaceIndexIterator it, uint fi)
290 {
291 Base::setElement(it, fi);
292 }
293
313 void setAdjFaceMod(int i, Face* f) { Base::setElementMod(i, f); }
314
334 void setAdjFaceMod(int i, uint fi) { Base::setElementMod(i, fi); }
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 containsAdjFace(const Face* f) const
379 {
380 return Base::containsElement(f);
381 }
382
391 bool containsAdjFace(uint fi) const { return Base::containsElement(fi); }
392
402 uint indexOfAdjFace(const Face* f) const { return Base::indexOfElement(f); }
403
413 uint indexOfAdjFace(uint fi) const { return Base::indexOfElement(fi); }
414
415 /* Member functions specific for dynamic vector adjacent faces */
416
423 void resizeAdjFaces(uint n) requires (N < 0 && !TTVN) { Base::resize(n); }
424
432 void pushAdjFace(Face* f) requires (N < 0 && !TTVN) { Base::pushBack(f); }
433
441 void pushAdjFace(uint fi) requires (N < 0 && !TTVN) { Base::pushBack(fi); }
442
453 void insertAdjFace(uint i, Face* f) requires (N < 0 && !TTVN)
454 {
455 Base::insert(i, f);
456 }
457
467 void insertAdjFace(uint i, uint fi) requires (N < 0 && !TTVN)
468 {
469 Base::insert(i, fi);
470 }
471
480 void eraseAdjFace(uint i) requires (N < 0 && !TTVN) { Base::erase(i); }
481
487 void clearAdjFaces() requires (N < 0 && !TTVN) { Base::clear(); }
488
489 /* Iterator Member functions */
490
497 AdjacentFaceIterator adjFaceBegin() { return Base::elementBegin(); }
498
505 AdjacentFaceIterator adjFaceEnd() { return Base::elementEnd(); }
506
513 ConstAdjacentFaceIterator adjFaceBegin() const
514 {
515 return Base::elementBegin();
516 }
517
524 ConstAdjacentFaceIterator adjFaceEnd() const { return Base::elementEnd(); }
525
532 ConstAdjacentFaceIndexIterator adjFaceIndexBegin() const
533 {
534 return Base::elementIndexBegin();
535 }
536
542 ConstAdjacentFaceIndexIterator adjFaceIndexEnd() const
543 {
544 return Base::elementIndexEnd();
545 }
546
563 View<AdjacentFaceIterator> adjFaces() { return Base::elements(); }
564
582 {
583 return Base::elements();
584 }
585
603 {
604 return Base::elementIndices();
605 }
606
607 // dummy member to discriminate between AdjacentFaces and
608 // FaceHalfEdgePointers
609 void __adjacentFaces() const {}
610
611protected:
612 // Component interface functions
613 template<typename Element>
614 void importFrom(const Element& e, bool importRefs = true)
615 {
616 if (importRefs) {
617 if constexpr (HasAdjacentFaces<Element>) {
618 if (isAdjacentFacesAvailableOn(e)) {
619 if constexpr (N > 0) {
620 // same static size
621 if constexpr (N == Element::ADJ_FACE_NUMBER) {
622 importIndicesFrom(e);
623 }
624 // from dynamic to static, but dynamic size == static
625 // size
626 else if constexpr (Element::ADJ_FACE_NUMBER < 0) {
627 if (e.adjFacesNumber() == N) {
628 importIndicesFrom(e);
629 }
630 }
631 else {
632 // do not import in this case: cannot import from
633 // dynamic size != static size
634 }
635 }
636 else {
637 // from static/dynamic to dynamic size: need to resize
638 // first, then import
639 Base::resize(e.adjFacesNumber());
640 importIndicesFrom(e);
641 }
642 }
643 }
644 }
645 }
646
647 void serialize(std::ostream& os) const
648 {
649 // regardless of the type of the container (indices or pointers), the
650 // serialization is always done using the indices
651 if constexpr (N < 0) {
652 vcl::serialize(os, adjFacesNumber());
653 }
654 for (uint i = 0; i < adjFacesNumber(); ++i) {
655 vcl::serialize(os, adjFaceIndex(i));
656 }
657 }
658
659 void deserialize(std::istream& is)
660 {
661 if constexpr (N < 0) {
662 uint n;
663 vcl::deserialize(is, n);
664 Base::resize(n);
665 }
666 for (uint i = 0; i < adjFacesNumber(); ++i) {
667 uint afi;
668 vcl::deserialize(is, afi);
669 setAdjFace(i, afi);
670 }
671 }
672
673private:
674 template<typename Element>
675 void importIndicesFrom(const Element& e)
676 {
677 for (uint i = 0; i < e.adjFacesNumber(); ++i) {
678 setAdjFace(i, e.adjFaceIndex(i));
679 }
680 }
681};
682
683/* Detector function to check if a class has AdjacentFaces available */
684
696bool isAdjacentFacesAvailableOn(const ElementConcept auto& element)
697{
698 return isComponentAvailableOn<CompId::ADJACENT_FACES>(element);
699}
700
701} // namespace vcl::comp
702
703#endif // VCL_MESH_COMPONENTS_ADJACENT_FACES_H
The Element class.
Definition element.h:57
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:49
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The AdjacentFaces class is a container of Face indices or pointers. It could be used by any Element t...
Definition adjacent_faces.h:105
View< ConstAdjacentFaceIndexIterator > adjFaceIndices() const
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_faces.h:602
ConstAdjacentFaceIndexIterator adjFaceIndexEnd() const
Returns an iterator to the end of the container of this component.
Definition adjacent_faces.h:542
void setAdjFaces(Rng &&r)
Sets all the adjacent faces of this element.
Definition adjacent_faces.h:365
ConstAdjacentFaceIterator adjFaceBegin() const
Returns a const iterator to the first adjacent face in the container of this component.
Definition adjacent_faces.h:513
ConstAdjacentFaceIterator adjFaceEnd() const
Returns a const iterator to the end of the container of this component.
Definition adjacent_faces.h:524
void setAdjFace(uint i, uint fi)
Sets the i-th adjacent face of the element.
Definition adjacent_faces.h:248
Face * adjFaceMod(int i)
Returns the pointer to the i-th adjacent face of this element but using as index the module between i...
Definition adjacent_faces.h:200
View< ConstAdjacentFaceIterator > adjFaces() const
Returns a lightweight const view object that stores the begin and end iterators of the container of a...
Definition adjacent_faces.h:581
void setAdjFace(ConstAdjacentFaceIterator it, uint fi)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:267
void setAdjFaceMod(int i, Face *f)
Sets the i-th adjacent face of the element, but using as index the module between i and the number of...
Definition adjacent_faces.h:313
uint adjFacesNumber() const
Returns the number of adjacent faces of this element.
Definition adjacent_faces.h:152
void setAdjFace(ConstAdjacentFaceIndexIterator it, Face *f)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:278
void pushAdjFace(Face *f)
Pushes in the back of the container the given adjacent face.
Definition adjacent_faces.h:432
void setAdjFace(ConstAdjacentFaceIterator it, Face *f)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:256
AdjacentFaceIterator adjFaceBegin()
Returns an iterator to the first adjacent face in the container of this component.
Definition adjacent_faces.h:497
uint adjFaceIndex(uint i) const
Returns the index in the face container of the i-th adjacent face of the element.
Definition adjacent_faces.h:177
static const int ADJ_FACE_NUMBER
Static size of the container. If the container is dynamic, this value will be negative and you should...
Definition adjacent_faces.h:134
uint indexOfAdjFace(const Face *f) const
Returns the index of the given adjacent face in the container of this element. If the given adjacent ...
Definition adjacent_faces.h:402
uint indexOfAdjFace(uint fi) const
Returns the index of the adjacent face with the given index in the container of this element....
Definition adjacent_faces.h:413
const Face * adjFace(uint i) const
Returns a const pointer to the i-th adjacent face of this element.
Definition adjacent_faces.h:169
View< AdjacentFaceIterator > adjFaces()
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_faces.h:563
void pushAdjFace(uint fi)
Pushes in the back of the container the given adjacent face.
Definition adjacent_faces.h:441
bool containsAdjFace(const Face *f) const
Returns true if the container of adjacent faces contains the given face, false otherwise.
Definition adjacent_faces.h:378
void resizeAdjFaces(uint n)
Resize the container of the adjacent faces to the given size.
Definition adjacent_faces.h:423
void clearAdjFaces()
Clears the container of adjacent faces, making it empty.
Definition adjacent_faces.h:487
const Face * adjFaceMod(int i) const
Same of adjFaceMod, but returns a const Pointer to the adjacent face.
Definition adjacent_faces.h:210
void setAdjFaceMod(int i, uint fi)
Sets the i-th adjacent face of the element, but using as index the module between i and the number of...
Definition adjacent_faces.h:334
ConstAdjacentFaceIndexIterator adjFaceIndexBegin() const
Returns an iterator to the first adjacent face index in the container of this component.
Definition adjacent_faces.h:532
Face * adjFace(uint i)
Returns the pointer to the i-th adjacent face of this element.
Definition adjacent_faces.h:161
void setAdjFace(uint i, Face *f)
Sets the i-th adjacent face of this element.
Definition adjacent_faces.h:240
void setAdjFaces(Rng &&r)
Sets all the adjacent faces of this element.
Definition adjacent_faces.h:348
AdjacentFaces()=default
Empty constructor.
uint adjFaceIndexMod(int i) const
Returns the index in the face container of the i-th adjacent face of the element, but using as index ...
Definition adjacent_faces.h:232
bool containsAdjFace(uint fi) const
Returns true if the container of adjacent faces contains the face with the given index,...
Definition adjacent_faces.h:391
void setAdjFace(ConstAdjacentFaceIndexIterator it, uint fi)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:289
void insertAdjFace(uint i, Face *f)
Inserts the given adjacent face in the container at the given position.
Definition adjacent_faces.h:453
AdjacentFaceIterator adjFaceEnd()
Returns an iterator to the end of the container of this component.
Definition adjacent_faces.h:505
void insertAdjFace(uint i, uint fi)
Inserts the adjacent face with the given index in the container at the given position.
Definition adjacent_faces.h:467
void eraseAdjFace(uint i)
Removes the adjacent face at the given position from the container.
Definition adjacent_faces.h:480
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