Subversion Repositories gelsvn

Rev

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