halfedge.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 __HALFEDGE_H__
00022 #define __HALFEDGE_H__
00023 
00024 #include <ostream>
00025 #include "vector3.h"
00026 
00027 namespace HE
00028 {
00029         class Vertex;
00030         class Face;
00031         
00042         class HalfEdge
00043         {
00044                 public:
00046                         explicit HalfEdge(Vertex* v, Face* f, HalfEdge* t, HalfEdge* n)
00047                         : _dst(v), _face(f), _twin(t), _next(n) {}
00049                         explicit HalfEdge(Vertex* v, Face* f)
00050                         : _dst(v), _face(f), _twin(0), _next(0) {}
00051                         
00052                         // Set methods
00053                         void next(HalfEdge* n) { _next = n; } 
00054                         void twin(HalfEdge* p) { _twin = p; } 
00055                         void face(Face* f) { _face = f; }     
00056                         void dst(Vertex* v) { _dst = v; }     
00057                         
00058                         // Get methods
00059                         HalfEdge* next() { return _next; }             
00060                         const HalfEdge* next() const { return _next; } 
00061                         HalfEdge* prev();                              
00062                         const HalfEdge* prev() const;                  
00063                         HalfEdge* twin() { return _twin; }             
00064                         const HalfEdge* twin() const { return _twin; } 
00065                         Face* face() { return _face; }                 
00066                         const Face* face() const { return _face; }     
00067                         Vertex* dst() { return _dst; }                 
00068                         const Vertex* dst() const { return _dst; }     
00069 
00071          Vertex* src() { return _twin->dst(); }
00073          const Vertex* src() const { return _twin->dst(); }
00074                         
00075                         // Simple computations
00076                         Geometry::Vector3Df normal() const;   
00077          Geometry::Vector3Df tangent() const;  
00078          Geometry::Vector3Df midpoint() const;  
00079          float squaredLength() const { return tangent().squaredModule(); } 
00080                         float length() const { return tangent().module(); }  
00081                         bool isBoundary() const;  
00082 
00083                 protected:
00084                         Vertex* _dst;
00085                         Face* _face;
00086                         HalfEdge* _twin;
00087                         HalfEdge* _next;
00088         };
00089         
00091         std::ostream& operator<< (std::ostream& out, const HalfEdge& he);
00092 };
00093 
00094 #endif // __HALFEDGE_H__

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