#include "ViewCell.h" #include "Mesh.h" #include "Intersectable.h" #include "MeshKdTree.h" #include "Triangle3.h" ViewCell::ViewCell(): MeshInstance(NULL), mPiercingRays(0) { } ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh), mPiercingRays(0) { } ViewCellPvs &ViewCell::GetPvs() { return mPvs; } int ViewCell::Type() const { return VIEW_CELL; } void ViewCell::DeriveViewCells(const ObjectContainer &objects, ViewCellContainer &viewCells, const int maxViewCells) { // maximal max viewcells int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size(); for (int i = 0; i < limit; ++ i) { Intersectable *object = objects[i]; // extract the mesh instances if (object->Type() == Intersectable::MESH_INSTANCE) { MeshInstance *inst = dynamic_cast(object); ViewCell *viewCell = new ViewCell(inst->GetMesh()); viewCells.push_back(viewCell); } //TODO: transformed meshes } } ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) { int i; // one mesh per view cell Mesh *mesh = new Mesh(); //-- construct prism // bottom mesh->mFaces.push_back(new Face(2,1,0)); // top mesh->mFaces.push_back(new Face(3,4,5)); // sides mesh->mFaces.push_back(new Face(1, 4, 3, 0)); mesh->mFaces.push_back(new Face(2, 5, 4, 1)); mesh->mFaces.push_back(new Face(3, 5, 2, 0)); //--- extrude new vertices for top of prism Vector3 triNorm = baseTri.GetNormal(); Triangle3 topTri; // add base vertices and calculate top vertices for (i = 0; i < 3; ++ i) mesh->mVertices.push_back(baseTri.mVertices[i]); // add top vertices for (i = 0; i < 3; ++ i) mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); mesh->Preprocess(); return new ViewCell(mesh); } ViewCell *ViewCell::Merge(ViewCell &front, ViewCell &back) { ViewCell *vc = new ViewCell(); // merge pvs vc->mPvs.Merge(front.mPvs, back.mPvs); // merge ray sets stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end()); stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end()); std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), back.mPiercingRays.begin(), back.mPiercingRays.end(), vc->mPiercingRays.begin()); return vc; } void ViewCell::AddPassingRay(const Ray &ray, const int contributions) { mPassingRays.AddRay(ray, contributions); }