50 std::map<std::string, osg::ref_ptr<osg::Node> > GUIOSGBuilder::myCars;
57 GUIOSGBuilder::buildOSGScene(osg::Node*
const tlg, osg::Node*
const tly, osg::Node*
const tlr, osg::Node*
const tlu) {
58 osgUtil::Tessellator tesselator;
59 osg::Group* root =
new osg::Group();
63 if (!e->isInternal()) {
64 buildOSGEdgeGeometry(*e, *root, tesselator);
74 for (std::vector<std::string>::const_iterator i = tlids.begin(); i != tlids.end(); ++i) {
77 const MSLane* lastLane = 0;
79 for (MSTrafficLightLogic::LaneVectorVector::const_iterator j = lanes.begin(); j != lanes.end(); ++j, ++idx) {
80 if ((*j).size() == 0) {
83 const MSLane*
const lane = (*j)[0];
87 if (lane == lastLane) {
91 d.
centerX = pos.
x() - 1.5 * sin(angle);
92 d.
centerY = pos.
y() - 1.5 * cos(angle);
94 osg::Switch* switchNode =
new osg::Switch();
95 switchNode->addChild(getTrafficLight(d, tlg, osg::Vec4d(0.1, 0.5, 0.1, 1.0), .25),
false);
96 switchNode->addChild(getTrafficLight(d, tly, osg::Vec4d(0.5, 0.5, 0.1, 1.0), .25),
false);
97 switchNode->addChild(getTrafficLight(d, tlr, osg::Vec4d(0.5, 0.1, 0.1, 1.0), .25),
false);
98 switchNode->addChild(getTrafficLight(d, tlu, osg::Vec4d(0.8, 0.4, 0.0, 1.0), .25),
false);
99 root->addChild(switchNode);
112 osg::Light* light =
new osg::Light(d.
filename[5] -
'0');
114 light->setPosition(osg::Vec4(0.0, 0.0, 0.0, 1.0));
115 light->setDiffuse(osg::Vec4(1.0, 1.0, 1.0, 1.0));
116 light->setSpecular(osg::Vec4(1.0, 1.0, 1.0, 1.0));
117 light->setAmbient(osg::Vec4(1.0, 1.0, 1.0, 1.0));
119 osg::LightSource* lightSource =
new osg::LightSource();
120 lightSource->setLight(light);
121 lightSource->setLocalStateSetModes(osg::StateAttribute::ON);
122 lightSource->setStateSetModes(*addTo.getOrCreateStateSet(), osg::StateAttribute::ON);
124 osg::PositionAttitudeTransform* lightTransform =
new osg::PositionAttitudeTransform();
125 lightTransform->addChild(lightSource);
127 lightTransform->setScale(osg::Vec3d(0.1, 0.1, 0.1));
128 addTo.addChild(lightTransform);
133 GUIOSGBuilder::buildOSGEdgeGeometry(
const MSEdge& edge,
135 osgUtil::Tessellator& tessellator) {
136 const std::vector<MSLane*>& lanes = edge.
getLanes();
137 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
140 osg::Geode* geode =
new osg::Geode();
141 osg::Geometry* geom =
new osg::Geometry();
142 geode->addDrawable(geom);
143 addTo.addChild(geode);
144 const int shapeSize = (int)(edge.
isWalkingArea() ? shape.size() : shape.size() * 2);
146 osg::Vec3Array* osg_coords =
new osg::Vec3Array(shapeSize);
147 geom->setVertexArray(osg_coords);
150 for (
int k = 0; k < (int)shape.size(); ++k, ++index) {
151 (*osg_coords)[index].set((
float)shape[k].x(), (float)shape[k].y(), (float)shape[k].z() + zOffset);
157 for (
int k = 0; k < (int)rshape.size(); ++k, ++index) {
158 (*osg_coords)[index].set((
float)rshape[k].x(), (float)rshape[k].y(), (float)rshape[k].z() + zOffset);
162 for (
int k = (
int) lshape.size() - 1; k >= 0; --k, ++index) {
163 (*osg_coords)[index].set((
float)lshape[k].x(), (float)lshape[k].y(), (float)lshape[k].z() + zOffset);
166 osg::Vec3Array* osg_normals =
new osg::Vec3Array(1);
167 (*osg_normals)[0] = osg::Vec3(0, 0, 1);
168 #if OSG_MIN_VERSION_REQUIRED(3,2,0)
169 geom->setNormalArray(osg_normals, osg::Array::BIND_PER_PRIMITIVE_SET);
171 geom->setNormalArray(osg_normals);
172 geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
174 osg::Vec4ubArray* osg_colors =
new osg::Vec4ubArray(1);
175 (*osg_colors)[0].set(128, 128, 128, 255);
176 #if OSG_MIN_VERSION_REQUIRED(3,2,0)
177 geom->setColorArray(osg_colors, osg::Array::BIND_OVERALL);
179 geom->setColorArray(osg_colors);
180 geom->setColorBinding(osg::Geometry::BIND_OVERALL);
182 geom->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, shapeSize));
184 osg::ref_ptr<osg::StateSet> ss = geode->getOrCreateStateSet();
185 ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
186 ss->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
188 if (shape.size() > 2) {
189 tessellator.retessellatePolygons(*geom);
191 std::cout <<
"l=" << l->
getID() <<
" origPoints=" << shape.size() <<
" geomSize=" << geom->getVertexArray()->getNumElements() <<
" points=";
192 for (
int i = 0; i < (int)geom->getVertexArray()->getNumElements(); i++) {
193 const osg::Vec3& p = (*((osg::Vec3Array*)geom->getVertexArray()))[i];
194 std::cout << p.x() <<
"," << p.y() <<
"," << p.z() <<
" ";
199 static_cast<GUILane*
>(l)->setGeometry(geom);
207 osgUtil::Tessellator& tessellator) {
209 osg::Geode* geode =
new osg::Geode();
210 osg::Geometry* geom =
new osg::Geometry();
211 geode->addDrawable(geom);
212 addTo.addChild(geode);
213 osg::Vec3Array* osg_coords =
new osg::Vec3Array((
int)shape.size());
214 geom->setVertexArray(osg_coords);
215 for (
int k = 0; k < (int)shape.size(); ++k) {
216 (*osg_coords)[k].set((
float)shape[k].x(), (float)shape[k].y(), (float)shape[k].z());
218 osg::Vec3Array* osg_normals =
new osg::Vec3Array(1);
219 (*osg_normals)[0] = osg::Vec3(0, 0, 1);
220 #if OSG_MIN_VERSION_REQUIRED(3,2,0)
221 geom->setNormalArray(osg_normals, osg::Array::BIND_PER_PRIMITIVE_SET);
223 geom->setNormalArray(osg_normals);
224 geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
226 osg::Vec4ubArray* osg_colors =
new osg::Vec4ubArray(1);
227 (*osg_colors)[0].set(128, 128, 128, 255);
228 #if OSG_MIN_VERSION_REQUIRED(3,2,0)
229 geom->setColorArray(osg_colors, osg::Array::BIND_OVERALL);
231 geom->setColorArray(osg_colors);
232 geom->setColorBinding(osg::Geometry::BIND_OVERALL);
234 geom->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, (
int)shape.size()));
236 osg::ref_ptr<osg::StateSet> ss = geode->getOrCreateStateSet();
237 ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
238 ss->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
240 if (shape.size() > 4) {
241 tessellator.retessellatePolygons(*geom);
243 junction.setGeometry(geom);
249 osg::Node* pLoadedModel = osgDB::readNodeFile(d.
filename);
250 if (pLoadedModel ==
nullptr) {
254 osg::ShadeModel* sm =
new osg::ShadeModel();
255 sm->setMode(osg::ShadeModel::FLAT);
256 pLoadedModel->getOrCreateStateSet()->setAttribute(sm);
257 osg::PositionAttitudeTransform* base =
new osg::PositionAttitudeTransform();
258 base->addChild(pLoadedModel);
259 osg::ComputeBoundsVisitor bboxCalc;
260 pLoadedModel->accept(bboxCalc);
261 const osg::BoundingBox& bbox = bboxCalc.getBoundingBox();
263 double xScale = d.
width > 0 ? d.
width / (bbox.xMax() - bbox.xMin()) : 1.;
264 double yScale = d.
height > 0 ? d.
height / (bbox.yMax() - bbox.yMin()) : 1.;
265 const double zScale = d.
altitude > 0 ? d.
altitude / (bbox.zMax() - bbox.zMin()) : 1.;
267 xScale = yScale = zScale;
269 base->setScale(osg::Vec3d(xScale, yScale, zScale));
271 base->setAttitude(osg::Quat(osg::DegreesToRadians(d.
roll), osg::Vec3d(1, 0, 0),
272 osg::DegreesToRadians(d.
tilt), osg::Vec3d(0, 1, 0),
273 osg::DegreesToRadians(d.
rot), osg::Vec3d(0, 0, 1)));
274 addTo.addChild(base);
278 osg::PositionAttitudeTransform*
279 GUIOSGBuilder::getTrafficLight(
const GUISUMOAbstractView::Decal& d, osg::Node* tl,
const osg::Vec4& color,
const double size) {
280 osg::PositionAttitudeTransform* ret =
new osg::PositionAttitudeTransform();
282 osg::PositionAttitudeTransform* base =
new osg::PositionAttitudeTransform();
284 osg::ComputeBoundsVisitor bboxCalc;
285 tl->accept(bboxCalc);
286 const osg::BoundingBox& bbox = bboxCalc.getBoundingBox();
287 double xScale = d.
width > 0 ? d.
width / (bbox.xMax() - bbox.xMin()) : 1.;
288 double yScale = d.
height > 0 ? d.
height / (bbox.yMax() - bbox.yMin()) : 1.;
289 const double zScale = d.
altitude > 0 ? d.
altitude / (bbox.zMax() - bbox.zMin()) : 1.;
291 xScale = yScale = zScale;
293 base->setScale(osg::Vec3d(xScale, yScale, zScale));
295 base->setAttitude(osg::Quat(osg::DegreesToRadians(d.
roll), osg::Vec3(1, 0, 0),
296 osg::DegreesToRadians(d.
tilt), osg::Vec3(0, 1, 0),
297 osg::DegreesToRadians(d.
rot), osg::Vec3(0, 0, 1)));
300 osg::Geode* geode =
new osg::Geode();
302 osg::ShapeDrawable* shape =
new osg::ShapeDrawable(
new osg::Sphere(center, (
float)size));
303 geode->addDrawable(shape);
304 osg::ref_ptr<osg::StateSet> ss = shape->getOrCreateStateSet();
305 ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
306 ss->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
307 osg::PositionAttitudeTransform* ellipse =
new osg::PositionAttitudeTransform();
308 ellipse->addChild(geode);
309 ellipse->setPivotPoint(center);
310 ellipse->setPosition(center);
311 ellipse->setScale(osg::Vec3d(4., 4., 2.5 * d.
altitude + 1.1));
312 shape->setColor(color);
313 ret->addChild(ellipse);
319 GUIOSGBuilder::setShapeState(osg::ref_ptr<osg::ShapeDrawable> shape) {
320 osg::ref_ptr<osg::StateSet> ss = shape->getOrCreateStateSet();
321 ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
322 ss->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
326 GUIOSGView::OSGMovable
328 GUIOSGView::OSGMovable m;
329 m.pos =
new osg::PositionAttitudeTransform();
331 const std::string& osgFile = type.
getOSGFile();
332 if (myCars.find(osgFile) == myCars.end()) {
333 myCars[osgFile] = osgDB::readNodeFile(osgFile);
334 if (myCars[osgFile] == 0) {
338 osg::Node* carNode = myCars[osgFile];
339 if (carNode !=
nullptr) {
340 osg::ComputeBoundsVisitor bboxCalc;
341 carNode->accept(bboxCalc);
342 const osg::BoundingBox& bbox = bboxCalc.getBoundingBox();
343 osg::PositionAttitudeTransform* base =
new osg::PositionAttitudeTransform();
344 base->addChild(carNode);
345 base->setPivotPoint(osg::Vec3d((bbox.xMin() + bbox.xMax()) / 2., bbox.yMin(), bbox.zMin()));
346 base->setScale(osg::Vec3d(type.
getWidth() / (bbox.xMax() - bbox.xMin()),
347 type.
getLength() / (bbox.yMax() - bbox.yMin()),
348 type.
getHeight() / (bbox.zMax() - bbox.zMin())));
349 m.pos->addChild(base);
352 m.lights =
new osg::Switch();
353 for (
double offset = -0.3; offset < 0.5; offset += 0.6) {
354 osg::Geode* geode =
new osg::Geode();
355 osg::ShapeDrawable* right =
new osg::ShapeDrawable(
new osg::Sphere(osg::Vec3d(offset, (type.
getLength() - .9) / 2., (type.
getHeight() - .5) / 2.), .1f));
356 geode->addDrawable(right);
357 setShapeState(right);
358 right->setColor(osg::Vec4(1.f, .5f, 0.f, .8f));
359 osg::Sequence* seq =
new osg::Sequence();
361 seq->addChild(geode, .33);
362 seq->addChild(
new osg::Geode(), .33);
364 seq->setInterval(osg::Sequence::LOOP, 0, -1);
366 seq->setDuration(1.0f, -1);
368 seq->setMode(osg::Sequence::START);
369 m.lights->addChild(seq);
372 osg::Geode* geode =
new osg::Geode();
373 osg::CompositeShape* comp =
new osg::CompositeShape();
374 comp->addChild(
new osg::Sphere(osg::Vec3d(-0.3, (type.
getLength() + .8) / 2., (type.
getHeight() - .5) / 2.), .1f));
375 comp->addChild(
new osg::Sphere(osg::Vec3d(0.3, (type.
getLength() + .8) / 2., (type.
getHeight() - .5) / 2.), .1f));
376 osg::ShapeDrawable* brake =
new osg::ShapeDrawable(comp);
377 brake->setColor(osg::Vec4(1.f, 0.f, 0.f, .8f));
378 geode->addDrawable(brake);
379 setShapeState(brake);
380 m.lights->addChild(geode);
382 geode =
new osg::Geode();
384 m.geom =
new osg::ShapeDrawable(
new osg::Sphere(center, .5f));
385 geode->addDrawable(m.geom);
386 setShapeState(m.geom);
387 osg::PositionAttitudeTransform* ellipse =
new osg::PositionAttitudeTransform();
388 ellipse->addChild(geode);
389 ellipse->addChild(m.lights);
390 ellipse->setPivotPoint(center);
391 ellipse->setPosition(center);
393 m.pos->addChild(ellipse);
#define WRITE_MESSAGE(msg)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const MSJunction & getJunction() const
Returns the represented junction.
Representation of a lane in the micro simulation (gui-version)
A MSNet extended by some values for usage within the gui.
std::vector< GUIJunctionWrapper * > myJunctionWrapper
Wrapped MS-junctions.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
bool isCrossing() const
return whether this edge is a pedestrian crossing
bool isWalkingArea() const
return whether this edge is walking area
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
const PositionVector & getShape() const
Returns this junction's shape.
Representation of a lane in the micro simulation.
const PositionVector & getShape() const
Returns this lane's shape.
double getWidth() const
Returns the lane's width.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Storage for all programs of a single tls.
void addSwitchCommand(OnSwitchAction *c)
MSTrafficLightLogic * getActive() const
std::vector< std::string > getAllTLIds() const
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
The car-following model and parameter.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
std::string getOSGFile() const
Get this vehicle type's 3D model file name.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
double getLength() const
Get vehicle's length [m].
const std::string & getID() const
Returns the id.
A point in 2D or 3D with translation and scaling methods.
double x() const
Returns the x-position.
double z() const
Returns the z-position.
double y() const
Returns the y-position.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
A decal (an image) that can be shown.
double tilt
The tilt of the image to the ground plane (in degrees)
double centerX
The center of the image in x-direction (net coordinates, in m)
double height
The height of the image (net coordinates in y-direction, in m)
double width
The width of the image (net coordinates in x-direction, in m)
double rot
The rotation of the image in the ground plane (in degrees)
double altitude
The altitude of the image (net coordinates in z-direction, in m)
double centerY
The center of the image in y-direction (net coordinates, in m)
double centerZ
The center of the image in z-direction (net coordinates, in m)
std::string filename
The path to the file the image is located at.
double roll
The roll of the image to the ground plane (in degrees)