INET Framework for OMNeT++/OMNEST
inet::visualizer::PhysicalEnvironmentCanvasVisualizer Class Reference

#include <PhysicalEnvironmentCanvasVisualizer.h>

Inheritance diagram for inet::visualizer::PhysicalEnvironmentCanvasVisualizer:
inet::visualizer::PhysicalEnvironmentVisualizerBase inet::visualizer::VisualizerBase

Classes

class  ObjectPositionComparator
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void refreshDisplay () const override
 
virtual void computeFacePoints (const IPhysicalObject *object, std::vector< std::vector< Coord > > &faces, const Rotation &rotation) const
 
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
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 InterfaceEntrygetInterfaceEntry (cModule *networkNode, cModule *module) const
 

Protected Attributes

double zIndex = NaN
 
Internal state
const CanvasProjectioncanvasProjection
 
Graphics
cGroupFigure * objectsLayer = nullptr
 
- Protected Attributes inherited from inet::visualizer::PhysicalEnvironmentVisualizerBase
const IPhysicalEnvironmentphysicalEnvironment = nullptr
 
bool displayObjects = false
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Member Function Documentation

void inet::visualizer::PhysicalEnvironmentCanvasVisualizer::computeFacePoints ( const IPhysicalObject object,
std::vector< std::vector< Coord > > &  faces,
const Rotation rotation 
) const
protectedvirtual

Referenced by refreshDisplay().

119 {
120  const Coord& position = object->getPosition();
121  for (std::vector<std::vector<Coord> >::const_iterator it = faces.begin(); it != faces.end(); it++)
122  {
123  std::vector<cFigure::Point> canvasPoints;
124  const std::vector<Coord>& facePoints = *it;
125  for (const auto & facePoint : facePoints)
126  {
127  cFigure::Point canvPoint = canvasProjection->computeCanvasPoint(rotation.rotateVectorClockwise(facePoint) + position);
128  canvasPoints.push_back(canvPoint);
129  }
130  cPolygonFigure *figure = new cPolygonFigure("objectFace");
131  figure->setTooltip("This polygon represents a physical object");
132  figure->setAssociatedObject(const_cast<cObject *>(check_and_cast<const cObject *>(object)));
133  figure->setFilled(true);
134  figure->setPoints(canvasPoints);
135  figure->setLineWidth(object->getLineWidth());
136  figure->setLineColor(object->getLineColor());
137  figure->setFillColor(object->getFillColor());
138  figure->setLineOpacity(object->getOpacity());
139  figure->setFillOpacity(object->getOpacity());
140  figure->setZoomLineWidth(false);
141  std::string objectTags("physical_object ");
142  if (object->getTags())
143  objectTags += object->getTags();
144  figure->setTags((objectTags + " " + tags).c_str());
145  objectsLayer->addFigure(figure);
146  }
147 }
const char * tags
Definition: VisualizerBase.h:32
const CanvasProjection * canvasProjection
Definition: PhysicalEnvironmentCanvasVisualizer.h:51
cGroupFigure * objectsLayer
Definition: PhysicalEnvironmentCanvasVisualizer.h:56
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:32
void inet::visualizer::PhysicalEnvironmentCanvasVisualizer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::PhysicalEnvironmentVisualizerBase.

