00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GB_Detail_h__
00022 #define __GB_Detail_h__
00023
00024 #include "GB_API.h"
00025 #include <iostream.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_Lock.h>
00028 #include <UT/UT_Notifier.h>
00029 #include "GB_Element.h"
00030 #include "GB_ElementList.h"
00031 #include "GB_GroupList.h"
00032 #include "GB_Group.h"
00033 #include "GB_Primitive.h"
00034 #include "GB_Error.h"
00035 #include "GB_Macros.h"
00036
00037 class UT_BoundingBox;
00038 class UT_BoundingSphere;
00039 class UT_Options;
00040 class UT_IStream;
00041 class GB_Vertex;
00042 class GB_Primitive;
00043 class GB_PrimGroupClosure;
00044 class GB_AttributeDict;
00045 class GB_AttributeHandleBase;
00046 class GB_Breakpoint;
00047 class GEO_Primitive;
00048
00049 #define GB_COPY_ONCE 0
00050 #define GB_COPY_START 1
00051 #define GB_COPY_ADD 2
00052 #define GB_COPY_END 3
00053
00054 class GB_API GB_Detail {
00055 public:
00056 GB_Detail(GB_ElementList *ptlist,GB_ElementList *primlist);
00057 virtual ~GB_Detail();
00058
00059
00060
00061
00062 virtual void clearAndDestroy();
00063
00064
00065
00066
00067 virtual int save(const char *, int binary,
00068 const UT_Options *options) const = 0;
00069 virtual int save(ostream& os, int binary,
00070 const UT_Options *options) const = 0;
00071 virtual int load(const char *, const UT_Options *options) = 0;
00072 virtual bool load(UT_IStream &is, const UT_Options *options) = 0;
00073
00074
00075
00076
00077 virtual int saveVertex(ostream &os,const GB_Vertex &vtx,int b) const;
00078 virtual bool loadVertex(UT_IStream &is, GB_Vertex &vtx);
00079
00080
00081
00082
00083 GB_Element *insertPointElem(GB_Element &pt, const GB_Element *prev = 0);
00084
00085
00086
00087 int isPointUsed(const GB_Element &p) const;
00088 int countPointUsed(const GB_Element &p,
00089 int maxcount = -1) const;
00090
00091
00092
00093
00094 void deletePoint(GB_Element &p, unsigned deleteFast = 0)
00095 {
00096 deletePoint((unsigned)p.getNum(), deleteFast);
00097 }
00098 void deletePoint(unsigned int num, unsigned deleteFast=0);
00099
00100
00101
00102 int deletePoint(const GB_PointGroup &ptGrp,
00103 unsigned deleteFast = 0,
00104 bool remove_degenerate = false);
00105
00106
00107
00108
00109
00110
00111
00112 GB_Primitive *insertPrimElem(GB_Primitive *prim,
00113 const GB_Primitive *beforeWhich = 0,
00114 int cleargroups = 1);
00115 GB_Primitive *appendPrimElem(GB_Primitive *prim,
00116 int cleargroups = 1)
00117 {
00118 return insertPrimElem(prim, 0, cleargroups);
00119 }
00120 virtual void deletePrimitive(GB_Primitive &p,int andpoints=0)
00121 {
00122 UT_ASSERT(p.getBaseParent() == this);
00123 deletePrimitive((unsigned)p.getNum(), andpoints);
00124 }
00125 virtual void deletePrimitive(unsigned int num, int andpoints = 0);
00126
00127
00128 virtual void deletePrimitives(const GB_PrimitiveGroup &primGrp,
00129 int andpoints = 0);
00130 virtual void deletePrimitives(const UT_PtrArray<GEO_Primitive*> &prims_in,
00131 int andpoints = 0);
00132
00133
00134
00135
00136
00137
00138
00139
00140 int removeUnusedPointGroups();
00141 int removeUnusedPrimGroups();
00142 void removeUnusedGroups()
00143 {
00144 removeUnusedPointGroups();
00145 removeUnusedPrimGroups();
00146 }
00147 int removeUnusedPoints(const GB_PointGroup *ptgrp = 0);
00148 int removeDegeneratePrimitives(const GB_PrimitiveGroup *prims=0,
00149 int andpoints = 0);
00150 void removeUnused(const GB_PrimitiveGroup *prims = 0, const GB_PointGroup *ptgrp = 0)
00151 {
00152 removeDegeneratePrimitives(prims, 0);
00153 removeUnusedPoints(ptgrp);
00154 }
00155
00156
00157
00158 virtual GB_Breakpoint *allocBreakpoint() const;
00159
00160
00161
00162
00163 int getBBox (UT_BoundingBox *bbox,
00164 const GB_PrimitiveGroup *g=0,
00165 const GB_PrimGroupClosure *c=0,
00166 bool closure_is_hidden = true) const;
00167
00168
00169 int getBBox (UT_BoundingBox& bbox, const UT_Matrix4& transform,
00170 const GB_PrimitiveGroup *g=0,
00171 const GB_PrimGroupClosure *c=0,
00172 bool closure_is_hidden = true) const;
00173 int getBSphere (UT_BoundingSphere *bsphere,
00174 const GB_PrimitiveGroup *g=0,
00175 int updateRequired = 0,
00176 const GB_PrimGroupClosure *c=0,
00177 bool closure_is_hidden = true) const;
00178 virtual int getPointBBox(UT_BoundingBox *bbox,
00179 const GB_PointGroup *g=0) const = 0;
00180
00181 virtual int getPointBBox(UT_BoundingBox& bbox, const UT_Matrix4& transform,
00182 const GB_PointGroup *g=0) const = 0;
00183
00184 virtual int getPointBSphere(UT_BoundingSphere *bsphere,
00185 const GB_PointGroup *g=0,
00186 int updateRequired = 0) const = 0;
00187
00188
00189
00190
00191 GB_PointGroup *newPointGroup(const char *name, int internal = 0)
00192 {
00193 return (GB_PointGroup*)ptGroups.newGroup(name,
00194 internal);
00195 }
00196 void destroyPointGroup(GB_PointGroup *grp)
00197 {
00198 ptGroups.destroy(grp);
00199 if (grp == myHomogGroup) myHomogGroup = 0;
00200 }
00201 void destroyPointGroup(const char *name)
00202 {
00203 GB_PointGroup *grp = (GB_PointGroup *)
00204 ptGroups.find(name);
00205 if (grp)
00206 {
00207 ptGroups.destroy(grp);
00208 if (grp == myHomogGroup) myHomogGroup = 0;
00209 }
00210 }
00211 GB_PointGroup *findPointGroup(const char *name) const
00212 {
00213 return (GB_PointGroup*)ptGroups.find(name);
00214 }
00215
00216
00217 GB_PrimitiveGroup *newPrimitiveGroup(const char *name, int internal = 0)
00218 {
00219 return (GB_PrimitiveGroup*)primGroups.newGroup(
00220 name, internal);
00221 }
00222 void destroyPrimitiveGroup(GB_PrimitiveGroup *grp)
00223 {
00224 primGroups.destroy(grp);
00225 }
00226 void destroyPrimitiveGroup(const char *name)
00227 {
00228 primGroups.destroy(primGroups.find(name));
00229 }
00230 GB_PrimitiveGroup *findPrimitiveGroup(const char *name) const
00231 {
00232 return (GB_PrimitiveGroup*)primGroups.find(name);
00233 }
00234
00235 void destroyGroup(GB_BaseGroup *grp);
00236
00237
00238
00239 GB_PointGroup *getHomogeneousGroup(void)
00240 {
00241 if (!myHomogGroup)
00242 {
00243 myHomogGroup = (GB_PointGroup*)
00244 ptGroups.newGroup("_gb_homogpoints_",1);
00245 }
00246 return myHomogGroup;
00247 }
00248
00249
00250
00251 GB_PointGroup *copyGroup(const GB_PointGroup &grp, const char *name);
00252 GB_PrimitiveGroup *copyGroup(const GB_PrimitiveGroup &grp,
00253 const char *name);
00254
00255
00256
00257
00258
00259
00260
00261
00262 void mergeGroups(const GB_Detail &src, int override = 1);
00263 GB_PointGroup *mergeGroup(const GB_Detail &src,
00264 const GB_PointGroup &group,
00265 int override = 1);
00266 GB_PrimitiveGroup *mergeGroup(const GB_Detail &src,
00267 const GB_PrimitiveGroup &group,
00268 int override = 1);
00269
00270
00271 GB_GroupList &pointGroups() { return ptGroups; }
00272 GB_GroupList &primitiveGroups() { return primGroups; }
00273
00274 const GB_GroupList &pointGroups() const { return ptGroups; }
00275 const GB_GroupList &primitiveGroups() const { return primGroups; }
00276
00277 GB_ElementList &basePoints() { return ptList; }
00278 GB_ElementList &basePrims () { return primList; }
00279
00280 const GB_ElementList &basePoints() const { return ptList; }
00281 const GB_ElementList &basePrims () const { return primList; }
00282
00283
00284 int getVersion(void) const { return myVersion; }
00285 int getUniqueId() const { return myUniqueId; }
00286
00287
00288
00289
00290
00291 void renumberPoints(int start = 0);
00292 void renumberPrimitives(int start = 0);
00293
00294
00295
00296 void registerAttributeHandle(
00297 GB_AttributeHandleBase *gah) const;
00298
00299
00300
00301 void unregisterAttributeHandle(
00302 GB_AttributeHandleBase *gah) const;
00303
00304 UT_NotifierImpl<GB_Element *> &edgeGroupNotifier() const { return myEdgeGroupNotifier; }
00305
00306 protected:
00307 GB_ElementList &ptList;
00308 GB_ElementList &primList;
00309
00310
00311
00312
00313
00314 GB_Primitive *replacePrimElem(GB_Primitive *prim,
00315 GB_Primitive *axeme,
00316 int cleargroups);
00317
00318
00319 int getLatestVersion(void) const;
00320 void setVersion(int v) { myVersion = v; }
00321
00322
00323
00324
00325 GB_Element *attachPoint(GB_Element &crt,const GB_Element *prv=0);
00326
00327
00328
00329
00330 int savePrimitives(int n, ostream &os, int binary) const;
00331 bool loadPrimitives(int n, UT_IStream &is);
00332
00333
00334
00335
00336 int saveGroups(ostream& os, int binary,
00337 bool savepointgroups,
00338 bool saveprimgroups) const;
00339 bool loadGroups(UT_IStream& is, int nptgrps, int nprimgrps);
00340
00341
00342 void clearAllGroups(GB_Primitive &prim);
00343
00344
00345
00346 int checkMagic(UT_IStream &is) const;
00347 int asciiMagic(void) const
00348 {
00349 return (('P'<<24) + ('G'<<16) + ('E'<<8) + 'O');
00350 }
00351 int binaryMagic(void) const
00352 {
00353 return (('B'<<24) + ('g'<<16) + ('e'<<8) + 'o');
00354 }
00355
00356
00357
00358 virtual GB_Primitive *appendNewPrimitive(unsigned type) = 0;
00359
00360
00361 virtual unsigned getPrimitiveType(const char *name) const = 0;
00362 virtual const char *getPrimitiveName(unsigned type) const = 0;
00363
00364
00365
00366
00367
00368
00369
00370 int useRecycledData() const
00371 { return myUseRecycledData; }
00372 void useRecycledData(int yesno)
00373 { myUseRecycledData = yesno; }
00374
00375
00376
00377
00378 void getTransformedBBoxBBox(const UT_BoundingBox& bbox,
00379 const UT_Matrix4& transform,
00380 UT_BoundingBox& bbox_out) const;
00381
00382 private:
00383 void mergeGroup(GB_ElementList &destList,
00384 GB_Group &destGroup,
00385 const GB_ElementList &srcList,
00386 const GB_Group &srcGroup);
00387
00388 GB_PointGroupList ptGroups;
00389 GB_PrimGroupList primGroups;
00390
00391 GB_PointGroup *myHomogGroup;
00392
00393 mutable UT_NotifierImpl<GB_Element *> myEdgeGroupNotifier;
00394
00395 int myVersion;
00396
00397 int myUniqueId;
00398 int myUseRecycledData;
00399
00400 mutable UT_PtrArray<GB_AttributeHandleBase *> myAttributeHandles;
00401
00402 mutable UT_Lock myAttribHandleLock;
00403
00404 };
00405
00406 #endif