[372] | 1 | #ifndef _ViewCell_H__
|
---|
| 2 | #define _ViewCell_H__
|
---|
| 3 |
|
---|
| 4 | #include "Mesh.h"
|
---|
| 5 | #include "Containers.h"
|
---|
| 6 | #include "Ray.h"
|
---|
[462] | 7 | #include "Statistics.h"
|
---|
[372] | 8 | //namespace GtpVisibilityPreprocessor {
|
---|
[469] | 9 |
|
---|
| 10 | struct Triangle3;
|
---|
| 11 |
|
---|
[372] | 12 | class BspInterior;
|
---|
| 13 | class BspPvs;
|
---|
| 14 | class BspLeaf;
|
---|
[453] | 15 | class VspKdTree;
|
---|
[462] | 16 | class VspKdLeaf;
|
---|
[469] | 17 | class KdLeaf;
|
---|
[372] | 18 |
|
---|
[479] | 19 | /** Statistics for a view cell partition.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | class ViewCellsStatistics: public StatisticsBase
|
---|
| 23 | {
|
---|
| 24 | public:
|
---|
| 25 |
|
---|
| 26 | /// number of view cells
|
---|
| 27 | int viewCells;
|
---|
| 28 |
|
---|
| 29 | /// size of the PVS
|
---|
| 30 | int pvs;
|
---|
| 31 |
|
---|
| 32 | /// largest PVS of all view cells
|
---|
| 33 | int maxPvs;
|
---|
| 34 |
|
---|
| 35 | /// smallest PVS of all view cells
|
---|
| 36 | int minPvs;
|
---|
| 37 |
|
---|
| 38 | /// view cells with empty PVS
|
---|
| 39 | int emptyPvs;
|
---|
| 40 |
|
---|
| 41 | /// number of leaves covering the view space
|
---|
| 42 | int leaves;
|
---|
| 43 |
|
---|
| 44 | /// largest number of leaves covered by one view cell
|
---|
| 45 | int maxLeaves;
|
---|
| 46 |
|
---|
| 47 | // Constructor
|
---|
| 48 | ViewCellsStatistics()
|
---|
| 49 | {
|
---|
| 50 | Reset();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | double AvgLeaves() const {return (double)leaves / (double)viewCells;};
|
---|
| 54 | double AvgPvs() const {return (double)pvs / (double)viewCells;};
|
---|
| 55 |
|
---|
| 56 | void Reset()
|
---|
| 57 | {
|
---|
| 58 | viewCells = 0;
|
---|
| 59 | pvs = 0;
|
---|
| 60 | maxPvs = 0;
|
---|
| 61 |
|
---|
| 62 | minPvs = 999999;
|
---|
| 63 | emptyPvs = 0;
|
---|
| 64 | leaves = 0;
|
---|
| 65 | maxLeaves = 0;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | void Print(ostream &app) const;
|
---|
| 69 |
|
---|
| 70 | friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
|
---|
| 71 | {
|
---|
| 72 | stat.Print(s);
|
---|
| 73 | return s;
|
---|
| 74 | }
|
---|
| 75 | };
|
---|
| 76 |
|
---|
[372] | 77 | /**
|
---|
| 78 | View cell with an optional mesh representation
|
---|
| 79 | */
|
---|
| 80 | class ViewCell: public MeshInstance
|
---|
| 81 | {
|
---|
| 82 | public:
|
---|
| 83 | ViewCell();
|
---|
[471] | 84 |
|
---|
[372] | 85 | /** Constructor taking a mesh representing the shape of the viewcell.
|
---|
| 86 | */
|
---|
| 87 | ViewCell(Mesh *mesh);
|
---|
[462] | 88 |
|
---|
[469] | 89 | /** Default destructor.
|
---|
| 90 | */
|
---|
[462] | 91 | virtual ~ViewCell() {}
|
---|
[471] | 92 | /** Returns Pvs.
|
---|
[372] | 93 | */
|
---|
[469] | 94 | const ObjectPvs &GetPvs() const;
|
---|
| 95 | ObjectPvs &GetPvs();
|
---|
[372] | 96 |
|
---|
| 97 | int Type() const;
|
---|
[471] | 98 |
|
---|
[372] | 99 | /** Adds a passing ray to the passing ray container.
|
---|
| 100 | */
|
---|
[471] | 101 | void AddPassingRay(const Ray &ray, const int contributions);
|
---|
[372] | 102 |
|
---|
[469] | 103 | /** Returns volume of the view cell.
|
---|
| 104 | */
|
---|
[478] | 105 | float GetVolume() const;
|
---|
[372] | 106 |
|
---|
[478] | 107 | /** Returns area of the view cell.
|
---|
[469] | 108 | */
|
---|
[478] | 109 | float GetArea() const;
|
---|
[469] | 110 |
|
---|
[478] | 111 | /** Sets the volume of the view cell.
|
---|
| 112 | */
|
---|
| 113 | void SetVolume(float volume);
|
---|
| 114 |
|
---|
| 115 | /** Sets the area of the view cell.
|
---|
| 116 | */
|
---|
| 117 | void SetArea(float area);
|
---|
[503] | 118 |
|
---|
| 119 | /** Updates the view cell statstics for this particular view cell.
|
---|
| 120 | */
|
---|
[479] | 121 | virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat);
|
---|
[478] | 122 |
|
---|
[471] | 123 | /// Ray set description of the rays passing through this node.
|
---|
[372] | 124 | PassingRaySet mPassingRays;
|
---|
| 125 |
|
---|
| 126 | /// Rays piercing this view cell.
|
---|
| 127 | RayContainer mPiercingRays;
|
---|
| 128 |
|
---|
[503] | 129 | /** Sets the mesh for this view cell.
|
---|
| 130 | */
|
---|
| 131 | void SetMesh(Mesh *mesh);
|
---|
| 132 |
|
---|
[372] | 133 | protected:
|
---|
| 134 |
|
---|
| 135 | /// the potentially visible objects
|
---|
[469] | 136 | ObjectPvs mPvs;
|
---|
| 137 |
|
---|
| 138 | float mVolume;
|
---|
[478] | 139 | float mArea;
|
---|
[372] | 140 | };
|
---|
| 141 |
|
---|
[469] | 142 | /**
|
---|
| 143 | View cell belonging to a hierarchy.
|
---|
| 144 | */
|
---|
| 145 | template<typename T>
|
---|
| 146 | class HierarchyViewCell: public ViewCell
|
---|
[366] | 147 | {
|
---|
| 148 | public:
|
---|
[469] | 149 | HierarchyViewCell<T>(): mLeaves(0) {}
|
---|
[471] | 150 | HierarchyViewCell<T>(Mesh *mesh):
|
---|
[469] | 151 | ViewCell(mesh), mLeaves(0) {}
|
---|
| 152 |
|
---|
[479] | 153 | void UpdateViewCellsStats(ViewCellsStatistics &vcStat)
|
---|
| 154 | {
|
---|
| 155 | ViewCell::UpdateViewCellsStats(vcStat);
|
---|
| 156 |
|
---|
| 157 | if ((int)mLeaves.size() > vcStat.maxLeaves)
|
---|
| 158 | vcStat.maxLeaves = (int)mLeaves.size();
|
---|
[520] | 159 | vcStat.leaves += (int)mLeaves.size();
|
---|
[479] | 160 | }
|
---|
| 161 |
|
---|
[469] | 162 | /// Leaves of the hierarchy which are part of this view cell.
|
---|
| 163 | std::vector<T> mLeaves;
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[479] | 166 |
|
---|
[469] | 167 | typedef HierarchyViewCell<BspLeaf *> BspViewCell;
|
---|
| 168 | typedef HierarchyViewCell<KdLeaf *> KdViewCell;
|
---|
| 169 | typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell;
|
---|
| 170 |
|
---|
[366] | 171 |
|
---|
[372] | 172 | #endif
|
---|