$search
00001 /* 00002 James R. Diebel 00003 Stanford University 00004 00005 Started: 27 August 2004 00006 Last revised: 27 Sugust 2004 00007 00008 face.cc - class implementation of Face class (face.hh) 00009 00010 Depends on face.hh 00011 */ 00012 00013 #include "bmtk/face.hh" 00014 00015 namespace bmtk { 00016 00017 // Constructor/Destructor 00018 Face::Face() { 00019 nf = ne = 0; 00020 i = -1; 00021 bound = false; 00022 flag = -1; 00023 } 00024 Face::~Face() { 00025 if (m) if (m->nd) delete [] ns; 00026 } 00027 00028 // Member functions 00029 void Face::findNormal() { 00030 n = (v[1]->x - v[0]->x).cross(v[2]->x - v[0]->x); 00031 s = 0.5*~n; 00032 n.normalize(); 00033 } 00034 00035 void Face::findCenter() { 00036 x = (v[0]->x + v[1]->x + v[2]->x)/3; 00037 } 00038 00039 void Face::findDistance() { 00040 d = x.dot(n); 00041 } 00042 00043 void Face::findArea() { 00044 s = 0.5*~((v[1]->x - v[0]->x).cross(v[2]->x - v[0]->x)); 00045 } 00046 00047 void Face::blur() { 00048 n = nr; 00049 for (int j=0;j<nf;j++) n += f[j]->nr; 00050 n.normalize(); 00051 } 00052 00053 int Face::indexOf(Vert& vp) { 00054 if (v[0] == &vp) return 0; 00055 if (v[1] == &vp) return 1; 00056 if (v[2] == &vp) return 2; 00057 return -1; 00058 } 00059 00060 // Membership tests 00061 bool operator < (Vert &vp, Face &fp) { 00062 return (fp.v[0] == &vp || fp.v[1] == &vp || fp.v[2] == &vp); 00063 } 00064 bool operator < (Edge &ep, Face &fp) { 00065 return ((fp.v[0] == ep.v[0] || fp.v[1] == ep.v[0] || fp.v[2] == ep.v[0]) && 00066 (fp.v[0] == ep.v[1] || fp.v[1] == ep.v[1] || fp.v[2] == ep.v[1])); 00067 } 00068 00069 // Define << operator to handle output to screen 00070 ostream& operator << (ostream& os, const Face &f) { 00071 return os<<"f"<<f.i<<": "<<f.v[0]->i<<", "<<f.v[1]->i 00072 <<", "<<f.v[2]->i<<" ("<<f.nf<<", "<<f.ne<<")"<<endl<<flush; 00073 } 00074 00075 } // namespace bmtk