vertex.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 <cassert>
00026 #include <iostream>
00027 #include "vertex.h"
00028 #include "halfedge.h"
00029 #include "face.h"
00030 
00031 using namespace std;
00032 using namespace Geometry;
00033 using namespace HE;
00034 
00035 
00036 Vector3Df Vertex::normal() const
00037 {
00038         const_edge_circulator e = begin();
00039         const_edge_circulator sentinel = e;
00040 
00041         Vector3Df N(0,0,0);
00042         do
00043         {
00044                 assert(this != (*e)->dst());
00045                 Vector3Df v((*e)->tangent());
00046                 ++e;
00047                 
00048                 // Do not use the normal of faces which are actually holes
00049                 if ((*e)->face()->hole())
00050                         continue;
00051 
00052                 Vector3Df v2((*e)->tangent());
00053                 float a = v.angle(v2);
00054                 Vector3Df n = v2 ^ v;
00055                 N += a*n;
00056         } while (e != sentinel) ;
00057 
00058         N.normalize();
00059         return N;
00060 }
00061 
00062 
00063 ostream& HE::operator<< (ostream& out, const Vertex& v)
00064 {
00065         //return out << '[' << v.index() << ": " << v.position() << ", e" << v.edge() << ']';
00066         return out << '[' << v.index() << ": " << v.position() << ']';
00067 }
00068 
00069 int Vertex::valence() const
00070 {
00071         const_edge_circulator e = begin();
00072         const_edge_circulator sentinel = e;
00073 
00074         int n(0);
00075         do
00076         {
00077                 n++;
00078                 ++e;
00079         } while (e != sentinel) ;
00080 
00081         return n;
00082 }
00083 
00084 
00085 HalfEdge* Vertex::edgeTo(int v)
00086 {
00087   edge_circulator e = begin();
00088   edge_circulator sentinel = e;
00089 
00090   do
00091   {
00092     if (v == (*e)->dst()->index())
00093       return *e;
00094     ++e;
00095   } while (e != sentinel) ;
00096 
00097   return 0;
00098 }
00099 
00100 const HalfEdge* Vertex::edgeTo(int v) const
00101 {
00102   const_edge_circulator e = begin();
00103   const_edge_circulator sentinel = e;
00104 
00105   do
00106   {
00107     if (v == (*e)->dst()->index())
00108       return *e;
00109     ++e;
00110   } while (e != sentinel) ;
00111 
00112   return 0;
00113 }
00114 
00115 
00116 void Vertex::edge_circulator::operator++()
00117 {
00118         _here = _here->twin()->next();
00119 }
00120 
00121 void Vertex::const_edge_circulator::operator++()
00122 {
00123         _here = _here->twin()->next();
00124 }
00125 
00126 
00127 bool Vertex::isBoundary() const
00128 {
00129   const_edge_circulator e = begin();
00130   const_edge_circulator sentinel = e;
00131 
00132   do
00133   {
00134     if ((*e)->isBoundary())
00135       return true;
00136     ++e;
00137   } while (e != sentinel) ;
00138 
00139   return false;  
00140 }
00141 

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