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

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