From c2284476c6e9b3574d6fa3efa2ee423ca4fa9e55 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 12 Nov 2024 20:14:37 -0500 Subject: [PATCH] Add std::chrono timing for mesh generation benchmark Signed-off-by: Geoff Hutchison --- avogadro/qtgui/meshgenerator.cpp | 47 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/avogadro/qtgui/meshgenerator.cpp b/avogadro/qtgui/meshgenerator.cpp index 45219537cf..a5ec758748 100644 --- a/avogadro/qtgui/meshgenerator.cpp +++ b/avogadro/qtgui/meshgenerator.cpp @@ -5,6 +5,8 @@ #include "meshgenerator.h" +#include + #include #include #include @@ -18,24 +20,22 @@ using Core::Cube; using Core::Mesh; MeshGenerator::MeshGenerator(QObject* p) - : QThread(p), m_iso(0.0), m_passes(6), m_reverseWinding(false), m_cube(nullptr), - m_mesh(nullptr), m_stepSize(0.0, 0.0, 0.0), m_min(0.0, 0.0, 0.0), - m_dim(0, 0, 0), m_progmin(0), m_progmax(0) + : QThread(p), m_iso(0.0), m_passes(6), m_reverseWinding(false), + m_cube(nullptr), m_mesh(nullptr), m_stepSize(0.0, 0.0, 0.0), + m_min(0.0, 0.0, 0.0), m_dim(0, 0, 0), m_progmin(0), m_progmax(0) { } MeshGenerator::MeshGenerator(const Cube* cube_, Mesh* mesh_, float iso, int passes, bool reverse, QObject* p) - : QThread(p), m_iso(0.0), m_passes(6), m_reverseWinding(reverse), m_cube(nullptr), - m_mesh(nullptr), m_stepSize(0.0, 0.0, 0.0), m_min(0.0, 0.0, 0.0), - m_dim(0, 0, 0), m_progmin(0), m_progmax(0) + : QThread(p), m_iso(0.0), m_passes(6), m_reverseWinding(reverse), + m_cube(nullptr), m_mesh(nullptr), m_stepSize(0.0, 0.0, 0.0), + m_min(0.0, 0.0, 0.0), m_dim(0, 0, 0), m_progmin(0), m_progmax(0) { initialize(cube_, mesh_, iso, passes); } -MeshGenerator::~MeshGenerator() -{ -} +MeshGenerator::~MeshGenerator() {} bool MeshGenerator::initialize(const Cube* cube_, Mesh* mesh_, float iso, int passes, bool reverse) @@ -78,6 +78,8 @@ void MeshGenerator::run() m_vertices.reserve(m_dim.x() * m_dim.y() * m_dim.z() * 3); m_normals.reserve(m_dim.x() * m_dim.y() * m_dim.z() * 3); + auto start = std::chrono::high_resolution_clock::now(); + // Now to march the cube for (int i = 0; i < m_dim.x() - 1; ++i) { for (int j = 0; j < m_dim.y() - 1; ++j) { @@ -92,6 +94,10 @@ void MeshGenerator::run() emit progressValueChanged(i); } + auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = end - start; + qDebug() << "Marching Cube Timing: " << elapsed.count() << " s"; + m_cube->lock()->unlock(); // Copy the data across @@ -187,18 +193,15 @@ bool MeshGenerator::marchingCube(const Vector3i& pos) afCubeValue[a2iEdgeConnection[i][1]]); asEdgeVertex[i] = - Vector3f(fPos.x() + - (a2fVertexOffset[a2iEdgeConnection[i][0]][0] + - fOffset * a2fEdgeDirection[i][0]) * - m_stepSize[0], - fPos.y() + - (a2fVertexOffset[a2iEdgeConnection[i][0]][1] + - fOffset * a2fEdgeDirection[i][1]) * - m_stepSize[1], - fPos.z() + - (a2fVertexOffset[a2iEdgeConnection[i][0]][2] + - fOffset * a2fEdgeDirection[i][2]) * - m_stepSize[2]); + Vector3f(fPos.x() + (a2fVertexOffset[a2iEdgeConnection[i][0]][0] + + fOffset * a2fEdgeDirection[i][0]) * + m_stepSize[0], + fPos.y() + (a2fVertexOffset[a2iEdgeConnection[i][0]][1] + + fOffset * a2fEdgeDirection[i][1]) * + m_stepSize[1], + fPos.z() + (a2fVertexOffset[a2iEdgeConnection[i][0]][2] + + fOffset * a2fEdgeDirection[i][2]) * + m_stepSize[2]); /// FIXME Optimize this to only calculate normals when required asEdgeNorm[i] = normal(asEdgeVertex[i]); @@ -610,4 +613,4 @@ const int MeshGenerator::a2iTriangleConnectionTable[256][16] = { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }; -} // End namespace Avogadro +} // namespace Avogadro::QtGui