osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/TerrainOptions.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #include <osgEarth/TerrainOptions>
00021 #include <osg/Notify>
00022 #include <OpenThreads/Thread>
00023 
00024 using namespace osgEarth;
00025 
00026 //------------------------------------------------------------------------
00027 
00028 LoadingPolicy::LoadingPolicy( const Config& conf ) :
00029 _mode( MODE_STANDARD ),
00030 _numLoadingThreads( 4 ),
00031 _numLoadingThreadsPerCore( 2 ),
00032 _numCompileThreads( 2 ),
00033 _numCompileThreadsPerCore( 0.5 )
00034 {
00035     fromConfig( conf );
00036 }
00037 
00038 void
00039 LoadingPolicy::fromConfig( const Config& conf )
00040 {
00041     conf.getIfSet( "mode", "standard", _mode, MODE_SERIAL );
00042     conf.getIfSet( "mode", "serial", _mode, MODE_SERIAL );
00043     conf.getIfSet( "mode", "parallel", _mode, MODE_PARALLEL );
00044     conf.getIfSet( "mode", "sequential", _mode, MODE_SEQUENTIAL );
00045     conf.getIfSet( "mode", "preemptive", _mode, MODE_PREEMPTIVE );
00046     conf.getIfSet( "loading_threads", _numLoadingThreads );
00047     conf.getIfSet( "loading_threads_per_logical_processor", _numLoadingThreadsPerCore );
00048     conf.getIfSet( "loading_threads_per_core", _numLoadingThreadsPerCore );
00049     conf.getIfSet( "compile_threads", _numCompileThreads );
00050     conf.getIfSet( "compile_threads_per_core", _numCompileThreadsPerCore );
00051 }
00052 
00053 Config
00054 LoadingPolicy::getConfig() const
00055 {
00056     Config conf( "loading_policy" );
00057     conf.addIfSet( "mode", "standard", _mode, MODE_STANDARD ); // aka MODE_SERIAL
00058     conf.addIfSet( "mode", "parallel", _mode, MODE_PARALLEL );
00059     conf.addIfSet( "mode", "sequential", _mode, MODE_SEQUENTIAL );
00060     conf.addIfSet( "mode", "preemptive", _mode, MODE_PREEMPTIVE );
00061     conf.addIfSet( "loading_threads", _numLoadingThreads );
00062     conf.addIfSet( "loading_threads_per_core", _numLoadingThreadsPerCore );
00063     conf.addIfSet( "compile_threads", _numCompileThreads );
00064     conf.addIfSet( "compile_threads_per_core", _numCompileThreadsPerCore );
00065     return conf;
00066 }
00067 
00068 int osgEarth::computeLoadingThreads(const LoadingPolicy& policy)
00069 {
00070     const char* env_numTaskServiceThreads = getenv("OSGEARTH_NUM_PREEMPTIVE_LOADING_THREADS");
00071     if ( env_numTaskServiceThreads )
00072     {
00073         return ::atoi( env_numTaskServiceThreads );
00074     }
00075     else if ( policy.numLoadingThreads().isSet() )
00076     {
00077         return osg::maximum( 1, policy.numLoadingThreads().get() );
00078     }
00079     else
00080     {
00081         return (int)osg::maximum( 1.0f, policy.numLoadingThreadsPerCore().get()
00082                                   * (float)OpenThreads::GetNumberOfProcessors() );
00083     }
00084 }
00085 
00086 //----------------------------------------------------------------------------
00087 
00088 TerrainOptions::TerrainOptions( const ConfigOptions& options ) :
00089 DriverConfigOptions( options ),
00090 _verticalScale( 1.0f ),
00091 _heightFieldSampleRatio( 1.0f ),
00092 _minTileRangeFactor( 6.0 ),
00093 _normalizeEdges( false ),
00094 _combineLayers( true ),
00095 _loadingPolicy( LoadingPolicy() ),
00096 _compositingTech( COMPOSITING_AUTO ),
00097 _maxLOD( 23 ),
00098 _enableLighting( false ),
00099 _attenuationDistance( 1000000 ),
00100 _lodBlending( false ),
00101 _lodTransitionTimeSeconds( 0.5f ),
00102 _elevationInterpolation( INTERP_BILINEAR ),
00103 _enableMipmapping( true )
00104 {
00105     fromConfig( _conf );
00106 }
00107 
00108 Config
00109 TerrainOptions::getConfig() const
00110 {
00111     Config conf = DriverConfigOptions::getConfig();
00112     conf.key() = "terrain";
00113 
00114     conf.updateObjIfSet( "loading_policy", _loadingPolicy );
00115     conf.updateIfSet( "vertical_scale", _verticalScale );
00116     conf.updateIfSet( "sample_ratio", _heightFieldSampleRatio );
00117     conf.updateIfSet( "min_tile_range_factor", _minTileRangeFactor );
00118     conf.updateIfSet( "normalize_edges", _normalizeEdges );
00119     conf.updateIfSet( "combine_layers", _combineLayers );
00120     conf.updateIfSet( "max_lod", _maxLOD );
00121     conf.updateIfSet( "lighting", _enableLighting );
00122     conf.updateIfSet( "attenuation_distance", _attenuationDistance );
00123     conf.updateIfSet( "lod_transition_time", _lodTransitionTimeSeconds );
00124     conf.updateIfSet( "mipmapping", _enableMipmapping );
00125 
00126     conf.updateIfSet( "compositor", "auto",             _compositingTech, COMPOSITING_AUTO );
00127     conf.updateIfSet( "compositor", "texture_array",    _compositingTech, COMPOSITING_TEXTURE_ARRAY );
00128     conf.updateIfSet( "compositor", "multitexture",     _compositingTech, COMPOSITING_MULTITEXTURE_GPU );
00129     conf.updateIfSet( "compositor", "multitexture_ffp", _compositingTech, COMPOSITING_MULTITEXTURE_FFP );
00130     conf.updateIfSet( "compositor", "multipass",        _compositingTech, COMPOSITING_MULTIPASS );
00131 
00132     conf.updateIfSet( "elevation_interpolation", "nearest",     _elevationInterpolation, INTERP_NEAREST);
00133     conf.updateIfSet( "elevation_interpolation", "average",     _elevationInterpolation, INTERP_AVERAGE);
00134     conf.updateIfSet( "elevation_interpolation", "bilinear",    _elevationInterpolation, INTERP_BILINEAR);
00135     conf.updateIfSet( "elevation_interpolation", "triangulate", _elevationInterpolation, INTERP_TRIANGULATE);
00136 
00137     return conf;
00138 }
00139 
00140 void
00141 TerrainOptions::fromConfig( const Config& conf )
00142 {
00143     conf.getObjIfSet( "loading_policy", _loadingPolicy );
00144     conf.getIfSet( "vertical_scale", _verticalScale );
00145     conf.getIfSet( "sample_ratio", _heightFieldSampleRatio );
00146     conf.getIfSet( "min_tile_range_factor", _minTileRangeFactor );
00147     conf.getIfSet( "normalize_edges", _normalizeEdges );
00148     conf.getIfSet( "combine_layers", _combineLayers );
00149     conf.getIfSet( "max_lod", _maxLOD );
00150     conf.getIfSet( "lighting", _enableLighting );
00151     conf.getIfSet( "attenuation_distance", _attenuationDistance );
00152     conf.getIfSet( "lod_transition_time", _lodTransitionTimeSeconds );
00153     conf.getIfSet( "mipmapping", _enableMipmapping );
00154 
00155     conf.getIfSet( "compositor", "auto",             _compositingTech, COMPOSITING_AUTO );
00156     conf.getIfSet( "compositor", "texture_array",    _compositingTech, COMPOSITING_TEXTURE_ARRAY );
00157     conf.getIfSet( "compositor", "multitexture",     _compositingTech, COMPOSITING_MULTITEXTURE_GPU );
00158     conf.getIfSet( "compositor", "multitexture_gpu", _compositingTech, COMPOSITING_MULTITEXTURE_GPU );
00159     conf.getIfSet( "compositor", "multitexture_ffp", _compositingTech, COMPOSITING_MULTITEXTURE_FFP );
00160     conf.getIfSet( "compositor", "multipass",        _compositingTech, COMPOSITING_MULTIPASS );
00161 
00162     conf.getIfSet( "elevation_interpolation", "nearest",     _elevationInterpolation, INTERP_NEAREST);
00163     conf.getIfSet( "elevation_interpolation", "average",     _elevationInterpolation, INTERP_AVERAGE);
00164     conf.getIfSet( "elevation_interpolation", "bilinear",    _elevationInterpolation, INTERP_BILINEAR);
00165     conf.getIfSet( "elevation_interpolation", "triangulate", _elevationInterpolation, INTERP_TRIANGULATE);
00166 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines