Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGGraphicStatisticsForeground.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *                     Copyright 2000-2002 by OpenSG Forum                   *
00006  *                                                                           *
00007  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00008  *                                                                           *
00009 \*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*\
00011  *                                License                                    *
00012  *                                                                           *
00013  * This library is free software; you can redistribute it and/or modify it   *
00014  * under the terms of the GNU Library General Public License as published    *
00015  * by the Free Software Foundation, version 2.                               *
00016  *                                                                           *
00017  * This library is distributed in the hope that it will be useful, but       *
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00020  * Library General Public License for more details.                          *
00021  *                                                                           *
00022  * You should have received a copy of the GNU Library General Public         *
00023  * License along with this library; if not, write to the Free Software       *
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00025  *                                                                           *
00026 \*---------------------------------------------------------------------------*/
00027 /*---------------------------------------------------------------------------*\
00028  *                                Changes                                    *
00029  *                                                                           *
00030  *                                                                           *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035 \*---------------------------------------------------------------------------*/
00036 //---------------------------------------------------------------------------
00037 //  Includes
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     /* check for invert */
00059     if(flags & OSG_RECIPROC)
00060     {
00061         value = 1.0f / value;
00062     }
00063 
00064     /* check for a to big Value */
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     /* check for to small values */
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     /* end of these checks */
00091 }
00092 
00093 /* */
00094 inline void GraphicStatisticsForeground::addValueToHistory(Real32 &value,
00095                                                            const UInt32 &elementID)
00096 {
00097     UInt32  flags = getFlags()[elementID];
00098 
00099     /* Smooth the value, if asked for */
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         /* increment the queue end */
00109         _historyID[elementID] = (_historyID[elementID] + 1) % size;
00110 
00111         /* check whether the value should be smoothed */
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                 //_history[ID][queueEnd] = value;
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 $"

Generated on Thu Aug 25 04:05:45 2005 for OpenSG by  doxygen 1.4.3