|
pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
|
Manages the Qt3D window, scene setup, and the main simulation loop. More...
#include <display.hpp>


Public Types | |
| using | BodyInformations = std::tuple< QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform >, QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform >, QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform > > |
| A tuple to hold the Qt-specific components for a single rendered body. More... | |
Signals | |
| void | simulationFinished () |
| Emitted when the simulation has run for n_iter iterations. | |
Public Member Functions | |
| Display (const Configuration::SimulationConfig &config) | |
| Initialise the 3D window and set up the scene. More... | |
| ~Display () override | |
| Destructor to ensure worker thread is cleaned up. More... | |
| void | cleanup () |
| Performs cleanup actions, such as printing profiling reports. More... | |
| void | runSimulation () |
| Starts the physics simulation by starting the worker thread. More... | |
| void | shutdownPhysicsThread () |
| Stops the physics thread and destroys the worker. More... | |
Private Slots | |
| void | updateFrame (const Model::Vector3dVec &positions, const Model::QuaterniondVec &quaternions, const Model::Vector3dVec &torques, const Model::Vector3dVec &alphas, std::size_t iteration) |
| Slot to receive updated data from the physics worker and update the scene. More... | |
Private Member Functions | |
| void | createSpheres (Rng::Pcg32 &gen) |
| Create and set up the spherical bodies in the scene. More... | |
| void | createScene (unsigned int seed) |
| Set up the scene. More... | |
| std::pair< Qt3DCore::QEntity *, Qt3DCore::QTransform * > | createArrowEntity (Qt3DCore::QEntity *parent, const QColor &colour, float radius, float length) |
| Creates a 3D arrow entity for vector visualization. More... | |
| void | updateVectorArrow (Qt3DCore::QTransform *arrowTransform, const Model::Vector3d &vector, double scaleFactor) const |
| Updates the transform of an arrow entity to represent a 3D vector. More... | |
Private Attributes | |
| std::size_t | iterationCount_ |
| The current iteration count. More... | |
| std::size_t | maxIterations_ |
| Maximum number of iterations. More... | |
| bool | showTorqueArrow_ |
| Flag to display torque vectors in the UI. More... | |
| bool | showAlphaArrow_ |
| Flag to display angular acceleration vectors in the UI. More... | |
| QPointer< Qt3DCore::QEntity > | rootEntity_ |
| The root entity for the 3D scene. More... | |
| QPointer< Qt3DExtras::QOrbitCameraController > | camController_ |
| Mouse camera controller. More... | |
| std::vector< BodyInformations > | bodies_ |
| List of spheres representing bodies. This list differs from the actual physical bodies in the simulation. More... | |
| QPointer< Model::PhysicsWorker > | physicsWorker_ |
| The worker object running the simulation. Uses QPointer for safety: it becomes nullptr if the object is destroyed. More... | |
| QThread * | physicsThread_ |
| The thread where the physics worker runs. Created with 'this' as parent, so Qt manages its lifetime. More... | |
| QTimer * | simulationTimer_ |
| Timer to drive the simulation loop. Reused timer that triggers physics steps automatically. More... | |
| bool | cleanupCalled_ |
| Flag to track if cleanup has already been called. This prevents cleanup from being called multiple times. More... | |
| bool | physicsShutdown_ |
| True after shutdownPhysicsThread() has run. More... | |
Manages the Qt3D window, scene setup, and the main simulation loop.
This class orchestrates the 3D rendering and the physics worker thread.
Definition at line 52 of file display.hpp.
| using Window::Display::BodyInformations = std::tuple< QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform>, QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform>, QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform> > |
A tuple to hold the Qt-specific components for a single rendered body.
Definition at line 60 of file display.hpp.
|
inlineexplicit |
Initialise the 3D window and set up the scene.
| config | The simulation configuration object. |
Definition at line 69 of file display.hpp.

|
override |
Destructor to ensure worker thread is cleaned up.
Definition at line 43 of file display.cpp.

| void Window::Display::cleanup | ( | ) |
Performs cleanup actions, such as printing profiling reports.
Definition at line 221 of file display.cpp.

|
private |
Creates a 3D arrow entity for vector visualization.
| parent | The parent entity. |
| colour | The colour of the arrow. |
| radius | The radius of the arrow's shaft. |
| length | The initial length of the arrow. |
Definition at line 48 of file display.cpp.
|
private |
Set up the scene.
| seed | The seed for the random number generator. |
Definition at line 150 of file display.cpp.

|
private |
Create and set up the spherical bodies in the scene.
| gen | A seeded random number generator for reproducible body colours. |
Definition at line 94 of file display.cpp.
| void Window::Display::runSimulation | ( | ) |
Starts the physics simulation by starting the worker thread.
Definition at line 160 of file display.cpp.
| void Window::Display::shutdownPhysicsThread | ( | ) |
Stops the physics thread and destroys the worker.
Safe to call multiple times. Used by cleanup() and the destructor.
Definition at line 170 of file display.cpp.


|
privateslot |
Slot to receive updated data from the physics worker and update the scene.
Definition at line 271 of file display.cpp.


|
private |
Updates the transform of an arrow entity to represent a 3D vector.
| arrowTransform | The transform component of the arrow to update. |
| vector | The 3D vector to visualise. |
| scaleFactor | A multiplier for the arrow's length. |
Definition at line 240 of file display.cpp.
|
private |
List of spheres representing bodies. This list differs from the actual physical bodies in the simulation.
Definition at line 179 of file display.hpp.
|
private |
Mouse camera controller.
Definition at line 173 of file display.hpp.
|
private |
Flag to track if cleanup has already been called. This prevents cleanup from being called multiple times.
Definition at line 196 of file display.hpp.
|
private |
The current iteration count.
Definition at line 158 of file display.hpp.
|
private |
Maximum number of iterations.
Definition at line 161 of file display.hpp.
|
private |
True after shutdownPhysicsThread() has run.
Definition at line 199 of file display.hpp.
|
private |
The thread where the physics worker runs. Created with 'this' as parent, so Qt manages its lifetime.
Definition at line 188 of file display.hpp.
|
private |
The worker object running the simulation. Uses QPointer for safety: it becomes nullptr if the object is destroyed.
Definition at line 184 of file display.hpp.
|
private |
The root entity for the 3D scene.
Definition at line 170 of file display.hpp.
|
private |
Flag to display angular acceleration vectors in the UI.
Definition at line 167 of file display.hpp.
|
private |
Flag to display torque vectors in the UI.
Definition at line 164 of file display.hpp.
|
private |
Timer to drive the simulation loop. Reused timer that triggers physics steps automatically.
Definition at line 192 of file display.hpp.