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

Revision 3240, 3.2 KB checked in by mattausch, 15 years ago (diff)
Line 
1#ifndef _VISIBILITYSOLUTIONCONVERTER_H
2#define _VISIBILITYSOLUTIONCONVERTER_H
3
4
5#include "SimpleVec.h"
6#include <string>
7#include <vector>
8#include "AxisAlignedBox3.h"
9
10
11typedef std::vector<SimpleVec> VertexArray;
12typedef std::pair<float, float> TexCoord;
13
14class ogzstream;
15
16struct BvhInterior;
17
18struct BvhNode
19{
20        int id;
21        char axis;
22        unsigned char depth;
23        short flags;
24
25        // indices to first and last triangle in the triangle array
26        // assumes the traingle are placed in continuous chunk of memory
27        // however this need not be a global array!
28        int first;
29        // one after the last triangle!
30        int last;
31
32        BvhNode(): axis(-1), first(-1), flags(0) {}
33
34        bool IsLeaf() { return axis == -1; }
35        bool Empty() const { return first == -1; }
36        int Count() const { return last - first + 1; }
37
38        SimpleVec bmin;
39        SimpleVec bmax;
40
41        BvhInterior *parent;
42        std::vector<int> mTriangleIds;
43};
44
45
46struct BvhInterior: public BvhNode
47{
48        BvhInterior():back(NULL), front(NULL) { }
49        BvhNode *back;
50        BvhNode *front;
51};
52
53
54struct BvhLeaf: public BvhNode
55{
56        //Color color;
57        int texture;
58
59        BvhLeaf(): BvhNode(), texture(0) {}
60};
61
62
63/** Converts obj format into objects readable by our format
64*/
65class VisibilitySolutionConverter
66{
67public:
68
69        VisibilitySolutionConverter();
70
71        ~VisibilitySolutionConverter();
72
73        bool Convert(const std::string &sceneInputFilename,
74                                 const std::string &sceneOutputFilename,
75                                 const std::string &bvhInputFilename,
76                         const std::string &bvhOutputFilename);
77       
78
79protected:
80
81        struct Geometry
82        {
83                SimpleVec *mVertices;
84                SimpleVec *mNormals;
85                TexCoord *mTexCoords;
86
87                int mVertexCount;
88                int mTexcoordCount;
89        };
90
91        void LoadShape(const VertexArray &vertices,
92                           const VertexArray &normals,
93                                   const std::vector<TexCoord> &texCoords);
94
95        void WriteGeometry(ogzstream &str, Geometry *geom);
96
97        bool ReadScene(const std::string &iFilename);
98
99        bool WriteScene(const std::string &oFilename);
100
101        bool ReadBvh(FILE *fr);
102
103        bool WriteBvh(const std::string &oFilename);
104
105        void ConstructBvhObjects(const VertexArray &vertices,
106                                     const VertexArray &normals,
107                                                         const std::vector<TexCoord> &texCoords);
108
109        bool LoadSolution(const std::string &filename);
110
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 ReadSimpleObj(const std::string &filename,
122                               VertexArray &vertices,
123                                           VertexArray &normals,
124                                           std::vector<TexCoord> &texcoords);
125
126        bool ReadBinObj(const std::string &filename,
127                    VertexArray &vertices,
128                                        float scale);
129
130        bool WriteBinObj(const std::string &filename,
131                             const VertexArray &vertices);
132
133        bool ExportBinObj(const std::string &filename,
134                              const VertexArray &vertices);
135
136        void WriteNextNode(ogzstream &stream, BvhNode *parent);
137
138
139
140        //////////////////////////////////
141
142        std::vector<Geometry *> mGeometry;
143
144        int mNumShapes;
145
146        std::vector<int> mGlobalTriangleIds;
147
148        std::vector<BvhNode *> mBvhNodes;
149
150        BvhNode *mRoot;
151
152        int mNumNodes;
153};
154
155
156
157#endif
Note: See TracBrowser for help on using the repository browser.