OpenCOVER
coVRPluginSupport.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef OPEN_COVER_PLUGIN_SUPPORT
9#define OPEN_COVER_PLUGIN_SUPPORT
10
26
27#ifdef _WIN32
28#ifndef _WIN32_WINNT
29#define _WIN32_WINNT 0x501 // This specifies WinXP or later - it is needed to access rawmouse from the user32.dll
30#endif
31#if (_MSC_VER >= 1300) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
32#define POINTER_64 __ptr64
33#else
34#define POINTER_64
35#endif
36#include <winsock2.h>
37#include <io.h>
38#ifndef PATH_MAX
39#define PATH_MAX 512
40#endif
41#endif
42
43#include <osg/Matrix>
44#include <osg/Geode>
45#include <osg/Drawable>
46#include <osg/ClipNode>
47#include <osg/MatrixTransform>
48#include <osgViewer/GraphicsWindow>
49#include <osg/BoundingBox>
50
51#include <list>
52#include <ostream>
53
55
56#include "coVRPlugin.h"
57#include "coVRMessageSender.h"
58
59#include <net/message_types.h>
60
61namespace opencover {
62namespace ui {
63class ButtonGroup;
64class Menu;
65class Manager;
66class VruiView;
67}
68}
69
70namespace covise {
71class Message;
72class UdpMessage;
73}
74
75namespace grmsg {
76class coGRMsg;
77}
78
79#define MAX_NUMBER_JOYSTICKS 64
80
81namespace osg
82{
83class MatrixTransform;
84}
85namespace osgText
86{
87class Font;
88}
89
90namespace vrui
91{
92class coUpdateManager;
93class coMenu;
94class coToolboxMenu;
95class coRowMenu;
96}
97namespace vrml
98{
99class Player;
100}
101
102namespace covise
103{
104class TokenBuffer;
105}
107namespace opencover
108{
109class coVRPlugin;
110class RenderObject;
111class coInteractor;
112class NotifyBuf;
113struct Isect
114{
116 {
119 Walk = 4,
120 Touch = 8,
121 Pick = 16,
124 Left = 128,
125 Right = 256,
128 Update = 2048,
129 OsgEarthSecondary = 0x80000000,
130 };
131
132private:
133};
134
135namespace Notify
136{
138{
143 Fatal
145}
146
150class COVEREXPORT coPointerButton
151{
152 friend class coVRPluginSupport;
153 friend class coVRMSController;
154
155public:
156 coPointerButton(const std::string &name);
160 unsigned int getState() const;
163 unsigned int oldState() const;
165 unsigned int wasPressed(unsigned int buttonMask=vrui::vruiButtons::ALL_BUTTONS) const;
167 unsigned int wasReleased(unsigned int buttonMask=vrui::vruiButtons::ALL_BUTTONS) const;
169 bool notPressed() const;
171 int getWheel(size_t idx=0) const;
173 void setWheel(size_t idx, int count);
175 const std::string &name() const;
176
177private:
179 void setState(unsigned int);
180
181 unsigned int buttonStatus = 0;
182 unsigned int lastStatus = 0;
183 int wheelCount[2]={0,0};
184 std::string m_name;
185};
186
192{
193 friend class OpenCOVER;
194 friend class fasi;
195 friend class fasi2;
196 friend class mopla;
197 friend class coVRMSController;
198 friend class coIntersection;
199
200public:
202
209 bool debugLevel(int level) const;
210 void initUI();
211 // show a message to the user
213 std::ostream &notify(Notify::NotificationLevel level, const char *format, ...) const
214#ifdef __GNUC__
215 __attribute__((format(printf, 3, 4)))
216#endif
217 ;
218
219 // OpenGL clipping
221 enum
222 {
223 MAX_NUM_CLIP_PLANES = 6
224 };
226
229
231 osg::ClipPlane *getClipPlane(int num)
232 {
233 return clipPlanes[num].get();
234 }
235
237
239 bool isClippingOn() const;
240
243
245 void setActiveClippingPlane(int plane);
246
247 // access to scene graph nodes and transformations
248
250 osg::Group *getScene() const;
251
253 osg::ClipNode *getObjectsRoot() const;
254
256 // (in VRSceneGraph handTransform)
257 osg::MatrixTransform *getPointer() const;
258
260 const osg::Matrix &getPointerMat() const;
261 // void setPointerMat(osg::Matrix);
262
265 const osg::Matrix &getMouseMat() const;
266
268 const osg::Matrix &getRelativeMat() const;
269
271 osg::MatrixTransform *getObjectsXform() const;
272
274 const osg::Matrix &getXformMat() const;
275
277 void setXformMat(const osg::Matrix &mat);
278
280 osg::MatrixTransform *getObjectsScale() const;
281
283 void setScale(float s);
284
286 float getScale() const;
287
289
290 const osg::Matrix &getBaseMat() const
291 {
292 return baseMatrix;
293 }
294
296
297 const osg::Matrix &getInvBaseMat() const;
298
303
305
307 float getSceneSize() const;
308
310 bool isHighQuality() const;
311
313
315 bool sendVrbMessage(const covise::MessageBase *msg) const;
316
317 // tracker data
318
320 const osg::Matrix &getViewerMat() const;
321
323 void setNodesIsectable(osg::Node *n, bool isect);
324
327
330
333
336
338 osg::Group *getMenuGroup() const;
339
340 // interfacing with plugins
341
343 coVRPlugin *addPlugin(const char *name);
344
346 coVRPlugin *getPlugin(const char *name);
347
350
352 int removePlugin(const char *name);
353
355 void addedNode(osg::Node *node, coVRPlugin *myPlugin);
356
358
361 bool removeNode(osg::Node *node, bool isGroup = false);
362
364 void sendMessage(coVRPlugin *sender, int toWhom, int type, int len, const void *buf);
365
367 void sendMessage(coVRPlugin *sender, const char *destination, int type, int len, const void *buf, bool localonly = false);
369
373
376
379
385 bool isViewerGrabbed() const;
386
389
395 double frameTime() const;
396
399 double frameDuration() const;
400
403 double frameRealTime() const;
404
408 static double currentTime();
409
411 osgViewer::GraphicsWindow::MouseCursor getCurrentCursor() const;
412
415 void setCurrentCursor(osgViewer::GraphicsWindow::MouseCursor type);
416
418 void setCursorVisible(bool visible);
419
421 osg::Node *getIntersectedNode() const;
422
424 const osg::NodePath &getIntersectedNodePath() const;
425
427 const osg::Vec3 &getIntersectionHitPointWorld() const;
428
430 const osg::Vec3 &getIntersectionHitPointWorldNormal() const;
431
433 osg::Matrix updateInteractorTransform(osg::Matrix mat, bool usePointer) const;
434
435 /*********************************************************************/
436 // do not use anything beyond this line
437
439 // deprecated, use coInteraction with high priority instead
440 // returns true if another plugin locked the pointer
441 int isPointerLocked();
442
443 // old COVISE Messages
444 int sendBinMessage(const char *keyword, const char *data, int len);
445 // update frametime
446 void updateTime();
447 // update matrices
448 void update();
449
451 void personSwitched(size_t personNumber);
452
453 ui::Manager *ui = nullptr;
454 ui::Menu *fileMenu = nullptr;
455 ui::Menu *viewOptionsMenu = nullptr;
456 ui::Menu *visMenu = nullptr;
457 ui::ButtonGroup *navGroup() const;
458 ui::VruiView *vruiView = nullptr;
459
460 osg::Matrix envCorrectMat;
461 osg::Matrix invEnvCorrectMat;
462
463 int registerPlayer(vrml::Player *player);
464 int unregisterPlayer(vrml::Player *player);
465 vrml::Player *usePlayer(void (*playerUnavailableCB)());
466 int unusePlayer(void (*playerUnavailableCB)());
467
468 int numJoysticks;
469 unsigned char number_buttons[MAX_NUMBER_JOYSTICKS];
470 int *buttons[MAX_NUMBER_JOYSTICKS];
471 unsigned char number_axes[MAX_NUMBER_JOYSTICKS];
472 float *axes[MAX_NUMBER_JOYSTICKS];
473 unsigned char number_sliders[MAX_NUMBER_JOYSTICKS];
474 float *sliders[MAX_NUMBER_JOYSTICKS];
475 unsigned char number_POVs[MAX_NUMBER_JOYSTICKS];
476 float *POVs[MAX_NUMBER_JOYSTICKS];
477
478 osg::ref_ptr<osg::ColorMask> getNoFrameBuffer()
479 {
480 return NoFrameBuffer;
481 }
482
483 // utility
484 float getSqrDistance(osg::Node *n, osg::Vec3 &p, osg::MatrixTransform **path, int pathLength) const;
485
486 osg::Matrix *getWorldCoords(osg::Node *node) const;
487 osg::Vec3 frontScreenCenter;
488 float frontHorizontalSize;
489 float frontVerticalSize;
490 int frontWindowHorizontalSize;
491 int frontWindowVerticalSize;
492
494 float getInteractorScale(osg::Vec3 &pos); // pos in World coordinates
495
497 float getViewerScreenDistance();
498
500 osg::BoundingBox getBBox(osg::Node *node) const;
501
502 //restrict interactors to visible scene
503 bool restrictOn() const;
504
506
508 enum MessageDestinations
509 {
510 TO_ALL,
511 TO_ALL_OTHERS,
512 TO_SAME,
513 TO_SAME_OTHERS,
514 VRML_EVENT, // Internal, do not use!!
515 NUM_TYPES
516 };
518
519 vrui::coToolboxMenu *getToolBar(bool create = false);
521
523 void setFrameTime(double ft);
524
525 void setRenderStrategy(osg::Drawable *draw, bool dynamic=false);
527 bool sendGrMessage(const grmsg::coGRMsg &grmsg, int msgType = covise::COVISE_MESSAGE_UI) const;
528private:
529 void setFrameRealTime(double ft);
530
531 float scaleFactor;
532 float viewerDist;
533 osg::Vec3 eyeToScreen;
534
535 osg::ref_ptr<osg::ColorMask> NoFrameBuffer;
536
537 osg::ref_ptr<osg::ClipPlane> clipPlanes[MAX_NUM_CLIP_PLANES];
538
539 mutable vrui::coUpdateManager *updateManager;
540
541 mutable int invCalculated;
542 osg::Matrix handMat;
543 bool wasHandValid = false;
544 osg::Matrix baseMatrix;
545 mutable osg::Matrix invBaseMatrix;
546 double lastFrameStartTime;
547 double frameStartTime, frameStartRealTime;
548 osgViewer::GraphicsWindow::MouseCursor currentCursor;
549 bool cursorVisible = true;
550 vrml::Player *player = nullptr;
551 std::set<void (*)()> playerUseList;
552
553 int activeClippingPlane;
554
555 osg::ref_ptr<osg::Geode> intersectedNode;
556 osg::ref_ptr<osg::Drawable> intersectedDrawable;
557 //osg::ref_ptr<osg::NodePath> intersectedNodePath;
558 osg::NodePath intersectedNodePath;
559 osg::Vec3 intersectionHitPointWorld;
560 osg::Vec3 intersectionHitPointWorldNormal;
561 osg::Vec3 intersectionHitPointLocal;
562 osg::Vec3 intersectionHitPointLocalNormal;
563 osg::ref_ptr<osg::RefMatrix> intersectionMatrix;
564
565 mutable coPointerButton *pointerButton = nullptr;
566 mutable coPointerButton *mouseButton = nullptr;
567 mutable coPointerButton *relativeButton = nullptr;
568 vrui::coToolboxMenu *m_toolBar = nullptr;
569 vrui::coMenu *m_vruiMenu = nullptr;
570 double interactorScale = 1.;
571
572 int numClipPlanes;
573
576
577 std::vector<std::ostream *> m_notifyStream;
578 std::vector<NotifyBuf *> m_notifyBuf;
579};
580
581COVEREXPORT covise::TokenBuffer &operator<<(covise::TokenBuffer &buffer, const osg::Matrixd &matrix);
582COVEREXPORT covise::TokenBuffer &operator>>(covise::TokenBuffer &buffer, osg::Matrixd &matrix);
583
584COVEREXPORT covise::TokenBuffer &operator<<(covise::TokenBuffer &buffer, const osg::Vec3f &vec);
585COVEREXPORT covise::TokenBuffer &operator>>(covise::TokenBuffer &buffer, osg::Vec3f &vec);
586
587//============================================================================
588// Useful inline Function Templates
589//============================================================================
590
592template <class C>
593inline C coClamp(const C a, const C left, const C right)
594{
595 if (a < left)
596 return left;
597 if (a > right)
598 return right;
599 return a;
600}
601
602extern COVEREXPORT coVRPluginSupport *cover;
603}
604#endif
OpenCOVER plugin interface, derive plugins from coVRPlugin.
Definition: ARToolKit.h:33
COVEREXPORT covise::TokenBuffer & operator>>(covise::TokenBuffer &buffer, osg::Matrixd &matrix)
std::ostream & operator<<(std::ostream &os, const coCommandLine &cmd)
C coClamp(const C a, const C left, const C right)
Definition: coVRPluginSupport.h:593
COVEREXPORT coVRPluginSupport * cover
Definition: coClusterStat.h:29
Definition: coTabletUI.h:51
collaborative interface manager
Definition: coVRCommunication.h:41
Definition: coVRFileManager.h:44
NotificationLevel
Definition: coVRPluginSupport.h:138
@ Info
Definition: coVRPluginSupport.h:140
@ Error
Definition: coVRPluginSupport.h:142
@ Debug
Definition: coVRPluginSupport.h:139
@ Fatal
Definition: coVRPluginSupport.h:143
@ Warning
Definition: coVRPluginSupport.h:141
Definition: coIntersection.h:63
Definition: coVRMessageSender.h:9
Definition: coVRMSController.h:61
make sure to clean up properly in the plugin's dtor
Definition: coVRPlugin.h:73
Definition: coVRPluginSupport.h:114
IntersectionBits
Definition: coVRPluginSupport.h:116
@ Walk
Definition: coVRPluginSupport.h:119
@ Visible
Definition: coVRPluginSupport.h:122
@ ReceiveShadow
Definition: coVRPluginSupport.h:127
@ Collision
Definition: coVRPluginSupport.h:117
@ Left
Definition: coVRPluginSupport.h:124
@ Pick
Definition: coVRPluginSupport.h:121
@ NoMirror
Definition: coVRPluginSupport.h:123
@ Touch
Definition: coVRPluginSupport.h:120
@ Intersection
Definition: coVRPluginSupport.h:118
@ OsgEarthSecondary
Definition: coVRPluginSupport.h:129
@ Update
Definition: coVRPluginSupport.h:128
@ CastShadow
Definition: coVRPluginSupport.h:126
@ Right
Definition: coVRPluginSupport.h:125
Definition: coVRPluginSupport.h:151
int getWheel(size_t idx=0) const
accumulated number of wheel events
bool notPressed() const
is no button pressed
unsigned int wasPressed(unsigned int buttonMask=vrui::vruiButtons::ALL_BUTTONS) const
buttons pressed since last frame
unsigned int oldState() const
unsigned int wasReleased(unsigned int buttonMask=vrui::vruiButtons::ALL_BUTTONS) const
buttons released since last frame
coPointerButton(const std::string &name)
void setWheel(size_t idx, int count)
set number wheel events
unsigned int getState() const
const std::string & name() const
button name
Definition: coVRPluginSupport.h:192
void setRenderStrategy(osg::Drawable *draw, bool dynamic=false)
void sendMessage(coVRPlugin *sender, const char *destination, int type, int len, const void *buf, bool localonly=false)
send a message to a named plugins
vrui::coMenu * getMenu()
returns the COVER Menu (Pinboard)
coVRPlugin * getPlugin(const char *name)
get plugin called name
void setCursorVisible(bool visible)
make the cursor visible or invisible
float getSceneSize() const
get the scene size defined in covise.config
osgViewer::GraphicsWindow::MouseCursor getCurrentCursor() const
get the number of the active cursor shape
bool isClippingOn() const
returns true if clipping is on
void watchFileDescriptor(int fd)
register filedescriptor fd for watching so that scene will be re-rendererd when it is ready
osg::MatrixTransform * getObjectsScale() const
get the MatrixTransform for objects scaling
float getScale() const
get the scale factor of the scale node
INTERNAL int getNumClipPlanes()
return the number of clipPlanes reserved for the kernel, others are available to VRML ClippingPlane N...
void setScale(float s)
set the scale matrix of the scale node
INTERNAL INTERNAL vrui::coToolboxMenu * getToolBar(bool create=false)
bool debugLevel(int level) const
returns true if level <= debugLevel
void releaseViewer(coVRPlugin *)
release control over viewer position
osg::ClipPlane * getClipPlane(int num)
return pointer to a clipping plane
Definition: coVRPluginSupport.h:231
bool removeNode(osg::Node *node, bool isGroup=false)
remove node from the scene graph,
bool grabViewer(coVRPlugin *)
let plugin request control over viewer position
coPointerButton * getMouseButton() const
returns a pointer to a coPointerButton object representing the mouse buttons state
void setActiveClippingPlane(int plane)
set number of clipping plane user is possibly interacting with
int removePlugin(const char *name)
remove a plugin by name
void unwatchFileDescriptor(int fd)
remove fd from filedescriptors to watch
opencover::coVRMessageSender * getSender()
const osg::Matrix & getBaseMat() const
transformation matrix from object coordinates to world coordinates
Definition: coVRPluginSupport.h:290
const osg::Matrix & getRelativeMat() const
get matrix for relative input (identity if no input)
coPointerButton * getPointerButton() const
returns a pointer to a coPointerButton object for the main button device
const osg::Matrix & getInvBaseMat() const
transformation from world coordinates to object coordinates
coVRPlugin * addPlugin(const char *name)
load a new plugin
bool sendGrMessage(const grmsg::coGRMsg &grmsg, int msgType=covise::COVISE_MESSAGE_UI) const
osg::MatrixTransform * getPointer() const
get the MatrixTransform node of the hand
bool isViewerGrabbed() const
whether a plugins controls viewer position
coPointerButton * getRelativeButton() const
returns a pointer to a coPointerButton object representing the buttons state on the relative input de...
const osg::Vec3 & getIntersectionHitPointWorld() const
get world coordinates of intersection hit point
bool sendVrbMessage(const covise::MessageBase *msg) const
send a message either via COVISE connection or via tcp to VRB
bool isKeyboardGrabbed()
check if keyboard is grabbed
osg::ClipNode * getObjectsRoot() const
get the group node for all COVISE and model geometry
int getActiveClippingPlane() const
return number of clipping plane user is possibly interacting with
void removePlugin(coVRPlugin *)
remove the plugin by pointer
const osg::Vec3 & getIntersectionHitPointWorldNormal() const
get normal of intersection hit
const osg::Matrix & getPointerMat() const
get matrix of hand transform (same as getPointer()->getMatrix())
osg::MatrixTransform * getObjectsXform() const
get the MatrixTransform for objects translation and rotation
vrui::coUpdateManager * getUpdateManager() const
osg::Group * getMenuGroup() const
return group node of menus
osg::Node * getIntersectedNode() const
get node currently intersected by pointer
bool grabKeyboard(coVRPlugin *)
grab keyboard input
osg::Matrix updateInteractorTransform(osg::Matrix mat, bool usePointer) const
update matrix of an interactor, honouring snapping, ...
osg::Group * getScene() const
get scene group node
const osg::Matrix & getXformMat() const
same as getObjectsXform()->getMatrix()
void setToolBar(vrui::coToolboxMenu *tb)
const osg::NodePath & getIntersectedNodePath() const
get path to node currently intersected by pointer
void sendMessage(coVRPlugin *sender, int toWhom, int type, int len, const void *buf)
send a message to other plugins
std::ostream & notify(Notify::NotificationLevel level=Notify::Info) const
void setCurrentCursor(osgViewer::GraphicsWindow::MouseCursor type)
void releaseKeyboard(coVRPlugin *)
release keyboard input, all plugins will get key events
const osg::Matrix & getMouseMat() const
void setNodesIsectable(osg::Node *n, bool isect)
search geodes under node and set Visible bit in node mask
void setFrameTime(double ft)
use only during coVRPlugin::update()
const osg::Matrix & getViewerMat() const
get the position and orientation of the user in world coordinates
void setXformMat(const osg::Matrix &mat)
same as getObjectsXform()->setMatrix()
bool isHighQuality() const
favor high-quality rendering instead of interactivity
std::ostream & notify(Notify::NotificationLevel level, const char *format,...) const
void addedNode(osg::Node *node, coVRPlugin *myPlugin)
informs other plugins that this plugin extended the scene graph
void protectScenegraph()
forbid saving of scenegraph
Definition: OpenCOVER.h:61
Definition: coMenu.h:51
Definition: coToolboxMenu.h:40
Definition: coUpdateManager.h:42