#ifndef _VISIBILITYSOLUTIONCONVERTER_H #define _VISIBILITYSOLUTIONCONVERTER_H #include "SimpleVec.h" #include #include #include "AxisAlignedBox3.h" typedef std::vector VertexArray; typedef std::pair TexCoord; class ogzstream; struct BvhInterior; 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; } SimpleVec bmin; SimpleVec bmax; BvhInterior *parent; std::vector mTriangleIds; }; struct BvhInterior: public BvhNode { BvhInterior():back(NULL), front(NULL) { } BvhNode *back; BvhNode *front; }; struct BvhLeaf: public BvhNode { //Color color; int texture; BvhLeaf(): BvhNode(), texture(0) {} }; /** 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: struct Geometry { SimpleVec *mVertices; SimpleVec *mNormals; TexCoord *mTexCoords; int mVertexCount; int mTexcoordCount; }; 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); ////////////////////////////////// std::vector mGeometry; int mNumShapes; std::vector mGlobalTriangleIds; std::vector mBvhNodes; BvhNode *mRoot; int mNumNodes; }; #endif