void LifeMainWindow::calculate() { int w = m_boardSize.width(); int h = m_boardSize.height(); while (m_running) { qApp->processEvents(); /* Let the GUI process events also! */ m_numGenerations++; QImage next = m_current; for (int x=0; x < w; ++x) { /* The rules of the game of life */ for (int y=0; y < h; ++y) { bool isAlive = (m_current.pixelIndex(x, y) == ALIVE); int nc = neighborCount(m_current, x, y); if (!isAlive && nc == 3) next.setPixel(x, y, ALIVE); if (!isAlive) continue; if ((nc < 2) || (nc > 3)) next.setPixel(x, y, DEAD); } } m_current = next; m_lifeWidget->setImage(m_current); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void BadDataNeighborOrientationCheck::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_GoodVoxelsArrayPath.getDataContainerName()); size_t totalPoints = m_GoodVoxelsPtr.lock()->getNumberOfTuples(); m_MisorientationTolerance = m_MisorientationTolerance * SIMPLib::Constants::k_Pi / 180.0; size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType dims[3] = { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), }; int32_t good = 1; DimType neighbor = 0; DimType column = 0, row = 0, plane = 0; DimType neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; neighpoints[0] = static_cast<DimType>(-dims[0] * dims[1]); neighpoints[1] = static_cast<DimType>(-dims[0]); neighpoints[2] = static_cast<DimType>(-1); neighpoints[3] = static_cast<DimType>(1); neighpoints[4] = static_cast<DimType>(dims[0]); neighpoints[5] = static_cast<DimType>(dims[0] * dims[1]); float w = 10000.0f; QuatF q1 = QuaternionMathF::New(); QuatF q2 = QuaternionMathF::New(); QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float n1 = 0.0f, n2 = 0.0f, n3 = 0.0f; uint32_t phase1 = 0, phase2 = 0; QVector<int32_t> neighborCount(totalPoints, 0); for (size_t i = 0; i < totalPoints; i++) { if (m_GoodVoxels[i] == false) { column = i % dims[0]; row = (i / dims[0]) % dims[1]; plane = i / (dims[0] * dims[1]); for (int32_t j = 0; j < 6; j++) { good = 1; neighbor = i + neighpoints[j]; if (j == 0 && plane == 0) { good = 0; } if (j == 5 && plane == (dims[2] - 1)) { good = 0; } if (j == 1 && row == 0) { good = 0; } if (j == 4 && row == (dims[1] - 1)) { good = 0; } if (j == 2 && column == 0) { good = 0; } if (j == 3 && column == (dims[0] - 1)) { good = 0; } if (good == 1 && m_GoodVoxels[neighbor] == true) { phase1 = m_CrystalStructures[m_CellPhases[i]]; QuaternionMathF::Copy(quats[i], q1); phase2 = m_CrystalStructures[m_CellPhases[neighbor]]; QuaternionMathF::Copy(quats[neighbor], q2); if (m_CellPhases[i] == m_CellPhases[neighbor] && m_CellPhases[i] > 0) { w = m_OrientationOps[phase1]->getMisoQuat( q1, q2, n1, n2, n3); } if (w < m_MisorientationTolerance) { neighborCount[i]++; } } } } } int32_t currentLevel = 6; int32_t counter = 0; while (currentLevel > m_NumberOfNeighbors) { counter = 1; while (counter > 0) { counter = 0; for (size_t i = 0; i < totalPoints; i++) { if (neighborCount[i] >= currentLevel && m_GoodVoxels[i] == false) { m_GoodVoxels[i] = true; counter++; column = i % dims[0]; row = (i / dims[0]) % dims[1]; plane = i / (dims[0] * dims[1]); for (DimType j = 0; j < 6; j++) { good = 1; neighbor = i + neighpoints[j]; if (j == 0 && plane == 0) { good = 0; } if (j == 5 && plane == (dims[2] - 1)) { good = 0; } if (j == 1 && row == 0) { good = 0; } if (j == 4 && row == (dims[1] - 1)) { good = 0; } if (j == 2 && column == 0) { good = 0; } if (j == 3 && column == (dims[0] - 1)) { good = 0; } if (good == 1 && m_GoodVoxels[neighbor] == false) { phase1 = m_CrystalStructures[m_CellPhases[i]]; QuaternionMathF::Copy(quats[i], q1); phase2 = m_CrystalStructures[m_CellPhases[neighbor]]; QuaternionMathF::Copy(quats[neighbor], q2); if (m_CellPhases[i] == m_CellPhases[neighbor] && m_CellPhases[i] > 0) { w = m_OrientationOps[phase1]->getMisoQuat( q1, q2, n1, n2, n3); } if (w < m_MisorientationTolerance) { neighborCount[neighbor]++; } } } } } } currentLevel = currentLevel - 1; } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }