diff --git a/applications/present3D/AnimationMaterial.h b/applications/present3D/AnimationMaterial.h deleted file mode 100644 index 624d10159..000000000 --- a/applications/present3D/AnimationMaterial.h +++ /dev/null @@ -1,170 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#ifndef OSG_ANIMATIONMATERIAL -#define OSG_ANIMATIONMATERIAL 1 - -#include -#include - -#include -#include - -namespace ss3d { - -/** AnimationMaterial for specify the time varying transformation pathway to use when update camera and model objects. - * Subclassed from Transform::ComputeTransformCallback allows AnimationMaterial to - * be attached directly to Transform nodes to move subgraphs around the scene. -*/ -class AnimationMaterial : public virtual osg::Object -{ - public: - - AnimationMaterial():_loopMode(LOOP) {} - - AnimationMaterial(const AnimationMaterial& ap, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - Object(ap,copyop), - _timeControlPointMap(ap._timeControlPointMap), - _loopMode(ap._loopMode) {} - - META_Object(osg,AnimationMaterial); - - - /** get the transformation matrix for a point in time.*/ - bool getMaterial(double time,osg::Material& material) const; - - void insert(double time,osg::Material* material); - - double getFirstTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.begin()->first; else return 0.0;} - double getLastTime() const { if (!_timeControlPointMap.empty()) return _timeControlPointMap.rbegin()->first; else return 0.0;} - double getPeriod() const { return getLastTime()-getFirstTime();} - - enum LoopMode - { - SWING, - LOOP, - NO_LOOPING - }; - - void setLoopMode(LoopMode lm) { _loopMode = lm; } - - LoopMode getLoopMode() const { return _loopMode; } - - - typedef std::map > TimeControlPointMap; - - TimeControlPointMap& getTimeControlPointMap() { return _timeControlPointMap; } - - const TimeControlPointMap& getTimeControlPointMap() const { return _timeControlPointMap; } - - /** read the anumation path from a flat ascii file stream.*/ - void read(std::istream& in); - - /** write the anumation path to a flat ascii file stream.*/ - void write(std::ostream& out) const; - - bool requiresBlending() const; - - protected: - - virtual ~AnimationMaterial() {} - - void interpolate(osg::Material& material, float r, const osg::Material& lhs,const osg::Material& rhs) const; - - TimeControlPointMap _timeControlPointMap; - LoopMode _loopMode; - -}; - - -class AnimationMaterialCallback : public osg::NodeCallback -{ - public: - - AnimationMaterialCallback(): - _timeOffset(0.0), - _timeMultiplier(1.0), - _firstTime(DBL_MAX), - _latestTime(0.0), - _pause(false), - _pauseTime(0.0) {} - - - AnimationMaterialCallback(const AnimationMaterialCallback& apc,const osg::CopyOp& copyop): - osg::NodeCallback(apc,copyop), - _animationMaterial(apc._animationMaterial), - _useInverseMatrix(apc._useInverseMatrix), - _timeOffset(apc._timeOffset), - _timeMultiplier(apc._timeMultiplier), - _firstTime(apc._firstTime), - _latestTime(apc._latestTime), - _pause(apc._pause), - _pauseTime(apc._pauseTime) {} - - - META_Object(osg,AnimationMaterialCallback); - - AnimationMaterialCallback(AnimationMaterial* ap,double timeOffset=0.0f,double timeMultiplier=1.0f): - _animationMaterial(ap), - _useInverseMatrix(false), - _timeOffset(timeOffset), - _timeMultiplier(timeMultiplier), - _firstTime(DBL_MAX), - _latestTime(0.0), - _pause(false), - _pauseTime(0.0) {} - - void setAnimationMaterial(AnimationMaterial* path) { _animationMaterial = path; } - - AnimationMaterial* getAnimationMaterial() { return _animationMaterial.get(); } - - const AnimationMaterial* getAnimationMaterial() const { return _animationMaterial.get(); } - - void setTimeOffset(double offset) { _timeOffset = offset; } - double getTimeOffset() const { return _timeOffset; } - - void setTimeMultiplier(double multiplier) { _timeMultiplier = multiplier; } - double getTimeMultiplier() const { return _timeMultiplier; } - - void reset(); - - void setPause(bool pause); - - /** get the animation time that is used to specify the position along the AnimationMaterial. - * Animation time is computed from the formula ((_latestTime-_firstTime)-_timeOffset)*_timeMultiplier.*/ - double getAnimationTime() const; - - /** implements the callback*/ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - - void update(osg::Node& node); - - public: - - osg::ref_ptr _animationMaterial; - bool _useInverseMatrix; - double _timeOffset; - double _timeMultiplier; - double _firstTime; - double _latestTime; - bool _pause; - double _pauseTime; - - protected: - - ~AnimationMaterialCallback(){} - -}; - -} - -#endif diff --git a/applications/present3D/CMakeLists.txt b/applications/present3D/CMakeLists.txt index 4f0abfd41..6680a1604 100644 --- a/applications/present3D/CMakeLists.txt +++ b/applications/present3D/CMakeLists.txt @@ -1,30 +1,18 @@ SET(TARGET_SRC - AnimationMaterial.cpp Cluster.cpp - CompileSlideCallback.cpp ExportHTML.cpp - PickEventHandler.cpp PointsEventHandler.cpp present3D.cpp - ReaderWriterP3D.cpp - ReaderWriterPaths.cpp ReadShowFile.cpp ShowEventHandler.cpp - SlideEventHandler.cpp - SlideShowConstructor.cpp ) SET(TARGET_H - AnimationMaterial.h Cluster.h - CompileSlideCallback.h ExportHTML.h - PickEventHandler.h PointsEventHandler.h ReadShowFile.h ShowEventHandler.h - SlideEventHandler.h - SlideShowConstructor.h ) IF (SDL_FOUND) @@ -52,7 +40,7 @@ IF (SDL_FOUND) ENDIF() -SET(TARGET_ADDED_LIBRARIES osgVolume osgFX) +SET(TARGET_ADDED_LIBRARIES osgVolume osgFX osgPresentation) IF (NOT DYNAMIC_OPENSCENEGRAPH) SET(TARGET_ADDED_LIBRARIES diff --git a/applications/present3D/CompileSlideCallback.cpp b/applications/present3D/CompileSlideCallback.cpp deleted file mode 100644 index fa19d89d3..000000000 --- a/applications/present3D/CompileSlideCallback.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#include "CompileSlideCallback.h" - -#include - -using namespace ss3d; - -void CompileSlideCallback::operator()(const osg::Camera & camera) const -{ - osg::GraphicsContext* context = const_cast(camera.getGraphicsContext()); - if (!context) return; - - osg::State* state = context->getState(); - if (!state) return; - - const osg::FrameStamp* fs = state->getFrameStamp(); - if (!fs) return; - - if (_needCompile) - { - _frameNumber = fs->getFrameNumber(); - _needCompile = false; - } - - if (_frameNumber!=fs->getFrameNumber()) return; - - osgUtil::GLObjectsVisitor globjVisitor(osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS| - osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES); - - globjVisitor.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); - - globjVisitor.setNodeMaskOverride(0xffffffff); - - globjVisitor.setState(state); - - _sceneToCompile->accept(globjVisitor); -} diff --git a/applications/present3D/CompileSlideCallback.h b/applications/present3D/CompileSlideCallback.h deleted file mode 100644 index 9b72ef7a0..000000000 --- a/applications/present3D/CompileSlideCallback.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#ifndef OSG_COMPILESLIDECALLBACK -#define OSG_COMPILESLIDECALLBACK 1 - -#include - -namespace ss3d { - -class CompileSlideCallback : public osg::Camera::DrawCallback -{ - public: - - CompileSlideCallback(): - _needCompile(false), - _frameNumber(0) {} - - virtual void operator()(const osg::Camera& camera) const; - - void needCompile(osg::Node* node) { _needCompile=true; _sceneToCompile = node; } - - protected: - - virtual ~CompileSlideCallback() {} - - mutable bool _needCompile; - mutable int _frameNumber; - osg::ref_ptr _sceneToCompile; - -}; - -} - -#endif diff --git a/applications/present3D/ExportHTML.h b/applications/present3D/ExportHTML.h index da25d7627..df17cfd67 100644 --- a/applications/present3D/ExportHTML.h +++ b/applications/present3D/ExportHTML.h @@ -13,7 +13,7 @@ #ifndef EXPORTHTML_H #define EXPORTHTML_H 1 -#include "SlideEventHandler.h" +#include #include class ExportHTML diff --git a/applications/present3D/PickEventHandler.cpp b/applications/present3D/PickEventHandler.cpp deleted file mode 100644 index 5bf8b9a42..000000000 --- a/applications/present3D/PickEventHandler.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#include "PickEventHandler.h" -#include "SlideEventHandler.h" - -#include -#include -#include - -using namespace osgPresentation; - -PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): - _operation(operation), - _relativeJump(relativeJump), - _slideNum(slideNum), - _layerNum(layerNum) -{ -} - -PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): - _command(str), - _operation(operation), - _relativeJump(relativeJump), - _slideNum(slideNum), - _layerNum(layerNum) -{ -} - -PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): - _keyPos(keyPos), - _operation(osgPresentation::EVENT), - _relativeJump(relativeJump), - _slideNum(slideNum), - _layerNum(layerNum) -{ -} - - -bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) -{ - switch(ea.getEventType()) - { - case(osgGA::GUIEventAdapter::MOVE): - case(osgGA::GUIEventAdapter::PUSH): - case(osgGA::GUIEventAdapter::RELEASE): - { - osgViewer::Viewer* viewer = dynamic_cast(&aa); - osgUtil::LineSegmentIntersector::Intersections intersections; - if (viewer->computeIntersections(ea.getX(),ea.getY(), nv->getNodePath(), intersections)) - { - for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin(); - hitr!=intersections.end(); - ++hitr) - { - if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE) - { - osg::notify(osg::INFO)<<"Tooltip..."<className()<dispatchEvent(_keyPos); - break; - } - case(osgPresentation::JUMP): - { - osg::notify(osg::NOTICE)<<"Requires jump "<getActiveSlide(); - int previousLayer = SlideEventHandler::instance()->getActiveLayer(); - int newSlide = previousSlide + _slideNum; - int newLayer = previousLayer + _layerNum; - if (newLayer<0) - { - newLayer = 0; - } - - osg::notify(osg::NOTICE)<<" jump to "<selectSlide(newSlide, newLayer); - } - else - { - SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum); - } - } - else - { - osg::notify(osg::NOTICE)<<"No jump required."< + #include #include #include @@ -160,6 +162,20 @@ bool p3d::readEnvVars(const std::string& fileName) return readVars; } +osgDB::Options* createOptions(const osgDB::ReaderWriter::Options* options) +{ + osg::ref_ptr local_options = options ? options->cloneOptions() : 0; + if (!local_options) + { + local_options = osgDB::Registry::instance()->getOptions() ? + osgDB::Registry::instance()->getOptions()->cloneOptions() : + new osgDB::Options; + } + + local_options->setPluginStringData("P3D_EVENTHANDLER","none"); + return local_options.release(); +} + osg::Node* p3d::readHoldingSlide(const std::string& filename) { std::string ext = osgDB::getFileExtension(filename); @@ -169,10 +185,9 @@ osg::Node* p3d::readHoldingSlide(const std::string& filename) osg::ref_ptr options = new osgDB::ReaderWriter::Options; options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE); options->setOptionString("holding_slide"); + options->setPluginStringData("P3D_EVENTHANDLER","none"); - osgDB::ReaderWriter::ReadResult readResult = osgDB::Registry::instance()->readNode(filename, options.get()); - if (readResult.validNode()) return readResult.takeNode(); - else return 0; + return osgDB::readNodeFile(filename, options.get()); } osg::Node* p3d::readPresentation(const std::string& filename,const osgDB::ReaderWriter::Options* options) @@ -180,11 +195,14 @@ osg::Node* p3d::readPresentation(const std::string& filename,const osgDB::Reader std::string ext = osgDB::getFileExtension(filename); if (!osgDB::equalCaseInsensitive(ext,"xml") && !osgDB::equalCaseInsensitive(ext,"p3d")) return 0; - return osgDB::readNodeFile(filename, options); + + osg::ref_ptr local_options = createOptions(options); + return osgDB::readNodeFile(filename, local_options.get()); } osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::ReaderWriter::Options* options) { + osg::ref_ptr local_options = createOptions(options); typedef std::vector< osg::ref_ptr > NodeList; NodeList nodeList; @@ -192,13 +210,13 @@ osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::Reader std::string filename; while (arguments.read("--image",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), options); + osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image.get())); } while (arguments.read("--movie",filename)) { - osg::ref_ptr image = readImageFile(filename.c_str(), options); + osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); osg::ref_ptr imageStream = dynamic_cast(image.get()); if (image.valid()) { @@ -209,7 +227,7 @@ osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::Reader while (arguments.read("--dem",filename)) { - osg::HeightField* hf = readHeightFieldFile(filename.c_str(), options); + osg::HeightField* hf = readHeightFieldFile(filename.c_str(), local_options.get()); if (hf) { osg::Geode* geode = new osg::Geode; @@ -224,14 +242,13 @@ osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::Reader if (!arguments.isOption(pos)) { // not an option so assume string is a filename. - osg::Node *node = osgDB::readNodeFile( arguments[pos], options); + osg::Node *node = osgDB::readNodeFile( arguments[pos], local_options); if(node) { if (node->getName().empty()) node->setName( arguments[pos] ); nodeList.push_back(node); } - } } diff --git a/applications/present3D/ReaderWriterP3D.cpp b/applications/present3D/ReaderWriterP3D.cpp index fde58a5cd..2bb8c35f6 100644 --- a/applications/present3D/ReaderWriterP3D.cpp +++ b/applications/present3D/ReaderWriterP3D.cpp @@ -20,7 +20,7 @@ #include -#include "SlideShowConstructor.h" +#include #include #include diff --git a/applications/present3D/ReaderWriterPaths.cpp b/applications/present3D/ReaderWriterPaths.cpp index 5984274df..a50aa55af 100644 --- a/applications/present3D/ReaderWriterPaths.cpp +++ b/applications/present3D/ReaderWriterPaths.cpp @@ -20,8 +20,8 @@ #include -#include "SlideShowConstructor.h" -#include "AnimationMaterial.h" +#include +#include #include #include diff --git a/applications/present3D/SlideEventHandler.h b/applications/present3D/SlideEventHandler.h deleted file mode 100644 index 6db0a5059..000000000 --- a/applications/present3D/SlideEventHandler.h +++ /dev/null @@ -1,330 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#ifndef SLIDEEVENTHANDLER -#define SLIDEEVENTHANDLER 1 - -#include -#include - -#include -#include - -#include "CompileSlideCallback.h" - -namespace osgPresentation -{ - -/// Operations related to click to run/load/key events. -enum Operation -{ - RUN, - LOAD, - EVENT, - JUMP -}; - -struct HomePosition : public virtual osg::Referenced -{ - HomePosition() {} - - HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up): - eye(in_eye), - center(in_center), - up(in_up) {} - - osg::Vec3 eye; - osg::Vec3 center; - osg::Vec3 up; -}; - -struct KeyPosition -{ - KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX): - _key((osgGA::GUIEventAdapter::KeySymbol)key), - _x(x), - _y(y) {} - - - void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX) - { - _key = (osgGA::GUIEventAdapter::KeySymbol)key; - _x = x; - _y = y; - } - - osgGA::GUIEventAdapter::KeySymbol _key; - float _x; - float _y; -}; - -struct LayerCallback : public virtual osg::Referenced -{ - virtual void operator() (osg::Node* node) const = 0; -}; - -struct LayerAttributes : public virtual osg::Referenced -{ - LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {} - LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {} - - void setDuration(double duration) { _duration = duration; } - double getDuration() const { return _duration; } - - typedef std::vector Keys; - typedef std::vector RunStrings; - - void setKeys(const Keys& keys) { _keys = keys; } - const Keys& getKeys() const { return _keys; } - - void addKey(const KeyPosition& kp) { _keys.push_back(kp); } - - void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; } - const RunStrings& getRunStrings() const { return _runStrings; } - - void addRunString(const std::string& runString) { _runStrings.push_back(runString); } - - void setJump(bool relativeJump, int slideNum, int layerNum) - { - _relativeJump = relativeJump; - _slideNum = slideNum; - _layerNum = layerNum; - } - - bool getRelativeJump() const { return _relativeJump; } - int getSlideNum() const { return _slideNum; } - int getLayerNum() const { return _layerNum; } - - bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; } - - double _duration; - Keys _keys; - RunStrings _runStrings; - - bool _relativeJump; - int _slideNum; - int _layerNum; - - void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); } - void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); } - - void callEnterCallbacks(osg::Node* node); - void callLeaveCallbacks(osg::Node* node); - - typedef std::list< osg::ref_ptr > LayerCallbacks; - LayerCallbacks _enterLayerCallbacks; - LayerCallbacks _leaveLayerCallbacks; -}; - -struct FilePathData : public virtual osg::Referenced -{ - FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {} - - osgDB::FilePathList filePathList; -}; - - -struct dereference_less -{ - template - inline bool operator() (const T& lhs,const U& rhs) const - { - return *lhs < *rhs; - } -}; - -struct ObjectOperator : public osg::Referenced -{ - inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); } - - virtual void* ptr() const = 0; - - virtual void enter() = 0; - virtual void maintain() = 0; - virtual void leave() = 0; - virtual void setPause(bool pause) = 0; - virtual void reset() = 0; - - virtual ~ObjectOperator() {} -}; - -class ActiveOperators -{ -public: - ActiveOperators(); - ~ActiveOperators(); - - void collect(osg::Node* incommingNode, osg::NodeVisitor::TraversalMode tm = osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); - - void process(); - - void setPause(bool pause); - bool getPause() const { return _pause; } - - void reset(); - - typedef std::set< osg::ref_ptr, dereference_less > OperatorList; - -protected: - - void processOutgoing(); - void processIncomming(); - void processMaintained(); - - bool _pause; - - OperatorList _previous; - OperatorList _current; - - OperatorList _outgoing; - OperatorList _incomming; - OperatorList _maintained; - -}; - -class SlideEventHandler : public osgGA::GUIEventHandler -{ -public: - - SlideEventHandler(osgViewer::Viewer* viewer=0); - - static SlideEventHandler* instance(); - - META_Object(osgslideshowApp,SlideEventHandler); - - void set(osg::Node* model); - - virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); } - - /** Event traversal node callback method.*/ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); - - virtual void getUsage(osg::ApplicationUsage& usage) const; - - osgViewer::Viewer* getViewer() { return _viewer.get(); } - - enum WhichPosition - { - FIRST_POSITION = 0, - LAST_POSITION = -1 - }; - - void compileSlide(unsigned int slideNum); - void releaseSlide(unsigned int slideNum); - - unsigned int getNumSlides(); - - int getActiveSlide() const { return _activeSlide; } - int getActiveLayer() const { return _activeLayer; } - - bool selectSlide(int slideNum,int layerNum=FIRST_POSITION); - bool selectLayer(int layerNum); - - bool nextLayerOrSlide(); - bool previousLayerOrSlide(); - - bool nextSlide(); - bool previousSlide(); - - bool nextLayer(); - bool previousLayer(); - - bool home(); - - void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; } - bool getAutoSteppingActive() const { return _autoSteppingActive; } - - void setTimeDelayBetweenSlides(double dt) { _timePerSlide = dt; } - double getTimeDelayBetweenSlides() const { return _timePerSlide; } - - double getDuration(const osg::Node* node) const; - - double getCurrentTimeDelayBetweenSlides() const; - - void setReleaseAndCompileOnEachNewSlide(bool flag) { _releaseAndCompileOnEachNewSlide = flag; } - bool getReleaseAndCompileOnEachNewSlide() const { return _releaseAndCompileOnEachNewSlide; } - - void setTimeDelayOnNewSlideWithMovies(float t) { _timeDelayOnNewSlideWithMovies = t; } - float getTimeDelayOnNewSlideWithMovies() const { return _timeDelayOnNewSlideWithMovies; } - - void setLoopPresentation(bool loop) { _loopPresentation = loop; } - bool getLoopPresentation() const { return _loopPresentation; } - - void dispatchEvent(const KeyPosition& keyPosition); - - enum ObjectMask - { - MOVIE = 1<<0, - OBJECTS = 1<<1, - ALL_OBJECTS = MOVIE | OBJECTS - }; - -protected: - - ~SlideEventHandler() {} - SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {} - - bool home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa); - - void updateAlpha(bool, bool, float x, float y); - void updateLight(float x, float y); - - - osg::observer_ptr _viewer; - - osg::observer_ptr _showSwitch; - int _activePresentation; - - osg::observer_ptr _presentationSwitch; - int _activeSlide; - - osg::observer_ptr _slideSwitch; - int _activeLayer; - - bool _firstTraversal; - double _previousTime; - double _timePerSlide; - bool _autoSteppingActive; - bool _loopPresentation; - bool _pause; - bool _hold; - - bool _updateLightActive; - bool _updateOpacityActive; - float _previousX, _previousY; - - bool _cursorOn; - - bool _releaseAndCompileOnEachNewSlide; - - bool _firstSlideOrLayerChange; - osg::Timer_t _tickAtFirstSlideOrLayerChange; - osg::Timer_t _tickAtLastSlideOrLayerChange; - - float _timeDelayOnNewSlideWithMovies; - - double _minimumTimeBetweenKeyPresses; - double _timeLastKeyPresses; - - ActiveOperators _activeOperators; - - osg::ref_ptr _compileSlideCallback; - - void updateOperators(); - -}; - -} - -#endif diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index b4d6e5c12..fd1daa149 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -36,10 +36,11 @@ #include #include +#include +#include + #include "ReadShowFile.h" -#include "SlideEventHandler.h" #include "PointsEventHandler.h" -#include "SlideShowConstructor.h" #include "Cluster.h" #include "ExportHTML.h" @@ -346,6 +347,7 @@ int main( int argc, char **argv ) bool loopPresentation = false; while (arguments.read("--loop")) loopPresentation = true; + // register the slide event handler - which moves the presentation from slide to slide, layer to layer. osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler(&viewer); viewer.addEventHandler(seh); diff --git a/include/osgDB/Options b/include/osgDB/Options index 5d2aae5d8..4effb1d6a 100644 --- a/include/osgDB/Options +++ b/include/osgDB/Options @@ -84,6 +84,8 @@ class OSGDB_EXPORT Options : public osg::Object META_Object(osgDB,Options); + Options* cloneOptions() const { return new Options(*this); } + /** Set the general Options string.*/ void setOptionString(const std::string& str) { _str = str; } diff --git a/src/osgPlugins/p3d/AnimationMaterial.h b/include/osgPresentation/AnimationMaterial similarity index 97% rename from src/osgPlugins/p3d/AnimationMaterial.h rename to include/osgPresentation/AnimationMaterial index 624d10159..b7b74301d 100644 --- a/src/osgPlugins/p3d/AnimationMaterial.h +++ b/include/osgPresentation/AnimationMaterial @@ -16,16 +16,18 @@ #include #include +#include + #include #include -namespace ss3d { +namespace osgPresentation { /** AnimationMaterial for specify the time varying transformation pathway to use when update camera and model objects. * Subclassed from Transform::ComputeTransformCallback allows AnimationMaterial to * be attached directly to Transform nodes to move subgraphs around the scene. */ -class AnimationMaterial : public virtual osg::Object +class OSGPRESENTATION_EXPORT AnimationMaterial : public virtual osg::Object { public: diff --git a/src/osgPlugins/p3d/CompileSlideCallback.h b/include/osgPresentation/CompileSlideCallback similarity index 88% rename from src/osgPlugins/p3d/CompileSlideCallback.h rename to include/osgPresentation/CompileSlideCallback index 9b72ef7a0..b2eb53c58 100644 --- a/src/osgPlugins/p3d/CompileSlideCallback.h +++ b/include/osgPresentation/CompileSlideCallback @@ -14,10 +14,11 @@ #define OSG_COMPILESLIDECALLBACK 1 #include +#include -namespace ss3d { +namespace osgPresentation { -class CompileSlideCallback : public osg::Camera::DrawCallback +class OSGPRESENTATION_EXPORT CompileSlideCallback : public osg::Camera::DrawCallback { public: diff --git a/applications/present3D/PickEventHandler.h b/include/osgPresentation/PickEventHandler similarity index 95% rename from applications/present3D/PickEventHandler.h rename to include/osgPresentation/PickEventHandler index 94365683c..028ab9ee2 100644 --- a/applications/present3D/PickEventHandler.h +++ b/include/osgPresentation/PickEventHandler @@ -18,12 +18,12 @@ #include -#include "SlideEventHandler.h" +#include namespace osgPresentation { -class PickEventHandler : public osgGA::GUIEventHandler +class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler { public: diff --git a/src/osgPlugins/p3d/SlideEventHandler.h b/include/osgPresentation/SlideEventHandler similarity index 96% rename from src/osgPlugins/p3d/SlideEventHandler.h rename to include/osgPresentation/SlideEventHandler index 6db0a5059..d02d61eb0 100644 --- a/src/osgPlugins/p3d/SlideEventHandler.h +++ b/include/osgPresentation/SlideEventHandler @@ -19,7 +19,7 @@ #include #include -#include "CompileSlideCallback.h" +#include namespace osgPresentation { @@ -72,7 +72,7 @@ struct LayerCallback : public virtual osg::Referenced virtual void operator() (osg::Node* node) const = 0; }; -struct LayerAttributes : public virtual osg::Referenced +struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced { LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {} LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {} @@ -157,7 +157,7 @@ struct ObjectOperator : public osg::Referenced virtual ~ObjectOperator() {} }; -class ActiveOperators +class OSGPRESENTATION_EXPORT ActiveOperators { public: ActiveOperators(); @@ -191,7 +191,7 @@ protected: }; -class SlideEventHandler : public osgGA::GUIEventHandler +class OSGPRESENTATION_EXPORT SlideEventHandler : public osgGA::GUIEventHandler { public: @@ -319,7 +319,7 @@ protected: ActiveOperators _activeOperators; - osg::ref_ptr _compileSlideCallback; + osg::ref_ptr _compileSlideCallback; void updateOperators(); diff --git a/applications/present3D/SlideShowConstructor.h b/include/osgPresentation/SlideShowConstructor similarity index 98% rename from applications/present3D/SlideShowConstructor.h rename to include/osgPresentation/SlideShowConstructor index 5d494a11a..6bc79faaa 100644 --- a/applications/present3D/SlideShowConstructor.h +++ b/include/osgPresentation/SlideShowConstructor @@ -25,13 +25,13 @@ #include -#include "AnimationMaterial.h" -#include "SlideEventHandler.h" +#include +#include namespace osgPresentation { -class SlideShowConstructor +class OSGPRESENTATION_EXPORT SlideShowConstructor { public: @@ -128,7 +128,7 @@ public: path_loop_mode(osg::AnimationPath::NO_LOOPING), animation_material_time_offset(0.0), animation_material_time_multiplier(1.0), - animation_material_loop_mode(ss3d::AnimationMaterial::NO_LOOPING) {} + animation_material_loop_mode(AnimationMaterial::NO_LOOPING) {} bool requiresPosition() const { @@ -169,7 +169,7 @@ public: std::string path; double animation_material_time_offset; double animation_material_time_multiplier; - ss3d::AnimationMaterial::LoopMode animation_material_loop_mode; + AnimationMaterial::LoopMode animation_material_loop_mode; std::string animation_material_filename; std::string fade; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 302847644..7a51f85e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ FOREACH( mylibfolder osgFX osgManipulator osgParticle + osgPresentation osgShadow osgSim osgTerrain diff --git a/src/osgPlugins/p3d/AnimationMaterial.cpp b/src/osgPlugins/p3d/AnimationMaterial.cpp deleted file mode 100644 index 1f9a65f3c..000000000 --- a/src/osgPlugins/p3d/AnimationMaterial.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#include "AnimationMaterial.h" -#include -#include -#include -#include - -using namespace ss3d; - -void AnimationMaterial::insert(double time,osg::Material* material) -{ - _timeControlPointMap[time] = material; -} - -bool AnimationMaterial::getMaterial(double time,osg::Material& material) const -{ - if (_timeControlPointMap.empty()) return false; - - switch(_loopMode) - { - case(SWING): - { - double modulated_time = (time - getFirstTime())/(getPeriod()*2.0); - double fraction_part = modulated_time - floor(modulated_time); - if (fraction_part>0.5) fraction_part = 1.0-fraction_part; - - time = getFirstTime()+(fraction_part*2.0) * getPeriod(); - break; - } - case(LOOP): - { - double modulated_time = (time - getFirstTime())/getPeriod(); - double fraction_part = modulated_time - floor(modulated_time); - time = getFirstTime()+fraction_part * getPeriod(); - break; - } - case(NO_LOOPING): - // no need to modulate the time. - break; - } - - - - TimeControlPointMap::const_iterator second = _timeControlPointMap.lower_bound(time); - if (second==_timeControlPointMap.begin()) - { - material = *(second->second); - } - else if (second!=_timeControlPointMap.end()) - { - TimeControlPointMap::const_iterator first = second; - --first; - - // we have both a lower bound and the next item. - - // deta_time = second.time - first.time - double delta_time = second->first - first->first; - - if (delta_time==0.0) - material = *(first->second); - else - { - interpolate(material,(time - first->first)/delta_time, *first->second, *second->second); - } - } - else // (second==_timeControlPointMap.end()) - { - material = *(_timeControlPointMap.rbegin()->second); - } - return true; -} - -template -T interp(float r, const T& lhs, const T& rhs) -{ - return lhs*(1.0f-r)+rhs*r; -} - - -void AnimationMaterial::interpolate(osg::Material& material, float r, const osg::Material& lhs,const osg::Material& rhs) const -{ - material.setColorMode(lhs.getColorMode()); - - material.setAmbient(osg::Material::FRONT_AND_BACK,interp(r, lhs.getAmbient(osg::Material::FRONT),rhs.getAmbient(osg::Material::FRONT))); - if (!material.getAmbientFrontAndBack()) - material.setAmbient(osg::Material::BACK,interp(r, lhs.getAmbient(osg::Material::BACK),rhs.getAmbient(osg::Material::BACK))); - - material.setDiffuse(osg::Material::FRONT_AND_BACK,interp(r, lhs.getDiffuse(osg::Material::FRONT),rhs.getDiffuse(osg::Material::FRONT))); - if (!material.getDiffuseFrontAndBack()) - material.setDiffuse(osg::Material::BACK,interp(r, lhs.getDiffuse(osg::Material::BACK),rhs.getDiffuse(osg::Material::BACK))); - - material.setSpecular(osg::Material::FRONT_AND_BACK,interp(r, lhs.getSpecular(osg::Material::FRONT),rhs.getSpecular(osg::Material::FRONT))); - if (!material.getSpecularFrontAndBack()) - material.setSpecular(osg::Material::BACK,interp(r, lhs.getSpecular(osg::Material::BACK),rhs.getSpecular(osg::Material::BACK))); - - material.setEmission(osg::Material::FRONT_AND_BACK,interp(r, lhs.getEmission(osg::Material::FRONT),rhs.getEmission(osg::Material::FRONT))); - if (!material.getEmissionFrontAndBack()) - material.setEmission(osg::Material::BACK,interp(r, lhs.getEmission(osg::Material::BACK),rhs.getEmission(osg::Material::BACK))); - - material.setShininess(osg::Material::FRONT_AND_BACK,interp(r, lhs.getShininess(osg::Material::FRONT),rhs.getShininess(osg::Material::FRONT))); - if (!material.getShininessFrontAndBack()) - material.setShininess(osg::Material::BACK,interp(r, lhs.getShininess(osg::Material::BACK),rhs.getShininess(osg::Material::BACK))); -} - -void AnimationMaterial::read(std::istream& in) -{ - while (!in.eof()) - { - double time; - osg::Vec4 color; - in >> time >> color[0] >> color[1] >> color[2] >> color[3]; - if(!in.eof()) - { - osg::Material* material = new osg::Material; - material->setAmbient(osg::Material::FRONT_AND_BACK,color); - material->setDiffuse(osg::Material::FRONT_AND_BACK,color); - insert(time,material); - } - } -} - -void AnimationMaterial::write(std::ostream& fout) const -{ - const TimeControlPointMap& tcpm = getTimeControlPointMap(); - for(TimeControlPointMap::const_iterator tcpmitr=tcpm.begin(); - tcpmitr!=tcpm.end(); - ++tcpmitr) - { - fout<first<<" "<second->getDiffuse(osg::Material::FRONT)<second->getDiffuse(osg::Material::FRONT))[3]!=1.0f) return true; - } - return false; -} - - -void AnimationMaterialCallback::operator()(osg::Node* node, osg::NodeVisitor* nv) -{ - if (_animationMaterial.valid() && - nv->getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR && - nv->getFrameStamp()) - { - double time = nv->getFrameStamp()->getReferenceTime(); - _latestTime = time; - - if (!_pause) - { - // Only update _firstTime the first time, when its value is still DBL_MAX - if (_firstTime==DBL_MAX) - { - osg::notify(osg::INFO)<<"AnimationMaterialCallback::operator() resetting _firstTime to "<(stateset->getAttribute(osg::StateAttribute::MATERIAL)); - - if (!material) - { - material = new osg::Material; - stateset->setAttribute(material,osg::StateAttribute::OVERRIDE); - } - - _animationMaterial->getMaterial(getAnimationTime(),*material); -} - - -void AnimationMaterialCallback::reset() -{ -#if 1 - _firstTime = DBL_MAX; - _pauseTime = DBL_MAX; -#else - _firstTime = _latestTime; - _pauseTime = _latestTime; -#endif -} - -void AnimationMaterialCallback::setPause(bool pause) -{ - if (_pause==pause) - { - return; - } - - _pause = pause; - - if (_firstTime==DBL_MAX) return; - - if (_pause) - { - _pauseTime = _latestTime; - } - else - { - _firstTime += (_latestTime-_pauseTime); - } -} diff --git a/src/osgPlugins/p3d/CMakeLists.txt b/src/osgPlugins/p3d/CMakeLists.txt index ccaee008f..e5cc9bdeb 100644 --- a/src/osgPlugins/p3d/CMakeLists.txt +++ b/src/osgPlugins/p3d/CMakeLists.txt @@ -1,21 +1,9 @@ SET(TARGET_SRC - SlideShowConstructor.cpp ReaderWriterP3D.cpp ReaderWriterPaths.cpp - PickEventHandler.cpp - AnimationMaterial.cpp - SlideEventHandler.cpp - CompileSlideCallback.cpp -) -SET(TARGET_H - SlideShowConstructor.h - PickEventHandler.h - AnimationMaterial.h - SlideEventHandler.h - CompileSlideCallback.h ) -SET(TARGET_ADDED_LIBRARIES osgGA osgText osgVolume osgFX osgViewer) +SET(TARGET_ADDED_LIBRARIES osgGA osgText osgVolume osgFX osgViewer osgPresentation) #### end var setup ### SETUP_PLUGIN(p3d) diff --git a/src/osgPlugins/p3d/PickEventHandler.h b/src/osgPlugins/p3d/PickEventHandler.h deleted file mode 100644 index 94365683c..000000000 --- a/src/osgPlugins/p3d/PickEventHandler.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#ifndef PICKEVENTHANDLER -#define PICKEVENTHANDLER 1 - -#include -#include - -#include - -#include "SlideEventHandler.h" - -namespace osgPresentation -{ - -class PickEventHandler : public osgGA::GUIEventHandler -{ - public: - - PickEventHandler(osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - PickEventHandler(const std::string& str, osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - PickEventHandler(const osgPresentation::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); - - void setOperation(osgPresentation::Operation operation) { _operation = operation; } - osgPresentation::Operation getOperation() const { return _operation; } - - void setCommand(const std::string& str) { _command = str; } - const std::string& getCommand() const { return _command; } - - void setKeyPosition(const osgPresentation::KeyPosition& keyPos) { _keyPos = keyPos; } - const osgPresentation::KeyPosition& getKeyPosition() const { return _keyPos; } - - void setRelativeJump(int slideDelta, int layerDelta); - void setAbsoluteJump(int slideNum, int layerNum); - - bool getRelativeJump() const { return _relativeJump; } - int getSlideNum() const { return _slideNum; } - int getLayerNum() const { return _layerNum; } - - bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; } - - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); - - virtual void accept(osgGA::GUIEventHandlerVisitor& v); - - virtual void getUsage(osg::ApplicationUsage& usage) const; - - void doOperation(); - - std::string _command; - osgPresentation::KeyPosition _keyPos; - osgPresentation::Operation _operation; - - bool _relativeJump; - int _slideNum; - int _layerNum; -}; - -} - -#endif diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 498762a92..8c69e6d21 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -20,7 +20,7 @@ #include -#include "SlideShowConstructor.h" +#include #include #include @@ -647,9 +647,9 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid if (getProperty(cur, "animation_material_loop_mode", str)) { osg::notify(_notifyLevel)<<"animation_material_loop_mode "<read(input); - - osg::notify(osg::NOTICE)<<"P3D parsing"<write(std::cout); @@ -1964,10 +1963,13 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp osg::ref_ptr presentation_node = constructor.takePresentation(); - osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler; - seh->set(presentation_node.get()); - presentation_node->setEventCallback(seh); + if (!options || options->getPluginStringData("P3D_EVENTHANDLER")!="none") + { + osgPresentation::SlideEventHandler* seh = new osgPresentation::SlideEventHandler; + seh->set(presentation_node.get()); + presentation_node->setEventCallback(seh); + } return presentation_node.release(); } diff --git a/src/osgPlugins/p3d/ReaderWriterPaths.cpp b/src/osgPlugins/p3d/ReaderWriterPaths.cpp index 4888aab95..1234b2daa 100644 --- a/src/osgPlugins/p3d/ReaderWriterPaths.cpp +++ b/src/osgPlugins/p3d/ReaderWriterPaths.cpp @@ -20,8 +20,8 @@ #include -#include "SlideShowConstructor.h" -#include "AnimationMaterial.h" +#include +#include #include #include @@ -125,7 +125,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterPaths::readObject(std::istream& fin, osgDB::ReaderWriter::ReadResult ReaderWriterPaths::read_material(std::istream& fin, const osgDB::Options* options) const { - osg::ref_ptr animationMaterial = new ss3d::AnimationMaterial; + osg::ref_ptr animationMaterial = new osgPresentation::AnimationMaterial; animationMaterial->read(fin); return animationMaterial.get(); diff --git a/src/osgPlugins/p3d/SlideEventHandler.cpp b/src/osgPlugins/p3d/SlideEventHandler.cpp deleted file mode 100644 index 949cae77c..000000000 --- a/src/osgPlugins/p3d/SlideEventHandler.cpp +++ /dev/null @@ -1,1350 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#include "SlideEventHandler.h" -#include "SlideShowConstructor.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "AnimationMaterial.h" - -#include - -using namespace osgPresentation; - -static osg::observer_ptr s_seh; - -SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); } - -void LayerAttributes::callEnterCallbacks(osg::Node* node) -{ - osg::notify(osg::INFO)<<"LayerAttributes::callEnterCallbacks("<rewind() + play"<pause()"<pause(); - } - - virtual void setPause(bool pause) - { - osg::notify(osg::INFO)<<"_imageStream->setPause("<pause(); - else _imageStream->play(); - } - - virtual void reset() - { - osg::ImageStream::StreamStatus previousStatus = _imageStream->getStatus(); - - _imageStream->rewind(); - - - //_imageStream->setVolume(previousVolume); - - if(previousStatus==osg::ImageStream::PLAYING) - { - _imageStream->play(); - } - - // add a delay so that movie thread has a chance to do the rewind - float microSecondsToDelay = SlideEventHandler::instance()->getTimeDelayOnNewSlideWithMovies() * 1000000.0f; - OpenThreads::Thread::microSleep(static_cast(microSecondsToDelay)); - } - - osg::ref_ptr _imageStream; -}; - -struct CallbackOperator : public ObjectOperator -{ - CallbackOperator(osg::Node* node, osg::Referenced* callback): - _node(node), - _callback(callback) {} - - virtual void* ptr() const { return _callback.get(); } - - virtual void enter() - { - reset(); - } - - virtual void maintain() - { - } - - virtual void leave() - { - } - - virtual void setPause(bool pause) - { - osg::AnimationPathCallback* apc = dynamic_cast(_callback.get()); - osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); - ss3d::AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); - if (apc) - { - osg::notify(osg::INFO)<<"apc->setPause("<setPause(pause); - } - if (tc) - { - osg::notify(osg::INFO)<<"tc->setPause("<setPause(pause); - } - if (amc) - { - osg::notify(osg::INFO)<<"amc->setPause("<setPause(pause); - } - } - - virtual void reset() - { - osg::AnimationPathCallback* apc = dynamic_cast(_callback.get()); - osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); - ss3d::AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); - if (apc) - { - apc->reset(); - apc->update(*_node); - } - if (tc) - { - } - if (amc) - { - amc->reset(); - amc->update(*_node); - } - } - - - osg::ref_ptr _node; - osg::ref_ptr _callback; -}; - -struct LayerAttributesOperator : public ObjectOperator -{ - LayerAttributesOperator(osg::Node* node, LayerAttributes* la): - _node(node), - _layerAttribute(la) - { - } - - virtual void* ptr() const { return _layerAttribute.get(); } - - virtual void enter() - { - _layerAttribute->callEnterCallbacks(_node.get()); - - if (!_layerAttribute->_keys.empty()) - { - osg::notify(osg::INFO)<<"applyKeys {"<_keys.begin(); - itr != _layerAttribute->_keys.end(); - ++itr) - { - SlideEventHandler::instance()->dispatchEvent(*itr); - } - - osg::notify(osg::INFO)<<"}"<_runStrings.empty()) - { - for(LayerAttributes::RunStrings::iterator itr = _layerAttribute->_runStrings.begin(); - itr != _layerAttribute->_runStrings.end(); - ++itr) - { - - osg::notify(osg::NOTICE)<<"Run "<c_str()<tick(); - - int result = system(itr->c_str()); - - osg::notify(osg::INFO)<<"system("<<*itr<<") result "<delta_s(startTick, osg::Timer::instance()->tick()); - - osgGA::EventQueue* eq = SlideEventHandler::instance()->getViewer()->getEventQueue(); - if (eq) - { - osg::Timer_t new_startTick = eq->getStartTick() + osg::Timer_t(timeForRun / osg::Timer::instance()->getSecondsPerTick()); - eq->setStartTick(new_startTick); - } - } - } - - } - - virtual void maintain() - { - } - - virtual void leave() - { - osg::notify(osg::INFO)<<"LayerAttribute leave"<callLeaveCallbacks(_node.get()); - } - - virtual void setPause(bool pause) - { - } - - virtual void reset() - { - } - - - osg::ref_ptr _node; - osg::ref_ptr _layerAttribute; -}; - - -class FindOperatorsVisitor : public osg::NodeVisitor -{ -public: - FindOperatorsVisitor(ActiveOperators::OperatorList& operatorList, osg::NodeVisitor::TraversalMode tm): - osg::NodeVisitor(tm), - _operatorList(operatorList) {} - - void apply(osg::Node& node) - { - if (node.getStateSet()) process(node.getStateSet()); - - if (node.getUpdateCallback()) - { - _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); - } - - LayerAttributes* la = dynamic_cast(node.getUserData()); - if (la) - { - _operatorList.insert(new LayerAttributesOperator(&node, la)); - } - - traverse(node); - } - - void apply(osg::Geode& node) - { - apply((osg::Node&)node); - for(unsigned int i=0;igetStateSet()) process(drawable->getStateSet()); - } - } - - virtual void process(osg::StateSet* ss) - { - for(unsigned int i=0;igetTextureAttributeList().size();++i) - { - osg::Texture* texture = dynamic_cast(ss->getTextureAttribute(i,osg::StateAttribute::TEXTURE)); - osg::Image* image = texture ? texture->getImage(0) : 0; - osg::ImageStream* imageStream = image ? dynamic_cast(image) : 0; - if (imageStream) - { - _operatorList.insert(new ImageStreamOperator(imageStream)); - } - } - } - - ActiveOperators::OperatorList& _operatorList; -}; - - -ActiveOperators::ActiveOperators(): - _pause(false) -{ -} - -ActiveOperators::~ActiveOperators() -{ -} - -void ActiveOperators::collect(osg::Node* incommingNode, osg::NodeVisitor::TraversalMode tm) -{ - _previous.swap(_current); - - _current.clear(); - - FindOperatorsVisitor fov(_current, tm); - incommingNode->accept(fov); - - osg::notify(osg::INFO)<<"ActiveOperators::collect("<filePathList); - } - - traverse(node); - } - -}; - -class UpdateLightVisitor : public osg::NodeVisitor -{ -public: - - UpdateLightVisitor(const osg::Matrixd& viewMatrix, float currentX, float currentY): - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN), - _viewMatrix(viewMatrix), - _currentX(currentX), _currentY(currentY) {} - - void apply(osg::Node& node) - { - if (node.getStateSet()) - { - apply(*node.getStateSet()); - } - - traverse(node); - } - - void apply(osg::LightSource& lightsource) - { - if (lightsource.getStateSet()) - { - apply(*lightsource.getStateSet()); - } - - if (lightsource.getLight()) - { - osg::notify(osg::INFO)<<"Adjusting light"<setPosition(osg::Vec4(direction,0.0f)); - - } - - traverse(lightsource); - } - - void apply(osg::StateSet& stateset) - { - osg::TexEnvCombine* texenvcombine = dynamic_cast(stateset.getTextureAttribute(0,osg::StateAttribute::TEXENV)); - if (texenvcombine) - { - apply(*texenvcombine); - } - } - - void apply(osg::TexEnvCombine& texenv) - { - osg::notify(osg::INFO)<<"Adjusting tex env combine"<(stateset.getAttribute(osg::StateAttribute::ALPHAFUNC)); - if (alphaFunc) - { - osg::notify(osg::INFO)<<"Adjusting alpha func"<getReferenceValue(); - alpha = osg::clampBetween((1.0f-_currentY)*0.5f,0.0f,1.0f); - - alphaFunc->setReferenceValue(alpha); - } - } - - if (_modMaterial) - { - osg::Material* material = dynamic_cast(stateset.getAttribute(osg::StateAttribute::MATERIAL)); - if (material) - { - osg::notify(osg::INFO)<<"Adjusting material func"<setAlpha(osg::Material::FRONT_AND_BACK,alpha); - } - } - } - - bool _modAlphaFunc, _modMaterial; - float _currentX, _currentY; - -}; - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// SlideEventHandler -// -SlideEventHandler::SlideEventHandler(osgViewer::Viewer* viewer): - _viewer(viewer), - _presentationSwitch(0), - _activeSlide(0), - _slideSwitch(0), - _activeLayer(0), - _firstTraversal(true), - _previousTime(-1.0f), - _timePerSlide(1.0), - _autoSteppingActive(false), - _loopPresentation(false), - _pause(false), - _hold(false), - _updateLightActive(false), - _updateOpacityActive(false), - _previousX(0), _previousY(0), - _cursorOn(true), - _releaseAndCompileOnEachNewSlide(false), - _firstSlideOrLayerChange(true), - _tickAtFirstSlideOrLayerChange(0), - _tickAtLastSlideOrLayerChange(0), - _timeDelayOnNewSlideWithMovies(0.25f), - _minimumTimeBetweenKeyPresses(0.25), - _timeLastKeyPresses(-1.0) -{ - s_seh = this; -} - -double SlideEventHandler::getDuration(const osg::Node* node) const -{ - const LayerAttributes* la = dynamic_cast(node->getUserData()); - return la ? la->_duration : -1.0; -} - -void SlideEventHandler::set(osg::Node* model) -{ -#if 0 - // pause all slides, then just reenable the current slide. - ActivityUpdateCallbacksVisitor aucv(ALL_OBJECTS, true); - aucv.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); - model->accept(aucv); -#endif - - ActiveOperators operators; - operators.collect(model, osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); - operators.setPause(true); - - FindNamedSwitchVisitor findPresentation("Presentation"); - model->accept(findPresentation); - - if (findPresentation._switch) - { - osg::notify(osg::INFO)<<"Presentation '"<getName()<<"'"<=0.0) - { - osg::notify(osg::INFO)<<"Presentation time set to "<accept(findSlide); - - if (findSlide._switch) - { - osg::notify(osg::INFO)<<"Found presentation slide"<getName()<(_slideSwitch->getNumChildren())) - { - duration = getDuration(_slideSwitch->getChild(_activeLayer)); - } - - if (duration < 0.0) - { - duration = getDuration(_slideSwitch.get()); - } - - if (duration >=0 ) - { - return duration; - } - } - - return _timePerSlide; -} - - -void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) -{ - osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev) - { - if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv); - - if (ev->getActionAdapter() && !ev->getEvents().empty()) - { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); - } - } - } -} - -bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) -{ - - if (!_viewer) - { - _viewer = dynamic_cast(&aa); - selectSlide(0); - home(); - osg::notify(osg::NOTICE)<<"Assigned viewer. to SlideEventHandler"<=getCurrentTimeDelayBetweenSlides()) - { - // _previousTime = time; - - if (!_hold) - { - // increment the previous by the required time delay, note relative to the current - // to keep the time relative to an absolute time signal, thus avoid drift of timing. - _previousTime += getCurrentTimeDelayBetweenSlides(); - - nextLayerOrSlide(); - } - else - { - // we're holding of the move to next layer to slide, but we need slip the time forward accordingly - // componensate for the extra time that this frame is recieving. - _previousTime = time-getCurrentTimeDelayBetweenSlides(); - } - } - } - return false; - } - - case(osgGA::GUIEventAdapter::KEYDOWN): - { - double time = ea.time(); - double deltaTime = time - _timeLastKeyPresses; - if (deltaTime < _minimumTimeBetweenKeyPresses) - { - break; - } - - _timeLastKeyPresses = time; - - if (ea.getKey()=='a') - { - if (!_autoSteppingActive) - { - _autoSteppingActive = true; - _previousTime = ea.time(); - } - return true; - } - else if (ea.getKey()=='q') - { - if (_autoSteppingActive) - { - _autoSteppingActive = false; - _previousTime = ea.time(); - } - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Home || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Home) - { - _autoSteppingActive = false; - selectSlide(0); - home(ea,aa); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_End || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_End) - { - _autoSteppingActive = false; - selectSlide(LAST_POSITION,LAST_POSITION); - home(ea,aa); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Down) - { - _autoSteppingActive = false; - nextLayer(); - return true; - } - else if (ea.getKey()=='n') - { - _autoSteppingActive = false; - nextLayerOrSlide(); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up) - { - _autoSteppingActive = false; - previousLayer(); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Page_Down || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Page_Down) - { - _autoSteppingActive = false; - nextLayerOrSlide(); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Page_Up || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Page_Up) - { - _autoSteppingActive = false; - previousLayerOrSlide(); - return true; - } - else if (ea.getKey()=='N' || - ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) - { - _autoSteppingActive = false; - nextSlide(); - home(ea,aa); - return true; - } - else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || - ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) - { - _autoSteppingActive = false; - previousSlide(); - home(ea,aa); - return true; - } - else if (ea.getKey()=='p') - { - if (!_pause) - { - _pause = true; -#if 0 - resetUpdateCallbackActivity(ALL_OBJECTS); -#endif - _activeOperators.setPause(_pause); - } - - return true; - - } - else if (ea.getKey()=='o') - { - if (_pause) - { - _pause = false; -#if 0 - resetUpdateCallbackActivity(ALL_OBJECTS); -#endif - _activeOperators.setPause(_pause); - } - return true; - - } - else if (ea.getKey()=='h') - { - _hold = true; - return true; - } - else if (ea.getKey()=='r') - { -#if 0 - resetUpdateCallbacks(ALL_OBJECTS); -#endif - _activeOperators.reset(); - return true; - } -/* - else if (ea.getKey()=='c') - { - _cursorOn = !_cursorOn; - - for( unsigned int i = 0; i < _viewer->getCameraConfig()->getNumberOfCameras(); i++ ) - { - Producer::Camera* cam = _viewer->getCameraConfig()->getCamera(i); - Producer::RenderSurface* rs = cam->getRenderSurface(); - rs->useCursor(_cursorOn); - } - - return true; - } -*/ - else if (ea.getKey()=='u') - { - updateAlpha(true,false,ea.getX(),ea.getY()); - return true; - } - else if (ea.getKey()=='i') - { - updateAlpha(false,true,ea.getX(),ea.getY()); - return true; - } - else if (ea.getKey()=='k') - { - updateLight(ea.getX(),ea.getY()); - return true; - } - - return false; - } - case(osgGA::GUIEventAdapter::KEYUP): - { - if (ea.getKey()=='h') - { - _hold = false; - return true; - } - return false; - } - default: - return false; - } - return false; -} - -void SlideEventHandler::getUsage(osg::ApplicationUsage& usage) const -{ - usage.addKeyboardMouseBinding("a","Toggle on/off the automatic advancement for image to image"); - usage.addKeyboardMouseBinding("n","Advance to next layer or slide"); - usage.addKeyboardMouseBinding("p","Move to previous layer or slide"); -} - -unsigned int SlideEventHandler::getNumSlides() -{ - if (_presentationSwitch.valid()) return _presentationSwitch->getNumChildren(); - else return 0; -} - - -bool SlideEventHandler::selectSlide(int slideNum,int layerNum) -{ - if (!_presentationSwitch) return false; - - osg::notify(osg::INFO)<<"selectSlide("<getNumChildren()>0) - { - slideNum = _presentationSwitch->getNumChildren()-1; - } - - if (slideNum>=static_cast(_presentationSwitch->getNumChildren())) return false; - - - osg::Timer_t tick = osg::Timer::instance()->tick(); - - if (_firstSlideOrLayerChange) - { - _firstSlideOrLayerChange = false; - _tickAtFirstSlideOrLayerChange = tick; - _tickAtLastSlideOrLayerChange = tick; - } - - osg::notify(osg::INFO)<<"selectSlide("<delta_s(_tickAtFirstSlideOrLayerChange, tick)<<" seconds, length ="<delta_s(_tickAtLastSlideOrLayerChange, tick)<<" seconds"<setSingleChildOn(_activeSlide); - - //osg::notify(osg::INFO)<<"Selected slide '"<<_presentationSwitch->getChild(_activeSlide)->getName()<<"'"<getChild(_activeSlide)->accept(findSlide); - - bool result = false; - if (findSlide._switch) - { - //osg::notify(osg::INFO)<<"Found slide '"<getName()<<"'"<getKeySwitchMatrixManipulator()->setMinimumDistance(0.001); - - _viewer->getCameraManipulator()->setNode(_slideSwitch.get()); - - _viewer->computeActiveCoordinateSystemNodePath(); - - // resetUpdateCallbacks(ALL_OBJECTS); - - bool _useSlideFilePaths = false; - if (_useSlideFilePaths) - { - // set up the file paths - FindFilePathDataVisitor ffpdv; - _presentationSwitch->accept(ffpdv); - } - - if (newSlide && _releaseAndCompileOnEachNewSlide) - { - compileSlide(slideNum); - } - - return result; - -} - -bool SlideEventHandler::selectLayer(int layerNum) -{ - if (!_slideSwitch) return false; - - if (layerNum==LAST_POSITION && _slideSwitch->getNumChildren()>0) - { - layerNum = _slideSwitch->getNumChildren()-1; - } - - if (layerNum>=static_cast(_slideSwitch->getNumChildren())) return false; - - _activeLayer = layerNum; - _slideSwitch->setSingleChildOn(_activeLayer); - - updateOperators(); - - osg::notify(osg::INFO)<<"Selected layer '"<<_slideSwitch->getChild(_activeLayer)->getName()<<"' num="<<_activeLayer<< std::endl; - - return true; -} - -bool SlideEventHandler::nextLayerOrSlide() -{ - if (nextLayer()) return true; - else return nextSlide(); -} - -bool SlideEventHandler::previousLayerOrSlide() -{ - if (previousLayer()) return true; - else return previousSlide(); -} - -bool SlideEventHandler::nextSlide() -{ - LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast(_slideSwitch->getUserData()) : 0; - if (la && la->requiresJump()) - { - if (la->getRelativeJump()) - { - int previousSlide = getActiveSlide(); - int previousLayer = getActiveLayer(); - int newSlide = previousSlide + la->getSlideNum(); - int newLayer = previousLayer + la->getLayerNum(); - if (newLayer<0) - { - newLayer = 0; - } - - return selectSlide(newSlide, newLayer); - } - else - { - return selectSlide(la->getSlideNum(),la->getLayerNum()); - } - } - - if (selectSlide(_activeSlide+1)) return true; - else if (_loopPresentation) return selectSlide(0); - else return false; -} - -bool SlideEventHandler::previousSlide() -{ -#if 1 - // start position when doing previous slide set to top of slide - if (_activeSlide>0) return selectSlide(_activeSlide-1); - else if (_loopPresentation && _presentationSwitch.valid()) return selectSlide(_presentationSwitch->getNumChildren()-1); - else return false; -#else - // start position when doing previous slide set to end of slide - if (_activeSlide>0) return selectSlide(_activeSlide-1,LAST_POSITION); - else if (_loopPresentation && _presentationSwitch.valid()) return selectSlide(_presentationSwitch->getNumChildren()-1,LAST_POSITION); - else return false; -#endif -} - -bool SlideEventHandler::nextLayer() -{ - LayerAttributes* la = (_slideSwitch.valid() && _activeLayer>=0) ? dynamic_cast(_slideSwitch->getChild(_activeLayer)->getUserData()) : 0; - if (la) - { - la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer)); - - if (la->requiresJump()) - { - if (la->getRelativeJump()) - { - int previousSlide = getActiveSlide(); - int previousLayer = getActiveLayer(); - int newSlide = previousSlide + la->getSlideNum(); - int newLayer = previousLayer + la->getLayerNum(); - if (newLayer<0) - { - newLayer = 0; - } - - return selectSlide(newSlide, newLayer); - } - else - { - return selectSlide(la->getSlideNum(),la->getLayerNum()); - } - } - } - - return selectLayer(_activeLayer+1); -} - -bool SlideEventHandler::previousLayer() -{ - if (_activeLayer>0) return selectLayer(_activeLayer-1); - else return false; -} - - -void SlideEventHandler::updateOperators() -{ - _activeOperators.collect(_slideSwitch.get()); - _activeOperators.process(); - - if (_viewer.valid()) - { - UpdateLightVisitor uav(_viewer->getCamera()->getViewMatrix(),0.0f,0.0f); - _viewer->getSceneData()->accept(uav); - } -} - -bool SlideEventHandler::home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) -{ - FindHomePositionVisitor fhpv; - osg::Node* node = _viewer->getSceneData(); - if (node) node->accept(fhpv); - - if (fhpv._homePosition.valid()) - { - osg::notify(osg::INFO)<<"Doing home for stored home position."<getCameraManipulator()->setAutoComputeHomePosition(false); - _viewer->getCameraManipulator()->setHomePosition( - fhpv._homePosition->eye, - fhpv._homePosition->center, - fhpv._homePosition->up); - } - else - { - _viewer->getCameraManipulator()->setAutoComputeHomePosition(true); - } - _viewer->getCameraManipulator()->home(ea,aa); - - return true; -} - -bool SlideEventHandler::home() -{ - osg::ref_ptr ea = new osgGA::GUIEventAdapter; - ea->setEventType(osgGA::GUIEventAdapter::FRAME); - ea->setTime(_viewer->getEventQueue()->getTime()); - - home(*ea,*_viewer); - return true; -} - -void SlideEventHandler::updateAlpha(bool modAlphaFunc, bool modMaterial, float x, float y) -{ - osg::notify(osg::INFO)<<"updateAlpha("<accept(uav); - else if (_viewer->getSceneData()) _viewer->getSceneData()->accept(uav); -} - - -void SlideEventHandler::updateLight(float x, float y) -{ - osg::notify(osg::INFO)<<"updateLight("<getCamera()->getViewMatrix(),x,y); - _viewer->getSceneData()->accept(uav); -} - -void SlideEventHandler::compileSlide(unsigned int slideNum) -{ - if (!_compileSlideCallback) - { - _compileSlideCallback = new ss3d::CompileSlideCallback(); - - osgViewer::Viewer::Cameras cameras; - _viewer->getCameras(cameras); - - for(osgViewer::Viewer::Cameras::iterator itr = cameras.begin(); - itr != cameras.end(); - ++itr) - { - (*itr)->setPreDrawCallback(_compileSlideCallback.get()); - } - - } - - _compileSlideCallback->needCompile(_presentationSwitch->getChild(slideNum)); - -} - -void SlideEventHandler::releaseSlide(unsigned int slideNum) -{ - osgUtil::GLObjectsVisitor globjVisitor(osgUtil::GLObjectsVisitor::RELEASE_DISPLAY_LISTS| - osgUtil::GLObjectsVisitor::RELEASE_STATE_ATTRIBUTES); - globjVisitor.setNodeMaskOverride(0xffffffff); - - _presentationSwitch->getChild(slideNum)->accept(globjVisitor); -} - -void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition) -{ - osg::notify(osg::INFO)<<" keyPosition._key "<getEventQueue(); - - // reset the time of the last key press to ensure thatthe event is disgarded as a key repeat. - _timeLastKeyPresses = -1.0; - - if (keyPosition._x!=FLT_MAX) - { - float xRescaled = eq->getCurrentEventState()->getXmin() + (keyPosition._x+1.0f)*0.5f*(eq->getCurrentEventState()->getXmax()-eq->getCurrentEventState()->getXmin()); - eq->getCurrentEventState()->setX(xRescaled); - } - - if (keyPosition._y!=FLT_MAX) - { - float yRescaled = eq->getCurrentEventState()->getYmin() + (keyPosition._y+1.0f)*0.5f*(eq->getCurrentEventState()->getXmax()-eq->getCurrentEventState()->getYmin()); - eq->getCurrentEventState()->setY(yRescaled); - } - - eq->keyPress(keyPosition._key); - eq->keyRelease(keyPosition._key); -} - - - diff --git a/src/osgPlugins/p3d/SlideShowConstructor.cpp b/src/osgPlugins/p3d/SlideShowConstructor.cpp deleted file mode 100644 index b5ea4be2e..000000000 --- a/src/osgPlugins/p3d/SlideShowConstructor.cpp +++ /dev/null @@ -1,1731 +0,0 @@ -/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield - * - * This software is open source and may be redistributed and/or modified under - * the terms of the GNU General Public License (GPL) version 2.0. - * The full license is in LICENSE.txt file included with this distribution,. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * include LICENSE.txt for more details. -*/ - -#include "SlideShowConstructor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include - -#include -#include -#include - -#include -#include - -#include "AnimationMaterial.h" -#include "PickEventHandler.h" - -using namespace osgPresentation; - -class SetToTransparentBin : public osg::NodeVisitor -{ -public: - - SetToTransparentBin(): - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - virtual void appply(osg::Node& node) - { - if (node.getStateSet()) - { - node.getStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON); - node.getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - } - } - - virtual void apply(osg::Geode& geode) - { - if (geode.getStateSet()) - { - geode.getStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON); - geode.getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - } - for(unsigned int i=0;igetStateSet()) - { - geode.getDrawable(i)->getStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON); - geode.getDrawable(i)->getStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - } - } - } -}; - -SlideShowConstructor::SlideShowConstructor(const osgDB::ReaderWriter::Options* options): - _options(options) -{ - _slideDistance = osg::DisplaySettings::instance()->getScreenDistance(); - _slideHeight = osg::DisplaySettings::instance()->getScreenHeight(); - _slideWidth = osg::DisplaySettings::instance()->getScreenWidth(); - - _backgroundColor.set(0.0f,0.0f,0.0f,1.0f); - - _presentationDuration = -1.0; - - // set up title defaults - _titleFontDataDefault.font = "fonts/arial.ttf"; - _titleFontDataDefault.color.set(1.0f,1.0f,1.0f,1.0f); - _titleFontDataDefault.layout = osgText::Text::LEFT_TO_RIGHT; - _titleFontDataDefault.alignment = osgText::Text::CENTER_BASE_LINE; - _titleFontDataDefault.axisAlignment = osgText::Text::XZ_PLANE; - _titleFontDataDefault.characterSize = 0.06f; - _titleFontDataDefault.maximumWidth = 0.9f; - - _titlePositionDataDefault.position.set(0.5f,0.92f,0.0f); - - // set up text defaults - _textFontDataDefault.font = "fonts/arial.ttf"; - _textFontDataDefault.color.set(1.0f,1.0f,1.0f,1.0f); - _textFontDataDefault.layout = osgText::Text::LEFT_TO_RIGHT; - _textFontDataDefault.alignment = osgText::Text::LEFT_BASE_LINE; - _textFontDataDefault.axisAlignment = osgText::Text::XZ_PLANE; - _textFontDataDefault.characterSize = 0.04f; - _textFontDataDefault.maximumWidth = 0.8f; - - _textPositionDataDefault.position.set(0.1f,0.85f,0.0f); - - _loopPresentation = false; - _autoSteppingActive = false; -} - -void SlideShowConstructor::setPresentationAspectRatio(float aspectRatio) -{ - _slideWidth = _slideHeight*aspectRatio; -} - -void SlideShowConstructor::setPresentationAspectRatio(const std::string& str) -{ - if (str=="Reality Theatre") setPresentationAspectRatio(3.0f); - else if (str=="Desktop") setPresentationAspectRatio(1280.0f/1024.0f); - else - { - float ratio = (float)atof(str.c_str()); - if (ratio!=0.0) setPresentationAspectRatio(1280.0f/1024.0f); - else - { - osg::notify(osg::WARN)<<"Error: presentation aspect ratio incorrect type"<addChild(_presentationSwitch.get()); - - osg::Vec3 slideCenter = _slideOrigin + osg::Vec3(_slideWidth*0.5f,0.0f,_slideHeight*0.5f); - - HomePosition* hp = new HomePosition; - hp->eye.set(0.0f,0.0f,0.0f); - hp->center = slideCenter; - hp->up.set(0.0f,0.0f,1.0f); - - osg::notify(osg::INFO)<<" slideCenter "<=0.0) - { - setDuration(_presentationSwitch.get(),_presentationDuration); - } - - _root->setUserData(hp); - - if (_loopPresentation) _root->addDescription("loop"); - if (_autoSteppingActive) _root->addDescription("auto"); -} - -LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node) -{ - LayerAttributes* la = dynamic_cast(node->getUserData()); - if (!la) - { - if (node->getUserData()) - { - osg::notify(osg::NOTICE)<<"UserData already assigned, overriding to set LayerAttributes."<setUserData(la); - } - - return la; -} - -void SlideShowConstructor::setBackgroundColor(const osg::Vec4& color, bool updateClearNode) -{ - _backgroundColor = color; - if (updateClearNode && _slideClearNode.valid()) _slideClearNode->setClearColor(_backgroundColor); -} - -void SlideShowConstructor::setTextColor(const osg::Vec4& color) -{ - _titleFontDataDefault.color = color; - _textFontDataDefault.color = color; - - _titleFontData.color = _titleFontDataDefault.color; - _textFontData.color = _textFontDataDefault.color; - -} - -void SlideShowConstructor::setPresentationName(const std::string& name) -{ - _presentationName = name; - if (_presentationSwitch.valid()) _presentationSwitch->setName(std::string("Presentation_")+_presentationName); -} - -void SlideShowConstructor::setPresentationDuration(double duration) -{ - _presentationDuration = duration; - if (_presentationDuration>=0.0 && _presentationSwitch.valid()) - { - setDuration(_presentationSwitch.get(),_presentationDuration); - } -} - -void SlideShowConstructor::addSlide() -{ - if (!_presentationSwitch) createPresentation(); - - // reset fonts - _titleFontData = _titleFontDataDefault; - _textFontData = _textFontDataDefault; - - // reset cursors - _titlePositionData = _titlePositionDataDefault; - _textPositionData = _textPositionDataDefault; - _imagePositionData = _imagePositionDataDefault; - _modelPositionData = _modelPositionDataDefault; - - _slide = new osg::Switch; - _slide->setName(std::string("Slide_")+_slideTitle); - - _slideClearNode = new osg::ClearNode; - _slideClearNode->setClearColor(_backgroundColor); - _slideClearNode->addChild(_slide.get()); - - _presentationSwitch->addChild(_slideClearNode.get()); - - _previousLayer = 0; - _currentLayer = 0; - - - _filePathData = new FilePathData(osgDB::getDataFilePathList()); - - _slideClearNode->setUserData(_filePathData.get()); -} - -void SlideShowConstructor::selectSlide(int slideNum) -{ - if (slideNum<0) - { - addSlide(); - } - else if (slideNum>=static_cast(_presentationSwitch->getNumChildren())) - { - addSlide(); - } - else - { - _slideClearNode = dynamic_cast(_presentationSwitch->getChild(slideNum)); - if (!_slideClearNode || _slideClearNode->getNumChildren()==0 || _slideClearNode->getChild(0)->asSwitch()==0) - { - addSlide(); - } - else - { - _slide = _slideClearNode->getChild(0)->asSwitch(); - _previousLayer = _slide->getChild(_slide->getNumChildren()-1)->asGroup(); - _currentLayer = 0; - } - } -} - -void SlideShowConstructor::setSlideDuration(double duration) -{ - if (!_slide) addSlide(); - - if (_slide.valid()) - { - setDuration(_slide.get(),duration); - } -} - -void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBaseLayer) -{ - if (!_slide) addSlide(); - - _currentLayer = new osg::Group; - - // osg::notify(osg::NOTICE)<<"addLayer"<setTextureAttributeAndModes(0, - texture, - osg::StateAttribute::ON); - } - else - { - osg::Texture2D* texture = new osg::Texture2D(image.get()); - texture->setResizeNonPowerOfTwoHint(false); - backgroundStateSet->setTextureAttributeAndModes(0, - texture, - osg::StateAttribute::ON); - } - - background->addDrawable(backgroundQuad); - - _currentLayer->addChild(background); - } - - if (!_slideTitle.empty()) - { - osg::Geode* geode = new osg::Geode; - - osg::Vec3 localPosition = computePositionInModelCoords(_titlePositionData); - - osgText::Text* text = new osgText::Text; - text->setFont(_titleFontData.font); - text->setColor(_titleFontData.color); - text->setCharacterSize(_titleFontData.characterSize*_slideHeight); - text->setFontResolution(110,120); - text->setMaximumWidth(_titleFontData.maximumWidth*_slideWidth); - text->setLayout(_titleFontData.layout); - text->setAlignment(_titleFontData.alignment); - text->setAxisAlignment(_titleFontData.axisAlignment); - //text->setPosition(_titlePositionData.position); - text->setPosition(localPosition); - - text->setText(_slideTitle); - - geode->addDrawable(text); - - _currentLayer->addChild(geode); - } - - } - else - { - // copy previous layer's children across into new layer. - for(unsigned int i=0;i<_previousLayer->getNumChildren();++i) - { - _currentLayer->addChild(_previousLayer->getChild(i)); - } - } - - if (!defineAsBaseLayer) - { - _slide->addChild(_currentLayer.get()); - } - - _previousLayer = _currentLayer; -} - -void SlideShowConstructor::selectLayer(int layerNum) -{ - if (!_slide) - { - addSlide(); - addLayer(); - } - else if (layerNum>=0 && layerNum(_slide->getNumChildren()) && _slide->getChild(layerNum)->asGroup()) - { - _currentLayer = _slide->getChild(layerNum)->asGroup(); - _previousLayer = _currentLayer; - } - else - { - addLayer(); - } - -} - - -void SlideShowConstructor::setLayerDuration(double duration) -{ - if (!_currentLayer) addLayer(); - - if (_currentLayer.valid()) - { - setDuration(_currentLayer.get(),duration); - } -} - -void SlideShowConstructor::layerClickToDoOperation(Operation operation, bool relativeJump, int slideNum, int layerNum) -{ - if (!_currentLayer) addLayer(); - - if (_currentLayer.valid()) - { - if (_previousLayer==_currentLayer) - { - if (_currentLayer->getNumChildren()>0) - { - osg::notify(osg::INFO)<<"creating new group within layer"<addChild(group); - _currentLayer = group; - } - } - else - { - osg::notify(osg::INFO)<<"creating secondary group within layer"<addChild(group); - _currentLayer = group; - } - _currentLayer->setEventCallback(new PickEventHandler(operation, relativeJump, slideNum, layerNum)); - } - -} - - -void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump, int slideNum, int layerNum) -{ - if (!_currentLayer) addLayer(); - - if (_currentLayer.valid()) - { - if (_previousLayer==_currentLayer) - { - if (_currentLayer->getNumChildren()>0) - { - osg::notify(osg::INFO)<<"creating new group within layer"<addChild(group); - _currentLayer = group; - } - } - else - { - osg::notify(osg::INFO)<<"creating secondary group within layer"<addChild(group); - _currentLayer = group; - } - _currentLayer->setEventCallback(new PickEventHandler(command, operation, relativeJump, slideNum, layerNum)); - } - -} - - -void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) -{ - if (!_currentLayer) addLayer(); - - if (_currentLayer.valid()) - { - if (_previousLayer==_currentLayer) - { - if (_currentLayer->getNumChildren()>0) - { - osg::notify(osg::INFO)<<"creating new group within layer"<addChild(group); - _currentLayer = group; - } - } - else - { - osg::notify(osg::INFO)<<"creating secondary group within layer"<addChild(group); - _currentLayer = group; - } - _currentLayer->setEventCallback(new PickEventHandler(keyPos, relativeJump, slideNum, layerNum)); - } - -} - -void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData) -{ - if (!_currentLayer) addLayer(); - - osg::Geode* geode = new osg::Geode; - - osgText::Text* text = new osgText::Text; - - osg::Vec3 localPosition = computePositionInModelCoords(positionData); - - text->setFont(fontData.font); - text->setColor(fontData.color); - text->setCharacterSize(fontData.characterSize*_slideHeight); - text->setFontResolution(110,120); - text->setMaximumWidth(fontData.maximumWidth*_slideWidth); - text->setLayout(fontData.layout); - text->setAlignment(fontData.alignment); - text->setAxisAlignment(fontData.axisAlignment); - text->setPosition(localPosition); - - text->setText(bullet); - - osg::BoundingBox bb = text->getBound(); - - // note, this increment is only "correct" when text is on the plane of the slide.. - // will need to make this more general later. - localPosition.z() = bb.zMin()-fontData.characterSize*_slideHeight*1.5; - - geode->addDrawable(text); - - osg::Node* subgraph = geode; - - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData); - - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(geode->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - _currentLayer->addChild(subgraph); - - updatePositionFromInModelCoords(localPosition, positionData); -} - -void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData) -{ - if (!_currentLayer) addLayer(); - - osg::Geode* geode = new osg::Geode; - - osg::Vec3 localPosition = computePositionInModelCoords(positionData); - - osgText::Text* text = new osgText::Text; - - text->setFont(fontData.font); - text->setColor(fontData.color); - text->setCharacterSize(fontData.characterSize*_slideHeight); - text->setFontResolution(110,120); - text->setMaximumWidth(fontData.maximumWidth*_slideWidth); - text->setLayout(fontData.layout); - text->setAlignment(fontData.alignment); - text->setAxisAlignment(fontData.axisAlignment); - text->setPosition(localPosition); - - text->setText(paragraph); - - osg::BoundingBox bb = text->getBound(); - - // note, this increment is only "correct" when text is on the plane of the slide.. - // will need to make this more general later. - localPosition.z() = bb.zMin()-fontData.characterSize*_slideHeight*1.5; - - geode->addDrawable(text); - - osg::Node* subgraph = geode; - - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData); - - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(geode->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - _currentLayer->addChild(subgraph); - - updatePositionFromInModelCoords(localPosition, positionData); -} - -class FindImageStreamsVisitor : public osg::NodeVisitor -{ -public: - FindImageStreamsVisitor(): - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} - - virtual void apply(osg::Node& node) - { - if (node.getStateSet()) - { - process(node.getStateSet()); - } - traverse(node); - } - - virtual void apply(osg::Geode& node) - { - if (node.getStateSet()) - { - process(node.getStateSet()); - } - - for(unsigned int i=0;igetStateSet()) - { - process(drawable->getStateSet()); - } - } - } - - void process(osg::StateSet* ss) - { - for(unsigned int i=0;igetTextureAttributeList().size();++i) - { - osg::Texture* texture = dynamic_cast(ss->getTextureAttribute(i,osg::StateAttribute::TEXTURE)); - osg::Image* image = texture ? texture->getImage(0) : 0; - osg::ImageStream* imageStream = image ? dynamic_cast(image) : 0; - if (imageStream) - { - texture->setDataVariance(osg::Object::DYNAMIC); - texture->setUnRefImageDataAfterApply(false); - texture->setResizeNonPowerOfTwoHint(false); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setClientStorageHint(true); - } - } - } - -}; - -void SlideShowConstructor::findImageStreamsAndAddCallbacks(osg::Node* node) -{ - FindImageStreamsVisitor fisv; - node->accept(fisv); -} - - -osg::Geometry* SlideShowConstructor::createTexturedQuadGeometry(const osg::Vec3& pos, const osg::Vec4& rotation, float width, float height, osg::Image* image, bool& usedTextureRectangle) -{ - osg::Geometry* pictureQuad = 0; - osg::Texture* texture = 0; - osg::StateSet* stateset = 0; - - osg::Vec3 positionVec = pos; - osg::Vec3 widthVec(width,0.0f,0.0f); - osg::Vec3 heightVec(0.0f,0.0f,height); - - osg::Matrixd rotationMatrix = osg::Matrixd::rotate(osg::DegreesToRadians(rotation[0]),rotation[1],rotation[2],rotation[3]); - widthVec = widthVec*rotationMatrix; - heightVec = heightVec*rotationMatrix; - - osg::ImageStream* imageStream = dynamic_cast(image); - - bool flipYAxis = image->getOrigin()==osg::Image::TOP_LEFT; - -#ifdef __sgi - bool useTextureRectangle = false; -#else - bool useTextureRectangle = true; -#endif - - // pass back info on wether texture 2D is used. - usedTextureRectangle = useTextureRectangle; - - if (useTextureRectangle) - { - pictureQuad = osg::createTexturedQuadGeometry(positionVec, - widthVec, - heightVec, - 0.0f, flipYAxis ? image->t() : 0.0f, - image->s(), flipYAxis ? 0.0f : image->t()); - - stateset = pictureQuad->getOrCreateStateSet(); - - texture = new osg::TextureRectangle(image); - stateset->setTextureAttributeAndModes(0, - texture, - osg::StateAttribute::ON); - - - - } - else - { - pictureQuad = osg::createTexturedQuadGeometry(positionVec, - widthVec, - heightVec, - 0.0f, flipYAxis ? 1.0f : 0.0f, - 1.0f, flipYAxis ? 0.0f : 1.0f); - - stateset = pictureQuad->getOrCreateStateSet(); - - texture = new osg::Texture2D(image); - - stateset->setTextureAttributeAndModes(0, - texture, - osg::StateAttribute::ON); - - } - - if (!pictureQuad) return 0; - - if (imageStream) - { - imageStream->pause(); - - osg::notify(osg::INFO)<<"Reading video "<getFileName()<setClientStorageHint(true); - } - - - return pictureQuad; -} - - -void SlideShowConstructor::addImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData) -{ - if (!_currentLayer) addLayer(); - - osg::Image* image = osgDB::readImageFile(filename, _options.get()); - if (image) recordOptionsFilePath(_options.get()); - - if (!image) return; - - bool isImageTranslucent = false; - - osg::ImageStream* imageStream = dynamic_cast(image); - if (imageStream) - { - imageStream->setLoopingMode(imageData.loopingMode); - - isImageTranslucent = imageStream->getPixelFormat()==GL_RGBA || - imageStream->getPixelFormat()==GL_BGRA; - - } - else - { - isImageTranslucent = image->isImageTranslucent(); - } - - float s = image->s(); - float t = image->t(); - - // temporary hack - float height = 0.0f; - - float sx = imageData.region_in_pixel_coords ? 1.0f : s; - float sy = imageData.region_in_pixel_coords ? 1.0f : t; - - float x1 = imageData.region[0]*sx; - float y1 = imageData.region[1]*sy; - float x2 = imageData.region[2]*sx; - float y2 = imageData.region[3]*sy; - - float aspectRatio = (y2-y1)/(x2-x1); - - float image_width = _slideWidth*positionData.scale.x(); - float image_height = image_width*aspectRatio*positionData.scale.y()/positionData.scale.x(); - float offset = height*image_height*0.1f; - - osg::Vec3 pos = computePositionInModelCoords(positionData) + osg::Vec3(-image_width*0.5f+offset,-offset,-image_height*0.5f-offset); - - osg::Geode* picture = new osg::Geode; - osg::Node* subgraph = picture; - - - bool usedTextureRectangle = false; - osg::Geometry* pictureQuad = createTexturedQuadGeometry(pos, positionData.rotate, image_width, image_height, image, usedTextureRectangle); - osg::StateSet* pictureStateSet = pictureQuad->getOrCreateStateSet(); - - attachTexMat(pictureStateSet, imageData, s, t, usedTextureRectangle); - - picture->addDrawable(pictureQuad); - - // attach any meterial animation. - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData); - - - if (isImageTranslucent) - { - SetToTransparentBin sttb; - subgraph->accept(sttb); - pictureStateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - } - - // attached any rotation - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(picture->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - - // attached any animation - osg::AnimationPathCallback* animation = getAnimationPathCallback(positionData); - if (animation) - { - osg::notify(osg::INFO)<<"Have animation path for image"<getBound().center(); - - osg::PositionAttitudeTransform* animation_transform = new osg::PositionAttitudeTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setPivotPoint(pivot); - animation->setPivotPoint(pivot); - - animation_transform->setUpdateCallback(animation); - - animation_transform->setReferenceFrame(positionData.absolute_path ? - osg::Transform::ABSOLUTE_RF: - osg::Transform::RELATIVE_RF); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - _currentLayer->addChild(subgraph); -} - -void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight, const ImageData& imageDataRight,const PositionData& positionData) -{ - if (!_currentLayer) addLayer(); - - - osg::ref_ptr imageLeft = osgDB::readImageFile(filenameLeft, _options.get()); - if (imageLeft.valid()) recordOptionsFilePath(_options.get()); - - osg::ref_ptr imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : osgDB::readImageFile(filenameRight, _options.get()); - if (imageRight.valid()) recordOptionsFilePath(_options.get()); - - if (!imageLeft && !imageRight) return; - - bool isImageTranslucent = false; - - osg::ImageStream* imageStreamLeft = dynamic_cast(imageLeft.get()); - if (imageStreamLeft) - { - imageStreamLeft->setLoopingMode(imageDataLeft.loopingMode); - isImageTranslucent = imageStreamLeft->getPixelFormat()==GL_RGBA || - imageStreamLeft->getPixelFormat()==GL_BGRA; - } - else - { - isImageTranslucent = imageLeft->isImageTranslucent(); - } - - osg::ImageStream* imageStreamRight = dynamic_cast(imageRight.get()); - if (imageStreamRight) - { - imageStreamRight->setLoopingMode(imageDataRight.loopingMode); - if (!isImageTranslucent) - { - isImageTranslucent = imageStreamRight->getPixelFormat()==GL_RGBA || - imageStreamRight->getPixelFormat()==GL_BGRA; - } - } - else if (!isImageTranslucent) - { - isImageTranslucent = imageRight->isImageTranslucent(); - } - - - float s = imageLeft->s(); - float t = imageLeft->t(); - - // temporary hack - float height = 0.0f; - - float sx = imageDataLeft.region_in_pixel_coords ? 1.0f : s; - float sy = imageDataLeft.region_in_pixel_coords ? 1.0f : t; - - float x1 = imageDataLeft.region[0]*sx; - float y1 = imageDataLeft.region[1]*sy; - float x2 = imageDataLeft.region[2]*sx; - float y2 = imageDataLeft.region[3]*sy; - - float aspectRatio = (y2-y1)/(x2-x1); - - float image_width = _slideWidth*positionData.scale.x(); - float image_height = image_width*aspectRatio*positionData.scale.y()/positionData.scale.x(); - - float offset = height*image_height*0.1f; - - bool usedTextureRectangle = false; - - osg::Vec3 pos = computePositionInModelCoords(positionData) + - osg::Vec3(-image_width*0.5f+offset,-offset,-image_height*0.5f-offset); - - osg::Geode* pictureLeft = new osg::Geode; - { - pictureLeft->setNodeMask(0x01); - - osg::Geometry* pictureLeftQuad = createTexturedQuadGeometry(pos, positionData.rotate, image_width,image_height,imageLeft.get(),usedTextureRectangle); - osg::StateSet* pictureLeftStateSet = pictureLeftQuad->getOrCreateStateSet(); - - if (isImageTranslucent) - { - pictureLeftStateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - } - - attachTexMat(pictureLeftStateSet, imageDataLeft, s, t, usedTextureRectangle); - - pictureLeft->addDrawable(pictureLeftQuad); - - } - - osg::Geode* pictureRight = new osg::Geode; - { - pictureRight->setNodeMask(0x02); - - osg::Geometry* pictureRightQuad = createTexturedQuadGeometry(pos, positionData.rotate, image_width,image_height,imageRight.get(),usedTextureRectangle); - osg::StateSet* pictureRightStateSet = pictureRightQuad->getOrCreateStateSet(); - - if (isImageTranslucent) - { - pictureRightStateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - } - - attachTexMat(pictureRightStateSet, imageDataRight, s, t, usedTextureRectangle); - - pictureRight->addDrawable(pictureRightQuad); - } - - osg::Group* subgraph = new osg::Group; - subgraph->addChild(pictureLeft); - subgraph->addChild(pictureRight); - - // attach any meterial animation. - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData)->asGroup(); - - if (isImageTranslucent) - { - SetToTransparentBin sttb; - subgraph->accept(sttb); - } - - // attached any rotation - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(subgraph->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - - // attached any animation - osg::AnimationPathCallback* animation = getAnimationPathCallback(positionData); - if (animation) - { - osg::notify(osg::INFO)<<"Have animation path for image"<getBound().center(); - - osg::PositionAttitudeTransform* animation_transform = new osg::PositionAttitudeTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setPivotPoint(pivot); - animation->setPivotPoint(pivot); - - animation_transform->setUpdateCallback(animation); - animation_transform->setReferenceFrame(positionData.absolute_path ? - osg::Transform::ABSOLUTE_RF: - osg::Transform::RELATIVE_RF); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - _currentLayer->addChild(subgraph); -} - -void SlideShowConstructor::addVNC(const std::string& hostname, const PositionData& positionData, const ImageData& imageData) -{ - addInteractiveImage(hostname+".vnc", positionData, imageData); -} - -void SlideShowConstructor::addBrowser(const std::string& url, const PositionData& positionData, const ImageData& imageData) -{ - addInteractiveImage(url+".gecko", positionData, imageData); -} - -void SlideShowConstructor::addPDF(const std::string& filename, const PositionData& positionData, const ImageData& imageData) -{ - addInteractiveImage(filename, positionData, imageData); -} - -class SetPageCallback: public LayerCallback -{ -public: - SetPageCallback(osgWidget::PdfImage* pdfImage, int pageNum): - _pdfImage(pdfImage), - _pageNum(pageNum) - { - } - - virtual void operator() (osg::Node*) const - { - osg::notify(osg::INFO)<<"PDF Page to be updated "<<_pageNum<getPageNum()!=_pageNum) - { - _pdfImage->page(_pageNum); - } - } - - osg::observer_ptr _pdfImage; - int _pageNum; -}; - - -osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData) -{ - if (!_currentLayer) addLayer(); - - osg::Image* image = osgDB::readImageFile(filename, _options.get()); - - osg::notify(osg::INFO)<<"addInteractiveImage("<s(); - float t = image->t(); - - // temporary hack - float height = 0.0f; - - float sx = imageData.region_in_pixel_coords ? 1.0f : s; - float sy = imageData.region_in_pixel_coords ? 1.0f : t; - - float x1 = imageData.region[0]*sx; - float y1 = imageData.region[1]*sy; - float x2 = imageData.region[2]*sx; - float y2 = imageData.region[3]*sy; - - float aspectRatio = (y2-y1)/(x2-x1); - - float image_width = _slideWidth*positionData.scale.x(); - float image_height = image_width*aspectRatio*positionData.scale.y()/positionData.scale.x(); - float offset = height*image_height*0.1f; - - osg::Vec3 pos = computePositionInModelCoords(positionData) + osg::Vec3(-image_width*0.5f+offset,-offset,-image_height*0.5f-offset); - - osg::Geode* picture = new osg::Geode; - osg::Node* subgraph = picture; - - - bool usedTextureRectangle = false; - osg::Geometry* pictureQuad = createTexturedQuadGeometry(pos, positionData.rotate, image_width, image_height, image, usedTextureRectangle); - - osg::ref_ptr handler = new osgViewer::InteractiveImageHandler(image); - pictureQuad->setEventCallback(handler.get()); - pictureQuad->setCullCallback(handler.get()); - - osg::StateSet* pictureStateSet = pictureQuad->getOrCreateStateSet(); - - attachTexMat(pictureStateSet, imageData, s, t, usedTextureRectangle); - - pictureStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - - picture->addDrawable(pictureQuad); - - // attach any meterial animation. - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData); - - - // attached any rotation - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(picture->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - - // attached any animation - osg::AnimationPathCallback* animation = getAnimationPathCallback(positionData); - if (animation) - { - osg::notify(osg::INFO)<<"Have animation path for image"<getBound().center(); - - osg::PositionAttitudeTransform* animation_transform = new osg::PositionAttitudeTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setPivotPoint(pivot); - animation->setPivotPoint(pivot); - - animation_transform->setUpdateCallback(animation); - - animation_transform->setReferenceFrame(positionData.absolute_path ? - osg::Transform::ABSOLUTE_RF: - osg::Transform::RELATIVE_RF); - - animation_transform->addChild(subgraph); - - subgraph = animation_transform; - } - - _currentLayer->addChild(subgraph); - - osgWidget::PdfImage* pdfImage = dynamic_cast(image); - if (pdfImage && imageData.page>=0) - { - getOrCreateLayerAttributes(_currentLayer.get())->addEnterCallback(new SetPageCallback(pdfImage, imageData.page)); - - osg::notify(osg::INFO)<<"Setting pdf page num "<setBackgroundColor(imageData.backgroundColor); - pdfImage->page(imageData.page); - - if (imageData.backgroundColor.a()<1.0f) - { - SetToTransparentBin sttb; - subgraph->accept(sttb); - } - - - } - - - return image; -} - -std::string SlideShowConstructor::findFileAndRecordPath(const std::string& filename) -{ - std::string foundFile = osgDB::findDataFile(filename, _options.get()); - if (foundFile.empty()) return foundFile; - - osg::notify(osg::INFO)<<"foundFile "<filePathList.begin(),_filePathData->filePathList.end(),path); - if (itr==_filePathData->filePathList.end()) - { - osg::notify(osg::INFO)<<"New path to record "<filePathList.push_front(path); - } - } - - return foundFile; - -} - -void SlideShowConstructor::addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData) -{ - osg::notify(osg::INFO)<<"SlideShowConstructor::addModel("<addDrawable(new osg::ShapeDrawable(new osg::Sphere)); - - subgraph = geode; - } - else if (filename=="box") - { - osg::Geode* geode = new osg::Geode; - geode->addDrawable(new osg::ShapeDrawable(new osg::Box)); - - subgraph = geode; - } - else - { - subgraph = osgDB::readNodeFile(filename, _options.get()); - if (subgraph) recordOptionsFilePath(_options.get()); - } - - if (subgraph) - { - addModel(subgraph, positionData, modelData); - } - - osg::notify(osg::INFO)<<"end of SlideShowConstructor::addModel("<setTextureUnit(1); - specularHighlights->addChild(subgraph); - subgraph = specularHighlights; - } - } - - if (positionData.frame==SLIDE) - { - osg::Vec3 pos = convertSlideToModel(positionData.position); - - const osg::BoundingSphere& bs = subgraph->getBound(); - float model_scale = positionData.scale.x()*_slideHeight*(1.0f-positionData.position.z())*0.7f/bs.radius(); - - osg::MatrixTransform* transform = new osg::MatrixTransform; - transform->setDataVariance(defaultMatrixDataVariance); - transform->setMatrix(osg::Matrix::translate(-bs.center())* - osg::Matrix::scale(model_scale,model_scale,model_scale)* - osg::Matrix::rotate(osg::DegreesToRadians(positionData.rotate[0]),positionData.rotate[1],positionData.rotate[2],positionData.rotate[3])* - osg::Matrix::translate(pos)); - - - transform->setStateSet(createTransformStateSet()); - transform->addChild(subgraph); - - subgraph = transform; - - } - else - { - osg::Matrix matrix(osg::Matrix::scale(1.0f/positionData.scale.x(),1.0f/positionData.scale.x(),1.0f/positionData.scale.x())* - osg::Matrix::rotate(osg::DegreesToRadians(positionData.rotate[0]),positionData.rotate[1],positionData.rotate[2],positionData.rotate[3])* - osg::Matrix::translate(positionData.position)); - - osg::MatrixTransform* transform = new osg::MatrixTransform; - transform->setDataVariance(defaultMatrixDataVariance); - transform->setMatrix(osg::Matrix::inverse(matrix)); - - osg::notify(osg::INFO)<<"Position Matrix "<getMatrix()<addChild(subgraph); - - subgraph = transform; - } - - float referenceSizeRatio = 0.707; - float referenceSize = subgraph->getBound().radius() * referenceSizeRatio; - - - // attach any meterial animation. - if (positionData.requiresMaterialAnimation()) - subgraph = attachMaterialAnimation(subgraph,positionData); - - // attached any rotation - if (positionData.rotation[0]!=0.0) - { - osg::MatrixTransform* animation_transform = new osg::MatrixTransform; - animation_transform->setDataVariance(osg::Object::DYNAMIC); - animation_transform->setUpdateCallback( - new osgUtil::TransformCallback(subgraph->getBound().center(), - osg::Vec3(positionData.rotation[1],positionData.rotation[2],positionData.rotation[3]), - osg::DegreesToRadians(positionData.rotation[0]))); - - animation_transform->addChild(subgraph); - - osg::notify(osg::INFO)<<"Rotation Matrix "<getMatrix()<getBound().center(); - - osg::AnimationPath* path = animation->getAnimationPath(); - if (positionData.animation_name=="wheel" && (path->getTimeControlPointMap()).size()>=2) - { - osg::notify(osg::INFO)<<"**** Need to handle special wheel animation"<getTimeControlPointMap(); - - osg::AnimationPath::TimeControlPointMap::iterator curr_itr = controlPoints.begin(); - osg::AnimationPath::TimeControlPointMap::iterator prev_itr=curr_itr; - ++curr_itr; - - osg::AnimationPath::ControlPoint* prev_cp = &(prev_itr->second); - osg::AnimationPath::ControlPoint* curr_cp = &(curr_itr->second); - - float totalLength = 0; - float rotation_y_axis = 0; - osg::Vec3 delta_position = curr_cp->getPosition() - prev_cp->getPosition(); - float rotation_z_axis = atan2f(delta_position.y(),delta_position.x()); - - osg::Quat quat_y_axis,quat_z_axis,quat_combined; - - quat_y_axis.makeRotate(rotation_y_axis,0.0f,1.0f,0.0f); - quat_z_axis.makeRotate(rotation_z_axis,0.0f,0.0f,1.0f); - quat_combined = quat_y_axis*quat_z_axis; - - // set first rotation. - prev_cp->setRotation(quat_combined); - - for(; - curr_itr!=controlPoints.end(); - ++curr_itr) - { - prev_cp = &(prev_itr->second); - curr_cp = &(curr_itr->second); - - delta_position = curr_cp->getPosition() - prev_cp->getPosition(); - - totalLength += delta_position.length(); - - // rolling - rotation about the y axis. - rotation_y_axis = totalLength/referenceSize; - - // direction - rotation about the z axis. - rotation_z_axis = atan2f(delta_position.y(),delta_position.x()); - - osg::notify(osg::INFO)<<" rotation_y_axis="< volume = new osgVolume::Volume; - osg::ref_ptr tile = new osgVolume::VolumeTile; - volume->addChild(tile.get()); - - osg::ref_ptr layer = new osgVolume::ImageLayer(image.get()); - layer->rescaleToZeroToOneRange(); - - osg::RefMatrix* matrix = dynamic_cast(image->getUserData()); - if (matrix) - { - osgVolume::Locator* locator = new osgVolume::Locator(*matrix); - layer->setLocator(locator); - tile->setLocator(locator); - } - - tile->setLayer(layer.get()); - - float alphaFunc = 0.1; - - osgVolume::SwitchProperty* sp = new osgVolume::SwitchProperty; - sp->setActiveProperty(0); - - osgVolume::AlphaFuncProperty* ap = new osgVolume::AlphaFuncProperty(alphaFunc); - osgVolume::SampleDensityProperty* sd = new osgVolume::SampleDensityProperty(0.005); - osgVolume::TransparencyProperty* tp = new osgVolume::TransparencyProperty(1.0); - - { - // Standard - osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; - cp->addProperty(ap); - cp->addProperty(sd); - cp->addProperty(tp); - - sp->addProperty(cp); - } - - { - // Light - osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; - cp->addProperty(ap); - cp->addProperty(sd); - cp->addProperty(tp); - cp->addProperty(new osgVolume::LightingProperty); - - sp->addProperty(cp); - } - - { - // Isosurface - osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; - cp->addProperty(sd); - cp->addProperty(tp); - cp->addProperty(new osgVolume::IsoSurfaceProperty(alphaFunc)); - - sp->addProperty(cp); - } - - { - // MaximumIntensityProjection - osgVolume::CompositeProperty* cp = new osgVolume::CompositeProperty; - cp->addProperty(ap); - cp->addProperty(sd); - cp->addProperty(tp); - cp->addProperty(new osgVolume::MaximumIntensityProjectionProperty); - - sp->addProperty(cp); - } - - layer->addProperty(sp); - tile->setVolumeTechnique(new osgVolume::RayTracedTechnique); - tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); - - ModelData modelData; - addModel(volume.get(), positionData, modelData); -} - -bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle) -{ - float xScale = textureRectangle ? s : 1.0f; - float yScale = textureRectangle ? t : 1.0f; - - float sx = (textureRectangle ? s : 1.0f) / (imageData.region_in_pixel_coords ? s : 1.0f); - float sy = (textureRectangle ? t : 1.0f) / (imageData.region_in_pixel_coords ? t : 1.0f); - - float x1 = imageData.region[0]*sx; - float y1 = imageData.region[1]*sy; - float x2 = imageData.region[2]*sx; - float y2 = imageData.region[3]*sy; - - if (x1!=0.0f || y1!=0.0f || x2!=xScale || y2 != yScale || - imageData.texcoord_rotate != 0.0f) - { - osg::TexMat* texmat = new osg::TexMat; - texmat->setMatrix(osg::Matrix::translate(-0.5f*xScale,-0.5f*yScale,0.0f)* - osg::Matrix::rotate(osg::DegreesToRadians(imageData.texcoord_rotate),0.0f,0.0f,1.0f)* - osg::Matrix::translate(0.5f*xScale,0.5f*yScale,0.0f)* - osg::Matrix::scale((x2-x1)/xScale,(y2-y1)/yScale,1.0f)* - osg::Matrix::translate(x1, - y1, - 0.0f)); - - stateset->setTextureAttribute(0,texmat); - return true; - } - return false; -} - -osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const PositionData& positionData) -{ - ss3d::AnimationMaterial* animationMaterial = 0; - - if (!positionData.animation_material_filename.empty()) - { -#if 0 - std::string absolute_animation_file_path = osgDB::findDataFile(positionData.animation_material_filename, _options.get()); - if (!absolute_animation_file_path.empty()) - { - std::ifstream animation_filestream(absolute_animation_file_path.c_str()); - if (!animation_filestream.eof()) - { - animationMaterial = new ss3d::AnimationMaterial; - animationMaterial->read(animation_filestream); - } - } -#else - osg::ref_ptr object = osgDB::readObjectFile(positionData.animation_material_filename, _options.get()); - animationMaterial = dynamic_cast(object.get()); -#endif - - } - else if (!positionData.fade.empty()) - { - std::istringstream iss(positionData.fade); - - animationMaterial = new ss3d::AnimationMaterial; - while (!iss.fail() && !iss.eof()) - { - float time=1.0f, alpha=1.0f; - iss >> time >> alpha; - if (!iss.fail()) - { - osg::Material* material = new osg::Material; - material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,alpha)); - material->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,alpha)); - animationMaterial->insert(time,material); - } - } - } - - if (animationMaterial) - { - animationMaterial->setLoopMode(positionData.animation_material_loop_mode); - - ss3d::AnimationMaterialCallback* animationMaterialCallback = new ss3d::AnimationMaterialCallback(animationMaterial); - animationMaterialCallback->setTimeOffset(positionData.animation_material_time_offset); - animationMaterialCallback->setTimeMultiplier(positionData.animation_material_time_multiplier); - - osg::Group* decorator = new osg::Group; - decorator->addChild(model); - - decorator->setUpdateCallback(animationMaterialCallback); - - if (animationMaterial->requiresBlending()) - { - SetToTransparentBin sttb; - decorator->accept(sttb); - } - - return decorator; - } - - return model; -} - -osg::AnimationPathCallback* SlideShowConstructor::getAnimationPathCallback(const PositionData& positionData) -{ - if (!positionData.path.empty()) - { - osg::ref_ptr object = osgDB::readObjectFile(positionData.path, _options.get()); - osg::AnimationPath* animation = dynamic_cast(object.get()); - if (animation) - { - if (positionData.frame==SlideShowConstructor::SLIDE) - { - osg::AnimationPath::TimeControlPointMap& controlPoints = animation->getTimeControlPointMap(); - for(osg::AnimationPath::TimeControlPointMap::iterator itr=controlPoints.begin(); - itr!=controlPoints.end(); - ++itr) - { - osg::AnimationPath::ControlPoint& cp = itr->second; - cp.setPosition(convertSlideToModel(cp.getPosition()+positionData.position)); - } - } - - animation->setLoopMode(positionData.path_loop_mode); - - osg::AnimationPathCallback* apc = new osg::AnimationPathCallback(animation); - apc->setTimeOffset(positionData.path_time_offset); - apc->setTimeMultiplier(positionData.path_time_multiplier); - apc->setUseInverseMatrix(positionData.inverse_path); - - osg::notify(osg::INFO)<<"UseInverseMatrix "<getPluginStringData("filename"); - std::string path = osgDB::getFilePath(filename_used); - if (!path.empty() && _filePathData.valid()) - { - osgDB::FilePathList::iterator itr = std::find(_filePathData->filePathList.begin(),_filePathData->filePathList.end(),path); - if (itr==_filePathData->filePathList.end()) - { - osg::notify(osg::INFO)<<"SlideShowConstructor::recordOptionsFilePath(..) - new path to record path="<setDuration(duration); - } - - void addKey(osg::Node* node,const KeyPosition& kp) - { - getOrCreateLayerAttributes(node)->addKey(kp); - } - - void addRunString(osg::Node* node, const std::string& runString) - { - getOrCreateLayerAttributes(node)->addRunString(runString); - } - - void setJump(osg::Node* node, bool relativeJump, int slideNum, int layerNum) - { - getOrCreateLayerAttributes(node)->setJump(relativeJump, slideNum, layerNum); - } - - void addPresentationKey(const KeyPosition& kp) - { - if (!_presentationSwitch) createPresentation(); - if (_presentationSwitch.valid()) addKey( _presentationSwitch.get(), kp); - } - - void addPresentationRunString(const std::string& runString) - { - if (!_presentationSwitch) createPresentation(); - if (_presentationSwitch.valid()) addRunString( _presentationSwitch.get(),runString); - } - - void addSlideKey(const KeyPosition& kp) - { - if (!_slide) addSlide(); - if (_slide.valid()) addKey(_slide.get(),kp); - } - - void addSlideRunString(const std::string& runString) - { - if (!_slide) addSlide(); - if (_slide.valid()) addRunString(_slide.get(),runString); - } - - void setSlideJump(bool relativeJump, int switchNum, int layerNum) - { - if (!_slide) addSlide(); - if (_slide.valid()) setJump(_slide.get(),relativeJump, switchNum, layerNum); - } - - void addLayerKey(const KeyPosition& kp) - { - if (!_currentLayer) addLayer(); - if (_currentLayer.valid()) addKey(_currentLayer.get(),kp); - } - - void addLayerRunString(const std::string& runString) - { - if (!_currentLayer) addLayer(); - if (_currentLayer.valid()) addRunString(_currentLayer.get(),runString); - } - - - void setLayerJump(bool relativeJump, int switchNum, int layerNum) - { - if (!_currentLayer) addLayer(); - if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum); - } - - - - struct PositionData - { - PositionData(): - frame(SlideShowConstructor::SLIDE), - position(0.0f,1.0f,0.0f), - //position(0.5f,0.5f,0.0f), - scale(1.0f,1.0f,1.0f), - rotate(0.0f,0.0f,0.0f,1.0f), - rotation(0.0f,0.0f,1.0f,0.0f), - absolute_path(false), - inverse_path(false), - path_time_offset(0.0), - path_time_multiplier(1.0f), - path_loop_mode(osg::AnimationPath::NO_LOOPING), - animation_material_time_offset(0.0), - animation_material_time_multiplier(1.0), - animation_material_loop_mode(ss3d::AnimationMaterial::NO_LOOPING) {} - - bool requiresPosition() const - { - return (position[0]!=0.0f || position[1]!=1.0f || position[2]!=1.0f); - } - - bool requiresScale() const - { - return (scale[0]!=1.0f || scale[1]!=1.0f || scale[2]!=1.0f); - } - - bool requiresRotate() const - { - return rotate[0]!=0.0f; - } - - bool requiresAnimation() const - { - return (rotation[0]!=0.0f || !path.empty()); - } - - bool requiresMaterialAnimation() const - { - return !animation_material_filename.empty() || !fade.empty(); - } - - CoordinateFrame frame; - osg::Vec3 position; - osg::Vec3 scale; - osg::Vec4 rotate; - osg::Vec4 rotation; - std::string animation_name; - bool absolute_path; - bool inverse_path; - double path_time_offset; - double path_time_multiplier; - osg::AnimationPath::LoopMode path_loop_mode; - std::string path; - double animation_material_time_offset; - double animation_material_time_multiplier; - ss3d::AnimationMaterial::LoopMode animation_material_loop_mode; - std::string animation_material_filename; - std::string fade; - }; - - struct ModelData - { - ModelData(): - effect("") {} - - std::string effect; - }; - - struct ImageData - { - ImageData(): - width(1.0f), - height(1.0f), - region(0.0f,0.0f,1.0f,1.0f), - region_in_pixel_coords(false), - texcoord_rotate(0.0f), - loopingMode(osg::ImageStream::NO_LOOPING), - page(-1), - backgroundColor(1.0f,1.0f,1.0f,1.0f) {} - - float width; - float height; - osg::Vec4 region; - bool region_in_pixel_coords; - float texcoord_rotate; - osg::ImageStream::LoopingMode loopingMode; - int page; - osg::Vec4 backgroundColor; - }; - - struct FontData - { - FontData(): - font("fonts/arial.ttf"), - layout(osgText::Text::LEFT_TO_RIGHT), - alignment(osgText::Text::LEFT_BASE_LINE), - axisAlignment(osgText::Text::XZ_PLANE), - characterSize(0.04f), - maximumHeight(1.0f), - maximumWidth(1.0f), - color(1.0f,1.0f,1.0f,1.0f) {} - - std::string font; - osgText::Text::Layout layout; - osgText::Text::AlignmentType alignment; - osgText::Text::AxisAlignment axisAlignment; - float characterSize; - float maximumHeight; - float maximumWidth; - osg::Vec4 color; - }; - - - SlideShowConstructor(const osgDB::ReaderWriter::Options* options); - - void createPresentation(); - - void setBackgroundColor(const osg::Vec4& color, bool updateClearNode); - const osg::Vec4& getBackgroundColor() const { return _backgroundColor; } - - void setTextColor(const osg::Vec4& color); - const osg::Vec4& getTextColor() const { return _textFontDataDefault.color; } - - void setPresentationName(const std::string& name); - - void setPresentationAspectRatio(float aspectRatio); - - void setPresentationAspectRatio(const std::string& str); - - void setPresentationDuration(double duration); - - - void addSlide(); - - void selectSlide(int slideNum); - - - void setSlideTitle(const std::string& name, PositionData& positionData, FontData& fontData) - { - _titlePositionData = positionData; - _titleFontData = fontData; - _slideTitle = name; - } - - void setSlideBackground(const std::string& name) { _slideBackgroundImageFileName = name; } - - void setSlideDuration(double duration); - - - void addLayer(bool inheritPreviousLayers=true, bool defineAsBaseLayer=false); - - void selectLayer(int layerNum); - - void setLayerDuration(double duration); - - - // title settings - FontData& getTitleFontData() { return _titleFontData; } - FontData& getTitleFontDataDefault() { return _titleFontDataDefault; } - - PositionData& getTitlePositionData() { return _titlePositionData; } - PositionData& getTitlePositionDataDefault() { return _titlePositionDataDefault; } - - // text settings - FontData& getTextFontData() { return _textFontData; } - FontData& getTextFontDataDefault() { return _textFontDataDefault; } - - PositionData& getTextPositionData() { return _textPositionData; } - PositionData& getTextPositionDataDefault() { return _textPositionDataDefault; } - - void translateTextCursor(const osg::Vec3& delta) { _textPositionData.position += delta; } - - // image settings - PositionData& getImagePositionData() { return _imagePositionData; } - PositionData& getImagePositionDataDefault() { return _imagePositionDataDefault; } - - // model settings - PositionData& getModelPositionData() { return _modelPositionData; } - PositionData& getModelPositionDataDefault() { return _modelPositionDataDefault; } - - - void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); - - void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData); - - void addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData); - - void addImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData); - - void addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight,const ImageData& imageDataRight, const PositionData& positionData); - - void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData); - void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData); - void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData); - osg::Image* addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData); - - void addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData); - - void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData); - - void addVolume(const std::string& filename, const PositionData& positionData); - - osg::Group* takePresentation() { return _root.release(); } - - osg::Group* getPresentation() { return _root.get(); } - - osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); } - - osg::Switch* getCurrentSlide() { return _slide.get(); } - - osg::Group* getCurrentLayer() { return _currentLayer.get(); } - - void setLoopPresentation(bool loop) { _loopPresentation = loop; } - bool getLoopPresentation() const { return _loopPresentation; } - - void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; } - bool getAutoSteppingActive() const { return _autoSteppingActive; } - -protected: - - void findImageStreamsAndAddCallbacks(osg::Node* node); - - osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos, const osg::Vec4& rotation, float width,float height, osg::Image* image, bool& usedTextureRectangle); - - osg::Vec3 computePositionInModelCoords(const PositionData& positionData) const; - void updatePositionFromInModelCoords(const osg::Vec3& vertex, PositionData& positionData) const; - - osg::Vec3 convertSlideToModel(const osg::Vec3& position) const; - osg::Vec3 convertModelToSlide(const osg::Vec3& position) const; - - osg::AnimationPathCallback* getAnimationPathCallback(const PositionData& positionData); - - osg::Node* attachMaterialAnimation(osg::Node* model, const PositionData& positionData); - bool attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle); - - osg::StateSet* createTransformStateSet() - { - osg::StateSet* stateset = new osg::StateSet; - stateset->setMode(GL_NORMALIZE,osg::StateAttribute::ON); - return stateset; - } - - osg::ref_ptr _options; - - osg::Vec3 _slideOrigin; - osg::Vec3 _eyeOrigin; - float _slideWidth; - float _slideHeight; - float _slideDistance; - - // title settings - FontData _titleFontData; - FontData _titleFontDataDefault; - - PositionData _titlePositionData; - PositionData _titlePositionDataDefault; - - // text settings - FontData _textFontData; - FontData _textFontDataDefault; - - PositionData _textPositionData; - PositionData _textPositionDataDefault; - - // image settings - PositionData _imagePositionData; - PositionData _imagePositionDataDefault; - - // model settings - PositionData _modelPositionData; - PositionData _modelPositionDataDefault; - - - bool _loopPresentation; - bool _autoSteppingActive; - osg::Vec4 _backgroundColor; - std::string _presentationName; - double _presentationDuration; - - osg::ref_ptr _root; - osg::ref_ptr _presentationSwitch; - - osg::ref_ptr _slideClearNode; - osg::ref_ptr _slide; - std::string _slideTitle; - std::string _slideBackgroundImageFileName; - - osg::ref_ptr _previousLayer; - osg::ref_ptr _currentLayer; - - osg::ref_ptr _filePathData; - - std::string findFileAndRecordPath(const std::string& filename); - - void recordOptionsFilePath(const osgDB::Options* options); - -}; - -} - -#endif diff --git a/applications/present3D/AnimationMaterial.cpp b/src/osgPresentation/AnimationMaterial.cpp similarity index 98% rename from applications/present3D/AnimationMaterial.cpp rename to src/osgPresentation/AnimationMaterial.cpp index 1f9a65f3c..f62f573f5 100644 --- a/applications/present3D/AnimationMaterial.cpp +++ b/src/osgPresentation/AnimationMaterial.cpp @@ -10,13 +10,14 @@ * include LICENSE.txt for more details. */ -#include "AnimationMaterial.h" +#include + #include #include #include #include -using namespace ss3d; +using namespace osgPresentation; void AnimationMaterial::insert(double time,osg::Material* material) { diff --git a/src/osgPlugins/p3d/CompileSlideCallback.cpp b/src/osgPresentation/CompileSlideCallback.cpp similarity index 94% rename from src/osgPlugins/p3d/CompileSlideCallback.cpp rename to src/osgPresentation/CompileSlideCallback.cpp index fa19d89d3..f95188da8 100644 --- a/src/osgPlugins/p3d/CompileSlideCallback.cpp +++ b/src/osgPresentation/CompileSlideCallback.cpp @@ -10,11 +10,11 @@ * include LICENSE.txt for more details. */ -#include "CompileSlideCallback.h" +#include #include -using namespace ss3d; +using namespace osgPresentation; void CompileSlideCallback::operator()(const osg::Camera & camera) const { diff --git a/src/osgPlugins/p3d/PickEventHandler.cpp b/src/osgPresentation/PickEventHandler.cpp similarity index 98% rename from src/osgPlugins/p3d/PickEventHandler.cpp rename to src/osgPresentation/PickEventHandler.cpp index 5bf8b9a42..71e5f4c36 100644 --- a/src/osgPlugins/p3d/PickEventHandler.cpp +++ b/src/osgPresentation/PickEventHandler.cpp @@ -10,8 +10,8 @@ * include LICENSE.txt for more details. */ -#include "PickEventHandler.h" -#include "SlideEventHandler.h" +#include +#include #include #include diff --git a/applications/present3D/SlideEventHandler.cpp b/src/osgPresentation/SlideEventHandler.cpp similarity index 98% rename from applications/present3D/SlideEventHandler.cpp rename to src/osgPresentation/SlideEventHandler.cpp index 949cae77c..b60b6a3c8 100644 --- a/applications/present3D/SlideEventHandler.cpp +++ b/src/osgPresentation/SlideEventHandler.cpp @@ -10,8 +10,8 @@ * include LICENSE.txt for more details. */ -#include "SlideEventHandler.h" -#include "SlideShowConstructor.h" +#include +#include #include #include @@ -25,7 +25,7 @@ #include -#include "AnimationMaterial.h" +#include #include @@ -138,7 +138,7 @@ struct CallbackOperator : public ObjectOperator { osg::AnimationPathCallback* apc = dynamic_cast(_callback.get()); osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); - ss3d::AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); + AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); if (apc) { osg::notify(osg::INFO)<<"apc->setPause("<(_callback.get()); osgUtil::TransformCallback* tc = dynamic_cast(_callback.get()); - ss3d::AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); + AnimationMaterialCallback* amc = dynamic_cast(_callback.get()); if (apc) { apc->reset(); @@ -1294,7 +1294,7 @@ void SlideEventHandler::compileSlide(unsigned int slideNum) { if (!_compileSlideCallback) { - _compileSlideCallback = new ss3d::CompileSlideCallback(); + _compileSlideCallback = new CompileSlideCallback(); osgViewer::Viewer::Cameras cameras; _viewer->getCameras(cameras); diff --git a/applications/present3D/SlideShowConstructor.cpp b/src/osgPresentation/SlideShowConstructor.cpp similarity index 99% rename from applications/present3D/SlideShowConstructor.cpp rename to src/osgPresentation/SlideShowConstructor.cpp index b5ea4be2e..5c0a29abe 100644 --- a/applications/present3D/SlideShowConstructor.cpp +++ b/src/osgPresentation/SlideShowConstructor.cpp @@ -10,7 +10,7 @@ * include LICENSE.txt for more details. */ -#include "SlideShowConstructor.h" +#include #include #include @@ -47,8 +47,8 @@ #include #include -#include "AnimationMaterial.h" -#include "PickEventHandler.h" +#include +#include using namespace osgPresentation; @@ -1571,7 +1571,7 @@ bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const PositionData& positionData) { - ss3d::AnimationMaterial* animationMaterial = 0; + AnimationMaterial* animationMaterial = 0; if (!positionData.animation_material_filename.empty()) { @@ -1582,13 +1582,13 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const std::ifstream animation_filestream(absolute_animation_file_path.c_str()); if (!animation_filestream.eof()) { - animationMaterial = new ss3d::AnimationMaterial; + animationMaterial = new AnimationMaterial; animationMaterial->read(animation_filestream); } } #else osg::ref_ptr object = osgDB::readObjectFile(positionData.animation_material_filename, _options.get()); - animationMaterial = dynamic_cast(object.get()); + animationMaterial = dynamic_cast(object.get()); #endif } @@ -1596,7 +1596,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const { std::istringstream iss(positionData.fade); - animationMaterial = new ss3d::AnimationMaterial; + animationMaterial = new AnimationMaterial; while (!iss.fail() && !iss.eof()) { float time=1.0f, alpha=1.0f; @@ -1615,7 +1615,7 @@ osg::Node* SlideShowConstructor::attachMaterialAnimation(osg::Node* model, const { animationMaterial->setLoopMode(positionData.animation_material_loop_mode); - ss3d::AnimationMaterialCallback* animationMaterialCallback = new ss3d::AnimationMaterialCallback(animationMaterial); + AnimationMaterialCallback* animationMaterialCallback = new AnimationMaterialCallback(animationMaterial); animationMaterialCallback->setTimeOffset(positionData.animation_material_time_offset); animationMaterialCallback->setTimeMultiplier(positionData.animation_material_time_multiplier);