#ifndef _VISIBILITYSOLUTIONCONVERTER_H #define _VISIBILITYSOLUTIONCONVERTER_H #include "Vector3.h" #include "Triangle3.h" #include #include #include "AxisAlignedBox3.h" typedef std::vector VertexArray; typedef std::pair TexCoord; class ogzstream; struct BvhInterior; struct Geometry { CHCDemoEngine::Vector3 *mVertices; CHCDemoEngine::Vector3 *mNormals; TexCoord *mTexCoords; int mVertexCount; int mTexcoordCount; }; struct BvhNode { int id; char axis; unsigned char depth; short flags; // indices to first and last triangle in the triangle array // assumes the traingle are placed in continuous chunk of memory // however this need not be a global array! int first; // one after the last triangle! int last; BvhNode(): axis(-1), first(-1), flags(0) {} bool IsLeaf() { return axis == -1; } bool Empty() const { return first == -1; } int Count() const { return last - first + 1; } CHCDemoEngine::AxisAlignedBox3 box; BvhInterior *parent; std::vector mTriangleIds; }; struct BvhInterior: public BvhNode { BvhInterior():back(NULL), front(NULL) { } BvhNode *back; BvhNode *front; }; struct BvhLeaf: public BvhNode { Geometry *geometry; BvhLeaf(): BvhNode(), geometry(NULL) {} }; /** Converts obj format into objects readable by our format */ class VisibilitySolutionConverter { public: VisibilitySolutionConverter(); ~VisibilitySolutionConverter(); bool Convert(const std::string &sceneInputFilename, const std::string &sceneOutputFilename, const std::string &bvhInputFilename, const std::string &bvhOutputFilename); protected: void LoadShape(const VertexArray &vertices, const VertexArray &normals, const std::vector &texCoords); void WriteGeometry(ogzstream &str, Geometry *geom); bool ReadScene(const std::string &iFilename); bool WriteScene(const std::string &oFilename); bool ReadBvh(FILE *fr); bool WriteBvh(const std::string &oFilename); void ConstructBvhObjects(const VertexArray &vertices, const VertexArray &normals, const std::vector &texCoords); bool LoadSolution(const std::string &filename); BvhNode *LoadNode(FILE *fr, int depth); bool ReadDummyTree(FILE *fr); bool ReadObj(const std::string &filename, VertexArray &vertices, VertexArray &normals, std::vector &texcoords); bool ReadSimpleObj(const std::string &filename, VertexArray &vertices, VertexArray &normals, std::vector &texcoords); bool ReadBinObj(const std::string &filename, VertexArray &vertices, float scale); bool WriteBinObj(const std::string &filename, const VertexArray &vertices); bool ExportBinObj(const std::string &filename, const VertexArray &vertices); void WriteNextNode(ogzstream &stream, BvhNode *parent); void UpdateLeafBox(BvhLeaf *leaf); void UpdateNodeBox(BvhNode *node); ////////////////////////////////// std::vector mGeometry; int mNumShapes; std::vector mGlobalTriangleIds; std::vector mBvhLeaves; BvhNode *mRoot; int mNumNodes; }; #endif