INET Framework for OMNeT++/OMNEST
inet::physicalenvironment::PhysicalEnvironment Class Reference

This class represents the physical environment. More...

#include <PhysicalEnvironment.h>

Inheritance diagram for inet::physicalenvironment::PhysicalEnvironment:
inet::physicalenvironment::IPhysicalEnvironment

Public Member Functions

 PhysicalEnvironment ()
 
virtual ~PhysicalEnvironment ()
 
virtual IObjectCachegetObjectCache () const override
 
virtual IGroundgetGround () const override
 
virtual K getTemperature () const
 
virtual const CoordgetSpaceMin () const override
 
virtual const CoordgetSpaceMax () const override
 
virtual const IMaterialRegistrygetMaterialRegistry () const override
 
virtual int getNumObjects () const override
 
virtual const PhysicalObjectgetObject (int index) const override
 
virtual const PhysicalObjectgetObjectById (int id) const override
 
virtual void visitObjects (const IVisitor *visitor, const LineSegment &lineSegment) const override
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void convertPoints (std::vector< Coord > &points)
 
virtual void parseShapes (cXMLElement *xml)
 
virtual void parseMaterials (cXMLElement *xml)
 
virtual void parseObjects (cXMLElement *xml)
 

Protected Attributes

Parameters
IGeographicCoordinateSystemcoordinateSystem = nullptr
 
K temperature
 
Coord spaceMin
 
Coord spaceMax
 
Submodules
IObjectCacheobjectCache = nullptr
 
IGroundground = nullptr
 
Internal state
std::vector< const ShapeBase * > shapes
 
std::vector< const Material * > materials
 
std::vector< const PhysicalObject * > objects
 
Cache
std::map< int, const ShapeBase * > idToShapeMap
 
std::map< int, const Material * > idToMaterialMap
 
std::map< int, const PhysicalObject * > idToObjectMap
 
std::map< const std::string, const Material * > nameToMaterialMap
 

Detailed Description

This class represents the physical environment.

The physical environment contains a set of physical objects and it also specifies certain physical properties.

The physical environment draws the physical objects on the canvas of its parent module.

Constructor & Destructor Documentation

inet::physicalenvironment::PhysicalEnvironment::PhysicalEnvironment ( )
33  :
35  spaceMin(Coord(NaN, NaN, NaN)),
36  spaceMax(Coord(NaN, NaN, NaN)),
37  objectCache(nullptr)
38 {
39 }
Coord spaceMax
Definition: PhysicalEnvironment.h:51
IObjectCache * objectCache
Definition: PhysicalEnvironment.h:56
Coord spaceMin
Definition: PhysicalEnvironment.h:50
#define NaN
Definition: INETMath.h:103
K temperature
Definition: PhysicalEnvironment.h:49
inet::physicalenvironment::PhysicalEnvironment::~PhysicalEnvironment ( )
virtual
42 {
43  for (auto & elem : shapes)
44  delete elem;
45  for (auto & elem : materials)
46  delete elem;
47  for (auto & elem : objects)
48  delete elem;
49 }
std::vector< const ShapeBase * > shapes
Definition: PhysicalEnvironment.h:62
std::vector< const Material * > materials
Definition: PhysicalEnvironment.h:63
std::vector< const PhysicalObject * > objects
Definition: PhysicalEnvironment.h:64

Member Function Documentation

void inet::physicalenvironment::PhysicalEnvironment::convertPoints ( std::vector< Coord > &  points)
protectedvirtual

Referenced by parseObjects(), and parseShapes().

