#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // construct the viewer. osgViewer::Viewer viewer; // set up the camera manipulators. { osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); std::string pathfile; char keyForAnimationPath = '5'; while (arguments.read("-p",pathfile)) { osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); if (apm || !apm->valid()) { unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); keyswitchManipulator->selectMatrixManipulator(num); ++keyForAnimationPath; } } viewer.setCameraManipulator( keyswitchManipulator.get() ); } // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); double x = 0.0; double y = 0.0; double w = 1.0; double h = 1.0; osg::ref_ptr terrain = new osgTerrain::TerrainNode; osg::ref_ptr locator = new osgTerrain::EllipsoidLocator(-osg::PI, -osg::PI*0.5, 2.0*osg::PI, osg::PI, 0.0); osg::ref_ptr validDataOperator = new osgTerrain::NoDataValue(0.0); unsigned int layerNum = 0; std::string filterName; bool readParameter = false; float minValue, maxValue; float scale = 1.0f; float offset = 0.0f; int pos = 1; while(pos hf = osgDB::readHeightFieldFile(filename); if (hf.valid()) { osg::ref_ptr hfl = new osgTerrain::HeightFieldLayer; hfl->setHeightField(hf.get()); hfl->setLocator(locator.get()); hfl->setValidDataOperator(validDataOperator.get()); if (offset!=0.0f || scale!=1.0f) { hfl->transform(offset,scale); } terrain->setElevationLayer(hfl.get()); osg::notify(osg::NOTICE)<<"created osgTerrain::HeightFieldLayer"< image = osgDB::readImageFile(filename); if (image.valid()) { osg::ref_ptr imageLayer = new osgTerrain::ImageLayer; imageLayer->setImage(image.get()); imageLayer->setLocator(locator.get()); imageLayer->setValidDataOperator(validDataOperator.get()); if (offset!=0.0f || scale!=1.0f) { imageLayer->transform(offset,scale); } terrain->setElevationLayer(imageLayer.get()); osg::notify(osg::NOTICE)<<"created Elevation osgTerrain::ImageLayer"<setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST); } else if (filterName=="LINEAER") { osg::notify(osg::NOTICE)<<"--filter "<setColorFilter(layerNum, osgTerrain::TerrainNode::LINEAR); } else { osg::notify(osg::NOTICE)<<"--filter "< tf = new osg::TransferFunction1D; tf->setInputRange(minValue, maxValue); tf->allocate(6); tf->setValue(0, osg::Vec4(1.0,1.0,1.0,1.0)); tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0)); tf->setValue(2, osg::Vec4(1.0,0.0,0.0,1.0)); tf->setValue(3, osg::Vec4(1.0,1.0,0.0,1.0)); tf->setValue(4, osg::Vec4(0.0,1.0,1.0,1.0)); tf->setValue(5, osg::Vec4(0.0,1.0,0.0,1.0)); osg::notify(osg::NOTICE)<<"--tf "<setColorTransferFunction(layerNum, tf.get()); } else { ++pos; } } osg::ref_ptr geometryTechnique = new osgTerrain::GeometryTechnique; terrain->setTerrainTechnique(geometryTechnique.get()); if (!terrain) return 0; // return 0; // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(terrain.get()); return viewer.run(); }