vertex.h

00001 /***************************************************************************
00002 *   Copyright (C) 2007 by Pablo Diaz-Gutierrez   *
00003 *   pablo@ics.uci.edu   *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Library General Public License as       *
00007 *   published by the Free Software Foundation; either version 2 of the    *
00008 *   License, or (at your option) any later version.                       *
00009 *                                                                         *
00010 *   This program is distributed in the hope that it will be useful,       *
00011 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013 *   GNU General Public License for more details.                          *
00014 *                                                                         *
00015 *   You should have received a copy of the GNU Library General Public     *
00016 *   License along with this program; if not, write to the                 *
00017 *   Free Software Foundation, Inc.,                                       *
00018 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019 ***************************************************************************/
00020 
00021 #ifndef __VERTEX_H__
00022 #define __VERTEX_H__
00023 
00024 #include "vector3.h"
00025 
00026 
00027 namespace HE
00028 {
00029   class HalfEdge;
00030 
00032   class Vertex
00033   {
00034       public:
00036         class edge_circulator;
00037         class const_edge_circulator;
00038         class edge_circulator
00039         {
00040           friend class const_edge_circulator;
00041           public:
00042               edge_circulator(const Vertex* v, HalfEdge* h) : _base(v), _here(h) {}
00043 
00044             const Vertex* base() const { return _base; };
00045             HalfEdge* operator*() { return _here; }
00046             void operator++();
00047             void operator++(int) { ++(*this); }
00048             bool operator==(const edge_circulator& e) const { return _base==e._base && _here==e._here; }
00049             bool operator!=(const edge_circulator& e) const { return !(e == *this); }
00050           protected:
00051             const Vertex* _base;
00052             HalfEdge* _here;
00053         };
00054 
00056         class const_edge_circulator
00057         {
00058           friend class edge_circulator;
00059             public:
00060               const_edge_circulator(const Vertex* v, const HalfEdge* h) : _base(v), _here(h) {}
00061               const_edge_circulator(const edge_circulator& ec) : _base(ec.base()), _here(ec._here) {}
00062 
00063               const Vertex* base() const { return _base; };
00064               const HalfEdge* operator*() const { return _here; }
00065               void operator++();
00066               void operator++(int) { ++(*this); }
00067               bool operator==(const const_edge_circulator& e) const { return _base==e._base && _here==e._here; }
00068               bool operator!=(const const_edge_circulator& e) const { return !(e == *this); }
00069             protected:
00070               const Vertex* _base;
00071               const HalfEdge* _here;
00072         };
00073 
00075         edge_circulator begin() { return edge_circulator(this, _edge); }
00077         const_edge_circulator begin() const { return const_edge_circulator(this, _edge); }
00078 
00079         explicit Vertex(int i=-1) : _edge(0), _index(i) {}    
00080         explicit Vertex(const Geometry::Vector3Df& pos, int i=-1) : _pos(pos), _edge(0), _index(i) {}    
00081         explicit Vertex(const Geometry::Vector3Df& pos, HalfEdge* e, int i=-1) : _pos(pos), _edge(e), _index(i) {}  
00082 
00083         // Set methods
00084         void index(int i) { _index = i; } 
00085         void position(const Geometry::Vector3Df& pos) { _pos = pos; } 
00086         void edge(HalfEdge* e) { _edge = e; }  
00087 
00088         // Get methods
00089         int index() const { return _index; }  
00090         const Geometry::Vector3Df& position() const { return _pos; } 
00091         HalfEdge* edge() { return _edge; }              
00092         const HalfEdge* edge() const { return _edge; }  
00093 
00094         // Simple computations
00095         Geometry::Vector3Df normal() const;    
00096         int valence() const;    
00097         int degree() const { return valence(); }    
00098                   bool isBoundary() const;
00099         
00100         bool operator==(const Vertex& v) const { return _index == v._index; } 
00101 
00102         HalfEdge* edgeTo(const Vertex* v) { return edgeTo(v->index()); }
00104         const HalfEdge* edgeTo(const Vertex* v) const { return edgeTo(v->index()); }
00105 
00107         HalfEdge* edgeTo(int v);
00109         const HalfEdge* edgeTo(int v) const;
00110 
00111       protected:
00112         Geometry::Vector3Df _pos;
00113         HalfEdge* _edge;
00114         int _index;
00115   };
00116   
00118   std::ostream& operator<< (std::ostream& out, const Vertex& v);
00119 };
00120 
00121 #endif // __VERTEX_H__

Generated on Wed Apr 9 19:22:38 2008 for HalfEdge library by  doxygen 1.5.3