76 {
77  auto originPosition = coordinateSystem == nullptr ? GeoCoord(0, 0, 0) : coordinateSystem->computeGeographicCoordinate(Coord::ZERO);
78  Box boundingBox = Box::computeBoundingBox(points);
79  Coord center = boundingBox.getCenter();
80  for (auto & point : points) {
81  point -= center;
82  if (coordinateSystem != nullptr)
83  point = coordinateSystem->computePlaygroundCoordinate(GeoCoord(point.x + originPosition.latitude, point.y + originPosition.longitude, 0));
84  }
85 }
static Box computeBoundingBox(const std::vector< Coord > &points)
Definition: Box.cc:30
IGeographicCoordinateSystem * coordinateSystem
Definition: PhysicalEnvironment.h:48
virtual Coord computePlaygroundCoordinate(const GeoCoord &geographicCoordinate) const =0
virtual IGround* inet::physicalenvironment::PhysicalEnvironment::getGround ( ) const
inlineoverridevirtual

Implements inet::physicalenvironment::IPhysicalEnvironment.

89 { return ground; }
IGround * ground
Definition: PhysicalEnvironment.h:57
virtual const IMaterialRegistry* inet::physicalenvironment::PhysicalEnvironment::getMaterialRegistry ( ) const
inlineoverridevirtual

Implements inet::physicalenvironment::IPhysicalEnvironment.

95 { return &MaterialRegistry::singleton; }
static MaterialRegistry singleton
Definition: MaterialRegistry.h:34
virtual int inet::physicalenvironment::PhysicalEnvironment::getNumObjects ( ) const
inlineoverridevirtual
virtual const PhysicalObject* inet::physicalenvironment::PhysicalEnvironment::getObject ( int  index) const
inlineoverridevirtual
const PhysicalObject * inet::physicalenvironment::PhysicalEnvironment::getObjectById ( int  id) const
overridevirtual

Implements inet::physicalenvironment::IPhysicalEnvironment.

475 {
476  std::map<int, const PhysicalObject *>::const_iterator it = idToObjectMap.find(id);
477  if (it == idToObjectMap.end())
478  return nullptr;
479  else
480  return it->second;
481 }
std::map< int, const PhysicalObject * > idToObjectMap
Definition: PhysicalEnvironment.h:71
virtual IObjectCache* inet::physicalenvironment::PhysicalEnvironment::getObjectCache ( ) const
inlineoverridevirtual

Implements inet::physicalenvironment::IPhysicalEnvironment.

88 { return objectCache; }
IObjectCache * objectCache
Definition: PhysicalEnvironment.h:56
virtual const Coord& inet::physicalenvironment::PhysicalEnvironment::getSpaceMax ( ) const
inlineoverridevirtual
virtual const Coord& inet::physicalenvironment::PhysicalEnvironment::getSpaceMin ( ) const
inlineoverridevirtual
virtual K inet::physicalenvironment::PhysicalEnvironment::getTemperature ( ) const
inlinevirtual
91 { return temperature; }
K temperature
Definition: PhysicalEnvironment.h:49
void inet::physicalenvironment::PhysicalEnvironment::initialize ( int  stage)
overrideprotectedvirtual
52 {
53  if (stage == INITSTAGE_LOCAL)
54  {
55  coordinateSystem = getModuleFromPar<IGeographicCoordinateSystem>(par("coordinateSystemModule"), this, false);
56  objectCache = dynamic_cast<IObjectCache *>(getSubmodule("objectCache"));
57  ground = dynamic_cast<IGround *>(getSubmodule("ground"));
58  temperature = K(par("temperature"));
59  spaceMin.x = par("spaceMinX");
60  spaceMin.y = par("spaceMinY");
61  spaceMin.z = par("spaceMinZ");
62  spaceMax.x = par("spaceMaxX");
63  spaceMax.y = par("spaceMaxY");
64  spaceMax.z = par("spaceMaxZ");
65  }
66  else if (stage == INITSTAGE_PHYSICAL_ENVIRONMENT)
67  {
68  cXMLElement *environment = par("config");
69  parseShapes(environment);
70  parseMaterials(environment);
71  parseObjects(environment);
72  }
73 }
IGround * ground
Definition: PhysicalEnvironment.h:57
Coord spaceMax
Definition: PhysicalEnvironment.h:51
IObjectCache * objectCache
Definition: PhysicalEnvironment.h:56
double z
Definition: Coord.h:51
virtual void parseObjects(cXMLElement *xml)
Definition: PhysicalEnvironment.cc:229
Physical environment initializations (mobility, obstacles, battery, annotations, etc).
Definition: InitStages.h:40
Coord spaceMin
Definition: PhysicalEnvironment.h:50
Local initializations.
Definition: InitStages.h:35
value< double, units::K > K
Definition: Units.h:1050
virtual void parseMaterials(cXMLElement *xml)
Definition: PhysicalEnvironment.cc:191
IGeographicCoordinateSystem * coordinateSystem
Definition: PhysicalEnvironment.h:48
K temperature
Definition: PhysicalEnvironment.h:49
double y
Definition: Coord.h:50
double x
Definition: Coord.h:49
virtual void parseShapes(cXMLElement *xml)
Definition: PhysicalEnvironment.cc:87
virtual int inet::physicalenvironment::PhysicalEnvironment::numInitStages ( ) const
inlineoverrideprotectedvirtual
76 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::physicalenvironment::PhysicalEnvironment::parseMaterials ( cXMLElement *  xml)
protectedvirtual

