- Timestamp:
- 01/02/09 23:07:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
r3242 r3243 2 2 #include "Timer/PerfTimer.h" 3 3 #include <stack> 4 #include <string> 4 5 5 6 using namespace std; 6 7 7 8 9 // MAGIC of all bin exports 10 #ifndef MAGIC 11 #define MAGIC 0x827923 12 #endif 13 14 #define VIEWCELLS_VERSION 1.0f 15 8 16 namespace CHCDemoEngine 9 17 { 10 18 19 11 20 ViewCell *ViewCellsTree::GetViewCell(const Vector3 &point) const 12 21 { 13 ViewCellsTreeNode *node = root;22 ViewCellsTreeNode *node = mRoot; 14 23 15 24 while (!node->IsLeaf()) 16 25 { 17 if (point[node-> axis] < node->position)18 node = node-> back;26 if (point[node->mAxis] < node->mPosition) 27 node = node->mBack; 19 28 else 20 node = node-> front;29 node = node->mFront; 21 30 } 22 31 23 return node-> viewCell;32 return node->mViewCell; 24 33 } 25 34 26 35 27 bool ViewCellsTree::LoadFromFile(const st ring &filename)36 bool ViewCellsTree::LoadFromFile(const std::string &filename) 28 37 { 29 cout << ("Info: Loading view cells from file '" + filename + "'" );38 cout << "Info: Loading view cells from file '" + filename + "'"; 30 39 31 40 FILE *fr = fopen(filename.c_str(), "rb"); 32 41 33 if (fr == NULL) { 34 Message("Error: Cannot open file for reading"); 42 if (!fr) 43 { 44 cerr << "Error: Cannot open file for reading" << endl; 35 45 return false; 36 46 } … … 38 48 bool result = _LoadFromFile(fr); 39 49 40 Debug<< "Info: done. " << endl;50 cout << "Info: done. " << endl; 41 51 fclose(fr); 42 52 … … 50 60 fread(buffer, sizeof(int), 3, fr); 51 61 52 if (buffer[0] != MAGIC) { 53 Message( "Error: Wrong file type"); 62 if (buffer[0] != MAGIC) 63 { 64 cerr << "Error: Wrong file type" << endl; 54 65 return false; 55 66 } 56 67 57 if (buffer[1] != (int)(1000*VIEWCELLS_VERSION)) { 58 Message( "Error: Wrong viewcells version" ); 68 if (buffer[1] != (int)(1000 * VIEWCELLS_VERSION)) 69 { 70 cerr << "Error: Wrong viewcells version" << endl; 59 71 return false; 60 72 } 61 73 62 74 // get the bounding box 63 fread(& box, sizeof(AxisAlignedBox3), 1, fr);75 fread(&mBox, sizeof(AxisAlignedBox3), 1, fr); 64 76 65 77 stack<ViewCellsTreeNode **> nodeStack; 66 78 67 nodeStack.push(& root);79 nodeStack.push(&mRoot); 68 80 69 while(!nodeStack.empty()) { 81 while (!nodeStack.empty()) 82 { 70 83 ViewCellsTreeNode *&node = *nodeStack.top(); 71 84 nodeStack.pop(); 72 node = new ViewCellsTreeNode; 73 fread(&node->axis, sizeof(int), 1, fr); 74 if (!node->IsLeaf()) { 75 fread(&node->position, sizeof(float), 1, fr); 76 nodeStack.push(&node->front); 77 nodeStack.push(&node->back); 85 node = new ViewCellsTreeNode(); 86 87 fread(&node->mAxis, sizeof(int), 1, fr); 88 89 if (!node->IsLeaf()) 90 { 91 fread(&node->mPosition, sizeof(float), 1, fr); 92 nodeStack.push(&node->mFront); 93 nodeStack.push(&node->mBack); 78 94 } 79 95 } … … 83 99 84 100 85 void ViewCellsTree::_ExportToFile(FILE *file)86 {87 int buffer[256];88 int i=0;89 buffer[i++] = MAGIC;90 buffer[i++] = VIEWCELLS_VERSION*1000;91 92 fwrite(buffer, sizeof(int), i, file);93 94 fwrite(&mMaxDepth, sizeof(float), 1, file);95 96 fwrite(&box, sizeof(AxisAlignedBox3), 1, file);97 98 stack<ViewCellsTreeNode *> nodeStack;99 100 nodeStack.push(root);101 102 while (!nodeStack.empty()) {103 ViewCellsTreeNode *node = nodeStack.top();104 nodeStack.pop();105 106 fwrite(&node->axis, sizeof(int), 1, file);107 if (!node->IsLeaf()) {108 fwrite(&node->position, sizeof(float), 1, file);109 nodeStack.push(node->front);110 nodeStack.push(node->back);111 }112 }113 101 } 114 115 }
Note: See TracChangeset
for help on using the changeset viewer.