source: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h @ 2539

Revision 2539, 20.6 KB checked in by mattausch, 17 years ago (diff)

fixed obj loading error

RevLine 
[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"
[608]8#include "Material.h"
[955]9#include "gzstream.h"
[2116]10#include "ObjectPvs.h"
[469]11
[860]12namespace GtpVisibilityPreprocessor {
13
[469]14struct Triangle3;
15
[372]16class BspInterior;
17class BspPvs;
18class BspLeaf;
[1008]19class VspLeaf;
[469]20class KdLeaf;
[580]21class ViewCellInterior;
22class MergeCandidate;
23class ViewCellsManager;
[881]24class ViewCellLeaf;
[372]25
[955]26
[2116]27//class ObjectPvs;
[1264]28
[2116]29
[479]30/** Statistics for a view cell partition.
31*/
32
33class ViewCellsStatistics: public StatisticsBase
34{
35public:
36
37        /// number of view cells
38        int viewCells;
[1709]39        /// cost of the PVS
40        float pvsCost;
[479]41        /// largest PVS of all view cells
[1709]42        float maxPvs;
[479]43        /// smallest PVS of all view cells
[1709]44        float minPvs;
[479]45        /// view cells with empty PVS
46        int emptyPvs;
47        /// number of leaves covering the view space
48        int leaves;
49        /// largest number of leaves covered by one view cell
50        int maxLeaves;
[1667]51        /// number of invalid view cells
[564]52        int invalid;
53
[479]54    // Constructor
55        ViewCellsStatistics()
56        {
57                Reset();
58        }
59
60        double AvgLeaves() const {return (double)leaves / (double)viewCells;};
[1709]61        double AvgPvs() const {return (double)pvsCost / (double)viewCells;};
[479]62
63        void Reset()
64        {
65                viewCells = 0;
[1709]66                pvsCost = 0;
[479]67                maxPvs = 0;
68
69                minPvs = 999999;
70                emptyPvs = 0;
71                leaves = 0;
72                maxLeaves = 0;
[564]73                invalid = 0;
[479]74        }
75
[2176]76        void Print(std::ostream &app) const;
[479]77
[2176]78        friend std::ostream &operator<<(std::ostream &s, const ViewCellsStatistics &stat)
[479]79        {
80                stat.Print(s);
81                return s;
82        }
83};
84
[580]85
[1709]86class ViewCellsTreeStats
87{
88public:
89        int mPass;
90   
91        int mNumViewCells;
92               
93        float mRenderCostDecrease;
94
95    float mTotalRenderCost;
96   
97        float mCurrentPvsCost;
98                                                       
99        float mExpectedCost;
100   
101        float mAvgRenderCost;
102       
103        float mDeviation;
104                       
105        float mTotalPvsCost;
106       
107        int mEntriesInPvs;
108   
109        float mMemoryCost;
110       
111        int mPvsSizeDecr;
[1771]112 
[1709]113        float mVolume;
114
115
116        void Reset()
117        {
118                mPass = 0;
119                mNumViewCells = 0;
120                mRenderCostDecrease = 0;
121                mTotalRenderCost = 0;
122                mCurrentPvsCost = 0;
123                mExpectedCost = 0;
124                mAvgRenderCost = 0;
125                mDeviation = 0;
126                mTotalPvsCost = 0;
127                mEntriesInPvs = 0;
128                mMemoryCost = 0;
129                mPvsSizeDecr = 0;
130                mVolume = 0;
131        }
132
133
[2176]134        void Print(std::ostream &app) const;
[1709]135
[2176]136        friend std::ostream &operator<<(std::ostream &s, const ViewCellsTreeStats &stat)
[1709]137        {
138                stat.Print(s);
139                return s;
140        }
141};
142
143
[372]144/**
[1667]145        A view cell. View cells are regions in space. The visibility informations,
146        i.e., the primitives seen by the view cell are stored in a PVs.
147        A view cell can be represented in many different ways, e.g.,
148        a mesh representation.
[372]149*/
150class ViewCell: public MeshInstance
151{
[752]152        friend class ViewCellsTree;
153        friend class ViewCellsManager;
154
[372]155public:
[1999]156
[372]157        ViewCell();
[471]158
[372]159        /** Constructor taking a mesh representing the shape of the viewcell.
160        */
161        ViewCell(Mesh *mesh);
[462]162
[469]163        /** Default destructor.
164        */
[1551]165        virtual ~ViewCell();
[471]166        /** Returns Pvs.
[372]167        */
[469]168        const ObjectPvs &GetPvs() const;
[1002]169        /** Returns pvs.
170        */
[469]171        ObjectPvs &GetPvs();
[1002]172        /** Completely substitutes the pvs.
173        */
[880]174        void SetPvs(const ObjectPvs &pvs);
[2199]175        /** Type of view cell.
[752]176        */
[372]177        int Type() const;
178        /** Adds a passing ray to the passing ray container.
179        */
[471]180        void AddPassingRay(const Ray &ray, const int contributions);
[469]181        /** Returns volume of the view cell.
182        */
[2199]183        inline float GetVolume() const
184        {
185                return mVolume;
186        }
187        /** Sets the volume of the view cell.
188        */
189        inline void SetVolume(float volume)
190        {
191                mVolume = volume;
192        }
[478]193        /** Returns area of the view cell.
[469]194        */
[2199]195        inline float GetArea() const
196        {
197                return mArea;
198        }
[478]199        /** Sets the area of the view cell.
200        */
[2199]201        void SetArea(float area)
202        {
203                mArea = area;
204        }
[580]205        /** if this view cell is the root of a view cell hierarchy
206        */
207        bool IsRoot() const;
208        /** Returns parent view cell.
209        */
210        ViewCellInterior *GetParent() const;
[1002]211        /** Sets parent of this view cell.
212        */
213        void SetParent(ViewCellInterior *parent);
[503]214        /** Sets the mesh for this view cell.
215        */
216        void SetMesh(Mesh *mesh);
[1002]217        /** Sets this view cell to be a valid view cell according to some criteria.
218        */
[547]219        void SetValid(const bool valid);
[1002]220        /** Returns true if this view cell is considered to be valid according to
221                some criteria.
222        */
[547]223        bool GetValid() const;
224
[728]225        /** Returns estimated render cost of this view cell.
226        */
227        float GetRenderCost() const;
[580]228
[752]229        /** set color for visiualizations.
230        */
231        void SetColor(const RgbColor &color);
[580]232
[752]233        /** get color for visualuzations.
234        */
235    RgbColor GetColor() const;
[580]236
[1002]237        /** Adds a sample to the pvs.
238                @param sample the sample to be added
239                @param pdf a continuos measure of visibility
240                @param contribution returns the contribution of this sample to the pvs
241        */
242        bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution);
[580]243
244        /** if this is a view cell correspending to a leaf in a hierarchy.
245        */
246        virtual bool IsLeaf() const = 0;
247
[2387]248        friend inline bool SmallerPvs(const ViewCell *a, const ViewCell *b);
249        friend inline bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b);
250        friend inline bool SmallerRenderCost(const ViewCell *a, const ViewCell *b);
251        friend inline bool LargerRenderCost(const ViewCell *a, const ViewCell *b);
252       
[569]253
[1002]254        /** Sets merge cost used for merging this view cell from other cells.
255                @hack The function is available for leaves also to have a common interface,
256                but it should be less than zero for leaves.
[1999]257        */
[600]258        void SetMergeCost(const float mergeCost);
[997]259
[1002]260        /** Returns merge cost needed to merge this leaf from other cells.
261                @hack The function is available for leaves also to have a common interface,
262                but it should be less than zero for leaves.
263        */
[600]264        float GetMergeCost() const;
[997]265
[1999]266        void UpdatePvsCost() {
267                mPvsCost = GetPvs().EvalPvsCost();
268        }
[1002]269
[2342]270        void SetTrianglesInPvs(const float c) {
[1999]271                mPvsCost = c;
272        }
[1771]273
[2332]274        void SetEntriesInPvs(const int e) {
275                mEntriesInPvs = e;
276        }
277
[2342]278        float GetTrianglesInPvs() const {
[1999]279                return mPvsCost;
280        }
[1761]281
[2332]282        int GetEntriesInPvs() const {
283                return mEntriesInPvs;
284        }
285
[1999]286        int GetFilteredPvsSize() const
287        {
288                return mFilteredPvsSize;
289        }
290
291        void SetFilteredPvsSize(const int s) {
292                mFilteredPvsSize = s;
[2124]293        }
[1771]294
[2124]295        //virtual int ViewCellType;
296
[372]297protected:
298
[1002]299        /// parent view cell in the view cell hierarchy
300        ViewCellInterior *mParent;
[372]301        /// the potentially visible objects
[469]302        ObjectPvs mPvs;
[1160]303        /// the volume of this view cell
[469]304        float mVolume;
[1545]305        /// the area of this view cell
[478]306        float mArea;
[1160]307        /// the cost that were paid for merging this view cells from two others.
[600]308        float mMergeCost;
[1160]309        /// if the view cell is valid view space
[547]310        bool mValid;
[881]311        /// color used for consistent visualization
[660]312        RgbColor mColor;
[1002]313        /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves
[1709]314        float mPvsCost;
[2332]315        /// stores number of entries in pvs
[1160]316        int mEntriesInPvs;
[1297]317        /** if the pvs size scalar (+ entries into pvs)
318                is up to date and corresponding to the real pvs size
319        */
[752]320        bool mPvsSizeValid;
[1771]321
[1999]322        /// Filter cost of the pvs
323        int mFilteredPvsSize;
324
[372]325};
326
[2387]327inline bool SmallerPvs(const ViewCell *a, const ViewCell *b)
328{
329        // HACK: take scalar value because pvs may not have been stored properly
330#if 1
331        return a->mPvsCost < b->mPvsCost;
332#else
333        return a->GetPvs().EvalPvsCost() < b->GetPvs().EvalPvsCost();
334#endif
335}
[580]336
[2387]337inline bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b)
338{
339        return !SmallerPvs(a, b);
340}
341
342inline bool SmallerRenderCost(const ViewCell *a, const ViewCell *b)
343{
344        return a->GetRenderCost() < b->GetRenderCost();
345}
346
347inline bool LargerRenderCost(const ViewCell *a, const ViewCell *b)
348{
349        return a->GetRenderCost() > b->GetRenderCost();
350}
351
[580]352class ViewCellInterior: public ViewCell
353{
[752]354        friend class ViewCellsManager;
[1284]355
[580]356public:
357        ViewCellInterior();
358        ~ViewCellInterior();
359
360        ViewCellInterior(Mesh *mesh);
[1999]361
[580]362        /** Sets pointer from parent to child and vice versa.
363        */
364        void SetupChildLink(ViewCell *l);
[1286]365        void ReplaceChildLink(ViewCell *prev, ViewCell *cur);
366
[586]367        void RemoveChildLink(ViewCell *l);
[580]368        bool IsLeaf() const;
369
[1284]370        void SetCost(const float c) {
371                mCost = c;
372        }
[1999]373
[1284]374        float GetCost() const {
375                return mCost;
376        }
377
[1999]378        ViewCellContainer mChildren;
379
[608]380protected:
[1999]381
382        /// Pverall cost resulting from the merge.
383        float mCost;
[580]384};
385
[881]386
[469]387/**
[881]388        Leaf of the view cell.
[469]389*/
[580]390class ViewCellLeaf: public ViewCell
[366]391{
392public:
[881]393        ViewCellLeaf()  {  mActiveViewCell = this; }
394        ViewCellLeaf(Mesh *mesh):
395        ViewCell(mesh) { mActiveViewCell = this; }
[469]396
[881]397        bool IsLeaf() const
398        {
399                return true;
400        }
401
[1551]402        /** Returns active view cell, i.e. this view cell or
403                a parent view cell which is set as active view cell.
[881]404        */
405        ViewCell *GetActiveViewCell() const
406        { return mActiveViewCell; }
407
408        /** Sets this view cell to be an active view cell.
409        */
410        void SetActiveViewCell(ViewCell *vc)
411        { mActiveViewCell = vc;}
[605]412       
[997]413        /** points to the currently active view cell. This is the
414                view cell representing the current brach.
415        */
[881]416        ViewCell *mActiveViewCell;
417};
[479]418
[1732]419
[1121]420/** Leaf of the view cell hierarchy corresponding
421        to a leaf in a spatial hierarchy.
[881]422*/
423template<typename T>
424class HierarchyLeafViewCell: public ViewCellLeaf
425{
426public:
427
428        HierarchyLeafViewCell<T>(): ViewCellLeaf() {  }
429        HierarchyLeafViewCell<T>(Mesh *mesh):
430        ViewCellLeaf(mesh) {  }
431               
[580]432        bool IsLeaf() const
433        {
434                return true;
435        }
436
[1551]437        /// Leaves of some hierarchy which contains this view cell.
438        vector<T> mLeaves;
[469]439};
440
[479]441
[1010]442typedef HierarchyLeafViewCell<VspLeaf *> VspViewCell;
[881]443typedef HierarchyLeafViewCell<BspLeaf *> BspViewCell;
444typedef HierarchyLeafViewCell<KdLeaf *> KdViewCell;
[469]445
[366]446
[580]447
[1008]448
[580]449class ViewCellsTree
450{
[600]451        friend class ViewCellsManager;
[1263]452        friend class ViewCellsParseHandlers;
[752]453
[580]454public:
[1999]455
[1264]456        ViewCellsTree();
[1999]457
[1004]458        /** View cells tree constructor taking a view cell mnanager as parameter
[997]459        */
[1004]460        ViewCellsTree(ViewCellsManager *vcm);
[580]461        ~ViewCellsTree();
462
463        /** Returns number of leaves this view cell consists of.
464        */
[736]465        int GetNumInitialViewCells(ViewCell *vc) const;
[580]466
467        /** Collects leaves corresponding to a view cell.
468        */
469        void CollectLeaves(ViewCell *vc, ViewCellContainer &leaves) const;
470
471        /** Merges view cells according to some cost heuristics.
472        */
473        int ConstructMergeTree(const VssRayContainer &rays, const ObjectContainer &objects);
474       
475        /** Refines view cells using shuffling, i.e., border leaves
476                of two view cells are exchanged if the resulting view cells
477                are tested to be "better" than the old ones.
478                @returns number of refined view cells
479        */
480        int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
[651]481       
482        /** Assign colors to the viewcells so that they can be renderered interactively without
[997]483            color flickering. 
484        */
[651]485        void AssignRandomColors();
[580]486
[997]487        /** Updates view cell stats for this particular view cell.
[605]488        */
489        void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat);
[580]490
[997]491        /** Get costs resulting from each merge step.
492        */
[651]493        void GetCostFunction(vector<float> &costFunction);
[1603]494       
495        /** Returns storage cost resulting from each merge step.
496        */
497        void GetStorageFunction(vector<int> &storageCost);
498
[580]499        /** Returns optimal set of view cells for a given number of view cells.
500        */
501        void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells);
502
[581]503        /** Root of view cells tree.
504        */
[584]505        ViewCell *GetRoot() const;
[581]506
[584]507        /** Returns pvs of view cell.
508                @note pvs is returned per reference if tree is not compressed,
509                per copy else.
510        */
511        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const;
512
[1709]513        /** Returns pvs size (i.e. the render cost of the stored objects)
[584]514        */
[2342]515        float GetTrianglesInPvs(ViewCell *vc) const;
[1761]516 
[1161]517        /** Returns number of entries associated with this view cell.
[1586]518
519                This returns the same value as the "GetPvsSize" function for object pvs
520                but most likely different values if we use object space grouping.
521                E.g., using bounding volumes.
[584]522        */
[1161]523        int GetPvsEntries(ViewCell *vc) const;
[584]524
[1586]525        /** Returns the number of physically stored entries in the view cells sub tree.
526                This can vary based on the current storage method
[1161]527        */
[1586]528        int CountStoredPvsEntries(ViewCell *root) const;
[1161]529
[584]530        /** Returns memory cost of this view cell.
531        */
532        float GetMemoryCost(ViewCell *vc) const;
533
[752]534        /** Sets method of storage for view cells.
[584]535        */
[752]536        void SetViewCellsStorage(int type);
[584]537
[837]538        /** pvs storage methods
539        */
[752]540        enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES};
541
[584]542        /** If view cells in this tree have compressed pvs.
543        */
[752]544        int ViewCellsStorage() const;
[584]545
[660]546        /** Returns active view cell that is in the path of this view cell.
547        */
[881]548        ViewCell *GetActiveViewCell(ViewCellLeaf *vc) const;
[660]549        /** Sets the leaves to be the currently active view cells.
550        */
551    void SetActiveSetToLeaves();
[651]552        /** Propagates pvs up the tree to the root and downwards the tree.
[610]553        */
[651]554        void PropagatePvs(ViewCell *vc);
[837]555        /** Exports view cells to file.
556        */
[1201]557        bool Export(OUT_STREAM &stream, const bool exportPvs = false);
[649]558        /** Export statistics of this view cell tree.
559        */
[2176]560        void ExportStats(const std::string &mergeStats);
[650]561        /** Sets root of hierarchy.
562        */
563        void SetRoot(ViewCell *root);
[651]564        /** Assignes unique ids to view cells.
565        */
566        void CreateUniqueViewCellsIds();
[660]567        /** Resets pvs of whole tree.
568        */
569        void ResetPvs();
[1121]570        /** Counts pvs of the view cell taking the kd cells into account.
571        */
572        int CountKdPvs(const ViewCellLeaf *vc) const;
[1551]573        /** Sets pointer to view cells manager.
574        */
575        void SetViewCellsManager(ViewCellsManager *vcm);
[1264]576
[2539]577        ViewCellInterior *ImportBinInterior(IN_STREAM  &stream, ViewCellInterior *parent);
[1586]578
[2539]579        ViewCellLeaf *ImportBinLeaf(IN_STREAM &stream,
580                                        ViewCellInterior *parent,
581                                                                const ObjectContainer &pvsObjects);
582
583        void ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior);
584
585        void ExportBinLeaf(OUT_STREAM &stream, ViewCell *leaf);
586
587        bool ExportBinary(OUT_STREAM &stream);
588       
589        bool ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects);
590
591        ViewCell *ImportNextNode(IN_STREAM &stream,
592                                                         ViewCellInterior *parent,
593                                                         const ObjectContainer &objects);
594
[580]595protected:
596
[1586]597        /** Reads the environment and sets member variables.
598        */
[1264]599        void ReadEnvironment();
[580]600
601
[1999]602        //////////////////////////////////////////////////////////////
603        //                    merge related stuff                   //
604        //////////////////////////////////////////////////////////////
605
606
[729]607        /** Computes render cost of the merged pvs.
608        */
609        float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const;
[580]610        /** Returns cost of this leaf according to current heuristics.
611        */
612        float GetCostHeuristics(ViewCell *vc) const;
613        /** Returns cost of leaf.
614        */
615        float GetRenderCost(ViewCell *vc) const;
616        /** Evaluates the merge cost of this merge candidate pair.
617        */
618        void EvalMergeCost(MergeCandidate &mc) const;
619        /** Variance of leaf.
620        */
621        float GetVariance(ViewCell *vc) const;
622        /** Standard deviation of leaf.
623        */
624        float GetDeviation(ViewCell *vc) const;
[582]625        /** Tries to set this merge candidate to valid.
626                @returns false if both view cells are the same
[580]627        */
[582]628        bool ValidateMergeCandidate(MergeCandidate &mc) const;
[580]629        /** Merge view cells of leaves l1 and l2.
630                @returns difference in pvs size
631        */
[1999]632        ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff);
[580]633        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it
634                to view cell 2.
635        */
[586]636        void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const;   
[580]637        /** Shuffles the leaves, i.e., tests if exchanging
638                the leaves helps in improving the view cells.
639        */
[586]640        bool ShuffleLeaves(MergeCandidate &mc) const;
[580]641        /** Calculates cost for merge of view cell 1 and 2.
642        */
[586]643        float EvalShuffleCost(ViewCell *leaf,
644                                                  ViewCellInterior *vc1,
645                                                  ViewCellInterior *vc2) const;
[580]646        /** Exports a snapshot of the merged view cells to disc.
647        */
648        void ExportMergedViewCells(ViewCellContainer &viewCells,
649                                                           const ObjectContainer &objects,
650                                                           const int numNewViewCells);
[997]651        /** Merge queue must be reset after some time because expected value
[580]652                may not be valid.
653        */
654        void ResetMergeQueue();
[1551]655        /** Updates the current cut of view cells.
[582]656                @returns number of newly merged view cells
[580]657        */
[582]658        int UpdateActiveViewCells(ViewCellContainer &viewCells);
[997]659        /** Helper function pullling pvs as high up in the tree as possible.
660        */
[610]661        void PullUpVisibility(ViewCellInterior *interior);
[997]662        /** Compress pvs of view cell and children.
663        */
[584]664        void CompressViewCellsPvs(ViewCell *root);
[582]665        /** Returns memory usage of view cells.
666        */
667        float GetMemUsage() const;
[837]668        /**     Exports single view cell.
[610]669                NOTE: should be in exporter!!
670        */
[1201]671        void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs);     
[837]672        /** Exports pvs of a view cell.
673        */
[1201]674        void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream);
[1586]675        /** Counts the logical number of entries in the pvs this view cell.
676                The pvs is assumed to be stored using lossless compression.
677        */
[1166]678        int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const;
[1586]679        /** Computes pvs size of this view cell.
680                The pvs is assumed to be stored using lossless compression.
681        */
[1709]682        float GetPvsCostForCompressedStorage(ViewCell *vc) const;
[1586]683        /** Computes pvs size of this view cell.
684                The pvs is assumed to be stored in the leaves.
685        */
[1709]686        float GetPvsCostForLeafStorage(ViewCell *vc) const;
[1586]687        /** Counts the logical number of entries in the pvs this view cell.
688                The pvs is assumed to be stored using the leaves.
689        */
[1166]690        int GetEntriesInPvsForLeafStorage(ViewCell *vc) const;
[1586]691        /** Update stats for the log.
692        */
[2176]693        void UpdateStats(std::ofstream &stats,
[1709]694                                         const ViewCellsTreeStats &vcStats);
[1842]695       
[1586]696
697        //////////////////////////////////////
698
[584]699        /// if the view cell tree hold compressed pvs
[752]700        int mViewCellsStorage;
[1551]701        /// pointer to the view cells manager
[580]702        ViewCellsManager *mViewCellsManager;
[1551]703        /// the root of the view cells hierarchy
[580]704        ViewCell *mRoot;
705
706        /// if merge visualization should be shown
707        bool mExportMergedViewCells;
[837]708        /// intermediate container of merged view cells.
[582]709        ViewCellContainer mMergedViewCells;
[837]710        /// if merged view cells are refined.
[586]711        bool mRefineViewCells;
[1842]712        /// weights between variance and render cost increase in the range [0 .. 1].
[580]713        float mRenderCostWeight;
714
715        /// overall cost used to normalize cost ratio
716        float mOverallCost;
717        float mExpectedCost;
718    float mDeviation;
719        float mAvgRenderCost;
[1551]720       
[837]721        /// the area is used for pvs heuristics
[580]722        int mUseAreaForPvs;
[1551]723        /// number of currently active view cells (=current cut)
[582]724        int mNumActiveViewCells;
[580]725        /// minimal number of view cells
726        int mMergeMinViewCells;
727        /// maximal cost ratio for the merge
728        float mMergeMaxCostRatio;
729
[2176]730        typedef std::priority_queue<MergeCandidate> MergeQueue;
[580]731
732        MergeQueue mMergeQueue;
733
[582]734        float mMaxMemory;
[580]735
[938]736        int mMaxMergesPerPass;
737        float mAvgCostMaxDeviation;
[580]738};
739
740
741/**
742        Candidate for leaf merging based on priority.
743*/
744class MergeCandidate
745
746        friend class ViewCellsTree;
747
748public:
749
750        MergeCandidate(ViewCell *l, ViewCell *r);
751
752        /** If this merge pair is still valid.
753        */
754        bool IsValid() const;
755
756       
757        friend bool operator<(const MergeCandidate &leafa, const MergeCandidate &leafb)
758        {
759                return leafb.GetMergeCost() < leafa.GetMergeCost();
760        }
761
762        void SetLeftViewCell(ViewCell *l);
763        void SetRightViewCell(ViewCell *l);
764
765        ViewCell *GetLeftViewCell() const;
766        ViewCell *GetRightViewCell() const;
767
[703]768        /** Returns leaf view cell initially associated with this merge candidate.
769        */
[580]770        ViewCell *GetInitialLeftViewCell() const;
[1133]771        /** Returns leaf view cell initially associated with this merge candidate.
772        */
[580]773        ViewCell *GetInitialRightViewCell() const;
774
775        /** Returns the increase of the standard deviation of this merge candidate.
776        */
777        float GetDeviationIncr() const;
778
779        /** Merge cost of this candidate pair.
780        */
781        float GetMergeCost() const;
782
783        /** Render cost of this candidate.
784        */
785        float GetRenderCost() const;
786       
787        static float sRenderCostWeight;
788
789protected:
790
791        /// render cost increase by this merge
792        float mRenderCost;
793        /// increase / decrease of standard deviation
794        float mDeviationIncr;
795
796        ViewCell *mLeftViewCell;
797        ViewCell *mRightViewCell;
798
799        ViewCell *mInitialLeftViewCell;
800        ViewCell *mInitialRightViewCell;
801};
802
803
804class MergeStatistics: public StatisticsBase
805{
806public:
807       
808        int merged;
809        int siblings;
810        int candidates;
811        int nodes;
812
813        int accTreeDist;
814        int maxTreeDist;
815       
816        Real collectTime;
817        Real mergeTime;
818
819        Real overallCost;
820
821        Real expectedRenderCost;
822        Real deviation;
823        Real heuristics;
824
825        // Constructor
826        MergeStatistics()
827        {
828                Reset();
829        }
830       
831        double AvgTreeDist() const {return (double)accTreeDist / (double)merged;};
832
833        void Reset()
834        {
835                nodes = 0;
836                merged = 0;
837                siblings = 0;
838                candidates = 0;
839       
840                accTreeDist = 0;
841                maxTreeDist = 0;
842
843                collectTime = 0;
844                mergeTime = 0;
845                overallCost = 0;
846
847                expectedRenderCost = 0;
848                deviation = 0;
849                heuristics = 0;
850
851        }
852
[2176]853        void Print(std::ostream &app) const;
[580]854
[2176]855        friend std::ostream &operator<<(std::ostream &s, const MergeStatistics &stat)
[580]856        {
857                stat.Print(s);
858                return s;
859        }
860};
861
[860]862}
863
[372]864#endif
Note: See TracBrowser for help on using the repository browser.