cherish
ToolGlobal.h
1 #ifndef TOOLGLOBAL_H
2 #define TOOLGLOBAL_H
3 
4 #include <vector>
5 #include <iostream>
6 #include <stdio.h>
7 
8 #include <osg/Group>
9 #include <osg/Switch>
10 #include <osg/AutoTransform>
11 #include <osg/Geode>
12 #include <osg/Geometry>
13 #include <osg/Camera>
14 
15 #include "Settings.h"
16 #include "ProtectedGroup.h"
17 
18 namespace entity {
19 
34 {
35 public:
41  ToolGlobal(int nVerts, osg::Array::Binding colorBind,
42  osg::PrimitiveSet* primitiveSet, float linewidth=3.f);
43 
44 protected:
47  virtual void initializeSG() = 0;
48 
49 public:
51  virtual void setVertices(const std::vector<osg::Vec3f>& source);
52 
54  virtual const osg::Vec3Array* getVertices() const;
55 
57  virtual void setColor(const osg::Vec4f& color);
58 
60  virtual const osg::Vec4f& getColor() const;
61 
63  virtual void setVisibility(bool on) = 0;
64 
66  virtual bool getVisibility() const = 0;
67 
69  osg::Geode* getGeodeWire() const;
70 
72  osg::Vec3f getCenterLocal() const;
73 
74 protected:
75  void updateGeometry();
76  void updateGeometry(osg::Geometry* geom);
77 
78  osg::Switch* m_switch;
79  osg::Geode* m_geodeWire;
80  osg::Geometry* m_geomWire;
81 };
82 
93 class BookmarkTool : public ToolGlobal
94 {
95 public:
101  BookmarkTool(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up);
102 
103 protected:
105  void initializeSG();
106 
107 public:
109  void setPose(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up);
110 
112  void getPose(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up);
113 
115  void setColorDefault();
116 
118  void setColorSelected();
119 
120 protected:
123  void updatePosition();
124 
125 public:
127  void setVisibility(bool on);
128 
130  bool getVisibility() const;
131 
132 private:
133  osg::AutoTransform* m_AT;
134 
135  osg::Vec3f m_eye, m_center, m_up;
136 };
137 
149 {
150 public:
152  AxisGlobalTool();
153 
154 protected:
156  void initializeSG();
157 
158 public:
160  void setVisibility(bool on);
161 
163  bool getVisibility() const;
164 
169  virtual void setColor(const osg::Vec4f c1, const osg::Vec4f c2, const osg::Vec4f c3);
170 
171 private:
172  osg::AutoTransform* m_AT;
173  osg::Camera* m_camera;
174 };
175 
180 class ATGeode : public osg::AutoTransform
181 {
182 public:
184  ATGeode();
185 
186 protected:
187  friend class FrameTool;
188 
189  osg::Geode* geode;
190  osg::Geometry* geometry;
191 };
192 
197 class ATRGeode : public osg::AutoTransform
198 {
199 public:
201  ATRGeode();
202 
203 protected:
204  friend class FrameTool;
205 
206  osg::Geode* geode;
207  osg::Geometry* geometry;
208  osg::Camera* camera;
209 
210 };
211 
244 class FrameTool : public ToolGlobal
245 {
246 public:
248  FrameTool();
249 
250 protected:
252  void initializeSG();
253 
254 public:
258  void setVisibility(bool on);
259 
261  bool getVisibility() const;
262 
274  void setVertices(const osg::Vec3f &center, float szX, float szY, float szCr, float szAx,
275  const osg::Vec3f& centerCustom = cher::CENTER ,
276  double theta = 0,
277  bool selectionIsEmpty = true);
278 
280  void setColor(const osg::Vec4f& color, const osg::Vec4f& colorIntersect = cher::CANVAS_CLR_PREVIOUS);
281 
283  void setIntersection(const osg::Vec3f &P1, const osg::Vec3f &P2, const osg::Vec3f &P3, const osg::Vec3f &P4);
284 
285 protected:
287  void setColorIntersection(const osg::Vec4f& colorIntersect);
288 
289 public:
291  void setEditable(bool editable);
292 
294  const osg::Geometry* getPickable() const;
295 
297  bool isSelected() const;
298 
300  virtual void moveDelta(double du, double dv);
301 
303  virtual void scale(double scaleX, double scaleY, osg::Vec3f center);
304 
306  virtual void scale(double scale, osg::Vec3f center);
307 
309  virtual void rotate(double theta, osg::Vec3f center);
310 
311 protected:
312  void initQuadGeometry(osg::Geometry* geom, const std::string& name = "");
313  void initLineGeometry(osg::Geometry* geom, float lineWidth, const std::string& name = "");
314 
315  void setQuadGeometry(osg::Geometry* geom, const osg::Vec3f& P, float szX, float szY, float theta = 0, const osg::Vec3f& center = cher::CENTER);
316 
318  void setScaleGeometry(osg::Geometry* geom, const osg::Vec3f& P0, const osg::Vec3f& P1, const osg::Vec3f& P2, const osg::Vec3f& P3);
319 
320  void setLineGeometry(osg::Geometry* geom, const osg::Vec3f& P1, const osg::Vec3f& P2);
321 
322  void setColorGeometry(osg::Geometry* geom, const osg::Vec4f& color);
323 
324  void moveDeltaWireGeometry(osg::Geometry*geometry, double du, double dv);
325  void scaleWireGeometry(osg::Geometry* geometry, double scaleX, double scaleY, osg::Vec3f center);
326  void scaleWireGeometry(osg::Geometry* geometry, double scale, osg::Vec3f center);
327  void rotateWireGeometry(osg::Geometry* geometry, double theta, osg::Vec3f center);
328 
329 private:
330  osg::Geode* m_geodeIntersect, * m_geodeNormal, * m_geodeRotation;
331  osg::Geometry* m_geomIntersect;
332 
333  /* canvas offset and 3d rotation drawables */
334  osg::Geometry * m_geomNormal1, * m_geomNormal2;
335  osg::Geometry * m_geomRotateX1, * m_geomRotateX2, * m_geomRotateY1, * m_geomRotateY2;
337  ATGeode* m_AT_pick;
338  ATRGeode* m_AT_scaleUV1, * m_AT_scaleUV2, * m_AT_scaleUV3, * m_AT_scaleUV4;
339  ATRGeode* m_AT_center;
340  ATRGeode* m_AT_axisU, * m_AT_axisV;
342  bool m_selected;
343  bool m_editable;
344  bool m_visible;
346  std::vector<bool> m_visibilityState;
347 };
348 
349 }
350 
351 
352 #endif // TOOLGlobal_H
ToolGlobal(int nVerts, osg::Array::Binding colorBind, osg::PrimitiveSet *primitiveSet, float linewidth=3.f)
Definition: ToolGlobal.cpp:14
An abstract class that denotes tool functionality and scene graph. The base tool entity has a starter...
Definition: ToolGlobal.h:33
Scene graph entities.
Definition: AddEntityCommand.h:17
osg::Vec3f getCenterLocal() const
Definition: ToolGlobal.cpp:76
Helper class to create non-scalable geometries that always render on top. The node has the following ...
Definition: ToolGlobal.h:197
virtual bool getVisibility() const =0
osg::Geode * getGeodeWire() const
Definition: ToolGlobal.cpp:71
osg::Geode * m_geodeWire
Definition: ToolGlobal.h:79
Helper class to create non-scalable geometries, e.g., AT -> Geode -> Geometry. Used for pickable geom...
Definition: ToolGlobal.h:180
virtual const osg::Vec3Array * getVertices() const
Definition: ToolGlobal.cpp:50
osg::Geometry * m_geomWire
Definition: ToolGlobal.h:80
virtual void initializeSG()=0
Settings is a configuration variables file for Cherish: enums, consts, defaults. Contains settings su...
Tool to depict the saved position of a camera and its associated scene state. The BookmarkTool has th...
Definition: ToolGlobal.h:93
virtual void setColor(const osg::Vec4f &color)
Definition: ToolGlobal.cpp:55
A tool to depict position of global axis X, Y and Z. The tool has the following scene graph structure...
Definition: ToolGlobal.h:148
A tool to depict canvas bounding box in both its non-editable and editable states.
Definition: ToolGlobal.h:244
virtual void setVisibility(bool on)=0
A convinience class that inherits full functionality of osg::Group except the methods that allow dire...
Definition: ProtectedGroup.h:17
virtual void setVertices(const std::vector< osg::Vec3f > &source)
Definition: ToolGlobal.cpp:41
osg::Switch * m_switch
Definition: ToolGlobal.h:78
virtual const osg::Vec4f & getColor() const
Definition: ToolGlobal.cpp:63