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 |
|
---|
18 | struct BvhInterior;
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 | struct Geometry
|
---|
23 | {
|
---|
24 | CHCDemoEngine::Vector3 *mVertices;
|
---|
25 | CHCDemoEngine::Vector3 *mNormals;
|
---|
26 | TexCoord *mTexCoords;
|
---|
27 |
|
---|
28 | int mVertexCount;
|
---|
29 | int mTexcoordCount;
|
---|
30 | };
|
---|
31 |
|
---|
32 |
|
---|
33 | struct 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 |
|
---|
60 | struct BvhInterior: public BvhNode
|
---|
61 | {
|
---|
62 | BvhInterior():back(NULL), front(NULL) { }
|
---|
63 | BvhNode *back;
|
---|
64 | BvhNode *front;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | struct BvhLeaf: public BvhNode
|
---|
69 | {
|
---|
70 | BvhLeaf(): BvhNode() {}
|
---|
71 | };
|
---|
72 |
|
---|
73 |
|
---|
74 | /** Converts obj format into objects readable by our format
|
---|
75 | */
|
---|
76 | class VisibilitySolutionConverter
|
---|
77 | {
|
---|
78 | public:
|
---|
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 |
|
---|
90 | protected:
|
---|
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 |
|
---|
140 |
|
---|
141 | //////////////////////////////////
|
---|
142 |
|
---|
143 | std::vector<Geometry *> mGeometry;
|
---|
144 |
|
---|
145 | int mNumShapes;
|
---|
146 |
|
---|
147 | std::vector<int> mGlobalTriangleIds;
|
---|
148 |
|
---|
149 | std::vector<BvhLeaf *> mBvhLeaves;
|
---|
150 |
|
---|
151 | BvhNode *mRoot;
|
---|
152 |
|
---|
153 | int mNumNodes;
|
---|
154 | };
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | #endif
|
---|