Changeset 3239


Ignore:
Timestamp:
01/02/09 10:24:19 (15 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp

    r3238 r3239  
    44#include "gzstream.h" 
    55#include <iostream> 
     6#include <queue> 
    67 
    78 
     
    1516#define BVH_VERSION 2.1 
    1617 
    17 const int maxVertices = 20000000; 
     18#define TYPE_INTERIOR -2 
     19#define TYPE_LEAF -3 
     20 
     21//const int maxVertices = 20000000; 
    1822 
    1923 
     
    246250        } 
    247251 
    248         /*if (!WriteBvh(bvhOutputFilename)) 
    249         { 
    250                 cerr << "could not write file" << endl; 
     252        if (!WriteBvh(bvhOutputFilename)) 
     253        { 
     254                cerr << "could not write bvh!" << endl; 
    251255                return false; 
    252         }*/ 
     256        } 
    253257 
    254258        return true; 
     
    578582 
    579583 
    580 bool VisibilitySolutionConverter::WriteBvh(const string &filename) 
    581 { 
    582          
    583         return true; 
    584 } 
    585  
    586  
    587584bool VisibilitySolutionConverter::ReadBvh(FILE *fr)  
    588585{ 
     
    653650                back  = LoadNode(fr, depth + 1); 
    654651 
    655                 // front->parent = (BvhNode *)interior; 
    656                 // back->parent = (BvhNode *)interior; 
     652                front->parent = interior; 
     653                back->parent = interior; 
     654 
    657655                interior->front = front; 
    658656                interior->back = back; 
    659657 
    660                 //interior->box = Union(front->box, back->box); 
     658                //interior->bmin = Minimize(front->bmin, back->bmin); 
     659                //interior->bmax = Maximize(front->bmax, back->bmax); 
    661660         
    662661                return (BvhNode *)interior; 
     
    667666                //Debug << "Info: Loading leaf (id: " << numberOfNodes << ", depth: " << depth << ")" << endl; 
    668667                BvhLeaf *leaf = new BvhLeaf(); 
     668 
    669669                leaf->first = buffer[0]; 
    670670                leaf->last  = buffer[1]; 
    671671                leaf->axis  = buffer[2]; 
    672                 leaf->id  = buffer[3]; 
     672                leaf->id    = buffer[3]; 
    673673 
    674674                leaf->depth = depth; 
     
    676676 
    677677                mBvhNodes.push_back(leaf); 
    678                 // leaf->id = numberOfNodes; 
     678         
    679679                return (BvhNode *)leaf; 
    680680        } 
     
    820820        return true; 
    821821} 
     822 
     823 
     824void VisibilitySolutionConverter::WriteNextNode(ogzstream &stream,  
     825                                                                                                BvhNode *node) 
     826{ 
     827        int nodeType; 
     828 
     829        if (!node->IsLeaf()) 
     830                nodeType = TYPE_LEAF; 
     831        else  
     832                nodeType = TYPE_INTERIOR; 
     833                 
     834        cerr << "error: wrong node type: " << nodeType << endl; 
     835                 
     836        stream.write(reinterpret_cast<char *>(&nodeType), sizeof(int)); 
     837 
     838        SimpleVec bMin, bMax; 
     839 
     840        stream.write(reinterpret_cast<char *>(&(node->first)), sizeof(int)); 
     841        stream.write(reinterpret_cast<char *>(&(node->last)), sizeof(int)); 
     842 
     843        stream.write(reinterpret_cast<char *>(&node->bmin), sizeof(SimpleVec)); 
     844        stream.write(reinterpret_cast<char *>(&node->bmax), sizeof(SimpleVec)); 
     845} 
     846 
     847 
     848bool VisibilitySolutionConverter::WriteBvh(const string &filename) 
     849{ 
     850        std::queue<BvhNode *> tQueue; 
     851        ogzstream stream(filename.c_str()); 
     852 
     853        if (!stream.is_open()) return NULL; 
     854 
     855        cout << "loading bvh" << endl; 
     856 
     857        WriteNextNode(stream, mRoot); 
     858 
     859        tQueue.push(mRoot); 
     860         
     861        while (!tQueue.empty()) 
     862        { 
     863                BvhNode *node = tQueue.front(); 
     864                tQueue.pop(); 
     865 
     866                if (!node->IsLeaf()) 
     867                { 
     868                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     869 
     870                        BvhNode *front = interior->front; 
     871                        BvhNode *back = interior->back; 
     872 
     873                        WriteNextNode(stream, front); 
     874                        WriteNextNode(stream, back); 
     875 
     876                        tQueue.push(front);                      
     877                        tQueue.push(back); 
     878                } 
     879        } 
     880 
     881        return true; 
     882} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h

    r3238 r3239  
    1414class ogzstream; 
    1515 
     16struct BvhInterior; 
    1617 
    1718struct BvhNode 
     
    3536        int Count() const { return last - first + 1; } 
    3637 
     38        SimpleVec bmin; 
     39        SimpleVec bmax; 
     40 
     41        BvhInterior *parent; 
    3742        std::vector<int> mTriangleIds; 
    3843}; 
     
    7176                         const std::string &bvhOutputFilename); 
    7277         
    73  
    7478 
    7579protected: 
     
    124128                                        float scale); 
    125129 
     130        bool WriteBinObj(const std::string &filename, 
     131                             const VertexArray &vertices); 
     132 
    126133        bool ExportBinObj(const std::string &filename, 
    127                       const VertexArray &vertices); 
     134                              const VertexArray &vertices); 
     135 
     136        void WriteNextNode(ogzstream &stream,  
     137                               BvhNode *parent); 
     138 
     139 
    128140 
    129141        ////////////////////////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3123 r3239  
    8484        tQueue.push(root); 
    8585         
    86         while(!tQueue.empty()) 
     86        while (!tQueue.empty()) 
    8787        { 
    8888                BvhNode *node = tQueue.front(); 
Note: See TracChangeset for help on using the changeset viewer.