[3235] | 1 | #ifndef _VISIBILITYSOLUTIONCONVERTER_H
|
---|
| 2 | #define _VISIBILITYSOLUTIONCONVERTER_H
|
---|
[3234] | 3 |
|
---|
[3235] | 4 |
|
---|
[3241] | 5 | #include "Vector3.h"
|
---|
| 6 | #include "Triangle3.h"
|
---|
[3234] | 7 | #include <string>
|
---|
| 8 | #include <vector>
|
---|
[3240] | 9 | #include "AxisAlignedBox3.h"
|
---|
[3234] | 10 |
|
---|
[3241] | 11 |
|
---|
[3234] | 12 |
|
---|
[3241] | 13 | typedef std::vector<CHCDemoEngine::Vector3> VertexArray;
|
---|
[3235] | 14 | typedef std::pair<float, float> TexCoord;
|
---|
[3234] | 15 |
|
---|
| 16 | class ogzstream;
|
---|
| 17 |
|
---|
[3239] | 18 | struct BvhInterior;
|
---|
[3235] | 19 |
|
---|
[3241] | 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 |
|
---|
[3235] | 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 |
|
---|
[3241] | 53 | CHCDemoEngine::AxisAlignedBox3 box;
|
---|
[3239] | 54 |
|
---|
| 55 | BvhInterior *parent;
|
---|
[3235] | 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 | {
|
---|
[3242] | 70 | BvhLeaf(): BvhNode() {}
|
---|
[3235] | 71 | };
|
---|
| 72 |
|
---|
| 73 |
|
---|
[3234] | 74 | /** Converts obj format into objects readable by our format
|
---|
| 75 | */
|
---|
[3235] | 76 | class VisibilitySolutionConverter
|
---|
[3234] | 77 | {
|
---|
| 78 | public:
|
---|
| 79 |
|
---|
[3235] | 80 | VisibilitySolutionConverter();
|
---|
[3234] | 81 |
|
---|
[3235] | 82 | ~VisibilitySolutionConverter();
|
---|
[3234] | 83 |
|
---|
[3235] | 84 | bool Convert(const std::string &sceneInputFilename,
|
---|
| 85 | const std::string &sceneOutputFilename,
|
---|
| 86 | const std::string &bvhInputFilename,
|
---|
| 87 | const std::string &bvhOutputFilename);
|
---|
| 88 |
|
---|
[3234] | 89 |
|
---|
| 90 | protected:
|
---|
| 91 |
|
---|
| 92 |
|
---|
[3235] | 93 | void LoadShape(const VertexArray &vertices,
|
---|
| 94 | const VertexArray &normals,
|
---|
| 95 | const std::vector<TexCoord> &texCoords);
|
---|
[3234] | 96 |
|
---|
| 97 | void WriteGeometry(ogzstream &str, Geometry *geom);
|
---|
| 98 |
|
---|
[3235] | 99 | bool ReadScene(const std::string &iFilename);
|
---|
[3234] | 100 |
|
---|
[3235] | 101 | bool WriteScene(const std::string &oFilename);
|
---|
[3234] | 102 |
|
---|
[3235] | 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 |
|
---|
[3238] | 118 | bool ReadObj(const std::string &filename,
|
---|
| 119 | VertexArray &vertices,
|
---|
| 120 | VertexArray &normals,
|
---|
| 121 | std::vector<TexCoord> &texcoords);
|
---|
| 122 |
|
---|
| 123 | bool ReadSimpleObj(const std::string &filename,
|
---|
| 124 | VertexArray &vertices,
|
---|
| 125 | VertexArray &normals,
|
---|
| 126 | std::vector<TexCoord> &texcoords);
|
---|
[3235] | 127 |
|
---|
[3238] | 128 | bool ReadBinObj(const std::string &filename,
|
---|
| 129 | VertexArray &vertices,
|
---|
| 130 | float scale);
|
---|
[3235] | 131 |
|
---|
[3239] | 132 | bool WriteBinObj(const std::string &filename,
|
---|
| 133 | const VertexArray &vertices);
|
---|
| 134 |
|
---|
[3238] | 135 | bool ExportBinObj(const std::string &filename,
|
---|
[3239] | 136 | const VertexArray &vertices);
|
---|
[3238] | 137 |
|
---|
[3240] | 138 | void WriteNextNode(ogzstream &stream, BvhNode *parent);
|
---|
[3239] | 139 |
|
---|
[3241] | 140 | void UpdateLeafBox(BvhLeaf *leaf);
|
---|
[3242] | 141 | /** Prepare bvh for exporting.
|
---|
| 142 | */
|
---|
| 143 | void UpdateBvh(BvhNode *node);
|
---|
[3239] | 144 |
|
---|
| 145 |
|
---|
[3243] | 146 |
|
---|
[3235] | 147 | //////////////////////////////////
|
---|
| 148 |
|
---|
[3234] | 149 | std::vector<Geometry *> mGeometry;
|
---|
| 150 |
|
---|
| 151 | int mNumShapes;
|
---|
[3235] | 152 |
|
---|
| 153 | std::vector<int> mGlobalTriangleIds;
|
---|
| 154 |
|
---|
[3241] | 155 | std::vector<BvhLeaf *> mBvhLeaves;
|
---|
[3235] | 156 |
|
---|
| 157 | BvhNode *mRoot;
|
---|
| 158 |
|
---|
| 159 | int mNumNodes;
|
---|
[3234] | 160 | };
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | #endif
|
---|