Subversion Repositories gelsvn

Rev

Rev 578 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 578 Rev 588
Line 9... Line 9...
9
 * @brief Contains class for iterating over mesh entities in a HMesh.
9
 * @brief Contains class for iterating over mesh entities in a HMesh.
10
 */
10
 */
11
#ifndef __HMESH_ITERATORS_H__
11
#ifndef __HMESH_ITERATORS_H__
12
#define __HMESH_ITERATORS_H__
12
#define __HMESH_ITERATORS_H__
13
 
13
 
14
#include "ConnectivityKernel.h"
14
#include "ItemVector.h"
15
 
15
 
16
namespace HMesh
16
namespace HMesh
17
{
17
{
18
    /** Traverse the entities of an HMesh in the order they are stored in the
18
    /** Traverse the entities of an HMesh in the order they are stored in the
19
      data structure. */
19
      data structure. */
20
    template<typename ID>
20
    template<typename ITEM>
21
    class IDIterator
21
    class IDIterator
22
    {
22
    {
23
    public:
23
    public:
-
 
24
        typedef ItemID<ITEM> ID;
-
 
25
        
24
        // typedefs to accommodiate stl compliance
26
        // typedefs to accommodiate stl compliance
25
        typedef std::bidirectional_iterator_tag iterator_category;
27
        typedef std::bidirectional_iterator_tag iterator_category;
26
        typedef ptrdiff_t difference_type;
28
        typedef ptrdiff_t difference_type;
27
        typedef ID value_type;
29
        typedef ID value_type;
28
        typedef value_type reference;
30
        typedef value_type reference;
29
        typedef value_type* pointer;
31
        typedef value_type* pointer;
30
 
32
 
31
        /// constructor (default: skipping enabled)
33
        /// constructor (default: skipping enabled)
32
        IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip = true);
34
        IDIterator(const ItemVector<ITEM>& _item_vector, ID _id, bool _skip = true);
33
 
35
 
34
        /// prefix increment 
36
        /// prefix increment 
35
        IDIterator& operator ++();		
37
        IDIterator& operator ++();		
36
        /// postfix increment
38
        /// postfix increment
37
        IDIterator& operator ++(int);
39
        IDIterator& operator ++(int);
Line 51... Line 53...
51
        pointer operator ->();
53
        pointer operator ->();
52
        /// cast
54
        /// cast
53
        //operator VertexID() const;
55
        //operator VertexID() const;
54
 
56
 
55
    private:
57
    private:
56
        const ConnectivityKernel* ck;
58
        const ItemVector<ITEM>* item_vector;
57
        ID id;
59
        ID id;
58
        bool skip;
60
        bool skip;
59
    };
61
    };
60
 
62
 
61
     /*---------
-
 
62
     * Typedefs
-
 
63
     *----------*/
-
 
64
    typedef IDIterator<VertexID> VertexIDIterator;
-
 
65
    typedef IDIterator<FaceID> FaceIDIterator;
-
 
66
    typedef IDIterator<HalfEdgeID> HalfEdgeIDIterator;
-
 
67
 
-
 
68
 
63
 
69
    /*-----------------------------------------
64
    /*-----------------------------------------
70
     * IDIterator template implementation
65
     * IDIterator template implementation
71
     *-----------------------------------------*/
66
     *-----------------------------------------*/
72
 
67
 
73
    template<typename ID>
68
    template<typename ITEM>
74
    inline IDIterator<ID>::IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip) 
69
    inline IDIterator<ITEM>::IDIterator(const ItemVector<ITEM>& _item_vector, ID _id, bool _skip) 
75
        : ck(&_ck), id(_id), skip(_skip){}
70
        : item_vector(&_item_vector), id(_id), skip(_skip){}
76
 
71
 
77
    template<typename ID>
72
    template<typename ITEM>
78
    inline IDIterator<ID>& IDIterator<ID>::operator ++(int)
73
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator ++(int)
79
    { return ++(*this); }
74
    { return ++(*this); }
80
 
75
 
81
    template<typename ID>
76
    template<typename ITEM>
82
    inline IDIterator<ID>& IDIterator<ID>::operator --(int)
77
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator --(int)
83
    { return --(*this); }
78
    { return --(*this); }
84
 
79
 
85
    template<typename ID>
80
    template<typename ITEM>
86
    inline bool IDIterator<ID>::operator ==(const IDIterator<ID>& other) const
81
    inline bool IDIterator<ITEM>::operator ==(const IDIterator<ITEM>& other) const
87
    { return ck == other.ck && id == other.id; }
82
    { return item_vector == other.item_vector && id == other.id; }
88
 
83
 
89
    template<typename ID>
84
    template<typename ITEM>
90
    inline bool IDIterator<ID>::operator !=(const IDIterator<ID>& other) const
85
    inline bool IDIterator<ITEM>::operator !=(const IDIterator<ITEM>& other) const
91
    { return ck != other.ck || id != other.id; }
86
    { return item_vector != other.item_vector || id != other.id; }
92
 
87
 
93
    template<typename ID>
88
    template<typename ITEM>
94
    inline ID IDIterator<ID>::operator *()
89
    inline ItemID<ITEM> IDIterator<ITEM>::operator *()
95
    { return id; }
90
    { return id; }
96
 
91
 
97
    template<typename ID>
92
    template<typename ITEM>
98
    inline ID* IDIterator<ID>::operator ->()
93
    inline ItemID<ITEM>* IDIterator<ITEM>::operator ->()
99
    { return &id; }
94
    { return &id; }
100
 
95
 
101
     /*-----------------------------
-
 
102
     * Specializations for vertices
-
 
103
     *------------------------------*/
-
 
104
    template<>
96
    template<typename ITEM>
105
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator ++()
-
 
106
    {
-
 
107
        id = ck->vertices_next(id, skip);
-
 
108
        return *this;
-
 
109
    }
-
 
110
    template<>
-
 
111
    inline IDIterator<VertexID>& IDIterator<VertexID>::operator --()
-
 
112
    {
-
 
113
        id = ck->vertices_prev(id, skip);
-
 
114
        return *this;
-
 
115
    }
-
 
116
 
-
 
117
     /*-----------------------------
-
 
118
     * Specializations for faces
-
 
119
     *------------------------------*/
-
 
120
    template<>
-
 
121
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator ++()
97
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator ++()
122
    {
-
 
123
        id = ck->faces_next(id, skip);
-
 
124
        return *this;
-
 
125
    }
-
 
126
 
-
 
127
    template<>
-
 
128
    inline IDIterator<FaceID>& IDIterator<FaceID>::operator --()
-
 
129
    {
-
 
130
        id = ck->faces_prev(id, skip);
-
 
131
        return *this;
-
 
132
    }
-
 
133
 
-
 
134
     /*-----------------------------
-
 
135
     * Specializations for halfedges
-
 
136
     *------------------------------*/
-
 
137
    template<>
-
 
138
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator ++()
-
 
139
    {
98
    {
140
        id = ck->halfedges_next(id, skip);
99
        id = item_vector->index_next(id, skip);
141
        return *this;
100
        return *this;
142
    }
101
    }
143
 
102
 
144
    template<>
103
    template<typename ITEM>
145
    inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator --()
104
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator --()
146
    {
105
    {
147
        id = ck->halfedges_prev(id, skip);
106
        id = item_vector->index_prev(id, skip);
148
        return *this;
107
        return *this;
149
    }
108
    }
150
}
109
}
151
 
110
 
152
#endif
111
#endif
153
 
112