CirculatorsT.hh 52.6 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                               OpenMesh                                    *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5 6 7
 *                           www.openmesh.org                                *
 *                                                                           *
 *---------------------------------------------------------------------------* 
8
 *  This file is part of OpenMesh.                                           *
Jan Möbius's avatar
Jan Möbius committed
9
 *                                                                           *
10 11 12 13 14
 *  OpenMesh is free software: you can redistribute it and/or modify         * 
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
Jan Möbius's avatar
Jan Möbius committed
15
 *                                                                           *
16 17 18 19 20 21 22
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
Jan Möbius's avatar
Jan Möbius committed
23
 *                                                                           *
24 25 26 27
 *  OpenMesh is distributed in the hope that it will be useful,              *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
Jan Möbius's avatar
Jan Möbius committed
28
 *                                                                           *
29 30 31 32 33 34 35 36 37 38
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenMesh.  If not,                                    *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/ 

/*===========================================================================*\
 *                                                                           *             
 *   $Revision$                                                         *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
39 40
 *                                                                           *
\*===========================================================================*/
41

Jan Möbius's avatar
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52 53 54
#ifndef OPENMESH_CIRCULATORS_HH
#define OPENMESH_CIRCULATORS_HH
//=============================================================================
//
//  Vertex and Face circulators for PolyMesh/TriMesh
//
//=============================================================================



//== INCLUDES =================================================================

#include <OpenMesh/Core/System/config.h>
55
#include <cassert>
56
#include <cstddef>
Jan Möbius's avatar
Jan Möbius committed
57 58 59 60 61 62 63


//== NAMESPACES ===============================================================

namespace OpenMesh {
namespace Iterators {

64 65 66 67 68 69
template<class Mesh, class CenterEntityHandle>
class GenericCirculator_CenterEntityFnsT {
    public:
        static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter);
        static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter);
};
Jan Möbius's avatar
Jan Möbius committed
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
template<class Mesh>
class GenericCirculator_CenterEntityFnsT<Mesh, typename Mesh::VertexHandle> {
    public:
        inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            heh = mesh->cw_rotated_halfedge_handle(heh);
            if (heh == start) ++lap_counter;
        }
        inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            if (heh == start) --lap_counter;
            heh = mesh->ccw_rotated_halfedge_handle(heh);
        }
};

template<class Mesh>
class GenericCirculator_CenterEntityFnsT<Mesh, typename Mesh::FaceHandle> {
    public:
        inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            heh = mesh->next_halfedge_handle(heh);
            if (heh == start) ++lap_counter;
        }
        inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            if (heh == start) --lap_counter;
            heh = mesh->prev_halfedge_handle(heh);
        }
};

template<class Mesh, class CenterEntityHandle, class ValueHandle>
class GenericCirculator_ValueHandleFnsT {
    public:
        inline static bool is_valid(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
            return heh.is_valid() && ((start != heh) || (lap_counter == 0));
        }
        inline static void init(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {};
        inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::increment(mesh, heh, start, lap_counter);
        }
        inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::decrement(mesh, heh, start, lap_counter);
        }
};

template<class Mesh, class CenterEntityHandle>
class GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, typename Mesh::FaceHandle> {
    public:
        inline static bool is_valid(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
            return heh.is_valid() && ((start != heh) || (lap_counter == 0));
        }
        inline static void init(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            if (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid())
                increment(mesh, heh, start, lap_counter);
        };
        inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            do {
                GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::increment(mesh, heh, start, lap_counter);
            } while (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid());
        }
        inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
            do {
                GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::decrement(mesh, heh, start, lap_counter);
            } while (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid());
        }
};
Jan Möbius's avatar
Jan Möbius committed
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
template<class Mesh>
class GenericCirculatorBaseT {
    public:
        typedef const Mesh* mesh_ptr;
        typedef const Mesh& mesh_ref;

    public:
        GenericCirculatorBaseT() : mesh_(0), lap_counter_(0) {}

        GenericCirculatorBaseT(mesh_ref mesh, HalfedgeHandle heh, bool end = false) :
            mesh_(&mesh), start_(heh), heh_(heh), lap_counter_(static_cast<int>(end)) {}

        GenericCirculatorBaseT(const GenericCirculatorBaseT &rhs) :
            mesh_(rhs.mesh_), start_(rhs.start_), heh_(rhs.heh_), lap_counter_(rhs.lap_counter_) {}