Referenced by initialize().

192 {
193  cXMLElementList children = xml->getChildrenByTagName("material");
194  for (cXMLElementList::const_iterator it = children.begin(); it != children.end(); ++it)
195  {
196  cXMLElement *element = *it;
197  // id
198  const char *idAttribute = element->getAttribute("id");
199  if (!idAttribute)
200  throw cRuntimeError("Missing mandatory id attribute of material");
201  int id = atoi(idAttribute);
202  // name
203  const char *name = element->getAttribute("name");
204  // resistivity
205  const char *resistivityAttribute = element->getAttribute("resistivity");
206  if (!resistivityAttribute)
207  throw cRuntimeError("Missing mandatory resistivity attribute of material");
208  Ohmm resistivity = Ohmm(atof(resistivityAttribute));
209  // relativePermittivity
210  const char *relativePermittivityAttribute = element->getAttribute("relativePermittivity");
211  if (!relativePermittivityAttribute)
212  throw cRuntimeError("Missing mandatory relativePermittivity attribute of material");
213  double relativePermittivity = atof(relativePermittivityAttribute);
214  // relativePermeability
215  const char *relativePermeabilityAttribute = element->getAttribute("relativePermeability");
216  if (!relativePermeabilityAttribute)
217  throw cRuntimeError("Missing mandatory relativePermeability attribute of material");
218  double relativePermeability = atof(relativePermeabilityAttribute);
219  // insert
220  if (idToMaterialMap.find(id) != idToMaterialMap.end())
221  throw cRuntimeError("Material already exists with the same id: '%d'", id);
222  Material *material = new Material(name, resistivity, relativePermittivity, relativePermeability);
223  materials.push_back(material);
224  idToMaterialMap.insert(std::pair<int, const Material *>(id, material));
225  nameToMaterialMap.insert(std::pair<const std::string, const Material *>(material->getName(), material));
226  }
227 }
compose< Ohm, m > Ohmm
Definition: Units.h:775
std::map< int, const Material * > idToMaterialMap
Definition: PhysicalEnvironment.h:70
std::vector< const Material * > materials
Definition: PhysicalEnvironment.h:63
std::map< const std::string, const Material * > nameToMaterialMap
Definition: PhysicalEnvironment.h:72
void inet::physicalenvironment::PhysicalEnvironment::parseObjects ( cXMLElement *  xml)
protectedvirtual

Referenced by initialize().

