OMNeT++ Simulation Library  5.6.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 // don't include OSG headers
23 namespace osg { class Node; }
24 
25 namespace omnetpp {
26 
42 class SIM_API cOsgCanvas : public cOwnedObject
43 {
44  public:
49  enum ViewerStyle {
51  STYLE_EARTH
52  };
53 
54  typedef cFigure::Color Color;
55 
65  CAM_EARTH
66  };
67 
68  // this is only needed to simplify the Viewpoint hint
69  struct SIM_API Vec3d {
70  double x, y, z;
71  Vec3d() : x(0), y(0), z(0) {}
72  Vec3d(double x, double y, double z): x(x), y(y), z(z) {}
73  std::string str();
74  };
75 
85  struct SIM_API Viewpoint {
88  Vec3d eye;
89  Vec3d center;
90  Vec3d up;
91  bool valid;
92 
93 
95  Viewpoint() : valid(false) {}
96  Viewpoint(const Vec3d& eye, const Vec3d& center, const Vec3d& up): eye(eye), center(center), up(up), valid(true) {}
98  };
99 
111  struct SIM_API EarthViewpoint {
114  double longitude = 0, latitude = 0, altitude = 0;
115  double heading = 0, pitch = 0, range = 0;
116  bool valid = false;
117 
118 
120  EarthViewpoint() {}
127  EarthViewpoint(double longitude, double latitude, double altitude, double heading, double pitch, double range)
128  : longitude(longitude), latitude(latitude), altitude(altitude), heading(heading), pitch(pitch), range(range), valid(true) {}
130  };
131 
132  protected:
133  osg::Node *scene; // reference counted
134 
135  ViewerStyle viewerStyle;
136 
137  // OSG viewer hints
138  Color clearColor;
139  CameraManipulatorType cameraManipulatorType;
140  double fieldOfViewAngle; // a.k.a. fovy, see OpenGL gluPerspective
141  double zNear; // see OpenGL gluPerspective
142  double zFar; // see OpenGL gluPerspective
143 
144  Viewpoint *genericViewpoint; // never nullptr
145  EarthViewpoint *earthViewpoint; // never nullptr
146 
147  private:
148  void copy(const cOsgCanvas& other);
149 
150  public:
153  cOsgCanvas(const char *name=nullptr, ViewerStyle viewerStyle=STYLE_GENERIC, osg::Node *scene=nullptr);
154  cOsgCanvas(const cOsgCanvas& other) : cOwnedObject(other) {copy(other);}
155  virtual ~cOsgCanvas();
156  cOsgCanvas& operator=(const cOsgCanvas& other);
158 
161  virtual cOsgCanvas *dup() const override {return new cOsgCanvas(*this);}
162  virtual std::string str() const override;
164 
171  virtual void setScene(osg::Node *scene);
172 
176  virtual osg::Node *getScene() const {return scene;}
178 
187  void setViewerStyle(ViewerStyle viewerStyle) {this->viewerStyle = viewerStyle;}
188 
192  ViewerStyle getViewerStyle() const {return viewerStyle;}
193 
199  void setClearColor(Color clearColor) {this->clearColor = clearColor;}
200 
204  const Color& getClearColor() const {return clearColor;}
205 
213  void setCameraManipulatorType(CameraManipulatorType manipulator) {this->cameraManipulatorType = manipulator;}
214 
218  CameraManipulatorType getCameraManipulatorType() const {return cameraManipulatorType;}
219 
223  void setFieldOfViewAngle(double fieldOfViewAngle) {this->fieldOfViewAngle = fieldOfViewAngle;}
224 
228  double getFieldOfViewAngle() const {return fieldOfViewAngle;}
229 
236  void setZNear(double zNear) {this->zNear = zNear;}
237 
244  void setZFar(double zFar) {this->zFar = zFar;}
245 
253  void setZLimits(double zNear, double zFar) {this->zNear = zNear; this->zFar = zFar;}
254 
258  void clearZLimits();
259 
264  bool hasZLimits() const;
265 
270  double getZNear() const {return zNear;}
271 
276  double getZFar() const {return zFar;}
278 
284  void setGenericViewpoint(const Viewpoint& viewpoint);
285 
289  const Viewpoint& getGenericViewpoint() const {return *genericViewpoint;}
291 
297  void setEarthViewpoint(const EarthViewpoint& earthViewpoint);
298 
302  const EarthViewpoint& getEarthViewpoint() const {return *earthViewpoint;}
304 };
305 
306 } // namespace omnetpp
307 
308 #endif
Suitable for flying above an object or terrain.
Definition: cosgcanvas.h:62
Similar to TERRAIN, but only allows seeing the object from above.
Definition: cosgcanvas.h:63
Defines a viewpoint in the 3D space.
Definition: cosgcanvas.h:85
Choose the camera manipulator automatically.
Definition: cosgcanvas.h:61
CameraManipulatorType getCameraManipulatorType() const
Definition: cosgcanvas.h:218
virtual cOsgCanvas * dup() const override
Definition: cosgcanvas.h:161
EarthViewpoint(double longitude, double latitude, double altitude, double heading, double pitch, double range)
Definition: cosgcanvas.h:127
ViewerStyle getViewerStyle() const
Definition: cosgcanvas.h:192
Represents an RGB color.
Definition: ccanvas.h:120
double getFieldOfViewAngle() const
Definition: cosgcanvas.h:228
Wraps an OpenSceneGraph scene, allowing 3D visualization in graphical user interfaces that support it...
Definition: cosgcanvas.h:42
double getZFar() const
Definition: cosgcanvas.h:276
bool valid
The validity of the data. If this is false, the vector members should not be read.
Definition: cosgcanvas.h:91
Defines a viewpoint in 3D space with geographical coordinates, for osgEarth-style viewing...
Definition: cosgcanvas.h:111
double getZNear() const
Definition: cosgcanvas.h:270
const Color & getClearColor() const
Definition: cosgcanvas.h:204
void setZNear(double zNear)
Definition: cosgcanvas.h:236
Vec3d eye
Specifies the position of the eye point.
Definition: cosgcanvas.h:88
void setZLimits(double zNear, double zFar)
Definition: cosgcanvas.h:253
Vec3d center
Specifies the position of the reference point.
Definition: cosgcanvas.h:89
void setFieldOfViewAngle(double fieldOfViewAngle)
Definition: cosgcanvas.h:223
void setZFar(double zFar)
Definition: cosgcanvas.h:244
void setViewerStyle(ViewerStyle viewerStyle)
Definition: cosgcanvas.h:187
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:64
Vec3d up
Specifies the direction of the up vector.
Definition: cosgcanvas.h:90
CameraManipulatorType
Camera manupulator types.
Definition: cosgcanvas.h:60
void setClearColor(Color clearColor)
Definition: cosgcanvas.h:199
Definition: cabstracthistogram.h:21
const EarthViewpoint & getEarthViewpoint() const
Definition: cosgcanvas.h:302
void setCameraManipulatorType(CameraManipulatorType manipulator)
Definition: cosgcanvas.h:213
Definition: cenvir.h:28
ViewerStyle
Viewer styles.
Definition: cosgcanvas.h:49
virtual osg::Node * getScene() const
Definition: cosgcanvas.h:176
For generic (non-osgEarth) OSG models.
Definition: cosgcanvas.h:50
const Viewpoint & getGenericViewpoint() const
Definition: cosgcanvas.h:289