        inline typename Mesh::FaceHandle toFaceHandle() const {
            return mesh_->face_handle(heh_);
        }

        inline typename Mesh::EdgeHandle toEdgeHandle() const {
            return mesh_->edge_handle(heh_);
        }

        inline typename Mesh::HalfedgeHandle toHalfedgeHandle() const {
            return heh_;
        }

        inline typename Mesh::HalfedgeHandle toOppositeHalfedgeHandle() const {
            return mesh_->opposite_halfedge_handle(heh_);
        }

        inline typename Mesh::VertexHandle toVertexHandle() const {
            return mesh_->to_vertex_handle(heh_);
        }

        inline GenericCirculatorBaseT &operator=(const GenericCirculatorBaseT &rhs) {
            mesh_ = rhs.mesh_;
            start_ = rhs.start_;
            heh_ = rhs.heh_;
            lap_counter_ = rhs.lap_counter_;
            return *this;
        }

        inline bool operator==(const GenericCirculatorBaseT &rhs) const {
            return mesh_ == rhs.mesh_ && start_ == rhs.start_ && heh_ == rhs.heh_ && lap_counter_ == rhs.lap_counter_;
        }

        inline bool operator!=(const GenericCirculatorBaseT &rhs) const {
            return !operator==(rhs);
        }

    protected:
        mesh_ptr mesh_;
        typename Mesh::HalfedgeHandle start_, heh_;
        int lap_counter_;
};
Jan Möbius's avatar
Jan Möbius committed
190

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
template<class Mesh, class CenterEntityHandle, class ValueHandle,
//        void (GenericCirculatorBaseT<Mesh>::*Increment)(),
//        void (GenericCirculatorBaseT<Mesh>::*Decrement)(),
        ValueHandle (GenericCirculatorBaseT<Mesh>::*Handle2Value)() const>
class GenericCirculatorT : protected GenericCirculatorBaseT<Mesh> {
    public:
        typedef std::ptrdiff_t difference_type;
        typedef ValueHandle value_type;
        typedef const value_type& reference;
        typedef const value_type* pointer;
        typedef std::bidirectional_iterator_tag iterator_category;

        typedef typename GenericCirculatorBaseT<Mesh>::mesh_ptr mesh_ptr;
        typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref;
        typedef GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, ValueHandle> GenericCirculator_ValueHandleFns;

    public:
        GenericCirculatorT() {}
        GenericCirculatorT(mesh_ref mesh, CenterEntityHandle start, bool end = false) :
            GenericCirculatorBaseT<Mesh>(mesh, mesh.halfedge_handle(start), end) {

            GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
        }
        GenericCirculatorT(mesh_ref mesh, HalfedgeHandle heh, bool end = false) :
            GenericCirculatorBaseT<Mesh>(mesh, heh, end) {

            GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
        }
        GenericCirculatorT(const GenericCirculatorT &rhs) : GenericCirculatorBaseT<Mesh>(rhs) {}

        GenericCirculatorT& operator++() {
            assert(this->mesh_);
            GenericCirculator_ValueHandleFns::increment(this->mesh_, this->heh_, this->start_, this->lap_counter_);
            return *this;
        }
        GenericCirculatorT& operator--() {
            assert(this->mesh_);
            GenericCirculator_ValueHandleFns::decrement(this->mesh_, this->heh_, this->start_, this->lap_counter_);
            return *this;
        }

        /// Post-increment
        GenericCirculatorT operator++(int) {
            assert(this->mesh_);
            GenericCirculatorT cpy(*this);
            ++(*this);
            return cpy;
        }

        /// Post-decrement
        GenericCirculatorT operator--(int) {
            assert(this->mesh_);
            GenericCirculatorT cpy(*this);
            --(*this);
            return cpy;
        }

        /// Standard dereferencing operator.
        value_type operator*() const {
            return (this->*Handle2Value)();
        }

        /// Standard pointer operator.
        value_type operator->() const {
            return (this->*Handle2Value)();
        }

        GenericCirculatorT &operator=(const GenericCirculatorT &rhs) {
            GenericCirculatorBaseT<Mesh>::operator=(rhs);
            return *this;
        };

        bool operator==(const GenericCirculatorT &rhs) const {
            return GenericCirculatorBaseT<Mesh>::operator==(rhs);
        }

        bool operator!=(const GenericCirculatorT &rhs) const {
            return GenericCirculatorBaseT<Mesh>::operator!=(rhs);
        }