230 {
231  Coord computedSpaceMin = Coord::NIL;
232  Coord computedSpaceMax = Coord::NIL;;
233  cXMLElementList children = xml->getChildren();
234  for (cXMLElementList::const_iterator it = children.begin(); it != children.end(); ++it)
235  {
236  const char *tok;
237  cXMLElement *element = *it;
238  const char *tag = element->getTagName();
239  if (strcmp(tag, "object"))
240  continue;
241  // id
242  const char *idAttribute = element->getAttribute("id");
243  int id = -1;
244  if (idAttribute)
245  id = atoi(idAttribute);
246  // name
247  const char *name = element->getAttribute("name");
248  // orientation
249  EulerAngles orientation;
250  const char *orientationAttribute = element->getAttribute("orientation");
251  if (orientationAttribute)
252  {
253  cStringTokenizer tokenizer(orientationAttribute);
254  if ((tok = tokenizer.nextToken()) == nullptr)
255  throw cRuntimeError("Missing orientation alpha at %s", element->getSourceLocation());
256  orientation.alpha = math::deg2rad(atof(tok));
257  if ((tok = tokenizer.nextToken()) == nullptr)
258  throw cRuntimeError("Missing orientation beta at %s", element->getSourceLocation());
259  orientation.beta = math::deg2rad(atof(tok));
260  if ((tok = tokenizer.nextToken()) == nullptr)
261  throw cRuntimeError("Missing orientation gamma at %s", element->getSourceLocation());
262  orientation.gamma = math::deg2rad(atof(tok));
263  }
264  // shape
265  Coord size = Coord::NIL;
266  const ShapeBase *shape = nullptr;
267  const char *shapeAttribute = element->getAttribute("shape");
268  if (!shapeAttribute)
269  throw cRuntimeError("Missing shape attribute of object");
270  cStringTokenizer shapeTokenizer(shapeAttribute);
271  const char *shapeType = shapeTokenizer.nextToken();
272  if (!strcmp(shapeType, "cuboid"))
273  {
274  if ((tok = shapeTokenizer.nextToken()) == nullptr)
275  throw cRuntimeError("Missing cuboid x at %s", element->getSourceLocation());
276  size.x = atof(tok);
277  if ((tok = shapeTokenizer.nextToken()) == nullptr)
278  throw cRuntimeError("Missing cuboid y at %s", element->getSourceLocation());
279  size.y = atof(tok);
280  if ((tok = shapeTokenizer.nextToken()) == nullptr)
281  throw cRuntimeError("Missing cuboid z at %s", element->getSourceLocation());
282  size.z = atof(tok);
283  shape = new Cuboid(size);
284  shapes.push_back(shape);
285  }
286  else if (!strcmp(shapeType, "sphere"))
287  {
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;
293  shapes.push_back(shape);
294  }
295  else if (!strcmp(shapeType, "prism"))
296  {
297  double height;
298  if ((tok = shapeTokenizer.nextToken()) == nullptr)
299  throw cRuntimeError("Missing prism height at %s", element->getSourceLocation());
300  height = atof(tok);
301  std::vector<Coord> points;
302  while (shapeTokenizer.hasMoreTokens())
303  {
304  Coord point;
305  point.x = atof(shapeTokenizer.nextToken());
306  if ((tok = shapeTokenizer.nextToken()) == nullptr)
307  throw cRuntimeError("Missing prism y at %s", element->getSourceLocation());
308  point.y = atof(tok);
309  point.z = -height / 2;
310  points.push_back(point);
311  }
312  if (points.size() < 3)
313  throw cRuntimeError("prism needs at least three points at %s", element->getSourceLocation());
314  size = Box::computeBoundingBox(points).getSize();
315  convertPoints(points);
316  shape = new Prism(height, Polygon(points));
317  shapes.push_back(shape);
318  }
319  else if (!strcmp(shapeType, "polyhedron"))
320  {
321  std::vector<Coord> points;
322  while (shapeTokenizer.hasMoreTokens())
323  {
324  Coord point;
325  point.x = atof(shapeTokenizer.nextToken());
326  if ((tok = shapeTokenizer.nextToken()) == nullptr)
327  throw cRuntimeError("Missing polyhedron y at %s", element->getSourceLocation());
328  point.y = atof(tok);
329  if ((tok = shapeTokenizer.nextToken()) == nullptr)
330  throw cRuntimeError("Missing polyhedron z at %s", element->getSourceLocation());
331  point.z = atof(tok);
332  points.push_back(point);
333  }
334  if (points.size() < 4)
335  throw cRuntimeError("polyhedron needs at least four points at %s", element->getSourceLocation());
336  size = Box::computeBoundingBox(points).getSize();
337  convertPoints(points);
338  shape = new Polyhedron(points);
339  shapes.push_back(shape);
340  }
341  else {
342  int id = atoi(shapeAttribute);
343  shape = idToShapeMap[id];
344  }
345  if (!shape)
346  throw cRuntimeError("Unknown shape '%s'", shapeAttribute);
347  // position
348  Coord position = Coord::NIL;
349  const char *positionAttribute = element->getAttribute("position");
350  if (positionAttribute)
351  {
352  cStringTokenizer tokenizer(positionAttribute);
353  const char *kind = tokenizer.nextToken();
354  if (!kind)
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"))
370  position += Coord::ZERO;
371  else
372  throw cRuntimeError("Unknown position kind");
373  if (coordinateSystem != nullptr) {
374  auto convertedPosition = coordinateSystem->computePlaygroundCoordinate(GeoCoord(position.x, position.y, 0));
375  position.x = convertedPosition.x;
376  position.y = convertedPosition.y;
377  }
378  }
379  // material
380  const Material *material;
381  const char *materialAttribute = element->getAttribute("material");
382  if (!materialAttribute)
383  throw cRuntimeError("Missing material attribute of object");
384  else if (nameToMaterialMap.find(materialAttribute) != nameToMaterialMap.end())
385  material = nameToMaterialMap[materialAttribute];
386  else if (MaterialRegistry::singleton.getMaterial(materialAttribute))
387  material = MaterialRegistry::singleton.getMaterial(materialAttribute);
388  else
389  material = idToMaterialMap[atoi(materialAttribute)];
390  if (!material)
391  throw cRuntimeError("Unknown material '%s'", materialAttribute);
392  // line width
393  double lineWidth = 1;
394  const char *lineWidthAttribute = element->getAttribute("line-width");
395  if (lineWidthAttribute)
396  lineWidth = atof(lineWidthAttribute);
397  // line color
398  cFigure::Color lineColor = cFigure::BLACK;
399  const char *lineColorAttribute = element->getAttribute("line-color");
400  if (lineColorAttribute)
401  {
402  if (strchr(lineColorAttribute, ' '))
403  {
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);
414  }
415  else
416  lineColor = cFigure::Color(lineColorAttribute);
417  }
418  // fill color
419  cFigure::Color fillColor = cFigure::WHITE;
420  const char *fillColorAttribute = element->getAttribute("fill-color");
421  if (fillColorAttribute)
422  {
423  if (strchr(fillColorAttribute, ' '))
424  {
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);
435  }
436  else
437  fillColor = cFigure::Color(fillColorAttribute);
438  }
439  // opacity
440  double opacity = 1;
441  const char *opacityAttribute = element->getAttribute("opacity");
442  if (opacityAttribute)
443  opacity = atof(opacityAttribute);
444  // texture
445  const char *texture = element->getAttribute("texture");
446  // tags
447  const char *tags = element->getAttribute("tags");
448  // insert object
449  PhysicalObject *object = new PhysicalObject(name, id, position, orientation, shape, material, lineWidth, lineColor, fillColor, opacity, texture, tags);
450  objects.push_back(object);
451  if (id != -1)
452  idToObjectMap.insert(std::pair<int, const PhysicalObject *>(id, object));
453  const Coord min = position - size / 2;
454  const Coord max = position + size / 2;
455  if ((!std::isnan(spaceMin.x) && min.x < spaceMin.x) || (!std::isnan(spaceMax.x) && max.x > spaceMax.x) ||
456  (!std::isnan(spaceMin.y) && min.y < spaceMin.y) || (!std::isnan(spaceMax.y) && max.y > spaceMax.y) ||
457  (!std::isnan(spaceMin.z) && min.z < spaceMin.z) || (!std::isnan(spaceMax.z) && max.z > spaceMax.z))
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;
465  }
466  if (std::isnan(spaceMin.x)) spaceMin.x = computedSpaceMin.x;
467  if (std::isnan(spaceMin.y)) spaceMin.y = computedSpaceMin.y;
468  if (std::isnan(spaceMin.z)) spaceMin.z = computedSpaceMin.z;
469  if (std::isnan(spaceMax.x)) spaceMax.x = computedSpaceMax.x;
470  if (std::isnan(spaceMax.y)) spaceMax.y = computedSpaceMax.y;
471  if (std::isnan(spaceMax.z)) spaceMax.z = computedSpaceMax.z;
472 }
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
void inet::physicalenvironment::PhysicalEnvironment::parseShapes ( cXMLElement *  xml)
protectedvirtual

