OpenCOVER
coVRIntersectionInteractor.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 _CO_VR_INTERSECTION_INTERACTOR_H
9#define _CO_VR_INTERSECTION_INTERACTOR_H
10
11#include "coIntersection.h"
15#include <osg/MatrixTransform>
16#include <memory>
17
18namespace osg
19{
20class Geode;
21class Node;
22}
23namespace vrb
24{
25class SharedStateBase;
26template<class T>
28}
29
30namespace opencover
31{
32class coVRLabel;
33
34// selectable sphere which can be positioned
35// the sphere is modeled in the origin
36// transDCS contains the matrix in object coordinates
37//
38//
39// scene
40// |
41// xformDCS
42// |
43// scaleDCS
44// | |
45// coviseObjectsRoot moveTransform
46// | |
47// dcs scaleTransform
48// | |
49// TracerSeq geometryNode
50// | |
51// TrGeode TrGeode
52//
53//
54
56{
57private:
58 osg::StateSet *loadDefaultGeostate();
59 bool constantInteractorSize_ = true;
60 float iconSize_;
61 bool firstTime = true;
62 bool _highliteHitNodeOnly;
63
64 osg::Geode *findGeode(osg::Node *n);
65
66protected:
67 osg::ref_ptr<osg::Node> geometryNode;
68 osg::ref_ptr<osg::MatrixTransform> moveTransform;
69 osg::ref_ptr<osg::MatrixTransform> scaleTransform;
70 osg::ref_ptr<osg::MatrixTransform> interactorCaseTransform;
71 osg::MatrixTransform *parent = nullptr;
72 char *_interactorName = nullptr;
73 char *labelStr_ = nullptr;
74
75 bool _hit = false;
76 bool _intersectionEnabled = true;
77 bool _justHit = false;
78 bool _wasHit = false;
79 bool _standardHL = true;
80 osg::ref_ptr<osg::Node> _hitNode; // current node under cursor
81 osg::Node *_interactionHitNode = nullptr; // this is the node which was hit, when interaction started
82
83 osg::Vec3 _hitPos;
84 vrui::OSGVruiNode *vNode = nullptr;
85
86 osg::ref_ptr<osg::StateSet> _selectedHl, _intersectedHl, _oldHl;
87
88 coVRLabel *label_ = nullptr;
89 bool m_isInitializedThroughSharedState = false;
90 float _interSize; // size in mm in world coordinates
91 float _scale = 1.; // scale factor for retaining screen size of interactor
92 std::unique_ptr<vrb::SharedStateBase> m_sharedState;
93 // the geosets are created in the derived classes
94 virtual void createGeometry() = 0;
95
96 // scale sphere to keep the size when the world scaling changes
97 virtual void keepSize();
98 float getScale() const;
99
100 osg::Vec3 restrictToVisibleScene(osg::Vec3);
101
102 const osg::Matrix &getPointerMat() const;
103
105 virtual void updateSharedState();
106
107
108public:
109 // size: size in world coordinates, the size of the sphere is fixed, even if the user scales the world
110 // buttonId: ButtonA, ButtonB etc.
111 // iconName: name of the inventor file in covise/icons
112 // interactorName: name which appears in the scene graph
113 // priority: interaction priority, default medium
114 // highliteHitNodeOnly: true: only the node under the cursor gets highlited - false: if any child node of the geometryNode gets hit all children are highlited
115 coVRIntersectionInteractor(float size, coInteraction::InteractionType buttonId, const char *iconName, const char *interactorName, enum coInteraction::InteractionPriority priority, bool highliteHitNodeOnly = false);
116
117 // delete scene graph
119
120 // make the interactor intersection sensitive
122
123 // check whether interactor is enabled
124 bool isEnabled();
125
126 // make the interactor intersection insensitive
128
129 // called every time when the geometry is intersected
130 virtual int hit(vrui::vruiHit *hit);
131
132 // called once when the geometry is not intersected any more
133 virtual void miss();
134
135 // start the interaction (set selected hl, store dcsmat)
136 virtual void startInteraction();
137
138 // move the interactor relatively to it's old position
139 // according to the hand movements
140 virtual void doInteraction();
141
142 // stop the interaction
143 virtual void stopInteraction();
144
145 // make the interactor visible
146 void show();
147
148 // make the interactor invisible
149 void hide();
150
151 // gives information whether this item has been initialized through a sharedState call
154 virtual void setShared(bool state);
155
157 virtual bool isShared() const;
158
159 virtual void addIcon(); // highlight and add
160
161 virtual void removeIcon(); // remove
162
163 virtual void resetState(); // un-highlight
164
165 // return the intersected state
167 {
168 return _hit;
169 }
170
171 // return true if just intesected
172 bool wasHit()
173 {
174 return _wasHit;
175 }
176
177 // return hit positon
178 osg::Vec3 getHitPos()
179 {
180 return _hitPos;
181 }
182
183 // called in preframe, does the interaction
184 virtual void preFrame();
185
186 //return interactor name
188 {
189 return _interactorName;
190 }
191
193 //static vector<coVRIntersectionInteractor*> *interactors; ///< class variable for storing references of children
194 //static int traverseIndex; ///< class variable for traversing children
195
196 //static void startTraverseInteractors();
197 //static void traverseInteractors();
198 //static void stopTraverseInteractors();
199
200 //static osg::Vec3 currentInterPos;
201 //static bool isTraverseInteractors;
202
203 osg::Matrix getMatrix()
204 {
205 return moveTransform->getMatrix();
206 }
207
208 const osg::Matrix& getMatrix() const
209 {
210 return moveTransform->getMatrix();
211 }
212
213 void setCaseTransform(osg::MatrixTransform *);
214};
215}
216#endif
OpenVRUI interface to (object-pointing device) intersections.
Definition: ARToolKit.h:33
Definition: coClusterStat.h:29
Definition: coTabletUI.h:59
Definition: coVRIntersectionInteractor.h:27
Definition: coVRIntersectionInteractor.h:56
virtual bool isShared() const
query whether Element state is shared among collaborative partners
char * getInteractorName()
class methods for traversing children
Definition: coVRIntersectionInteractor.h:187
bool wasHit()
Definition: coVRIntersectionInteractor.h:172
osg::ref_ptr< osg::Node > geometryNode
Geometry node.
Definition: coVRIntersectionInteractor.h:67
osg::ref_ptr< osg::MatrixTransform > scaleTransform
Definition: coVRIntersectionInteractor.h:69
coVRIntersectionInteractor(float size, coInteraction::InteractionType buttonId, const char *iconName, const char *interactorName, enum coInteraction::InteractionPriority priority, bool highliteHitNodeOnly=false)
std::unique_ptr< vrb::SharedStateBase > m_sharedState
Definition: coVRIntersectionInteractor.h:92
osg::Vec3 getHitPos()
Definition: coVRIntersectionInteractor.h:178
osg::Vec3 _hitPos
Definition: coVRIntersectionInteractor.h:83
osg::ref_ptr< osg::Node > _hitNode
Definition: coVRIntersectionInteractor.h:80
osg::ref_ptr< osg::MatrixTransform > interactorCaseTransform
Definition: coVRIntersectionInteractor.h:70
float _interSize
Definition: coVRIntersectionInteractor.h:90
const osg::Matrix & getMatrix() const
Definition: coVRIntersectionInteractor.h:208
osg::ref_ptr< osg::MatrixTransform > moveTransform
Definition: coVRIntersectionInteractor.h:68
virtual int hit(vrui::vruiHit *hit)
int isIntersected()
Definition: coVRIntersectionInteractor.h:166
osg::ref_ptr< osg::StateSet > _intersectedHl
Definition: coVRIntersectionInteractor.h:86
osg::Vec3 restrictToVisibleScene(osg::Vec3)
osg::Matrix getMatrix()
Definition: coVRIntersectionInteractor.h:203
const osg::Matrix & getPointerMat() const
virtual void setShared(bool state)
make state shared among partners in a collaborative session
void setCaseTransform(osg::MatrixTransform *)
virtual void updateSharedState()
reimplement in derived class for updating value of m_sharedState
Definition: coVRLabel.h:52
Definition: coAction.h:26
Definition: coCombinedButtonInteraction.h:22
Definition: vruiHit.h:21
Definition: OSGVruiNode.h:21