Subversion Repositories gelsvn

Rev

Rev 518 | Rev 572 | 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:
520 s042372 23
        // typedefs to accommodiate stl compliance
515 s042372 24
        typedef std::bidirectional_iterator_tag iterator_category;
25
        typedef ptrdiff_t difference_type;
520 s042372 26
        typedef ID value_type;
518 s042372 27
        typedef value_type reference;
515 s042372 28
        typedef value_type* pointer;
520 s042372 29
 
512 s042372 30
        /// constructor (default: skipping enabled)
518 s042372 31
        IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip = true);
511 s042372 32
 
512 s042372 33
        /// prefix increment 
518 s042372 34
        IDIterator& operator ++();		
512 s042372 35
        /// postfix increment
518 s042372 36
        IDIterator& operator ++(int);
512 s042372 37
        /// prefix decrement
518 s042372 38
        IDIterator& operator --();
512 s042372 39
        /// postfix decrement
518 s042372 40
        IDIterator& operator --(int);
511 s042372 41
 
512 s042372 42
        /// equal to
518 s042372 43
        bool operator ==(const IDIterator& other) const;
512 s042372 44
        /// not equal to
518 s042372 45
        bool operator !=(const IDIterator& other) const;
511 s042372 46
 
512 s042372 47
        /// indirection
518 s042372 48
        reference operator *();
512 s042372 49
        /// member by pointer
518 s042372 50
        pointer operator ->();
512 s042372 51
        /// cast
52
        //operator VertexID() const;
511 s042372 53
 
512 s042372 54
    private:
55
        const ConnectivityKernel* ck;
518 s042372 56
        ID id;
512 s042372 57
        bool skip;
58
    };
511 s042372 59
 
518 s042372 60
     /*---------
61
     * Typedefs
62
     *----------*/
63
    typedef IDIterator<VertexID> VertexIDIterator;
64
    typedef IDIterator<FaceID> FaceIDIterator;
65
    typedef IDIterator<HalfEdgeID> HalfEdgeIDIterator;
515 s042372 66
 
67
 
518 s042372 68
    /*-----------------------------------------
69
     * IDIterator template implementation
70
     *-----------------------------------------*/
511 s042372 71
 
518 s042372 72
    template<typename ID>
73
    inline IDIterator<ID>::IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip) 
74
        : ck(&_ck), id(_id), skip(_skip){}
511 s042372 75
 
518 s042372 76
    template<typename ID>
77
    inline IDIterator<ID>& IDIterator<ID>::operator ++(int)
78
    { return ++(*this); }
511 s042372 79
 
518 s042372 80
    template<typename ID>
81
    inline IDIterator<ID>& IDIterator<ID>::operator --(int)
82
    { return --(*this); }
511 s042372 83
 
518 s042372 84
    template<typename ID>
85
    inline bool IDIterator<ID>::operator ==(const IDIterator<ID>& other) const
86
    { return ck == other.ck && id == other.id; }
511 s042372 87
 
518 s042372 88
    template<typename ID>
89
    inline bool IDIterator<ID>::operator !=(const IDIterator<ID>& other) const
90
    { return ck != other.ck || id != other.id; }
511 s042372 91
 
518 s042372 92
    template<typename ID>
93
    inline ID IDIterator<ID>::operator *()
94
    { return id; }
511 s042372 95
 
518 s042372 96
    template<typename ID>
97
    inline ID* IDIterator<ID>::operator ->()
98
    { return &id; }
515 s042372 99
 
518 s042372 100
     /*-----------------------------
101
     * Specializations for vertices
102
     *------------------------------*/
103
    template<>
104
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator ++()
512 s042372 105
    {
106
        id = ck->vertices_next(id, skip);
107
        return *this;
108
    }
518 s042372 109
    template<>
110
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator --()
512 s042372 111
    {
112
        id = ck->vertices_prev(id, skip);
113
        return *this;
114
    }
511 s042372 115
 
518 s042372 116
     /*-----------------------------
117
     * Specializations for faces
118
     *------------------------------*/
119
    template<>
120
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator ++()
512 s042372 121
    {
122
        id = ck->faces_next(id, skip);
123
        return *this;
124
    }
511 s042372 125
 
518 s042372 126
    template<>
127
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator --()
512 s042372 128
    {
129
        id = ck->faces_prev(id, skip);
130
        return *this;
131
    }
511 s042372 132
 
518 s042372 133
     /*-----------------------------
134
     * Specializations for halfedges
135
     *------------------------------*/
136
    template<>
137
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator ++()
512 s042372 138
    {
139
        id = ck->halfedges_next(id, skip);
140
        return *this;
141
    }
511 s042372 142
 
518 s042372 143
    template<>
144
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator --()
512 s042372 145
    {
146
        id = ck->halfedges_prev(id, skip);
147
        return *this;
148
    }
511 s042372 149
}
150
 
151
#endif