Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

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