// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t MergeColonies::getSeed(int32_t newFid) { setErrorCondition(0); int32_t numfeatures = static_cast<int32_t>(m_FeaturePhasesPtr.lock()->getNumberOfTuples()); SIMPL_RANDOMNG_NEW() int32_t seed = -1; int32_t randfeature = 0; // Precalculate some constants int32_t totalFMinus1 = numfeatures - 1; size_t counter = 0; randfeature = int32_t(float(rg.genrand_res53()) * float(totalFMinus1)); while (seed == -1 && counter < numfeatures) { if (randfeature > totalFMinus1) { randfeature = randfeature - numfeatures; } if (m_FeatureParentIds[randfeature] == -1) { seed = randfeature; } randfeature++; counter++; } if (seed >= 0) { m_FeatureParentIds[seed] = newFid; QVector<size_t> tDims(1, newFid + 1); getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName())->getAttributeMatrix(getNewCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); } return seed; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFeatureMapToElementArray::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); size_t totalPoints = m_SelectedCellDataPtr.lock()->getNumberOfTuples(); int32_t maxIndex = 0; std::vector<bool> active; for (size_t i = 0; i < totalPoints; i++) { int32_t index = m_SelectedCellData[i]; if ((index + 1) > maxIndex) { active.resize(index + 1); active[index] = true; maxIndex = index + 1; } } QVector<size_t> tDims(1, maxIndex); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); for (int32_t i = 0; i < maxIndex; i++) { m_Active[i] = active[i]; } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int64_t EBSDSegmentFeatures::getSeed(int32_t gnum) { setErrorCondition(0); DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); int64_t seed = -1; Generator& numberGenerator = *m_NumberGenerator; while (seed == -1 && m_TotalRandomNumbersGenerated < totalPoints) { // Get the next voxel index in the precomputed list of voxel seeds int64_t randpoint = numberGenerator(); m_TotalRandomNumbersGenerated++; // Increment this counter if (m_FeatureIds[randpoint] == 0) // If the GrainId of the voxel is ZERO then we can use this as a seed point { if ((m_UseGoodVoxels == false || m_GoodVoxels[randpoint] == true) && m_CellPhases[randpoint] > 0) { seed = randpoint; } } } if (seed >= 0) { m_FeatureIds[seed] = gnum; QVector<size_t> tDims(1, gnum + 1); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); } return seed; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int64_t EBSDSegmentFeatures::getSeed(int32_t gnum, int64_t nextSeed) { setErrorCondition(0); DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); int64_t seed = -1; // start with the next voxel after the last seed size_t randpoint = static_cast<size_t>(nextSeed); while (seed == -1 && randpoint < totalPoints) { if (m_FeatureIds[randpoint] == 0) // If the GrainId of the voxel is ZERO then we can use this as a seed point { if ((m_UseGoodVoxels == false || m_GoodVoxels[randpoint] == true) && m_CellPhases[randpoint] > 0) { seed = randpoint; } else { randpoint += 1; } } else { randpoint += 1; } } if (seed >= 0) { m_FeatureIds[seed] = gnum; QVector<size_t> tDims(1, gnum + 1); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); } return seed; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t GroupMicroTextureRegions::getSeed(int32_t newFid) { setErrorCondition(0); int32_t numfeatures = static_cast<int32_t>(m_FeaturePhasesPtr.lock()->getNumberOfTuples()); float c1[3] = { 0.0f, 0.0f, 0.0f }; uint32_t phase1 = 0; QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); float caxis[3] = { 0.0f, 0.0f, 1.0f }; QuatF q1 = QuaternionMathF::New(); float g1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float g1t[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; SIMPL_RANDOMNG_NEW() int32_t seed = -1; int32_t randfeature = 0; // Precalculate some constants int32_t totalFMinus1 = numfeatures - 1; size_t counter = 0; randfeature = int32_t(float(rg.genrand_res53()) * float(totalFMinus1)); while (seed == -1 && counter < numfeatures) { if (randfeature > totalFMinus1) { randfeature = randfeature - numfeatures; } if (m_FeatureParentIds[randfeature] == -1) { seed = randfeature; } randfeature++; counter++; } if (seed >= 0) { m_FeatureParentIds[seed] = newFid; QVector<size_t> tDims(1, newFid + 1); getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName())->getAttributeMatrix(getNewCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); if (m_UseRunningAverage == true) { QuaternionMathF::Copy(avgQuats[seed], q1); phase1 = m_CrystalStructures[m_FeaturePhases[seed]]; FOrientArrayType om(9); FOrientTransformsType::qu2om(FOrientArrayType(q1), om); om.toGMatrix(g1); // transpose the g matrix so when caxis is multiplied by it // it will give the sample direction that the caxis is along MatrixMath::Transpose3x3(g1, g1t); MatrixMath::Multiply3x3with3x1(g1t, caxis, c1); // normalize so that the dot product can be taken below without // dividing by the magnitudes (they would be 1) MatrixMath::Normalize3x1(c1); MatrixMath::Copy3x1(c1, avgCaxes); MatrixMath::Multiply3x1withConstant(avgCaxes, m_Volumes[seed]); } } return seed; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VectorSegmentFeatures::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); QVector<size_t> tDims(1, 1); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); int64_t totalPoints = static_cast<int64_t>(m_FeatureIdsPtr.lock()->getNumberOfTuples()); m_BeenPickedPtr = BoolArrayType::CreateArray(totalPoints, "BeenPicked INTERNAL ARRAY ONLY"); m_BeenPickedPtr->initializeWithValue(0); m_BeenPicked = m_BeenPickedPtr->getPointer(0); // Convert user defined tolerance to radians. angleTolerance = m_AngleTolerance * SIMPLib::Constants::k_Pi / 180.0f; // Generate the random voxel indices that will be used for the seed points to start a new grain growth/agglomeration const int64_t rangeMin = 0; const int64_t rangeMax = totalPoints - 1; initializeVoxelSeedGenerator(rangeMin, rangeMax); SegmentFeatures::execute(); int32_t totalFeatures = static_cast<int32_t>(m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->getNumTuples()); if (totalFeatures < 2) { setErrorCondition(-87000); notifyErrorMessage(getHumanLabel(), "The number of Features was 0 or 1 which means no Features were detected. A threshold value may be set too high", getErrorCondition()); return; } // By default we randomize grains if (true == m_RandomizeFeatureIds) { randomizeFeatureIds(totalPoints, totalFeatures); } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Completed"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void EBSDSegmentFeatures::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); int64_t totalPoints = static_cast<int64_t>(m_FeatureIdsPtr.lock()->getNumberOfTuples()); QVector<size_t> tDims(1, 1); m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); // Convert user defined tolerance to radians. misoTolerance = m_MisorientationTolerance * DREAM3D::Constants::k_Pi / 180.0f; // Generate the random voxel indices that will be used for the seed points to start a new grain growth/agglomeration const int64_t rangeMin = 0; const int64_t rangeMax = totalPoints - 1; initializeVoxelSeedGenerator(rangeMin, rangeMax); SegmentFeatures::execute(); int64_t totalFeatures = static_cast<int64_t>(m_ActivePtr.lock()->getNumberOfTuples()); if (totalFeatures < 2) { setErrorCondition(-87000); notifyErrorMessage(getHumanLabel(), "The number of Features was 0 or 1 which means no Features were detected. A threshold value may be set too high", getErrorCondition()); return; } // By default we randomize grains if (true == getRandomizeFeatureIds()) { totalPoints = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getNumberOfElements()); randomizeFeatureIds(totalPoints, totalFeatures); } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
void YSChoiAbaqusReader::execute() { dataCheck(); DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); int xpoints, ypoints, zpoints, totalpoints = 0; float resx, resy, resz; float** *mat = NULL; //const unsigned int size(1024); // Read header from data file to figure out how many points there are QFile in(getInputFile()); if (!in.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QObject::tr("Abaqus file could not be opened: %1").arg(getInputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "", getErrorCondition()); return; } QString word; bool ok = false; bool headerdone = false; while (headerdone == false) { QByteArray buf = in.readLine(); if (buf.startsWith(DIMS)) { QList<QByteArray> tokens = buf.split(' '); xpoints = tokens[1].toInt(&ok, 10); ypoints = tokens[2].toInt(&ok, 10); zpoints = tokens[3].toInt(&ok, 10); totalpoints = xpoints * ypoints * zpoints; size_t dims[3] = { static_cast<size_t>(xpoints), static_cast<size_t>(ypoints), static_cast<size_t>(zpoints) }; m->getGeometryAs<ImageGeom>()->setDimensions(dims); m->getGeometryAs<ImageGeom>()->setOrigin(0, 0, 0); } if (buf.startsWith(RES)) { QList<QByteArray> tokens = buf.split(' '); resx = tokens[1].toInt(&ok, 10); resy = tokens[2].toInt(&ok, 10); resz = tokens[3].toInt(&ok, 10); float res[3] = {resx, resy, resz}; m->getGeometryAs<ImageGeom>()->setResolution(res); } if (buf.startsWith(LOOKUP)) { headerdone = true; word = QString(buf); } } // Read header from grain info file to figure out how many features there are QFile in2(getInputFeatureInfoFile()); if (!in2.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QObject::tr("Abaqus Feature Info file could not be opened: %1").arg(getInputFeatureInfoFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "", getErrorCondition()); return; } int numfeatures; QByteArray buf = in2.readLine(); numfeatures = buf.toInt(&ok, 10); buf = in2.readLine(); QList<QByteArray> tokens = buf.split(' '); // in2 >> word >> word >> word >> word >> word >> word; QVector<size_t> tDims(3, 0); tDims[0] = xpoints; tDims[1] = ypoints; tDims[2] = zpoints; m->getAttributeMatrix(getCellAttributeMatrixName())->resizeAttributeArrays(tDims); tDims.resize(1); tDims[0] = numfeatures + 1; m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); tDims[0] = 2; m->getAttributeMatrix(getCellEnsembleAttributeMatrixName())->resizeAttributeArrays(tDims); updateCellInstancePointers(); updateFeatureInstancePointers(); updateEnsembleInstancePointers(); //Read data file int gnum = 0; bool onedge = false; int col, row, plane; float value; for (int i = 0; i < totalpoints; i++) { mat[i] = new float *[3]; for(int j = 0; j < 3; j++) { mat[i][j] = new float [3]; } onedge = false; gnum = tokens[6].toInt(&ok, 10); col = i % xpoints; row = (i / xpoints) % ypoints; plane = i / (xpoints * ypoints); if (col == 0 || col == (xpoints - 1) || row == 0 || row == (ypoints - 1) || plane == 0 || plane == (zpoints - 1)) { onedge = true; } m_FeatureIds[i] = gnum; m_SurfaceFeatures[gnum] = onedge; } for (int iter1 = 0; iter1 < 3; iter1++) { for (int iter2 = 0; iter2 < 3; iter2++) { headerdone = false; while (headerdone == false) { buf = in2.readLine(); if (buf.startsWith(LOOKUP)) { headerdone = true; //in >> word; } } for (int i = 0; i < totalpoints; i++) { onedge = 0; value = buf.toInt(&ok, 10); mat[i][iter1][iter2] = value; } } } //Read feature info QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); avgQuats[0].x = 0.0; avgQuats[0].y = 0.0; avgQuats[0].z = 0.0; avgQuats[0].w = 0.0; for (int i = 1; i < numfeatures + 1; i++) { buf = in2.readLine(); tokens = buf.split(' '); gnum = tokens[0].toInt(&ok, 10); avgQuats[i].x = tokens[2].toFloat(&ok); avgQuats[i].y = tokens[3].toFloat(&ok); avgQuats[i].z = tokens[4].toFloat(&ok); avgQuats[i].w = tokens[5].toFloat(&ok); } QuatF q; QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float g[3][3]; for(int i = 0; i < (xpoints * ypoints * zpoints); i++) { for(int j = 0; j < 3; j++) { for(int k = 0; k < 3; k++) { g[j][k] = mat[i][j][k]; } } MatrixMath::Normalize3x3(g); q.w = static_cast<float>( sqrt((1.0 + g[0][0] + g[1][1] + g[2][2])) / 2.0 ); q.x = static_cast<float>( (g[1][2] - g[2][1]) / (4.0 * q.w) ); q.y = static_cast<float>( (g[2][0] - g[0][2]) / (4.0 * q.w) ); q.z = static_cast<float>( (g[0][1] - g[1][0]) / (4.0 * q.w) ); QuaternionMathF::Copy(q, quats[i]); FOrientArrayType eu(m_CellEulerAngles + (3 * i), 3); FOrientTransformsType::qu2eu(FOrientArrayType(q), eu); delete[] mat[i]; } delete[] mat; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void EstablishMatrixPhase::establish_matrix() { notifyStatusMessage(getHumanLabel(), "Establishing Matrix"); SIMPL_RANDOMNG_NEW() DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getOutputCellAttributeMatrixPath().getDataContainerName()); StatsDataArray& statsDataArray = *(m_StatsDataArray.lock()); 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]), }; sizex = dims[0] * m->getGeometryAs<ImageGeom>()->getXRes(); sizey = dims[1] * m->getGeometryAs<ImageGeom>()->getYRes(); sizez = dims[2] * m->getGeometryAs<ImageGeom>()->getZRes(); totalvol = sizex * sizey * sizez; size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); size_t currentnumfeatures = m_FeaturePhasesPtr.lock()->getNumberOfTuples(); size_t numensembles = m_PhaseTypesPtr.lock()->getNumberOfTuples(); QVector<size_t> tDims(1, 1); if (currentnumfeatures == 0) { m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); currentnumfeatures = 1; } firstMatrixFeature = currentnumfeatures; float random = 0.0f; float totalmatrixfractions = 0.0f; for (size_t i = 1; i < numensembles; ++i) { if (m_PhaseTypes[i] == DREAM3D::PhaseType::MatrixPhase) { MatrixStatsData* mp = MatrixStatsData::SafePointerDownCast(statsDataArray[i].get()); if (NULL == mp) { QString ss = QObject::tr("Tried to cast a statsDataArray[%1].get() to a MatrixStatsData* " "pointer but this resulted in a NULL pointer. The value at m_PhaseTypes[%2] = %3 does not match up " "with the type of pointer stored in the StatsDataArray (MatrixStatsData)\n") .arg(i).arg(i).arg(m_PhaseTypes[i]); notifyErrorMessage(getHumanLabel(), ss, -666); setErrorCondition(-666); return; } matrixphases.push_back(i); matrixphasefractions.push_back(mp->getPhaseFraction()); totalmatrixfractions = totalmatrixfractions + mp->getPhaseFraction(); } } for (int32_t i = 0; i < matrixphases.size(); i++) { matrixphasefractions[i] = matrixphasefractions[i] / totalmatrixfractions; if (i > 0) { matrixphasefractions[i] = matrixphasefractions[i] + matrixphasefractions[i - 1]; } } size_t j = 0; for (size_t i = 0; i < totalPoints; ++i) { if ((m_UseMask == false && m_FeatureIds[i] <= 0) || (m_UseMask == true && m_Mask[i] == true && m_FeatureIds[i] <= 0)) { random = static_cast<float>( rg.genrand_res53() ); j = 0; while (random > matrixphasefractions[j]) { j++; } if (m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->getNumTuples() <= (firstMatrixFeature + j)) { tDims[0] = (firstMatrixFeature + j) + 1; m->getAttributeMatrix(m_OutputCellFeatureAttributeMatrixName)->resizeAttributeArrays(tDims); updateFeatureInstancePointers(); m_NumFeatures[j] = 1; } m_FeatureIds[i] = (firstMatrixFeature + j); m_CellPhases[i] = matrixphases[j]; m_FeaturePhases[(firstMatrixFeature + j)] = matrixphases[j]; } else if (m_UseMask == true && m_Mask[i] == false) { m_FeatureIds[i] = 0; m_CellPhases[i] = 0; } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t FeatureInfoReader::readFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixName()); std::ifstream inFile; inFile.open(getInputFile().toLatin1().data(), std::ios_base::binary); if (!inFile) { QString ss = QObject::tr("Error opening input file: %1").arg(getInputFile()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } int32_t numfeatures = 0; int32_t gnum = 0, phase = 0; int32_t maxphase = 0; float ea1 = 0.0f, ea2 = 0.0f, ea3 = 0.0f; inFile >> numfeatures; if (0 == numfeatures) { QString ss = QObject::tr("The number of Features (%1) specified in the file must be greater than zero").arg(numfeatures); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); int32_t maxFeatureId = 0; for (size_t i = 0; i < totalPoints; i++) { if (m_FeatureIds[i] > maxFeatureId) { maxFeatureId = m_FeatureIds[i]; } } if (numfeatures != maxFeatureId) { QString ss = QObject::tr("The number of Features (%1) specified in the file does not correspond to the maximum Feature Id (%2) in the selected Feature Ids array").arg(numfeatures).arg(maxFeatureId); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } QVector<size_t> tDims(1, numfeatures + 1); cellFeatureAttrMat->setTupleDimensions(tDims); updateFeatureInstancePointers(); for (int32_t i = 0; i < numfeatures; i++) { inFile >> gnum >> phase >> ea1 >> ea2 >> ea3; if (gnum > maxFeatureId) { QString ss = QObject::tr("A Feature Id (%1) specified in the file is larger than the maximum Feature Id (%2) in the selected Feature Ids array").arg(numfeatures).arg(maxFeatureId); setErrorCondition(-600); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } m_FeatureEulerAngles[3 * gnum] = ea1; m_FeatureEulerAngles[3 * gnum + 1] = ea2; m_FeatureEulerAngles[3 * gnum + 2] = ea3; m_FeaturePhases[gnum] = phase; if (phase > maxphase) { maxphase = phase; } } if (m_CreateCellLevelArrays == true) { for (size_t i = 0; i < totalPoints; i++) { gnum = m_FeatureIds[i]; m_CellEulerAngles[3 * i] = m_FeatureEulerAngles[3 * gnum]; m_CellEulerAngles[3 * i + 1] = m_FeatureEulerAngles[3 * gnum + 1]; m_CellEulerAngles[3 * i + 2] = m_FeatureEulerAngles[3 * gnum + 2]; m_CellPhases[i] = m_FeaturePhases[gnum]; } } if (m_RenumberFeatures == true) { size_t totalFeatures = cellFeatureAttrMat->getNumTuples(); // Find the unique set of feature ids QVector<bool> activeObjects(totalFeatures, false); for (size_t i = 0; i < totalPoints; ++i) { activeObjects[m_FeatureIds[i]] = true; } cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } notifyStatusMessage(getHumanLabel(), "Complete"); return 0; }