/****************************************************************************
** GMAF - The Geometry Modeling Algorithms Framework
**
** Created : 04012000
**
** Copyright (C) 2000 by Le-Jeng Shiue.  All rights reserved.
**
****************************************************************************/
#ifndef gmafFacetAroundVertexIterator_H
#define gmafFacetAroundVertexIterator_H

#include "CgalExtension/cgalConfig.h"
#include "DataStructure/gmafPolyhedron.h"
#include "DataStructure/gmafVertexIterator.h"

/**
   gmafFacetAroundVertexIterator: traverse the facets around the vertex 
*/
class gmafFacetAroundVertexIterator {
// ENUMS
public:

// VARIABLES
/**@name Class Variables */
//@{
protected:
  Vertex* mpcgalVertex;
  Halfedge_around_vertex_circulator mcgalEdgeCir; // CW
private:
  int mCurPos;
  int mEndPos;

//@}

// METHODS
/**@name Class Methods */
//@{
public:
  /**
     Constructor of gmafFacetAroundVertexIterator
  */    
  gmafFacetAroundVertexIterator(const Vertex* v);
  /**
     Destructor of gmafFacetAroundVertexIterator
  */    
  virtual ~gmafFacetAroundVertexIterator();
  
  inline virtual int size() const;
  inline virtual void restart();
  inline virtual bool valid() const;
  inline virtual void next();
  inline virtual Facet& current() const;
  
protected:
  
private:
};

//---------------------------------------------------------
inline gmafFacetAroundVertexIterator::gmafFacetAroundVertexIterator(const Vertex* v) {
  mpcgalVertex = const_cast<Vertex*>(v);
  mcgalEdgeCir = mpcgalVertex->vertex_begin(); //CW

  mCurPos = 0;
  mEndPos = CGAL::circulator_size(mcgalEdgeCir);
}

inline gmafFacetAroundVertexIterator::~gmafFacetAroundVertexIterator() {
}

inline int gmafFacetAroundVertexIterator::size() const {
  return mEndPos;
}

inline void gmafFacetAroundVertexIterator::restart() {
  mcgalEdgeCir = mpcgalVertex->vertex_begin();
  mCurPos = 0;
}

inline bool gmafFacetAroundVertexIterator::valid() const {
  return (mCurPos < mEndPos);
}

inline void gmafFacetAroundVertexIterator::next() {
  if (mCurPos < mEndPos) {
    mcgalEdgeCir++;
    mCurPos++;
  }
}

inline Facet& gmafFacetAroundVertexIterator::current() const {
  return *(mcgalEdgeCir->facet());
}



#endif gmafFacetAroundVertexIterator_H

