2003-10-28 00:07:21 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This application is open source and may be redistributed and / or modified
* freely and without restriction , both in commericial and non commericial applications ,
* as long as this copyright notice is maintained .
*
* This application is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
*/
# include <osg/Texture2D>
# include <osg/Geometry>
# include <osg/State>
# include <osg/ShapeDrawable>
# include <osgDB/ReadFile>
# include <osgDB/WriteFile>
# include <osgDB/ImageOptions>
# include <osgDB/FileNameUtils>
# include <osgUtil/Optimizer>
# include <osgUtil/TriStripVisitor>
# include <osgUtil/SmoothingVisitor>
# include <osgUtil/TangentSpaceGenerator>
# include <osgFX/BumpMapping>
# include <osgProducer/Viewer>
2004-01-29 23:47:06 +08:00
# include <osg/Switch>
2003-10-28 00:07:21 +08:00
2004-03-12 00:14:25 +08:00
# include <osgTerrain/DataSet>
2003-10-28 00:07:21 +08:00
2004-01-29 23:47:06 +08:00
# include <ogr_spatialref.h>
2004-03-12 00:14:25 +08:00
char * SanitizeSRS ( const char * pszUserInput )
{
OGRSpatialReferenceH hSRS ;
char * pszResult = NULL ;
CPLErrorReset ( ) ;
hSRS = OSRNewSpatialReference ( NULL ) ;
if ( OSRSetFromUserInput ( hSRS , pszUserInput ) = = OGRERR_NONE )
OSRExportToWkt ( hSRS , & pszResult ) ;
else
{
CPLError ( CE_Failure , CPLE_AppDefined ,
" Translating source or target SRS failed: \n %s " ,
pszUserInput ) ;
exit ( 1 ) ;
}
OSRDestroySpatialReference ( hSRS ) ;
return pszResult ;
}
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
int main ( int argc , char * * argv )
2003-10-28 00:07:21 +08:00
{
2003-11-25 19:40:10 +08:00
// use an ArgumentParser object to manage the program arguments.
osg : : ArgumentParser arguments ( & argc , argv ) ;
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
// set up the usage document, in case we need to print out how to use this program.
arguments . getApplicationUsage ( ) - > setApplicationName ( arguments . getApplicationName ( ) ) ;
arguments . getApplicationUsage ( ) - > setDescription ( arguments . getApplicationName ( ) + " is the standard OpenSceneGraph example which loads and visualises 3d models. " ) ;
arguments . getApplicationUsage ( ) - > setCommandLineUsage ( arguments . getApplicationName ( ) + " [options] filename ... " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -d <filename> " , " Specify the digital elevation map input file to process " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -t <filename> " , " Specify the texture map input file to process " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -m <filename> " , " Specify the 3D database model input file to process " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -o <outputfile> " , " Specify the output master file to generate " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -l <numOfLevels> " , " Specify the number of PagedLOD levels to generate " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -e <x> <y> <w> <h> " , " Extents of the model to generate " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -h or --help " , " Display this information " ) ;
2004-03-12 06:04:41 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --o_cs <coordinates system string> " , " Set the output coordinates system. The string may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPS " ) ;
2003-11-25 19:40:10 +08:00
if ( arguments . argc ( ) < = 1 )
2003-10-28 00:07:21 +08:00
{
2003-11-25 19:40:10 +08:00
arguments . getApplicationUsage ( ) - > write ( std : : cout , osg : : ApplicationUsage : : COMMAND_LINE_OPTION ) ;
return 1 ;
2003-10-28 00:07:21 +08:00
}
2003-11-25 19:40:10 +08:00
// create DataSet.
2004-03-12 00:14:25 +08:00
osg : : ref_ptr < osgTerrain : : DataSet > dataset = new osgTerrain : : DataSet ;
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
std : : string filename ;
while ( arguments . read ( " -d " , filename ) )
2003-10-28 00:07:21 +08:00
{
2004-03-12 00:14:25 +08:00
if ( ! filename . empty ( ) ) dataset - > addSource ( new osgTerrain : : DataSet : : Source ( osgTerrain : : DataSet : : Source : : HEIGHT_FIELD , filename ) ) ;
2003-10-28 00:07:21 +08:00
}
2003-11-25 19:40:10 +08:00
while ( arguments . read ( " -t " , filename ) )
2003-10-28 00:07:21 +08:00
{
2004-03-12 00:14:25 +08:00
if ( ! filename . empty ( ) ) dataset - > addSource ( new osgTerrain : : DataSet : : Source ( osgTerrain : : DataSet : : Source : : IMAGE , filename ) ) ;
2003-10-28 00:07:21 +08:00
}
2003-11-25 19:40:10 +08:00
while ( arguments . read ( " -m " , filename ) )
2003-10-28 00:07:21 +08:00
{
2004-03-12 00:14:25 +08:00
if ( ! filename . empty ( ) ) dataset - > addSource ( new osgTerrain : : DataSet : : Source ( osgTerrain : : DataSet : : Source : : MODEL , filename ) ) ;
2003-10-28 00:07:21 +08:00
}
2003-11-25 19:40:10 +08:00
float x , y , w , h ;
while ( arguments . read ( " -e " , x , y , w , h ) )
2003-10-28 00:07:21 +08:00
{
2003-11-25 19:40:10 +08:00
dataset - > setDestinationExtents ( osg : : BoundingBox ( x , y , 0.0f , x + w , y + h , 0.0f ) ) ;
2003-10-28 00:07:21 +08:00
}
2004-01-29 23:47:06 +08:00
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
dataset - > setDestinationTileBaseName ( " output " ) ;
dataset - > setDestinationTileExtension ( " .ive " ) ;
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
std : : string outputFileName ( " output.ive " ) ;
while ( arguments . read ( " -o " , outputFileName ) )
2003-10-28 00:07:21 +08:00
{
2003-11-25 19:40:10 +08:00
std : : string path = osgDB : : getFilePath ( outputFileName ) ;
std : : string base = path . empty ( ) ? osgDB : : getStrippedName ( outputFileName ) :
path + ' / ' + osgDB : : getStrippedName ( outputFileName ) ;
std : : string extension = ' . ' + osgDB : : getLowerCaseFileExtension ( outputFileName ) ;
2003-10-28 00:07:21 +08:00
2003-11-25 19:40:10 +08:00
dataset - > setDestinationTileBaseName ( base ) ;
dataset - > setDestinationTileExtension ( extension ) ;
2003-10-28 00:07:21 +08:00
}
2004-01-16 05:07:34 +08:00
float numLevels = 6.0f ;
2003-10-28 00:07:21 +08:00
while ( arguments . read ( " -l " , numLevels ) ) { }
2003-11-25 19:40:10 +08:00
float verticalScale ;
2004-03-12 00:14:25 +08:00
while ( arguments . read ( " -v " , verticalScale ) )
{
dataset - > setVerticalScale ( verticalScale ) ;
}
2003-10-28 00:07:21 +08:00
2003-10-29 19:11:17 +08:00
2003-10-28 00:07:21 +08:00
// if user request help write it out to cout.
if ( arguments . read ( " -h " ) | | arguments . read ( " --help " ) )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout ) ;
return 1 ;
}
2004-03-12 00:14:25 +08:00
std : : string def ;
2004-03-12 06:04:41 +08:00
while ( arguments . read ( " --o_cs " , def ) )
2004-03-12 00:14:25 +08:00
{
dataset - > setDestinationCoordinateSystem ( SanitizeSRS ( def . c_str ( ) ) ) ;
}
if ( false )
2004-01-29 23:47:06 +08:00
{
// set up the coordinate system
OGRSpatialReference oSRS ;
2004-02-01 18:27:19 +08:00
oSRS . SetProjCS ( " WGS 84 / UTM zone 47S " ) ;
2004-01-29 23:47:06 +08:00
oSRS . SetWellKnownGeogCS ( " WGS84 " ) ;
oSRS . SetUTM ( 47 , FALSE ) ;
// get the Well Known Text string
char * pszWKT = NULL ;
oSRS . exportToWkt ( & pszWKT ) ;
// set the destination coordinate system
dataset - > setDestinationCoordinateSystem ( pszWKT ) ;
}
2003-10-28 00:07:21 +08:00
// any option left unread are converted into errors to write out later.
arguments . reportRemainingOptionsAsUnrecognized ( ) ;
// report any errors if they have occured when parsing the program aguments.
if ( arguments . errors ( ) )
{
arguments . writeErrorMessages ( std : : cout ) ;
return 1 ;
}
2003-11-25 19:40:10 +08:00
dataset - > loadSources ( ) ;
2003-10-28 00:07:21 +08:00
2004-01-16 05:07:34 +08:00
dataset - > createDestination ( ( unsigned int ) numLevels ) ;
2003-11-25 19:40:10 +08:00
dataset - > writeDestination ( outputFileName ) ;
2003-10-28 00:07:21 +08:00
return 0 ;
}