From 09e7bcdf4e2501a55eec59d1a7b18ef90603b33b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 21 Jul 2008 10:10:01 +0000 Subject: [PATCH] Added ImagePager first cut, and updated wrappers --- include/osgDB/ImagePager | 94 +++++++ src/osgDB/ImagePager.cpp | 66 +++++ src/osgWrappers/osg/ImageStream.cpp | 5 +- src/osgWrappers/osgViewer/Scene.cpp | 19 ++ src/osgWrappers/osgViewer/View.cpp | 19 ++ .../osgViewer/ViewerEventHandlers.cpp | 258 ++++++++++++++++++ 6 files changed, 459 insertions(+), 2 deletions(-) create mode 100644 include/osgDB/ImagePager create mode 100644 src/osgDB/ImagePager.cpp diff --git a/include/osgDB/ImagePager b/include/osgDB/ImagePager new file mode 100644 index 000000000..2e59b6de9 --- /dev/null +++ b/include/osgDB/ImagePager @@ -0,0 +1,94 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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 + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGDB_IMAGEPAGER +#define OSGDB_IMAGEPAGER 1 + +#include + +#include +#include + +#include + +namespace osgDB +{ + +class OSGDB_EXPORT ImagePager : public osg::Referenced +{ + public: + + ImagePager(); + + struct ImageRequest : public osg::Referenced + { + ImageRequest(): + osg::Referenced(true) {} + + std::string _fileName; + osg::ref_ptr _loadOptions; + + + osg::ref_ptr _objectToAttachTo; + osg::ref_ptr _loadedImage; + + }; + + class OSGDB_EXPORT ImageThread : public osg::Referenced, public OpenThreads::Thread + { + public: + + enum Mode + { + HANDLE_ALL_REQUESTS, + HANDLE_NON_HTTP, + HANDLE_ONLY_HTTP + }; + + ImageThread(ImagePager* pager, Mode mode, const std::string& name); + + ImageThread(const ImageThread& dt, ImagePager* pager); + + void setDone(bool done) { _done = done; } + bool getDone() const { return _done; } + + virtual int cancel(); + + virtual void run(); + + protected: + + virtual ~ImageThread(); + + bool _done; + ImagePager* _pager; + Mode _mode; + std::string _name; + }; + + /** Return true if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */ + bool requiresUpdateSceneGraph() const; + + /** Merge the changes to the scene graph. */ + virtual void updateSceneGraph(double currentFrameTime); + + public: + + virtual ~ImagePager(); +}; + + +} + +#endif + diff --git a/src/osgDB/ImagePager.cpp b/src/osgDB/ImagePager.cpp new file mode 100644 index 000000000..26c6dc1af --- /dev/null +++ b/src/osgDB/ImagePager.cpp @@ -0,0 +1,66 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library 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 + * OpenSceneGraph Public License for more details. +*/ + +#include + +#include + +using namespace osgDB; + +////////////////////////////////////////////////////////////////////////////////////// +// +// ImageThread +// +ImagePager::ImageThread::ImageThread(ImagePager* pager, Mode mode, const std::string& name) +{ +} + +ImagePager::ImageThread::ImageThread(const ImageThread& dt, ImagePager* pager) +{ +} + +ImagePager::ImageThread::~ImageThread() +{ +} + +int ImagePager::ImageThread::cancel() +{ +} + +void ImagePager::ImageThread::run() +{ +} + +////////////////////////////////////////////////////////////////////////////////////// +// +// ImagePager +// +ImagePager::ImagePager() +{ +} + +ImagePager::~ImagePager() +{ +} + +bool ImagePager::requiresUpdateSceneGraph() const +{ + //osg::notify(osg::NOTICE)<<"ImagePager::requiresUpdateSceneGraph()"< #include +#include #include #include #include @@ -147,9 +148,9 @@ BEGIN_OBJECT_REFLECTOR(osg::ImageStream) __float__getVolume, "", ""); - I_Method0(void, update, + I_Method1(void, update, IN, osg::FrameStamp *, fs, Properties::VIRTUAL, - __void__update, + __void__update__osg_FrameStamp_P1, "", ""); I_ProtectedMethod0(void, applyLoopingMode, diff --git a/src/osgWrappers/osgViewer/Scene.cpp b/src/osgWrappers/osgViewer/Scene.cpp index bbffe81a3..61177bf17 100644 --- a/src/osgWrappers/osgViewer/Scene.cpp +++ b/src/osgWrappers/osgViewer/Scene.cpp @@ -12,6 +12,7 @@ #include #include +#include #include // Must undefine IN and OUT macros defined in Windows headers @@ -55,6 +56,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene) __C5_osgDB_DatabasePager_P1__getDatabasePager, "", ""); + I_Method1(void, setImagePager, IN, osgDB::ImagePager *, ip, + Properties::NON_VIRTUAL, + __void__setImagePager__osgDB_ImagePager_P1, + "", + ""); + I_Method0(osgDB::ImagePager *, getImagePager, + Properties::NON_VIRTUAL, + __osgDB_ImagePager_P1__getImagePager, + "", + ""); + I_Method0(const osgDB::ImagePager *, getImagePager, + Properties::NON_VIRTUAL, + __C5_osgDB_ImagePager_P1__getImagePager, + "", + ""); I_StaticMethod1(osgViewer::Scene *, getScene, IN, osg::Node *, node, __Scene_P1__getScene__osg_Node_P1_S, "Get the Scene object that has the specified node assigned to it. ", @@ -65,6 +81,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene) I_SimpleProperty(osgDB::DatabasePager *, DatabasePager, __osgDB_DatabasePager_P1__getDatabasePager, __void__setDatabasePager__osgDB_DatabasePager_P1); + I_SimpleProperty(osgDB::ImagePager *, ImagePager, + __osgDB_ImagePager_P1__getImagePager, + __void__setImagePager__osgDB_ImagePager_P1); I_SimpleProperty(osg::Node *, SceneData, __osg_Node_P1__getSceneData, __void__setSceneData__osg_Node_P1); diff --git a/src/osgWrappers/osgViewer/View.cpp b/src/osgWrappers/osgViewer/View.cpp index eb9b11850..9f23e609f 100644 --- a/src/osgWrappers/osgViewer/View.cpp +++ b/src/osgWrappers/osgViewer/View.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View) __C5_osgDB_DatabasePager_P1__getDatabasePager, "Get the const View's database pager. ", ""); + I_Method1(void, setImagePager, IN, osgDB::ImagePager *, ip, + Properties::NON_VIRTUAL, + __void__setImagePager__osgDB_ImagePager_P1, + "Set the View's image pager. ", + ""); + I_Method0(osgDB::ImagePager *, getImagePager, + Properties::NON_VIRTUAL, + __osgDB_ImagePager_P1__getImagePager, + "Get the View's image pager. ", + ""); + I_Method0(const osgDB::ImagePager *, getImagePager, + Properties::NON_VIRTUAL, + __C5_osgDB_ImagePager_P1__getImagePager, + "Get the const View's image pager. ", + ""); I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue, Properties::NON_VIRTUAL, __void__setEventQueue__osgGA_EventQueue_P1, @@ -345,6 +361,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View) I_SimpleProperty(float, FusionDistanceValue, __float__getFusionDistanceValue, 0); + I_SimpleProperty(osgDB::ImagePager *, ImagePager, + __osgDB_ImagePager_P1__getImagePager, + __void__setImagePager__osgDB_ImagePager_P1); I_SimpleProperty(osgViewer::Scene *, Scene, __Scene_P1__getScene, 0); diff --git a/src/osgWrappers/osgViewer/ViewerEventHandlers.cpp b/src/osgWrappers/osgViewer/ViewerEventHandlers.cpp index 89d3df931..fc87b6fe8 100644 --- a/src/osgWrappers/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgWrappers/osgViewer/ViewerEventHandlers.cpp @@ -11,7 +11,12 @@ #include #include +#include #include +#include +#include +#include +#include #include #include #include @@ -24,6 +29,14 @@ #undef OUT #endif +BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgViewer::CaptureOperation) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_BaseType(osg::Referenced); + I_Constructor0(____CaptureOperation, + "", + ""); +END_REFLECTOR + BEGIN_OBJECT_REFLECTOR(osgViewer::HelpHandler) I_DeclaringFile("osgViewer/ViewerEventHandlers"); I_BaseType(osgGA::GUIEventHandler); @@ -203,6 +216,56 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::RecordCameraPathHandler) __void__setKeyEventToggleRecord__int); END_REFLECTOR +BEGIN_OBJECT_REFLECTOR(osgViewer::ScreenCaptureHandler) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_BaseType(osgGA::GUIEventHandler); + I_Constructor0(____ScreenCaptureHandler, + "", + ""); + I_Method1(void, setKeyEventTakeScreenShot, IN, int, key, + Properties::NON_VIRTUAL, + __void__setKeyEventTakeScreenShot__int, + "", + ""); + I_Method0(int, getKeyEventTakeScreenShot, + Properties::NON_VIRTUAL, + __int__getKeyEventTakeScreenShot, + "", + ""); + I_Method1(void, setCaptureOperation, IN, osgViewer::CaptureOperation *, operation, + Properties::NON_VIRTUAL, + __void__setCaptureOperation__CaptureOperation_P1, + "", + ""); + I_Method0(osgViewer::CaptureOperation *, getCaptureOperation, + Properties::NON_VIRTUAL, + __CaptureOperation_P1__getCaptureOperation, + "", + ""); + I_Method2(bool, handle, IN, const osgGA::GUIEventAdapter &, ea, IN, osgGA::GUIActionAdapter &, aa, + Properties::VIRTUAL, + __bool__handle__C5_osgGA_GUIEventAdapter_R1__osgGA_GUIActionAdapter_R1, + "Deprecated, Handle events, return true if handled, false otherwise. ", + ""); + I_Method1(void, getUsage, IN, osg::ApplicationUsage &, usage, + Properties::VIRTUAL, + __void__getUsage__osg_ApplicationUsage_R1, + "Get the keyboard and mouse usage of this manipulator. ", + ""); + I_ProtectedMethod1(void, addCallbackToViewer, IN, osgViewer::ViewerBase &, viewer, + Properties::NON_VIRTUAL, + Properties::NON_CONST, + __void__addCallbackToViewer__osgViewer_ViewerBase_R1, + "", + ""); + I_SimpleProperty(osgViewer::CaptureOperation *, CaptureOperation, + __CaptureOperation_P1__getCaptureOperation, + __void__setCaptureOperation__CaptureOperation_P1); + I_SimpleProperty(int, KeyEventTakeScreenShot, + __int__getKeyEventTakeScreenShot, + __void__setKeyEventTakeScreenShot__int); +END_REFLECTOR + BEGIN_ENUM_REFLECTOR(osgViewer::StatsHandler::StatsType) I_DeclaringFile("osgViewer/ViewerEventHandlers"); I_EnumLabel(osgViewer::StatsHandler::NO_STATS); @@ -393,6 +456,129 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::ThreadingHandler) __void__setKeyEventChangeThreadingModel__int); END_REFLECTOR +TYPE_NAME_ALIAS(std::map< osg::GraphicsContext * COMMA osg::ref_ptr< osgViewer::WindowCaptureCallback::ContextData > >, osgViewer::WindowCaptureCallback::ContextDataMap) + +BEGIN_ENUM_REFLECTOR(osgViewer::WindowCaptureCallback::Mode) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_EnumLabel(osgViewer::WindowCaptureCallback::READ_PIXELS); + I_EnumLabel(osgViewer::WindowCaptureCallback::SINGLE_PBO); + I_EnumLabel(osgViewer::WindowCaptureCallback::DOUBLE_PBO); + I_EnumLabel(osgViewer::WindowCaptureCallback::TRIPLE_PBO); +END_REFLECTOR + +BEGIN_ENUM_REFLECTOR(osgViewer::WindowCaptureCallback::FramePosition) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_EnumLabel(osgViewer::WindowCaptureCallback::START_FRAME); + I_EnumLabel(osgViewer::WindowCaptureCallback::END_FRAME); +END_REFLECTOR + +BEGIN_OBJECT_REFLECTOR(osgViewer::WindowCaptureCallback) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_BaseType(osg::Camera::DrawCallback); + I_Constructor3(IN, osgViewer::WindowCaptureCallback::Mode, mode, IN, osgViewer::WindowCaptureCallback::FramePosition, position, IN, GLenum, readBuffer, + ____WindowCaptureCallback__Mode__FramePosition__GLenum, + "", + ""); + I_Method0(osgViewer::WindowCaptureCallback::FramePosition, getFramePosition, + Properties::NON_VIRTUAL, + __FramePosition__getFramePosition, + "", + ""); + I_Method1(osgViewer::WindowCaptureCallback::ContextData *, createContextData, IN, osg::GraphicsContext *, gc, + Properties::NON_VIRTUAL, + __ContextData_P1__createContextData__osg_GraphicsContext_P1, + "", + ""); + I_Method1(osgViewer::WindowCaptureCallback::ContextData *, getContextData, IN, osg::GraphicsContext *, gc, + Properties::NON_VIRTUAL, + __ContextData_P1__getContextData__osg_GraphicsContext_P1, + "", + ""); + I_Method1(void, setCaptureOperation, IN, osgViewer::CaptureOperation *, operation, + Properties::NON_VIRTUAL, + __void__setCaptureOperation__CaptureOperation_P1, + "", + ""); + I_Method0(osgViewer::CaptureOperation *, getCaptureOperation, + Properties::NON_VIRTUAL, + __CaptureOperation_P1__getCaptureOperation, + "", + ""); + I_SimpleProperty(osgViewer::CaptureOperation *, CaptureOperation, + __CaptureOperation_P1__getCaptureOperation, + __void__setCaptureOperation__CaptureOperation_P1); + I_SimpleProperty(osgViewer::WindowCaptureCallback::FramePosition, FramePosition, + __FramePosition__getFramePosition, + 0); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::Mode, _mode); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::FramePosition, _position); + I_PublicMemberProperty(GLenum, _readBuffer); + I_PublicMemberProperty(OpenThreads::Mutex, _mutex); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::ContextDataMap, _contextDataMap); +END_REFLECTOR + +TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osg::Image > >, osgViewer::WindowCaptureCallback::ContextData::ImageBuffer) + +TYPE_NAME_ALIAS(std::vector< GLuint >, osgViewer::WindowCaptureCallback::ContextData::PBOBuffer) + +BEGIN_OBJECT_REFLECTOR(osgViewer::WindowCaptureCallback::ContextData) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_BaseType(osg::Referenced); + I_Constructor3(IN, osg::GraphicsContext *, gc, IN, osgViewer::WindowCaptureCallback::Mode, mode, IN, GLenum, readBuffer, + ____ContextData__osg_GraphicsContext_P1__Mode__GLenum, + "", + ""); + I_Method3(void, getSize, IN, osg::GraphicsContext *, gc, IN, int &, width, IN, int &, height, + Properties::NON_VIRTUAL, + __void__getSize__osg_GraphicsContext_P1__int_R1__int_R1, + "", + ""); + I_Method4(void, updateTimings, IN, osg::Timer_t, tick_start, IN, osg::Timer_t, tick_afterReadPixels, IN, osg::Timer_t, tick_afterMemCpy, IN, unsigned int, dataSize, + Properties::NON_VIRTUAL, + __void__updateTimings__osg_Timer_t__osg_Timer_t__osg_Timer_t__unsigned_int, + "", + ""); + I_Method0(void, read, + Properties::NON_VIRTUAL, + __void__read, + "", + ""); + I_Method0(void, readPixels, + Properties::NON_VIRTUAL, + __void__readPixels, + "", + ""); + I_Method1(void, singlePBO, IN, osg::BufferObject::Extensions *, ext, + Properties::NON_VIRTUAL, + __void__singlePBO__osg_BufferObject_Extensions_P1, + "", + ""); + I_Method1(void, multiPBO, IN, osg::BufferObject::Extensions *, ext, + Properties::NON_VIRTUAL, + __void__multiPBO__osg_BufferObject_Extensions_P1, + "", + ""); + I_PublicMemberProperty(osg::GraphicsContext *, _gc); + I_PublicMemberProperty(unsigned int, _index); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::Mode, _mode); + I_PublicMemberProperty(GLenum, _readBuffer); + I_PublicMemberProperty(GLenum, _pixelFormat); + I_PublicMemberProperty(GLenum, _type); + I_PublicMemberProperty(int, _width); + I_PublicMemberProperty(int, _height); + I_PublicMemberProperty(unsigned int, _currentImageIndex); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::ContextData::ImageBuffer, _imageBuffer); + I_PublicMemberProperty(unsigned int, _currentPboIndex); + I_PublicMemberProperty(osgViewer::WindowCaptureCallback::ContextData::PBOBuffer, _pboBuffer); + I_PublicMemberProperty(unsigned int, _reportTimingFrequency); + I_PublicMemberProperty(unsigned int, _numTimeValuesRecorded); + I_PublicMemberProperty(double, _timeForReadPixels); + I_PublicMemberProperty(double, _timeForFullCopy); + I_PublicMemberProperty(double, _timeForMemCpy); + I_PublicMemberProperty(osg::Timer_t, _previousFrameTick); + I_PublicMemberProperty(osg::ref_ptr< osgViewer::CaptureOperation >, _captureOperation); +END_REFLECTOR + BEGIN_OBJECT_REFLECTOR(osgViewer::WindowSizeHandler) I_DeclaringFile("osgViewer/ViewerEventHandlers"); I_BaseType(osgGA::GUIEventHandler); @@ -494,3 +680,75 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::WindowSizeHandler) __void__setToggleFullscreen__bool); END_REFLECTOR +BEGIN_ENUM_REFLECTOR(osgViewer::WriteToFileCaptureOperation::SavePolicy) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_EnumLabel(osgViewer::WriteToFileCaptureOperation::OVERWRITE); + I_EnumLabel(osgViewer::WriteToFileCaptureOperation::SEQUENTIAL_NUMBER); +END_REFLECTOR + +BEGIN_OBJECT_REFLECTOR(osgViewer::WriteToFileCaptureOperation) + I_DeclaringFile("osgViewer/ViewerEventHandlers"); + I_BaseType(osgViewer::CaptureOperation); + I_ConstructorWithDefaults3(IN, const std::string &, filename, , IN, const std::string &, extension, , IN, osgViewer::WriteToFileCaptureOperation::SavePolicy, savePolicy, osgViewer::WriteToFileCaptureOperation::OVERWRITE, + ____WriteToFileCaptureOperation__C5_std_string_R1__C5_std_string_R1__SavePolicy, + "", + ""); + I_Method1(void, setSavePolicy, IN, osgViewer::WriteToFileCaptureOperation::SavePolicy, savePolicy, + Properties::NON_VIRTUAL, + __void__setSavePolicy__SavePolicy, + "", + ""); + I_Method0(osgViewer::WriteToFileCaptureOperation::SavePolicy, getSavePolicy, + Properties::NON_VIRTUAL, + __SavePolicy__getSavePolicy, + "", + ""); + I_SimpleProperty(osgViewer::WriteToFileCaptureOperation::SavePolicy, SavePolicy, + __SavePolicy__getSavePolicy, + __void__setSavePolicy__SavePolicy); +END_REFLECTOR + +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgViewer::WindowCaptureCallback::ContextData >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osgViewer::WindowCaptureCallback::ContextData *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osgViewer::WindowCaptureCallback::ContextData > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osgViewer::WindowCaptureCallback::ContextData *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osgViewer::WindowCaptureCallback::ContextData *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osgViewer::WindowCaptureCallback::ContextData > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osgViewer::WindowCaptureCallback::ContextData *, , + __T_P1__get, + 0); +END_REFLECTOR + +STD_MAP_REFLECTOR(std::map< osg::GraphicsContext * COMMA osg::ref_ptr< osgViewer::WindowCaptureCallback::ContextData > >) + +STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osg::Image > >) +