VR-Forces 4.0.4 Class Documentation
include/vrvOsg/DtOsgCullVisitorParameters.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (c) 2011 MAK Technologies, Inc.
00003  * All rights reserved.
00004  *****************************************************************************/
00005 /*****************************************************************************
00006  * $RCSfile: DtOsgCullVisitorParameters.h,v $ $Revision: 1.51 $ $State: Exp $
00007  *****************************************************************************/
00008  
00014  
00015 #pragma once
00016  
00017 #include <vrvOsg/vrvOsg.h> 
00018 #include <osg/Referenced>
00019 #include <osg/BoundingBox>
00020 #include <osg/BoundingSphere>
00021 #include <osg/Vec2>
00022 #include <osgUtil/CullVisitor>
00023 
00024 #include <vrvCore/DtObserverObject.h>
00025 
00026 #include <algorithm>
00027 #include <math.h>
00028 
00029 #ifdef min
00030 #undef min
00031 #endif
00032 
00033 namespace makVrv 
00034 { 
00038    class DT_DLL_VRVOSG DtOsgCullVisitorParameters : public osg::Referenced
00039    {
00040    public:
00041 
00043       DtOsgCullVisitorParameters()
00044          : osg::Referenced()
00045          , mySkyFlag(true)
00046          , myOrthoFlag(false)
00047          , myCameraResolution( 1.0 )
00048          , myTerrainRadius( 1.0 )
00049          , myScalingFlag( true )
00050          , myScaleFactor( 1.0 )
00051          , myClampedPixelSize( 1.0 )
00052          , myCameraMagnification( 1.0 )
00053          , myScaleType( DtObserverObject::XRScale )
00054          , myCoordinateSystemChanged( false )
00055          , myAltitude2D( 0. )
00056       {
00057       }
00058 
00060       void setCameraMagnification( double mag )
00061       {
00062          myCameraMagnification = mag;
00063       }
00064 
00065       inline double cameraMagnification() const
00066       {
00067          return myCameraMagnification;
00068       }
00069 
00071       void setCameraResolution(double factor)
00072       {
00073          myCameraResolution = factor;
00074       }
00075 
00077       inline double cameraResolution() const
00078       {
00079          return myCameraResolution;
00080       }
00081 
00083       void setTerrainRadius(double rad)
00084       {
00085          myTerrainRadius = rad;
00086       }
00087 
00089       void setAltitude2D( double altitude )
00090       {
00091          myAltitude2D = altitude;
00092       }
00093 
00094       double altitude2D() const
00095       {
00096          return myAltitude2D;
00097       }
00098 
00100       inline double terrainRadius() const
00101       {
00102          return myTerrainRadius;
00103       }
00104 
00106       void setOrthoCulling(bool ortho)
00107       {
00108          myOrthoFlag = ortho;
00109       }
00110 
00112       inline bool orthoCulling() const
00113       {
00114          return myOrthoFlag;
00115       }
00116 
00117       inline void setSkyRendering(bool renderSky)
00118       {
00119          mySkyFlag = renderSky;
00120 
00121       }
00122 
00123       inline bool skyRendering() const
00124       {
00125          return mySkyFlag;
00126       }
00127 
00129       void setScaling( bool scaling )
00130       {
00131          myScalingFlag = scaling;
00132       }
00133 
00135       inline bool scaling() const
00136       {
00137          return myScalingFlag;
00138       }
00139       
00141       void setScaleFactor( double scaleFactor )
00142       {
00143          myScaleFactor = scaleFactor;
00144       }
00145 
00147       inline double scaleFactor() const
00148       {  
00149          return myScaleFactor;
00150       }
00151       
00153       void setCoordinateSystemChanged( bool changed )
00154       {
00155          myCoordinateSystemChanged = changed;
00156       }
00157 
00159       inline bool coordinateSystemChanged() const
00160       {
00161          return myCoordinateSystemChanged;
00162       }
00163 
00165       void setScaleType( DtObserverObject::ScaleType scaleType )
00166       {
00167          myScaleType = scaleType;
00168       }
00169 
00171       inline DtObserverObject::ScaleType scaleType() const
00172       {  
00173          return myScaleType;
00174       }
00175 
00176       inline double calculateFixedScale(double basempp, double mpp )
00177       {
00178          return mpp / basempp;
00179       }
00180 
00181       inline double calculateScaleFromDistance(double distance, double r )
00182       {
00183          double distsqr = distance * distance;
00184          double scaleDistRatio = 250 - 2.0 * myScaleFactor;
00185          double scaleBasedOnDistance = sqrt(distsqr)/scaleDistRatio;
00186          
00187          // Calculate a scale for the entity based on its size.
00188          // Scale the scale so that big entities are scaled less and 
00189          // small entities are scaled more.  For example, a lifeform model
00190          // should be only slightly smaller than a helicopter and a large
00191          // submarine should only be a few times bigger than a helicopter
00192          if ( r > 0.0 )
00193          {
00194             //double scaleScale = 3.0 / sqrt(r);   
00195             double scaleScale = 6.0 / r;   
00196             scaleBasedOnDistance *= scaleScale;
00197          }
00198             
00199          if (scaleBasedOnDistance < 1.0) 
00200          {
00201             scaleBasedOnDistance = 1.0;
00202          }   
00203 
00204          return scaleBasedOnDistance;
00205       }
00206 
00207       void setClampedPixelSize(double d)
00208       {
00209          myClampedPixelSize = d;
00210       }
00211 
00212       double clampedPixelSize() const
00213       {
00214          return myClampedPixelSize;
00215       }
00216 
00217    protected:
00218 
00219       double myCameraMagnification;
00220       double myCameraResolution;
00221       double myTerrainRadius;
00222       double myAltitude2D;
00223       bool mySkyFlag;
00224       bool myOrthoFlag;
00225       bool myScalingFlag;
00226       double myScaleFactor;
00227       double myClampedPixelSize;
00228       DtObserverObject::ScaleType myScaleType;
00229       bool myCoordinateSystemChanged;
00230    };
00231 
00234    class DT_DLL_VRVOSG DtOsgFixedScaleParameters : public osg::Referenced
00235    {
00236    public:
00237       DtOsgFixedScaleParameters()
00238          : myFixedPixelSize( 1.0 )
00239          , myLength( 0.0 )
00240          , myWidth( 0.0 )
00241          , myHeight( 0.0 )
00242          , myScaleX(true)
00243          , myScaleY(true)
00244          , myScaleZ(true)
00245       {
00246 } 
00247 
00248       virtual ~DtOsgFixedScaleParameters()
00249       {
00250       }
00251  
00252       void setFixedPixelSize(double d)
00253       {
00254          myFixedPixelSize = d;
00255       }
00256 
00257       double fixedPixelSize() const
00258       {
00259          return myFixedPixelSize;
00260       }
00261 
00262       void setDimensions(double length, double width, double height)
00263       {
00264          myLength = length; myWidth = width; myHeight = height;
00265       }
00266 
00267       inline double length() const
00268       {
00269          return myLength;
00270       }
00271 
00272       inline double width() const
00273       {
00274          return myWidth;
00275       }
00276 
00277       inline double height() const
00278       {
00279          return myHeight;
00280       }
00281 
00282       inline void calculateScaleFactors(const osgUtil::CullVisitor& visitor,
00283          const osg::BoundingSphere& sphere, DtOsgCullVisitorParameters* info,
00284          double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
00285       {
00286          double clampedSize =
00287             visitor.clampedPixelSize( sphere.center(), info->terrainRadius() );
00288          info->setClampedPixelSize(clampedSize);
00289 
00290          calculateScaleFactors( sphere, *info, scaleFactorX,
00291             scaleFactorY, scaleFactorZ );
00292       }
00293 
00294       inline void calculateScaleFactors(const osg::BoundingSphere& sphere, const DtOsgCullVisitorParameters& info,
00295          double& scaleFactorX, double& scaleFactorY, double& scaleFactorZ) const
00296       {
00297          scaleFactorX = scaleFactorY = scaleFactorZ = 1.0;
00298 
00299          double metersPerPixel = info.terrainRadius() / info.clampedPixelSize();  // Meters per pixel
00300          double curPixels = myWidth / metersPerPixel;  // Pixels needed to draw
00301 
00302          if (myScaleX)
00303          {
00304             scaleFactorX = myFixedPixelSize / curPixels;
00305          }
00306 
00307          if (myScaleY)
00308          {
00309             scaleFactorY = scaleFactorX;
00310          }
00311 
00312          if (myScaleX)
00313          {
00314             scaleFactorZ = 1.0;
00315          }
00316       }
00317 
00318       void setScaleX(bool b)
00319       {
00320          myScaleX = b;
00321       }
00322 
00323       inline bool scaleX() const
00324       {
00325          return myScaleX;
00326       }
00327 
00328       void setScaleXY(bool b)
00329       {
00330          myScaleY = b;
00331       }
00332 
00333       inline bool scaleY() const
00334       {
00335          return myScaleY;
00336       }
00337 
00338       void setScaleZ(bool b)
00339       {
00340          myScaleZ = b;
00341       }
00342 
00343       inline bool scaleZ() const
00344       {
00345          return myScaleZ;
00346       }
00347 
00348    protected:
00349       double myFixedPixelSize;
00350       double myLength, myWidth, myHeight;
00351       bool myScaleX, myScaleY, myScaleZ;
00352    };
00353 
00354 } 
00355 
00356  

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)