Subversion Repositories gelsvn

Rev

Rev 512 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* Written by Christian Thode Larsen 2009-2010
* Contact: thode2d@gmail.com
* Based on original work by J. Andreas Baerentzen
* Inspired by OpenMesh (www.openmesh.org)
*/

#ifndef __HMESH_ITERATORS_H__
#define __HMESH_ITERATORS_H__

#include "ConnectivityKernel.h"

namespace HMesh
{
        class VertexIDIterator
        {
        public:
                /// constructor (default: skipping enabled)
                VertexIDIterator(const ConnectivityKernel& _ck, VertexID _id, bool _skip = true);

                /// prefix increment 
                VertexIDIterator& operator ++();                
                /// postfix increment
                VertexIDIterator& operator ++(int);
                /// prefix decrement
                VertexIDIterator& operator --();
                /// postfix decrement
                VertexIDIterator& operator --(int);

                /// equal to
                bool operator ==(const VertexIDIterator& other) const;
                /// not equal to
                bool operator !=(const VertexIDIterator& other) const;

                /// indirection
                VertexID operator *();
                /// member by pointer
                VertexID* operator ->();
                /// cast
                //operator VertexID() const;

        private:
                const ConnectivityKernel* ck;
                VertexID id;
                bool skip;
        };

        class FaceIDIterator
        {
        public:
                /// constructor (default: skipping enabled)
                FaceIDIterator(const ConnectivityKernel& _ck, FaceID _id, bool _skip = true);

                /// prefix increment
                FaceIDIterator& operator ++();
                /// postfix increment
                FaceIDIterator& operator ++(int);
                /// prefix decrement
                FaceIDIterator& operator --();
                /// postfix decrement
                FaceIDIterator& operator --(int);

                /// equal to
                bool operator ==(const FaceIDIterator& other) const;
                /// not equal to
                bool operator !=(const FaceIDIterator& other) const;


                /// indirection
                FaceID operator *();
                /// member by pointer
                FaceID* operator ->();
                /// cast
                //operator FaceID() const;


        private:
                const ConnectivityKernel* ck;
                FaceID id;
                bool skip;
        };

        class HalfEdgeIDIterator
        {
        public:
                /// constructor (default: skipping enabled)
                HalfEdgeIDIterator(const ConnectivityKernel& _ck, HalfEdgeID _id, bool _skip = true);

                /// prefix increment
                HalfEdgeIDIterator& operator ++();
                /// postfix increment
                HalfEdgeIDIterator& operator ++(int);
                /// prefix decrement
                HalfEdgeIDIterator& operator --();
                /// postfix decrement
                HalfEdgeIDIterator& operator --(int);

                /// equal to
                bool operator ==(const HalfEdgeIDIterator& other) const;
                /// not equal to
                bool operator !=(const HalfEdgeIDIterator& other) const;

                /// indirection
                HalfEdgeID operator *();
                /// member by pointer
                HalfEdgeID* operator ->();
                /// cast
                //operator HalfEdgeID() const;

        private:
                const ConnectivityKernel* ck;
                HalfEdgeID id;
                bool skip;
        };

        inline VertexIDIterator::VertexIDIterator(const ConnectivityKernel& _ck, VertexID _id, bool _skip) : ck(&_ck), id(_id), skip(_skip){}


        inline VertexIDIterator& VertexIDIterator::operator ++()
        {
                id = ck->vertices_next(id, skip);
                return *this;
        }

        inline VertexIDIterator& VertexIDIterator::operator ++(int)
        { return ++(*this); }


        inline VertexIDIterator& VertexIDIterator::operator --()
        {
                id = ck->vertices_prev(id, skip);
                return *this;
        }

        inline VertexIDIterator& VertexIDIterator::operator --(int)
        { return --(*this); }


        inline bool VertexIDIterator::operator ==(const VertexIDIterator& other) const
        { return ck == other.ck && id == other.id; }

        inline bool VertexIDIterator::operator !=(const VertexIDIterator& other) const
        { return ck == other.ck && id == other.id; }


        inline VertexID VertexIDIterator::operator *()
        { return id; }

        inline VertexID* VertexIDIterator::operator ->()
        { return &id; }

        //inline VertexIDIterator::operator VertexID() const
        //{ return id; }



        inline FaceIDIterator::FaceIDIterator(const ConnectivityKernel& _ck, FaceID _id, bool _skip) : ck(&_ck), id(_id), skip(_skip){}


        inline FaceIDIterator& FaceIDIterator::operator ++()
        {
                id = ck->faces_next(id, skip);
                return *this;
        }

        inline FaceIDIterator& FaceIDIterator::operator ++(int)
        { return ++(*this); }

        inline FaceIDIterator& FaceIDIterator::operator --()
        {
                id = ck->faces_prev(id, skip);
                return *this;
        }

        inline FaceIDIterator& FaceIDIterator::operator --(int)
        { return --(*this); }


        inline bool FaceIDIterator::operator ==(const FaceIDIterator& other) const
        { return ck == other.ck && id == other.id; }

        inline bool FaceIDIterator::operator !=(const FaceIDIterator& other) const
        { return ck == other.ck && id == other.id; }


        inline FaceID FaceIDIterator::operator *()
        { return id; }

        inline FaceID* FaceIDIterator::operator ->()
        {return &id; }

        //inline FaceIDIterator::operator FaceID() const
        //{ return id; }


        inline HalfEdgeIDIterator::HalfEdgeIDIterator(const ConnectivityKernel& _ck, HalfEdgeID _id, bool _skip) : ck(&_ck), id(_id), skip(_skip){}


        inline HalfEdgeIDIterator& HalfEdgeIDIterator::operator ++()
        {
                id = ck->halfedges_next(id, skip);
                return *this;
        }

        inline HalfEdgeIDIterator& HalfEdgeIDIterator::operator ++(int)
        { return ++(*this); }

        inline HalfEdgeIDIterator& HalfEdgeIDIterator::operator --()
        {
                id = ck->halfedges_prev(id, skip);
                return *this;
        }

        inline HalfEdgeIDIterator& HalfEdgeIDIterator::operator --(int)
        { return --(*this); }


        inline bool HalfEdgeIDIterator::operator ==(const HalfEdgeIDIterator& other) const
        { return ck == other.ck && id == other.id; }

        inline bool HalfEdgeIDIterator::operator !=(const HalfEdgeIDIterator& other) const
        { return ck == other.ck && id == other.id; }


        inline HalfEdgeID HalfEdgeIDIterator::operator *()
        { return id; }

        inline HalfEdgeID* HalfEdgeIDIterator::operator ->()
        { return &id; }

        //inline HalfEdgeIDIterator::operator HalfEdgeID() const
        //{ return id; }


}

#endif

Generated by GNU Enscript 1.6.6.