        bool is_valid() const {
            return GenericCirculator_ValueHandleFns::is_valid(this->mesh_, this->heh_, this->start_, this->lap_counter_);
        }

        DEPRECATED("current_halfedge_handle() is an implementation detail and should not be accessed from outside the iterator class.")
        const HalfedgeHandle &current_halfedge_handle() const {
            return this->heh_;
        }

        DEPRECATED("Do not use this error prone implicit cast. Compare to end-iterator, instead.")
        operator bool() const {
            return is_valid();
        }

        /// Return the handle of the current target.
        DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
        value_type handle() const {
          return **this;
        }

        /// Cast to the handle of the current target.
        DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
        operator value_type() const {
          return **this;
        }
};
Jan Möbius's avatar
Jan Möbius committed
297

298
//== FORWARD DECLARATIONS =====================================================
Jan Möbius's avatar
Jan Möbius committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

template <class Mesh> class FaceVertexIterT;
template <class Mesh> class FaceHalfedgeIterT;
template <class Mesh> class FaceEdgeIterT;
template <class Mesh> class FaceFaceIterT;

template <class Mesh> class ConstFaceVertexIterT;
template <class Mesh> class ConstFaceHalfedgeIterT;
template <class Mesh> class ConstFaceEdgeIterT;
template <class Mesh> class ConstFaceFaceIterT;

//== CLASS DEFINITION =========================================================


/** \class FaceVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class FaceVertexIterT
{
 public:


  //--- Typedefs ---

325
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
326

327 328
  typedef typename Mesh::Vertex             value_type;
  typedef typename Mesh::VertexHandle       value_handle;
Jan Möbius's avatar
Jan Möbius committed
329 330

#if 0
331
  typedef std::bidirectional_iterator_tag   iterator_category;
332
  typedef std::ptrdiff_t                    difference_type;
333 334 335 336
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Vertex&      reference;
  typedef const typename Mesh::Vertex*      pointer;
Jan Möbius's avatar
Jan Möbius committed
337
#else
338
  typedef std::bidirectional_iterator_tag   iterator_category;
339
  typedef std::ptrdiff_t                    difference_type;
340 341 342 343
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Vertex&            reference;
  typedef typename Mesh::Vertex*            pointer;
Jan Möbius's avatar
Jan Möbius committed
344 345 346 347 348
#endif



  /// Default constructor
349
  FaceVertexIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
350 351 352


  /// Construct with mesh and a typename Mesh::FaceHandle
353
  FaceVertexIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
354 355 356
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
357
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
358 359 360 361
  {  ; }


  /// Construct with mesh and start halfedge
362
  FaceVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
363 364 365
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
366
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
367 368 369 370 371 372 373 374
  {  ; }


  /// Copy constructor
  FaceVertexIterT(const FaceVertexIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
375
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
376 377 378 379 380 381 382 383 384
  {  ; }


  /// Assignment operator
  FaceVertexIterT& operator=(const FaceVertexIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
385
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
386 387 388 389 390 391 392 393 394 395
    return *this;
  }


#if 0
  /// construct from non-const circulator type
  FaceVertexIterT(const FaceVertexIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
396
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
397 398 399 400 401 402 403 404 405
  {  ; }


  /// assign from non-const circulator
  FaceVertexIterT& operator=(const FaceVertexIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
406
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
407 408 409 410 411 412 413 414 415 416
    return *this;
  }
#else
  friend class ConstFaceVertexIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const FaceVertexIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
Jan Möbius's avatar
Jan Möbius committed
417 418 419
            (start_  == _rhs.start_) &&
            (heh_    == _rhs.heh_) &&
            (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
420 421 422 423 424 425 426 427 428 429 430 431
  }


  /// Not equal ?
  bool operator!=(const FaceVertexIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  FaceVertexIterT& operator++() { 
    assert(mesh_);
432 433
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
434 435 436 437 438 439 440
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  FaceVertexIterT& operator--() {
    assert(mesh_);
441 442
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
    return *this;
  }


  /** Get the current halfedge. There are \c Vertex*Iters and \c
      Face*Iters.  For both the current state is defined by the
      current halfedge. This is what this method returns. 
  */
  HalfedgeHandle current_halfedge_handle() const {
    return heh_;
  }


  /// Return the handle of the current target.
  typename Mesh::VertexHandle handle() const {
    assert(mesh_);
    return mesh_->to_vertex_handle(heh_); 
  }


  /// Cast to the handle of the current target.
  operator typename Mesh::VertexHandle() const {
    assert(mesh_);
    return mesh_->to_vertex_handle(heh_); 
  }
    

  ///  Return a reference to the current target.
  reference operator*() const { 
    assert(mesh_);
    return mesh_->deref(handle());
  }


  /// Return a pointer to the current target.
  pointer operator->() const { 
    assert(mesh_);
    return &mesh_->deref(handle());
  }


  /** Returns whether the circulator is still valid.
      After one complete round around a vertex/face the circulator becomes
      invalid, i.e. this function will return \c false. Nevertheless you
      can continue circulating. This method just tells you whether you
      have completed the first round.
   */
  operator bool() const { 
491
    return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
Jan Möbius's avatar
Jan Möbius committed
492 493 494 495 496 497 498
  }


