|
INET Framework for OMNeT++/OMNEST
|
#include <SceneOsgVisualizerBase.h>
|
| virtual void | initializeScene () |
| |
| virtual void | initializeAxis (double axisLength) |
| |
| virtual void | initializeSceneFloor () |
| |
| virtual osg::Geode * | createSceneFloor (const Coord &min, const Coord &max, cFigure::Color &color, osg::Image *image, double imageSize, double opacity, bool shading) const |
| |
| virtual osg::BoundingSphere | getNetworkBoundingSphere () |
| |
| virtual void | initialize (int stage) override |
| |
| virtual Box | getSceneBounds () |
| |
| virtual int | numInitStages () const override |
| |
| virtual Coord | getPosition (const cModule *networkNode) const |
| |
| virtual Coord | getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const |
| |
| virtual Quaternion | getOrientation (const cModule *networkNode) const |
| |
| virtual void | mapChunks (const Ptr< const Chunk > &chunk, const std::function< void(const Ptr< const Chunk > &, int)> &thunk) const |
| |
◆ createSceneFloor()
| osg::Geode * inet::visualizer::SceneOsgVisualizerBase::createSceneFloor |
( |
const Coord & |
min, |
|
|
const Coord & |
max, |
|
|
cFigure::Color & |
color, |
|
|
osg::Image * |
image, |
|
|
double |
imageSize, |
|
|
double |
opacity, |
|
|
bool |
shading |
|
) |
| const |
|
protectedvirtual |
93 if (!std::isfinite(dx) || !std::isfinite(dy))
94 return new osg::Geode();
96 auto d = shading ?
sqrt(dx * dx + dy * dy) : 0;
97 auto width = dx + 2 * d;
98 auto height = dy + 2 * d;
99 auto r = width / imageSize / 2;
100 auto t = height / imageSize / 2;
101 osg::Geometry *geometry =
nullptr;
102 if (image ==
nullptr)
105 geometry = osg::createTexturedQuadGeometry(osg::Vec3(
min.x - d,
min.y - d, 0.0), osg::Vec3(width, 0.0, 0.0), osg::Vec3(0.0, height, 0.0), -r, -t, r, t);
107 geometry->setStateSet(stateSet);
108 osg::Texture2D *texture =
nullptr;
109 if (image !=
nullptr) {
110 texture =
new osg::Texture2D();
111 texture->setImage(image);
112 texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
113 texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);
115 stateSet->setTextureAttributeAndModes(0, texture);
117 auto program =
new osg::Program();
118 auto vertexShader =
new osg::Shader(osg::Shader::VERTEX);
119 auto fragmentShader =
new osg::Shader(osg::Shader::FRAGMENT);
120 vertexShader->setShaderSource(R
"(
123 gl_Position = ftransform();
125 gl_TexCoord[0]=gl_MultiTexCoord0;
127 if (texture !=
nullptr) {
128 fragmentShader->setShaderSource(R
"(
131 uniform float min, max;
132 uniform sampler2D texture;
134 float alpha = 1.0 - smoothstep(min, max, length(verpos.xyz - center));
135 gl_FragColor = vec4(texture2D(texture, gl_TexCoord[0].xy).rgb, alpha);
137 stateSet->addUniform(new osg::Uniform(
"texture", 0));
140 fragmentShader->setShaderSource(R
"(
144 uniform float min, max;
146 float alpha = 1.0 - smoothstep(min, max, length(verpos.xyz - center));
147 gl_FragColor = vec4(color, alpha);
149 stateSet->addUniform(new osg::Uniform(
"color", osg::Vec3((
double)color.red / 255.0, (
double)color.green / 255.0, (
double)color.blue / 255.0)));
151 program->addShader(vertexShader);
152 program->addShader(fragmentShader);
153 auto center = (
max +
min) / 2;
154 stateSet->addUniform(
new osg::Uniform(
"center", osg::Vec3(center.x, center.y, center.z)));
155 stateSet->addUniform(
new osg::Uniform(
"min", (
float)d / 2));
156 stateSet->addUniform(
new osg::Uniform(
"max", (
float)d));
157 stateSet->setAttributeAndModes(program, osg::StateAttribute::ON);
159 auto polygonOffset =
new osg::PolygonOffset();
160 polygonOffset->setFactor(1.0);
161 polygonOffset->setUnits(1.0);
162 stateSet->setAttributeAndModes(polygonOffset, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
163 auto geode =
new osg::Geode();
164 geode->addDrawable(geometry);
Referenced by initializeSceneFloor().
◆ getNetworkBoundingSphere()
| osg::BoundingSphere inet::visualizer::SceneOsgVisualizerBase::getNetworkBoundingSphere |
( |
| ) |
|
|
protectedvirtual |
171 auto nodes =
new osg::Group();
172 auto networkNodeVisualizer = getModuleFromPar<NetworkNodeOsgVisualizer>(par(
"networkNodeVisualizerModule"),
this);
174 auto networkNode = *it;
178 if (
auto networkNodeVisualization = networkNodeVisualizer->findNetworkNodeVisualization(networkNode)) {
179 auto mainNode = networkNodeVisualization->getMainPart();
180 auto radius =
std::max(0.0f, mainNode->computeBound().radius());
181 auto drawable =
new osg::ShapeDrawable(
new osg::Sphere(networkNodeVisualization->getPosition(), radius));
182 auto geode =
new osg::Geode();
183 geode->addDrawable(drawable);
184 nodes->addChild(geode);
189 return osg::BoundingSphere(osg::Vec3d(0, 0, 0), 100);
190 else if (nodeCount == 1)
191 return osg::BoundingSphere(nodes->getBound().center(), 100);
193 return nodes->getBound();
Referenced by inet::visualizer::SceneOsgVisualizer::initializeViewpoint().
◆ initializeAxis()
| void inet::visualizer::SceneOsgVisualizerBase::initializeAxis |
( |
double |
axisLength | ) |
|
|
protectedvirtual |
◆ initializeScene()
| void inet::visualizer::SceneOsgVisualizerBase::initializeScene |
( |
| ) |
|
|
protectedvirtual |
Reimplemented in inet::visualizer::SceneOsgVisualizer.
27 if (osgCanvas->getScene() !=
nullptr)
28 throw cRuntimeError(
"OSG canvas scene at '%s' has been already initialized",
visualizationTargetModule->getFullPath().c_str());
31 osgCanvas->setScene(topLevelScene);
32 const char *clearColor = par(
"clearColor");
33 if (*clearColor !=
'\0')
35 osgCanvas->setZNear(par(
"zNear"));
36 osgCanvas->setZFar(par(
"zFar"));
37 osgCanvas->setFieldOfViewAngle(par(
"fieldOfView"));
38 const char *cameraManipulatorString = par(
"cameraManipulator");
39 cOsgCanvas::CameraManipulatorType cameraManipulator;
40 if (!strcmp(cameraManipulatorString,
"auto"))
41 cameraManipulator = cOsgCanvas::CAM_AUTO;
42 else if (!strcmp(cameraManipulatorString,
"trackball"))
43 cameraManipulator = cOsgCanvas::CAM_TRACKBALL;
44 else if (!strcmp(cameraManipulatorString,
"terrain"))
45 cameraManipulator = cOsgCanvas::CAM_TERRAIN;
46 else if (!strcmp(cameraManipulatorString,
"overview"))
47 cameraManipulator = cOsgCanvas::CAM_OVERVIEW;
48 else if (!strcmp(cameraManipulatorString,
"earth"))
49 cameraManipulator = cOsgCanvas::CAM_EARTH;
51 throw cRuntimeError(
"Unknown camera manipulator: '%s'", cameraManipulatorString);
52 osgCanvas->setCameraManipulatorType(cameraManipulator);
Referenced by inet::visualizer::SceneOsgVisualizer::initializeScene().
◆ initializeSceneFloor()
| void inet::visualizer::SceneOsgVisualizerBase::initializeSceneFloor |
( |
| ) |
|
|
protectedvirtual |
75 if (sceneBounds.getMin() != sceneBounds.getMax()) {
76 const char *imageName = par(
"sceneImage");
78 double imageSize = par(
"sceneImageSize");
80 double opacity = par(
"sceneOpacity");
81 bool shading = par(
"sceneShading");
82 auto sceneFloor =
createSceneFloor(sceneBounds.getMin(), sceneBounds.getMax(), color, image, imageSize, opacity, shading);
84 scene->addChild(sceneFloor);
Referenced by inet::visualizer::SceneOsgVisualizer::initialize().
The documentation for this class was generated from the following files:
osg::Node * createLine(const Coord &start, const Coord &end, cFigure::Arrowhead startArrowhead, cFigure::Arrowhead endArrowhead)
Definition: OsgUtils.cc:171
static const Coord ZERO
Definition: Coord.h:27
virtual Box getSceneBounds()
Definition: SceneVisualizerBase.cc:35
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
osgText::Text * createText(const char *string, const Coord &position, const cFigure::Color &color)
Definition: OsgUtils.cc:199
Geometry * createQuadGeometry(const Coord &min, const Coord &max)
Definition: OsgUtils.cc:135
cModule * visualizationTargetModule
Definition: VisualizerBase.h:25
virtual SimulationScene * getSimulationScene()
Definition: OsgScene.cc:22
value< Value, pow< Unit, 1, 2 > > sqrt(const value< Value, Unit > &a)
Definition: Units.h:272
virtual osg::Geode * createSceneFloor(const Coord &min, const Coord &max, cFigure::Color &color, osg::Image *image, double imageSize, double opacity, bool shading) const
Definition: SceneOsgVisualizerBase.cc:88
bool isNetworkNode(const cModule *mod)
Returns true if the given module is a network node, i.e.
Definition: ModuleAccess.cc:18
double max(const double a, const double b)
Returns the maximum of a and b.
Definition: SctpAssociation.h:266
osg::Image * createImageFromResource(const char *imageName)
Definition: OsgUtils.cc:250
StateSet * createStateSet(const cFigure::Color &color, double opacity, bool cullBackFace)
Definition: OsgUtils.cc:273
This class is used for the topmost node in the OSG node hierarchy.
Definition: OsgScene.h:49
Color
Definition: DiffservUtil.h:17
cModule * visualizationSubjectModule
Definition: VisualizerBase.h:26
AutoTransform * createAutoTransform(Drawable *drawable, AutoTransform::AutoRotateMode mode, bool autoScaleToScreen, const Coord &position)
Definition: OsgUtils.cc:209