33 {
35  if (!hasGUI()) return;
36  if (stage == INITSTAGE_LOCAL) {
37  zIndex = par("zIndex");
38  cCanvas *canvas = visualizerTargetModule->getCanvas();
40  objectsLayer = new cGroupFigure("objectsLayer");
41  objectsLayer->setZIndex(zIndex);
42  objectsLayer->insertBelow(canvas->getSubmodulesLayer());
43  }
44 }
double zIndex
Definition: PhysicalEnvironmentCanvasVisualizer.h:48
const CanvasProjection * canvasProjection
Definition: PhysicalEnvironmentCanvasVisualizer.h:51
cGroupFigure * objectsLayer
Definition: PhysicalEnvironmentCanvasVisualizer.h:56
Local initializations.
Definition: InitStages.h:35
virtual void initialize(int stage) override
Definition: PhysicalEnvironmentVisualizerBase.cc:25
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
static const CanvasProjection * getCanvasProjection(const cCanvas *canvas)
Definition: CanvasProjection.cc:38
void inet::visualizer::PhysicalEnvironmentCanvasVisualizer::refreshDisplay ( ) const
overrideprotectedvirtual
47 {
48  // only update after initialize
49  if (physicalEnvironment != nullptr && getSimulation()->getEventNumber() == 0 && displayObjects) {
50  while (objectsLayer->getNumFigures())
51  delete objectsLayer->removeFigure(0);
52  // KLUDGE: sorting objects with their rotated position's z coordinate to draw them in a "better" order
53  std::vector<const IPhysicalObject *> objectsCopy;
54  for (int i = 0; i < physicalEnvironment->getNumObjects(); i++)
55  objectsCopy.push_back(physicalEnvironment->getObject(i));
56  std::stable_sort(objectsCopy.begin(), objectsCopy.end(), ObjectPositionComparator(canvasProjection->getRotation()));
57  for (auto object : objectsCopy) {
58  const ShapeBase *shape = object->getShape();
59  const Coord& position = object->getPosition();
60  const EulerAngles& orientation = object->getOrientation();
61  const Rotation rotation(orientation);
62  // cuboid
63  const Cuboid *cuboid = dynamic_cast<const Cuboid *>(shape);
64  if (cuboid) {
65  std::vector<std::vector<Coord> > faces;
66  cuboid->computeVisibleFaces(faces, rotation, canvasProjection->getRotation());
67  computeFacePoints(object, faces, rotation);
68  }
69  // sphere
70  const Sphere *sphere = dynamic_cast<const Sphere *>(shape);
71  if (sphere) {
72  double radius = sphere->getRadius();
73  cOvalFigure *figure = new cOvalFigure("sphere");
74  figure->setTooltip("This oval represents a physical object");
75  figure->setAssociatedObject(const_cast<cObject *>(check_and_cast<const cObject *>(object)));
76  figure->setFilled(true);
77  cFigure::Point center = canvasProjection->computeCanvasPoint(position);
78  figure->setBounds(cFigure::Rectangle(center.x - radius, center.y - radius, radius * 2, radius * 2));
79  figure->setLineWidth(object->getLineWidth());
80  figure->setLineColor(object->getLineColor());
81  figure->setFillColor(object->getFillColor());
82  figure->setLineOpacity(object->getOpacity());
83  figure->setFillOpacity(object->getOpacity());
84  figure->setZoomLineWidth(false);
85  std::string objectTags("physical_object ");
86  if (object->getTags())
87  objectTags += object->getTags();
88  figure->setTags((objectTags + " " + tags).c_str());
89  objectsLayer->addFigure(figure);
90  }
91  // prism
92  const Prism *prism = dynamic_cast<const Prism *>(shape);
93  if (prism) {
94  std::vector<std::vector<Coord> > faces;
95  prism->computeVisibleFaces(faces, rotation, canvasProjection->getRotation());
96  computeFacePoints(object, faces, rotation);
97  }
98  // polyhedron
99  const Polyhedron *polyhedron = dynamic_cast<const Polyhedron *>(shape);
100  if (polyhedron) {
101  std::vector<std::vector<Coord> > faces;
102  polyhedron->computeVisibleFaces(faces, rotation, canvasProjection->getRotation());
103  computeFacePoints(object, faces, rotation);
104  }
105  // add name to the end
106  const char *name = check_and_cast<const cObject *>(object)->getName();
107  if (name) {
108  cLabelFigure *nameFigure = new cLabelFigure("objectName");
109  nameFigure->setPosition(canvasProjection->computeCanvasPoint(position));
110  nameFigure->setTags((std::string("physical_object object_name label ") + tags).c_str());
111  nameFigure->setText(name);
112  objectsLayer->addFigure(nameFigure);
113  }
114  }
115  }
116 }
const char * tags
Definition: VisualizerBase.h:32
const Rotation & getRotation() const
Definition: CanvasProjection.h:39
const IPhysicalEnvironment * physicalEnvironment
Definition: PhysicalEnvironmentVisualizerBase.h:35
bool displayObjects
Definition: PhysicalEnvironmentVisualizerBase.h:36
const CanvasProjection * canvasProjection
Definition: PhysicalEnvironmentCanvasVisualizer.h:51
cGroupFigure * objectsLayer
Definition: PhysicalEnvironmentCanvasVisualizer.h:56
virtual const IPhysicalObject * getObject(int index) const =0
virtual void computeFacePoints(const IPhysicalObject *object, std::vector< std::vector< Coord > > &faces, const Rotation &rotation) const
Definition: PhysicalEnvironmentCanvasVisualizer.cc:118
cFigure::Point computeCanvasPoint(const Coord &point) const
Definition: CanvasProjection.cc:32

Member Data Documentation

const CanvasProjection* inet::visualizer::PhysicalEnvironmentCanvasVisualizer::canvasProjection
protected
cGroupFigure* inet::visualizer::PhysicalEnvironmentCanvasVisualizer::objectsLayer = nullptr
protected
double inet::visualizer::PhysicalEnvironmentCanvasVisualizer::zIndex = NaN
protected

Referenced by initialize().


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