protected:

  mesh_ptr         mesh_;
  HalfedgeHandle   start_, heh_;
499
  int              lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
};



//== CLASS DEFINITION =========================================================

	      
/** \class ConstFaceVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class ConstFaceVertexIterT
{
 public:


  //--- Typedefs ---

519
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
520

521 522
  typedef typename Mesh::Vertex             value_type;
  typedef typename Mesh::VertexHandle       value_handle;
Jan Möbius's avatar
Jan Möbius committed
523 524

#if 1
525
  typedef std::bidirectional_iterator_tag   iterator_category;
526
  typedef std::ptrdiff_t                    difference_type;
527 528 529 530
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Vertex&      reference;
  typedef const typename Mesh::Vertex*      pointer;
Jan Möbius's avatar
Jan Möbius committed
531
#else
532
  typedef std::bidirectional_iterator_tag   iterator_category;
533
  typedef std::ptrdiff_t                    difference_type;
534 535 536 537
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Vertex&            reference;
  typedef typename Mesh::Vertex*            pointer;
Jan Möbius's avatar
Jan Möbius committed
538 539 540 541 542
#endif



  /// Default constructor
543
  ConstFaceVertexIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
544 545 546


  /// Construct with mesh and a typename Mesh::FaceHandle
547
  ConstFaceVertexIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
548 549 550
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
551
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
552 553 554 555
  {  ; }


  /// Construct with mesh and start halfedge
556
  ConstFaceVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
557 558 559
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
560
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
561 562 563 564 565 566 567 568
  {  ; }


  /// Copy constructor
  ConstFaceVertexIterT(const ConstFaceVertexIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
569
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
570 571 572 573 574 575 576 577 578
  {  ; }


  /// Assignment operator
  ConstFaceVertexIterT& operator=(const ConstFaceVertexIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
579
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
580 581 582 583 584 585 586 587 588 589
    return *this;
  }


#if 1
  /// construct from non-const circulator type
  ConstFaceVertexIterT(const FaceVertexIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
590
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
591 592 593 594 595 596 597 598 599
  {  ; }


  /// assign from non-const circulator
  ConstFaceVertexIterT& operator=(const FaceVertexIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
600
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
601 602 603 604 605 606 607 608 609 610 611 612
    return *this;
  }
#else
  friend class ConstFaceVertexIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const ConstFaceVertexIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
	    (start_  == _rhs.start_) &&
	    (heh_    == _rhs.heh_) &&
613
	    (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
614 615 616 617 618 619 620 621 622 623 624 625
  }


  /// Not equal ?
  bool operator!=(const ConstFaceVertexIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  ConstFaceVertexIterT& operator++() { 
    assert(mesh_);
626 627
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
628 629 630 631 632 633 634
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  ConstFaceVertexIterT& operator--() { 
    assert(mesh_);
635 636
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
    return *this;
  }


  /** Get the current halfedge. There are \c Vertex*Iters and \c
      Face*Iters.  For both the current state is defined by the
      current halfedge. This is what this method returns. 
  */
  HalfedgeHandle current_halfedge_handle() const {
    return heh_;
  }


  /// Return the handle of the current target.
  typename Mesh::VertexHandle handle() const {
    assert(mesh_);
    return mesh_->to_vertex_handle(heh_); 
  }


  /// Cast to the handle of the current target.
  operator typename Mesh::VertexHandle() const {
    assert(mesh_);
    return mesh_->to_vertex_handle(heh_); 
  }
    

  ///  Return a reference to the current target.
  reference operator*() const { 
    assert(mesh_);
    return mesh_->deref(handle());
  }


  /// Return a pointer to the current target.
  pointer operator->() const { 
    assert(mesh_);
    return &mesh_->deref(handle());
  }


  /** Returns whether the circulator is still valid.
      After one complete round around a vertex/face the circulator becomes
      invalid, i.e. this function will return \c false. Nevertheless you
      can continue circulating. This method just tells you whether you
      have completed the first round.
   */
  operator bool() const { 
685
    return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
Jan Möbius's avatar
Jan Möbius committed
686 687 688 689 690 691 692
  }


