cosgcanvas.h Source File

API: cosgcanvas.h Source File
API
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
23namespace osg { class Node; }
24
25namespace omnetpp {
26
42class SIM_API cOsgCanvas : public cOwnedObject
43{
44 public:
53
54 typedef cFigure::Color Color;
55
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;
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;
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) {}
129
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
167
171 virtual void setScene(osg::Node *scene);
172
176 virtual osg::Node *getScene() const {return scene;}
178
181
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
259
264 bool hasZLimits() const;
265
270 double getZNear() const {return zNear;}
271
276 double getZFar() const {return zFar;}
278
281
284 void setGenericViewpoint(const Viewpoint& viewpoint);
285
289 const Viewpoint& getGenericViewpoint() const {return *genericViewpoint;}
291
294
297 void setEarthViewpoint(const EarthViewpoint& earthViewpoint);
298
302 const EarthViewpoint& getEarthViewpoint() const {return *earthViewpoint;}
304};
305
306} // namespace omnetpp
307
308#endif
Wraps an OpenSceneGraph scene, allowing 3D visualization in graphical user interfaces that support it...
Definition cosgcanvas.h:43
void setViewerStyle(ViewerStyle viewerStyle)
Definition cosgcanvas.h:187
const EarthViewpoint & getEarthViewpoint() const
Definition cosgcanvas.h:302
void setZLimits(double zNear, double zFar)
Definition cosgcanvas.h:253
void setGenericViewpoint(const Viewpoint &viewpoint)
CameraManipulatorType getCameraManipulatorType() const
Definition cosgcanvas.h:218
double getFieldOfViewAngle() const
Definition cosgcanvas.h:228
const Viewpoint & getGenericViewpoint() const
Definition cosgcanvas.h:289
double getZFar() const
Definition cosgcanvas.h:276
void setEarthViewpoint(const EarthViewpoint &earthViewpoint)
double getZNear() const
Definition cosgcanvas.h:270
void setZNear(double zNear)
Definition cosgcanvas.h:236
virtual cOsgCanvas * dup() const override
Definition cosgcanvas.h:161
const Color & getClearColor() const
Definition cosgcanvas.h:204
void setFieldOfViewAngle(double fieldOfViewAngle)
Definition cosgcanvas.h:223
void setZFar(double zFar)
Definition cosgcanvas.h:244
virtual void setScene(osg::Node *scene)
void setCameraManipulatorType(CameraManipulatorType manipulator)
Definition cosgcanvas.h:213
ViewerStyle getViewerStyle() const
Definition cosgcanvas.h:192
bool hasZLimits() const
virtual std::string str() const override
void setClearColor(Color clearColor)
Definition cosgcanvas.h:199
virtual osg::Node * getScene() const
Definition cosgcanvas.h:176
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition cownedobject.h:106
CameraManipulatorType
Camera manupulator types.
Definition cosgcanvas.h:60
ViewerStyle
Viewer styles.
Definition cosgcanvas.h:49
@ CAM_EARTH
Useful when viewing osgEarth scenes.
Definition cosgcanvas.h:65
@ CAM_TERRAIN
Suitable for flying above an object or terrain.
Definition cosgcanvas.h:62
@ CAM_AUTO
Choose the camera manipulator automatically.
Definition cosgcanvas.h:61
@ CAM_TRACKBALL
Allows unrestricted movement centered around an object.
Definition cosgcanvas.h:64
@ CAM_OVERVIEW
Similar to TERRAIN, but only allows seeing the object from above.
Definition cosgcanvas.h:63
@ STYLE_EARTH
For osgEarth models.
Definition cosgcanvas.h:51
@ STYLE_GENERIC
For generic (non-osgEarth) OSG models.
Definition cosgcanvas.h:50
Represents an RGB color.
Definition ccanvas.h:124
Defines a viewpoint in 3D space with geographical coordinates, for osgEarth-style viewing.
Definition cosgcanvas.h:111
bool valid
The validity of the data. If false, the other members should not be read.
Definition cosgcanvas.h:116
double altitude
The location of the "focal point".
Definition cosgcanvas.h:114
double range
The distance and angle of the camera.
Definition cosgcanvas.h:115
EarthViewpoint(double longitude, double latitude, double altitude, double heading, double pitch, double range)
Definition cosgcanvas.h:127
Defines a viewpoint in the 3D space.
Definition cosgcanvas.h:85
bool valid
The validity of the data. If this is false, the vector members should not be read.
Definition cosgcanvas.h:91
Vec3d up
Specifies the direction of the up vector.
Definition cosgcanvas.h:90
Vec3d center
Specifies the position of the reference point.
Definition cosgcanvas.h:89
Vec3d eye
Specifies the position of the eye point.
Definition cosgcanvas.h:88