00001 #ifndef __JBXL_BREP_H_
00002 #define __JBXL_BREP_H_
00003
00004
00016 #ifdef WIN32
00017 #pragma warning(disable:4251)
00018 #endif
00019
00020
00021 #include "ClassBox.h"
00022
00023 #include <list>
00024 #include <algorithm>
00025
00026 #include "Vector.h"
00027 #include "TVector.h"
00028
00029
00030
00031 namespace jbxl {
00032
00033
00034 class DllExport BREP_SOLID;
00035 class DllExport BREP_SHELL;
00036 class DllExport BREP_FACET;
00037 class DllExport BREP_CONTOUR;
00038 class DllExport BREP_EDGE;
00039 class DllExport BREP_WING;
00040 class DllExport BREP_VERTEX;
00041 class DllExport OctreeNode;
00042
00043 typedef std::list<BREP_SOLID*> BREP_SOLID_LIST;
00044 typedef std::list<BREP_SHELL*> BREP_SHELL_LIST;
00045 typedef std::list<BREP_FACET*> BREP_FACET_LIST;
00046 typedef std::list<BREP_CONTOUR*> BREP_CONTOUR_LIST;
00047 typedef std::list<BREP_EDGE*> BREP_EDGE_LIST;
00048 typedef std::list<BREP_WING*> BREP_WING_LIST;
00049 typedef std::list<BREP_VERTEX*> BREP_VERTEX_LIST;
00050
00051 DllExport BREP_WING* CreateWingWithoutContour(BREP_VERTEX* vertex1, BREP_VERTEX* vertex2);
00052 DllExport BREP_WING* GetWingOtherSide(BREP_WING* wing);
00053
00054 DllExport BREP_EDGE* FindEdge(BREP_VERTEX* vertex1, BREP_VERTEX* vertex2);
00055 DllExport BREP_EDGE* CreateEdge(BREP_VERTEX* v1, BREP_VERTEX* v2);
00056
00057 DllExport BREP_VERTEX* AddVertex2Octree(BREP_VERTEX* vertex, OctreeNode* octree, bool dupli=false);
00058 DllExport BREP_VERTEX** GetOctreeVertices(OctreeNode* octree, long int* vertexno);
00059 DllExport long int OctreeGetter(OctreeNode* p, BREP_VERTEX** vtx, long int counter);
00060
00061 DllExport void ConnectWingToVertex(BREP_WING* wing);
00062 DllExport void DestroyWing(BREP_WING* wing);
00063 DllExport int CompareVertex(BREP_VERTEX* v1, BREP_VERTEX* v2);
00064
00065 DllExport TVector<double> Vertex2TVector(BREP_VERTEX* v);
00066
00067
00068
00070
00071
00072
00073 class DllExport BREP_SOLID
00074 {
00075 public:
00076 unsigned int facetno;
00077 unsigned int vertexno;
00078 unsigned int vertexid;
00079 int vcount;
00080
00081 BREP_SHELL_LIST shells;
00082 OctreeNode* octree;
00083 RBound<double> rbound;
00084
00085 BREP_CONTOUR_LIST contours;
00086 BREP_WING_LIST wings;
00087
00088 BREP_CONTOUR_LIST surplus_contours;
00089 BREP_WING_LIST shortage_wings;
00090
00091 std::string name;
00092 CVCounter* counter;
00093
00094 bool freed;
00095
00096 public:
00097 BREP_SOLID();
00098 virtual ~BREP_SOLID();
00099
00100 void FreeData(void);
00101 void CloseData(void);
00102 void ConnectShell(BREP_SHELL* shell);
00103 void DisconnectShell(BREP_SHELL* shell);
00104 };
00105
00106
00107 inline void freeBrepSolid(BREP_SOLID*& solid) { if(solid!=NULL){ solid->FreeData(); delete solid; solid=NULL;} }
00108
00109
00110
00112
00113
00114
00115 class DllExport BREP_SHELL
00116 {
00117 public:
00118 BREP_SOLID* solid;
00119 BREP_FACET_LIST facets;
00120 RBound<double> rbound;
00121
00122 public:
00123 BREP_SHELL(BREP_SOLID* pr_solid);
00124 virtual ~BREP_SHELL();
00125
00126 void CloseData();
00127 void ConnectFacet(BREP_FACET* facet);
00128 void DisconnectFacet(BREP_FACET* facet);
00129 };
00130
00131
00132
00134
00135
00136
00137 class DllExport BREP_FACET
00138 {
00139 public:
00140 BREP_SHELL* shell;
00141 BREP_CONTOUR_LIST outer_contours;
00142
00143 Vector<double> normal;
00144 RBound<double> rbound;
00145
00146 double d;
00147 double tolerance;
00148
00149 bool deletable;
00150 bool notdelete;
00151
00152 public:
00153 BREP_FACET(BREP_SHELL* pr_shell);
00154 virtual ~BREP_FACET();
00155
00156 void CloseData();
00157 void ConnectContour(BREP_CONTOUR* contour);
00158 void DisconnectContour(BREP_CONTOUR* contour);
00159
00160 void ComputePlaneEquation();
00161 };
00162
00163
00164
00166
00167
00168
00169 class DllExport BREP_CONTOUR
00170 {
00171 public:
00172 BREP_FACET* facet;
00173 BREP_WING* wing;
00174
00175 RBound<double> rbound;
00176 Vector<double> normal;
00177
00179 TVector<double> directR;
00180 TVector<double> directS;
00181 TVector<double> directRS;
00182
00183 int dup_edge;
00184 bool collision;
00185 bool hasCollisionVector;
00186
00187 public:
00188 BREP_CONTOUR(BREP_FACET* pr_facet);
00189 virtual ~BREP_CONTOUR();
00190
00191 void CloseData();
00192 void ConnectWing(BREP_WING* wing);
00193 void DisconnectWing(BREP_WING* wing);
00194 void DestroyWings();
00195
00196 void CloseFacet(BREP_FACET* facet, double& emax, double& dmin, double& dmax);
00197 void ComputeNormal();
00198 void ComputeDirectRS();
00199
00200 BREP_WING* CreateWing(BREP_VERTEX* vertex1, BREP_VERTEX* vertex2);
00201 };
00202
00203
00204
00206
00207
00208
00209 class DllExport BREP_WING
00210 {
00211 public:
00212 BREP_VERTEX* vertex;
00213 BREP_WING* prev;
00214 BREP_WING* next;
00215
00216 BREP_EDGE* edge;
00217 BREP_CONTOUR* contour;
00218
00219 public:
00220 BREP_WING(BREP_VERTEX* v);
00221 virtual ~BREP_WING() {}
00222
00223 void CloseData() {}
00224 };
00225
00226
00227
00229
00230
00231
00232 class DllExport BREP_EDGE
00233 {
00234 public:
00235 BREP_WING* wing1;
00236 BREP_WING* wing2;
00237
00238 Vector<double> center;
00239 BREP_EDGE_LIST* edge_list;
00240
00241 bool complete;
00242 double tolerance;
00243
00244 public:
00245 BREP_EDGE(BREP_VERTEX* vertex1, BREP_VERTEX* vertex2);
00246 virtual ~BREP_EDGE();
00247
00248 void CloseData();
00249 };
00250
00251
00252
00254
00255
00256
00257 class DllExport BREP_VERTEX
00258 {
00259 public:
00260 BREP_WING_LIST wing_list;
00261
00262 Vector<double> point;
00263 Vector<double> normal;
00264 UVMap<double> uvmap;
00265
00266
00267 long int index;
00268 bool calc_normal;
00269
00270 double distance2;
00271 double tolerance;
00272
00273 BREP_VERTEX_LIST* forbidden_list;
00274
00275 public:
00276 BREP_VERTEX();
00277 virtual ~BREP_VERTEX();
00278
00279 void CloseData();
00280 void DisconnectWing(BREP_WING* wing);
00281
00282 void ComputeNormal();
00283 void ComputeTolerance();
00284 };
00285
00286
00287
00289
00290
00291
00292 class DllExport OctreeNode
00293 {
00294 public:
00295 BREP_SOLID* solid;
00296
00297 private:
00298 BREP_VERTEX* vertex;
00299 OctreeNode* child[8];
00300
00301 public:
00303 OctreeNode(BREP_VERTEX* new_vertex, BREP_SOLID* sld);
00304 ~OctreeNode();
00305
00308 OctreeNode* AddWithUnique(BREP_VERTEX* new_vertex);
00309
00312 OctreeNode* AddWithDuplicates(BREP_VERTEX* new_vertex);
00313
00315 OctreeNode* FindSubtree(BREP_VERTEX* element);
00316
00317
00318 void ComputeVerticesNormal(void);
00319
00320
00321 friend BREP_VERTEX** GetOctreeVertices(OctreeNode* octree, long int* vertexno);
00322 friend long int OctreeGetter(OctreeNode* p, BREP_VERTEX** vtx, long int counter);
00323
00324 friend BREP_VERTEX* AddVertex2Octree(BREP_VERTEX* vertex, OctreeNode* octree, bool dupli);
00325 };
00326
00327
00328 }
00329
00330
00331 #endif
00332