protected:

  mesh_ptr         mesh_;
  HalfedgeHandle   start_, heh_;
693
  int              lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
};



//== CLASS DEFINITION =========================================================

	      
/** \class FaceHalfedgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class FaceHalfedgeIterT
{
 public:


  //--- Typedefs ---

713
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
714 715

  typedef typename Mesh::Halfedge           value_type;
716
  typedef typename Mesh::HalfedgeHandle     value_handle;
Jan Möbius's avatar
Jan Möbius committed
717 718

#if 0
719
  typedef std::bidirectional_iterator_tag   iterator_category;
720
  typedef std::ptrdiff_t                    difference_type;
721 722 723 724
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Halfedge&    reference;
  typedef const typename Mesh::Halfedge*    pointer;
Jan Möbius's avatar
Jan Möbius committed
725
#else
726
  typedef std::bidirectional_iterator_tag   iterator_category;
727
  typedef std::ptrdiff_t                    difference_type;
728 729 730 731
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Halfedge&          reference;
  typedef typename Mesh::Halfedge*          pointer;
Jan Möbius's avatar
Jan Möbius committed
732 733 734 735 736
#endif



  /// Default constructor
737
  FaceHalfedgeIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
738 739 740


  /// Construct with mesh and a typename Mesh::FaceHandle
741
  FaceHalfedgeIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
742 743 744
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
745
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
746 747 748 749
  {  ; }


  /// Construct with mesh and start halfedge
750
  FaceHalfedgeIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
751 752 753
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
754
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
755 756 757 758 759 760 761 762
  {  ; }


  /// Copy constructor
  FaceHalfedgeIterT(const FaceHalfedgeIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
763
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
764 765 766 767 768 769 770 771 772
  {  ; }


  /// Assignment operator
  FaceHalfedgeIterT& operator=(const FaceHalfedgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
773
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
774 775 776 777 778 779 780 781 782 783
    return *this;
  }


#if 0
  /// construct from non-const circulator type
  FaceHalfedgeIterT(const FaceHalfedgeIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
784
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
785 786 787 788 789 790 791 792 793
  {  ; }


  /// assign from non-const circulator
  FaceHalfedgeIterT& operator=(const FaceHalfedgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
794
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
795 796 797 798 799 800 801 802 803 804 805 806
    return *this;
  }
#else
  friend class ConstFaceHalfedgeIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const FaceHalfedgeIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
	    (start_  == _rhs.start_) &&
	    (heh_    == _rhs.heh_) &&
807
	    (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
808 809 810 811 812 813 814 815 816 817 818 819
  }


  /// Not equal ?
  bool operator!=(const FaceHalfedgeIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  FaceHalfedgeIterT& operator++() { 
    assert(mesh_);
820 821
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
822 823 824 825 826 827 828
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  FaceHalfedgeIterT& operator--() { 
    assert(mesh_);
829 830
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
    return *this;
  }


  /** Get the current halfedge. There are \c Vertex*Iters and \c
      Face*Iters.  For both the current state is defined by the
      current halfedge. This is what this method returns.
  */
  HalfedgeHandle current_halfedge_handle() const {
    return heh_;
  }


  /// Return the handle of the current target.
  typename Mesh::HalfedgeHandle handle() const {
    assert(mesh_);
    return heh_; 
  }


  /// Cast to the handle of the current target.
  operator typename Mesh::HalfedgeHandle() const {
    assert(mesh_);
    return heh_; 
  }
    

  ///  Return a reference to the current target.
  reference operator*() const { 
    assert(mesh_);
    return mesh_->deref(handle());
  }


  /// Return a pointer to the current target.
  pointer operator->() const { 
    assert(mesh_);
    return &mesh_->deref(handle());
  }


  /** Returns whether the circulator is still valid.
      After one complete round around a vertex/face the circulator becomes
      invalid, i.e. this function will return \c false. Nevertheless you
      can continue circulating. This method just tells you whether you
      have completed the first round.
   */
  operator bool() const { 
879
    return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
Jan Möbius's avatar
Jan Möbius committed
880 881 882 883 884 885 886
  }


