halfedge.cpp

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 #ifdef _WIN32
00022 #pragma warning(disable:4786)
00023 #endif
00024 
00025 #include <cstdio>
00026 #include <cassert>
00027 #include "halfedge.h"
00028 #include "face.h"
00029 #include "vertex.h"
00030 
00031 using namespace std;
00032 using namespace Geometry;
00033 using namespace HE;
00034 
00035 HalfEdge* HalfEdge::prev()
00036 {
00037         HalfEdge* he = _next;
00038         while (he->next() != this)
00039                 he = he->next();
00040 
00041         return he;
00042 }
00043 
00044 const HalfEdge* HalfEdge::prev() const
00045 {
00046         HalfEdge* he = _next;
00047         while (he->next() != this)
00048                 he = he->next();
00049 
00050         return he;
00051 }
00052 
00053 
00054 ostream& HE::operator<< (ostream& out, const HalfEdge& he)
00055 {
00056         char s[128];
00057         if (he.twin())
00058         {
00059                 if (he.src())
00060                         sprintf(s, "%d", he.src()->index());
00061                 else
00062                         strcpy(s, "NULL");
00063         }
00064         else
00065                 strcpy(s, "unreachable through twin");
00066 
00067         char d[128];
00068         if (he.dst())
00069                 sprintf(d, "%d", he.dst()->index());
00070         else
00071                 strcpy(d, "NULL");
00072 
00073         return out << "[(src " << s
00074                         << "), (dst " << d
00075                         << "), (face " << (int) he.face()
00076                         << "), (twin " << (int) he.twin()
00077                         << "), (next " << (int) he.next() << ")]";
00078 }
00079 
00080 Vector3Df HalfEdge::normal() const
00081 {
00082          return (src()->normal()+dst()->normal())/2;
00083 }
00084 
00085 
00086 Vector3Df HalfEdge::tangent() const 
00087 {
00088   return dst()->position() - src()->position(); 
00089 }
00090 
00091 Vector3Df HalfEdge::midpoint() const 
00092 {
00093   //return src()->position() + tangent()/2; 
00094   return (src()->position() + dst()->position()) / 2; 
00095 }
00096 
00097 bool HalfEdge::isBoundary() const
00098 {
00099          return face()->hole() || twin()->face()->hole();
00100 }
00101 

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