Visualization
gradysim.simulator.handler.visualization
This handler adds visualization to the simulation. It shows regularly updated node positions in a graphical representation of the simulation. This graphical representation is web-based and can be accessed via a browser through this link. When the simulation starts running a WebSocket server is started which the browser connects to. The browser then displays the simulation in a 3D environment. The visualization is updated regularly with the current node positions and other information.
Danger
The visualization handler uses a separate process to run the WebSocket server, this means that on Windows your
script will be rerun when the new process starts. This means that any code that should not be run multiple times
should be put in the if __name__ == "__main__"
block.
VisualizationConfiguration
dataclass
Configuration for the VisualizationHandler
Source code in gradysim/simulator/handler/visualization.py
host: str = 'localhost'
class-attribute
instance-attribute
Host address of the visualization server
information_collection_interval: float = 0.01
class-attribute
instance-attribute
Interval in simulation seconds between visualization information update. Beware that this is not the frequency
at which the visualization is updated in the browser, but the frequency at which data is collected from the
running simulation. You can change the broser update frequency with the update_rate
parameter.
open_browser: bool = False
class-attribute
instance-attribute
Whether to open the browser automatically when the simulation starts
port: int = 5678
class-attribute
instance-attribute
Port that the visualization server will run in
update_rate: float = 0.05
class-attribute
instance-attribute
Rate in seconds at which the visualization is updated in the browser. This is the frequency at which the browser receives the information from the simulation.
x_range: Tuple[float, float] = (-50, 50)
class-attribute
instance-attribute
Range of the X axis of the visualization in meters
y_range: Tuple[float, float] = (-50, 50)
class-attribute
instance-attribute
Range of the Y axis of the visualization in meters
z_range: Tuple[float, float] = (0, 50)
class-attribute
instance-attribute
Range of the Z axis of the visualization in meters
VisualizationController
Controller for the visualization handler. Can be used to send commands to the visualization handler from a protocol. Commands can be used to affect the visualization, such as painting nodes or changing the environment's color.
Info
Every method in this class is a no-op if a visualization handler is not active. This includes when the protocol is not runnign on a python simulation environment.
Warning
The VisualizationController is attached to the last active visualization handler. This means that if you have
multiple visualization handlers active for some reason, the controller will only affect the last one. This also
means that this class should always be instantiated in the protocol's initialize
method, to avoid
initialization before the visualization handler is active.
Source code in gradysim/simulator/handler/visualization.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
paint_environment(color)
Paints the environment in the visualization with a specific color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color |
Tuple[float, float, float]
|
RGB color of the environment |
required |
Source code in gradysim/simulator/handler/visualization.py
paint_node(node_id, color)
Paints a node in the visualization with a specific color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id |
int
|
ID of the node to paint |
required |
color |
Tuple[float, float, float]
|
RGB color of the node |
required |
Source code in gradysim/simulator/handler/visualization.py
resize_nodes(size)
Resizes the nodes in the visualization Args: size: New size of the nodes
Source code in gradysim/simulator/handler/visualization.py
show_node_id(node_id, show)
Paints or unpaints the node_id text over the node. Args: node_id: ID of the node show: wheter to show the node_id or not
Source code in gradysim/simulator/handler/visualization.py
VisualizationHandler
Bases: INodeHandler
Adds visualization to the simulation. Shows regularly updated node position and other simulation information in a graphical representation of the simulation. The graphical representation is web-based and can be accessed via a browser through this link.
The visualization handler uses a separate process to run the WebSocket server, on Windows your
script will be rerun when the new process starts. This means that any code that should not be run multiple times
should be put in the if __name__ == "__main__"
block.
Source code in gradysim/simulator/handler/visualization.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
__init__(configuration=VisualizationConfiguration())
Constructs the visualization handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configuration |
VisualizationConfiguration
|
Configuration for the visualization handler. If not set all default values will be used. |
VisualizationConfiguration()
|