OMNeT++ Simulation Library  5.1.1
cosgcanvas.h
1 //==========================================================================
2 // COSGCANVAS.H - header for
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_COSGCANVAS_H
17 #define __OMNETPP_COSGCANVAS_H
18 
19 #include "cownedobject.h"
20 #include "ccanvas.h"
21 
22 #ifdef WITH_OSG
23 
24 // don't include OSG headers yet
25 namespace osg { class Node; class Group; class Vec3d; }
26 namespace osgEarth { class Viewpoint; }
27 
28 namespace omnetpp {
29 
45 class SIM_API cOsgCanvas : public cOwnedObject
46 {
47  public:
52  enum ViewerStyle {
54 #ifdef WITH_OSGEARTH
55  STYLE_EARTH
56 #endif
57  };
58 
59  typedef cFigure::Color Color;
60 
70 #ifdef WITH_OSGEARTH
71  CAM_EARTH
72 #endif
73  };
74 
75  // this is only needed to simplify the Viewpoint hint
76  struct SIM_API Vec3d {
77  double x, y, z;
78  Vec3d() : x(0), y(0), z(0) {}
79  Vec3d(double x, double y, double z): x(x), y(y), z(z) {}
80  operator osg::Vec3d() const;
81  };
82 
92  struct SIM_API Viewpoint {
95  Vec3d eye;
96  Vec3d center;
97  Vec3d up;
98  bool valid;
100 
102  Viewpoint() : valid(false) {}
103  Viewpoint(const Vec3d& eye, const Vec3d& center, const Vec3d& up): eye(eye), center(center), up(up), valid(true) {}
105  };
106 
107  protected:
108  osg::Node *scene; // reference counted
109 
110  ViewerStyle viewerStyle;
111 
112  // OSG viewer hints
113  Color clearColor;
114  CameraManipulatorType cameraManipulatorType;
115  double fieldOfViewAngle; // a.k.a. fovy, see OpenGL gluPerspective
116  double zNear; // see OpenGL gluPerspective
117  double zFar; // see OpenGL gluPerspective
118 
119  Viewpoint *genericViewpoint; // never nullptr
120 
121 #ifdef WITH_OSGEARTH
122  // osgEarth-specific viewer hints
123  osgEarth::Viewpoint *earthViewpoint; // never nullptr
124 #endif
125 
126  private:
127  void copy(const cOsgCanvas& other);
128 
129  public:
132  cOsgCanvas(const char *name=nullptr, ViewerStyle viewerStyle=STYLE_GENERIC, osg::Node *scene=nullptr);
133  cOsgCanvas(const cOsgCanvas& other) : cOwnedObject(other) {copy(other);}
134  virtual ~cOsgCanvas();
135  cOsgCanvas& operator=(const cOsgCanvas& other);
137 
140  virtual cOsgCanvas *dup() const override {return new cOsgCanvas(*this);}
141  virtual std::string str() const override;
143 
150  virtual void setScene(osg::Node *scene);
151 
155  virtual osg::Node *getScene() const {return scene;}
157 
166  void setViewerStyle(ViewerStyle viewerStyle) {this->viewerStyle = viewerStyle;}
167 
171  ViewerStyle getViewerStyle() const {return viewerStyle;}
172 
178  void setClearColor(Color clearColor) {this->clearColor = clearColor;}
179 
183  const Color& getClearColor() const {return clearColor;}
184 
192  void setCameraManipulatorType(CameraManipulatorType manipulator) {this->cameraManipulatorType = manipulator;}
193 
197  CameraManipulatorType getCameraManipulatorType() const {return cameraManipulatorType;}
198 
202  void setFieldOfViewAngle(double fieldOfViewAngle) {this->fieldOfViewAngle = fieldOfViewAngle;}
203 
207  double getFieldOfViewAngle() const {return fieldOfViewAngle;}
208 
215  void setZNear(double zNear) {this->zNear = zNear;}
216 
223  void setZFar(double zFar) {this->zFar = zFar;}
224 
232  void setZLimits(double zNear, double zFar) {this->zNear = zNear; this->zFar = zFar;}
233 
237  void clearZLimits();
238 
243  bool hasZLimits() const;
244 
249  double getZNear() const {return zNear;}
250 
255  double getZFar() const {return zFar;}
257 
263  void setGenericViewpoint(const Viewpoint& viewpoint);
264 
268  const Viewpoint& getGenericViewpoint() const {return *genericViewpoint;}
270 
271 #ifdef WITH_OSGEARTH
272 
277  void setEarthViewpoint(const osgEarth::Viewpoint& earthViewpoint);
278 
282  const osgEarth::Viewpoint& getEarthViewpoint() const {return *earthViewpoint;}
284 #endif
285 };
286 
287 } // namespace omnetpp
288 
289 #else // not WITH_OSG
290 
291 // Dummy cOsgCanvas class in case OpenSceneGraph is not available
292 namespace omnetpp {
293 
294  class SIM_API cOsgCanvas : public cOwnedObject
295  {
296  public:
297  cOsgCanvas();
298  };
299 
300 }
301 
302 #endif // WITH_OSG
303 
304 #endif
Suitable for flying above an object or terrain.
Definition: cosgcanvas.h:67
Similar to TERRAIN, but only allows seeing the object from above.
Definition: cosgcanvas.h:68
Defines a viewpoint in the 3D space.
Definition: cosgcanvas.h:92
Choose the camera manipulator automatically.
Definition: cosgcanvas.h:66
virtual cOsgCanvas * dup() const override
Definition: cosgcanvas.h:140
const Viewpoint & getGenericViewpoint() const
Definition: cosgcanvas.h:268
Represents an RGB color.
Definition: ccanvas.h:120
Wraps an OpenSceneGraph scene, allowing 3D visualization in graphical user interfaces that support it...
Definition: cosgcanvas.h:45
double getFieldOfViewAngle() const
Definition: cosgcanvas.h:207
ViewerStyle getViewerStyle() const
Definition: cosgcanvas.h:171
void setZNear(double zNear)
Definition: cosgcanvas.h:215
Vec3d eye
Specifies the position of the eye point.
Definition: cosgcanvas.h:95
void setZLimits(double zNear, double zFar)
Definition: cosgcanvas.h:232
Vec3d center
Specifies the position of the reference point.
Definition: cosgcanvas.h:96
void setFieldOfViewAngle(double fieldOfViewAngle)
Definition: cosgcanvas.h:202
void setZFar(double zFar)
Definition: cosgcanvas.h:223
void setViewerStyle(ViewerStyle viewerStyle)
Definition: cosgcanvas.h:166
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:104
Allows unrestricted movement centered around an object.
Definition: cosgcanvas.h:69
double getZNear() const
Definition: cosgcanvas.h:249
Vec3d up
Specifies the direction of the up vector.
Definition: cosgcanvas.h:97
virtual osg::Node * getScene() const
Definition: cosgcanvas.h:155
const Color & getClearColor() const
Definition: cosgcanvas.h:183
CameraManipulatorType
Camera manupulator types.
Definition: cosgcanvas.h:65
void setClearColor(Color clearColor)
Definition: cosgcanvas.h:178
Definition: carray.h:21
CameraManipulatorType getCameraManipulatorType() const
Definition: cosgcanvas.h:197
void setCameraManipulatorType(CameraManipulatorType manipulator)
Definition: cosgcanvas.h:192
Definition: cosgcanvas.h:25
double getZFar() const
Definition: cosgcanvas.h:255
ViewerStyle
Viewer styles.
Definition: cosgcanvas.h:52
Definition: cosgcanvas.h:26
For generic (non-osgEarth) OSG models.
Definition: cosgcanvas.h:53