pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
Window::Display Class Reference

Manages the Qt3D window, scene setup, and the main simulation loop. More...

#include <display.hpp>

Inheritance diagram for Window::Display:
Inheritance graph
Collaboration diagram for Window::Display:
Collaboration graph

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...
 

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...
 
std::unique_ptr< Qt3DCore::QEntity > rootEntity_
 The root entity for the 3D scene. More...
 
QPointer< Qt3DExtras::QOrbitCameraController > camController_
 Mouse camera controller. More...
 
std::vector< BodyInformationsbodies_
 List of spheres representing bodies. This list differs from the actual physical bodies in the simulation. More...
 
QPointer< Model::PhysicsWorkerphysicsWorker_
 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...
 

Detailed Description

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.

Member Typedef Documentation

◆ BodyInformations

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.

Constructor & Destructor Documentation

◆ Display()

Window::Display::Display ( const Configuration::SimulationConfig &  config)
inlineexplicit

Initialise the 3D window and set up the scene.

Parameters
configThe simulation configuration object.

Definition at line 69 of file display.hpp.

Here is the call graph for this function:

◆ ~Display()

Window::Display::~Display ( )
override

Destructor to ensure worker thread is cleaned up.

Definition at line 43 of file display.cpp.

Member Function Documentation

◆ cleanup()

void Window::Display::cleanup ( )

Performs cleanup actions, such as printing profiling reports.

Definition at line 185 of file display.cpp.

Here is the call graph for this function:

◆ createArrowEntity()

std::pair< Qt3DCore::QEntity *, Qt3DCore::QTransform * > Window::Display::createArrowEntity ( Qt3DCore::QEntity *  parent,
const QColor &  colour,
float  radius,
float  length 
)
private

Creates a 3D arrow entity for vector visualization.

Parameters
parentThe parent entity.
colourThe colour of the arrow.
radiusThe radius of the arrow's shaft.
lengthThe initial length of the arrow.
Returns
A tuple containing the arrow's root entity and its transform component.

Definition at line 60 of file display.cpp.

◆ createScene()

void Window::Display::createScene ( unsigned int  seed)
private

Set up the scene.

Parameters
seedThe seed for the random number generator.

Definition at line 162 of file display.cpp.

Here is the caller graph for this function:

◆ createSpheres()

void Window::Display::createSpheres ( Rng::Pcg32 gen)
private

Create and set up the spherical bodies in the scene.

Parameters
genA seeded random number generator for reproducible body colours.

Definition at line 106 of file display.cpp.

◆ runSimulation()

void Window::Display::runSimulation ( )

Starts the physics simulation by starting the worker thread.

Definition at line 172 of file display.cpp.

◆ updateFrame

void Window::Display::updateFrame ( const Model::Vector3dVec &  positions,
const Model::QuaterniondVec &  quaternions,
const Model::Vector3dVec &  torques,
const Model::Vector3dVec &  alphas,
std::size_t  iteration 
)
privateslot

Slot to receive updated data from the physics worker and update the scene.

Definition at line 298 of file display.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateVectorArrow()

void Window::Display::updateVectorArrow ( Qt3DCore::QTransform *  arrowTransform,
const Model::Vector3d &  vector,
double  scaleFactor 
) const
private

Updates the transform of an arrow entity to represent a 3D vector.

Parameters
arrowTransformThe transform component of the arrow to update.
vectorThe 3D vector to visualise.
scaleFactorA multiplier for the arrow's length.

Definition at line 267 of file display.cpp.

Member Data Documentation

◆ bodies_

std::vector<BodyInformations> Window::Display::bodies_
private

List of spheres representing bodies. This list differs from the actual physical bodies in the simulation.

Definition at line 171 of file display.hpp.

◆ camController_

QPointer<Qt3DExtras::QOrbitCameraController> Window::Display::camController_
private

Mouse camera controller.

Definition at line 165 of file display.hpp.

◆ cleanupCalled_

bool Window::Display::cleanupCalled_
private

Flag to track if cleanup has already been called. This prevents cleanup from being called multiple times.

Definition at line 188 of file display.hpp.

◆ iterationCount_

std::size_t Window::Display::iterationCount_
private

The current iteration count.

Definition at line 150 of file display.hpp.

◆ maxIterations_

std::size_t Window::Display::maxIterations_
private

Maximum number of iterations.

Definition at line 153 of file display.hpp.

◆ physicsThread_

QThread* Window::Display::physicsThread_
private

The thread where the physics worker runs. Created with 'this' as parent, so Qt manages its lifetime.

Definition at line 180 of file display.hpp.

◆ physicsWorker_

QPointer<Model::PhysicsWorker> Window::Display::physicsWorker_
private

The worker object running the simulation. Uses QPointer for safety: it becomes nullptr if the object is destroyed.

Definition at line 176 of file display.hpp.

◆ rootEntity_

std::unique_ptr<Qt3DCore::QEntity> Window::Display::rootEntity_
private

The root entity for the 3D scene.

Definition at line 162 of file display.hpp.

◆ showAlphaArrow_

bool Window::Display::showAlphaArrow_
private

Flag to display angular acceleration vectors in the UI.

Definition at line 159 of file display.hpp.

◆ showTorqueArrow_

bool Window::Display::showTorqueArrow_
private

Flag to display torque vectors in the UI.

Definition at line 156 of file display.hpp.

◆ simulationTimer_

QTimer* Window::Display::simulationTimer_
private

Timer to drive the simulation loop. Reused timer that triggers physics steps automatically.

Definition at line 184 of file display.hpp.


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