OMNeT++ Simulation Library  6.0.3
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 = 0, y = 0, z = 0;
71  Vec3d() {}
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 = Color(128, 128, 220);
139  CameraManipulatorType cameraManipulatorType = CAM_AUTO;
140  double fieldOfViewAngle = 30; // 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
omnetpp::cOsgCanvas::getZNear
double getZNear() const
Definition: cosgcanvas.h:270
omnetpp::cOsgCanvas::setFieldOfViewAngle
void setFieldOfViewAngle(double fieldOfViewAngle)
Definition: cosgcanvas.h:223
omnetpp::cOsgCanvas::setZLimits
void setZLimits(double zNear, double zFar)
Definition: cosgcanvas.h:253
omnetpp::cOsgCanvas::setCameraManipulatorType
void setCameraManipulatorType(CameraManipulatorType manipulator)
Definition: cosgcanvas.h:213
omnetpp::cOsgCanvas::Viewpoint::valid
bool valid
The validity of the data. If this is false, the vector members should not be read.
Definition: cosgcanvas.h:91
omnetpp::cOsgCanvas::CAM_TRACKBALL
@ CAM_TRACKBALL
Allows unrestricted movement centered around an object.
Definition: cosgcanvas.h:64
omnetpp::cOsgCanvas::getFieldOfViewAngle
double getFieldOfViewAngle() const
Definition: cosgcanvas.h:228
omnetpp::cOsgCanvas::setViewerStyle
void setViewerStyle(ViewerStyle viewerStyle)
Definition: cosgcanvas.h:187
omnetpp::cOsgCanvas::CAM_AUTO
@ CAM_AUTO
Choose the camera manipulator automatically.
Definition: cosgcanvas.h:61
omnetpp::cOsgCanvas::STYLE_GENERIC
@ STYLE_GENERIC
For generic (non-osgEarth) OSG models.
Definition: cosgcanvas.h:50
omnetpp::cOsgCanvas::getCameraManipulatorType
CameraManipulatorType getCameraManipulatorType() const
Definition: cosgcanvas.h:218
omnetpp::cOsgCanvas::setZNear
void setZNear(double zNear)
Definition: cosgcanvas.h:236
omnetpp::cOsgCanvas::dup
virtual cOsgCanvas * dup() const override
Definition: cosgcanvas.h:161
omnetpp::cOsgCanvas::getZFar
double getZFar() const
Definition: cosgcanvas.h:276
omnetpp::cOsgCanvas::Viewpoint::eye
Vec3d eye
Specifies the position of the eye point.
Definition: cosgcanvas.h:88
omnetpp::cFigure::Color
Represents an RGB color.
Definition: ccanvas.h:124
omnetpp::cOsgCanvas::Viewpoint
Defines a viewpoint in the 3D space.
Definition: cosgcanvas.h:85
omnetpp::cOsgCanvas::CAM_TERRAIN
@ CAM_TERRAIN
Suitable for flying above an object or terrain.
Definition: cosgcanvas.h:62
omnetpp::cOsgCanvas::getViewerStyle
ViewerStyle getViewerStyle() const
Definition: cosgcanvas.h:192
omnetpp::cOsgCanvas::CAM_OVERVIEW
@ CAM_OVERVIEW
Similar to TERRAIN, but only allows seeing the object from above.
Definition: cosgcanvas.h:63
omnetpp::cOsgCanvas::Viewpoint::center
Vec3d center
Specifies the position of the reference point.
Definition: cosgcanvas.h:89
omnetpp::cOsgCanvas::getEarthViewpoint
const EarthViewpoint & getEarthViewpoint() const
Definition: cosgcanvas.h:302
omnetpp::cOsgCanvas::CameraManipulatorType
CameraManipulatorType
Camera manupulator types.
Definition: cosgcanvas.h:60
omnetpp::cOsgCanvas::getClearColor
const Color & getClearColor() const
Definition: cosgcanvas.h:204
omnetpp::cOsgCanvas::EarthViewpoint
Defines a viewpoint in 3D space with geographical coordinates, for osgEarth-style viewing.
Definition: cosgcanvas.h:111
omnetpp::cOsgCanvas::ViewerStyle
ViewerStyle
Viewer styles.
Definition: cosgcanvas.h:49
omnetpp::cOsgCanvas::setClearColor
void setClearColor(Color clearColor)
Definition: cosgcanvas.h:199
omnetpp::cOsgCanvas::Viewpoint::up
Vec3d up
Specifies the direction of the up vector.
Definition: cosgcanvas.h:90
omnetpp::cOsgCanvas::getScene
virtual osg::Node * getScene() const
Definition: cosgcanvas.h:176
omnetpp::cOsgCanvas::getGenericViewpoint
const Viewpoint & getGenericViewpoint() const
Definition: cosgcanvas.h:289
omnetpp::cOsgCanvas::setZFar
void setZFar(double zFar)
Definition: cosgcanvas.h:244
omnetpp::cOsgCanvas
Wraps an OpenSceneGraph scene, allowing 3D visualization in graphical user interfaces that support it...
Definition: cosgcanvas.h:42
omnetpp::cOsgCanvas::EarthViewpoint::EarthViewpoint
EarthViewpoint(double longitude, double latitude, double altitude, double heading, double pitch, double range)
Definition: cosgcanvas.h:127
omnetpp::cOwnedObject
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:105