Skip to content

Commit

Permalink
Add a separate track for mesh generation
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 27, 2024
1 parent b51e1bf commit 360a464
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
48 changes: 33 additions & 15 deletions avogadro/qtplugins/surfaces/orbitals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,21 @@ void Orbitals::calculateOrbitalFromWidget(unsigned int orbital,
double resolution)
{
m_updateMesh = true;
addCalculationToQueue(orbital, resolution, m_dialog->isovalue(), 0);

// check if the orbital is already in the queue
bool found = false;
for (int i = 0; i < m_queue.size(); i++) {
if (m_queue[i].orbital == orbital && m_queue[i].resolution == resolution) {
// change the priority to the highest
m_queue[i].priority = 0;
found = true;
break;
}
}

if (!found) {
addCalculationToQueue(orbital, resolution, m_dialog->isovalue(), 0);
}
checkQueue();
}

Expand Down Expand Up @@ -238,7 +252,7 @@ void Orbitals::checkQueue()
for (int i = 0; i < m_queue.size(); i++) {
state = m_queue.at(i).state;

// If there is already a running job, return.
// If there is already a running cube, return.
if (state == Running) {
return;
}
Expand Down Expand Up @@ -348,19 +362,18 @@ void Orbitals::calculateCubeDone()
watcher->disconnect(this);

if (m_updateMesh) {
m_currentMeshCalculation = m_currentRunningCalculation;
calculatePosMesh();
} else
calculationComplete();
}
calculationComplete();
}

void Orbitals::calculatePosMesh()
{
if (m_currentRunningCalculation == -1)
if (m_currentMeshCalculation == -1)
return;

calcInfo* info = &m_queue[m_currentRunningCalculation];

info->state = Running;
calcInfo* info = &m_queue[m_currentMeshCalculation];

auto posMesh = m_molecule->addMesh();
auto cube = info->cube;
Expand All @@ -381,12 +394,10 @@ void Orbitals::calculatePosMeshDone()

void Orbitals::calculateNegMesh()
{
if (m_currentRunningCalculation == -1)
if (m_currentMeshCalculation == -1)
return;

calcInfo* info = &m_queue[m_currentRunningCalculation];

info->state = Running;
calcInfo* info = &m_queue[m_currentMeshCalculation];

auto negMesh = m_molecule->addMesh();
auto cube = info->cube;
Expand All @@ -406,12 +417,20 @@ void Orbitals::calculateNegMeshDone()
{
disconnect(m_meshGenerator, 0, this, 0);

calculationComplete();
meshComplete();

// ask for a repaint
m_molecule->emitChanged(QtGui::Molecule::Added);
}

void Orbitals::meshComplete()
{
if (m_currentMeshCalculation == -1)
return;

m_currentMeshCalculation = -1;
}

void Orbitals::calculationComplete()
{
if (m_currentRunningCalculation == -1)
Expand Down Expand Up @@ -462,8 +481,7 @@ void Orbitals::renderOrbital(unsigned int row)
m_dialog->defaultQuality()));
} else {
// just need to update the meshes
m_currentRunningCalculation = index;
m_runningMutex->tryLock();
m_currentMeshCalculation = index;
calculatePosMesh(); // will eventually call negMesh too
}

Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/surfaces/orbitals.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private slots:
void calculateNegMesh();
void calculateNegMeshDone();
void calculationComplete();
void meshComplete();

/**
* Draw the indicated orbital on the GLWidget
Expand All @@ -147,6 +148,7 @@ private slots:

QList<calcInfo> m_queue;
int m_currentRunningCalculation = -1;
int m_currentMeshCalculation = -1;

QtGui::GaussianSetConcurrent* m_gaussianConcurrent = nullptr;
QtGui::SlaterSetConcurrent* m_slaterConcurrent = nullptr;
Expand Down

1 comment on commit 360a464

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.