00001
00002
00003
00004
00005
00006
00007 #ifndef VERT_ATTRIB_H_IS_INCLUDED
00008 #define VERT_ATTRIB_H_IS_INCLUDED
00009
00010 #include "bface.H"
00011
00012
00013 template <typename AttType, typename RetType>
00014 class VertAttrib {
00015 public :
00016
00017 virtual ~VertAttrib() {}
00018
00019
00020 virtual AttType get_attrib(CBvert *v, CBface* f) = 0;
00021
00022
00023
00024
00025
00026 virtual RetType dFd(CBface* f, int dir)
00027 {
00028
00029
00030
00031
00032 AttType att1 = get_attrib(f->v1(),f);
00033 AttType att2 = get_attrib(f->v2(),f);
00034 AttType att3 = get_attrib(f->v3(),f);
00035
00036
00037
00038 Wvec A = f->v2()->wloc() - f->v1()->wloc();
00039 Wvec B = f->v3()->wloc() - f->v1()->wloc();
00040
00041 RetType delta1 = att2 - att1;
00042 RetType delta2 = att3 - att1;
00043
00044
00045 double a_T,b_T,c_T,d_T;
00046
00047
00048
00049
00050
00051 a_T = A[0]*A[0]+A[1]*A[1]+A[2]*A[2];
00052 b_T = A[0]*B[0]+A[1]*B[1]+A[2]*B[2];
00053 c_T = A[0]*B[0]+A[1]*B[1]+A[2]*B[2];
00054 d_T = B[0]*B[0]+B[1]*B[1]+B[2]*B[2];
00055
00056 double a_S,b_S,c_S,d_S,e_S,f_S;
00057 double det = 1.0 /(a_T * d_T - b_T * c_T);
00058
00059
00060
00061
00062
00063
00064
00065
00066 a_S = ((A[0] * d_T) + (B[0] * -c_T)) * det;
00067 b_S = ((A[0] * -b_T) + (B[0] * a_T)) * det;
00068
00069 c_S = ((A[1] * d_T) + (B[1] * -c_T)) * det;
00070 d_S = ((A[1] * -b_T) + (B[1] * a_T)) * det;
00071
00072 e_S = ((A[2] * d_T) + (B[2] * -c_T)) * det;
00073 f_S = ((A[2] * -b_T) + (B[2] * a_T)) * det;
00074
00075
00076 switch (dir)
00077 {
00078 case 0 :
00079 {
00080 return delta1 * a_S + delta2 * b_S;
00081 }
00082
00083 case 1 :
00084 {
00085 return delta1 * c_S + delta2 * d_S;
00086 }
00087
00088 case 2 :
00089 {
00090 return delta1 * e_S + delta2 * f_S;
00091 }
00092 }
00093
00094
00095
00096 return((delta1 * a_S + delta2 * b_S) +
00097 (delta1 * c_S + delta2 * d_S) +
00098 (delta1 * e_S + delta2 * f_S)) / 3.0;
00099
00100 }
00101
00102
00103 virtual RetType dFdx(CBface* f) {
00104
00105 return dFd(f,0);
00106
00107 }
00108
00109 virtual RetType dFdy(CBface* f) {
00110
00111 return dFd(f,1);
00112
00113 }
00114
00115 virtual RetType dFdz(CBface* f) {
00116
00117 return dFd(f,2);
00118
00119 }
00120 };
00121
00122 #endif // VERT_ATTRIB_H_IS_INCLUDED
00123
00124