00001 #ifndef __JBXL_FACET_BASE_H_
00002 #define __JBXL_FACET_BASE_H_
00003
00011 #include <vector>
00012 #include <algorithm>
00013
00014 #include "Vector.h"
00015 #include "Rotation.h"
00016 #include "buffer.h"
00017
00018
00019 namespace jbxl {
00020
00021
00022 class FacetTriIndex;
00023 class FacetTriData;
00024
00025 class FacetBaseData;
00026 class TriPolyData;
00027
00028
00029 typedef std::vector<Vector<double> > FACET_VECTOR_ARRAY;
00030 typedef std::vector<Vector<float> > FACET_VECTOR_ARRAY32;
00031 typedef std::vector<FacetTriIndex> FACET_TRIINDX_ARRAY;
00032 typedef std::vector<FacetTriData> FACET_TRIDATA_ARRAY;
00033
00034
00035
00037
00038
00039
00040 class FacetTriIndex
00041 {
00042 public:
00043 int v1, v2, v3;
00044 int n1, n2, n3;
00045 int uv1, uv2, uv3;
00046
00047 public:
00048 FacetTriIndex(int w1=0,int w2=0,int w3=0,int m1=0,int m2=0,int m3=0) { init(w1,w2,w3,m1,m2,m3);}
00049 virtual ~FacetTriIndex(void) {}
00050
00051 void init(int w1=0,int w2=0,int w3=0,int m1=0,int m2=0,int m3=0,int u1=0,int u2=0,int u3=0) { set(w1,w2,w3,m1,m2,m3,u1,u2,u3);}
00052 void set (int w1=0,int w2=0,int w3=0,int m1=0,int m2=0,int m3=0,int u1=0,int u2=0,int u3=0);
00053 void mlt_set(int d1=0,int d2=0,int d3=0);
00054
00055 public:
00056 Vector<double> SurfaceNormal(FACET_VECTOR_ARRAY* coords) {
00057 Vector<double> normal = NewellMethod<double>((*coords)[v1],(*coords)[v2],(*coords)[v3]);
00058 return normal.normalize();
00059 }
00060
00061
00062 Vector<float> SurfaceNormal(FACET_VECTOR_ARRAY32* coords) {
00063 Vector<float> normal = NewellMethod<float>((*coords)[v1], (*coords)[v2], (*coords)[v3]);
00064 return normal.normalize();
00065 }
00066 };
00067
00068
00069
00071
00072
00073
00074 class FacetTriData
00075 {
00076 public:
00077 int facetNum;
00078
00079 Vector<double> v1, v2, v3;
00080 Vector<double> n1, n2, n3;
00081 UVMap<double> uv1, uv2, uv3;
00082
00083 public:
00084 FacetTriData(int n=0) { init(); facetNum = n;}
00085 virtual ~FacetTriData(void) {}
00086
00087 void init(void);
00088
00089 public:
00090 void execScale(double x, double y, double z);
00091 void execShift(double x, double y, double z) { Vector<double> m(x, y, z); v1 = v1 + m; v2 = v2 + m; v3 = v3 + m;}
00092 void execRotate(Quaternion<double> q);
00093 void ComputeTriNormal() { Vector<double> nv = NewellMethod(v1, v2, v3); nv.normalize(); n1 = n2 = n3 = nv;}
00094 };
00095
00096
00097
00098
00100
00101
00102
00103 class FacetBaseData
00104 {
00105 public:
00106 int num_index;
00107 int num_data;
00108 int vcount;
00109
00110 int* index;
00111 Vector<double>* vertex;
00112 Vector<double>* normal;
00113 UVMap<double>* texcrd;
00114
00115 public:
00116 FacetBaseData(int idx=0, int num=0) { init(idx, num);}
00117 virtual ~FacetBaseData(void) {}
00118
00119 void init(int idx=0, int num=0);
00120 void free(void);
00121 bool getm(void);
00122 void dup(FacetBaseData a);
00123
00124 public:
00125 void execScale(Vector<double> scale);
00126 void execShift(Vector<double> shift);
00127 void execRotate(Quaternion<double> quat);
00128 };
00129
00130
00131 inline void freeFacetBaseData(FacetBaseData*& facet) { if(facet!=NULL){ facet->free(); delete facet; facet = NULL;}}
00132
00133
00134
00136
00137
00138
00139 class TriPolyData
00140 {
00141 public:
00142 int facetNum;
00143 bool has_normal;
00144 bool has_texcrd;
00145
00146 Vector<double> vertex[3];
00147 Vector<double> normal[3];
00148 UVMap<double> texcrd[3];
00149
00150 public:
00151 TriPolyData(void) { init();}
00152 virtual ~TriPolyData(void) {}
00153
00154 void init(void);
00155 void free(void) { init();}
00156 void dup(TriPolyData a);
00157
00158 public:
00159 void execScale(Vector<double> scale);
00160 void execShift(Vector<double> shift);
00161 void execRotate(Quaternion<double> quat);
00162 };
00163
00164
00165 TriPolyData* dupTriPolyData(TriPolyData* data, int num);
00166 TriPolyData* joinTriPolyData(TriPolyData*& first, int num_f, TriPolyData*& next, int num_n);
00167
00168 inline void freeTriPolyData(TriPolyData*& tridata) { if(tridata!=NULL){ tridata->free(); delete tridata; tridata = NULL;}}
00169 void freeTriPolyData(TriPolyData*& tridata, int n);
00170
00171
00172
00173 }
00174
00175 #endif