root/OpenSceneGraph/trunk/src/osgPlugins/p3d/ReaderWriterP3D.cpp @ 12597

Revision 12597, 82.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    /* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 *
3 * This software is open source and may be redistributed and/or modified under 
4 * the terms of the GNU General Public License (GPL) version 2.0.
5 * The full license is in LICENSE.txt file included with this distribution,.
6 *
7 * This software is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * include LICENSE.txt for more details.
11*/
12
13#include <osg/Notify>
14#include <osg/io_utils>
15#include <osg/PagedLOD>
16
17#include <osgDB/ReaderWriter>
18#include <osgDB/FileNameUtils>
19#include <osgDB/FileUtils>
20#include <osgDB/Registry>
21
22#include <osgWidget/PdfReader>
23
24#include <osgPresentation/SlideShowConstructor>
25
26#include <stdio.h>
27#include <string.h>
28#include <stdlib.h>
29
30#include <osgDB/XmlParser>
31
32#include <sstream>
33#include <iostream>
34
35
36/**
37 * OpenSceneGraph plugin wrapper/converter.
38 */
39class ReaderWriterP3DXML : public osgDB::ReaderWriter
40{
41public:
42    ReaderWriterP3DXML()
43    {
44        _colorMap["WHITE"]  .set(1.0f,1.0f,1.0f,1.0f);
45        _colorMap["BLACK"]  .set(0.0f,0.0f,0.0f,1.0f);
46        _colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f);
47        _colorMap["BLUE"]   .set(0.0f,0.0f,1.0f,1.0f);
48        _colorMap["RED"]    .set(1.0f,0.0f,0.0f,1.0f);
49        _colorMap["CYAN"]   .set(0.0f,1.0f,1.0f,1.0f);
50        _colorMap["YELLOW"] .set(1.0f,1.0f,0.0f,1.0f);
51        _colorMap["GREEN"]  .set(0.0f,1.0f,0.0f,1.0f);
52        _colorMap["SKY"]    .set(0.2f, 0.2f, 0.4f, 1.0f);
53
54        _layoutMap["LEFT_TO_RIGHT"] = osgText::Text::LEFT_TO_RIGHT;
55        _layoutMap["RIGHT_TO_LEFT"] = osgText::Text::RIGHT_TO_LEFT;
56        _layoutMap["VERTICAL"] = osgText::Text::VERTICAL;
57
58        _alignmentMap["LEFT_TOP"] = osgText::Text::LEFT_TOP;
59        _alignmentMap["LEFT_CENTER"] = osgText::Text::LEFT_CENTER;
60        _alignmentMap["LEFT_BOTTOM"] = osgText::Text::LEFT_BOTTOM;
61
62        _alignmentMap["CENTER_TOP"] = osgText::Text::CENTER_TOP;
63        _alignmentMap["CENTER_CENTER"] = osgText::Text::CENTER_CENTER;
64        _alignmentMap["CENTER_BOTTOM"] = osgText::Text::CENTER_BOTTOM;
65
66        _alignmentMap["RIGHT_TOP"] = osgText::Text::RIGHT_TOP;
67        _alignmentMap["RIGHT_CENTER"] = osgText::Text::RIGHT_CENTER;
68        _alignmentMap["RIGHT_BOTTOM"] = osgText::Text::RIGHT_BOTTOM;
69       
70        _alignmentMap["LEFT_BASE_LINE"] = osgText::Text::LEFT_BASE_LINE;
71        _alignmentMap["CENTER_BASE_LINE"] = osgText::Text::CENTER_BASE_LINE;
72        _alignmentMap["RIGHT_BASE_LINE"] = osgText::Text::RIGHT_BASE_LINE;
73        _alignmentMap["BASE_LINE"] = osgText::Text::LEFT_BASE_LINE;
74
75        _characterSizeModeMap["OBJECT_COORDS"] = osgText::Text::OBJECT_COORDS;
76        _characterSizeModeMap["SCREEN_COORDS"] = osgText::Text::SCREEN_COORDS;
77        _characterSizeModeMap["OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT"] = osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT;
78
79        _stringKeyMap["Home"]=' ';
80        _stringKeyMap["Start"]= osgGA::GUIEventAdapter::KEY_Home;
81        _stringKeyMap["Next"]= osgGA::GUIEventAdapter::KEY_Page_Down;
82        _stringKeyMap["Previous"]=osgGA::GUIEventAdapter::KEY_Page_Up;
83        _stringKeyMap["Up"]=osgGA::GUIEventAdapter::KEY_Up;
84        _stringKeyMap["Down"]=osgGA::GUIEventAdapter::KEY_Down;
85        _stringKeyMap["End"]=osgGA::GUIEventAdapter::KEY_End;
86        _stringKeyMap["Page Down"]=osgGA::GUIEventAdapter::KEY_Page_Down;
87        _stringKeyMap["Page Up"]=osgGA::GUIEventAdapter::KEY_Page_Up;
88        _stringKeyMap["F1"]=osgGA::GUIEventAdapter::KEY_F1;
89        _stringKeyMap["F2"]=osgGA::GUIEventAdapter::KEY_F2;
90        _stringKeyMap["F3"]=osgGA::GUIEventAdapter::KEY_F3;
91        _stringKeyMap["F4"]=osgGA::GUIEventAdapter::KEY_F4;
92        _stringKeyMap["F5"]=osgGA::GUIEventAdapter::KEY_F5;
93        _stringKeyMap["F6"]=osgGA::GUIEventAdapter::KEY_F6;
94        _stringKeyMap["F7"]=osgGA::GUIEventAdapter::KEY_F7;
95        _stringKeyMap["F8"]=osgGA::GUIEventAdapter::KEY_F8;
96        _stringKeyMap["F9"]=osgGA::GUIEventAdapter::KEY_F9;
97        _stringKeyMap["F10"]=osgGA::GUIEventAdapter::KEY_F10;
98        _stringKeyMap["F11"]=osgGA::GUIEventAdapter::KEY_F11;
99        _stringKeyMap["F12"]=osgGA::GUIEventAdapter::KEY_F12;
100
101
102        _notifyLevel = osg::INFO;
103    }
104   
105    virtual const char* className() const
106    {
107        return "present3D XML Reader/Writer";
108    }
109
110    virtual bool acceptsExtension(const std::string& extension) const
111    {
112        return osgDB::equalCaseInsensitive(extension,"p3d") ||
113               osgDB::equalCaseInsensitive(extension,"xml") ;
114    }
115
116    virtual ReadResult readNode(const std::string& fileName,
117                                const osgDB::ReaderWriter::Options* options) const;
118
119    virtual ReadResult readNode(std::istream& fin, const Options* options) const;
120
121    ReadResult readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const;
122
123    osg::Node* parseXmlGraph(osgDB::XmlNode* root, bool readOnlyHoldingPage, osgDB::Options* options) const;
124
125    void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
126
127    osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename, float scale) const;
128    void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
129
130    void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
131
132    void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
133 
134    void parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const;
135    void parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const;
136
137    void parsePage (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
138   
139    void parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool parseTitles=true, bool parseLayers=true) const;
140
141    void parsePdfDocument (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
142
143    osg::Vec4 mapStringToColor(const std::string& str) const
144    {
145        ColorMap::const_iterator itr=_colorMap.find(str);
146        if (itr!=_colorMap.end()) return itr->second;
147        osg::Vec4 color;
148        if (read(str,color)) return color;
149        else return osg::Vec4(0.0f,0.0f,0.0f,1.0f);
150    }
151   
152    inline osg::Vec4 accumulateRotation(const osg::Vec4& lhs, const osg::Vec4& rhs) const
153    {
154        osg::Quat qlhs,qrhs;
155        qlhs.makeRotate(osg::DegreesToRadians(lhs[0]),lhs[1],lhs[2],lhs[3]);
156        qrhs.makeRotate(osg::DegreesToRadians(rhs[0]),rhs[1],rhs[2],rhs[3]);
157        osg::Quat quat = qlhs*qrhs;
158        osg::Vec4d result;
159        quat.getRotate ( result[0], result[1], result[2], result[3]);
160        result[0] = osg::RadiansToDegrees(result[0]);
161        return result;
162    }
163
164    inline bool read(const char* str, int& value) const;
165    inline bool read(const char* str, float& value) const;
166    inline bool read(const char* str, double& value) const;
167    inline bool read(const char* str, int numberValues, float* values) const;
168    inline bool read(const char* str, osg::Vec2& value) const;
169    inline bool read(const char* str, osg::Vec3& value) const;
170    inline bool read(const char* str, osg::Vec4& value) const;
171   
172    inline bool read(const std::string& str, int& value) const;
173    inline bool read(const std::string& str, float& value) const;
174    inline bool read(const std::string& str, double& value) const;
175    inline bool read(const std::string& str, int numberValues, float* values) const;
176    inline bool read(const std::string& str, osg::Vec2& value) const;
177    inline bool read(const std::string& str, osg::Vec3& value) const;
178    inline bool read(const std::string& str, osg::Vec4& value) const;
179
180    bool getProperty(osgDB::XmlNode*cur, const char* token) const;
181    bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
182    bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
183    bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
184    bool getProperty(osgDB::XmlNode*cur, const char* token, int numberValues, float* values) const;
185    bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const;
186    bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const;
187    bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const;
188    bool getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const;
189    bool getTrimmedProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const;
190    bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const;
191    bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const;
192    bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::CharacterSizeMode& value) const;
193   
194    bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const;
195    bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const;
196    bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const;
197    bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const;
198    bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const;
199 
200    bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
201    bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
202
203    typedef std::map<std::string,osg::Vec4> ColorMap;
204    typedef std::map<std::string,osgText::Text::Layout> LayoutMap;
205    typedef std::map<std::string,osgText::Text::AlignmentType> AlignmentMap;
206    typedef std::map<std::string,osgText::Text::CharacterSizeMode> CharacterSizeModeMap;
207    typedef std::map<std::string, unsigned int> StringKeyMap;
208
209    std::string expandEnvVarsInFileName(const std::string& filename) const;
210
211
212    ColorMap                _colorMap;
213    LayoutMap               _layoutMap;
214    AlignmentMap            _alignmentMap;
215    CharacterSizeModeMap    _characterSizeModeMap;
216    StringKeyMap            _stringKeyMap;
217   
218    typedef std::map<std::string, osg::ref_ptr<osgDB::XmlNode> > TemplateMap;
219    mutable TemplateMap _templateMap;
220
221    osg::NotifySeverity _notifyLevel;
222
223};
224
225// now register with Registry to instantiate the above
226// reader/writer.
227REGISTER_OSGPLUGIN(p3d, ReaderWriterP3DXML)
228
229std::string ReaderWriterP3DXML::expandEnvVarsInFileName(const std::string& filename) const
230{
231    std::string argument(filename);
232    std::string::size_type start_pos = argument.find("${");
233   
234    while (start_pos != std::string::npos)
235    {       
236        std::string::size_type end_pos = argument.find("}",start_pos);
237        if (start_pos != std::string::npos)
238        {
239            std::string var = argument.substr(start_pos+2, end_pos-start_pos-2);
240            const char* str = getenv(var.c_str());
241            if (str)
242            {
243                argument.erase(start_pos, end_pos-start_pos+1);
244                argument.insert(start_pos, str);
245            }
246            start_pos = argument.find("${",end_pos);
247        }
248        else
249        {
250            start_pos = std::string::npos;
251        }
252    }
253
254    return argument;
255}
256
257bool ReaderWriterP3DXML::read(const char* str, int& value) const
258{
259    if (!str) return false;
260    std::istringstream iss((const char*)str);
261    iss >> value;
262    return !iss.fail();
263}
264
265bool ReaderWriterP3DXML::read(const char* str, float& value) const
266{
267    if (!str) return false;
268    std::istringstream iss((const char*)str);
269    iss >> value;
270    return !iss.fail();
271}
272
273bool ReaderWriterP3DXML::read(const char* str, double& value) const
274{
275    if (!str) return false;
276    std::istringstream iss((const char*)str);
277    iss >> value;
278    return !iss.fail();
279}
280
281bool ReaderWriterP3DXML::read(const char* str, int numberValues, float* values) const
282{
283    if (!str) return false;
284    std::istringstream iss((const char*)str);
285    for(int i=0; i<numberValues && !iss.fail(); i++)
286    {
287        iss >> *values;
288        ++values;
289    }
290    return !iss.fail();
291}
292
293bool ReaderWriterP3DXML::read(const char* str, osg::Vec2& value) const
294{
295    if (!str) return false;
296    std::istringstream iss((const char*)str);
297    iss >> value.x() >> value.y();
298    return !iss.fail();
299}
300
301bool ReaderWriterP3DXML::read(const char* str, osg::Vec3& value) const
302{
303    if (!str) return false;
304    std::istringstream iss((const char*)str);
305    iss >> value.x() >> value.y() >> value.z();
306    return !iss.fail();
307}
308
309bool ReaderWriterP3DXML::read(const char* str, osg::Vec4& value) const
310{
311    if (!str) return false;
312    std::istringstream iss((const char*)str);
313    iss >> value.x() >> value.y() >> value.z() >> value.w();
314    return !iss.fail();
315}
316
317bool ReaderWriterP3DXML::read(const std::string& str, int& value) const
318{
319    std::istringstream iss(str);
320    iss >> value;
321    return !iss.fail();
322}
323
324bool ReaderWriterP3DXML::read(const std::string& str, float& value) const
325{
326    std::istringstream iss(str);
327    iss >> value;
328    return !iss.fail();
329}
330
331bool ReaderWriterP3DXML::read(const std::string& str, double& value) const
332{
333    std::istringstream iss(str);
334    iss >> value;
335    return !iss.fail();
336}
337
338
339bool ReaderWriterP3DXML::read(const std::string& str, int numberValues, float* values) const
340{
341    std::istringstream iss(str);
342    for(int i=0; i<numberValues && !iss.fail(); i++)
343    {
344        iss >> *values;
345        ++values;
346    }
347    return !iss.fail();
348}
349
350bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec2& value) const
351{
352    std::istringstream iss(str);
353    iss >> value.x() >> value.y();
354    return !iss.fail();
355}
356
357bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec3& value) const
358{
359    std::istringstream iss(str);
360    iss >> value.x() >> value.y() >> value.z();
361    return !iss.fail();
362}
363
364bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec4& value) const
365{
366    std::istringstream iss(str);
367    iss >> value.x() >> value.y() >> value.z() >> value.w();
368    return !iss.fail();
369}
370
371bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) const
372{
373    return cur->properties.count(token)!=0;
374}
375
376bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const
377{
378    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
379    if (itr==cur->properties.end()) return false;
380    return read(itr->second,value);
381}
382
383bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const
384{
385    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
386    if (itr==cur->properties.end()) return false;
387    return read(itr->second,value);
388}
389
390bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, double& value) const
391{
392    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
393    if (itr==cur->properties.end()) return false;
394    return read(itr->second,value);
395}
396
397bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int numberValues, float* values) const
398{
399    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
400    if (itr==cur->properties.end()) return false;
401    return read(itr->second, numberValues, values);
402}
403
404bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const
405{
406    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
407    if (itr==cur->properties.end()) return false;
408    return read(itr->second,value);
409}
410
411bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const
412{
413    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
414    if (itr==cur->properties.end()) return false;
415    return read(itr->second,value);
416}
417
418bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const
419{
420    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
421    if (itr==cur->properties.end()) return false;
422    return read(itr->second,value);
423}
424
425bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const
426{
427    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
428    if (itr==cur->properties.end()) return false;
429    value = itr->second;
430    return true;
431}
432
433bool ReaderWriterP3DXML::getTrimmedProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const
434{
435    osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
436    if (itr==cur->properties.end()) return false;
437    value = osgDB::trimEnclosingSpaces(itr->second);
438    return true;
439}
440
441bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const
442{
443    osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token);
444    if (pitr==cur->properties.end()) return false;
445
446    const std::string& str = pitr->second;
447    LayoutMap::const_iterator itr = _layoutMap.find(str);
448    if (itr!=_layoutMap.end())
449    {
450        value = itr->second;
451    }
452    return true;
453}
454
455bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const
456{
457    osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token);
458    if (pitr==cur->properties.end()) return false;
459
460    const std::string& str = pitr->second;
461    AlignmentMap::const_iterator itr = _alignmentMap.find(str);
462    if (itr!=_alignmentMap.end())
463    {
464        value = itr->second;
465    }
466    return true;
467}
468
469bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::CharacterSizeMode& value) const
470{
471    osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token);
472    if (pitr==cur->properties.end()) return false;
473
474    const std::string& str = pitr->second;
475    CharacterSizeModeMap::const_iterator itr = _characterSizeModeMap.find(str);
476    if (itr!=_characterSizeModeMap.end())
477    {
478        value = itr->second;
479    }
480    return true;
481}
482
483bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const
484{
485    bool propertiesRead=false;   
486
487    osg::Vec3 position(0.0f,1.0f,0.0f);
488    osg::Vec4 rotate(0.0f,0.0f,0.0f,1.0f);
489    float scale = 1.0f;
490
491    osg::Vec4 rotation(0.0f,0.0f,0.0f,1.0f);
492
493    // temporary
494    std::string str;
495
496    if (getProperty(cur, "coordinate_frame", str))
497    {
498        propertiesRead = true;
499
500        if (str=="model") value.frame = osgPresentation::SlideShowConstructor::MODEL;
501        else if (str=="slide") value.frame = osgPresentation::SlideShowConstructor::SLIDE;
502        else OSG_NOTIFY(_notifyLevel)<<"Parser error - coordinate_frame=\""<<str<<"\" unrecongonized value"<<std::endl;
503       
504        OSG_NOTIFY(_notifyLevel)<<"read coordinate_frame "<< ((value.frame==osgPresentation::SlideShowConstructor::MODEL) ? "osgPresentation::SlideShowConstructor::MODEL" : "osgPresentation::SlideShowConstructor::SLIDE")<<std::endl;
505    }
506
507    if (value.frame==osgPresentation::SlideShowConstructor::SLIDE)
508    {
509       
510        if (getProperty(cur, "position", str))
511        {
512            value.position.set(0.5,0.5,0.0);
513
514            propertiesRead = true;
515
516            osg::Vec2 vec2;
517            osg::Vec3 vec3;
518       
519            bool fail = false;
520            if (str=="center") value.position.set(0.5f,.5f,0.0f);
521            else if (str=="eye") value.position.set(0.0f,0.0f,1.0f);
522            else if (read(str,vec3)) value.position = vec3;
523            else if (read(str,vec2)) value.position.set(vec3.x(),vec3.y(),0.0f);
524            else fail = true;
525
526            if (fail) { OSG_NOTIFY(_notifyLevel)<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl; }
527            else { OSG_NOTIFY(_notifyLevel)<<"Read position="<<value.position<<std::endl; }
528        }
529    }
530    else // value.frame==osgPresentation::SlideShowConstructor::MODEL
531    {
532
533        if (getProperty(cur, "position", str))
534        {
535            value.position.set(0.0,0.0,0.0);
536
537            propertiesRead = true;
538           
539            bool fail = false;
540            if (str=="center") value.position.set(0.0f,1.0f,0.0f);
541            else if (str=="eye") value.position.set(0.0f,0.0f,0.0f);
542            else if (!read(str,value.position)) fail = true;
543
544            if (fail) { OSG_NOTIFY(_notifyLevel)<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl; }
545            else { OSG_NOTIFY(_notifyLevel)<<"Read position="<<value.position<<std::endl; }
546        }
547    }
548
549   
550    if (getProperty(cur, "scale", scale))
551    {
552        value.scale.set(scale,scale,scale);
553        propertiesRead = true;
554        OSG_NOTIFY(_notifyLevel)<<"scale read "<<scale<<std::endl;
555    }
556
557    if (getProperty(cur, "scale_x", scale) || getProperty(cur, "width", scale))
558    {
559        value.scale.x() = scale;
560        propertiesRead = true;
561        OSG_NOTIFY(_notifyLevel)<<"scale read_x "<<scale<<std::endl;
562    }
563
564    if (getProperty(cur, "scale_y", scale) || getProperty(cur, "height", scale))
565    {
566        value.scale.y() = scale;
567        propertiesRead = true;
568        OSG_NOTIFY(_notifyLevel)<<"scale read_y "<<scale<<std::endl;
569    }
570
571    if (getProperty(cur, "scale_z", scale))
572    {
573        value.scale.z() = scale;
574        propertiesRead = true;
575        OSG_NOTIFY(_notifyLevel)<<"scale read_z "<<scale<<std::endl;
576    }
577
578    if (getProperty(cur, "rotate", rotate))
579    {
580        value.rotate = rotate;
581        propertiesRead = true;
582        OSG_NOTIFY(_notifyLevel)<<"rotate read "<<rotate<<std::endl;
583    }
584
585    if (getProperty(cur, "rotate1", rotate))
586    {
587        // note may need to reverse once Quat * order is sorted out.
588        value.rotate = accumulateRotation(rotate,value.rotate);
589        propertiesRead = true;
590        OSG_NOTIFY(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl;
591    }
592
593    if (getProperty(cur, "rotate2", rotate))
594    {
595        // note may need to reverse once Quat * order is sorted out.
596        value.rotate = accumulateRotation(rotate,value.rotate);
597        propertiesRead = true;
598        OSG_NOTIFY(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl;
599    }
600
601    if (getProperty(cur, "rotate3", rotate))
602    {
603        // note may need to reverse once Quat * order is sorted out.
604        value.rotate = accumulateRotation(rotate,value.rotate);
605        propertiesRead = true;
606        OSG_NOTIFY(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl;
607    }
608
609    if (getProperty(cur, "rotation", rotation))
610    {
611        value.rotation = rotation;
612        OSG_NOTIFY(_notifyLevel)<<"rotation read "<<rotation<<std::endl;
613        propertiesRead = true;
614    }
615
616    if (getProperty(cur, "rotation1", rotation))
617    {
618        value.rotation = accumulateRotation(rotation,value.rotation);
619        OSG_NOTIFY(_notifyLevel)<<"rotation1 read "<<rotation<<std::endl;
620        propertiesRead = true;
621    }
622
623    if (getProperty(cur, "rotation2", rotation))
624    {
625        value.rotation = accumulateRotation(rotation,value.rotation);
626        OSG_NOTIFY(_notifyLevel)<<"rotation2 read "<<rotation<<std::endl;
627        propertiesRead = true;
628    }
629
630    if (getProperty(cur, "rotation3", rotation))
631    {
632        value.rotation = accumulateRotation(rotation,value.rotation);
633        OSG_NOTIFY(_notifyLevel)<<"rotation3 read "<<rotation<<std::endl;
634        propertiesRead = true;
635    }
636
637    if (getTrimmedProperty(cur, "path", str))
638    {
639   
640        value.absolute_path = false;
641        value.inverse_path = false;
642        value.path = expandEnvVarsInFileName(str);
643
644        OSG_NOTIFY(_notifyLevel)<<"path read "<<str<<std::endl;
645        propertiesRead = true;
646    }
647
648    if (getTrimmedProperty(cur, "camera_path", str))
649    {
650        value.absolute_path = true;
651        value.inverse_path = true;
652        value.path = expandEnvVarsInFileName(str);
653
654        OSG_NOTIFY(_notifyLevel)<<"camera path read "<<str<<std::endl;
655        propertiesRead = true;
656    }
657
658    if (getProperty(cur, "path_time_offset", value.path_time_offset))
659    {
660        OSG_NOTIFY(_notifyLevel)<<"read path_time_offset"<<value.path_time_offset<<std::endl;
661        propertiesRead = true;
662    }
663
664    if (getProperty(cur, "path_time_multiplier", value.path_time_multiplier))
665    {
666        OSG_NOTIFY(_notifyLevel)<<"read path_time_multiplier"<<value.path_time_multiplier<<std::endl;
667        propertiesRead = true;
668    }
669
670    if (getProperty(cur, "animation_material_time_offset", value.animation_material_time_offset))
671    {
672        OSG_NOTIFY(_notifyLevel)<<"read animation_material_time_offset"<<value.animation_material_time_offset<<std::endl;
673        propertiesRead = true;
674    }
675
676    if (getProperty(cur, "animation_material_time_multiplier", value.animation_material_time_multiplier))
677    {
678        OSG_NOTIFY(_notifyLevel)<<"read animation_material_time_multiplier"<<value.animation_material_time_multiplier<<std::endl;
679        propertiesRead = true;
680    }
681
682    if (getTrimmedProperty(cur, "animation_material", str))
683    {
684        value.animation_material_filename = str;
685
686        OSG_NOTIFY(_notifyLevel)<<"animation_material read "<<str<<std::endl;
687        propertiesRead = true;
688    }
689
690    if (getTrimmedProperty(cur, "animation_name", str))
691    {
692        value.animation_name = str;
693
694        OSG_NOTIFY(_notifyLevel)<<"animation_name "<<str<<std::endl;
695        propertiesRead = true;
696    }
697
698    if (getProperty(cur, "fade", value.fade))
699    {
700        OSG_NOTIFY(_notifyLevel)<<"fade "<<value.fade<<std::endl;
701        propertiesRead = true;
702    }
703
704    if (getProperty(cur, "path_loop_mode", str))
705    {
706        OSG_NOTIFY(_notifyLevel)<<"path_loop_mode "<<str<<std::endl;
707        if (str=="LOOP") value.path_loop_mode=osg::AnimationPath::LOOP;
708        else if (str=="SWING") value.path_loop_mode=osg::AnimationPath::SWING;
709        else if (str=="NO_LOOPING") value.path_loop_mode=osg::AnimationPath::NO_LOOPING;
710        propertiesRead = true;
711    }
712
713    if (getProperty(cur, "animation_material_loop_mode", str))
714    {
715        OSG_NOTIFY(_notifyLevel)<<"animation_material_loop_mode "<<str<<std::endl;
716        if (str=="LOOP") value.animation_material_loop_mode=osgPresentation::AnimationMaterial::LOOP;
717        else if (str=="SWING") value.animation_material_loop_mode=osgPresentation::AnimationMaterial::SWING;
718        else if (str=="NO_LOOPING") value.animation_material_loop_mode=osgPresentation::AnimationMaterial::NO_LOOPING;
719        propertiesRead = true;
720    }
721
722    if (getProperty(cur, "billboard", str))
723    {
724        value.autoRotate = (str != "off" && str != "Off" && str != "OFF");
725        OSG_NOTIFY(_notifyLevel)<<"billboard, str="<<str<<", autoRotate="<<value.autoRotate<<std::endl;
726        propertiesRead = true;
727    }
728
729    if (getProperty(cur, "scale_to_screen",str))
730    {
731        value.autoScale = (str != "off" && str != "Off" && str != "OFF");
732        OSG_NOTIFY(_notifyLevel)<<"scale-to-screen, str="<<str<<", autoRotate="<<value.autoScale<<std::endl;
733        propertiesRead = true;
734    }
735
736    if (getProperty(cur, "hud", str))
737    {
738        value.hud = (str != "off" && str != "Off" && str != "OFF");
739        OSG_NOTIFY(_notifyLevel)<<"hud, str="<<str<<", hud="<<value.hud<<std::endl;
740        propertiesRead = true;
741    }
742
743
744    return propertiesRead;
745}
746
747bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const
748{
749    bool propertiesRead=false;   
750   
751    OSG_NOTIFY(_notifyLevel)<<"in getProperties(FontData)"<<std::endl;
752
753    if (getProperty(cur, "font", value.font))
754    {
755        propertiesRead = true;
756        OSG_NOTIFY(_notifyLevel)<<"read font \""<<value.font<<"\""<<std::endl;
757    }
758
759    if (getProperty(cur, "character_size", value.characterSize))
760    {
761        propertiesRead = true;
762        OSG_NOTIFY(_notifyLevel)<<"read height \""<<value.characterSize<<"\""<<std::endl;
763    }
764
765    if (getProperty(cur, "character_size_mode", value.characterSizeMode))
766    {
767        propertiesRead = true;
768
769        OSG_NOTIFY(_notifyLevel)<<"read character_size_mode \""<<value.characterSizeMode<<"\""<<std::endl;
770    }
771
772    if (getProperty(cur, "layout", value.layout))
773    {
774        propertiesRead = true;
775
776        OSG_NOTIFY(_notifyLevel)<<"read layout \""<<value.layout<<"\""<<std::endl;
777    }
778
779    if (getProperty(cur, "alignment", value.alignment))
780    {
781        propertiesRead = true;
782
783        OSG_NOTIFY(_notifyLevel)<<"read alignment \""<<value.alignment<<"\""<<std::endl;
784    }
785
786    return propertiesRead;
787}
788
789bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const
790{
791    bool propertiesRead=false;   
792   
793    OSG_NOTIFY(_notifyLevel)<<"in getProperties(ModelData)"<<std::endl;
794
795    if (getProperty(cur, "effect", value.effect))
796    {
797        propertiesRead = true;
798        OSG_NOTIFY(_notifyLevel)<<"read effect \""<<value.effect<<"\""<<std::endl;
799    }
800
801    return propertiesRead;
802}
803
804bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const
805{
806    bool propertiesRead=false;   
807   
808    OSG_NOTIFY(_notifyLevel)<<"in getProperties(ImageData)"<<std::endl;
809
810    if (getProperty(cur, "page", value.page))
811    {
812        propertiesRead = true;
813        OSG_NOTIFY(_notifyLevel)<<"read page \""<<value.page<<"\""<<std::endl;
814    }
815
816    osg::Vec4 bgColour;
817    if (getProperty(cur, "background", value.backgroundColor))
818    {
819        propertiesRead = true;
820        OSG_NOTIFY(_notifyLevel)<<"read background colour \""<<value.backgroundColor<<"\""<<std::endl;
821    }
822
823    if (getProperty(cur, "width", value.width))
824    {
825        propertiesRead = true;
826        OSG_NOTIFY(_notifyLevel)<<"read width \""<<value.width<<"\""<<std::endl;
827    }
828
829    if (getProperty(cur, "height", value.height))
830    {
831        propertiesRead = true;
832        OSG_NOTIFY(_notifyLevel)<<"read height \""<<value.height<<"\""<<std::endl;
833    }
834
835    if (getProperty(cur, "region", value.region))
836    {
837        propertiesRead = true;
838        value.region_in_pixel_coords = false;
839        OSG_NOTIFY(_notifyLevel)<<"read region \""<<value.region<<"\""<<std::endl;
840    }
841
842    if (getProperty(cur, "pixel_region", value.region))
843    {
844        propertiesRead = true;
845        value.region_in_pixel_coords = true;
846        OSG_NOTIFY(_notifyLevel)<<"read pixel_region \""<<value.region<<"\""<<std::endl;
847    }
848
849    std::string str;
850    if (getProperty(cur, "looping", str))
851    {
852        propertiesRead = true;
853        if (str=="ON") value.loopingMode = osg::ImageStream::LOOPING;
854        else value.loopingMode = osg::ImageStream::NO_LOOPING;
855        OSG_NOTIFY(_notifyLevel)<<"looping \""<<str<<"\""<<std::endl;
856    }
857
858/*
859    if (getProperty(cur, "texcoord_offset", value.texcoord_offset))
860    {
861        propertiesRead = true;
862        OSG_NOTIFY(_notifyLevel)<<"read offset \""<<value.texcoord_offset<<"\""<<std::endl;
863    }
864
865    if (getProperty(cur, "texcoord_scale", value.texcoord_scale))
866    {
867        propertiesRead = true;
868        OSG_NOTIFY(_notifyLevel)<<"read texcoord_scale \""<<value.texcoord_scale<<"\""<<std::endl;
869    }
870   
871    if (getProperty(cur, "texcoord_rotate", value.texcoord_rotate))
872    {
873        propertiesRead = true;
874        OSG_NOTIFY(_notifyLevel)<<"read texcoord_rotate \""<<value.texcoord_rotate<<"\""<<std::endl;
875    }
876*/
877    return propertiesRead;
878}
879
880bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const
881{
882    bool propertyRead = false;
883
884    if (getProperty(cur, "slide", slideNum))
885    {
886        OSG_INFO<<"slide "<<slideNum<<std::endl;
887        propertyRead = true;
888    }
889
890    if (getProperty(cur, "layer", layerNum))
891    {
892        OSG_INFO<<"layer "<<layerNum<<std::endl;
893        propertyRead = true;
894    }
895
896    std::string jumpType;
897    if (getProperty(cur, "jump", jumpType))
898    {
899        OSG_INFO<<"jump "<<jumpType<<std::endl;
900        propertyRead = true;
901        relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ;
902    }
903
904    return propertyRead;
905}
906
907void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
908{
909
910    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData();
911   bool positionRead = getProperties(cur,positionData);
912
913    osgPresentation::SlideShowConstructor::ModelData modelData;// = constructor.getModelData();
914    getProperties(cur,modelData);
915
916    std::string filename = cur->getTrimmedContents();
917
918    if (!filename.empty())
919    {
920        constructor.addModel(filename,
921                             positionRead ? positionData : constructor.getModelPositionData(),
922                             modelData);
923    }
924}
925
926
927
928osg::TransferFunction1D* ReaderWriterP3DXML::readTransferFunctionFile(const std::string& filename, float scale) const
929{
930    std::string foundFile = osgDB::findDataFile(filename);
931    if (foundFile.empty())
932    {
933        OSG_NOTICE<<"Error: could not find transfer function file : "<<filename<<std::endl;
934        return 0;
935    }
936
937    OSG_NOTICE<<"Reading transfer function "<<filename<<std::endl;
938
939    osg::TransferFunction1D::ColorMap colorMap;
940    osgDB::ifstream fin(foundFile.c_str());
941    while(fin)
942    {
943        char readline[4096];
944        *readline = 0;
945        fin.getline(readline, sizeof(readline));
946
947        if (*readline!=0)
948        {
949            std::stringstream str(readline);
950
951            float value, red, green, blue, alpha;
952            str >> value >> red >> green >> blue >> alpha;
953
954            *readline = 0;
955            str.getline(readline, sizeof(readline));
956
957            char* comment = readline;
958            while(*comment==' ' || *comment=='\t' ) ++comment;
959
960            if (*comment!=0)
961            {
962                OSG_NOTICE<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<") comment = ["<<comment<<"]"<<std::endl;
963            }
964            else
965            {
966                OSG_NOTICE<<"value = "<<value<<" ("<<red<<", "<<green<<", "<<blue<<", "<<alpha<<")"<<std::endl;
967            }
968            colorMap[value] = osg::Vec4(red*scale,green*scale,blue*scale,alpha*scale);
969        }
970    }
971
972    if (colorMap.empty())
973    {
974        OSG_NOTICE<<"Error: No values read from transfer function file: "<<filename<<std::endl;
975        return 0;
976    }
977
978    osg::TransferFunction1D* tf = new osg::TransferFunction1D;
979    tf->assign(colorMap);
980
981    return tf;
982}
983
984
985void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur) const
986{
987
988    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData();
989    bool positionRead = getProperties(cur,positionData);
990
991    osgPresentation::SlideShowConstructor::VolumeData volumeData;
992
993    // check the rendering technique/shading model to use
994    std::string technique;
995    if (getProperty(cur, "technique", technique))
996    {
997        if      (technique=="standard") volumeData.shadingModel =  osgPresentation::SlideShowConstructor::VolumeData::Standard;
998        else if (technique=="mip") volumeData.shadingModel =  osgPresentation::SlideShowConstructor::VolumeData::MaximumIntensityProjection;
999        else if (technique=="isosurface" || technique=="iso" ) volumeData.shadingModel =  osgPresentation::SlideShowConstructor::VolumeData::Isosurface;
1000        else if (technique=="light") volumeData.shadingModel =  osgPresentation::SlideShowConstructor::VolumeData::Light;
1001    }
1002
1003    if (getProperty(cur, "alpha", volumeData.alphaValue)) {}
1004    if (getProperty(cur, "cutoff", volumeData.cutoffValue)) {}
1005    if (getProperty(cur, "region", 6, volumeData.region)) {}
1006    if (getProperty(cur, "sampleDensity", volumeData.sampleDensityValue)) {}
1007    if (getProperty(cur, "sampleDensityWhenMoving", volumeData.sampleDensityWhenMovingValue)) {}
1008
1009    // check for any transfer function required
1010    std::string transferFunctionFile;
1011    if (getTrimmedProperty(cur, "tf", transferFunctionFile))
1012    {
1013        volumeData.transferFunction = readTransferFunctionFile(transferFunctionFile, 1.0);
1014    }
1015
1016    if (getTrimmedProperty(cur, "tf-255", transferFunctionFile))
1017    {
1018        volumeData.transferFunction = readTransferFunctionFile(transferFunctionFile, 1.0/255.0);
1019    }
1020
1021    // check for draggers required
1022    std::string dragger;
1023    if (getProperty(cur, "dragger", dragger))
1024    {
1025        if (dragger=="trackball")
1026        {
1027            volumeData.useTabbedDragger = false;
1028            volumeData.useTrackballDragger = true;
1029        }
1030        if (dragger=="trackball-box")
1031        {
1032            volumeData.useTabbedDragger = true;
1033            volumeData.useTrackballDragger = true;
1034        }
1035        else
1036        {
1037            volumeData.useTabbedDragger = true;
1038            volumeData.useTrackballDragger = false;
1039        }
1040    }
1041
1042    std::string filename = cur->getTrimmedContents();
1043    if (!filename.empty())
1044    {
1045        constructor.addVolume(filename,
1046                             positionRead ? positionData : constructor.getModelPositionData(),
1047                             volumeData);
1048    }
1049}
1050
1051void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
1052{
1053
1054    OSG_INFO<<"ReaderWriterP3DXML::parseStereoPair()"<<std::endl;
1055
1056
1057    std::string filenameLeft;
1058    std::string filenameRight;
1059
1060    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1061    bool positionRead = getProperties(cur,positionData);
1062
1063    osgPresentation::SlideShowConstructor::ImageData imageDataLeft;// = constructor.getImageData();
1064    osgPresentation::SlideShowConstructor::ImageData imageDataRight;// = constructor.getImageData();
1065
1066    for(osgDB::XmlNode::Children::iterator itr = cur->children.begin();
1067        itr != cur->children.end();
1068        ++itr)
1069    {
1070        osgDB::XmlNode* child = itr->get();
1071
1072        if (child->name == "image_left")
1073        {
1074            getProperties(child,imageDataLeft);
1075            filenameLeft = child->getTrimmedContents();
1076        }
1077        if (child->name == "image_right")
1078        {
1079            getProperties(child,imageDataRight);
1080            filenameRight = child->getTrimmedContents();
1081            getProperties(cur,imageDataRight);
1082        }
1083    }
1084
1085    OSG_INFO<<"    filenameLeft="<<filenameLeft<<std::endl;
1086    OSG_INFO<<"    filenameRight="<<filenameRight<<std::endl;
1087
1088
1089    if (!filenameLeft.empty() && !filenameRight.empty())
1090        constructor.addStereoImagePair(filenameLeft,imageDataLeft,
1091                                       filenameRight, imageDataRight,
1092                                       positionRead ? positionData : constructor.getImagePositionData());
1093
1094}
1095
1096bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const
1097{
1098    if (cur->name == "key")
1099    {
1100        return getKeyPositionInner(cur, keyPosition);
1101    }
1102    if (cur->name == "escape" ||
1103        cur->name == "esc" ||
1104        cur->name == "exit")
1105    {
1106        keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f);
1107        return true;
1108    }
1109    return false;
1110}
1111
1112bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const
1113{
1114    // x in range -1 to 1, from left to right
1115    float x = FLT_MAX;
1116    getProperty(cur, "x", x);
1117
1118    // y in range -1 to 1, from bottom to top
1119    float y = FLT_MAX;
1120    getProperty(cur, "y", y);
1121
1122    float h = FLT_MAX;
1123    if (getProperty(cur, "h", h))
1124    {
1125        // h in range 0.0 to 1, from left to right
1126        x = h*2.0f-1.0f;
1127    }
1128
1129    float v = FLT_MAX;
1130    if (getProperty(cur, "v", v))
1131    {
1132        // v in range 0.0 to 1, from bottom to top
1133        y = v*2.0f-1.0f;
1134    }
1135
1136
1137    std::string key = cur->getTrimmedContents();
1138    unsigned int keyValue = 0;
1139
1140    StringKeyMap::const_iterator itr=_stringKeyMap.find(key);
1141    if (itr != _stringKeyMap.end())
1142    {
1143        keyValue = itr->second;
1144    }
1145    else if (key.length()==1)
1146    {
1147        keyValue = key[0];
1148    }
1149    else
1150    {
1151        OSG_NOTICE<<"Warning: unreconginized key sequence '"<<key<<"'"<<std::endl;
1152    }
1153
1154    keyPosition.set(keyValue,x,y);
1155    return true;
1156}
1157
1158
1159
1160
1161void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const
1162{
1163    // create a keyPosition just in case we need it.
1164    osgPresentation::KeyPosition keyPosition;
1165
1166    OSG_INFO<<std::endl<<"parseLayer"<<std::endl;
1167
1168    float totalIndent = 0.0f;
1169
1170    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
1171        itr != root->children.end();
1172        ++itr)
1173    {
1174        osgDB::XmlNode* cur = itr->get();
1175        if (cur->name == "run")
1176        {
1177            OSG_INFO<<"run ["<<cur->contents<<"]"<<std::endl;
1178            constructor.addLayerRunString(cur->contents);
1179        }
1180        else if (cur->name == "jump")
1181        {
1182            OSG_INFO<<"Parsed Jump "<<std::endl;
1183
1184            bool relativeJump = true;
1185            int slideNum = 0;
1186            int layerNum = 0;
1187            if (getJumpProperties(cur, relativeJump, slideNum, layerNum))
1188            {
1189                OSG_INFO<<"Layer Jump "<<relativeJump<<","<< slideNum<<", "<<layerNum<<std::endl;
1190           
1191                constructor.setLayerJump(relativeJump, slideNum, layerNum);
1192            }
1193        }
1194        else if (cur->name == "click_to_run")
1195        {
1196            bool relativeJump = true;
1197            int slideNum = 0;
1198            int layerNum = 0;
1199            getJumpProperties(cur, relativeJump, slideNum, layerNum);
1200
1201            OSG_INFO<<"click_to_run ["<<cur->contents<<"]"<<std::endl;
1202            constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, relativeJump, slideNum, layerNum);
1203        }
1204        else if (cur->name == "click_to_load")
1205        {
1206            bool relativeJump = true;
1207            int slideNum = 0;
1208            int layerNum = 0;
1209            getJumpProperties(cur, relativeJump, slideNum, layerNum);
1210
1211            OSG_INFO<<"click_to_load ["<<cur->contents<<"]"<<std::endl;
1212            constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum);
1213        }
1214
1215        else if (cur->name == "click_to_event")
1216        {
1217            bool relativeJump = true;
1218            int slideNum = 0;
1219            int layerNum = 0;
1220            getJumpProperties(cur, relativeJump, slideNum, layerNum);
1221
1222            if (getKeyPositionInner( cur, keyPosition))
1223            {
1224                OSG_INFO<<"click_to_event ["<<keyPosition._key<<"]"<<std::endl;
1225                constructor.layerClickEventOperation(keyPosition, relativeJump, slideNum, layerNum);
1226            }
1227        }
1228
1229        else if (cur->name == "click_to_jump")
1230        {
1231            bool relativeJump = true;
1232            int slideNum = 0;
1233            int layerNum = 0;
1234            getJumpProperties(cur, relativeJump, slideNum, layerNum);
1235
1236            constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum);
1237        }
1238
1239        else if (cur->name == "newline")
1240        {
1241            constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f));
1242        }
1243        else if (cur->name == "indent")
1244        {
1245            float localIndent = 0.05f;
1246            constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f));
1247            totalIndent += localIndent;
1248        }
1249        else if (cur->name == "unindent")
1250        {
1251            float localIndent = -0.05f;
1252            constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f));
1253            totalIndent += localIndent;
1254        }
1255        else if (cur->name == "bullet")
1256        {
1257            OSG_INFO<<"bullet ["<<cur->contents<<"]"<<std::endl;
1258            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData();
1259            bool positionRead = getProperties(cur,positionData);
1260
1261            osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
1262            bool fontRead = getProperties(cur,fontData);
1263
1264            constructor.addBullet(cur->contents,
1265                                    positionRead ? positionData : constructor.getTextPositionData(),
1266                                    fontRead ? fontData : constructor.getTextFontData());
1267        }
1268        else if (cur->name == "paragraph")
1269        {
1270            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData();
1271            bool positionRead = getProperties(cur,positionData);
1272
1273            osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
1274            bool fontRead = getProperties(cur,fontData);
1275
1276            constructor.addParagraph(cur->contents,
1277                                        positionRead ? positionData : constructor.getTextPositionData(),
1278                                        fontRead ? fontData : constructor.getTextFontData());
1279        }
1280        else if (cur->name == "image")
1281        {
1282            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1283            bool positionRead = getProperties(cur,positionData);
1284
1285            osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1286            getProperties(cur,imageData);
1287
1288            constructor.addImage(cur->getTrimmedContents(),
1289                                    positionRead ? positionData : constructor.getImagePositionData(),
1290                                    imageData);
1291        }
1292        else if (cur->name == "graph")
1293        {
1294            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1295            bool positionRead = getProperties(cur,positionData);
1296
1297            osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1298            getProperties(cur,imageData);
1299
1300            std::string options;
1301            getProperty(cur, "options", options);
1302
1303            constructor.addGraph(cur->getTrimmedContents(), options,
1304                                 positionRead ? positionData : constructor.getImagePositionData(),
1305                                 imageData);
1306        }
1307        else if (cur->name == "vnc")
1308        {
1309            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1310            bool positionRead = getProperties(cur,positionData);
1311
1312            osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1313            getProperties(cur,imageData);
1314
1315            constructor.addVNC(cur->getTrimmedContents(),
1316                                    positionRead ? positionData : constructor.getImagePositionData(),
1317                                    imageData);
1318        }
1319        else if (cur->name == "browser")
1320        {
1321            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1322            bool positionRead = getProperties(cur,positionData);
1323
1324            osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1325            getProperties(cur,imageData);
1326
1327            constructor.addBrowser(cur->getTrimmedContents(),
1328                                    positionRead ? positionData : constructor.getImagePositionData(),
1329                                    imageData);
1330        }
1331        else if (cur->name == "pdf")
1332        {
1333            osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1334            bool positionRead = getProperties(cur,positionData);
1335
1336            osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1337            getProperties(cur,imageData);
1338
1339            constructor.addPDF(cur->getTrimmedContents(),
1340                                    positionRead ? positionData : constructor.getImagePositionData(),
1341                                    imageData);
1342        }
1343        else if (cur->name == "stereo_pair")
1344        {
1345            parseStereoPair(constructor, cur);
1346        }
1347        else if (cur->name == "model")
1348        {
1349            parseModel(constructor, cur);
1350        }
1351        else if (cur->name == "volume")
1352        {
1353            parseVolume(constructor, cur);
1354        }
1355        else if (cur->name == "duration")
1356        {
1357            constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str()));
1358        }
1359        else if (getKeyPosition(cur, keyPosition))
1360        {
1361            constructor.addLayerKey(keyPosition);
1362        }
1363    }
1364
1365    if (totalIndent != 0.0f)
1366    {
1367        constructor.translateTextCursor(osg::Vec3(-totalIndent,0.0f,0.0f));
1368    }
1369
1370}
1371
1372void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const
1373{
1374    constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer);
1375
1376    OSG_INFO<<"bullets ["<<cur->contents<<"]"<<std::endl;
1377    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData();
1378    bool positionRead = getProperties(cur,positionData);
1379
1380    osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
1381    bool fontRead = getProperties(cur,fontData);
1382
1383    constructor.addBullet(cur->contents,
1384                            positionRead ? positionData : constructor.getTextPositionData(),
1385                            fontRead ? fontData : constructor.getTextFontData());
1386}
1387
1388
1389void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const
1390{
1391    constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer);
1392
1393    OSG_INFO<<"text ["<<cur->contents<<"]"<<std::endl;
1394    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData();
1395    bool positionRead = getProperties(cur,positionData);
1396
1397    osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
1398    bool fontRead = getProperties(cur,fontData);
1399
1400    constructor.addParagraph(cur->contents,
1401                            positionRead ? positionData : constructor.getTextPositionData(),
1402                            fontRead ? fontData : constructor.getTextFontData());
1403}
1404
1405void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
1406{
1407    constructor.addSlide();
1408
1409    std::string title;
1410    getProperty(cur, "title", title);
1411
1412    std::string inherit;
1413    getProperty(cur, "inherit", inherit);
1414
1415    if (!inherit.empty() && _templateMap.count(inherit)!=0)
1416    {
1417        parseSlide(constructor, _templateMap[inherit].get(), true, false);
1418    }
1419
1420    if (!title.empty())
1421    {
1422        constructor.setSlideTitle(title,
1423                                    constructor.getTitlePositionData(),
1424                                    constructor.getTitleFontData());
1425    }
1426
1427    if (!inherit.empty() && _templateMap.count(inherit)!=0)
1428    {
1429        parseSlide(constructor, _templateMap[inherit].get(), false, true);
1430    }
1431
1432    constructor.addLayer(true,false);
1433
1434    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData();
1435    bool positionRead = getProperties(cur,positionData);
1436
1437    osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
1438    bool fontRead = getProperties(cur,fontData);
1439
1440    constructor.addParagraph(cur->contents,
1441                            positionRead ? positionData : constructor.getTextPositionData(),
1442                            fontRead ? fontData : constructor.getTextFontData());
1443}
1444
1445void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
1446{
1447    std::string title;
1448    getProperty(cur, "title", title);
1449
1450    std::string inherit;
1451    getProperty(cur, "inherit", inherit);
1452
1453    constructor.addSlide();
1454
1455    if (!inherit.empty() && _templateMap.count(inherit)!=0)
1456    {
1457        parseSlide(constructor, _templateMap[inherit].get(), true, false);
1458    }
1459
1460    if (!title.empty())
1461    {
1462        constructor.setSlideTitle(title,
1463                                    constructor.getTitlePositionData(),
1464                                    constructor.getTitleFontData());
1465    }
1466
1467    if (!inherit.empty() && _templateMap.count(inherit)!=0)
1468    {
1469        parseSlide(constructor, _templateMap[inherit].get(), false, true);
1470    }
1471
1472    constructor.addLayer(true,false);
1473
1474    osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData();
1475    getProperties(cur,positionData);
1476
1477    osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
1478    imageData.page = 0;
1479    getProperties(cur,imageData);
1480
1481    osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData);
1482    osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image);
1483    if (pdfImage)
1484    {
1485        int numPages = pdfImage->getNumOfPages();
1486        OSG_INFO<<"NumOfPages = "<<numPages<<std::endl;
1487
1488        if (numPages>1)
1489        {
1490            for(int pageNum=1; pageNum<numPages; ++pageNum)
1491            {
1492                imageData.page = pageNum;
1493
1494                constructor.addSlide();
1495
1496                if (!inherit.empty() && _templateMap.count(inherit)!=0)
1497                {
1498                    parseSlide(constructor, _templateMap[inherit].get(), true, false);
1499                }
1500
1501                if (!title.empty())
1502                {
1503                    constructor.setSlideTitle(title,
1504                                                constructor.getTitlePositionData(),
1505                                                constructor.getTitleFontData());
1506                }
1507
1508                if (!inherit.empty() && _templateMap.count(inherit)!=0)
1509                {
1510                    parseSlide(constructor, _templateMap[inherit].get(), false, true);
1511                }
1512
1513                constructor.addLayer(true,false);
1514
1515                constructor.addPDF(cur->getTrimmedContents(), positionData, imageData);
1516
1517            }
1518        }
1519    }
1520}
1521
1522void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root, bool parseTitles, bool parseLayers) const
1523{
1524
1525    osg::Vec4 previous_bgcolor = constructor.getBackgroundColor();
1526    osg::Vec4 previous_textcolor = constructor.getTextColor();
1527
1528    // create a keyPosition just in case we need it.
1529    osgPresentation::KeyPosition keyPosition;
1530
1531    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
1532        itr != root->children.end();
1533        ++itr)
1534    {
1535        osgDB::XmlNode* cur = itr->get();
1536
1537        if (parseTitles)
1538        {
1539            if (cur->name == "title")
1540            {
1541                osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData();
1542                bool positionRead = getProperties(cur,positionData);
1543
1544                osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTitleFontData();
1545                bool fontRead = getProperties(cur,fontData);
1546
1547                constructor.setSlideTitle(cur->contents,
1548                                          positionRead ? positionData : constructor.getTitlePositionData(),
1549                                          fontRead ? fontData : constructor.getTitleFontData());
1550            }
1551            else if (cur->name == "background")
1552            {
1553                constructor.setSlideBackground(cur->contents);
1554
1555                std::string str;
1556                if (getProperty(cur, "hud", str))
1557                {
1558                    bool hud = (str != "off" && str != "Off" && str != "OFF");
1559                    OSG_NOTIFY(_notifyLevel)<<"background hud, str="<<str<<", hud="<<hud<<std::endl;
1560                    constructor.setSlideBackgrondHUD(hud);
1561                }
1562            }
1563            else if (cur->name == "bgcolor")
1564            {
1565                constructor.setBackgroundColor(mapStringToColor(cur->contents),true);
1566            }
1567            else if (cur->name == "textcolor")
1568            {
1569                constructor.setTextColor(mapStringToColor(cur->contents));
1570            }
1571        }
1572        if (parseLayers)
1573        {
1574            if (cur->name == "base")
1575            {
1576                constructor.addLayer(true, true);
1577                parseLayer (constructor, cur);
1578            }
1579            else if (cur->name == "layer")
1580            {
1581                constructor.addLayer(true, false);
1582                parseLayer (constructor, cur);
1583            }
1584            else if (cur->name == "clean_layer")
1585            {
1586                constructor.addLayer(false, false);
1587                parseLayer (constructor, cur);
1588            }
1589            else if (cur->name == "modify_layer")
1590            {
1591                int layerNum;
1592                if (getProperty(cur, "layer", layerNum))
1593                {           
1594                    constructor.selectLayer(layerNum);
1595                }
1596                else
1597                {
1598                    constructor.addLayer(true, false);
1599                }
1600
1601                parseLayer (constructor, cur);
1602            }
1603            else if (cur->name == "bullets")
1604            {
1605                parseBullets (constructor, cur,true, false);
1606            }
1607            else if (cur->name == "duration")
1608            {
1609                constructor.setSlideDuration(osg::asciiToDouble(cur->contents.c_str()));
1610            }
1611            else if (getKeyPosition(cur, keyPosition))
1612            {
1613                constructor.addSlideKey(keyPosition);
1614            }
1615        }
1616    }
1617
1618    constructor.setBackgroundColor(previous_bgcolor,false);
1619    constructor.setTextColor(previous_textcolor);
1620
1621    return;
1622}
1623
1624#include <iostream>
1625
1626
1627struct MyFindFileCallback : public osgDB::FindFileCallback
1628{
1629    virtual std::string findDataFile(const std::string& filename, const osgDB::Options* options, osgDB::CaseSensitivity caseSensitivity)
1630    {
1631        OSG_INFO<<std::endl<<std::endl<<"find file "<<filename<<std::endl;
1632
1633        const osgDB::FilePathList& paths = options ? options->getDatabasePathList() : osgDB::getDataFilePathList();
1634
1635        for(osgDB::FilePathList::const_iterator itr = paths.begin();
1636            itr != paths.end();
1637            ++itr)
1638        {
1639            const std::string& path = *itr;
1640            std::string newpath = osgDB::concatPaths(path, filename);
1641            if (osgDB::containsServerAddress(path))
1642            {
1643                osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("curl");
1644                OSG_INFO<<"  file on server "<<*itr<<", try path "<<newpath<<std::endl;
1645                OSG_INFO<<"  we have curl rw= "<<rw<<std::endl;
1646                if (rw && rw->fileExists(newpath, options))
1647                {
1648                    OSG_INFO<<"  FOUND on server "<<newpath<<std::endl;
1649                    return newpath;
1650                }
1651            }
1652            else
1653            {
1654                if(osgDB::fileExists(newpath))
1655                {
1656                    OSG_INFO<<" FOUND "<<newpath<<std::endl;
1657                    return newpath;
1658                }
1659            }
1660        }
1661
1662        return osgDB::Registry::instance()->findDataFileImplementation(filename, options, caseSensitivity);
1663    }
1664};
1665
1666class MyReadFileCallback : public virtual osgDB::ReadFileCallback
1667{
1668    public:
1669
1670        osgDB::FilePathList _paths;
1671
1672        typedef std::map< std::string, osg::ref_ptr<osg::Object> >  ObjectCache;
1673
1674        enum ObjectType
1675        {
1676            OBJECT,
1677            IMAGE,
1678            HEIGHT_FIELD,
1679            NODE,
1680            SHADER
1681        };
1682
1683        osgDB::ReaderWriter::ReadResult readLocal(ObjectType type, const std::string& filename, const osgDB::Options* options)
1684        {
1685            OSG_INFO<<"Trying local file "<<filename<<std::endl;
1686
1687            switch(type)
1688            {
1689                case(OBJECT): return osgDB::Registry::instance()->readObjectImplementation(filename,options);
1690                case(IMAGE): return osgDB::Registry::instance()->readImageImplementation(filename,options);
1691                case(HEIGHT_FIELD): return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options);
1692                case(NODE): return osgDB::Registry::instance()->readNodeImplementation(filename,options);
1693                case(SHADER): return osgDB::Registry::instance()->readShaderImplementation(filename,options);
1694            }
1695            return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
1696        }
1697
1698       
1699        osgDB::ReaderWriter::ReadResult readFileCache(ObjectType type, const std::string& filename, const osgDB::Options* options)
1700        {
1701
1702            osgDB::FileCache* fileCache = options ? options->getFileCache() : 0;
1703            if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache();
1704            if (!fileCache) return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1705
1706            OSG_INFO<<"Trying fileCache "<<filename<<std::endl;
1707
1708            osgDB::ReaderWriter::ReadResult result;
1709            if (fileCache && fileCache->isFileAppropriateForFileCache(filename))
1710            {
1711                if (fileCache->existsInCache(filename))
1712                {
1713                    switch(type)
1714                    {
1715                        case(OBJECT):
1716                            result = fileCache->readObject(filename, 0);
1717                            break;
1718                        case(IMAGE):
1719                            result = fileCache->readImage(filename, 0);
1720                            break;
1721                        case(HEIGHT_FIELD):
1722                            result = fileCache->readHeightField(filename, 0);
1723                            break;
1724                        case(NODE):
1725                            result = fileCache->readNode(filename,0);
1726                            break;
1727                        case(SHADER):
1728                            result = fileCache->readShader(filename, 0);
1729                            break;
1730                    }
1731
1732                    if (result.success())
1733                    {
1734                        OSG_INFO<<"   File read from FileCache."<<std::endl;
1735                        return result;
1736                    }
1737
1738                    OSG_INFO<<"   File in FileCache, but not successfully read"<<std::endl;
1739                }
1740                else
1741                {
1742                    OSG_INFO<<"   File does not exist in FileCache: "<<fileCache->createCacheFileName(filename)<<std::endl;
1743                }
1744            }
1745
1746            return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1747
1748        }
1749
1750        osgDB::ReaderWriter::ReadResult readServer(ObjectType type, const std::string& filename, const osgDB::Options* options)
1751        {
1752            OSG_INFO<<"Trying server file "<<filename<<std::endl;
1753
1754            osgDB::ReaderWriter::ReadResult result;
1755            osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("curl");
1756            if (!rw) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
1757
1758            switch(type)
1759            {
1760                case(OBJECT):
1761                    result = rw->readObject(filename,options);
1762                    break;
1763                case(IMAGE):
1764                    result = rw->readImage(filename,options);
1765                    break;
1766                case(HEIGHT_FIELD):
1767                    result = rw->readHeightField(filename,options);
1768                    break;
1769                case(NODE):
1770                    result = rw->readNode(filename,options);
1771                    break;
1772                case(SHADER):
1773                    result = rw->readShader(filename,options);
1774                    break;
1775            }
1776
1777            if (result.success())
1778            {
1779                osgDB::FileCache* fileCache = options ? options->getFileCache() : 0;
1780                if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache();
1781
1782                if (fileCache && fileCache->isFileAppropriateForFileCache(filename))
1783                {
1784                    switch(type)
1785                    {
1786                        case(OBJECT):
1787                            fileCache->writeObject(*result.getObject(),filename,options);
1788                            break;
1789                        case(IMAGE):
1790                            result.getImage()->setFileName(filename);
1791                            fileCache->writeImage(*result.getImage(),filename,options);
1792                            break;
1793                        case(HEIGHT_FIELD):
1794                            fileCache->writeHeightField(*result.getHeightField(),filename,options);
1795                            break;
1796                        case(NODE):
1797                            fileCache->writeNode(*result.getNode(),filename,options);
1798                            break;
1799                        case(SHADER):
1800                            fileCache->writeShader(*result.getShader(),filename,options);
1801                            break;
1802                    }
1803                }
1804
1805                return result;
1806            }
1807            return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1808        }
1809
1810
1811        osgDB::ReaderWriter::ReadResult read(const osgDB::FilePathList& filePathList, ObjectType type, const std::string& filename, const osgDB::Options* options, bool checkLocalFiles)
1812        {
1813            // go look in http paths
1814            for(osgDB::FilePathList::const_iterator itr = filePathList.begin();
1815                itr != filePathList.end();
1816                ++itr)
1817            {
1818                const std::string& path = *itr;
1819                std::string newpath = path.empty() ? filename : osgDB::concatPaths(path, filename);
1820                osgDB::ReaderWriter::ReadResult result;
1821                if (osgDB::containsServerAddress(newpath))
1822                {
1823                    if (checkLocalFiles) result = readFileCache(type, newpath, options);
1824                    else result = readServer(type, newpath, options);
1825                }
1826                else if (checkLocalFiles && osgDB::fileExists(newpath))
1827                {
1828                    result = readLocal(type, newpath, options);
1829                }
1830
1831                if (result.success())
1832                {
1833                    OSG_INFO<<"   inserting object into file cache "<<filename<<", "<<result.getObject()<<std::endl;
1834                    _objectCache[filename] = result.getObject();
1835
1836                    options->setPluginStringData("filename",newpath);
1837                    return result;
1838                }
1839            }
1840            return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1841        }
1842
1843        osgDB::ReaderWriter::ReadResult read(ObjectType type, const std::string& filename, const osgDB::Options* options)
1844        {
1845            osgDB::FileCache* fileCache = options ? options->getFileCache() : 0;
1846            if (!fileCache) fileCache = osgDB::Registry::instance()->getFileCache();
1847            if (fileCache && !fileCache->isFileAppropriateForFileCache(filename)) fileCache = 0;
1848
1849            OSG_INFO<<"MyReadFileCallback::reading file "<<filename<<std::endl;
1850            ObjectCache::iterator itr = _objectCache.find(filename);
1851            if (itr != _objectCache.end())
1852            {
1853                // object is in cache, just retrieve it.
1854                if (itr->second.valid())
1855                {
1856                    OSG_INFO<<"File retrieved from cache, filename="<<filename<<std::endl;
1857                    return itr->second.get();
1858                }
1859                else
1860                {
1861                    OSG_INFO<<"File failed to load previously, won't attempt a second time "<<filename<<std::endl;
1862                    return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1863                }
1864            }
1865
1866            OSG_INFO<<"   MyReadFileCallback::reading file A"<<filename<<std::endl;
1867
1868            {
1869                bool checkLocalFiles = true;
1870                osgDB::ReaderWriter::ReadResult result = read(_paths, type, filename, options, checkLocalFiles);
1871                if (result.success()) return result;
1872
1873                if (options && !(options->getDatabasePathList().empty()))
1874                {
1875                    result = read(options->getDatabasePathList(), type, filename, options, checkLocalFiles);
1876                    if (result.success()) return result;
1877                }
1878
1879                result = read(osgDB::Registry::instance()->getDataFilePathList(), type, filename, options, checkLocalFiles);
1880                if (result.success()) return result;
1881            }
1882
1883            OSG_INFO<<"   MyReadFileCallback::reading file B"<<filename<<std::endl;
1884
1885            {
1886                bool checkLocalFiles = false;
1887                osgDB::ReaderWriter::ReadResult result = read(_paths, type, filename, options, checkLocalFiles);
1888                if (result.success()) return result;
1889
1890                if (options && !(options->getDatabasePathList().empty()))
1891                {
1892                    result = read(options->getDatabasePathList(), type, filename, options, checkLocalFiles);
1893                    if (result.success()) return result;
1894                }
1895
1896                result = read(osgDB::Registry::instance()->getDataFilePathList(), type, filename, options, checkLocalFiles);
1897                if (result.success()) return result;
1898            }
1899
1900            OSG_INFO<<"   MyReadFileCallback::reading file C"<<filename<<std::endl;
1901
1902            _objectCache[filename] = 0;
1903
1904            return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
1905        }
1906
1907        virtual osgDB::ReaderWriter::ReadResult readObject(const std::string& filename, const osgDB::Options* options)
1908        {
1909            return read(OBJECT, filename, options);
1910        }
1911
1912        virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& filename, const osgDB::Options* options)
1913        {
1914            return read(IMAGE, filename, options);
1915        }
1916
1917        virtual osgDB::ReaderWriter::ReadResult readHeightField(const std::string& filename, const osgDB::Options* options)
1918        {
1919            return read(HEIGHT_FIELD, filename, options);
1920        }
1921
1922        virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::Options* options)
1923        {
1924            return read(NODE, filename, options);
1925        }
1926
1927        virtual osgDB::ReaderWriter::ReadResult readShader(const std::string& filename, const osgDB::Options* options)
1928        {
1929            return read(SHADER, filename, options);
1930        }
1931
1932    protected:
1933        virtual ~MyReadFileCallback() {}
1934
1935        ObjectCache _objectCache;
1936};
1937
1938osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file,
1939                                                           const osgDB::ReaderWriter::Options* options) const
1940{
1941    OSG_INFO<<"readNode("<<file<<")"<<std::endl;
1942
1943
1944    std::string ext = osgDB::getLowerCaseFileExtension(file);
1945    if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
1946
1947    std::string fileName = file;
1948
1949    std::string fileNameSansExtension = osgDB::getNameLessExtension(fileName);
1950    std::string nestedExtension = osgDB::getFileExtension(fileNameSansExtension);
1951    std::string fileNameSansNestedExtension = osgDB::getNameLessExtension(fileNameSansExtension);
1952
1953    if (nestedExtension=="preview" || nestedExtension=="main")
1954    {
1955        fileName = fileNameSansNestedExtension + "." + ext;
1956        OSG_INFO<<"Removed nested extension "<<nestedExtension<<" result = "<<fileName<<std::endl;
1957    }
1958
1959    fileName = osgDB::findDataFile( fileName, options );
1960    if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
1961
1962    // code for setting up the database path so that internally referenced file are searched for on relative paths.
1963    osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
1964    local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
1965    local_opt->setFindFileCallback(new MyFindFileCallback);
1966    local_opt->setPluginStringData("filename",file);
1967
1968    osgDB::XmlNode::Input input;
1969    input.open(fileName);
1970    input.readAllDataIntoBuffer();
1971
1972    return readNode(input, local_opt.get());
1973}
1974
1975osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin, const Options* options) const
1976{
1977    osgDB::XmlNode::Input input;
1978    input.attach(fin);
1979    input.readAllDataIntoBuffer();
1980
1981    osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
1982    local_opt->setReadFileCallback(new MyReadFileCallback);
1983
1984    return readNode(input, local_opt.get());
1985}
1986
1987osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const
1988{
1989    std::string fileName = options ? options->getPluginStringData("filename") : std::string();
1990    std::string extension = osgDB::getFileExtension(fileName);
1991    std::string fileNameSansExtension = osgDB::getNameLessExtension(fileName);
1992    std::string nestedExtension = osgDB::getFileExtension(fileNameSansExtension);
1993    std::string fileNameSansNestedExtension = osgDB::getFileExtension(fileNameSansExtension);
1994
1995    bool readOnlyHoldingPage = nestedExtension=="preview" || (options && options->getOptionString()=="preview");
1996    bool readOnlyMainPresentation = nestedExtension=="main" || (options && options->getOptionString()=="main");
1997
1998    osg::ref_ptr<osgDB::XmlNode> doc = new osgDB::XmlNode;
1999    osgDB::XmlNode* root = 0;
2000
2001    doc->read(input);
2002
2003    OSG_INFO<<"P3D xml file read, now building presentation scene graph."<<std::endl;
2004
2005#if 0
2006    std::ofstream fout("output.p3d");
2007    doc->write(fout);
2008#endif
2009
2010    if (doc == NULL )
2011    {
2012            fprintf(stderr,"Document not parsed successfully. \n");
2013            return ReadResult::FILE_NOT_HANDLED;
2014    }
2015
2016    for(osgDB::XmlNode::Children::iterator itr = doc->children.begin();
2017        itr != doc->children.end() && !root;
2018        ++itr)
2019    {
2020        if ((*itr)->name=="presentation") root = itr->get();
2021    }
2022
2023    if (root == NULL)
2024    {
2025            fprintf(stderr,"empty document\n");
2026            return ReadResult::FILE_NOT_HANDLED;
2027    }
2028
2029    if (root->name!="presentation")
2030    {
2031            fprintf(stderr,"document of the wrong type, root node != presentation");
2032            return ReadResult::FILE_NOT_HANDLED;
2033    }
2034
2035
2036    bool hasHoldingSlide = false;
2037    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
2038        itr != root->children.end() && !hasHoldingSlide;
2039        ++itr)
2040    {
2041        osgDB::XmlNode* cur = itr->get();
2042        if (cur->name == "holding_slide")
2043        {
2044            hasHoldingSlide = true;
2045        }
2046    }
2047
2048    // if we are looking for a holding slide, but one isn't present return NULL.
2049    if (readOnlyHoldingPage && !hasHoldingSlide) return 0;
2050
2051    OSG_INFO<<"hasHoldingSlide "<<hasHoldingSlide<<std::endl;
2052    OSG_INFO<<"readOnlyHoldingPage "<<readOnlyHoldingPage<<std::endl;
2053    OSG_INFO<<"readOnlyMainPresentation "<<readOnlyMainPresentation<<std::endl;
2054
2055    osg::ref_ptr<osg::Node> presentation_node;
2056
2057
2058    if (!readOnlyHoldingPage && !readOnlyMainPresentation)
2059    {
2060        if (fileName.empty()) hasHoldingSlide = false;
2061
2062        osg::ref_ptr<osg::Node> holdingslide_node = hasHoldingSlide ? parseXmlGraph(root, true, options) : 0;
2063
2064        if (holdingslide_node.valid())
2065        {
2066            double farDistance = 10000.0f;
2067
2068            osg::ref_ptr<osg::PagedLOD> pagedLOD = new osg::PagedLOD;
2069
2070            pagedLOD->setDatabaseOptions(options);
2071
2072            pagedLOD->addChild(holdingslide_node.get());
2073            pagedLOD->setRange(0,farDistance,2.0*farDistance);
2074
2075            std::string fileNameToLoadMainPresentation = fileNameSansExtension + std::string(".main.")+extension;
2076
2077            pagedLOD->setFileName(1,fileNameToLoadMainPresentation);
2078            pagedLOD->setRange(1,0.0,farDistance);
2079
2080            presentation_node = pagedLOD.get();
2081
2082        }
2083        else
2084        {
2085            presentation_node = parseXmlGraph(root, false, options);
2086        }
2087    }
2088    else
2089    {
2090        presentation_node = parseXmlGraph(root, readOnlyHoldingPage, options);
2091    }
2092
2093    if (presentation_node.valid())
2094    {
2095        if (!options || options->getPluginStringData("P3D_EVENTHANDLER")!="none")
2096        {
2097            // if (!readOnlyHoldingPage && !readOnlyMainPresentation)
2098            {
2099                osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler;
2100                seh->set(presentation_node.get());
2101                presentation_node->setEventCallback(seh);
2102            }
2103        }
2104        return presentation_node.release();
2105    }
2106    else
2107    {
2108        return osgDB::ReaderWriter::ReadResult::ERROR_IN_READING_FILE;
2109    }
2110}
2111
2112osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnlyHoldingPage, osgDB::Options* options) const
2113{
2114    osgPresentation::SlideShowConstructor constructor(options);
2115
2116    // create a keyPosition just in case we need it.
2117    osgPresentation::KeyPosition keyPosition;
2118
2119    osgDB::FilePathList previousPaths = osgDB::getDataFilePathList();
2120
2121    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
2122        itr != root->children.end();
2123        ++itr)
2124    {
2125        osgDB::XmlNode* cur = itr->get();
2126
2127        if (cur->name=="env")
2128        {
2129            char* str = strdup(cur->contents.c_str());
2130            OSG_INFO<<"putenv("<<str<<")"<<std::endl;
2131            putenv(str);
2132        }
2133    }
2134
2135    std::string pathToPresentation;
2136    MyReadFileCallback* readFileCallback = options ? dynamic_cast<MyReadFileCallback*>(options->getReadFileCallback()) : 0;
2137
2138    if (options && !(options->getDatabasePathList().empty()))
2139    {
2140        pathToPresentation = options->getDatabasePathList().front();
2141
2142       if (readFileCallback) readFileCallback->_paths.push_front(pathToPresentation);
2143    }
2144
2145
2146    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
2147        itr != root->children.end();
2148        ++itr)
2149    {
2150        osgDB::XmlNode* cur = itr->get();
2151
2152        if (cur->name == "path")
2153        {
2154            std::string newpath = expandEnvVarsInFileName(cur->contents);
2155
2156            // now check if an absolue or http path
2157            std::string::size_type colonPos = newpath.find_first_of(':');
2158            std::string::size_type backslashPos = newpath.find_first_of('/');
2159            std::string::size_type forwardslashPos = newpath.find_first_of('\\');
2160            bool relativePath = colonPos == std::string::npos &&
2161                                backslashPos != 0 &&
2162                                forwardslashPos != 0;
2163
2164            if (relativePath && !pathToPresentation.empty())
2165            {
2166                newpath = osgDB::concatPaths(pathToPresentation, newpath);
2167                OSG_INFO<<"relative path = "<<cur->contents<<", newpath="<<newpath<<std::endl;
2168            }
2169            else
2170            {
2171                OSG_INFO<<"absolute path = "<<cur->contents<<", newpath="<<newpath<<std::endl;
2172            }
2173
2174            if (readFileCallback) readFileCallback->_paths.push_back(newpath);
2175            else options->getDatabasePathList().push_back(newpath);
2176        }
2177    }
2178
2179
2180    for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
2181        itr != root->children.end();
2182        ++itr)
2183    {
2184        osgDB::XmlNode* cur = itr->get();
2185
2186        if (cur->name == "name")
2187        {
2188            constructor.setPresentationName(cur->contents);
2189        }
2190        else if (cur->name == "loop")
2191        {
2192            constructor.setLoopPresentation(true);
2193        }
2194        else if (cur->name == "auto")
2195        {
2196            constructor.setAutoSteppingActive(true);
2197        }
2198        else if (cur->name == "title-settings")
2199        {
2200            bool fontRead = getProperties(cur,constructor.getTitleFontDataDefault());
2201            if (fontRead)
2202            {
2203                OSG_INFO<<"Title font details read"<<std::endl;
2204            }
2205        }
2206        else if (cur->name == "text-settings")
2207        {
2208            bool fontRead = getProperties(cur,constructor.getTextFontDataDefault());
2209            if (fontRead)
2210            {
2211                OSG_INFO<<"Text font details read"<<std::endl;
2212            }
2213        }
2214        /*else if (cur->name == "ratio")
2215        {
2216            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2217            if (key) constructor.setPresentationAspectRatio(cur->contents);
2218            xmlFree(key);
2219        }*/
2220        else if (cur->name == "path")
2221        {
2222            OSG_INFO<<"Appending search path "<<cur->contents<<std::endl;
2223            osgDB::getDataFilePathList().push_front(expandEnvVarsInFileName(cur->contents));
2224        }
2225        else if (cur->name == "bgcolor")
2226        {
2227            constructor.setBackgroundColor(mapStringToColor(cur->contents),false);
2228        }
2229        else if (cur->name == "textcolor")
2230        {
2231            constructor.setTextColor(mapStringToColor(cur->contents));
2232        }
2233        else if (cur->name == "duration")
2234        {
2235            constructor.setPresentationDuration(osg::asciiToDouble(cur->contents.c_str()));
2236        }
2237        else if (getKeyPosition(cur, keyPosition))
2238        {
2239            constructor.addPresentationKey(keyPosition);
2240        }
2241        else if (readOnlyHoldingPage && cur->name == "holding_slide")
2242        {
2243            constructor.addSlide();
2244            parseSlide (constructor, cur);
2245        }
2246        else if (!readOnlyHoldingPage && cur->name == "slide")
2247        {
2248            constructor.addSlide();
2249
2250            std::string inherit;
2251            if (getProperty(cur, "inherit", inherit) && !inherit.empty() && _templateMap.count(inherit)!=0)
2252            {
2253                parseSlide(constructor, _templateMap[inherit].get(), true, false);
2254                parseSlide (constructor, cur, true, false);
2255                parseSlide(constructor, _templateMap[inherit].get(), false, true);
2256                parseSlide (constructor, cur, false, true);
2257            }
2258            else
2259            {
2260                parseSlide (constructor, cur);
2261            }
2262        }
2263        else if (!readOnlyHoldingPage && cur->name == "modify_slide")
2264        {
2265            int slideNum;
2266            if (getProperty(cur, "slide", slideNum))
2267            {           
2268                constructor.selectSlide(slideNum);
2269                parseSlide (constructor, cur);
2270            }
2271            else
2272            {
2273                constructor.addSlide();
2274            }
2275        }
2276        else if (!readOnlyHoldingPage && cur->name == "page")
2277        {
2278            parsePage (constructor, cur);
2279        }
2280        else if (!readOnlyHoldingPage && cur->name == "pdf_document")
2281        {
2282            parsePdfDocument(constructor, cur);
2283        }
2284        else if (!readOnlyHoldingPage && cur->name == "template_slide")
2285        {
2286            std::string name;
2287            if (getProperty(cur, "name", name))
2288            {           
2289                _templateMap[name] = cur;
2290                std::cout<<"Defining template slide "<<name<<std::endl;
2291            }
2292        }
2293    }
2294
2295    osgDB::getDataFilePathList() = previousPaths;
2296   
2297    return constructor.takePresentation();
2298}
Note: See TracBrowser for help on using the browser.