protected:

  mesh_ptr         mesh_;
  HalfedgeHandle   start_, heh_;
887
  int              lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
};



//== CLASS DEFINITION =========================================================

	      
/** \class ConstFaceHalfedgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class ConstFaceHalfedgeIterT
{
 public:


  //--- Typedefs ---

907
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
908 909

  typedef typename Mesh::Halfedge           value_type;
910
  typedef typename Mesh::HalfedgeHandle     value_handle;
Jan Möbius's avatar
Jan Möbius committed
911 912

#if 1
913
  typedef std::bidirectional_iterator_tag   iterator_category;
914
  typedef std::ptrdiff_t                    difference_type;
915 916 917 918
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Halfedge&    reference;
  typedef const typename Mesh::Halfedge*    pointer;
Jan Möbius's avatar
Jan Möbius committed
919
#else
920
  typedef std::bidirectional_iterator_tag   iterator_category;
921
  typedef std::ptrdiff_t                    difference_type;
922 923 924 925
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Halfedge&          reference;
  typedef typename Mesh::Halfedge*          pointer;
Jan Möbius's avatar
Jan Möbius committed
926 927 928 929 930
#endif



  /// Default constructor
931
  ConstFaceHalfedgeIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
932 933 934


  /// Construct with mesh and a typename Mesh::FaceHandle
935
  ConstFaceHalfedgeIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
936 937 938
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
939
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
940 941 942 943
  {  ; }


  /// Construct with mesh and start halfedge
944
  ConstFaceHalfedgeIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
945 946 947
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
948
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
949 950 951 952 953 954 955 956
  {  ; }


  /// Copy constructor
  ConstFaceHalfedgeIterT(const ConstFaceHalfedgeIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
957
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
958 959 960 961 962 963 964 965 966
  {  ; }


  /// Assignment operator
  ConstFaceHalfedgeIterT& operator=(const ConstFaceHalfedgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
967
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
968 969 970 971 972 973 974 975 976 977
    return *this;
  }


#if 1
  /// construct from non-const circulator type
  ConstFaceHalfedgeIterT(const FaceHalfedgeIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
978
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
979 980 981 982 983 984 985 986 987
  {  ; }


  /// assign from non-const circulator
  ConstFaceHalfedgeIterT& operator=(const FaceHalfedgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
988
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
989 990 991 992 993 994 995 996 997 998 999 1000
    return *this;
  }
#else
  friend class ConstFaceHalfedgeIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const ConstFaceHalfedgeIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
	    (start_  == _rhs.start_) &&
	    (heh_    == _rhs.heh_) &&
1001
	    (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
  }


  /// Not equal ?
  bool operator!=(const ConstFaceHalfedgeIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  ConstFaceHalfedgeIterT& operator++() { 
    assert(mesh_);
1014 1015
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
1016 1017 1018 1019 1020 1021 1022
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  ConstFaceHalfedgeIterT& operator--() { 
    assert(mesh_);
1023 1024
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    return *this;
  }


  /** Get the current halfedge. There are \c Vertex*Iters and \c
      Face*Iters.  For both the current state is defined by the
      current halfedge. This is what this method returns. 
  */
  HalfedgeHandle current_halfedge_handle() const {
    return heh_;
  }


  /// Return the handle of the current target.
  typename Mesh::HalfedgeHandle handle() const {
    assert(mesh_);
    return heh_; 
  }


  /// Cast to the handle of the current target.
  operator typename Mesh::HalfedgeHandle() const {
    assert(mesh_);
    return heh_; 
  }
    

  ///  Return a reference to the current target.
  reference operator*() const { 
    assert(mesh_);
    return mesh_->deref(handle());
  }


  /// Return a pointer to the current target.
  pointer operator->() const { 
    assert(mesh_);
    return &mesh_->deref(handle());
  }


  /** Returns whether the circulator is still valid.
      After one complete round around a vertex/face the circulator becomes
      invalid, i.e. this function will return \c false. Nevertheless you
      can continue circulating. This method just tells you whether you
      have completed the first round.
   */
  operator bool() const { 
1073
    return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
Jan Möbius's avatar
Jan Möbius committed
1074 1075 1076 1077 1078 1079 1080
  }


protected:

  mesh_ptr         mesh_;
  HalfedgeHandle   start_, heh_;
1081
  int              lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
};



