Visual Computing Library
Loading...
Searching...
No Matches
cell_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_SPACE_COMPLEX_GRID_ITERATORS_CELL_ITERATOR_H
24#define VCL_SPACE_COMPLEX_GRID_ITERATORS_CELL_ITERATOR_H
25
26#include <vclib/space/core/point.h>
27
28namespace vcl {
29
30template<int N>
32{
34 Point<uint, N> mFirst, mEnd;
35
36public:
39 using reference = const Point<uint, N>&;
40 using pointer = const Point<uint, N>*;
41 using iterator_category = std::forward_iterator_tag;
42
44 {
45 mIt.setConstant(UINT_NULL);
46 mFirst = mEnd = mIt;
47 }
48
49 CellIterator(const Point<uint, N>& first, const Point<uint, N>& end) :
50 mIt(first), mFirst(first), mEnd(end)
51 {
52 }
53
54 reference operator*() const { return mIt; }
55
56 pointer operator->() const { return &mIt; }
57
58 bool operator==(const CellIterator& oi) const { return (mIt == oi.mIt); }
59
60 bool operator!=(const CellIterator& oi) const { return (mIt != oi.mIt); }
61
62 CellIterator operator++()
63 {
64 uint d = N - 1;
65 while (d != UINT_NULL && mIt(d) == mEnd(d) - 1) {
66 mIt(d) = mFirst(d);
67 d--;
68 }
69 if (d != -1)
70 mIt(d)++;
71 else
72 mIt.setConstant(UINT_NULL);
73 return *this;
74 }
75
76 CellIterator operator++(int)
77 {
78 CellIterator<N> oit = mIt;
79 ++(*this);
80 return oit;
81 }
82};
83
84} // namespace vcl
85
86#endif // VCL_SPACE_COMPLEX_GRID_ITERATORS_CELL_ITERATOR_H
Definition cell_iterator.h:32
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