1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/**
* @file
* @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de)
* @copyright Simplified BSD
*
* @cond
* This program is free software: you can redistribute it and/or modify
* it under the terms of the FreeBSD license as published by the FreeBSD
* project.
*
* This program 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.
*
* You should have received a copy of the FreeBSD license along with this
* program. If not, see <http://www.opensource.org/licenses/bsd-license>.
* @endcond
*/
#ifndef OSGINVOKER_H_H6T4R8HU
#define OSGINVOKER_H_H6T4R8HU
#include <uscxml/Interpreter.h>
#include <DOM/Events/MutationEvent.hpp>
#include <DOM/Events/EventListener.hpp>
#include <DOM/Events/Event.hpp>
#include "CompositeDisplay.h"
#include <osg/MatrixTransform>
#include <osg/Material>
#include <osgDB/ReadFile>
#include <set>
#ifdef BUILD_AS_PLUGINS
#include "uscxml/plugins/Plugins.h"
#endif
namespace uscxml {
class OSGInvoker : public InvokerImpl, public Arabica::DOM::Events::EventListener<std::string> {
public:
OSGInvoker();
virtual ~OSGInvoker();
virtual boost::shared_ptr<InvokerImpl> create(InterpreterImpl* interpreter);
virtual std::set<std::string> getNames() {
std::set<std::string> names;
names.insert("3d");
names.insert("scenegraph");
names.insert("http://uscxml.tk.informatik.tu-darmstadt.de/#3d");
return names;
}
virtual Data getDataModelVariables();
virtual void send(const SendRequest& req);
virtual void cancel(const std::string sendId);
virtual void invoke(const InvokeRequest& req);
virtual void handleEvent(Arabica::DOM::Events::Event<std::string>& event);
virtual void runOnMainThread();
protected:
void processDisplay(const Arabica::DOM::Node<std::string>& element);
void updateDisplay(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processViewport(const Arabica::DOM::Node<std::string>& element);
void updateViewport(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processCamera(const Arabica::DOM::Node<std::string>& element);
void updateCamera(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processTranslation(const Arabica::DOM::Node<std::string>& element);
void updateTranslation(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processRotation(const Arabica::DOM::Node<std::string>& element);
void updateRotation(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
static osg::Matrix rotationFromElement(const Arabica::DOM::Node<std::string>& element);
void processScale(const Arabica::DOM::Node<std::string>& element);
void updateScale(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processNode(const Arabica::DOM::Node<std::string>& element);
void updateNode(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processSphere(const Arabica::DOM::Node<std::string>& element);
void updateSphere(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processBox(const Arabica::DOM::Node<std::string>& element);
void updateBox(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processCapsule(const Arabica::DOM::Node<std::string>& element);
void updateCapsule(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processCone(const Arabica::DOM::Node<std::string>& element);
void updateCone(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
void processCylinder(const Arabica::DOM::Node<std::string>& element);
void updateCylinder(osg::ref_ptr<osg::Node> node, Arabica::DOM::Events::Event<std::string>& event);
osg::Vec4 getColor(const Arabica::DOM::Node<std::string>& element, const std::string& attr, bool& valid);
osg::ref_ptr<osg::Material> getMaterial(const Arabica::DOM::Node<std::string>& element);
osg::Vec4 parseVec4(const std::string& coeffs, int& number);
void processChildren(const std::set<std::string>& validChildren, const Arabica::DOM::Node<std::string>& element);
void getViewport(const Arabica::DOM::Node<std::string>& element,
unsigned int& x,
unsigned int& y,
unsigned int& width,
unsigned int& height,
int& screenId);
void getViewport(const Arabica::DOM::Node<std::string>& element,
unsigned int& x,
unsigned int& y,
unsigned int& width,
unsigned int& height,
CompositeDisplay* display);
void getViewport(const Arabica::DOM::Node<std::string>& element,
unsigned int& x,
unsigned int& y,
unsigned int& width,
unsigned int& height,
unsigned int fullWidth,
unsigned int fullHeight);
osgViewer::View* getView(const Arabica::DOM::Node<std::string>& element);
std::map<Arabica::DOM::Node<std::string>, CompositeDisplay*> _displays;
typedef std::map<Arabica::DOM::Node<std::string>, CompositeDisplay*> _displays_t;
std::map<Arabica::DOM::Node<std::string>, osgViewer::View*> _views;
typedef std::map<Arabica::DOM::Node<std::string>, osgViewer::View*> _views_t;
std::map<Arabica::DOM::Node<std::string>, osg::ref_ptr<osg::Node> > _nodes;
typedef std::map<Arabica::DOM::Node<std::string>, osg::ref_ptr<osg::Node> > _nodes_t;
void setupColors();
std::map<std::string, osg::Vec4> _colors;
typedef std::map<std::string, osg::Vec4> _colors_t;
tthread::recursive_mutex _mutex;
};
#ifdef BUILD_AS_PLUGINS
PLUMA_INHERIT_PROVIDER(OSGInvoker, InvokerImpl);
#endif
}
#endif /* end of include guard: OSGINVOKER_H_H6T4R8HU */
|