//== CLASS DEFINITION =========================================================

	      
/** \class FaceEdgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class FaceEdgeIterT
{
 public:


  //--- Typedefs ---

1101
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
1102

1103
  typedef typename Mesh::Edge               value_type;
Jan Möbius's avatar
Jan Möbius committed
1104 1105 1106
  typedef typename Mesh::EdgeHandle         value_handle;

#if 0
1107
  typedef std::bidirectional_iterator_tag   iterator_category;
1108
  typedef std::ptrdiff_t                    difference_type;
1109 1110 1111 1112
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Edge&        reference;
  typedef const typename Mesh::Edge*        pointer;
Jan Möbius's avatar
Jan Möbius committed
1113
#else
1114
  typedef std::bidirectional_iterator_tag   iterator_category;
1115
  typedef std::ptrdiff_t                    difference_type;
1116 1117 1118 1119
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Edge&              reference;
  typedef typename Mesh::Edge*              pointer;
Jan Möbius's avatar
Jan Möbius committed
1120 1121 1122 1123 1124
#endif



  /// Default constructor
1125
  FaceEdgeIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
1126 1127 1128


  /// Construct with mesh and a typename Mesh::FaceHandle
1129
  FaceEdgeIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
1130 1131 1132
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
1133
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
1134 1135 1136 1137
  {  ; }


  /// Construct with mesh and start halfedge
1138
  FaceEdgeIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
1139 1140 1141
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
1142
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
1143 1144 1145 1146 1147 1148 1149 1150
  {  ; }


  /// Copy constructor
  FaceEdgeIterT(const FaceEdgeIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
1151
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
1152 1153 1154 1155 1156 1157 1158 1159 1160
  {  ; }


  /// Assignment operator
  FaceEdgeIterT& operator=(const FaceEdgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
1161
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
    return *this;
  }


#if 0
  /// construct from non-const circulator type
  FaceEdgeIterT(const FaceEdgeIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
1172
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
1173 1174 1175 1176 1177 1178 1179 1180 1181
  {  ; }


  /// assign from non-const circulator
  FaceEdgeIterT& operator=(const FaceEdgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
1182
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
    return *this;
  }
#else
  friend class ConstFaceEdgeIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const FaceEdgeIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
	    (start_  == _rhs.start_) &&
	    (heh_    == _rhs.heh_) &&
1195
	    (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
  }


  /// Not equal ?
  bool operator!=(const FaceEdgeIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  FaceEdgeIterT& operator++() { 
    assert(mesh_);
1208 1209
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
1210 1211 1212 1213 1214 1215 1216
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  FaceEdgeIterT& operator--() { 
    assert(mesh_);
1217 1218
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
    return *this;
  }


  /** Get the current halfedge. There are \c Vertex*Iters and \c
      Face*Iters.  For both the current state is defined by the
      current halfedge. This is what this method returns. 
  */
  HalfedgeHandle current_halfedge_handle() const {
    return heh_;
  }


  /// Return the handle of the current target.
  typename Mesh::EdgeHandle handle() const {
    assert(mesh_);
    return mesh_->edge_handle(heh_); 
  }


  /// Cast to the handle of the current target.
  operator typename Mesh::EdgeHandle() const {
    assert(mesh_);
    return mesh_->edge_handle(heh_); 
  }
    

  ///  Return a reference to the current target.
  reference operator*() const { 
    assert(mesh_);
    return mesh_->deref(handle());
  }


  /// Return a pointer to the current target.
  pointer operator->() const { 
    assert(mesh_);
    return &mesh_->deref(handle());
  }


  /** Returns whether the circulator is still valid.
      After one complete round around a vertex/face the circulator becomes
      invalid, i.e. this function will return \c false. Nevertheless you
      can continue circulating. This method just tells you whether you
      have completed the first round.
   */
  operator bool() const { 
1267
    return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
Jan Möbius's avatar
Jan Möbius committed
1268 1269 1270 1271 1272 1273 1274
  }


protected:

  mesh_ptr         mesh_;
  HalfedgeHandle   start_, heh_;
1275
  int              lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
};



//== CLASS DEFINITION =========================================================

	      
/** \class ConstFaceEdgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
    Circulator.
*/

template <class Mesh>
class ConstFaceEdgeIterT
{
 public:


