summaryrefslogtreecommitdiff
path: root/include/gudhi_patches/CGAL/internal/Triangulation/Triangulation_ds_iterators.h
blob: 7e36002611fd208b858abefb28b0d5ae2876edc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) 2009-2014 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s)    : Samuel Hornus (Well... `copy, paste and hack' of Monique Teillaud's work)

#ifndef CGAL_INTERNAL_TRIANGULATION_TRIANGULATION_DS_ITERATORS_H
#define CGAL_INTERNAL_TRIANGULATION_TRIANGULATION_DS_ITERATORS_H

namespace CGAL {

namespace internal {
namespace Triangulation {

template< typename TDS >
class Triangulation_ds_facet_iterator
{
    typedef typename TDS::Full_cell_handle  Full_cell_handle;
    typedef typename TDS::Facet             Facet;

    typedef Facet                           value_type;
    typedef const Facet *                   pointer;
    typedef const Facet &                   reference;
    typedef std::size_t                     size_type;
    typedef std::ptrdiff_t                  difference_type;
    typedef std::bidirectional_iterator_tag iterator_category;

    typedef Triangulation_ds_facet_iterator<TDS> Facet_iterator;

    TDS & tds_;
    Facet ft_;
    const int cur_dim_;

public:
    Triangulation_ds_facet_iterator(TDS & tds)
    : tds_(tds), ft_(tds.full_cells_begin(), 0), cur_dim_(tds.current_dimension())
    {
        CGAL_assertion( cur_dim_ > 0 );
        while( ! canonical() )
            raw_increment();
    }

    Triangulation_ds_facet_iterator(TDS & tds, int)
    : tds_(tds), ft_(tds.full_cells_end(), 0), cur_dim_(tds.current_dimension())
    {
        CGAL_assertion( cur_dim_ > 0 );
        CGAL_assertion( canonical() );
    }

    Facet_iterator & operator++()
    {
        increment();
        return (*this);
    }

    Facet_iterator operator++(int)
    {
        Facet_iterator tmp(*this);
        increment();
        return tmp;
    }

    Facet_iterator & operator--()
    {
        decrement();
        return (*this);
    }

    Facet_iterator operator--(int)
    {
        Facet_iterator tmp(*this);
        decrement();
        return tmp;
    }

    bool operator==(const Facet_iterator & fi) const
    {
        return (&tds_ == &fi.tds_) &&
            (tds_.index_of_covertex(ft_) == fi.tds_.index_of_covertex(fi.ft_)) &&
            (tds_.full_cell(ft_) == fi.tds_.full_cell(fi.ft_));
    }

    bool operator!=(const Facet_iterator & fi) const
    {
        return !(*this == fi);
    }

    reference operator*() const
    {
        return ft_;
    }

    pointer operator->() const
    {
        return &ft_;
    }

private:
    bool canonical()
    {
        if( tds_.full_cells_end() == tds_.full_cell(ft_) )
            return ( 0 == tds_.index_of_covertex(ft_) );
        return ( tds_.full_cell(ft_) <
                    tds_.full_cell(ft_)->neighbor(tds_.index_of_covertex(ft_)) );
    }

    void raw_decrement()
    {
        int i = tds_.index_of_covertex(ft_);
        if( i == 0 )
            ft_ = Facet(--tds_.full_cell(ft_), cur_dim_);
        else
            ft_ = Facet(tds_.full_cell(ft_), i - 1);
    }

    void raw_increment()
    {
        int i = tds_.index_of_covertex(ft_);
        if( i == cur_dim_ )
            ft_ = Facet(++tds_.full_cell(ft_), 0);
        else
            ft_ = Facet(tds_.full_cell(ft_), i + 1);
    }

    void decrement()
    {
        do { raw_decrement(); } while( ! canonical() );
    }

    void increment()
    {
        do { raw_increment(); } while( ! canonical() );
    }
};

} // namespace Triangulation
} // namespace internal

} //namespace CGAL

#endif // CGAL_INTERNAL_TRIANGULATION_TRIANGULATION_DS_ITERATORS_H