1 | #ifndef _VISIBILITYSOLUTIONCONVERTER_H
|
---|
2 | #define _VISIBILITYSOLUTIONCONVERTER_H
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "SimpleVec.h"
|
---|
6 | #include <string>
|
---|
7 | #include <vector>
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 | typedef std::vector<SimpleVec> VertexArray;
|
---|
12 | typedef std::pair<float, float> TexCoord;
|
---|
13 |
|
---|
14 | class ogzstream;
|
---|
15 |
|
---|
16 |
|
---|
17 | struct BvhNode
|
---|
18 | {
|
---|
19 | int id;
|
---|
20 | char axis;
|
---|
21 | unsigned char depth;
|
---|
22 | short flags;
|
---|
23 |
|
---|
24 | // indices to first and last triangle in the triangle array
|
---|
25 | // assumes the traingle are placed in continuous chunk of memory
|
---|
26 | // however this need not be a global array!
|
---|
27 | int first;
|
---|
28 | // one after the last triangle!
|
---|
29 | int last;
|
---|
30 |
|
---|
31 | BvhNode(): axis(-1), first(-1), flags(0) {}
|
---|
32 |
|
---|
33 | bool IsLeaf() { return axis == -1; }
|
---|
34 | bool Empty() const { return first == -1; }
|
---|
35 | int Count() const { return last - first + 1; }
|
---|
36 |
|
---|
37 | std::vector<int> mTriangleIds;
|
---|
38 | };
|
---|
39 |
|
---|
40 |
|
---|
41 | struct BvhInterior: public BvhNode
|
---|
42 | {
|
---|
43 | BvhInterior():back(NULL), front(NULL) { }
|
---|
44 | BvhNode *back;
|
---|
45 | BvhNode *front;
|
---|
46 | };
|
---|
47 |
|
---|
48 |
|
---|
49 | struct BvhLeaf: public BvhNode
|
---|
50 | {
|
---|
51 | //Color color;
|
---|
52 | int texture;
|
---|
53 |
|
---|
54 | BvhLeaf(): BvhNode(), texture(0) {}
|
---|
55 | };
|
---|
56 |
|
---|
57 |
|
---|
58 | /** Converts obj format into objects readable by our format
|
---|
59 | */
|
---|
60 | class VisibilitySolutionConverter
|
---|
61 | {
|
---|
62 | public:
|
---|
63 |
|
---|
64 | VisibilitySolutionConverter();
|
---|
65 |
|
---|
66 | ~VisibilitySolutionConverter();
|
---|
67 |
|
---|
68 | bool Convert(const std::string &sceneInputFilename,
|
---|
69 | const std::string &sceneOutputFilename,
|
---|
70 | const std::string &bvhInputFilename,
|
---|
71 | const std::string &bvhOutputFilename);
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | protected:
|
---|
76 |
|
---|
77 | struct Geometry
|
---|
78 | {
|
---|
79 | SimpleVec *mVertices;
|
---|
80 | SimpleVec *mNormals;
|
---|
81 | TexCoord *mTexCoords;
|
---|
82 |
|
---|
83 | int mVertexCount;
|
---|
84 | int mTexcoordCount;
|
---|
85 | };
|
---|
86 |
|
---|
87 | void LoadShape(const VertexArray &vertices,
|
---|
88 | const VertexArray &normals,
|
---|
89 | const std::vector<TexCoord> &texCoords);
|
---|
90 |
|
---|
91 | void WriteGeometry(ogzstream &str, Geometry *geom);
|
---|
92 |
|
---|
93 | bool ReadScene(const std::string &iFilename);
|
---|
94 |
|
---|
95 | bool WriteScene(const std::string &oFilename);
|
---|
96 |
|
---|
97 | bool ReadBvh(FILE *fr);
|
---|
98 |
|
---|
99 | bool WriteBvh(const std::string &oFilename);
|
---|
100 |
|
---|
101 | void ConstructBvhObjects(const VertexArray &vertices,
|
---|
102 | const VertexArray &normals,
|
---|
103 | const std::vector<TexCoord> &texCoords);
|
---|
104 |
|
---|
105 | bool LoadSolution(const std::string &filename);
|
---|
106 |
|
---|
107 |
|
---|
108 | BvhNode *LoadNode(FILE *fr, int depth);
|
---|
109 |
|
---|
110 | bool ReadDummyTree(FILE *fr);
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 | //////////////////////////////////
|
---|
115 |
|
---|
116 | std::vector<Geometry *> mGeometry;
|
---|
117 |
|
---|
118 | int mNumShapes;
|
---|
119 |
|
---|
120 | std::vector<int> mGlobalTriangleIds;
|
---|
121 |
|
---|
122 | std::vector<BvhNode *> mBvhNodes;
|
---|
123 |
|
---|
124 | BvhNode *mRoot;
|
---|
125 |
|
---|
126 | int mNumNodes;
|
---|
127 | };
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | #endif
|
---|