$search
00001 /* 00002 James R. Diebel 00003 Stanford University 00004 00005 Started: 27 August 2004 00006 Last revised: 27 Sugust 2004 00007 00008 edge.cc - class implementation of Edge class (edge.hh) 00009 00010 Depends on edge.hh 00011 */ 00012 00013 #include "bmtk/edge.hh" 00014 #include <math.h> 00015 00016 namespace bmtk { 00017 00018 // Constructor/Destructor 00019 Edge::Edge() { 00020 flag = nf = 0; i = -1; 00021 a = l = psi = 0.0; 00022 } 00023 Edge::~Edge() { 00024 } 00025 00026 // Member functions 00027 void Edge::findAngle() { 00028 if (nf == 2) a = acos(f[0]->n.dot(f[1]->n)); 00029 } 00030 00031 void Edge::findPotential() { 00032 if (nf == 2) { 00033 l = v[0]->x.distTo(v[1]->x); 00034 psi = m->psiSpline->evalf(1-f[0]->n.dot(f[1]->n)); 00035 } 00036 } 00037 00038 // finds gradient of psi WRT position of vertex i 00039 Vec3d Edge::gradient(Vert& vi) { 00040 Vec3d gradPsi; 00041 00042 if (nf == 2) { 00043 // Compute the gradient of potential WRT 00044 float dpsi_dy = m->psiSpline->evaldf(1-f[1]->n.dot(f[0]->n)); 00045 00046 int ivi0 = f[0]->indexOf(vi); 00047 if (ivi0 != -1) { 00048 Vec3d n0pn1 = f[0]->n - f[0]->n.dot(f[1]->n)*f[1]->n; 00049 gradPsi += dpsi_dy*n0pn1.cross(f[0]->v[(ivi0 + 2)%3]->x - 00050 f[0]->v[(ivi0 + 1)%3]->x); 00051 } 00052 00053 int ivi1 = f[1]->indexOf(vi); 00054 if (ivi1 != -1) { 00055 Vec3d n1pn0 = f[1]->n - f[1]->n.dot(f[0]->n)*f[0]->n; 00056 gradPsi += dpsi_dy*n1pn0.cross(f[1]->v[(ivi1 + 2)%3]->x - 00057 f[1]->v[(ivi1 + 1)%3]->x); 00058 } 00059 } 00060 00061 return gradPsi; 00062 } 00063 00064 void Edge::findLength() { 00065 l = v[0]->x.distTo(v[1]->x); 00066 } 00067 00068 int Edge::indexOf(Vert& vp) { 00069 if (v[0] == &vp) return 0; 00070 if (v[1] == &vp) return 1; 00071 return -1; 00072 } 00073 00074 // Equality tests 00075 bool Edge::operator == (const Edge &e) const { 00076 return ((v[0] == e.v[0] && v[1] == e.v[1]) || 00077 (v[1] == e.v[0] && v[0] == e.v[1])); 00078 } 00079 bool Edge::operator != (const Edge &e) const { 00080 return ((v[0] != e.v[0] || v[1] != e.v[1]) && 00081 (v[1] != e.v[0] || v[0] != e.v[1])); 00082 } 00083 00084 // Membership tests 00085 bool operator < (Vert &vp, Edge &ep) { 00086 return (ep.v[0] == &vp || ep.v[1] == &vp); 00087 } 00088 00089 // Define << operator to handle output to screen 00090 ostream& operator << (ostream& os, const Edge &e) { 00091 return os<<"e"<<e.i<<": "<<e.v[0]->i<<", "<<e.v[1]->i<<endl<<flush; 00092 } 00093 00094 } // namespace bmtk