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; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t EnsembleInfoReader::readFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); AttributeMatrix::Pointer cellensembleAttrMat = m->getAttributeMatrix(getCellEnsembleAttributeMatrixName()); int32_t numphases = 0; QSettings settings(getInputFile(), QSettings::IniFormat); // The .ini or .txt input file settings.beginGroup("EnsembleInfo"); numphases = settings.value("Number_Phases").toInt(); // read number of phases from input file settings.endGroup(); if (0 == numphases) // Either the group name "EnsembleInfo" is incorrect or 0 was entered as the Number_Phases { QString ss = QObject::tr("Check the group name EnsembleInfo and that Number_Phases > 0"); setErrorCondition(-10003); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } // Figure out if we are reading contiguous groups std::vector<bool> visited(numphases + 1, false); visited[0] = true; //this is DREAM3D's internal, which is always visited. QVector<size_t> tDims(1, numphases + 1); cellensembleAttrMat->resizeAttributeArrays(tDims); updateEnsembleInstancePointers(); for (int32_t index = 1; index < numphases + 1; index++) { QString group = QString::number(index); settings.beginGroup(group); QString xtalString = settings.value(DREAM3D::StringConstants::CrystalStructure, "MissingCrystalStructure").toString(); QString phaseTypeString = settings.value(DREAM3D::StringConstants::PhaseType, "MissingPhaseType").toString(); // Check to make sure the user has something for each of the Crystal Structure and Phase Type if (xtalString.compare("MissingCrystalStructure") == 0) { QString ss = QObject::tr("Missing crystal structure for phase '%1'").arg(group); setErrorCondition(-10008); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } if (phaseTypeString.compare("MissingPhaseType") == 0) { QString ss = QObject::tr("Missing phase type for phase '%1'").arg(group); setErrorCondition(-10009); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } // Past that sanity check, so we have values, lets parse them QStringList values; values << xtalString << phaseTypeString; ensembleLookup(values); // Lookup number for the crystal number string and the phase type string read from the file // Check to see if the Crystal Structure string was valid if (m_crystruct == Ebsd::CrystalStructure::UnknownCrystalStructure) // The crystal structure name read from the file was not found in the lookup table { QString ss = QObject::tr("Incorrect crystal structure name '%1'").arg(xtalString); setErrorCondition(-10006); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } else { m_CrystalStructures[index] = m_crystruct; } // now check to see if the Phase type string was valid. if (m_ptype == DREAM3D::PhaseType::UnknownPhaseType) { QString ss = QObject::tr("Incorrect phase type name '%1'").arg(phaseTypeString); // The phase type name read from the file was not found in the lookup table setErrorCondition(-10007); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } else { m_PhaseTypes[index] = m_ptype; } visited[index] = true; // Close up this group settings.endGroup(); } //Make sure we visited all the groups. for(std::vector<bool>::size_type i = 0; i < visited.size(); i++) { if(visited[i] == false) { QString ss = QObject::tr("Phase '%1' did not have entries in the file. Phase numbering must start at 1 and no phases may be skipped").arg(i); // The phase type name read from the file was not found in the lookup table setErrorCondition(-10005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } } notifyStatusMessage(getHumanLabel(), "Complete"); return 0; }