Referenced by initialize().

88 {
89  cXMLElementList children = xml->getChildrenByTagName("shape");
90  for (cXMLElementList::const_iterator it = children.begin(); it != children.end(); ++it)
91  {
92  cXMLElement *element = *it;
93  ShapeBase *shape = nullptr;
94  const char *tok;
95  // id
96  const char *idAttribute = element->getAttribute("id");
97  int id = -1;
98  if (idAttribute)
99  id = atoi(idAttribute);
100  // type
101  const char *typeAttribute = element->getAttribute("type");
102  if (!typeAttribute)
103  throw cRuntimeError("Missing type attribute of shape");
104  else if (!strcmp(typeAttribute, "cuboid"))
105  {
106  Coord size;
107  const char *sizeAttribute = element->getAttribute("size");
108  if (!sizeAttribute)
109  throw cRuntimeError("Missing size attribute of cuboid");
110  cStringTokenizer tokenizer(sizeAttribute);
111  if ((tok = tokenizer.nextToken()) == nullptr)
112  throw cRuntimeError("Missing cuboid size x at %s", element->getSourceLocation());
113  size.x = atof(tok);
114  if ((tok = tokenizer.nextToken()) == nullptr)
115  throw cRuntimeError("Missing cuboid size y at %s", element->getSourceLocation());
116  size.y = atof(tok);
117  if ((tok = tokenizer.nextToken()) == nullptr)
118  throw cRuntimeError("Missing cuboid size z at %s", element->getSourceLocation());
119  size.z = atof(tok);
120  shape = new Cuboid(size);
121  }
122  else if (!strcmp(typeAttribute, "sphere"))
123  {
124  double radius;
125  const char *radiusAttribute = element->getAttribute("radius");
126  if (!radiusAttribute)
127  throw cRuntimeError("Missing radius attribute of sphere");
128  radius = atof(radiusAttribute);
129  shape = new Sphere(radius);
130  }
131  else if (!strcmp(typeAttribute, "prism"))
132  {
133  double height;
134  const char *heightAttribute = element->getAttribute("height");
135  if (!heightAttribute)
136  throw cRuntimeError("Missing height attribute of prism");
137  height = atof(heightAttribute);
138  std::vector<Coord> points;
139  const char *pointsAttribute = element->getAttribute("points");
140  if (!pointsAttribute)
141  throw cRuntimeError("Missing points attribute of prism");
142  cStringTokenizer tokenizer(pointsAttribute);
143  while (tokenizer.hasMoreTokens())
144  {
145  Coord point;
146  point.x = atof(tokenizer.nextToken());
147  if ((tok = tokenizer.nextToken()) == nullptr)
148  throw cRuntimeError("Missing prism y at %s", element->getSourceLocation());
149  point.y = atof(tok);
150  point.z = -height / 2;
151  points.push_back(point);
152  }
153  if (points.size() < 3)
154  throw cRuntimeError("prism needs at least three points at %s", element->getSourceLocation());
155  convertPoints(points);
156  shape = new Prism(height, Polygon(points));
157  }
158  else if (!strcmp(typeAttribute, "polyhedron"))
159  {
160  std::vector<Coord> points;
161  const char *pointsAttribute = element->getAttribute("points");
162  if (!pointsAttribute)
163  throw cRuntimeError("Missing points attribute of polyhedron");
164  cStringTokenizer tokenizer(pointsAttribute);
165  while (tokenizer.hasMoreTokens())
166  {
167  Coord point;
168  point.x = atof(tokenizer.nextToken());
169  if ((tok = tokenizer.nextToken()) == nullptr)
170  throw cRuntimeError("Missing polyhedron y at %s", element->getSourceLocation());
171  point.y = atof(tok);
172  if ((tok = tokenizer.nextToken()) == nullptr)
173  throw cRuntimeError("Missing polyhedron z at %s", element->getSourceLocation());
174  point.z = atof(tok);
175  points.push_back(point);
176  }
177  if (points.size() < 4)
178  throw cRuntimeError("polyhedron needs at least four points at %s", element->getSourceLocation());
179  convertPoints(points);
180  shape = new Polyhedron(points);
181  }
182  else
183  throw cRuntimeError("Unknown shape type '%s'", typeAttribute);
184  // insert
185  if (idToShapeMap.find(id) != idToShapeMap.end())
186  throw cRuntimeError("Shape already exists with the same id: '%d'", id);
187  idToShapeMap.insert(std::pair<int, const ShapeBase *>(id, shape));
188  }
189 }
virtual void convertPoints(std::vector< Coord > &points)
Definition: PhysicalEnvironment.cc:75
std::map< int, const ShapeBase * > idToShapeMap
Definition: PhysicalEnvironment.h:69
void inet::physicalenvironment::PhysicalEnvironment::visitObjects ( const IVisitor visitor,
const LineSegment lineSegment 
) const
overridevirtual

