Subversion Repositories gelsvn

Rev

Rev 515 | Rev 520 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
512 s042372 1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
4
 *
5
 * Principal authors:
6
 *  Christian Thode Larsen (thode2d@gmail.com)
7
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
8
 *
9
 * See LICENSE.txt for licensing information
10
 * ----------------------------------------------------------------------- */
511 s042372 11
 
12
#ifndef __HMESH_ITERATORS_H__
13
#define __HMESH_ITERATORS_H__
14
 
15
#include "ConnectivityKernel.h"
16
 
17
namespace HMesh
18
{
518 s042372 19
    template<typename ID>
20
    class IDIterator
512 s042372 21
    {
22
    public:
518 s042372 23
        typedef ID value_type;
515 s042372 24
 
25
        typedef std::bidirectional_iterator_tag iterator_category;
26
        typedef ptrdiff_t difference_type;
518 s042372 27
        typedef value_type reference;
515 s042372 28
        typedef value_type* pointer;
512 s042372 29
        /// constructor (default: skipping enabled)
518 s042372 30
        IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip = true);
511 s042372 31
 
512 s042372 32
        /// prefix increment 
518 s042372 33
        IDIterator& operator ++();		
512 s042372 34
        /// postfix increment
518 s042372 35
        IDIterator& operator ++(int);
512 s042372 36
        /// prefix decrement
518 s042372 37
        IDIterator& operator --();
512 s042372 38
        /// postfix decrement
518 s042372 39
        IDIterator& operator --(int);
511 s042372 40
 
512 s042372 41
        /// equal to
518 s042372 42
        bool operator ==(const IDIterator& other) const;
512 s042372 43
        /// not equal to
518 s042372 44
        bool operator !=(const IDIterator& other) const;
511 s042372 45
 
512 s042372 46
        /// indirection
518 s042372 47
        reference operator *();
512 s042372 48
        /// member by pointer
518 s042372 49
        pointer operator ->();
512 s042372 50
        /// cast
51
        //operator VertexID() const;
511 s042372 52
 
512 s042372 53
    private:
54
        const ConnectivityKernel* ck;
518 s042372 55
        ID id;
512 s042372 56
        bool skip;
57
    };
511 s042372 58
 
518 s042372 59
     /*---------
60
     * Typedefs
61
     *----------*/
62
    typedef IDIterator<VertexID> VertexIDIterator;
63
    typedef IDIterator<FaceID> FaceIDIterator;
64
    typedef IDIterator<HalfEdgeID> HalfEdgeIDIterator;
515 s042372 65
 
66
 
518 s042372 67
    /*-----------------------------------------
68
     * IDIterator template implementation
69
     *-----------------------------------------*/
511 s042372 70
 
518 s042372 71
    template<typename ID>
72
    inline IDIterator<ID>::IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip) 
73
        : ck(&_ck), id(_id), skip(_skip){}
511 s042372 74
 
518 s042372 75
    template<typename ID>
76
    inline IDIterator<ID>& IDIterator<ID>::operator ++(int)
77
    { return ++(*this); }
511 s042372 78
 
518 s042372 79
    template<typename ID>
80
    inline IDIterator<ID>& IDIterator<ID>::operator --(int)
81
    { return --(*this); }
511 s042372 82
 
518 s042372 83
    template<typename ID>
84
    inline bool IDIterator<ID>::operator ==(const IDIterator<ID>& other) const
85
    { return ck == other.ck && id == other.id; }
511 s042372 86
 
518 s042372 87
    template<typename ID>
88
    inline bool IDIterator<ID>::operator !=(const IDIterator<ID>& other) const
89
    { return ck != other.ck || id != other.id; }
511 s042372 90
 
518 s042372 91
    template<typename ID>
92
    inline ID IDIterator<ID>::operator *()
93
    { return id; }
511 s042372 94
 
518 s042372 95
    template<typename ID>
96
    inline ID* IDIterator<ID>::operator ->()
97
    { return &id; }
515 s042372 98
 
518 s042372 99
     /*-----------------------------
100
     * Specializations for vertices
101
     *------------------------------*/
102
    template<>
103
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator ++()
512 s042372 104
    {
105
        id = ck->vertices_next(id, skip);
106
        return *this;
107
    }
518 s042372 108
    template<>
109
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator --()
512 s042372 110
    {
111
        id = ck->vertices_prev(id, skip);
112
        return *this;
113
    }
511 s042372 114
 
518 s042372 115
     /*-----------------------------
116
     * Specializations for faces
117
     *------------------------------*/
118
    template<>
119
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator ++()
512 s042372 120
    {
121
        id = ck->faces_next(id, skip);
122
        return *this;
123
    }
511 s042372 124
 
518 s042372 125
    template<>
126
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator --()
512 s042372 127
    {
128
        id = ck->faces_prev(id, skip);
129
        return *this;
130
    }
511 s042372 131
 
518 s042372 132
     /*-----------------------------
133
     * Specializations for halfedges
134
     *------------------------------*/
135
    template<>
136
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator ++()
512 s042372 137
    {
138
        id = ck->halfedges_next(id, skip);
139
        return *this;
140
    }
511 s042372 141
 
518 s042372 142
    template<>
143
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator --()
512 s042372 144
    {
145
        id = ck->halfedges_prev(id, skip);
146
        return *this;
147
    }
511 s042372 148
}
149
 
150
#endif