root/OpenSceneGraph/trunk/examples/osgthreadedterrain/osgthreadedterrain.cpp @ 13276

Revision 12597, 31.0 kB (checked in by robert, 3 years ago)

Resolved warnings reported by g++ 4.6's -Wunused-but-set-variable.

Warnings were:

/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp: In member function ‘void PrimitiveShapeVisitor::createHalfSphere(unsigned int, unsigned int, float, int, float, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1409:11: warning: variable ‘nzBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1410:11: warning: variable ‘nRatioBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In function ‘osgUtil::Triangle_list osgUtil::fillHole(osg::Vec3Array*, std::vector<unsigned int, std::allocator<unsigned int> >)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:569:27: warning: variable ‘ptest’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In member function ‘bool osgUtil::DelaunayTriangulator::triangulate()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:979:45: warning: variable ‘curp’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp: In member function ‘void osgUtil::RenderStage::runCameraSetUp(osg::RenderInfo?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp:631:18: warning: variable ‘stencilAttached’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp: In member function ‘void FadeTextPolytopeData::buildPolytope()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:74:20: warning: variable ‘edge23’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:75:20: warning: variable ‘edge30’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp: In member function ‘void osgText::Text::computeBackdropPositions(unsigned int) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp:747:10: warning: variable ‘is_valid_size’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp: In member function ‘virtual bool osgGA::NodeTrackerManipulator::performMovementLeftMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:257:21: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:259:21: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp: In member function ‘virtual bool osgGA::TerrainManipulator::performMovementMiddleMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:217:11: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:219:11: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp: In member function ‘virtual void osgVolume::FixedFunctionTechnique::init()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp:124:30: warning: variable ‘tf’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp: In member function ‘virtual void osgParticle::FluidProgram::execute(double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp:38:23: warning: variable ‘velBefore’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp: In member function ‘virtual void osgShadow::ParallelSplitShadowMap::cull(osgUtil::CullVisitor?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp:593:22: warning: variable ‘bb’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp: In member function ‘virtual void osgTerrain::GeometryTechnique::generateGeometry(osgTerrain::GeometryTechnique::BufferData?&, osgTerrain::Locator*, const osg::Vec3d&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:777:12: warning: variable ‘i_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:778:12: warning: variable ‘j_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘osg::Image* ReadDDSFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:314:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘bool WriteDDSFile(const osg::Image*, std::ostream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:721:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp: In static member function ‘static bool HDRLoader::load(const char*, bool, HDRLoaderResult&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp:101:10: warning: variable ‘cmd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp: In function ‘osg::Image* ReadVTFFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp:360:23: warning: variable ‘base’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp: In function ‘int putdata(jas_stream_t*, jas_image_t*, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp:41:13: warning: variable ‘linelen’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp: In member function ‘void ConvertToInventor::processGeometry(const osg::Geometry*, ConvertToInventor::InventorState?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp:1639:10: warning: variable ‘ok’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp: In member function ‘virtual SbBool? SoVRMLImageTextureOsg::readInstance(SoInput?*, short unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp:1264:16: warning: variable ‘retval’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Face::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:369:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Mesh::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:942:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp: In member function ‘virtual osgDB::ReaderWriter::ReadResult? FLTReaderWriter::readNode(std::istream&, const Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:427:40: warning: variable ‘pos’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp: In member function ‘void ive::ShapeAttributeList::write(ive::DataOutputStream?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp:31:48: warning: variable ‘it’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp: In member function ‘void ac3d::Geode::ProcessGeometry?(std::ostream&, unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:35: warning: variable ‘fRep_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:43: warning: variable ‘fRep_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:35: warning: variable ‘fOffset_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:46: warning: variable ‘fOffset_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:932:38: warning: variable ‘primLength’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp: In member function ‘virtual bool trpgGeometry::Write(trpgWriteBuffer&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp:615:19: warning: variable ‘u’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp: In member function ‘int trpgMatTable::AddMaterial?(const trpgMaterial&, bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp:103:10: warning: variable ‘spaceInTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp: In member function ‘virtual bool trpgr_Archive::ReadHeader?(bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp:261:14: warning: variable ‘headerHasTexTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp: In member function ‘ZRESULT TUnzip::Get(int, ZIPENTRY*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:8: warning: variable ‘hidden’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:22: warning: variable ‘system’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:36: warning: variable ‘archive’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp: In member function ‘virtual bool ZipArchive::getFileNames(osgDB::Archive::FileNameList?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp:91:37: warning: variable ‘iterEnd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp: In member function ‘osgDB::ReaderWriter::ReadResult? ReaderWriterPVR::readPVRStream(std::istream&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp:155:14: warning: variable ‘hasAlpha’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* create3DSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:737:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1130:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1118:15: warning: variable ‘dx’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp: In member function ‘virtual void osgViewer::GraphicsWindowX11::checkEvents()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp:1181:10: warning: variable ‘destroyWindowRequested’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp: In member function ‘bool osgProducer::CameraConfig::parseFile(const string&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp:2247:13: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp: In member function ‘bool osgQt::QGraphicsViewAdapter::handlePointerEvent(int, int, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp:344:17: warning: variable ‘viewportGeometry’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Node* createDistortionSubgraph(osg::Node*, const Vec4&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:125:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:126:19: warning: variable ‘texcoord’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Geometry* createDomeDistortionMesh(const Vec3&, const Vec3&, const Vec3&, osg::ArgumentParser?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:358:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp:253:31: warning: variable ‘outputTiles’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp:669:10: warning: variable ‘readParameter’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp: In member function ‘virtual void osgText::Layout::layout(osgText::TextNode?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp:80:11: warning: variable ‘characterHeightScale’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp:678:38: warning: variable ‘internalFormatMode’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool windowMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:27:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool widgetMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:35:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp: In member function ‘osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode?*, bool, osgDB::Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp:2121:10: warning: variable ‘readSlide’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp:639:10: warning: variable ‘sizesSpecified’ set but not used [-Wunused-but-set-variable]

  • Property svn:eol-style set to native
Line 
1/* OpenSceneGraph example, osgterrain.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#include <OpenThreads/Block>
20
21#include <osg/Group>
22#include <osg/Geode>
23#include <osg/ShapeDrawable>
24#include <osg/Texture2D>
25#include <osg/PositionAttitudeTransform>
26#include <osg/MatrixTransform>
27#include <osg/CoordinateSystemNode>
28#include <osg/ClusterCullingCallback>
29#include <osg/ArgumentParser>
30
31
32#include <osgDB/FileUtils>
33#include <osgDB/fstream>
34#include <osgDB/ReadFile>
35
36#include <osgUtil/IncrementalCompileOperation>
37
38#include <osgText/FadeText>
39
40#include <osgViewer/Viewer>
41#include <osgViewer/ViewerEventHandlers>
42
43#include <osgGA/TrackballManipulator>
44#include <osgGA/FlightManipulator>
45#include <osgGA/DriveManipulator>
46#include <osgGA/KeySwitchMatrixManipulator>
47#include <osgGA/StateSetManipulator>
48#include <osgGA/AnimationPathManipulator>
49#include <osgGA/TerrainManipulator>
50
51#include <osgTerrain/TerrainTile>
52#include <osgTerrain/GeometryTechnique>
53#include <osgTerrain/Layer>
54
55#include <iostream>
56
57
58typedef std::vector< osg::ref_ptr<osg::GraphicsThread> > GraphicsThreads;
59
60struct ReleaseBlockOnCompileCompleted : public osgUtil::IncrementalCompileOperation::CompileCompletedCallback
61{
62
63    ReleaseBlockOnCompileCompleted(osg::RefBlockCount* block):
64        _block(block) {}
65
66    virtual bool compileCompleted(osgUtil::IncrementalCompileOperation::CompileSet* compileSet)
67    {
68        if (_block.valid()) _block->completed();
69       
70        // tell IncrementalCompileOperation that it's now safe to remove the compileSet
71       
72        osg::notify(osg::NOTICE)<<"compileCompleted("<<compileSet<<")"<<std::endl;
73       
74        return true;
75    }
76
77    osg::ref_ptr<osg::RefBlockCount> _block;
78};
79
80
81class LoadAndCompileOperation : public osg::Operation
82{
83public:
84
85    LoadAndCompileOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico , osg::RefBlockCount* block):
86        Operation("Load and compile Operation", false),
87        _filename(filename),
88        _incrementalCompileOperation(ico),
89        _block(block) {}
90
91    virtual void operator () (osg::Object* object)
92    {
93        // osg::notify(osg::NOTICE)<<"LoadAndCompileOperation "<<_filename<<std::endl;
94
95        _loadedModel = osgDB::readNodeFile(_filename);
96
97        if (_loadedModel.valid() && _incrementalCompileOperation.valid())
98        {
99            osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet =
100                new osgUtil::IncrementalCompileOperation::CompileSet(_loadedModel.get());
101
102            compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_block.get());
103
104            _incrementalCompileOperation->add(compileSet.get());
105        }
106        else 
107        {
108            if (_block.valid()) _block->completed();
109        }
110
111        // osg::notify(osg::NOTICE)<<"done LoadAndCompileOperation "<<_filename<<std::endl;
112    }
113   
114    std::string                                         _filename;
115    osg::ref_ptr<osg::Node>                             _loadedModel;
116    osg::ref_ptr<osgUtil::IncrementalCompileOperation>  _incrementalCompileOperation;
117    osg::ref_ptr<osg::RefBlockCount>                    _block;
118
119};
120
121class MasterOperation : public osg::Operation
122{
123public:
124
125    typedef std::set<std::string> Files;
126    typedef std::map<std::string, osg::ref_ptr<osg::Node> >  FilenameNodeMap;
127    typedef std::vector< osg::ref_ptr<osg::Node> >  Nodes;
128
129
130    MasterOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico):
131        Operation("Master reading operation",true),
132        _filename(filename),
133        _incrementalCompileOperation(ico)
134    {
135    }
136   
137    /** Set the OperationQueue that the MasterOperation can use to place tasks like file loading on for other processes to handle.*/ 
138    void setOperationQueue(osg::OperationQueue* oq) { _operationQueue = oq; }
139   
140    osg::OperationQueue* getOperationQueue() { return _operationQueue.get(); }
141   
142    bool readMasterFile(Files& files) const
143    {
144        osgDB::ifstream fin(_filename.c_str());
145        if (fin)
146        {
147            osgDB::Input fr;
148            fr.attach(&fin);
149
150            bool readFilename = false;
151
152            while(!fr.eof())
153            {
154                bool itrAdvanced = false;
155                if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
156                {
157                    files.insert(fr[1].getStr());
158                    fr += 2;
159                    itrAdvanced = true;
160                    readFilename = true;
161                }
162
163                if (!itrAdvanced)
164                {
165                    ++fr;
166                }
167            }
168           
169            return readFilename;
170        }
171        return false;
172    }
173   
174    bool open(osg::Group* group)
175    {
176        Files files;
177        readMasterFile(files);
178        for(Files::iterator itr = files.begin();
179            itr != files.end();
180            ++itr)
181        {
182            osg::Node* model = osgDB::readNodeFile(*itr);
183            if (model)
184            {
185                osg::notify(osg::NOTICE)<<"open: Loaded file "<<*itr<<std::endl;
186                group->addChild(model);
187                _existingFilenameNodeMap[*itr] = model;
188            }
189        }
190       
191        return true;
192    }
193   
194
195    virtual void operator () (osg::Object* callingObject)
196    {
197        // decided which method to call according to whole has called me.
198        osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(callingObject);
199
200        if (viewer) update(viewer->getSceneData());
201        else load();
202    }
203
204    void load()
205    {
206        //osg::notify(osg::NOTICE)<<"void load(Object)"<<std::endl;
207        Files filesA;
208        Files filesB;
209       
210        readMasterFile(filesB);
211        // osg::notify(osg::NOTICE)<<"First read "<<filesA.size()<<std::endl;
212
213        // itererate until the master file is stable
214        do
215        {
216            OpenThreads::Thread::microSleep(100000);
217
218            filesB.swap(filesA);
219            filesB.clear();
220            readMasterFile(filesB);
221
222            // osg::notify(osg::NOTICE)<<"second read "<<filesB.size()<<std::endl;
223           
224        } while (filesA!=filesB);
225
226        Files files;
227        files.swap(filesB);
228
229        // osg::notify(osg::NOTICE)<<"Now equal "<<files.size()<<std::endl;
230
231
232        Files newFiles;
233        Files removedFiles;
234
235        // find out which files are new, and which ones have been removed.
236        {           
237            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
238
239            for(Files::iterator fitr = files.begin();
240                fitr != files.end();
241                ++fitr)
242            {
243                if (_existingFilenameNodeMap.count(*fitr)==0) newFiles.insert(*fitr);
244            }
245
246            for(FilenameNodeMap::iterator litr = _existingFilenameNodeMap.begin();
247                litr != _existingFilenameNodeMap.end();
248                ++litr)
249            {
250                if (files.count(litr->first)==0)
251                {
252                    removedFiles.insert(litr->first);
253                }
254            }
255        }
256       
257#if 0
258        if (!newFiles.empty() || !removedFiles.empty())
259        {
260            osg::notify(osg::NOTICE)<<std::endl<<std::endl<<"void operator () files.size()="<<files.size()<<std::endl;
261        }
262#endif
263
264        // first load the new files.
265        FilenameNodeMap nodesToAdd;
266        if (!newFiles.empty())
267        {
268
269            typedef std::vector< osg::ref_ptr<osg::GraphicsThread> > GraphicsThreads;
270            GraphicsThreads threads;
271       
272            for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
273            {
274                osg::GraphicsContext* gc = osg::GraphicsContext::getCompileContext(i);
275                osg::GraphicsThread* gt = gc ? gc->getGraphicsThread() : 0;
276                if (gt) threads.push_back(gt);
277            }
278
279            if (_operationQueue.valid())
280            {
281                // osg::notify(osg::NOTICE)<<"Using OperationQueue"<<std::endl;
282
283                _endOfLoadBlock = new osg::RefBlockCount(newFiles.size());
284               
285                _endOfLoadBlock->reset();
286     
287                typedef std::list< osg::ref_ptr<LoadAndCompileOperation> > LoadAndCompileList;
288                LoadAndCompileList loadAndCompileList;
289     
290                for(Files::iterator nitr = newFiles.begin();
291                    nitr != newFiles.end();
292                    ++nitr)
293                {
294                    // osg::notify(osg::NOTICE)<<"Adding LoadAndCompileOperation "<<*nitr<<std::endl;
295
296                    osg::ref_ptr<LoadAndCompileOperation> loadAndCompile = new LoadAndCompileOperation( *nitr, _incrementalCompileOperation.get(), _endOfLoadBlock.get() );
297                    loadAndCompileList.push_back(loadAndCompile);
298                    _operationQueue->add( loadAndCompile.get() );
299                }
300
301#if 1
302                osg::ref_ptr<osg::Operation> operation;
303                while ((operation=_operationQueue->getNextOperation()).valid())
304                {
305                    // osg::notify(osg::NOTICE)<<"Local running of operation"<<std::endl;
306                    (*operation)(0);
307                }
308#endif                               
309                // osg::notify(osg::NOTICE)<<"Waiting for completion of LoadAndCompile operations"<<std::endl;
310                _endOfLoadBlock->block();
311                // osg::notify(osg::NOTICE)<<"done ... Waiting for completion of LoadAndCompile operations"<<std::endl;
312               
313                for(LoadAndCompileList::iterator litr = loadAndCompileList.begin();
314                    litr != loadAndCompileList.end();
315                    ++litr)
316                {
317                    if ((*litr)->_loadedModel.valid())
318                    {
319                        nodesToAdd[(*litr)->_filename] = (*litr)->_loadedModel;
320                    }
321                }
322
323            }
324           
325            else
326            {
327
328                _endOfLoadBlock = new osg::RefBlockCount(newFiles.size());
329               
330                _endOfLoadBlock->reset();
331
332                for(Files::iterator nitr = newFiles.begin();
333                    nitr != newFiles.end();
334                    ++nitr)
335                {
336                    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(*nitr);
337
338                    if (loadedModel.get())
339                    {
340                        nodesToAdd[*nitr] = loadedModel;
341
342                        if (_incrementalCompileOperation.valid())
343                        {
344                            osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet =
345                                new osgUtil::IncrementalCompileOperation::CompileSet(loadedModel.get());
346
347                            compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_endOfLoadBlock.get());
348
349                            _incrementalCompileOperation->add(compileSet.get());
350                        }
351                        else
352                        {
353                            _endOfLoadBlock->completed();
354                        }
355                    }
356                    else
357                    {
358                        _endOfLoadBlock->completed();
359                    }
360                }
361
362                _endOfLoadBlock->block();
363
364            }
365                       
366        }
367       
368        bool requiresBlock = false;
369       
370        // pass the locally peppared data to MasterOperations shared data
371        // so that updated thread can merge these changes with the main scene
372        // graph.  This merge is carried out via the update(..) method.
373        if (!removedFiles.empty() || !nodesToAdd.empty())       
374        {
375            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
376            _nodesToRemove.swap(removedFiles);
377            _nodesToAdd.swap(nodesToAdd);
378            requiresBlock = true;
379        }
380
381        // now block so we don't try to load anything till the new data has been merged
382        // otherwise _existingFilenameNodeMap will get out of sync.
383        if (requiresBlock)
384        {
385            _updatesMergedBlock.block();
386        }
387        else
388        {
389            OpenThreads::Thread::YieldCurrentThread();
390        }
391
392    }
393   
394    // merge the changes with the main scene graph.
395    void update(osg::Node* scene)
396    {
397        // osg::notify(osg::NOTICE)<<"void update(Node*)"<<std::endl;
398
399        osg::Group* group = dynamic_cast<osg::Group*>(scene);
400        if (!group)
401        {
402            osg::notify(osg::NOTICE)<<"Error, MasterOperation::update(Node*) can only work with a Group as Viewer::getSceneData()."<<std::endl;
403            return;
404        }
405   
406        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
407       
408        if (!_nodesToRemove.empty() || !_nodesToAdd.empty())
409        {
410            osg::notify(osg::NOTICE)<<"update().................. "<<std::endl;
411        }
412
413        if (!_nodesToRemove.empty())
414        {
415            for(Files::iterator itr = _nodesToRemove.begin();
416                itr != _nodesToRemove.end();
417                ++itr)
418            {
419                FilenameNodeMap::iterator fnmItr = _existingFilenameNodeMap.find(*itr);
420                if (fnmItr != _existingFilenameNodeMap.end())
421                {
422                    osg::notify(osg::NOTICE)<<"  update():removing "<<*itr<<std::endl;
423               
424                    group->removeChild(fnmItr->second.get());
425                    _existingFilenameNodeMap.erase(fnmItr);
426                }
427            }
428
429            _nodesToRemove.clear();
430        }
431       
432        if (!_nodesToAdd.empty())
433        {
434            for(FilenameNodeMap::iterator itr = _nodesToAdd.begin();
435                itr != _nodesToAdd.end();
436                ++itr)
437            {
438                osg::notify(osg::NOTICE)<<"  update():inserting "<<itr->first<<std::endl;
439                group->addChild(itr->second.get());
440                _existingFilenameNodeMap[itr->first] = itr->second;
441            }
442           
443            _nodesToAdd.clear();
444        }
445
446        _updatesMergedBlock.release();
447
448    }
449   
450    // add release implementation so that any thread cancellation can
451    // work even when blocks and barriers are used.
452    virtual void release()
453    {
454        if (_operationQueue.valid()) _operationQueue->removeAllOperations();
455
456        _updatesMergedBlock.release();
457        if (_endOfCompilebarrier.valid()) _endOfCompilebarrier.release();
458        if (_endOfLoadBlock.valid()) _endOfLoadBlock.release();
459    }
460
461   
462    std::string                         _filename;
463   
464    OpenThreads::Mutex                  _mutex;
465    FilenameNodeMap                     _existingFilenameNodeMap;
466    Files                               _nodesToRemove;
467    FilenameNodeMap                     _nodesToAdd;
468    OpenThreads::Block                  _updatesMergedBlock;
469
470    osg::ref_ptr<osgUtil::IncrementalCompileOperation>  _incrementalCompileOperation;
471    osg::ref_ptr<osg::BarrierOperation> _endOfCompilebarrier;
472    osg::ref_ptr<osg::RefBlockCount>    _endOfLoadBlock;
473   
474    osg::ref_ptr<osg::OperationQueue>   _operationQueue;
475};
476
477class FilterHandler : public osgGA::GUIEventHandler
478{
479public:
480
481    FilterHandler(osgTerrain::GeometryTechnique* gt):
482        _gt(gt) {}
483
484    bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
485    {
486        if (!_gt) return false;
487
488        switch(ea.getEventType())
489        {
490        case(osgGA::GUIEventAdapter::KEYDOWN):
491            {
492                if (ea.getKey() == 'g')
493                {
494                    osg::notify(osg::NOTICE)<<"Gaussian"<<std::endl;
495                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::GAUSSIAN);
496                    return true;
497                }
498                else if (ea.getKey() == 's')
499                {
500                    osg::notify(osg::NOTICE)<<"Smooth"<<std::endl;
501                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SMOOTH);
502                    return true;
503                }
504                else if (ea.getKey() == 'S')
505                {
506                    osg::notify(osg::NOTICE)<<"Sharpen"<<std::endl;
507                    _gt->setFilterMatrixAs(osgTerrain::GeometryTechnique::SHARPEN);
508                    return true;
509                }
510                else if (ea.getKey() == '+')
511                {
512                    _gt->setFilterWidth(_gt->getFilterWidth()*1.1);
513                    osg::notify(osg::NOTICE)<<"Filter width = "<<_gt->getFilterWidth()<<std::endl;
514                    return true;
515                }
516                else if (ea.getKey() == '-')
517                {
518                    _gt->setFilterWidth(_gt->getFilterWidth()/1.1);
519                    osg::notify(osg::NOTICE)<<"Filter width = "<<_gt->getFilterWidth()<<std::endl;
520                    return true;
521                }
522                else if (ea.getKey() == '>')
523                {
524                    _gt->setFilterBias(_gt->getFilterBias()+0.1);
525                    osg::notify(osg::NOTICE)<<"Filter bias = "<<_gt->getFilterBias()<<std::endl;
526                    return true;
527                }
528                else if (ea.getKey() == '<')
529                {
530                    _gt->setFilterBias(_gt->getFilterBias()-0.1);
531                    osg::notify(osg::NOTICE)<<"Filter bias = "<<_gt->getFilterBias()<<std::endl;
532                    return true;
533                }
534                break;
535            }
536        default:
537            break;
538        }
539        return false;
540
541    }
542
543protected:
544
545    osg::observer_ptr<osgTerrain::GeometryTechnique> _gt;
546
547};
548
549
550
551class LayerHandler : public osgGA::GUIEventHandler
552{
553public:
554
555    LayerHandler(osgTerrain::Layer* layer):
556        _layer(layer) {}
557
558    bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
559    {
560        if (!_layer) return false;
561
562        float scale = 1.2;
563
564        switch(ea.getEventType())
565        {
566        case(osgGA::GUIEventAdapter::KEYDOWN):
567            {
568                if (ea.getKey() == 'q')
569                {
570                    _layer->transform(0.0, scale);
571                    return true;
572                }
573                else if (ea.getKey() == 'a')
574                {
575                    _layer->transform(0.0, 1.0f/scale);
576                    return true;
577                }
578                break;
579            }
580        default:
581            break;
582        }
583        return false;
584
585    }
586
587protected:
588
589    osg::observer_ptr<osgTerrain::Layer> _layer;
590};
591
592int main(int argc, char** argv)
593{
594    osg::ArgumentParser arguments(&argc, argv);
595
596    // construct the viewer.
597    osgViewer::Viewer viewer(arguments);
598
599    // set up the camera manipulators.
600    {
601        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
602
603        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
604        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
605        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
606        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
607
608        std::string pathfile;
609        char keyForAnimationPath = '5';
610        while (arguments.read("-p",pathfile))
611        {
612            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
613            if (apm || !apm->valid())
614            {
615                unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
616                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
617                keyswitchManipulator->selectMatrixManipulator(num);
618                ++keyForAnimationPath;
619            }
620        }
621
622        viewer.setCameraManipulator( keyswitchManipulator.get() );
623    }
624
625
626    // add the state manipulator
627    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
628
629    // add the stats handler
630    viewer.addEventHandler(new osgViewer::StatsHandler);
631
632    // add the record camera path handler
633    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler);
634
635    // attach an IncrementaCompileOperation to allow the master loading
636    // to be handled with an incremental compile to avoid frame drops when large objects are added.
637    viewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation());
638
639    double x = 0.0;
640    double y = 0.0;
641    double w = 1.0;
642    double h = 1.0;
643
644    unsigned int numLoadThreads = 1;
645    while (arguments.read("--load-threads",numLoadThreads)) { }
646
647    osg::ref_ptr<MasterOperation> masterOperation;
648    std::string masterFilename;
649    while(arguments.read("-m",masterFilename))
650    {
651        masterOperation = new MasterOperation(masterFilename, viewer.getIncrementalCompileOperation());
652    }
653   
654
655    osg::ref_ptr<osgTerrain::TerrainTile> terrainTile = new osgTerrain::TerrainTile;
656    osg::ref_ptr<osgTerrain::Locator> locator = new osgTerrain::Locator;
657    osg::ref_ptr<osgTerrain::ValidDataOperator> validDataOperator = new osgTerrain::NoDataValue(0.0);
658    osg::ref_ptr<osgTerrain::Layer> lastAppliedLayer;
659
660    locator->setCoordinateSystemType(osgTerrain::Locator::GEOCENTRIC);
661    locator->setTransformAsExtents(-osg::PI, -osg::PI*0.5, osg::PI, osg::PI*0.5);
662
663    unsigned int layerNum = 0;
664
665    std::string filterName;
666
667    osg::Texture::FilterMode filter = osg::Texture::LINEAR;
668
669    float minValue, maxValue;
670    float scale = 1.0f;
671    float offset = 0.0f;
672
673    int pos = 1;
674    while(pos<arguments.argc())
675    {
676        std::string filename;
677       
678        if (arguments.read(pos, "--layer",layerNum))
679        {
680            osg::notify(osg::NOTICE)<<"Set layer number to "<<layerNum<<std::endl;
681        }
682
683        else if (arguments.read(pos, "-b"))
684        {
685            terrainTile->setTreatBoundariesToValidDataAsDefaultValue(true);
686        }
687       
688        else if (arguments.read(pos, "-e",x,y,w,h))
689        {
690            // define the extents.
691            locator->setCoordinateSystemType(osgTerrain::Locator::GEOCENTRIC);
692            locator->setTransformAsExtents(x,y,x+w,y+h);
693        }
694
695        else if (arguments.read(pos, "--transform",offset, scale) || arguments.read(pos, "-t",offset, scale))
696        {
697            // define the extents.
698        }
699
700        else if (arguments.read(pos, "--cartesian",x,y,w,h))
701        {
702            // define the extents.
703            locator->setCoordinateSystemType(osgTerrain::Locator::PROJECTED);
704            locator->setTransformAsExtents(x,y,x+w,y+h);
705        }
706
707        else if (arguments.read(pos, "--hf",filename))
708        {
709            osg::notify(osg::NOTICE)<<"--hf "<<filename<<std::endl;
710
711            osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(filename);
712            if (hf.valid())
713            {
714                osg::ref_ptr<osgTerrain::HeightFieldLayer> hfl = new osgTerrain::HeightFieldLayer;
715                hfl->setHeightField(hf.get());
716               
717                hfl->setLocator(locator.get());
718                hfl->setValidDataOperator(validDataOperator.get());
719                hfl->setMagFilter(filter);
720               
721                if (offset!=0.0f || scale!=1.0f)
722                {
723                    hfl->transform(offset,scale);
724                }
725               
726                terrainTile->setElevationLayer(hfl.get());
727               
728                lastAppliedLayer = hfl.get();
729               
730                osg::notify(osg::NOTICE)<<"created osgTerrain::HeightFieldLayer"<<std::endl;
731            }
732            else
733            {
734                osg::notify(osg::NOTICE)<<"failed to create osgTerrain::HeightFieldLayer"<<std::endl;
735            }
736           
737            scale = 1.0f;
738            offset = 0.0f;
739           
740        }
741
742        else if (arguments.read(pos, "-d",filename) || arguments.read(pos, "--elevation-image",filename))
743        {
744            osg::notify(osg::NOTICE)<<"--elevation-image "<<filename<<std::endl;
745
746            osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
747            if (image.valid())
748            {
749                osg::ref_ptr<osgTerrain::ImageLayer> imageLayer = new osgTerrain::ImageLayer;
750                imageLayer->setImage(image.get());
751                imageLayer->setLocator(locator.get());
752                imageLayer->setValidDataOperator(validDataOperator.get());
753                imageLayer->setMagFilter(filter);
754               
755                if (offset!=0.0f || scale!=1.0f)
756                {
757                    imageLayer->transform(offset,scale);
758                }
759               
760                terrainTile->setElevationLayer(imageLayer.get());
761               
762                lastAppliedLayer = imageLayer.get();
763
764                osg::notify(osg::NOTICE)<<"created Elevation osgTerrain::ImageLayer"<<std::endl;
765            }
766            else
767            {
768                osg::notify(osg::NOTICE)<<"failed to create osgTerrain::ImageLayer"<<std::endl;
769            }
770
771            scale = 1.0f;
772            offset = 0.0f;
773           
774        }
775       
776        else if (arguments.read(pos, "-c",filename) || arguments.read(pos, "--image",filename))
777        {
778            osg::notify(osg::NOTICE)<<"--image "<<filename<<" x="<<x<<" y="<<y<<" w="<<w<<" h="<<h<<std::endl;
779
780            osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
781            if (image.valid())
782            {
783                osg::ref_ptr<osgTerrain::ImageLayer> imageLayer = new osgTerrain::ImageLayer;
784                imageLayer->setImage(image.get());
785                imageLayer->setLocator(locator.get());
786                imageLayer->setValidDataOperator(validDataOperator.get());
787                imageLayer->setMagFilter(filter);
788               
789                if (offset!=0.0f || scale!=1.0f)
790                {
791                    imageLayer->transform(offset,scale);
792                }
793
794                terrainTile->setColorLayer(layerNum, imageLayer.get());
795
796                lastAppliedLayer = imageLayer.get();
797
798                osg::notify(osg::NOTICE)<<"created Color osgTerrain::ImageLayer"<<std::endl;
799            }
800            else
801            {
802                osg::notify(osg::NOTICE)<<"failed to create osgTerrain::ImageLayer"<<std::endl;
803            }
804
805            scale = 1.0f;
806            offset = 0.0f;
807           
808        }
809
810        else if (arguments.read(pos, "--filter",filterName))
811        {
812            if (filterName=="NEAREST")
813            {
814                osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
815                filter = osg::Texture::NEAREST;
816            }
817            else if (filterName=="LINEAR")
818            {
819                filter = osg::Texture::LINEAR;
820                osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
821            }
822            else
823            {
824                osg::notify(osg::NOTICE)<<"--filter "<<filterName<<" unrecognized filter name, please use LINEAER or NEAREST."<<std::endl;
825            }           
826
827            if (terrainTile->getColorLayer(layerNum))
828            {
829                terrainTile->getColorLayer(layerNum)->setMagFilter(filter);
830            }
831           
832        }
833
834        else if (arguments.read(pos, "--tf",minValue, maxValue))
835        {
836            osg::ref_ptr<osg::TransferFunction1D> tf = new osg::TransferFunction1D;
837           
838            unsigned int numCells = 6;
839            float delta = (maxValue-minValue)/float(numCells-1);
840            float v = minValue;
841           
842            tf->allocate(6);
843            tf->setColor(v, osg::Vec4(1.0,1.0,1.0,1.0)); v += delta;
844            tf->setColor(v, osg::Vec4(1.0,0.0,1.0,1.0)); v += delta;
845            tf->setColor(v, osg::Vec4(1.0,0.0,0.0,1.0)); v += delta;
846            tf->setColor(v, osg::Vec4(1.0,1.0,0.0,1.0)); v += delta;
847            tf->setColor(v, osg::Vec4(0.0,1.0,1.0,1.0)); v += delta;
848            tf->setColor(v, osg::Vec4(0.0,1.0,0.0,1.0));
849           
850            osg::notify(osg::NOTICE)<<"--tf "<<minValue<<" "<<maxValue<<std::endl;
851
852            terrainTile->setColorLayer(layerNum, new osgTerrain::ContourLayer(tf.get()));
853        }
854        else
855        {
856            ++pos;
857        }
858
859    }
860   
861
862    osg::ref_ptr<osg::Group> scene = new osg::Group;
863
864    if (terrainTile.valid() && (terrainTile->getElevationLayer() || terrainTile->getColorLayer(0)))
865    {
866        osg::notify(osg::NOTICE)<<"Terrain created"<<std::endl;
867   
868        scene->addChild(terrainTile.get());
869
870        osg::ref_ptr<osgTerrain::GeometryTechnique> geometryTechnique = new osgTerrain::GeometryTechnique;
871        terrainTile->setTerrainTechnique(geometryTechnique.get());
872        viewer.addEventHandler(new FilterHandler(geometryTechnique.get()));
873        viewer.addEventHandler(new LayerHandler(lastAppliedLayer.get()));
874    }
875
876    if (masterOperation.valid())
877    {
878        osg::notify(osg::NOTICE)<<"Master operation created"<<std::endl;
879
880        masterOperation->open(scene.get());
881    }
882   
883    if (scene->getNumChildren()==0)
884    {
885        osg::notify(osg::NOTICE)<<"No model created, please specify terrain or master file on command line."<<std::endl;
886        return 0;
887    }
888   
889    viewer.setSceneData(scene.get());
890
891
892    // start operation thread if a master file has been used.
893    osg::ref_ptr<osg::OperationThread> masterOperationThread;
894   
895    typedef std::list< osg::ref_ptr<osg::OperationThread> > OperationThreadList;
896    OperationThreadList generalThreadList;
897   
898    if (masterOperation.valid())
899    {
900        masterOperationThread = new osg::OperationThread;
901        masterOperationThread->startThread();
902       
903        masterOperationThread->add(masterOperation.get());
904
905//        if (numLoadThreads>0)
906        {
907            osg::ref_ptr<osg::OperationQueue> operationQueue = new osg::OperationQueue;
908            masterOperation->setOperationQueue(operationQueue.get());
909
910            for(unsigned int i=0; i<numLoadThreads; ++i)
911            {       
912                osg::ref_ptr<osg::OperationThread> thread = new osg::OperationThread;
913                thread->setOperationQueue(operationQueue.get());
914                thread->startThread();
915                generalThreadList.push_back(thread);
916            }
917        }
918       
919        viewer.addUpdateOperation(masterOperation.get());
920    }
921   
922    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
923   
924    // enable the use of compile contexts and associated threads.
925    // osg::DisplaySettings::instance()->setCompileContextsHint(true);
926
927    // realize the graphics windows.
928    viewer.realize();
929
930    // run the viewers main loop
931    return viewer.run();
932
933}
Note: See TracBrowser for help on using the browser.