233 cXMLElementList children = xml->getChildren();
234 for (cXMLElementList::const_iterator it = children.begin(); it != children.end(); ++it)
237 cXMLElement *element = *it;
238 const char *tag = element->getTagName();
239 if (strcmp(tag,
"object"))
242 const char *idAttribute = element->getAttribute(
"id");
245 id = atoi(idAttribute);
247 const char *name = element->getAttribute(
"name");
249 EulerAngles orientation;
250 const char *orientationAttribute = element->getAttribute(
"orientation");
251 if (orientationAttribute)
253 cStringTokenizer tokenizer(orientationAttribute);
254 if ((tok = tokenizer.nextToken()) ==
nullptr)
255 throw cRuntimeError(
"Missing orientation alpha at %s", element->getSourceLocation());
257 if ((tok = tokenizer.nextToken()) ==
nullptr)
258 throw cRuntimeError(
"Missing orientation beta at %s", element->getSourceLocation());
260 if ((tok = tokenizer.nextToken()) ==
nullptr)
261 throw cRuntimeError(
"Missing orientation gamma at %s", element->getSourceLocation());
266 const ShapeBase *shape =
nullptr;
267 const char *shapeAttribute = element->getAttribute(
"shape");
269 throw cRuntimeError(
"Missing shape attribute of object");
270 cStringTokenizer shapeTokenizer(shapeAttribute);
271 const char *shapeType = shapeTokenizer.nextToken();
272 if (!strcmp(shapeType,
"cuboid"))
274 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
275 throw cRuntimeError(
"Missing cuboid x at %s", element->getSourceLocation());
277 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
278 throw cRuntimeError(
"Missing cuboid y at %s", element->getSourceLocation());
280 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
281 throw cRuntimeError(
"Missing cuboid z at %s", element->getSourceLocation());
283 shape =
new Cuboid(size);
286 else if (!strcmp(shapeType,
"sphere"))
288 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
289 throw cRuntimeError(
"Missing sphere radius at %s", element->getSourceLocation());
290 double radius = atof(tok);
291 shape =
new Sphere(radius);
292 size = Coord(radius, radius, radius) * 2;
295 else if (!strcmp(shapeType,
"prism"))
298 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
299 throw cRuntimeError(
"Missing prism height at %s", element->getSourceLocation());
301 std::vector<Coord> points;
302 while (shapeTokenizer.hasMoreTokens())
305 point.x = atof(shapeTokenizer.nextToken());
306 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
307 throw cRuntimeError(
"Missing prism y at %s", element->getSourceLocation());
309 point.z = -height / 2;
310 points.push_back(point);
312 if (points.size() < 3)
313 throw cRuntimeError(
"prism needs at least three points at %s", element->getSourceLocation());
316 shape =
new Prism(height, Polygon(points));
319 else if (!strcmp(shapeType,
"polyhedron"))
321 std::vector<Coord> points;
322 while (shapeTokenizer.hasMoreTokens())
325 point.x = atof(shapeTokenizer.nextToken());
326 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
327 throw cRuntimeError(
"Missing polyhedron y at %s", element->getSourceLocation());
329 if ((tok = shapeTokenizer.nextToken()) ==
nullptr)
330 throw cRuntimeError(
"Missing polyhedron z at %s", element->getSourceLocation());
332 points.push_back(point);
334 if (points.size() < 4)
335 throw cRuntimeError(
"polyhedron needs at least four points at %s", element->getSourceLocation());
338 shape =
new Polyhedron(points);
342 int id = atoi(shapeAttribute);
346 throw cRuntimeError(
"Unknown shape '%s'", shapeAttribute);
349 const char *positionAttribute = element->getAttribute(
"position");
350 if (positionAttribute)
352 cStringTokenizer tokenizer(positionAttribute);
353 const char *kind = tokenizer.nextToken();
355 throw cRuntimeError(
"Missing position kind");
356 if ((tok = tokenizer.nextToken()) ==
nullptr)
357 throw cRuntimeError(
"Missing position x at %s", element->getSourceLocation());
358 position.x = atof(tok);
359 if ((tok = tokenizer.nextToken()) ==
nullptr)
360 throw cRuntimeError(
"Missing position y at %s", element->getSourceLocation());
361 position.y = atof(tok);
362 if ((tok = tokenizer.nextToken()) ==
nullptr)
363 throw cRuntimeError(
"Missing position z at %s", element->getSourceLocation());
364 position.z = atof(tok);
365 if (!strcmp(kind,
"min"))
366 position += size / 2;
367 else if (!strcmp(kind,
"max"))
368 position -= size / 2;
369 else if (!strcmp(kind,
"center"))
372 throw cRuntimeError(
"Unknown position kind");
375 position.
x = convertedPosition.x;
376 position.y = convertedPosition.y;
380 const Material *material;
381 const char *materialAttribute = element->getAttribute(
"material");
382 if (!materialAttribute)
383 throw cRuntimeError(
"Missing material attribute of object");
391 throw cRuntimeError(
"Unknown material '%s'", materialAttribute);
393 double lineWidth = 1;
394 const char *lineWidthAttribute = element->getAttribute(
"line-width");
395 if (lineWidthAttribute)
396 lineWidth = atof(lineWidthAttribute);
399 const char *lineColorAttribute = element->getAttribute(
"line-color");
400 if (lineColorAttribute)
402 if (strchr(lineColorAttribute,
' '))
404 cStringTokenizer tokenizer(lineColorAttribute);
405 if ((tok = tokenizer.nextToken()) ==
nullptr)
406 throw cRuntimeError(
"Missing line-color red at %s", element->getSourceLocation());
407 lineColor.red = atoi(tok);
408 if ((tok = tokenizer.nextToken()) ==
nullptr)
409 throw cRuntimeError(
"Missing line-color green at %s", element->getSourceLocation());
410 lineColor.green = atoi(tok);
411 if ((tok = tokenizer.nextToken()) ==
nullptr)
412 throw cRuntimeError(
"Missing line-color blue at %s", element->getSourceLocation());
413 lineColor.blue = atoi(tok);
420 const char *fillColorAttribute = element->getAttribute(
"fill-color");
421 if (fillColorAttribute)
423 if (strchr(fillColorAttribute,
' '))
425 cStringTokenizer tokenizer(fillColorAttribute);
426 if ((tok = tokenizer.nextToken()) ==
nullptr)
427 throw cRuntimeError(
"Missing fill-color red at %s", element->getSourceLocation());
428 fillColor.red = atoi(tok);
429 if ((tok = tokenizer.nextToken()) ==
nullptr)
430 throw cRuntimeError(
"Missing fill-color green at %s", element->getSourceLocation());
431 fillColor.green = atoi(tok);
432 if ((tok = tokenizer.nextToken()) ==
nullptr)
433 throw cRuntimeError(
"Missing fill-color blue at %s", element->getSourceLocation());
434 fillColor.blue = atoi(tok);
441 const char *opacityAttribute = element->getAttribute(
"opacity");
442 if (opacityAttribute)
443 opacity = atof(opacityAttribute);
445 const char *texture = element->getAttribute(
"texture");
447 const char *tags = element->getAttribute(
"tags");
449 PhysicalObject *
object =
new PhysicalObject(name,
id, position, orientation, shape, material, lineWidth, lineColor, fillColor, opacity, texture, tags);
452 idToObjectMap.insert(std::pair<int, const PhysicalObject *>(
id,
object));
453 const Coord
min = position - size / 2;
454 const Coord
max = position + size / 2;
458 throw cRuntimeError(
"Object is outside of space limits");
459 if (std::isnan(computedSpaceMin.x) || min.x < computedSpaceMin.x) computedSpaceMin.x = min.x;
460 if (std::isnan(computedSpaceMin.y) || min.y < computedSpaceMin.y) computedSpaceMin.y = min.y;
461 if (std::isnan(computedSpaceMin.z) || min.z < computedSpaceMin.z) computedSpaceMin.z = min.z;
462 if (std::isnan(computedSpaceMax.x) || max.x > computedSpaceMax.x) computedSpaceMax.x = max.x;
463 if (std::isnan(computedSpaceMax.y) || max.y > computedSpaceMax.y) computedSpaceMax.y = max.y;
464 if (std::isnan(computedSpaceMax.z) || max.z > computedSpaceMax.z) computedSpaceMax.z = max.z;
Coord spaceMax
Definition: PhysicalEnvironment.h:51
std::map< int, const PhysicalObject * > idToObjectMap
Definition: PhysicalEnvironment.h:71
std::vector< const ShapeBase * > shapes
Definition: PhysicalEnvironment.h:62
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
double z
Definition: Coord.h:51
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
static MaterialRegistry singleton
Definition: MaterialRegistry.h:34
std::map< int, const Material * > idToMaterialMap
Definition: PhysicalEnvironment.h:70
double max(double a, double b)
Returns the greater of the given parameters.
Definition: INETMath.h:161
Coord spaceMin
Definition: PhysicalEnvironment.h:50
virtual void convertPoints(std::vector< Coord > &points)
Definition: PhysicalEnvironment.cc:75
static Box computeBoundingBox(const std::vector< Coord > &points)
Definition: Box.cc:30
Color
Definition: DiffservUtil.h:30
Coord getSize() const
Definition: Box.h:43
double deg2rad(double deg)
Convert a degree value to radian.
Definition: INETMath.h:186
IGeographicCoordinateSystem * coordinateSystem
Definition: PhysicalEnvironment.h:48
uint16_t id
Definition: TCP_NSC.cc:85
static const Coord ZERO
Definition: Coord.h:41
double y
Definition: Coord.h:50
std::map< const std::string, const Material * > nameToMaterialMap
Definition: PhysicalEnvironment.h:72
double x
Definition: Coord.h:49
virtual Coord computePlaygroundCoordinate(const GeoCoord &geographicCoordinate) const =0
std::map< int, const ShapeBase * > idToShapeMap
Definition: PhysicalEnvironment.h:69
std::vector< const PhysicalObject * > objects
Definition: PhysicalEnvironment.h:64