Visual Computing Library
Loading...
Searching...
No Matches
edge_adj_face_iterator.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_ITERATORS_FACE_EDGE_ADJ_FACE_ITERATOR_H
24#define VCL_MESH_ITERATORS_FACE_EDGE_ADJ_FACE_ITERATOR_H
25
26#include <vclib/types.h>
27
28#include <iterator>
29
30namespace vcl {
31
32template<typename FaceType, bool CNST = false>
34{
35 using FT = std::conditional_t<CNST, const FaceType, FaceType>;
36
37 using VT = std::conditional_t<
38 CNST,
39 const typename FT::VertexType,
40 typename FT::VertexType>;
41
42 FT* mCurrent = nullptr;
43 FT* mEnd = nullptr;
44 VT* mV0 = nullptr;
45 VT* mV1 = nullptr;
46
47public:
49 using iterator_category = std::forward_iterator_tag;
50 using value_type = FT*;
51 using reference = FT*&;
52 using pointer = FT**;
53
54 EdgeAdjFaceIterator() = default;
55
56 EdgeAdjFaceIterator(FT& f, uint edge) :
57 mCurrent(&f), mEnd(&f), mV0(f.vertex(edge)),
58 mV1(f.vertexMod(edge + 1))
59 {
60 }
61
62 bool operator==(const EdgeAdjFaceIterator& oi) const
63 {
64 return mCurrent == oi.mCurrent && mV0 == oi.mV0 && mV1 == oi.mV1;
65 }
66
67 bool operator!=(const EdgeAdjFaceIterator& oi) const
68 {
69 return !(*this == oi);
70 }
71
72 EdgeAdjFaceIterator& operator++()
73 {
74 assert(mCurrent);
75 uint edge = mCurrent->indexOfEdge(mV0, mV1);
76 assert(edge != UINT_NULL);
77 mCurrent = mCurrent->adjFace(edge);
78 if (mCurrent == mEnd || mCurrent == nullptr) {
79 mCurrent = nullptr;
80 mV0 = nullptr;
81 mV1 = nullptr;
82 }
83 return *this;
84 }
85
86 EdgeAdjFaceIterator operator++(int)
87 {
88 auto it = *this;
89 ++(*this);
90 return it;
91 }
92
93 reference operator*() const { return mCurrent; }
94
95 pointer operator->() const { return &mCurrent; }
96};
97
98template<typename FaceType>
100
101} // namespace vcl
102
103#endif // VCL_MESH_ITERATORS_FACE_EDGE_ADJ_FACE_ITERATOR_H
Definition edge_adj_face_iterator.h:34
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48