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

Revision 3272, 3.2 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        BvhLeaf(): BvhNode() {}
71};
72
73
74/** Converts obj format into objects readable by our format
75*/
76class VisibilitySolutionConverter
77{
78public:
79
80        VisibilitySolutionConverter();
81
82        ~VisibilitySolutionConverter();
83
84        bool Convert(const std::string &sceneInputFilename,
85                                 const std::string &sceneOutputFilename,
86                                 const std::string &bvhInputFilename,
87                         const std::string &bvhOutputFilename);
88       
89
90protected:
91
92
93        void LoadShape(const VertexArray &vertices,
94                           const VertexArray &normals,
95                                   const std::vector<TexCoord> &texCoords);
96
97        void WriteGeometry(ogzstream &str, Geometry *geom);
98
99        bool ReadScene(const std::string &iFilename);
100
101        bool WriteScene(const std::string &oFilename);
102
103        bool ReadBvh(FILE *fr);
104
105        bool WriteBvh(const std::string &oFilename);
106
107        void ConstructBvhObjects(const VertexArray &vertices,
108                                     const VertexArray &normals,
109                                                         const std::vector<TexCoord> &texCoords);
110
111        bool LoadSolution(const std::string &filename);
112
113
114        BvhNode *LoadNode(FILE *fr, int depth);
115
116        bool ReadDummyTree(FILE *fr);
117
118        bool ReadObj(const std::string &filename,
119                         VertexArray &vertices,
120                                 VertexArray &normals,
121                                 std::vector<TexCoord> &texcoords);
122
123        bool ReadBinObj(const std::string &filename,
124                    VertexArray &vertices);
125
126        bool WriteBinObj(const std::string &filename,
127                             const VertexArray &vertices);
128
129        bool ExportBinObj(const std::string &filename,
130                              const VertexArray &vertices);
131
132        void WriteNextNode(ogzstream &stream, BvhNode *parent);
133
134        void UpdateLeafBox(BvhLeaf *leaf);
135        /** Prepare bvh for exporting.
136        */
137        void UpdateBvh(BvhNode *node);
138
139        bool LoadSolutionTest(const std::string &filename);
140
141
142        //////////////////////////////////
143
144        std::vector<Geometry *> mGeometry;
145
146        int mNumShapes;
147
148        std::vector<int> mGlobalTriangleIds;
149
150        std::vector<BvhLeaf *> mBvhLeaves;
151
152        BvhNode *mRoot;
153
154        int mNumNodes;
155};
156
157
158
159#endif
Note: See TracBrowser for help on using the repository browser.