Skip to content

Commit

Permalink
Add std::chrono timing for mesh generation benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Nov 13, 2024
1 parent 98eb30e commit c228447
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions avogadro/qtgui/meshgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "meshgenerator.h"

#include <chrono>

#include <avogadro/core/cube.h>
#include <avogadro/core/mesh.h>
#include <avogadro/core/mutex.h>
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -92,6 +94,10 @@ void MeshGenerator::run()
emit progressValueChanged(i);
}

auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = end - start;
qDebug() << "Marching Cube Timing: " << elapsed.count() << " s";

m_cube->lock()->unlock();

// Copy the data across
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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

0 comments on commit c228447

Please sign in to comment.