Subversion Repositories gelsvn

Rev

Rev 630 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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