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 |
|
---|
13 | typedef std::vector<CHCDemoEngine::Vector3> VertexArray;
|
---|
14 | typedef std::pair<float, float> TexCoord;
|
---|
15 |
|
---|
16 | class ogzstream;
|
---|
17 | struct BvhInterior;
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | struct Geometry
|
---|
22 | {
|
---|
23 | CHCDemoEngine::Vector3 *mVertices;
|
---|
24 | CHCDemoEngine::Vector3 *mNormals;
|
---|
25 | TexCoord *mTexCoords;
|
---|
26 |
|
---|
27 | int mVertexCount;
|
---|
28 | int mTexcoordCount;
|
---|
29 | };
|
---|
30 |
|
---|
31 |
|
---|
32 | struct 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 |
|
---|
59 | struct BvhInterior: public BvhNode
|
---|
60 | {
|
---|
61 | BvhInterior():back(NULL), front(NULL) { }
|
---|
62 | BvhNode *back;
|
---|
63 | BvhNode *front;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | struct BvhLeaf: public BvhNode
|
---|
68 | {
|
---|
69 | BvhLeaf(): BvhNode() {}
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | /** Converts obj format into objects readable by our format
|
---|
74 | */
|
---|
75 | class VisibilitySolutionConverter
|
---|
76 | {
|
---|
77 | public:
|
---|
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 |
|
---|
89 | protected:
|
---|
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 | BvhNode *LoadNode(FILE *fr, int depth);
|
---|
113 |
|
---|
114 | bool ReadDummyTree(FILE *fr);
|
---|
115 |
|
---|
116 | bool ReadObj(const std::string &filename,
|
---|
117 | VertexArray &vertices,
|
---|
118 | VertexArray &normals,
|
---|
119 | std::vector<TexCoord> &texcoords);
|
---|
120 |
|
---|
121 | bool ReadBinObj(const std::string &filename,
|
---|
122 | VertexArray &vertices);
|
---|
123 |
|
---|
124 | bool WriteBinObj(const std::string &filename,
|
---|
125 | const VertexArray &vertices);
|
---|
126 |
|
---|
127 | bool ExportBinObj(const std::string &filename,
|
---|
128 | const VertexArray &vertices);
|
---|
129 |
|
---|
130 | void WriteNextNode(ogzstream &stream, BvhNode *parent);
|
---|
131 |
|
---|
132 | void UpdateLeafBox(BvhLeaf *leaf);
|
---|
133 | /** Prepare bvh for exporting.
|
---|
134 | */
|
---|
135 | void UpdateBvh(BvhNode *node);
|
---|
136 |
|
---|
137 | bool LoadSolutionTest(const std::string &filename);
|
---|
138 |
|
---|
139 |
|
---|
140 | bool ReadObjSimple(const std::string &filename,
|
---|
141 | std::vector<CHCDemoEngine::Triangle3 *> &triangles);
|
---|
142 |
|
---|
143 | void ConstructBvhObjects2(const std::vector<CHCDemoEngine::Triangle3 *> &triangles);
|
---|
144 |
|
---|
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
|
---|