Implements inet::physicalenvironment::IPhysicalEnvironment.

484 {
485  if (objectCache)
486  objectCache->visitObjects(visitor, lineSegment);
487  else
488  for (const auto & elem : objects)
489  visitor->visit(elem);
490 }
IObjectCache * objectCache
Definition: PhysicalEnvironment.h:56
virtual void visitObjects(const IVisitor *visitor, const LineSegment &lineSegment) const =0
Calls the visitor with at least all physical objects that intersect with the provided line segment...
std::vector< const PhysicalObject * > objects
Definition: PhysicalEnvironment.h:64

Member Data Documentation

IGeographicCoordinateSystem* inet::physicalenvironment::PhysicalEnvironment::coordinateSystem = nullptr
protected
IGround* inet::physicalenvironment::PhysicalEnvironment::ground = nullptr
protected

Referenced by initialize().

std::map<int, const Material *> inet::physicalenvironment::PhysicalEnvironment::idToMaterialMap
protected

Referenced by parseMaterials(), and parseObjects().

std::map<int, const PhysicalObject *> inet::physicalenvironment::PhysicalEnvironment::idToObjectMap
protected

Referenced by getObjectById(), and parseObjects().

std::map<int, const ShapeBase *> inet::physicalenvironment::PhysicalEnvironment::idToShapeMap
protected

Referenced by parseObjects(), and parseShapes().

std::vector<const Material *> inet::physicalenvironment::PhysicalEnvironment::materials
protected
std::map<const std::string, const Material *> inet::physicalenvironment::PhysicalEnvironment::nameToMaterialMap
protected

Referenced by parseMaterials(), and parseObjects().

IObjectCache* inet::physicalenvironment::PhysicalEnvironment::objectCache = nullptr
protected

Referenced by initialize(), and visitObjects().

std::vector<const PhysicalObject *> inet::physicalenvironment::PhysicalEnvironment::objects
protected
std::vector<const ShapeBase *> inet::physicalenvironment::PhysicalEnvironment::shapes
protected
Coord inet::physicalenvironment::PhysicalEnvironment::spaceMax
protected

Referenced by initialize(), and parseObjects().

Coord inet::physicalenvironment::PhysicalEnvironment::spaceMin
protected

Referenced by initialize(), and parseObjects().

K inet::physicalenvironment::PhysicalEnvironment::temperature
protected

Referenced by initialize().


The documentation for this class was generated from the following files: