Subversion Repositories gelsvn

Rev

Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 595 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
/**
7
/**
8
@file Walker.h
8
@file Walker.h
9
 Contains class for walking a mesh.
9
 Contains class for walking a mesh.
10
 */
10
 */
11
 
11
 
12
#ifndef __HMESH_HALFEDGEWALKER_H__
12
#ifndef __HMESH_HALFEDGEWALKER_H__
13
#define __HMESH_HALFEDGEWALKER_H__
13
#define __HMESH_HALFEDGEWALKER_H__
14
 
14
 
15
#include "ConnectivityKernel.h"
15
#include "ConnectivityKernel.h"
16
 
16
 
17
namespace HMesh
17
namespace HMesh
18
{
18
{
19
    /** Class for traversing the entities of a HMesh. This class can work as 
19
    /** Class for traversing the entities of a HMesh. This class can work as 
20
     both a vertex and a face circulator but also move in other ways. It is,
20
     both a vertex and a face circulator but also move in other ways. It is,
21
     in fact, the only way to traverse the mesh from the users point of view. */
21
     in fact, the only way to traverse the mesh from the users point of view. */
22
    class Walker
22
    class Walker
23
    {
23
    {
24
    public:
24
    public:
25
        /// construct from kernel and a halfedge
25
        /// construct from kernel and a halfedge
26
        Walker(const ConnectivityKernel& _ck, HalfEdgeID _current);
26
        Walker(const ConnectivityKernel& _ck, HalfEdgeID _current);
27
 
27
 
28
        /// returned walker has made one step to the next halfedge 
28
        /// returned walker has made one step to the next halfedge 
29
        Walker next() const;
29
        Walker next() const;
30
        /// returned walker has made one step to the previous halfedge 
30
        /// returned walker has made one step to the previous halfedge 
31
        Walker prev() const;
31
        Walker prev() const;
32
        /// returned walker has made one step to the opposite halfedge 
32
        /// returned walker has made one step to the opposite halfedge 
33
        Walker opp() const;
33
        Walker opp() const;
34
 
34
 
35
        /// returned walker has circulated vertex clockwise one step
35
        /// returned walker has circulated vertex clockwise one step
36
        Walker circulate_vertex_cw() const;
36
        Walker circulate_vertex_cw() const;
37
        /// returned walker has circulated vertex counterclockwise one step
37
        /// returned walker has circulated vertex counterclockwise one step
38
        Walker circulate_vertex_ccw() const;
38
        Walker circulate_vertex_ccw() const;
39
 
39
 
40
        /// returned walker has circulated face clockwise one step
40
        /// returned walker has circulated face clockwise one step
41
        Walker circulate_face_cw() const;
41
        Walker circulate_face_cw() const;
42
        /// returned walker has circulated face counterclockwise one step
42
        /// returned walker has circulated face counterclockwise one step
43
        Walker circulate_face_ccw() const;
43
        Walker circulate_face_ccw() const;
44
 
44
 
45
        /// test if the walker has reached its initial halfedge
45
        /// test if the walker has reached its initial halfedge
46
        bool full_circle() const;
46
        bool full_circle() const;
47
        
47
        
48
        /// number of steps taken
48
        /// number of steps taken
49
        int no_steps() const;
49
        int no_steps() const;
50
 
50
 
51
        /// get ID of vertex pointed to by current halfedge of walker
51
        /// get ID of vertex pointed to by current halfedge of walker
52
        VertexID vertex() const; 
52
        VertexID vertex() const; 
53
        /// get ID of face owning current halfedge of walker
53
        /// get ID of face owning current halfedge of walker
54
        FaceID face() const; 
54
        FaceID face() const; 
55
        /// get ID of current halfedge of walker
55
        /// get ID of current halfedge of walker
56
        HalfEdgeID halfedge() const;
56
        HalfEdgeID halfedge() const;
57
 
57
 
58
        /// assignment operator
58
        /// assignment operator
59
        Walker operator =(const Walker& w);
59
        Walker operator =(const Walker& w);
60
 
60
 
61
    private:
61
    private:
62
        const ConnectivityKernel* ck;
62
        const ConnectivityKernel* ck;
63
        HalfEdgeID current;
63
        HalfEdgeID current;
64
        HalfEdgeID last;
64
        HalfEdgeID last;
65
        int counter;
65
        int counter;
66
 
66
 
67
        Walker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter);
67
        Walker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter);
68
    };
68
    };
69
 
69
 
70
    inline Walker::Walker(const ConnectivityKernel& _ck, HalfEdgeID _current) 
70
    inline Walker::Walker(const ConnectivityKernel& _ck, HalfEdgeID _current) 
71
        : ck(&_ck), current(_current), last(_current), counter(0){}
71
        : ck(&_ck), current(_current), last(_current), counter(0){}
72
 
72
 
73
    inline Walker::Walker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter)
73
    inline Walker::Walker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter)
74
        : ck(&_ck), current(_current), last(_last), counter(_counter){}
74
        : ck(&_ck), current(_current), last(_last), counter(_counter){}
75
 
75
 
76
    inline Walker Walker::next() const
76
    inline Walker Walker::next() const
77
    { return Walker(*ck, ck->next(current), last, counter + 1); }
77
    { return Walker(*ck, ck->next(current), last, counter + 1); }
78
 
78
 
79
    inline Walker Walker::prev() const
79
    inline Walker Walker::prev() const
80
    { return Walker(*ck, ck->prev(current), last, counter + 1); }
80
    { return Walker(*ck, ck->prev(current), last, counter + 1); }
81
 
81
 
82
    inline Walker Walker::opp() const
82
    inline Walker Walker::opp() const
83
    { return Walker(*ck, ck->opp(current), last, counter + 1); }
83
    { return Walker(*ck, ck->opp(current), last, counter + 1); }
84
 
84
 
85
    inline Walker Walker::circulate_vertex_cw() const
85
    inline Walker Walker::circulate_vertex_cw() const
86
    { return Walker(*ck, ck->next(ck->opp(current)), last, counter + 1); }
86
    { return Walker(*ck, ck->next(ck->opp(current)), last, counter + 1); }
87
 
87
 
88
    inline Walker Walker::circulate_vertex_ccw() const
88
    inline Walker Walker::circulate_vertex_ccw() const
89
    { return Walker(*ck, ck->opp(ck->prev(current)), last, counter + 1); }
89
    { return Walker(*ck, ck->opp(ck->prev(current)), last, counter + 1); }
90
 
90
 
91
    inline Walker Walker::circulate_face_cw() const
91
    inline Walker Walker::circulate_face_cw() const
92
    { return Walker(*ck, ck->prev(current), last, counter + 1); }
92
    { return Walker(*ck, ck->prev(current), last, counter + 1); }
93
 
93
 
94
    inline Walker Walker::circulate_face_ccw() const
94
    inline Walker Walker::circulate_face_ccw() const
95
    { return Walker(*ck, ck->next(current), last, counter + 1); }
95
    { return Walker(*ck, ck->next(current), last, counter + 1); }
96
 
96
 
97
    inline bool Walker::full_circle() const
97
    inline bool Walker::full_circle() const
98
    { return (counter > 0 && current == last) ? true : false; }
98
    { return (counter > 0 && current == last) ? true : false; }
99
	
99
	
100
    inline int Walker::no_steps() const
100
    inline int Walker::no_steps() const
101
    { return counter; }
101
    { return counter; }
102
 
102
 
103
    inline VertexID Walker::vertex() const
103
    inline VertexID Walker::vertex() const
104
    { return ck->vert(current); }
104
    { return ck->vert(current); }
105
 
105
 
106
    inline FaceID Walker::face() const
106
    inline FaceID Walker::face() const
107
    { return ck->face(current); }
107
    { return ck->face(current); }
108
 
108
 
109
    inline HalfEdgeID Walker::halfedge() const
109
    inline HalfEdgeID Walker::halfedge() const
110
    { return current; }
110
    { return current; }
111
 
111
 
112
    inline Walker Walker::operator =(const Walker& w)
112
    inline Walker Walker::operator =(const Walker& w)
113
    { 
113
    { 
114
        current = w.current;
114
        current = w.current;
115
        counter = w.counter;
115
        counter = w.counter;
116
        ck = w.ck;
116
        ck = w.ck;
117
        last = w.last;
117
        last = w.last;
118
        return *this;
118
        return *this;
119
    }
119
    }
120
 
120
 
121
}
121
}
122
 
122
 
123
#endif
123
#endif
124
 
124