00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <OSGConfig.h>
00040
00041
00042
00043 OSG_BEGIN_NAMESPACE inline void GraphicStatisticsForeground::processValue(Real32 &value,
00044 const UInt32 &elementID)
00045 {
00046 processOnlyValue(value, elementID);
00047 addValueToHistory(value, elementID);
00048 }
00049
00050
00051 inline void GraphicStatisticsForeground::processOnlyValue(Real32 &value,
00052 const UInt32 &elementID)
00053 {
00054 UInt32 flags = getFlags()[elementID];
00055 Real32 minV = getMinValue()[elementID];
00056 Real32 maxV = getMaxValue()[elementID];
00057
00058
00059 if(flags & OSG_RECIPROC)
00060 {
00061 value = 1.0f / value;
00062 }
00063
00064
00065 if(value > maxV)
00066 {
00067 if(flags & OSG_OVERFLOW_RESIZE)
00068 {
00069 getMaxValue()[elementID] = value;
00070 }
00071 else
00072 {
00073 value = maxV;
00074 }
00075 }
00076
00077
00078 if(value < minV)
00079 {
00080 if(flags & OSG_UNDERFLOW_RESIZE)
00081 {
00082 getMinValue()[elementID] = value;
00083 }
00084 else
00085 {
00086 value = minV;
00087 }
00088 }
00089
00090
00091 }
00092
00093
00094 inline void GraphicStatisticsForeground::addValueToHistory(Real32 &value,
00095 const UInt32 &elementID)
00096 {
00097 UInt32 flags = getFlags()[elementID];
00098
00099
00100 UInt32 hSize = _history.size();
00101 UInt32 size = (elementID < hSize) ? _history[elementID].size() : 0;
00102
00103 if(size > 0)
00104 {
00105 UInt32 queueEnd = _historyID[elementID];
00106 _history[elementID][queueEnd] = value;
00107
00108
00109 _historyID[elementID] = (_historyID[elementID] + 1) % size;
00110
00111
00112 if((flags & OSG_SMOOTH) ||
00113 (flags & OSG_OVERFLOW_RESIZE) ||
00114 (flags & OSG_UNDERFLOW_RESIZE))
00115 {
00116 Real32 v = 0.0, max = 0.0, min = 0.0, sum = 0.0;
00117
00118 for(UInt32 i = 0; i < size; i++)
00119 {
00120 v = _history[elementID][i];
00121
00122 if(i)
00123 {
00124 if(v > max)
00125 max = v;
00126 else if(v < min)
00127 min = v;
00128 }
00129 else
00130 min = max = v;
00131
00132 sum += v;
00133 }
00134
00135 if(flags & OSG_SMOOTH)
00136 {
00137 value = sum / size;
00138
00139
00140 }
00141
00142 if((flags & OSG_OVERFLOW_RESIZE) && (max < getMaxValue()[elementID]))
00143 {
00144 max += (getMaxValue()[elementID] - max) / 2.0f;
00145 getMaxValue()[elementID] = osgMax(v, max);
00146 }
00147
00148 if((flags & OSG_UNDERFLOW_RESIZE) && (min > getMinValue()[elementID]))
00149 {
00150 min -= (min - getMinValue()[elementID]) / 2.0f;
00151 getMinValue()[elementID] = osgMin(v, min);
00152 }
00153 }
00154 }
00155 }
00156
00157 OSG_END_NAMESPACE
00158 #define OSGGRAPHICSTATISTICSFOREGROUND_INLINE_CVSID \
00159 "@(#)$Id: OSGGraphicStatisticsForeground.inl,v 1.2 2002/07/30 16:30:32 jbehr Exp $"