Subversion Repositories gelsvn

Rev

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