source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp @ 338

Revision 338, 1.9 KB checked in by mattausch, 19 years ago (diff)

fixed bug in balanced view cell criterium
started merge view cells functionality

RevLine 
[235]1#include "ViewCell.h"
2#include "Mesh.h"
[308]3#include "Intersectable.h"
[235]4#include "MeshKdTree.h"
5#include "Triangle3.h"
6
[308]7ViewCell::ViewCell(): MeshInstance(NULL)
[265]8{
9}
[235]10
[308]11ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh)
[235]12{
13}
14
[308]15ViewCellPvs &ViewCell::GetPvs()
[261]16{
[235]17        return mPvs;
18}
19
20int ViewCell::Type() const
21{
[308]22        return VIEW_CELL;
[235]23}
24
25void ViewCell::DeriveViewCells(const ObjectContainer &objects,
26                                                           ViewCellContainer &viewCells,
[239]27                                                           const int maxViewCells)
[235]28{
[237]29        // maximal max viewcells
[245]30        int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size();
[237]31
[338]32        for (int i = 0; i < limit; ++ i)
[235]33        {
34                Intersectable *object = objects[i];
[256]35               
[235]36                // extract the mesh instances
37                if (object->Type() == Intersectable::MESH_INSTANCE)
38                {
39                        MeshInstance *inst = dynamic_cast<MeshInstance *>(object);
40
41                        ViewCell *viewCell = new ViewCell(inst->GetMesh());
42                        viewCells.push_back(viewCell);
43                }
[237]44                //TODO: transformed meshes
[235]45        }
[245]46}
[260]47
[261]48ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height)
[260]49{
[261]50        // one mesh per view cell
[260]51        Mesh *mesh = new Mesh();
[261]52       
53        //-- construct prism
[260]54
[261]55        // bottom
[264]56        mesh->mFaces.push_back(new Face(2,1,0));
[261]57        // top
[264]58    mesh->mFaces.push_back(new Face(3,4,5));
[261]59        // sides
[264]60        mesh->mFaces.push_back(new Face(1, 4, 3, 0));
61        mesh->mFaces.push_back(new Face(2, 5, 4, 1));
62        mesh->mFaces.push_back(new Face(3, 5, 2, 0));
[261]63
64        //--- extrude new vertices for top of prism
65        Vector3 triNorm = baseTri.GetNormal();
66
67        Triangle3 topTri;       
68
69        // add base vertices and calculate top vertices
[323]70        for (int i = 0; i < 3; ++ i)
[313]71                 mesh->mVertices.push_back(baseTri.mVertices[i]);
[312]72       
[261]73        // add top vertices     
[333]74        for (i = 0; i < 3; ++ i)
[312]75                mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm);
[261]76       
[263]77        mesh->Preprocess();
78
[260]79        return new ViewCell(mesh);
80}
[308]81
82void ViewCell::AddPassingRay(const Ray &ray, const int contributions)
83{
84        mPassingRays.AddRay(ray, contributions);
[333]85}
Note: See TracBrowser for help on using the repository browser.