Visual Computing Library  devel
Loading...
Searching...
No Matches
adjacent_faces.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_FACES_H
24#define VCL_MESH_COMPONENTS_ADJACENT_FACES_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 Face,
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 AdjacentFaces<
91 STORE_INDICES,
92 Face,
93 N,
94 TTVC,
95 ParentElemType,
96 VERT,
97 OPT>,
98 CompId::ADJACENT_FACES,
99 Face,
100 N,
101 ParentElemType,
102 VERT,
103 OPT,
104 TTVC>
105{
106 using Base = ReferenceContainerComponent<
109 CompId::ADJACENT_FACES,
110 Face,
111 N,
113 VERT,
114 OPT,
115 TTVC>;
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_COUNT = Base::SIZE;
135
136 /* Constructors */
137
144 AdjacentFaces() = default;
145
146 /* Member functions */
147
152 uint adjFaceCount() 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
199 Face* adjFaceMod(int i) { return Base::elementMod(i); }
200
208 const Face* adjFaceMod(int i) const { return Base::elementMod(i); }
209
230
237 void setAdjFace(uint i, Face* f) { Base::setElement(i, f); }
238
245 void setAdjFace(uint i, uint fi) { Base::setElement(i, fi); }
246
253 void setAdjFace(ConstAdjacentFaceIterator it, Face* f)
254 {
255 Base::setElement(it, f);
256 }
257
264 void setAdjFace(ConstAdjacentFaceIterator it, uint fi)
265 {
266 Base::setElement(it, fi);
267 }
268
275 void setAdjFace(ConstAdjacentFaceIndexIterator it, Face* f)
276 {
277 Base::setElement(it, f);
278 }
279
286 void setAdjFace(ConstAdjacentFaceIndexIterator it, uint fi)
287 {
288 Base::setElement(it, fi);
289 }
290
310 void setAdjFaceMod(int i, Face* f) { Base::setElementMod(i, f); }
311
332
344 template<Range Rng>
346 {
348 }
349
361 template<Range Rng>
363 {
365 }
366
375 bool containsAdjFace(const Face* f) const
376 {
377 return Base::containsElement(f);
378 }
379
389
399 uint indexOfAdjFace(const Face* f) const { return Base::indexOfElement(f); }
400
411
412 /* Member functions specific for dynamic vector adjacent faces */
413
420 void resizeAdjFaces(uint n) requires (N < 0 && !TTVC) { Base::resize(n); }
421
429 void pushAdjFace(Face* f) requires (N < 0 && !TTVC) { Base::pushBack(f); }
430
438 void pushAdjFace(uint fi) requires (N < 0 && !TTVC) { Base::pushBack(fi); }
439
450 void insertAdjFace(uint i, Face* f) requires (N < 0 && !TTVC)
451 {
452 Base::insert(i, f);
453 }
454
464 void insertAdjFace(uint i, uint fi) requires (N < 0 && !TTVC)
465 {
466 Base::insert(i, fi);
467 }
468
477 void eraseAdjFace(uint i) requires (N < 0 && !TTVC) { Base::erase(i); }
478
484 void clearAdjFaces() requires (N < 0 && !TTVC) { Base::clear(); }
485
486 /* Iterator Member functions */
487
494 AdjacentFaceIterator adjFaceBegin() { return Base::elementBegin(); }
495
502 AdjacentFaceIterator adjFaceEnd() { return Base::elementEnd(); }
503
510 ConstAdjacentFaceIterator adjFaceBegin() const
511 {
512 return Base::elementBegin();
513 }
514
521 ConstAdjacentFaceIterator adjFaceEnd() const { return Base::elementEnd(); }
522
529 ConstAdjacentFaceIndexIterator adjFaceIndexBegin() const
530 {
532 }
533
539 ConstAdjacentFaceIndexIterator adjFaceIndexEnd() const
540 {
541 return Base::elementIndexEnd();
542 }
543
560 View<AdjacentFaceIterator> adjFaces() { return Base::elements(); }
561
579 {
580 return Base::elements();
581 }
582
603
604 // dummy member to discriminate between AdjacentFaces and
605 // FaceHalfEdgePointers
606 void __adjacentFaces() const {}
607
608protected:
609 // Component interface functions
610 template<typename Element>
611 void importFrom(const Element& e, bool importRefs = true);
612
613 void serialize(std::ostream& os) const
614 {
615 // regardless of the type of the container (indices or pointers), the
616 // serialization is always done using the indices
617 if constexpr (N < 0) {
618 vcl::serialize(os, adjFaceCount());
619 }
620 for (uint i = 0; i < adjFaceCount(); ++i) {
621 vcl::serialize(os, adjFaceIndex(i));
622 }
623 }
624
625 void deserialize(std::istream& is)
626 {
627 if constexpr (N < 0) {
628 uint n;
629 vcl::deserialize(is, n);
630 Base::resize(n);
631 }
632 for (uint i = 0; i < adjFaceCount(); ++i) {
633 uint afi;
634 vcl::deserialize(is, afi);
635 setAdjFace(i, afi);
636 }
637 }
638
639private:
640 template<typename Element>
641 void importIndicesFrom(const Element& e)
642 {
643 for (uint i = 0; i < e.adjFaceCount(); ++i) {
644 setAdjFace(i, e.adjFaceIndex(i));
645 }
646 }
647};
648
649/* concepts */
650
668template<typename T>
670 BTIBTBB::IsDerivedFromSpecializationOfV<T, AdjacentFaces>;
671
682template<typename T>
686
698template<typename T>
701 RemoveRef<T>::VERTEX_COUNT == RemoveRef<T>::ADJ_FACE_COUNT;
702
715template<typename T>
718
719/* importFrom function */
720
721template<
722 bool STORE_INDICES,
723 typename Face,
724 int N,
725 bool TTVC,
726 typename ParentElemType,
727 bool VERT,
728 bool OPT>
729template<typename Element>
730void AdjacentFaces<STORE_INDICES, Face, N, TTVC, ParentElemType, VERT, OPT>::
731 importFrom(const Element& e, bool importRefs)
732{
733 if (importRefs) {
734 if constexpr (HasAdjacentFaces<Element>) {
735 if (isAdjacentFacesAvailableOn(e)) {
736 if constexpr (N > 0) {
737 // same static size
738 if constexpr (N == Element::ADJ_FACE_COUNT) {
739 importIndicesFrom(e);
740 }
741 // from dynamic to static, but dynamic size == static size
742 else if constexpr (Element::ADJ_FACE_COUNT < 0) {
743 if (e.adjFaceCount() == N) {
744 importIndicesFrom(e);
745 }
746 }
747 else {
748 // do not import in this case: cannot import from
749 // dynamic size != static size
750 }
751 }
752 else {
753 // from static/dynamic to dynamic size: need to resize
754 // first, then import
755 Base::resize(e.adjFaceCount());
756 importIndicesFrom(e);
757 }
758 }
759 }
760 }
761}
762
763/* Detector function to check if a class has AdjacentFaces available */
764
775bool isAdjacentFacesAvailableOn(const auto& element)
776{
778}
779
780} // namespace vcl::comp
781
782#endif // VCL_MESH_COMPONENTS_ADJACENT_FACES_H
The Element class.
Definition element.h:75
The Face class represents an Face element of the vcl::Mesh class.
Definition face.h:48
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 AdjacentFaces class is a container of Face indices or pointers. It could be used by any Element t...
Definition adjacent_faces.h:105
void setAdjFaces(Rng &&r)
Sets all the adjacent faces of this element.
Definition adjacent_faces.h:362
void resizeAdjFaces(uint n)
Resize the container of the adjacent faces to the given size.
Definition adjacent_faces.h:420
void setAdjFace(ConstAdjacentFaceIndexIterator it, uint fi)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:286
void eraseAdjFace(uint i)
Removes the adjacent face at the given position from the container.
Definition adjacent_faces.h:477
Face * adjFace(uint i)
Returns the pointer to the i-th adjacent face of this element.
Definition adjacent_faces.h:161
bool containsAdjFace(uint fi) const
Returns true if the container of adjacent faces contains the face with the given index,...
Definition adjacent_faces.h:388
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:199
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:331
void clearAdjFaces()
Clears the container of adjacent faces, making it empty.
Definition adjacent_faces.h:484
View< AdjacentFaceIterator > adjFaces()
Returns a lightweight view object that stores the begin and end iterators of the container of adjacen...
Definition adjacent_faces.h:560
void setAdjFaces(Rng &&r)
Sets all the adjacent faces of this element.
Definition adjacent_faces.h:345
AdjacentFaceIterator adjFaceEnd()
Returns an iterator to the end of the container of this component.
Definition adjacent_faces.h:502
bool containsAdjFace(const Face *f) const
Returns true if the container of adjacent faces contains the given face, false otherwise.
Definition adjacent_faces.h:375
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:599
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:310
uint adjFaceCount() const
Returns the number of adjacent faces of this element.
Definition adjacent_faces.h:152
const Face * adjFace(uint i) const
Returns a const pointer to the i-th adjacent face of this element.
Definition adjacent_faces.h:169
void pushAdjFace(uint fi)
Pushes in the back of the container the given adjacent face.
Definition adjacent_faces.h:438
void setAdjFace(ConstAdjacentFaceIterator it, Face *f)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:253
ConstAdjacentFaceIterator adjFaceEnd() const
Returns a const iterator to the end of the container of this component.
Definition adjacent_faces.h:521
static const int ADJ_FACE_COUNT
Static size of the container. If the container is dynamic, this value will be negative and you should...
Definition adjacent_faces.h:134
const Face * adjFaceMod(int i) const
Same of adjFaceMod, but returns a const Pointer to the adjacent face.
Definition adjacent_faces.h:208
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:399
void setAdjFace(uint i, uint fi)
Sets the i-th adjacent face of the element.
Definition adjacent_faces.h:245
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:229
ConstAdjacentFaceIndexIterator adjFaceIndexEnd() const
Returns an iterator to the end of the container of this component.
Definition adjacent_faces.h:539
void setAdjFace(ConstAdjacentFaceIterator it, uint fi)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:264
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:464
ConstAdjacentFaceIndexIterator adjFaceIndexBegin() const
Returns an iterator to the first adjacent face index in the container of this component.
Definition adjacent_faces.h:529
void setAdjFace(ConstAdjacentFaceIndexIterator it, Face *f)
Sets the adjacent face pointed by the iterator.
Definition adjacent_faces.h:275
AdjacentFaces()=default
Empty constructor.
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
AdjacentFaceIterator adjFaceBegin()
Returns an iterator to the first adjacent face in the container of this component.
Definition adjacent_faces.h:494
ConstAdjacentFaceIterator adjFaceBegin() const
Returns a const iterator to the first adjacent face in the container of this component.
Definition adjacent_faces.h:510
void pushAdjFace(Face *f)
Pushes in the back of the container the given adjacent face.
Definition adjacent_faces.h:429
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:410
void setAdjFace(uint i, Face *f)
Sets the i-th adjacent face of this element.
Definition adjacent_faces.h:237
void insertAdjFace(uint i, Face *f)
Inserts the given adjacent face in the container at the given position.
Definition adjacent_faces.h:450
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:578
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 AdjacentFaces component (in...
Definition adjacent_faces.h:669
A concept that checks whether a type T (that should be a Element) has the AdjacentFaces component (in...
Definition adjacent_faces.h:683
HasRightNumberOfAdjacentFaces concept.
Definition adjacent_faces.h:699
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
SanityCheckAdjacentFaces concept.
Definition adjacent_faces.h:716