Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | 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
/**
8
@file HalfEdgeWalker.h
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. */
512 s042372 22
    class HalfEdgeWalker
23
    {
24
    public:
520 s042372 25
        /// construct from kernel and a halfedge
512 s042372 26
        HalfEdgeWalker(const ConnectivityKernel& _ck, HalfEdgeID _current);
511 s042372 27
 
520 s042372 28
        /// returned walker has made one step to the next halfedge 
512 s042372 29
        HalfEdgeWalker next() const;
520 s042372 30
        /// returned walker has made one step to the previous halfedge 
512 s042372 31
        HalfEdgeWalker prev() const;
520 s042372 32
        /// returned walker has made one step to the opposite halfedge 
512 s042372 33
        HalfEdgeWalker opp() const;
511 s042372 34
 
520 s042372 35
        /// returned walker has circulated vertex clockwise one step
512 s042372 36
        HalfEdgeWalker circulate_vertex_cw() const;
520 s042372 37
        /// returned walker has circulated vertex counterclockwise one step
512 s042372 38
        HalfEdgeWalker circulate_vertex_ccw() const;
511 s042372 39
 
520 s042372 40
        /// returned walker has circulated face clockwise one step
512 s042372 41
        HalfEdgeWalker circulate_face_cw() const;
520 s042372 42
        /// returned walker has circulated face counterclockwise one step
512 s042372 43
        HalfEdgeWalker 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
512 s042372 59
        HalfEdgeWalker operator =(const HalfEdgeWalker& 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
 
518 s042372 67
        HalfEdgeWalker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter);
512 s042372 68
    };
511 s042372 69
 
512 s042372 70
    inline HalfEdgeWalker::HalfEdgeWalker(const ConnectivityKernel& _ck, HalfEdgeID _current) 
71
        : ck(&_ck), current(_current), last(_current), counter(0){}
511 s042372 72
 
518 s042372 73
    inline HalfEdgeWalker::HalfEdgeWalker(const ConnectivityKernel& _ck, HalfEdgeID _current, HalfEdgeID _last, int _counter)
512 s042372 74
        : ck(&_ck), current(_current), last(_last), counter(_counter){}
511 s042372 75
 
512 s042372 76
    inline HalfEdgeWalker HalfEdgeWalker::next() const
77
    { return HalfEdgeWalker(*ck, ck->next(current), last, counter + 1); }
511 s042372 78
 
512 s042372 79
    inline HalfEdgeWalker HalfEdgeWalker::prev() const
80
    { return HalfEdgeWalker(*ck, ck->prev(current), last, counter + 1); }
511 s042372 81
 
512 s042372 82
    inline HalfEdgeWalker HalfEdgeWalker::opp() const
83
    { return HalfEdgeWalker(*ck, ck->opp(current), last, counter + 1); }
511 s042372 84
 
512 s042372 85
    inline HalfEdgeWalker HalfEdgeWalker::circulate_vertex_cw() const
86
    { return HalfEdgeWalker(*ck, ck->next(ck->opp(current)), last, counter + 1); }
511 s042372 87
 
512 s042372 88
    inline HalfEdgeWalker HalfEdgeWalker::circulate_vertex_ccw() const
89
    { return HalfEdgeWalker(*ck, ck->opp(ck->prev(current)), last, counter + 1); }
511 s042372 90
 
512 s042372 91
    inline HalfEdgeWalker HalfEdgeWalker::circulate_face_cw() const
537 jab 92
    { return HalfEdgeWalker(*ck, ck->prev(current), last, counter + 1); }
511 s042372 93
 
512 s042372 94
    inline HalfEdgeWalker HalfEdgeWalker::circulate_face_ccw() const
537 jab 95
    { return HalfEdgeWalker(*ck, ck->next(current), last, counter + 1); }
511 s042372 96
 
512 s042372 97
    inline bool HalfEdgeWalker::full_circle() const
98
    { return (counter > 0 && current == last) ? true : false; }
551 jab 99
 
518 s042372 100
    inline int HalfEdgeWalker::no_steps() const
512 s042372 101
    { return counter; }
511 s042372 102
 
512 s042372 103
    inline VertexID HalfEdgeWalker::vertex() const
104
    { return ck->vert(current); }
511 s042372 105
 
512 s042372 106
    inline FaceID HalfEdgeWalker::face() const
107
    { return ck->face(current); }
511 s042372 108
 
512 s042372 109
    inline HalfEdgeID HalfEdgeWalker::halfedge() const
110
    { return current; }
511 s042372 111
 
512 s042372 112
    inline HalfEdgeWalker HalfEdgeWalker::operator =(const HalfEdgeWalker& w)
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