vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SphereBVH_Object_Data.h
Go to the documentation of this file.
1 #ifndef SPHEREBVH_OBJECT_DATA_H
2 #define SPHEREBVH_OBJECT_DATA_H
3 
4 #include "GeometryLoaderBase.h"
5 #include "SP_Object_Data_Base.h"
6 #include <vrecko/Ability.h>
7 #include <osg/Node>
8 #include <osg/Geode>
9 #include <osg/Geometry>
10 
11 using namespace vrecko;
12 
13 namespace APSpacePartitioning {
14 
16 public:
17  //
18  // constructors / destructors
19  //
21  SphereBVH_Object_Data(const char* abName);
23 
24  virtual bool isHierarchyCreated() { return bSphereBVHierarchyCreated; }
25 
26 
27  struct STNodeSphere {
28  void *pParent; // pointer to STNode (or descendant class)
29  osg::Vec3 center;
30  float radius;
31  void *pChild[2]; // pointers to STNodes (or descendant classes)
32  unsigned long int face_index;
33  // Used only in leaves.
34  // NOTE: Descendants, such as SNCH_Object_Data, will use it also in non-leaf nodes.
35  };
36  virtual void* allocateSTNode() { return new STNodeSphere; }
37  virtual unsigned long getSTNodeStructureSize() { return sizeof(STNodeSphere); }
38  virtual bool saveTreeNodeToFile(void* node, vrecko::BufferedFileWrite *bfile);
39  // WARNING: pParent is not saved. pChild[X] is not saved directly, but only a boolean value is saved (true if a child is present)
40  virtual bool loadTreeNodeFromFile(void* node, vrecko::BufferedFile *bfile);
41  // WARNING: pChild[X] will be only 1 or 0
42 
43  void *getRootPtr(void) {return root;}
44  virtual bool destroyHierarchy(STNodeSphere *subTreeToDestroy = NULL);
45 
46 protected:
48 
49  void *root; // pointer to STNode or its descendant class
50 
51  virtual bool constructCacheDataName(char *pOutDataName, int* version);
52  // should be overridden in descendants to supply different name
53 
54  virtual bool saveDataToPersistentCache_Init();
55  // This function call isHierarchyCreated() and in case of getting "false" as an answer IT DOES NOTHING.
56  // So it can be safely called several times during the initialization - it only saves the data at the end.
57  virtual bool saveDataToPersistentCache_WriteData(vrecko::BufferedFileWrite *bfile);
58  virtual bool saveDataToPC_SaveTreeNode(vrecko::BufferedFileWrite *bfile, STNodeSphere* node);
59 
60  virtual bool loadDataFromPersistentCache_Init();
61  // returns "true" in case of success, otherwise the data have to be regenerated
62  virtual bool loadDataFromPersistentCache_ReadData(vrecko::BufferedFile *bfile);
63  virtual bool loadDataFromPC_LoadTreeNode(vrecko::BufferedFile *bfile, STNodeSphere** ptrToStoreNode);
64 
65  virtual bool createTreeFromGeometry(osg::Node *pNode);
66  bool constructTree(void *pSTNode, unsigned long left_pos, unsigned long right_pos, int last_sort);
67 
68  virtual int processNotification(BaseClass *sender, unsigned long notificationType, void *notificationData);
69 
70  virtual bool coreHierarchyCreation(void);
71 };
72 
73 }
74 
75 #endif
76 
77