int main(int argc, char **argv) { AngReader reader; reader.setFileName(argv[1]); int err = reader.readHeaderOnly(); if (err < 0) { std::cout << "Error Trying to read the header for " << argv[1] << std::endl; } return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenODFWidget::on_loadODFTextureBtn_clicked() { QString file = angleFilePath->text(); if(true == file.isEmpty()) { return; } QFileInfo fi(angleFilePath->text()); if(fi.exists() == false) { return; } size_t count = 0; QVector<float> e1s(count); QVector<float> e2s(count); QVector<float> e3s(count); QVector<float> weights(count); QVector<float> sigmas(count); QProgressDialog progress("Loading Data ....", "Cancel", 0, 3, this); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(2000); if (fi.suffix().compare(Ebsd::Ang::FileExt) == 0) { progress.setValue(1); progress.setLabelText("[1/3] Reading File ..."); AngReader loader; loader.setFileName(angleFilePath->text()); int err = loader.readFile(); if(err < 0) { QMessageBox::critical(this, "Error loading the ANG file", loader.getErrorMessage(), QMessageBox::Ok); return; } float* phi1 = loader.getPhi1Pointer(); float* phi = loader.getPhiPointer(); float* phi2 = loader.getPhi2Pointer(); int xDim = loader.getXDimension(); int yDim = loader.getYDimension(); count = xDim * yDim; e1s.resize(count); e2s.resize(count); e3s.resize(count); weights.resize(count); sigmas.resize(count); for(size_t i = 0; i < count; ++i) { e1s[i] = phi1[i]; e2s[i] = phi[i]; e3s[i] = phi2[i]; weights[i] = 1.0; sigmas[i] = 0.0; } } else if (fi.suffix().compare(Ebsd::Ctf::FileExt) == 0) { progress.setValue(1); progress.setLabelText("[1/3] Reading File ..."); CtfReader loader; loader.setFileName(angleFilePath->text()); int err = loader.readFile(); if(err < 0) { QMessageBox::critical(this, "Error loading the CTF file", loader.getErrorMessage(), QMessageBox::Ok); return; } float* phi1 = loader.getEuler1Pointer(); float* phi = loader.getEuler2Pointer(); float* phi2 = loader.getEuler3Pointer(); int xDim = loader.getXDimension(); int yDim = loader.getYDimension(); count = xDim * yDim; e1s.resize(count); e2s.resize(count); e3s.resize(count); weights.resize(count); sigmas.resize(count); for(size_t i = 0; i < count; ++i) { e1s[i] = phi1[i]; e2s[i] = phi[i]; e3s[i] = phi2[i]; weights[i] = 1.0; sigmas[i] = 0.0; } } else { progress.setValue(1); progress.setLabelText("[1/3] Reading File ..."); AngleFileLoader::Pointer loader = AngleFileLoader::New(); loader->setInputFile(angleFilePath->text()); loader->setAngleRepresentation(angleRepresentation->currentIndex()); loader->setFileAnglesInDegrees(anglesInDegrees->isChecked()); loader->setOutputAnglesInDegrees(true); QString delim; int index = delimiter->currentIndex(); switch(index) { case 0: delim = " "; break; case 1: delim = "\t"; break; case 2: delim = ","; break; case 3: delim = ";"; break; default: delim = " "; } loader->setDelimiter(delim); FloatArrayType::Pointer data = loader->loadData(); if (loader->getErrorCode() < 0) { QMessageBox::critical(this, "Error Loading Angle data", loader->getErrorMessage(), QMessageBox::Ok); return; } count = data->getNumberOfTuples(); e1s.resize(count); e2s.resize(count); e3s.resize(count); weights.resize(count); sigmas.resize(count); for(size_t i = 0; i < count; ++i) { e1s[i] = data->getComponent(i, 0); e2s[i] = data->getComponent(i, 1); e3s[i] = data->getComponent(i, 2); weights[i] = data->getComponent(i, 3); sigmas[i] = data->getComponent(i, 4); } } progress.setValue(2); progress.setLabelText("[2/3] Rendering Pole Figure ..."); m_OdfBulkTableModel->removeRows(0, m_OdfBulkTableModel->rowCount()); #if 1 m_OdfBulkTableModel->blockSignals(true); m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler1, e1s); m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler2, e2s); m_OdfBulkTableModel->setColumnData(SGODFTableModel::Euler3, e3s); m_OdfBulkTableModel->setColumnData(SGODFTableModel::Weight, weights); m_OdfBulkTableModel->setColumnData(SGODFTableModel::Sigma, sigmas); m_OdfBulkTableModel->blockSignals(false); #endif on_m_CalculateODFBtn_clicked(); progress.setValue(3); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Hex2SqrConverter::execute() { std::stringstream ss; herr_t err = 0; std::vector<int> indices; // Loop on Each EBSD File float total = static_cast<float>( m_ZEndIndex - m_ZStartIndex ); int progress = 0; int64_t z = m_ZStartIndex; /* There is a frailness about the z index and the file list. The programmer * using this code MUST ensure that the list of files that is sent into this * class is in the appropriate order to match up with the z index (slice index) * otherwise the import will have subtle errors. The programmer is urged NOT to * simply gather a list from the file system as those lists are sorted in such * a way that if the number of digits appearing in the filename are NOT the same * then the list will be wrong, ie, this example: * * slice_1.ang * slice_2.ang * .... * slice_10.ang * * Most, if not ALL C++ libraries when asked for that list will return the list * sorted like the following: * * slice_1.ang * slice_10.ang * slice_2.ang * * which is going to cause problems because the data is going to be placed * into the HDF5 file at the wrong index. YOU HAVE BEEN WARNED. */ // int totalSlicesImported = 0; for (std::vector<std::string>::iterator filepath = m_EbsdFileList.begin(); filepath != m_EbsdFileList.end(); ++filepath) { std::string ebsdFName = *filepath; progress = static_cast<int>( z - m_ZStartIndex ); progress = (int)(100.0f * (float)(progress) / total); std::string msg = "Converting File: " + ebsdFName; ss.str(""); notifyStatusMessage(msg.c_str()); // Write the Manufacturer of the OIM file here // This list will grow to be the number of EBSD file formats we support std::string ext = MXAFileInfo::extension(ebsdFName); std::string base = MXAFileInfo::fileNameWithOutExtension(ebsdFName); std::string path = MXAFileInfo::parentPath(ebsdFName); if(ext.compare(Ebsd::Ang::FileExt) == 0) { AngReader reader; reader.setFileName(ebsdFName); reader.setReadHexGrid(true); int err = reader.readFile(); if(err < 0 && err != -600) { addErrorMessage(getHumanLabel(), reader.getErrorMessage(), reader.getErrorCode()); setErrorCondition(reader.getErrorCode()); return; } else if(reader.getGrid().find(Ebsd::Ang::SquareGrid) == 0) { ss.str(""); ss << "Ang File is already a square grid: " << ebsdFName; setErrorCondition(-55000); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); return; } else { if (err == -600) { notifyWarningMessage( reader.getErrorMessage(), reader.getErrorCode() ); } std::string origHeader = reader.getOriginalHeader(); if (origHeader.empty() == true) { ss.str(); ss << "Header could not be retrieved: " << ebsdFName; setErrorCondition(-55001); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } char buf[kBufferSize]; std::stringstream in(origHeader); std::string newEbsdFName = path + "/Sqr_" + base + "." + ext; std::ofstream outFile; outFile.open(newEbsdFName.c_str()); m_HeaderIsComplete = false; float HexXStep = reader.getXStep(); float HexYStep = reader.getYStep(); int HexNumColsOdd = reader.getNumOddCols(); int HexNumColsEven = reader.getNumEvenCols(); int HexNumRows = reader.getNumRows(); m_NumCols = (HexNumColsOdd*HexXStep)/m_XResolution; m_NumRows = (HexNumRows*HexYStep)/m_YResolution; float xSqr, ySqr, xHex1, yHex1, xHex2, yHex2; int point, point1, point2; int row1, row2, col1, col2; float dist1, dist2; float* phi1 = reader.getPhi1Pointer(); float* PHI = reader.getPhiPointer(); float* phi2 = reader.getPhi2Pointer(); float* ci = reader.getConfidenceIndexPointer(); float* iq = reader.getImageQualityPointer(); float* semsig = reader.getSEMSignalPointer(); float* fit = reader.getFitPointer(); int* phase = reader.getPhaseDataPointer(); while (!in.eof()) { std::string line; ::memset(buf, 0, kBufferSize); in.getline(buf, kBufferSize); line = modifyAngHeaderLine(buf, kBufferSize); if(m_HeaderIsComplete == false) outFile << line << std::endl; } for(int j = 0; j < m_NumRows; j++) { for(int i = 0; i < m_NumCols; i++) { xSqr = float(i)*m_XResolution; ySqr = float(j)*m_YResolution; row1 = ySqr/(HexYStep); yHex1 = row1*HexYStep; row2 = row1 + 1; yHex2 = row2*HexYStep; if(row1%2 == 0) { col1 = xSqr/(HexXStep); xHex1 = col1*HexXStep; point1 = ((row1/2)*HexNumColsEven) + ((row1/2)*HexNumColsOdd) + col1; col2 = (xSqr-(HexXStep/2.0))/(HexXStep); xHex2 = col2*HexXStep + (HexXStep/2.0); point2 = ((row1/2)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col2; } else { col1 = (xSqr-(HexXStep/2.0))/(HexXStep); xHex1 = col1*HexXStep + (HexXStep/2.0); point1 = ((row1/2)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col1; col2 = xSqr/(HexXStep); xHex2 = col2*HexXStep; point2 = (((row1/2)+1)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col2; } dist1 = ((xSqr-xHex1)*(xSqr-xHex1)) + ((ySqr-yHex1)*(ySqr-yHex1)); dist2 = ((xSqr-xHex2)*(xSqr-xHex2)) + ((ySqr-yHex2)*(ySqr-yHex2)); if(dist1 <= dist2 || row1 == (HexNumRows-1)) {point = point1;} else {point = point2;} outFile << " " << phi1[point] << " " << PHI[point] << " " << phi2[point] << " " << xSqr << " " << ySqr << " " << iq[point] << " " << ci[point] << " " << phase[point] << " " << semsig[point] << " " << fit[point] << " " << std::endl; } } } } else if(ext.compare(Ebsd::Ctf::FileExt) == 0) { std::cout << "Ctf files are not on a hexagonal grid and do not need to be converted." << std::endl; } else { err = -1; ss.str(""); ss << "The File extension was not detected correctly"; addErrorMessage(getHumanLabel(), ss.str(), err); setErrorCondition(-1); return; } } notifyStatusMessage("Import Complete"); }