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

Revision 1999, 20.2 KB checked in by mattausch, 17 years ago (diff)
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"
[469]10
[1010]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
[1264]27
[479]28/** Statistics for a view cell partition.
29*/
30
31class ViewCellsStatistics: public StatisticsBase
32{
33public:
34
35        /// number of view cells
36        int viewCells;
[1709]37        /// cost of the PVS
38        float pvsCost;
[479]39        /// largest PVS of all view cells
[1709]40        float maxPvs;
[479]41        /// smallest PVS of all view cells
[1709]42        float minPvs;
[479]43        /// view cells with empty PVS
44        int emptyPvs;
45        /// number of leaves covering the view space
46        int leaves;
47        /// largest number of leaves covered by one view cell
48        int maxLeaves;
[1667]49        /// number of invalid view cells
[564]50        int invalid;
51
[479]52    // Constructor
53        ViewCellsStatistics()
54        {
55                Reset();
56        }
57
58        double AvgLeaves() const {return (double)leaves / (double)viewCells;};
[1709]59        double AvgPvs() const {return (double)pvsCost / (double)viewCells;};
[479]60
61        void Reset()
62        {
63                viewCells = 0;
[1709]64                pvsCost = 0;
[479]65                maxPvs = 0;
66
67                minPvs = 999999;
68                emptyPvs = 0;
69                leaves = 0;
70                maxLeaves = 0;
[564]71                invalid = 0;
[479]72        }
73
74        void Print(ostream &app) const;
75
76        friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
77        {
78                stat.Print(s);
79                return s;
80        }
81};
82
[580]83
[1709]84class ViewCellsTreeStats
85{
86public:
87        int mPass;
88   
89        int mNumViewCells;
90               
91        float mRenderCostDecrease;
92
93    float mTotalRenderCost;
94   
95        float mCurrentPvsCost;
96                                                       
97        float mExpectedCost;
98   
99        float mAvgRenderCost;
100       
101        float mDeviation;
102                       
103        float mTotalPvsCost;
104       
105        int mEntriesInPvs;
106   
107        float mMemoryCost;
108       
109        int mPvsSizeDecr;
[1771]110 
[1709]111        float mVolume;
112
113
114        void Reset()
115        {
116                mPass = 0;
117                mNumViewCells = 0;
118                mRenderCostDecrease = 0;
119                mTotalRenderCost = 0;
120                mCurrentPvsCost = 0;
121                mExpectedCost = 0;
122                mAvgRenderCost = 0;
123                mDeviation = 0;
124                mTotalPvsCost = 0;
125                mEntriesInPvs = 0;
126                mMemoryCost = 0;
127                mPvsSizeDecr = 0;
128                mVolume = 0;
129        }
130
131
132        void Print(ostream &app) const;
133
134        friend ostream &operator<<(ostream &s, const ViewCellsTreeStats &stat)
135        {
136                stat.Print(s);
137                return s;
138        }
139};
140
141
[372]142/**
[1667]143        A view cell. View cells are regions in space. The visibility informations,
144        i.e., the primitives seen by the view cell are stored in a PVs.
145        A view cell can be represented in many different ways, e.g.,
146        a mesh representation.
[372]147*/
148class ViewCell: public MeshInstance
149{
[752]150        friend class ViewCellsTree;
151        friend class ViewCellsManager;
152
[372]153public:
[1999]154
[372]155        ViewCell();
[471]156
[372]157        /** Constructor taking a mesh representing the shape of the viewcell.
158        */
159        ViewCell(Mesh *mesh);
[462]160
[469]161        /** Default destructor.
162        */
[1551]163        virtual ~ViewCell();
[471]164        /** Returns Pvs.
[372]165        */
[469]166        const ObjectPvs &GetPvs() const;
[1002]167        /** Returns pvs.
168        */
[469]169        ObjectPvs &GetPvs();
[1002]170        /** Completely substitutes the pvs.
171        */
[880]172        void SetPvs(const ObjectPvs &pvs);
[752]173        /** Type of view cells.
174        */
[372]175        int Type() const;
176        /** Adds a passing ray to the passing ray container.
177        */
[471]178        void AddPassingRay(const Ray &ray, const int contributions);
[469]179        /** Returns volume of the view cell.
180        */
[478]181        float GetVolume() const;
182        /** Returns area of the view cell.
[469]183        */
[478]184        float GetArea() const;
185        /** Sets the volume of the view cell.
186        */
187        void SetVolume(float volume);
188        /** Sets the area of the view cell.
189        */
190        void SetArea(float area);
[580]191        /** if this view cell is the root of a view cell hierarchy
192        */
193        bool IsRoot() const;
194        /** Returns parent view cell.
195        */
196        ViewCellInterior *GetParent() const;
[1002]197        /** Sets parent of this view cell.
198        */
199        void SetParent(ViewCellInterior *parent);
[503]200        /** Sets the mesh for this view cell.
201        */
202        void SetMesh(Mesh *mesh);
203
[1002]204        /** Sets this view cell to be a valid view cell according to some criteria.
205        */
[547]206        void SetValid(const bool valid);
[1002]207        /** Returns true if this view cell is considered to be valid according to
208                some criteria.
209        */
[547]210        bool GetValid() const;
211
[728]212        /** Returns estimated render cost of this view cell.
213        */
214        float GetRenderCost() const;
[580]215
[752]216        /** set color for visiualizations.
217        */
218        void SetColor(const RgbColor &color);
[580]219
[752]220        /** get color for visualuzations.
221        */
222    RgbColor GetColor() const;
[580]223
[1002]224        /** Adds a sample to the pvs.
225                @param sample the sample to be added
226                @param pdf a continuos measure of visibility
227                @param contribution returns the contribution of this sample to the pvs
228        */
229        bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution);
[580]230
231        /** if this is a view cell correspending to a leaf in a hierarchy.
232        */
233        virtual bool IsLeaf() const = 0;
234
[752]235        static bool SmallerPvs(const ViewCell *a, const ViewCell *b)
236        {
[997]237                // HACK: take scalar value because pvs may not have been stored properly
238#if 1
[1709]239                return a->mPvsCost < b->mPvsCost;
[997]240#else
[1707]241                return a->GetPvs().EvalPvsCost() < b->GetPvs().EvalPvsCost();
[997]242#endif
243        }
[569]244
[1999]245        static bool GreaterOrEqualPvs(const ViewCell *a, const ViewCell *b)
246        {
247                return !SmallerPvs(a, b);
248        }
[1761]249
[997]250        static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b)
251        {
252                return a->GetRenderCost() < b->GetRenderCost();
253        }
[580]254
[997]255        static bool LargerRenderCost(const ViewCell *a, const ViewCell *b)
256        {
257                return a->GetRenderCost() > b->GetRenderCost();
258        }
[801]259
[1002]260        /** Sets merge cost used for merging this view cell 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.
[1999]263        */
[600]264        void SetMergeCost(const float mergeCost);
[997]265
[1002]266        /** Returns merge cost needed to merge this leaf from other cells.
267                @hack The function is available for leaves also to have a common interface,
268                but it should be less than zero for leaves.
269        */
[600]270        float GetMergeCost() const;
[997]271
[1999]272        void UpdatePvsCost() {
273                mPvsCost = GetPvs().EvalPvsCost();
274        }
[1002]275
[1999]276        void SetPvsCost(const float c) {
277                mPvsCost = c;
278        }
[1771]279
[1999]280        float GetPvsCost() const {
281                return mPvsCost;
282        }
[1761]283
[1551]284        //////////
[1297]285        //-- mailing stuff
[1002]286
[1999]287        //      static void NewMail(const int reserve = 1)
288        //      {
289        //              sMailId += sReservedMailboxes;
290        //              sReservedMailboxes = reserve;
291        //      }
[997]292
[1999]293        //      void Mail() { mMailbox = sMailId; }
294        //      bool Mailed() const { return mMailbox == sMailId; }
[580]295
[1999]296        //      void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
297        //      bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
[580]298
[1999]299        //      int IncMail() { return ++ mMailbox - sMailId; }
[580]300
301
302        // last mail id -> warning not thread safe!
303        // both mailId and mailbox should be unique for each thread!!!
[1867]304
[1999]305        //static int sMailId;
306        //static int sReservedMailboxes;
[1545]307
[1999]308        int GetFilteredPvsSize() const
309        {
310                return mFilteredPvsSize;
311        }
312
313        void SetFilteredPvsSize(const int s) {
314                mFilteredPvsSize = s;
[1771]315  }
316
[372]317protected:
318
[1002]319        /// parent view cell in the view cell hierarchy
320        ViewCellInterior *mParent;
[372]321        /// the potentially visible objects
[469]322        ObjectPvs mPvs;
[1160]323        /// the volume of this view cell
[469]324        float mVolume;
[1545]325        /// the area of this view cell
[478]326        float mArea;
[1160]327        /// the cost that were paid for merging this view cells from two others.
[600]328        float mMergeCost;
[1160]329        /// if the view cell is valid view space
[547]330        bool mValid;
[881]331        /// color used for consistent visualization
[660]332        RgbColor mColor;
[1002]333        /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves
[1709]334        float mPvsCost;
[1161]335        /** stores number of entries in pvs
336            this variable has the same value as mPvsSize for object pvs,
337                but usually not for kd cell based pvs
338        */
[1160]339        int mEntriesInPvs;
[1297]340        /** if the pvs size scalar (+ entries into pvs)
341                is up to date and corresponding to the real pvs size
342        */
[752]343        bool mPvsSizeValid;
[1771]344
345
[1999]346        /// Filter cost of the pvs
347        int mFilteredPvsSize;
348
[372]349};
350
[580]351
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        */
[1709]515        float GetPvsCost(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;
[590]549
[660]550        /** Sets the leaves to be the currently active view cells.
551        */
552    void SetActiveSetToLeaves();
553
[651]554        /** Propagates pvs up the tree to the root and downwards the tree.
[610]555        */
[651]556        void PropagatePvs(ViewCell *vc);
[610]557
[837]558        /** Exports view cells to file.
559        */
[1201]560        bool Export(OUT_STREAM &stream, const bool exportPvs = false);
[610]561
[649]562        /** Export statistics of this view cell tree.
563        */
[660]564        void ExportStats(const string &mergeStats);
[610]565
[650]566        /** Sets root of hierarchy.
567        */
568        void SetRoot(ViewCell *root);
569
[651]570        /** Assignes unique ids to view cells.
571        */
572        void CreateUniqueViewCellsIds();
573
[660]574        /** Resets pvs of whole tree.
575        */
576        void ResetPvs();
[651]577
[1121]578        /** Counts pvs of the view cell taking the kd cells into account.
579        */
580        int CountKdPvs(const ViewCellLeaf *vc) const;
581
[1551]582        /** Sets pointer to view cells manager.
583        */
584        void SetViewCellsManager(ViewCellsManager *vcm);
[1264]585
[1603]586        void Update();
[1586]587
[580]588protected:
589
[1586]590        /** Reads the environment and sets member variables.
591        */
[1264]592        void ReadEnvironment();
[580]593
594
[1999]595        //////////////////////////////////////////////////////////////
596        //                    merge related stuff                   //
597        //////////////////////////////////////////////////////////////
598
599
[729]600        /** Computes render cost of the merged pvs.
601        */
602        float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const;
603
[580]604        /** Returns cost of this leaf according to current heuristics.
605        */
606        float GetCostHeuristics(ViewCell *vc) const;
607
608        /** Returns cost of leaf.
609        */
610        float GetRenderCost(ViewCell *vc) const;
611
612        /** Evaluates the merge cost of this merge candidate pair.
613        */
614        void EvalMergeCost(MergeCandidate &mc) const;
615
616        /** Variance of leaf.
617        */
618        float GetVariance(ViewCell *vc) const;
619
620        /** Standard deviation of leaf.
621        */
622        float GetDeviation(ViewCell *vc) const;
623
[582]624        /** Tries to set this merge candidate to valid.
625                @returns false if both view cells are the same
[580]626        */
[582]627        bool ValidateMergeCandidate(MergeCandidate &mc) const;
[580]628
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
634        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it
635                to view cell 2.
636        */
[586]637        void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const;   
[580]638               
639        /** Shuffles the leaves, i.e., tests if exchanging
640                the leaves helps in improving the view cells.
641        */
[586]642        bool ShuffleLeaves(MergeCandidate &mc) const;
[580]643
644        /** Calculates cost for merge of view cell 1 and 2.
645        */
[586]646        float EvalShuffleCost(ViewCell *leaf,
647                                                  ViewCellInterior *vc1,
648                                                  ViewCellInterior *vc2) const;
[580]649
650        /** Exports a snapshot of the merged view cells to disc.
651        */
652        void ExportMergedViewCells(ViewCellContainer &viewCells,
653                                                           const ObjectContainer &objects,
654                                                           const int numNewViewCells);
655
[997]656        /** Merge queue must be reset after some time because expected value
[580]657                may not be valid.
658        */
659        void ResetMergeQueue();
660
[1551]661        /** Updates the current cut of view cells.
[582]662                @returns number of newly merged view cells
[580]663        */
[582]664        int UpdateActiveViewCells(ViewCellContainer &viewCells);
[580]665
[997]666        /** Helper function pullling pvs as high up in the tree as possible.
667        */
[610]668        void PullUpVisibility(ViewCellInterior *interior);
[580]669
[997]670        /** Compress pvs of view cell and children.
671        */
[584]672        void CompressViewCellsPvs(ViewCell *root);
[580]673
[582]674        /** Returns memory usage of view cells.
675        */
676        float GetMemUsage() const;
[837]677
678        /**     Exports single view cell.
[610]679                NOTE: should be in exporter!!
680        */
[1201]681        void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs);     
[581]682
[837]683        /** Exports pvs of a view cell.
684        */
[1201]685        void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream);
[582]686
[1586]687        /** Counts the logical number of entries in the pvs this view cell.
688                The pvs is assumed to be stored using lossless compression.
689        */
[1166]690        int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const;
[1586]691
692        /** Computes pvs size of this view cell.
693                The pvs is assumed to be stored using lossless compression.
694        */
[1709]695        float GetPvsCostForCompressedStorage(ViewCell *vc) const;
[1586]696       
697        /** Computes pvs size of this view cell.
698                The pvs is assumed to be stored in the leaves.
699        */
[1709]700        float GetPvsCostForLeafStorage(ViewCell *vc) const;
[1586]701
702        /** Counts the logical number of entries in the pvs this view cell.
703                The pvs is assumed to be stored using the leaves.
704        */
[1166]705        int GetEntriesInPvsForLeafStorage(ViewCell *vc) const;
[610]706
[1586]707        /** Update stats for the log.
708        */
[1653]709        void UpdateStats(ofstream &stats,
[1709]710                                         const ViewCellsTreeStats &vcStats);
[1166]711
[1842]712       
[1586]713
714        //////////////////////////////////////
715
[584]716        /// if the view cell tree hold compressed pvs
[752]717        int mViewCellsStorage;
[1551]718        /// pointer to the view cells manager
[580]719        ViewCellsManager *mViewCellsManager;
[1551]720        /// the root of the view cells hierarchy
[580]721        ViewCell *mRoot;
722
723        /// if merge visualization should be shown
724        bool mExportMergedViewCells;
[837]725        /// intermediate container of merged view cells.
[582]726        ViewCellContainer mMergedViewCells;
[837]727        /// if merged view cells are refined.
[586]728        bool mRefineViewCells;
[1842]729        /// weights between variance and render cost increase in the range [0 .. 1].
[580]730        float mRenderCostWeight;
731
732        /// overall cost used to normalize cost ratio
733        float mOverallCost;
734        float mExpectedCost;
735    float mDeviation;
736        float mAvgRenderCost;
[1551]737       
[837]738        /// the area is used for pvs heuristics
[580]739        int mUseAreaForPvs;
[1551]740        /// number of currently active view cells (=current cut)
[582]741        int mNumActiveViewCells;
[580]742        /// minimal number of view cells
743        int mMergeMinViewCells;
744        /// maximal cost ratio for the merge
745        float mMergeMaxCostRatio;
746
747        typedef priority_queue<MergeCandidate> MergeQueue;
748
749        MergeQueue mMergeQueue;
750
[582]751        float mMaxMemory;
[580]752
[938]753        int mMaxMergesPerPass;
754        float mAvgCostMaxDeviation;
[580]755};
756
757
758/**
759        Candidate for leaf merging based on priority.
760*/
761class MergeCandidate
762
763        friend class ViewCellsTree;
764
765public:
766
767        MergeCandidate(ViewCell *l, ViewCell *r);
768
769        /** If this merge pair is still valid.
770        */
771        bool IsValid() const;
772
773       
774        friend bool operator<(const MergeCandidate &leafa, const MergeCandidate &leafb)
775        {
776                return leafb.GetMergeCost() < leafa.GetMergeCost();
777        }
778
779        void SetLeftViewCell(ViewCell *l);
780        void SetRightViewCell(ViewCell *l);
781
782        ViewCell *GetLeftViewCell() const;
783        ViewCell *GetRightViewCell() const;
784
[703]785        /** Returns leaf view cell initially associated with this merge candidate.
786        */
[580]787        ViewCell *GetInitialLeftViewCell() const;
[1133]788        /** Returns leaf view cell initially associated with this merge candidate.
789        */
[580]790        ViewCell *GetInitialRightViewCell() const;
791
792        /** Returns the increase of the standard deviation of this merge candidate.
793        */
794        float GetDeviationIncr() const;
795
796        /** Merge cost of this candidate pair.
797        */
798        float GetMergeCost() const;
799
800        /** Render cost of this candidate.
801        */
802        float GetRenderCost() const;
803       
804        static float sRenderCostWeight;
805
806protected:
807
808        /// render cost increase by this merge
809        float mRenderCost;
810        /// increase / decrease of standard deviation
811        float mDeviationIncr;
812
813        ViewCell *mLeftViewCell;
814        ViewCell *mRightViewCell;
815
816        ViewCell *mInitialLeftViewCell;
817        ViewCell *mInitialRightViewCell;
818};
819
820
821class MergeStatistics: public StatisticsBase
822{
823public:
824       
825        int merged;
826        int siblings;
827        int candidates;
828        int nodes;
829
830        int accTreeDist;
831        int maxTreeDist;
832       
833        Real collectTime;
834        Real mergeTime;
835
836        Real overallCost;
837
838        Real expectedRenderCost;
839        Real deviation;
840        Real heuristics;
841
842        // Constructor
843        MergeStatistics()
844        {
845                Reset();
846        }
847       
848        double AvgTreeDist() const {return (double)accTreeDist / (double)merged;};
849
850        void Reset()
851        {
852                nodes = 0;
853                merged = 0;
854                siblings = 0;
855                candidates = 0;
856       
857                accTreeDist = 0;
858                maxTreeDist = 0;
859
860                collectTime = 0;
861                mergeTime = 0;
862                overallCost = 0;
863
864                expectedRenderCost = 0;
865                deviation = 0;
866                heuristics = 0;
867
868        }
869
870        void Print(ostream &app) const;
871
872        friend ostream &operator<<(ostream &s, const MergeStatistics &stat)
873        {
874                stat.Print(s);
875                return s;
876        }
877};
878
[860]879}
880
[372]881#endif
Note: See TracBrowser for help on using the repository browser.