OpenCOVER
input.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/*
9 * input.h
10 *
11 * Created on: Dec 5, 2014
12 * Author: svnvlad
13 */
14
15#ifndef INPUT_H
16#define INPUT_H
17
18#include <vector>
19#include <osg/Matrix>
20
21#include "person.h"
22#include "trackingbody.h"
23#include "buttondevice.h"
24#include "valuator.h"
25
26namespace opencover
27{
28
29class InputDevice;
30class deviceDiscovery;
31class DriverFactoryBase;
32class coMousePointer;
33
39class COVEREXPORT Input
40{
41public:
42 static Input *instance(); //< access input subsystem
44 bool init(); //< initialize input subsytem, legacy driver requires cover/coVRPluginSupport to exist
45
46 enum DebugBits {
47 Config = 1,
48 Mouse = 2,
49 Driver = 4,
50 Raw = 8,
51 Transformed = 16,
52 Matrices = 32,
53 Buttons = 64,
54 Valuators = 128,
55 };
56 static bool debug(DebugBits kind);
57 void setDebug(int debugFlags /* bitwise or of some DebugBits */);
58 int getDebug();
59
60 void printConfig() const; //< debug output
61
62 bool update(); //< global update, call once per frame
63
64 bool isTrackingOn() const;
65
66 bool hasMouse() const; //< whether active person has a mouse
67 bool hasHead() const; //< whether active person's head is tracked
68 bool isHeadValid() const; //< whether active person's head matrix is valid
69 bool hasHand(int num = 0) const; //< whether active person's hand is tracked
70 bool isHandValid(int num = 0) const; //< whether active person's hand matrix is valid
71 bool hasRelative() const; //< whether active person has a relative input matrix
72 bool isRelativeValid() const; //< whether active person's relative matrix is valid
73
74 //Persons control
75 size_t getNumPersons() const; //< number of configured persons
76 size_t getNumBodies() const; //< number of bodies
77 size_t getNumDevices() const; //< number of Devices
78 size_t getActivePerson() const; //< number of current person
79 bool setActivePerson(size_t numPerson); //< set active person
80 Person *getPerson(const std::string &name);
81 Person *getPerson(size_t idx);
82
83 size_t getNumObjects() const
84 {
85 return objects.size();
86 } //< number of tracked objects (not part of persons)
87
88 //Interface for the users of input devices
89 const osg::Matrix &getMouseMat() const; //< mouse matrix of active persion
90 const osg::Matrix &getHeadMat() const; //< head matrix of active persion
91 const osg::Matrix &getRelativeMat() const; //< relative matrix of active persion
92 const osg::Matrix &getHandMat(int num = 0) const; //< hand matrix of active person
93 unsigned int getButtonState(int num = 0) const; //< button states of active person's device
94 unsigned int getRelativeButtonState(int num = 0) const; //< button states of active person's device
95 double getValuatorValue(size_t idx) const; //< valuator values corresponding to current person
96 float eyeDistance() const; //< eye distance (in mm) of active person
97
98 DriverFactoryBase *getDriverPlugin(const std::string &name);
99 void addDevice(const std::string &name, InputDevice *dev); //< add internal device e.g. from a cover plugin
100 void removeDevice(const std::string &name, InputDevice *dev); //< remove internal device e.g. from a cover plugin if the plugin is deleted
101 InputDevice *getDevice(const std::string &name); //< get driver instance
102 InputDevice *getDevice(size_t idx); //< get driver instance
103 TrackingBody *getBody(const std::string &name); //< a single tracked body (matrix)
104 TrackingBody *getBody(size_t idx); //< a single tracked body (matrix)
105 ButtonDevice *getButtons(const std::string &name); //< state of a set of buttons (e.g. mouse)
106 Valuator *getValuator(const std::string &name); //< a single analog value
107
110
111private:
112 Input();
113 static Input *s_singleton;
114
115 int m_debug;
116 coMousePointer *m_mouse;
117
118 typedef std::map<std::string, Person *> PersonMap;
119 PersonMap persons; //< configured persons
120 Person *activePerson; //< active person
121 std::vector<std::string> personNames; //< ordered list of names of configured persons
122
123 std::vector<TrackingBody *> objects;
124
125 typedef std::map<std::string, TrackingBody *> TrackingBodyMap;
126 TrackingBodyMap trackingbodies; //< all configured tracking bodies
127
128 typedef std::map<std::string, ButtonDevice *> ButtonDeviceMap;
129 ButtonDeviceMap buttondevices; //< all configured button devices
130
131 typedef std::map<std::string, Valuator *> ValuatorMap;
132 ValuatorMap valuators; //< all configured valuators
133
134 typedef std::map<std::string, InputDevice *> DriverMap;
135 DriverMap drivers; //< all driver instances
136
137 std::map<std::string, DriverFactoryBase *> plugins; //< all loaded driver plugins
138
139 bool initHardware();
140 bool initPersons();
141 bool initObjects();
142
143 std::string configPath(std::string src, int n = -1); //< access configuration values
144};
145}
146#endif
Definition: ARToolKit.h:33
Definition: buttondevice.h:28
Definition: coMousePointer.h:48
Definition: deviceDiscovery.h:47
The Input class.
Definition: input.h:40
void removeDevice(const std::string &name, InputDevice *dev)
unsigned int getRelativeButtonState(int num=0) const
bool hasMouse() const
bool isHandValid(int num=0) const
Person * getPerson(size_t idx)
InputDevice * getDevice(size_t idx)
bool isTrackingOn() const
InputDevice * getDevice(const std::string &name)
Person * getPerson(const std::string &name)
const osg::Matrix & getMouseMat() const
Valuator * getValuator(const std::string &name)
const osg::Matrix & getHeadMat() const
void printConfig() const
deviceDiscovery * dD
Definition: input.h:109
bool hasHead() const
ButtonDevice * getButtons(const std::string &name)
TrackingBody * getBody(const std::string &name)
const osg::Matrix & getHandMat(int num=0) const
float eyeDistance() const
DriverFactoryBase * getDriverPlugin(const std::string &name)
bool setActivePerson(size_t numPerson)
size_t getActivePerson() const
TrackingBody * getBody(size_t idx)
size_t getNumPersons() const
size_t getNumObjects() const
Definition: input.h:83
void addDevice(const std::string &name, InputDevice *dev)
bool hasRelative() const
void setDebug(int debugFlags)
DebugBits
Definition: input.h:46
bool isRelativeValid() const
size_t getNumBodies() const
size_t getNumDevices() const
coMousePointer * mouse() const
double getValuatorValue(size_t idx) const
static bool debug(DebugBits kind)
bool hasHand(int num=0) const
static Input * instance()
const osg::Matrix & getRelativeMat() const
unsigned int getButtonState(int num=0) const
bool isHeadValid() const
The InputDevice class interacts with input hardware.
Definition: inputdevice.h:38
Definition: inputdevice.h:123
Definition: person.h:30
Definition: trackingbody.h:29
Definition: valuator.h:28