  //--- Typedefs ---

1295
  typedef typename Mesh::HalfedgeHandle     HalfedgeHandle;
Jan Möbius's avatar
Jan Möbius committed
1296

1297
  typedef typename Mesh::Edge               value_type;
Jan Möbius's avatar
Jan Möbius committed
1298 1299 1300
  typedef typename Mesh::EdgeHandle         value_handle;

#if 1
1301
  typedef std::bidirectional_iterator_tag   iterator_category;
1302
  typedef std::ptrdiff_t                    difference_type;
1303 1304 1305 1306
  typedef const Mesh&                       mesh_ref;
  typedef const Mesh*                       mesh_ptr;
  typedef const typename Mesh::Edge&        reference;
  typedef const typename Mesh::Edge*        pointer;
Jan Möbius's avatar
Jan Möbius committed
1307
#else
1308
  typedef std::bidirectional_iterator_tag   iterator_category;
1309
  typedef std::ptrdiff_t                    difference_type;
1310 1311 1312 1313
  typedef Mesh&                             mesh_ref;
  typedef Mesh*                             mesh_ptr;
  typedef typename Mesh::Edge&              reference;
  typedef typename Mesh::Edge*              pointer;
Jan Möbius's avatar
Jan Möbius committed
1314 1315 1316 1317 1318
#endif



  /// Default constructor
1319
  ConstFaceEdgeIterT() : mesh_(0), lap_counter_(false) {}
Jan Möbius's avatar
Jan Möbius committed
1320 1321 1322


  /// Construct with mesh and a typename Mesh::FaceHandle
1323
  ConstFaceEdgeIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
1324 1325 1326
    mesh_(&_mesh), 
    start_(_mesh.halfedge_handle(_start)),
    heh_(start_),
1327
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
1328 1329 1330 1331
  {  ; }


  /// Construct with mesh and start halfedge
1332
  ConstFaceEdgeIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
Jan Möbius's avatar
Jan Möbius committed
1333 1334 1335
    mesh_(&_mesh),
    start_(_heh),
    heh_(_heh),
1336
    lap_counter_(_end)
Jan Möbius's avatar
Jan Möbius committed
1337 1338 1339 1340 1341 1342 1343 1344
  {  ; }


  /// Copy constructor
  ConstFaceEdgeIterT(const ConstFaceEdgeIterT& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
1345
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
1346 1347 1348 1349 1350 1351 1352 1353 1354
  {  ; }


  /// Assignment operator
  ConstFaceEdgeIterT& operator=(const ConstFaceEdgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
1355
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
    return *this;
  }


#if 1
  /// construct from non-const circulator type
  ConstFaceEdgeIterT(const FaceEdgeIterT<Mesh>& _rhs) :
    mesh_(_rhs.mesh_),
    start_(_rhs.start_),
    heh_(_rhs.heh_),
1366
    lap_counter_(_rhs.lap_counter_)
Jan Möbius's avatar
Jan Möbius committed
1367 1368 1369 1370 1371 1372 1373 1374 1375
  {  ; }


  /// assign from non-const circulator
  ConstFaceEdgeIterT& operator=(const FaceEdgeIterT<Mesh>& _rhs)
  {
    mesh_   = _rhs.mesh_;
    start_  = _rhs.start_;
    heh_    = _rhs.heh_;
1376
    lap_counter_ = _rhs.lap_counter_;
Jan Möbius's avatar
Jan Möbius committed
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
    return *this;
  }
#else
  friend class ConstFaceEdgeIterT<Mesh>;
#endif  


  /// Equal ?
  bool operator==(const ConstFaceEdgeIterT& _rhs) const {
    return ((mesh_   == _rhs.mesh_) &&
	    (start_  == _rhs.start_) &&
	    (heh_    == _rhs.heh_) &&
1389
	    (lap_counter_ == _rhs.lap_counter_));
Jan Möbius's avatar
Jan Möbius committed
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
  }


  /// Not equal ?
  bool operator!=(const ConstFaceEdgeIterT& _rhs) const {
    return !operator==(_rhs);
  }


  /// Pre-Increment (next cw target)
  ConstFaceEdgeIterT& operator++() { 
    assert(mesh_);
1402 1403
    heh_=mesh_->next_halfedge_handle(heh_);
    if(heh_ == start_) lap_counter_++;
Jan Möbius's avatar
Jan Möbius committed
1404 1405 1406 1407 1408 1409 1410
    return *this;
  }


  /// Pre-Decrement (next ccw target)
  ConstFaceEdgeIterT& operator--() { 
    assert(mesh_);
1411 1412
    if(heh_ == start_) lap_counter_--;
    heh_=mesh_->prev_halfedge_handle(heh_);
Jan Möbius's avatar
Jan Möbius committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432