source: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h @ 3277

Revision 3277, 3.4 KB checked in by mattausch, 15 years ago (diff)
Line 
1#ifndef _VISIBILITYSOLUTIONCONVERTER_H
2#define _VISIBILITYSOLUTIONCONVERTER_H
3
4
5#include "Vector3.h"
6#include "Triangle3.h"
7#include <string>
8#include <vector>
9#include "AxisAlignedBox3.h"
10
11       
12
13typedef std::vector<CHCDemoEngine::Vector3> VertexArray;
14typedef std::pair<float, float> TexCoord;
15
16class ogzstream;
17struct BvhInterior;
18
19
20
21struct Geometry
22{
23        CHCDemoEngine::Vector3 *mVertices;
24        CHCDemoEngine::Vector3 *mNormals;
25        TexCoord *mTexCoords;
26
27        int mVertexCount;
28        int mTexcoordCount;
29};
30
31
32struct BvhNode
33{
34        int id;
35        char axis;
36        unsigned char depth;
37        short flags;
38
39        // indices to first and last triangle in the triangle array
40        // assumes the traingle are placed in continuous chunk of memory
41        // however this need not be a global array!
42        int first;
43        // one after the last triangle!
44        int last;
45
46        BvhNode(): axis(-1), first(-1), flags(0) {}
47
48        bool IsLeaf() { return axis == -1; }
49        bool Empty() const { return first == -1; }
50        int Count() const { return last - first + 1; }
51
52        CHCDemoEngine::AxisAlignedBox3 box;
53
54        BvhInterior *parent;
55        std::vector<int> mTriangleIds;
56};
57
58
59struct BvhInterior: public BvhNode
60{
61        BvhInterior():back(NULL), front(NULL) { }
62        BvhNode *back;
63        BvhNode *front;
64};
65
66
67struct BvhLeaf: public BvhNode
68{
69        BvhLeaf(): BvhNode() {}
70};
71
72
73/** Converts obj format into objects readable by our format
74*/
75class VisibilitySolutionConverter
76{
77public:
78
79        VisibilitySolutionConverter();
80
81        ~VisibilitySolutionConverter();
82
83        bool Convert(const std::string &sceneInputFilename,
84                                 const std::string &sceneOutputFilename,
85                                 const std::string &bvhInputFilename,
86                         const std::string &bvhOutputFilename);
87       
88
89protected:
90
91
92        void LoadShape(const VertexArray &vertices,
93                           const VertexArray &normals,
94                                   const std::vector<TexCoord> &texCoords);
95
96        void WriteGeometry(ogzstream &str, Geometry *geom);
97
98        bool ReadScene(const std::string &iFilename);
99
100        bool WriteScene(const std::string &oFilename);
101
102        bool ReadBvh(FILE *fr);
103
104        bool WriteBvh(const std::string &oFilename);
105
106        void ConstructBvhObjects(const VertexArray &vertices,
107                                     const VertexArray &normals,
108                                                         const std::vector<TexCoord> &texCoords);
109
110        bool LoadSolution(const std::string &filename);
111
112
113        BvhNode *LoadNode(FILE *fr, int depth);
114
115        bool ReadDummyTree(FILE *fr);
116
117        bool ReadObj(const std::string &filename,
118                         VertexArray &vertices,
119                                 VertexArray &normals,
120                                 std::vector<TexCoord> &texcoords);
121
122        bool ReadBinObj(const std::string &filename,
123                    VertexArray &vertices);
124
125        bool WriteBinObj(const std::string &filename,
126                             const VertexArray &vertices);
127
128        bool ExportBinObj(const std::string &filename,
129                              const VertexArray &vertices);
130
131        void WriteNextNode(ogzstream &stream, BvhNode *parent);
132
133        void UpdateLeafBox(BvhLeaf *leaf);
134        /** Prepare bvh for exporting.
135        */
136        void UpdateBvh(BvhNode *node);
137
138        bool LoadSolutionTest(const std::string &filename);
139
140
141        bool ReadObjSimple(const std::string &filename,
142                std::vector<CHCDemoEngine::Triangle3 *> &triangles);
143
144        void ConstructBvhObjects2(const std::vector<CHCDemoEngine::Triangle3 *> &triangles);
145
146
147
148        //////////////////////////////////
149
150        std::vector<Geometry *> mGeometry;
151
152        int mNumShapes;
153
154        std::vector<int> mGlobalTriangleIds;
155
156        std::vector<BvhLeaf *> mBvhLeaves;
157
158        BvhNode *mRoot;
159
160        int mNumNodes;
161};
162
163
164
165#endif
Note: See TracBrowser for help on using the repository browser.