Hi Robert,
Here's a small number of updated API spelling cases
(include/osgVolume/Property and include/osgWidget/WindowManager).
Unfortunately, some of them are in the public API of osgVolume.
Paul
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 OSGVOLUME_PROPERTY
#define OSGVOLUME_PROPERTY 1
#include <osg/TransferFunction>
#include <osg/Uniform>
#include <osg/AlphaFunc>
#include <osgGA/GUIEventHandler>
#include <osgVolume/Export>
namespace osgVolume {
// forward decarle
class Property;
class CompositeProperty;
class SwitchProperty;
class TransferFunctionProperty;
class ScalarProperty;
class IsoSurfaceProperty;
class MaximumIntensityProjectionProperty;
class LightingProperty;
class AlphaFuncProperty;
class SampleDensityProperty;
class TransparencyProperty;
class OSGVOLUME_EXPORT PropertyVisitor
{
public:
PropertyVisitor(bool traverseOnlyActiveChildren=true);
virtual ~PropertyVisitor() {}
virtual void apply(Property&) {}
virtual void apply(CompositeProperty&);
virtual void apply(SwitchProperty&);
virtual void apply(TransferFunctionProperty&) {}
virtual void apply(ScalarProperty&) {}
virtual void apply(IsoSurfaceProperty&) {}
virtual void apply(AlphaFuncProperty&) {}
virtual void apply(MaximumIntensityProjectionProperty&) {}
virtual void apply(LightingProperty&) {}
virtual void apply(SampleDensityProperty&) {}
virtual void apply(TransparencyProperty&) {}
bool _traverseOnlyActiveChildren;
};
class OSGVOLUME_EXPORT Property : public osg::Object
{
public:
Property();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Property(const Property&,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, Property);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~Property();
};
class OSGVOLUME_EXPORT CompositeProperty : public Property
{
public:
CompositeProperty();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
CompositeProperty(const CompositeProperty& compositeProperty,const
osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, CompositeProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
void clear();
typedef std::vector< osg::ref_ptr<Property> > Properties;
void setProperty(unsigned int i, Property* property) { if
(i>=_properties.size()) _properties.resize(i+1); _properties[i] = property; }
Property* getProperty(unsigned int i) { return i<_properties.size() ?
_properties[i].get() : 0; }
const Property* getProperty(unsigned int i) const { return
i<_properties.size() ? _properties[i].get() : 0; }
void addProperty(Property* property) { _properties.push_back(property);
}
void removeProperty(unsigned int i) {
_properties.erase(_properties.begin()+i); }
unsigned int getNumProperties() const { return _properties.size(); }
protected:
virtual ~CompositeProperty() {}
Properties _properties;
};
class OSGVOLUME_EXPORT SwitchProperty : public CompositeProperty
{
public:
SwitchProperty();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
SwitchProperty(const SwitchProperty& switchProperty,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, SwitchProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
/** Set which child property is active.
* -1 disables all children.*/
void setActiveProperty(int i) { _activeProperty = i; }
/** Get the active property.*/
int getActiveProperty() const { return _activeProperty; }
protected:
virtual ~SwitchProperty() {}
int _activeProperty;
};
class OSGVOLUME_EXPORT TransferFunctionProperty : public Property
{
public:
TransferFunctionProperty(osg::TransferFunction* tf = 0);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TransferFunctionProperty(const TransferFunctionProperty& tfp,const
osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, TransferFunctionProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
/** Set the transfer function.*/
void setTransferFunction(osg::TransferFunction* tf) { _tf = tf; }
/** Get the transfer function.*/
osg::TransferFunction* getTransferFunction() { return _tf.get(); }
/** Get the const transfer function.*/
const osg::TransferFunction* getTransferFunction() const { return
_tf.get(); }
protected:
virtual ~TransferFunctionProperty() {}
osg::ref_ptr<osg::TransferFunction> _tf;
};
class OSGVOLUME_EXPORT ScalarProperty : public Property
{
public:
ScalarProperty(const std::string& scaleName, float value);
ScalarProperty(const ScalarProperty& scalarProperty,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, ScalarProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
/** Set the value.*/
virtual void setValue(float v) { _uniform->set(v); }
/** Get the value.*/
float getValue() const { float v; _uniform->get(v); return v; }
/** Get the underlying uniform.*/
osg::Uniform* getUniform() { return _uniform.get(); }
/** Get the underlying uniform.*/
const osg::Uniform* getUniform() const { return _uniform.get(); }
protected:
virtual ~ScalarProperty() {}
ScalarProperty();
osg::ref_ptr<osg::Uniform> _uniform;
};
class OSGVOLUME_EXPORT IsoSurfaceProperty : public ScalarProperty
{
public:
IsoSurfaceProperty(float value=1.0);
IsoSurfaceProperty(const IsoSurfaceProperty& isp,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, IsoSurfaceProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~IsoSurfaceProperty() {}
};
class OSGVOLUME_EXPORT AlphaFuncProperty : public ScalarProperty
{
public:
AlphaFuncProperty(float value=1.0);
AlphaFuncProperty(const AlphaFuncProperty& isp,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, AlphaFuncProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
virtual void setValue(float v);
osg::AlphaFunc* getAlphaFunc() { return _alphaFunc.get(); }
const osg::AlphaFunc* getAlphaFunc() const { return _alphaFunc.get(); }
protected:
virtual ~AlphaFuncProperty() {}
osg::ref_ptr<osg::AlphaFunc> _alphaFunc;
};
class OSGVOLUME_EXPORT MaximumIntensityProjectionProperty : public Property
{
public:
MaximumIntensityProjectionProperty();
MaximumIntensityProjectionProperty(const
MaximumIntensityProjectionProperty& mipp,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, MaximumIntensityProjectionProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~MaximumIntensityProjectionProperty() {}
};
class OSGVOLUME_EXPORT LightingProperty : public Property
{
public:
LightingProperty();
LightingProperty(const LightingProperty& mipp,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, LightingProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~LightingProperty() {}
};
class OSGVOLUME_EXPORT SampleDensityProperty : public ScalarProperty
{
public:
SampleDensityProperty(float value=1.0);
SampleDensityProperty(const SampleDensityProperty& isp,const
osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, SampleDensityProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~SampleDensityProperty() {}
};
class OSGVOLUME_EXPORT TransparencyProperty : public ScalarProperty
{
public:
TransparencyProperty(float value=1.0);
TransparencyProperty(const TransparencyProperty& isp,const osg::CopyOp&
copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgVolume, TransparencyProperty);
virtual void accept(PropertyVisitor& pv) { pv.apply(*this); }
protected:
virtual ~TransparencyProperty() {}
};
class OSGVOLUME_EXPORT CollectPropertiesVisitor : public
osgVolume::PropertyVisitor
{
public:
CollectPropertiesVisitor(bool traverseOnlyActiveChildren=true);
virtual void apply(Property&);
virtual void apply(TransferFunctionProperty&);
virtual void apply(ScalarProperty&);
virtual void apply(IsoSurfaceProperty& iso);
virtual void apply(AlphaFuncProperty& af);
virtual void apply(MaximumIntensityProjectionProperty& mip);
virtual void apply(LightingProperty& lp);
virtual void apply(SampleDensityProperty& sdp);
virtual void apply(TransparencyProperty& tp);
osg::ref_ptr<TransferFunctionProperty> _tfProperty;
osg::ref_ptr<IsoSurfaceProperty> _isoProperty;
osg::ref_ptr<AlphaFuncProperty> _afProperty;
osg::ref_ptr<MaximumIntensityProjectionProperty> _mipProperty;
osg::ref_ptr<LightingProperty> _lightingProperty;
osg::ref_ptr<SampleDensityProperty>
_sampleDensityProperty;
osg::ref_ptr<TransparencyProperty>
_transparencyProperty;
};
class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public
osgGA::GUIEventHandler, public osg::StateSet::Callback
{
public:
PropertyAdjustmentCallback();
PropertyAdjustmentCallback(const PropertyAdjustmentCallback&,const
osg::CopyOp&) {}
META_Object(osgVolume,PropertyAdjustmentCallback);
void setKeyEventCycleForward(int key) { _cyleForwardKey = key; }
int getKeyEventCyclesForward() const { return _cyleForwardKey; }
void setKeyEventCycleBackward(int key) { _cyleBackwardKey = key; }
int getKeyEventCyclesBackward() const { return _cyleBackwardKey; }
void setKeyEventActivatesTransparencyAdjustment(int key) {
_transparencyKey = key; }
int getKeyEventActivatesTransparencyAdjustment() const { return
_transparencyKey; }
void setKeyEventActivatesSampleDensityAdjustment(int key) {
_sampleDensityKey = key; }
int getKeyEventActivatesSampleAdjustment() const { return
_sampleDensityKey; }
void setKeyEventActivatesAlphaFuncAdjustment(int key) { _alphaFuncKey =
key; }
int getKeyEventActivatesAlphaFuncAdjustment() const { return
_alphaFuncKey; }
virtual bool handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter&, osg::Object* object, osg::NodeVisitor*);
int _cyleForwardKey;
int _cyleBackwardKey;
int _transparencyKey;
int _alphaFuncKey;
int _sampleDensityKey;
bool _updateTransparency;
bool _updateAlphaCutOff;
bool _updateSampleDensity;
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 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.
*/
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_WINDOW_MANAGER
#define OSGWIDGET_WINDOW_MANAGER
#include <osg/Switch>
#include <osg/Uniform>
#include <osg/Drawable>
#include <osgGA/GUIEventAdapter>
#include <osgUtil/LineSegmentIntersector>
#include <osgViewer/View>
#include <osgWidget/ScriptEngine>
#include <osgWidget/StyleManager>
#include <osgWidget/Window>
namespace osgWidget {
// TODO: It should be possible to use something other than
osgWidget/ViewerEventHandlers
// to handle all of these events. In fact, I need to create an SDL example
showing this.
// A private typedef that we use for pickAtXY() below.
typedef osgUtil::LineSegmentIntersector::Intersections Intersections;
// A WindowManager performs pointer interaction with the topmost (highest Z)
Widget,
// and performs keyboard input on the currently focused Window->Widget.
class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public
UIObjectParent<Window> {
public:
enum WmFlags {
WM_USE_LUA = 0x00000001,
WM_USE_PYTHON = 0x00000002,
WM_USE_RENDERBINS = 0x00000004,
WM_PICK_DEBUG = 0x00000008
};
enum PointerDirection {
PD_NONE = 0x00000000,
PD_LEFT = 0x00000001,
PD_RIGHT = 0x00000002,
PD_UP = 0x00000004,
PD_DOWN = 0x00000008
};
enum PointerFocusMode {
PFM_FOCUS = 0x00000000,
PFM_UNFOCUS = 0x00000001,
PFM_SLOPPY = 0x00000002
};
public:
META_Object(osgWidget, WindowManager);
WindowManager(
osgViewer::View* = 0,
point_type = 0.0f,
point_type = 0.0f,
unsigned int = 0,
unsigned int = 0
);
WindowManager(const WindowManager&, const osg::CopyOp&);
virtual ~WindowManager();
// A static method that will set both the _widget and _window data of
an Event
// reference from a passed-in Interface.
static void setEventFromInterface(Event&, EventInterface*);
// A static template method that will iterate over a container and
return a
// properly formed EventInterface*.
template<typename T>
static EventInterface* getFirstEventInterface(T&, Event&);
bool pickAtXY (float, float, WidgetList&);
bool setFocused (Window*);
void setPointerXY (float, float);
void setStyleManager (StyleManager*);
void resizeAllWindows (bool = true);
XYCoord windowXY (double, double) const;
XYCoord localXY (double, double) const;
// Methods all called by the ViewerEventHandlers::MouseHandler object,
or
// by some customer caller of your own. Examples of this to come...
bool pointerMove (float, float);
bool pointerDrag (float, float);
bool mouseScroll (float, float);
osg::Camera* createParentOrthoCamera();
unsigned int getNodeMask() const {
return _nodeMask;
}
point_type getWidth() const {
return _width;
}
point_type getHeight() const {
return _height;
}
bool isUsingLua() const {
return (_flags & WM_USE_LUA) != 0;
}
bool isUsingPython() const {
return (_flags & WM_USE_PYTHON) != 0;
}
bool isUsingRenderBins() const {
return (_flags & WM_USE_RENDERBINS) != 0;
}
int getMouseKeysDown() const {
int flag = 0;
flag |= _leftDown ? osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON : 0;
flag |= _middleDown ? osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:
0;
flag |= _rightDown ? osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON : 0;
return flag;
}
ScriptEngine* getLuaEngine() {
return _lua.get();
}
const ScriptEngine* getLuaEngine() const {
return _lua.get();
}
ScriptEngine* getPythonEngine() {
return _python.get();
}
const ScriptEngine* getPythonEngine() const {
return _python.get();
}
StyleManager* getStyleManager() {
return _styleManager.get();
}
const StyleManager* getStyleManager() const {
return _styleManager.get();
}
PointerDirection getPointerVerticalDirection() const {
return _lastVertical;
}
PointerDirection getPointerHorizontalDirection() const {
return _lastHorizontal;
}
PointerFocusMode getPointerFocusMode() const {
return _focusMode;
}
int getPointerDirectionVector() const {
return _lastVertical | _lastHorizontal;
}
bool isPointerMovingUp() const {
return _lastVertical == PD_UP;
}
bool isPointerMovingDown() const {
return _lastVertical == PD_DOWN;
}
bool isPointerMovingLeft() const {
return _lastHorizontal == PD_LEFT;
}
bool isPointerMovingRight() const {
return _lastHorizontal == PD_RIGHT;
}
bool isPointerMovingVertically() const {
return _lastVertical != PD_NONE;
}
bool isPointerMovingHorizontally() const {
return _lastHorizontal != PD_NONE;
}
bool isLeftMouseButtonDown() const {
return _leftDown;
}
bool isMiddleMouseButtonDown() const {
return _middleDown;
}
bool isRightMouseButtonDown() const {
return _rightDown;
}
bool isMouseScrollingUp() const {
return _scrolling == osgGA::GUIEventAdapter::SCROLL_UP;
}
bool isMouseScrollingDown() const {
return _scrolling == osgGA::GUIEventAdapter::SCROLL_DOWN;
}
bool setFocusedByName(const std::string& name) {
return setFocused(getByName(name));
}
void setScrollingMotion(osgGA::GUIEventAdapter::ScrollingMotion sm) {
_scrolling = sm;
}
void setPointerFocusMode(PointerFocusMode pfm) {
_focusMode = pfm;
}
void setWidth(point_type w) {
_width = w;
}
void setHeight(point_type h) {
_height = h;
}
void setSize(point_type w, point_type h) {
_width = w;
_height = h;
}
void setWindowSize(point_type w, point_type h) {
_windowWidth = w;
_windowHeight = h;
}
// Wrappers around the real calls. These only pertains to mouse buttons,
// particularly 3-button mice, although there are other more generic
// "pointer" API methods.
bool mousePushedLeft(float x, float y) {
return _handleMousePushed(x, y, _leftDown);
}
bool mousePushedMiddle(float x, float y) {
return _handleMousePushed(x, y, _middleDown);
}
bool mousePushedRight(float x, float y) {
return _handleMousePushed(x, y, _rightDown);
}
bool mouseReleasedLeft(float x, float y) {
return _handleMouseReleased(x, y, _leftDown);
}
bool mouseReleasedMiddle(float x, float y) {
return _handleMouseReleased(x, y, _middleDown);
}
bool mouseReleasedRight(float x, float y) {
return _handleMouseReleased(x, y, _rightDown);
}
// Keyboards wrappers, as above; takes the key and key's mask code,
which
// can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}.
bool keyDown (int, int);
bool keyUp (int, int);
private:
// A functor used to sort the Windows by their Z component in
descending order.
struct WindowZCompare: public std::binary_function<ptr_type, ptr_type,
bool> {
bool operator()(const ptr_type& x, const ptr_type& y) {
return x.get()->getZ() > y.get()->getZ();
}
};
// A functor used to sort the Windows by their BinNum component in
descending order.
struct WindowBinNumberCompare: public std::binary_function<ptr_type,
ptr_type, bool> {
bool operator()(const ptr_type& x, const ptr_type& y) {
return
x.get()->getOrCreateStateSet()->getBinNumber() >
y.get()->getOrCreateStateSet()->getBinNumber()
;
}
};
point_type _width;
point_type _height;
point_type _windowWidth;
point_type _windowHeight;
matrix_type _numForeground;
matrix_type _numBackground;
unsigned int _flags;
unsigned int _nodeMask;
osgViewer::View* _view;
float _lastX;
float _lastY;
EventInterface* _lastEvent;
EventInterface* _lastPush;
PointerDirection _lastVertical;
PointerDirection _lastHorizontal;
PointerFocusMode _focusMode;
bool _leftDown;
bool _middleDown;
bool _rightDown;
osgGA::GUIEventAdapter::ScrollingMotion _scrolling;
osg::ref_ptr<ScriptEngine> _lua;
osg::ref_ptr<ScriptEngine> _python;
osg::ref_ptr<StyleManager> _styleManager;
osg::observer_ptr<Widget> _widget;
osg::observer_ptr<Window> _focused;
osg::observer_ptr<Window> _pickWindow;
void childInserted (unsigned int);
void childRemoved (unsigned int, unsigned int);
bool _handleMousePushed (float, float, bool&);
bool _handleMouseReleased (float, float, bool&);
bool _handleMouseScrolled (float, float, bool = false);
void _getPointerXYDiff (float&, float&);
void _updatePickWindow (const WidgetList*, point_type, point_type);
};
// We use a template here because the container could be a list or a vector; or
something
// else that supports iteration!
template<typename T>
EventInterface* WindowManager::getFirstEventInterface(T& container, Event& ev) {
if(!container.size()) return 0;
// See if we can find a Widget that responds to this event...
for(typename T::iterator i = container.begin(); i != container.end(); i++) {
Widget* widget = i->get();
// If so, set the _widget/_window members and return it.
if(widget->getEventMask() & ev.type) {
ev._window = widget->getParent();
ev._widget = widget;
return widget;
}
}
// If we can't find a Widget that will accept this event, try and recurse
all
// of the parent Windows and find one that can.
WindowList windowList;
Window* parent = container.back()->getParent();
if(parent) {
parent->getParentList(windowList);
// A WindowList from getParentList includes the Window the method was
called
// on, and the entire tree of parentage.
for(WindowList::iterator i = windowList.begin(); i != windowList.end();
i++) {
Window* window = i->get();
if(window->getEventMask() & ev.type) {
ev._window = window;
return window;
}
}
}
return 0;
}
}
#endif
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org