Subversion Repositories gelsvn

Rev

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

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