VR-Forces 4.0.4 Class Documentation
include/geometry/ssUniformAnalyzer.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2005 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: ssUniformAnalyzer.h,v $ $Revision: 1.7 $ $State: Exp $
00007 *******************************************************************************/
00008 #ifndef ssUniformAnalyzer_H_
00009 #define ssUniformAnalyzer_H_
00010 
00011 #include "geometry/spatialSubdivision.h"
00012 #include "geometry/simpleStats.h"
00013 #include <vlutil/vlConfig.h>
00014 #include <map>
00015 #include <vector>
00016 
00017 
00023 
00024 template<typename T>
00025 class DtSsUniformAnalyzer
00026 {
00027 public:
00028 
00029    typedef unsigned int DtNumElementsInCell;
00030    typedef unsigned int DtNumCells;
00031    typedef std::map<DtNumElementsInCell, DtNumCells> DtNumCellsWithNumElementsContainer;
00032 
00033    typedef unsigned int DtElementFillRate;
00034    typedef unsigned int DtNumElementsWithFillRate;
00035    typedef std::map<DtElementFillRate, DtNumElementsWithFillRate> DtElementFillRatesContainer;
00036 
00037    typedef std::vector<unsigned int> DtFillDistributionContainer;
00038 
00039    typedef std::list<unsigned int>   DtFillModeContainer;
00040    
00041 
00042    DtSsUniformAnalyzer(const DtSpatialSubdivision<T>& spatialSubdivision);
00043 
00044    // This object requires none of the big three to be defined.  It *is* copyable,
00045    // assignable, and destroyable. - The compiler will generate these.
00046 //   virtual ~DtSsUniformAnalyzer();
00047 //   DtSsUniformAnalyzer(const DtSsUniformAnalyzer& original);
00048 //   DtSsUniformAnalyzer& operator=(const DtSsUniformAnalyzer& original);
00049 
00050 public:
00051 
00052    // @returns The number of empty cells in the SS.
00053    unsigned int numEmptyCells() const;
00054 
00055    // @returns The number of non-empty cells in the SS.
00056    unsigned int numNonEmptyCells();
00057    
00058    // @returns The largest number of elements contained in a single SS cell.
00059    unsigned int maxFill() const;
00060 
00061    // @returns The smallest number of elements contained in a single SS cell.  
00062    // @note This is almost always zero, but for highly and/or evenly filled 
00063    // subdivisions, it may not be.
00064    unsigned int minFill() const;
00065    
00066    // @returns The median fill rate for the spatial subdivision.
00067    unsigned int medianFill() const;
00068 
00069    // @returns The average fill rate for the spatial subdivision.
00070    float averageFill() const;
00071 
00072    // Determines the fill rate mode for the spatial subdivision.
00073    // @returns A container of cell sizes that are most common.
00074    // For example, a spatial subdivision with 9 cells, with the fill values of:
00075    // 3, 6, 4, 2, 0, 2, 6, 0, 0
00076    // would have a single mode of 0.  If, instead the values were:
00077    // 6, 6, 4, 2, 0, 2, 6, 0, 0
00078    // the SS would have two modes, 0 and 6.
00079    // 
00080    DtFillModeContainer fillMode() const;
00081 
00082    // @returns The fill rate statistical range for the SS.
00083    unsigned int fillRange() const;
00084 
00085    // Determines the fill distribution for the spatial subdivision.  This can be 
00086    // used to get the relative efficiency of the spatial subdivision, as
00087    // it can point to areas of higher and lower utilization.
00088    //
00089    // @returns A container of the fill rates for each cell, where the index into the
00090    // returned container is the same as the associated cell in the spatial subdivision,
00091    // and the value is that cell's fill amount.
00092    // For example, if the spatial subdivision contained 1000 cells, then the 
00093    // returned container's 500th element would contain the 500th cell's fill amount.
00094    const DtFillDistributionContainer& fillDistribution() const;
00095 
00096    // Determines the number of cells with the same number of elements.  For example,
00097    // the first entry in the returned container may be 17, 12.  This would mean that
00098    // there are 12 cells in the SS that have 17 elements referenced in them.  
00099    //
00100    // @returns A container values, where the index into the container is the number 
00101    // of referenced elements, and the value at that index in the container is the number
00102    // of cells that reference <index> numbers of elements.  
00103    const DtNumCellsWithNumElementsContainer& numCellsWithNumElements() const;
00104 
00105    // Determines the number of cells that the elements are individually referenced in.
00106    // For example, in the returned container, the index is equal to the number of 
00107    // cells and the value at that index is the number of elements that are stored 
00108    // in that many cells.
00109    //
00110    // @returns A container of pairs of data:  the number of cells used to store 
00111    // the elements, and the number of elements stored individually in that many 
00112    // cells.
00113    //
00114    // For instance, if 100 items total are sorted spatially in the spatial 
00115    // subdivision, and 20 of those items happen to be referenced in 10 cells
00116    // each, then the container would contain an entry with key 10 and value 20.
00117    const DtElementFillRatesContainer& elementFillRates() const;
00118 
00119 
00120    // Notify the SS analyzer that its spatial subdivision has changed.
00121    void spatialSubdivisionChanged() const;
00122 
00123 protected:
00124 
00125    // @returns A boolean indicating whether or not the statistics need to be
00126    // generated or not.
00127    bool isStatsClean() const;
00128 
00129    // Sets the state of the statistics to be clean or unclean.  When unclean,
00130    // they need to be recalculated before they are valid.
00131    void setStatsClean(bool yesOrNo) const;
00132 
00133    // Analyzes the spatial subdivision, and calculates all statistics.
00134    // @note When this is finished, the statistics are considered clean.
00135    void analyzeSs() const;
00136 
00137 private:
00138 
00139    // The spatial subdivision to reference.
00140    const DtSpatialSubdivision<T>& mySpatialSubdivision;
00141 
00143    // Holds the min, max, sum, and average of all cell size counts
00145    mutable DtSimpleStats<unsigned int> mySimpleStats;
00146 
00147    // The number of empty cells in the spatial subdivision
00148    mutable unsigned int myNumEmptyCells;
00149    // The number of cells referencing at least one element.
00150    mutable unsigned int myNumNonEmptyCells;
00151 
00153    // Fill stats.
00154    // For these statistics, fill is defined as the number of elements in a 
00155    // spatial subdivision cell.
00157 
00158    // Essentially a container with numCells elements that contains the fill 
00159    // amount of each cell in the spatial subdivision.  
00160    // @note If this data was plotted, it might give an idea of the efficiency 
00161    // graphically.  (You could see areas of higher and lower cell fill rates.)
00162    mutable DtFillDistributionContainer myFillDistribution;
00163 
00164    // The median fill amount.  
00165    mutable unsigned int myFillMedian;
00166 
00167    // A container of the fill modes (most commonly occurring cell sizes).
00168    mutable DtFillModeContainer myFillMode;
00169 
00170    // A container that maps the number of cells referencing N elements to the 
00171    // number of elements.  For example, if 10 cells reference 5 elements, and 
00172    // 15 reference 1, and 20 reference 0, the this container would have 3 
00173    // entries, of those three pairs.
00174    mutable DtNumCellsWithNumElementsContainer myNumCellsWithNumElements;
00175 
00176    // This container maps between the number of elements referenced in N cells,
00177    // and the number of elements.  It's essentially the opposite of the previous
00178    // container, as it is concerned with how many elements are stored over 
00179    // how many cells.  The higher the number of elements that are stored in more
00180    // cells, the more likely that the subdivision is an overly high resolution.
00181    mutable DtElementFillRatesContainer myNumElementsReferencedInNumCells;    
00182 
00183    // This group of statistics is not trivial to calculate, especially for very 
00184    // large datasets.  As a result, don't calculate the values until requested,
00185    // and then not again until the spatial subdivision has changed.  
00186    mutable bool myStatsClean;
00187 };
00188 
00189 //------------------------------------------------------
00190 //  INLINE METHODS
00191 //------------------------------------------------------
00192 // include the inline code
00193 #define SSUNIFORMANALYZER_HEADER
00194 #include "geometry/ssUniformAnalyzer.inl"
00195 #undef  SSUNIFORMANALYZER_HEADER
00196 
00197 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)