BVList.h

Go to the documentation of this file.
00001 /* $Id: BVList.h,v 1.2 2002/11/05 14:31:15 anonymous Exp $ */
00002 
00003 #ifndef __BV_LIST_H
00004 #define __BV_LIST_H
00005 
00006 #include <esg/List.h>
00007 #include <esg/SceneGraphObject.h>
00008 #include <esg/explorer/Explorer.h>
00009 
00010 namespace esg {
00011 
00017 class OGSCENE_EXPORT BVList {
00018 public:
00022         enum SplitStrategy {
00023             SPLIT_BY_MAX_VARIATION, 
00024             SPLIT_BY_MAX_EXTENT
00025         };
00026     
00027 protected:
00028         struct BVNode {
00029                 SceneGraphObject* pObject;
00030                 float*            handle;
00031                 Interval*         extents;
00032                 
00033                 BVNode (unsigned s, SceneGraphObject* o = NULL) {
00034                     handle  = new float    [s];
00035                     extents = new Interval [s];
00036                     pObject = o;
00037                 }
00038                 
00039                 ~BVNode () {
00040                     if (handle)  delete [] handle;
00041                     if (extents) delete [] extents;
00042                 }
00043                 
00044                 void __debug() { if (pObject) pObject->__debug(); }
00045         };
00046     
00047         List<BVNode> * _pList;
00048         unsigned       _dirs;
00049         const float  (*_dirMat)[3];  // matrix of direction
00050 
00051 protected: // methods and attribute used for qsort()
00052         static unsigned qsortIndex;
00053         static int qsortCompare (const void*, const void*);
00054 
00055 protected:
00056         /*
00057          * split list by handles using median
00058          */
00059         void _split_by_handles (List<BVNode>&      /* src */,
00060                                 List<BVNode>&      /* dst */,
00061                                 unsigned           /* split dir */);
00062 
00063         /*
00064          * Precompute object extents and a handle of centroid
00065          */
00066         virtual void _comp_handle  (BVNode*);
00067         virtual void _comp_extents (BVNode*);
00068 
00069         /*
00070          * Extent splitting strategy taken from POV-Ray 3.5
00071          */
00072         unsigned _index_with_max_extent ();
00073         void     _build_area_table      (BVNode**, long, long, double*) const;
00074         unsigned _split_by_extent       (List<BVNode>&);
00075         
00076         /*
00077          * Splitting strategy using maximal variation + median
00078          */
00079         unsigned _index_with_max_variation ();
00080         unsigned _split_by_variation (List<BVNode>&);
00081     
00082 public:
00089         BVList (unsigned s, const float (*m)[3]);
00090 
00094         virtual ~BVList ();
00095 
00101         void append (SceneGraphObject* o);
00102 
00109         SceneGraphObject* remove (SceneGraphObject*);
00110 
00114         unsigned length () const { return _pList->length(); }
00115 
00124         unsigned split (BVList& list, SplitStrategy splitStrategy);
00125 
00132         SceneGraphObject* firstItem () {
00133             BVNode* pN = _pList->firstItem();
00134             return ((pN) ? pN->pObject : NULL);
00135         }
00136 
00142         SceneGraphObject* nextItem () {
00143             BVNode* pN = _pList->nextItem();
00144             return ((pN) ? pN->pObject : NULL);
00145         }
00146 
00155         SceneGraphObject* iThItem (unsigned i, bool setAct) {
00156             BVNode* pN = _pList->iThItem(i, setAct);
00157             return ((pN) ? pN->pObject : NULL);
00158         }
00159 
00160 
00164         virtual void __debug() { _pList->__debug(); }
00165 };
00166 
00167 }; // namespace
00168 
00169 #endif // __BV_LIST_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6