OpenCOVER
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
18 namespace osg
19 {
20 class Geode;
21 class Node;
22 }
23 namespace vrb
24 {
25 class SharedStateBase;
26 template<class T>
28 }
29 
30 namespace opencover
31 {
32 class 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 {
57 private:
58  osg::StateSet *loadDefaultGeostate();
59  bool constantInteractorSize_;
60  float iconSize_;
61  bool firstTime;
62 
63  osg::Geode *findGeode(osg::Node *n);
64 
65 protected:
66  osg::ref_ptr<osg::Node> geometryNode;
67  osg::ref_ptr<osg::MatrixTransform> moveTransform;
68  osg::ref_ptr<osg::MatrixTransform> scaleTransform;
69  osg::ref_ptr<osg::MatrixTransform> interactorCaseTransform;
70  osg::MatrixTransform *parent;
72  char *labelStr_;
73 
74  bool _hit;
76  bool _justHit;
77  bool _wasHit;
79  osg::ref_ptr<osg::Node> _hitNode;
80  osg::Vec3 _hitPos;
82 
83  osg::ref_ptr<osg::StateSet> _selectedHl, _intersectedHl, _oldHl;
84 
86  bool m_isInitializedThroughSharedState = false;
87  float _interSize; // size in mm in world coordinates
88  float _scale = 1.; // scale factor for retaining screen size of interactor
89  std::unique_ptr<vrb::SharedStateBase> m_sharedState;
90  // the geosets are created in the derived classes
91  virtual void createGeometry() = 0;
92 
93  // scale sphere to keep the size when the world scaling changes
94  virtual void keepSize();
95  float getScale() const;
96 
97  osg::Vec3 restrictToVisibleScene(osg::Vec3);
98 
99  const osg::Matrix &getPointerMat() const;
100 
102  virtual void updateSharedState();
103 
104 
105 public:
106  // size: size in world coordinates, the size of the sphere is fixed, even if the user scales the world
107  // buttonId: ButtonA, ButtonB etc.
108  // iconName: name of the inventor file in covise/icons
109  // interactorName: name which appears in the scene graph
110  // priority: interaction priority, default medium
111  coVRIntersectionInteractor(float size, coInteraction::InteractionType buttonId, const char *iconName, const char *interactorName, enum coInteraction::InteractionPriority priority);
112 
113  // delete scene graph
114  virtual ~coVRIntersectionInteractor();
115 
116  // make the interactor intersection sensitive
117  void enableIntersection();
118 
119  // check whether interactor is enabled
120  bool isEnabled();
121 
122  // make the interactor intersection insensitive
123  void disableIntersection();
124 
125  // called every time when the geometry is intersected
126  virtual int hit(vrui::vruiHit *hit);
127 
128  // called once when the geometry is not intersected any more
129  virtual void miss();
130 
131  // start the interaction (set selected hl, store dcsmat)
132  virtual void startInteraction();
133 
134  // move the interactor relatively to it's old position
135  // according to the hand movements
136  virtual void doInteraction();
137 
138  // stop the interaction
139  virtual void stopInteraction();
140 
141  // make the interactor visible
142  void show();
143 
144  // make the interactor invisible
145  void hide();
146 
147  // gives information whether this item has been initialized through a sharedState call
148  bool isInitializedThroughSharedState();
150  virtual void setShared(bool state);
151 
153  virtual bool isShared() const;
154 
155  virtual void addIcon(); // highlight and add
156 
157  virtual void removeIcon(); // remove
158 
159  virtual void resetState(); // un-highlight
160 
161  // return the intersected state
163  {
164  return _hit;
165  }
166 
167  // return true if just intesected
168  bool wasHit()
169  {
170  return _wasHit;
171  }
172 
173  // return hit positon
174  osg::Vec3 getHitPos()
175  {
176  return _hitPos;
177  }
178 
179  osg::Node *getHitNode();
180 
181  // called in preframe, does the interaction
182  virtual void preFrame();
183 
184  //return interactor name
186  {
187  return _interactorName;
188  }
189 
191  //static vector<coVRIntersectionInteractor*> *interactors; ///< class variable for storing references of children
192  //static int traverseIndex; ///< class variable for traversing children
193 
194  //static void startTraverseInteractors();
195  //static void traverseInteractors();
196  //static void stopTraverseInteractors();
197 
198  //static osg::Vec3 currentInterPos;
199  //static bool isTraverseInteractors;
200 
201  osg::Matrix getMatrix()
202  {
203  return moveTransform->getMatrix();
204  }
205 
206  void setCaseTransform(osg::MatrixTransform *);
207 };
208 }
209 #endif
vrui::OSGVruiNode * vNode
Definition: coVRIntersectionInteractor.h:81
char * getInteractorName()
class methods for traversing children
Definition: coVRIntersectionInteractor.h:185
std::unique_ptr< vrb::SharedStateBase > m_sharedState
Definition: coVRIntersectionInteractor.h:89
osg::Vec3 _hitPos
Definition: coVRIntersectionInteractor.h:80
bool _intersectionEnabled
Definition: coVRIntersectionInteractor.h:75
Definition: vruiHit.h:20
osg::ref_ptr< osg::StateSet > _selectedHl
Definition: coVRIntersectionInteractor.h:83
char * _interactorName
Definition: coVRIntersectionInteractor.h:71
OpenVRUI interface to (object-pointing device) intersections.
Definition: coAction.h:25
osg::ref_ptr< osg::MatrixTransform > moveTransform
Definition: coVRIntersectionInteractor.h:67
bool _hit
Definition: coVRIntersectionInteractor.h:74
coVRLabel * label_
Definition: coVRIntersectionInteractor.h:85
Definition: coVRIntersectionInteractor.h:55
char * labelStr_
Definition: coVRIntersectionInteractor.h:72
osg::ref_ptr< osg::MatrixTransform > interactorCaseTransform
Definition: coVRIntersectionInteractor.h:69
Definition: coCombinedButtonInteraction.h:20
osg::Matrix getMatrix()
Definition: coVRIntersectionInteractor.h:201
bool wasHit()
Definition: coVRIntersectionInteractor.h:168
osg::MatrixTransform * parent
Definition: coVRIntersectionInteractor.h:70
Definition: OSGVruiNode.h:20
osg::ref_ptr< osg::Node > geometryNode
Geometry node.
Definition: coVRIntersectionInteractor.h:66
bool _justHit
Definition: coVRIntersectionInteractor.h:76
Definition: coVRIntersectionInteractor.h:27
bool _wasHit
Definition: coVRIntersectionInteractor.h:77
osg::Vec3 getHitPos()
Definition: coVRIntersectionInteractor.h:174
Definition: coVRLabel.h:51
osg::ref_ptr< osg::Node > _hitNode
Definition: coVRIntersectionInteractor.h:79
osg::ref_ptr< osg::MatrixTransform > scaleTransform
Definition: coVRIntersectionInteractor.h:68
int isIntersected()
Definition: coVRIntersectionInteractor.h:162
float _interSize
Definition: coVRIntersectionInteractor.h:87
bool _standardHL
Definition: coVRIntersectionInteractor.h:78