// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AddOrientationNoise::add_orientation_noise() { notifyStatusMessage("Adding Orientation Noise"); DREAM3D_RANDOMNG_NEW() VoxelDataContainer* m = getVoxelDataContainer(); //float ea1, ea2, ea3; float g[3][3]; float newg[3][3]; float rot[3][3]; float w, n1, n2, n3; int64_t totalPoints = m->getTotalPoints(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); ++i) { float ea1 = m_CellEulerAngles[3*i+0]; float ea2 = m_CellEulerAngles[3*i+1]; float ea3 = m_CellEulerAngles[3*i+2]; OrientationMath::EulertoMat(ea1, ea2, ea3, g); n1 = static_cast<float>( rg.genrand_res53() ); n2 = static_cast<float>( rg.genrand_res53() ); n3 = static_cast<float>( rg.genrand_res53() ); w = static_cast<float>( rg.genrand_res53() ); w = 2.0*(w-0.5); w = (m_Magnitude*w); OrientationMath::AxisAngletoMat(w, n1, n2, n3, rot); MatrixMath::Multiply3x3with3x3(g, rot, newg); OrientationMath::MattoEuler(newg, ea1, ea2, ea3); m_CellEulerAngles[3*i+0] = ea1; m_CellEulerAngles[3*i+1] = ea2; m_CellEulerAngles[3*i+2] = ea3; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AddOrientationNoise::execute() { int err = 0; setErrorCondition(err); DREAM3D_RANDOMNG_NEW() VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); dataCheck(false, totalPoints, totalFields, m->getNumEnsembleTuples()); if (getErrorCondition() < 0) { return; } m_Magnitude = m_Magnitude*m_pi/180.0; add_orientation_noise(); // If there is an error set this to something negative and also set a message notifyStatusMessage("AddOrientationNoises Completed"); }
void OrientationMath::_calcDetermineHomochoricValues(float init[3], float step[3], float phi[3], int choose, float &r1, float &r2, float &r3) { float random; DREAM3D_RANDOMNG_NEW() random = static_cast<float>( rg.genrand_res53() ); r1 = (step[0] * phi[0]) + (step[0] * random) - (init[0]); random = static_cast<float>( rg.genrand_res53() ); r2 = (step[1] * phi[1]) + (step[1] * random) - (init[1]); random = static_cast<float>( rg.genrand_res53() ); r3 = (step[2] * phi[2]) + (step[2] * random) - (init[2]); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void PrecipitateRolledPreset::initializeClusteringTableModel(StatsGenPlotWidget* plot, QVector<float> binNumbers) { // Make sure the distribution is set correctly plot->setDistributionType(DREAM3D::DistributionType::LogNormal, false); // This line basically makes sure we have the distribution type we are looking for SGLogNormalTableModel* model = qobject_cast<SGLogNormalTableModel*> (plot->tableModel()); if (NULL == model) { return; } qint32 count = binNumbers.count(); // Remove all the current rows in the table model model->removeRows(0, model->rowCount()); float mu, sigma; DREAM3D_RANDOMNG_NEW() QVector<float> mus; QVector<float> sigmas; QVector<QString> colors; QStringList colorNames = QColor::colorNames(); qint32 colorOffset = 21; int middlebin = count / 2; for (qint32 i = 0; i < count; ++i) { mu = log(8.0 + (1.0 * float(i - middlebin))); sigma = 0.3 + (float(middlebin - i) / float(middlebin * 10)); mus.push_back(mu); sigmas.push_back(sigma); colors.push_back(colorNames[colorOffset++]); if (colorOffset == colorNames.size()) { colorOffset = 21; } } QVector<QVector<float> > data; data.push_back(mus); data.push_back(sigmas); model->setTableData(binNumbers, data, colors); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void PrecipitateRolledPreset::initializeOmega3TableModel(StatsGenPlotWidget* plot, QVector<float> binNumbers) { // Make sure the distribution is set correctly plot->setDistributionType(DREAM3D::DistributionType::Beta, false); // This line basically makes sure we have the distribution type we are looking for SGBetaTableModel* model = qobject_cast<SGBetaTableModel*> (plot->tableModel()); if (NULL == model) { return; } qint32 count = binNumbers.count(); // Remove all the current rows in the table model // model->removeRows(0, model->rowCount()); float alpha, beta; DREAM3D_RANDOMNG_NEW() QVector<float> alphas; QVector<float> betas; QVector<QString> colors; QStringList colorNames = QColor::colorNames(); qint32 colorOffset = 21; for (qint32 i = 0; i < count; ++i) { alpha = (0 * i) + 10.0 + rg.genrand_res53(); beta = (0 * i) + 1.5 + (0.5 * rg.genrand_res53()); alphas.push_back(alpha); betas.push_back(beta); colors.push_back(colorNames[colorOffset++]); if (colorOffset == colorNames.size()) { colorOffset = 21; } } QVector<QVector<float> > data; data.push_back(alphas); data.push_back(betas); model->setTableData(binNumbers, data, colors); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AddBadData::add_noise() { notifyStatusMessage(getHumanLabel(), "Adding Noise"); DREAM3D_RANDOMNG_NEW() DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getGBEuclideanDistancesArrayPath().getDataContainerName()); QString attMatName = getGBEuclideanDistancesArrayPath().getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attMatName)->getAttributeArrayNames(); float random = 0.0f; size_t totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); for (size_t i = 0; i < totalPoints; ++i) { if (m_BoundaryNoise == true && m_GBEuclideanDistances[i] < 1) { random = static_cast<float>( rg.genrand_res53() ); if (random < m_BoundaryVolFraction) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attMatName)->getAttributeArray(*iter); p->initializeTuple(i, 0); } } } if (m_PoissonNoise == true) { random = static_cast<float>( rg.genrand_res53() ); if (random < m_PoissonVolFraction) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attMatName)->getAttributeArray(*iter); p->initializeTuple(i, 0); } } } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsMutualInformation::form_features_sections() { DREAM3D_RANDOMNG_NEW() DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); 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]), }; DimType point = 0; DimType seed = 0; bool noseeds = false; int32_t featurecount = 1; DimType neighbor = 0; QuatF q1 = QuaternionMathF::New(); QuatF q2 = QuaternionMathF::New(); QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float w = 0.0f; float n1 = 0.0f; float n2 = 0.0f; float n3 = 0.0f; DimType randx = 0; DimType randy = 0; bool good = false; DimType x = 0, y = 0, z = 0; DimType col = 0, row = 0; size_t size = 0; size_t initialVoxelsListSize = 1000; m_FeatureCounts->resize(dims[2]); featurecounts = m_FeatureCounts->getPointer(0); std::vector<DimType> voxelslist(initialVoxelsListSize, -1); DimType neighpoints[4] = { 0, 0, 0, 0 }; neighpoints[0] = -dims[0]; neighpoints[1] = -1; neighpoints[2] = 1; neighpoints[3] = dims[0]; uint32_t phase1 = 0, phase2 = 0; for (DimType slice = 0; slice < dims[2]; slice++) { QString ss = QObject::tr("Aligning Sections || Identifying Features on Sections || %1% Complete").arg(((float)slice / dims[2]) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); featurecount = 1; noseeds = false; while (noseeds == false) { seed = -1; randx = DimType(float(rg.genrand_res53()) * float(dims[0])); randy = DimType(float(rg.genrand_res53()) * float(dims[1])); for (DimType j = 0; j < dims[1]; ++j) { for (DimType i = 0; i < dims[0]; ++i) { x = randx + i; y = randy + j; z = slice; if (x > dims[0] - 1) { x = x - dims[0]; } if (y > dims[1] - 1) { y = y - dims[1]; } point = (z * dims[0] * dims[1]) + (y * dims[0]) + x; if ((m_UseGoodVoxels == false || m_GoodVoxels[point] == true) && m_FeatureIds[point] == 0 && m_CellPhases[point] > 0) { seed = point; } if (seed > -1) { break; } } if( seed > -1) { break; } } if (seed == -1) { noseeds = true; } if (seed >= 0) { size = 0; m_FeatureIds[seed] = featurecount; voxelslist[size] = seed; size++; for (size_t j = 0; j < size; ++j) { DimType currentpoint = voxelslist[j]; col = currentpoint % dims[0]; row = (currentpoint / dims[0]) % dims[1]; QuaternionMathF::Copy(quats[currentpoint], q1); phase1 = m_CrystalStructures[m_CellPhases[currentpoint]]; for (int32_t i = 0; i < 4; i++) { good = true; neighbor = currentpoint + neighpoints[i]; if ((i == 0) && row == 0) { good = false; } if ((i == 3) && row == (dims[1] - 1)) { good = false; } if ((i == 1) && col == 0) { good = false; } if ((i == 2) && col == (dims[0] - 1)) { good = false; } if (good == true && m_FeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0) { w = std::numeric_limits<float>::max(); QuaternionMathF::Copy(quats[neighbor], q2); phase2 = m_CrystalStructures[m_CellPhases[neighbor]]; if (phase1 == phase2) { w = m_OrientationOps[phase1]->getMisoQuat(q1, q2, n1, n2, n3); } if (w < m_MisorientationTolerance) { m_FeatureIds[neighbor] = featurecount; voxelslist[size] = neighbor; size++; if (std::vector<DimType>::size_type(size) >= voxelslist.size()) { size = voxelslist.size(); voxelslist.resize(size + initialVoxelsListSize); for (std::vector<DimType>::size_type v = size; v < voxelslist.size(); ++v) { voxelslist[v] = -1; } } } } } } voxelslist.erase(std::remove(voxelslist.begin(), voxelslist.end(), -1), voxelslist.end()); featurecount++; voxelslist.assign(initialVoxelsListSize, -1); } } featurecounts[slice] = featurecount; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::execute() { int err = 0; setErrorCondition(err); DREAM3D_RANDOMNG_NEW() VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); if (getErrorCondition() < 0) { return; } if(m->getXRes() == m_Resolution.x && m->getYRes() == m_Resolution.y && m->getZRes() == m_Resolution.z) { return; } size_t dims[3]; m->getDimensions(dims); float sizex = (dims[0])*m->getXRes(); float sizey = (dims[1])*m->getYRes(); float sizez = (dims[2])*m->getZRes(); int m_XP = int(sizex / m_Resolution.x); int m_YP = int(sizey / m_Resolution.y); int m_ZP = int(sizez / m_Resolution.z); int64_t totalPoints = m_XP*m_YP*m_ZP; float x, y, z; int col, row, plane; int index; int index_old; std::vector<size_t> newindicies; newindicies.resize(totalPoints); for (int i = 0; i < m_ZP; i++) { std::stringstream ss; ss << "Changing Resolution - " << ((float)i/m->getZPoints())*100 << " Percent Complete"; notifyStatusMessage(ss.str()); for (int j = 0; j < m_YP; j++) { for (int k = 0; k < m_XP; k++) { x = (k * m_Resolution.x); y = (j * m_Resolution.y); z = (i * m_Resolution.z); col = int(x / m->getXRes()); row = int(y / m->getYRes()); plane = int(z / m->getZRes()); index_old = (plane * m->getXPoints() * m->getYPoints()) + (row * m->getXPoints()) + col; index = (i * m_XP * m_YP) + (j * m_XP) + k; newindicies[index] = index_old; } } } std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); for (std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); // Make a copy of the 'p' array that has the same name. When placed into // the data container this will over write the current array with // the same name. At least in theory IDataArray::Pointer data = p->createNewArray(p->GetNumberOfTuples(), p->GetNumberOfComponents(), p->GetName()); data->Resize(totalPoints); void* source = NULL; void* destination = NULL; size_t newIndicies_I = 0; int nComp = data->GetNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++) { newIndicies_I = newindicies[i]; source = p->GetVoidPointer((nComp * newIndicies_I)); destination = data->GetVoidPointer((data->GetNumberOfComponents() * i)); ::memcpy(destination, source, p->GetTypeSize() * data->GetNumberOfComponents()); } m->addCellData(*iter, data); } m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->setDimensions(m_XP, m_YP, m_ZP); notifyStatusMessage("Complete"); }