// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void YSChoiAbaqusReader::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if (getInputFile().empty() == true) { ss << ClassName() << " needs the Input File Set and it was not."; setErrorCondition(-387); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else if (MXAFileInfo::exists(getInputFile()) == false) { ss << "The input file does not exist."; setErrorCondition(-388); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else { const unsigned int size(1024); char buf[size]; // Read header from data file to figure out how many points there are std::ifstream in(getInputFile().c_str()); std::string word; bool headerdone = false; int xpoints, ypoints, zpoints; float resx, resy, resz; while (headerdone == false) { in.getline(buf, size); std::string line = buf; in >> word; if (DIMS == word) { in >> xpoints >> ypoints >> zpoints; size_t dims[3] = {xpoints, ypoints, zpoints}; m->setDimensions(dims); m->setOrigin(0,0,0); } if (RES == word) { in >> resx >> resy >> resz; float res[3] = {resx, resy, resz}; m->setResolution(res); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::preflight() { VoxelDataContainer* m = getVoxelDataContainer(); 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); m->setDimensions(m_XP, m_YP, m_ZP); m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); }
//----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int DxReader::readHeader() { VoxelDataContainer* m = getVoxelDataContainer(); std::stringstream ss; int error = 0; std::string line; std::string delimeters(", ;\t"); /* delimeters to split the data */ std::vector<std::string> tokens; /* vector to store the split data */ getline(m_InStream, line, '\n'); tokenize(line, tokens, delimeters); // Process the header information and look for the std::string "counts" // Then read the data size after that size_t pos1 = 0; while (pos1 == 0) { // continue until we find the keyword for (size_t i = 0; i < tokens.size(); i++) { if(tokens[i] == "counts") { pos1 = i; } } // Read the next line of the header if we did not find the keyword // in the line if(pos1 == 0) { tokens.clear(); getline(m_InStream, line, '\n'); tokenize(line, tokens, delimeters); if(tokens.size() == 20) { ss.clear(); ss << "ERROR: Unable to read data dimensions from the header" << std::endl; addErrorMessage(getHumanLabel(), ss.str(), -7); setErrorCondition(-499); m_InStream.close(); return -499; } } } int nx = 0; int ny = 0; int nz = 0; if(pos1 != 0) { error = 0; error += sscanf(tokens[pos1 + 1].c_str(), "%d", &nz); error += sscanf(tokens[pos1 + 2].c_str(), "%d", &ny); error += sscanf(tokens[pos1 + 3].c_str(), "%d", &nx); tokens.clear(); // The dimensions listed in the DX file are always one greater // than the actual dimensions nx--; ny--; nz--; } // std::cout << "INFO: DX data dimensions: " << std::endl; // std::cout << "nz= " << nz << std::endl; // std::cout << "ny= " << ny << std::endl; // std::cout << "nx= " << nx << std::endl; //The DX file has a unique format of 20 entries on each line. I have //no idea who initiated this insanity but I am about to perpetuate //it. // //The most simple thing to do is to read the entire dataset into one //long vector and then read that vector to assign values to the grid // ADR: 6 Sep 08; time to make the input much more general! // equivalent to list-direcvted input in Fortran, actually !! pos1 = 0; while (pos1 == 0) { // continue until we find the keyword for (size_t i = 0; i < tokens.size(); i++) { if(tokens[i] == "items") { pos1 = i; } } // Read the next line of the header if we did not find the keyword // in the line if(pos1 == 0) { tokens.clear(); getline(m_InStream, line, '\n'); tokenize(line, tokens, delimeters); if(tokens.size() == 20) { ss.clear(); ss << "ERROR: Unable to locate the last header line" << std::endl; addErrorMessage(getHumanLabel(), ss.str(), -8); setErrorCondition(-496); m_InStream.close(); return -496; } } } // when we get here, we are looking at data int points = 0; if(pos1 != 0) { error = 0; error += sscanf(tokens[pos1 + 1].c_str(), "%d", &points); tokens.clear(); } m->setDimensions(nx, ny, nz); // std::cout << "Compare no. points " << points << " with x*y*z: " << nx * ny * nz << std::endl; return error; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void RawBinaryReader::execute() { int err = 0; std::stringstream ss; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The Voxel DataContainer Object was NULL", -999); return; } setErrorCondition(0); // Get the total size of the array from the options size_t voxels = m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; if (m_OverRideOriginResolution == true) { m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z); m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); } m->setDimensions(m_Dimensions.x, m_Dimensions.y, m_Dimensions.z); array = IDataArray::NullPointer(); if (m_ScalarType == Detail::Int8) { Int8ArrayType::Pointer p = Int8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<int8_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::UInt8) { UInt8ArrayType::Pointer p = UInt8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<uint8_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::Int16) { Int16ArrayType::Pointer p = Int16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<int16_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::UInt16) { UInt16ArrayType::Pointer p = UInt16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<uint16_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::Int32) { Int32ArrayType::Pointer p = Int32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<int32_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::UInt32) { UInt32ArrayType::Pointer p = UInt32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<uint32_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::Int64) { Int64ArrayType::Pointer p = Int64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<int64_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::UInt64) { UInt64ArrayType::Pointer p = UInt64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<uint64_t>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::Float) { FloatArrayType::Pointer p = FloatArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<float>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } else if (m_ScalarType == Detail::Double) { DoubleArrayType::Pointer p = DoubleArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); err = ReadBinaryFile<double>(p, m_InputFile, m_SkipHeaderBytes); if (err >= 0 ) { SWAP_ARRAY(p) array = p;} } if (NULL != array.get()) { m->addCellData(array->GetName(), array); } else if(err == RBR_FILE_NOT_OPEN ) { setErrorCondition(RBR_FILE_NOT_OPEN); notifyErrorMessage("RawBinaryReader was unable to open the specified file.", getErrorCondition()); } else if (err == RBR_FILE_TOO_SMALL) { setErrorCondition(RBR_FILE_TOO_SMALL); notifyErrorMessage("The file size is smaller than the allocated size.", getErrorCondition()); } else if (err == RBR_FILE_TOO_BIG) { notifyWarningMessage("The file size is larger than the allocated size.", RBR_FILE_TOO_BIG); } else if(err == RBR_READ_EOF) { setErrorCondition(RBR_READ_EOF); notifyErrorMessage("RawBinaryReader read past the end of the specified file.", getErrorCondition()); } /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void RawBinaryReader::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if (getInputFile().empty() == true) { ss << ClassName() << " needs the Input File Set and it was not."; setErrorCondition(-387); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else if (MXAFileInfo::exists(getInputFile()) == false) { ss << "The input file does not exist."; setErrorCondition(-388); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } if(m_OutputArrayName.empty() == true) { ss.str(""); ss << "The Output Array Name is blank (empty) and a value must be filled in for the pipeline to complete."; setErrorCondition(-398); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } if (m_NumberOfComponents < 1) { ss.str(""); ss << "The number of components must be larger than Zero"; setErrorCondition(-391); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } if (m_Dimensionality < 1) { ss.str(""); ss << "The dimensionality must be larger than Zero"; setErrorCondition(-389); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } if ( m_Dimensions.x == 0 || m_Dimensions.y == 0 || m_Dimensions.z == 0) { ss.str(""); ss << "One of the dimensions has a size less than or Equal to Zero (0). The minimum size must be greater than One (1)."; setErrorCondition(-390); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } if (true == preflight) { size_t allocatedBytes = 0; IDataArray::Pointer p = IDataArray::NullPointer(); if (m_ScalarType == Detail::Int8) { p = Int8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(int8_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::UInt8) { p = UInt8ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(uint8_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::Int16) { p = Int16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(int16_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::UInt16) { p = UInt16ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(uint16_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::Int32) { p = Int32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(int32_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::UInt32) { p = UInt32ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(uint32_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::Int64) { p = Int64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(int64_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::UInt64) { p = UInt64ArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(uint64_t) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::Float) { p = FloatArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(float) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } else if (m_ScalarType == Detail::Double) { p = DoubleArrayType::CreateArray(voxels, m_NumberOfComponents, m_OutputArrayName); allocatedBytes = sizeof(double) * m_NumberOfComponents * m_Dimensions.x * m_Dimensions.y * m_Dimensions.z; } // Sanity Check Allocated Bytes versus size of file uint64_t fileSize = MXAFileInfo::fileSize(m_InputFile); int check = SanityCheckFileSizeVersusAllocatedSize(allocatedBytes, fileSize, m_SkipHeaderBytes); if (check == -1) { ss.str(""); ss << "The file size is " << fileSize << " but the number of bytes needed to fill the array is " << allocatedBytes << ". This condition would cause an error reading the input file."; ss << " Please adjust the input parameters to match the size of the file or select a different data file."; setErrorCondition(RBR_FILE_TOO_SMALL); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else if (check == 1) { ss.str(""); ss << "The file size is " << fileSize << " but the number of bytes needed to fill the array is " << allocatedBytes << " which is less than the size of the file."; ss << " DREAM3D will read only the first part of the file into the array."; addWarningMessage(getHumanLabel(), ss.str(), RBR_FILE_TOO_BIG); } m->addCellData(p->GetName(), p); m->setDimensions(m_Dimensions.x, m_Dimensions.y, m_Dimensions.z); m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ReadH5Ebsd::execute() { std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-1); ss << " DataContainer was NULL"; addErrorMessage(getHumanLabel(), ss.str(), -1); return; } int err = 0; setErrorCondition(err); std::string manufacturer; // Get the Size and Resolution of the Volume { H5EbsdVolumeInfo::Pointer volumeInfoReader = H5EbsdVolumeInfo::New(); volumeInfoReader->setFileName(m_InputFile); err = volumeInfoReader->readVolumeInfo(); setErrorCondition(err); int64_t dims[3]; float res[3]; volumeInfoReader->getDimsAndResolution(dims[0], dims[1], dims[2], res[0], res[1], res[2]); /* Sanity check what we are trying to load to make sure it can fit in our address space. * Note that this does not guarantee the user has enough left, just that the * size of the volume can fit in the address space of the program */ #if (CMP_SIZEOF_SSIZE_T==4) int64_t max = std::numeric_limits<size_t>::max(); #else int64_t max = std::numeric_limits<int64_t>::max(); #endif if(dims[0] * dims[1] * dims[2] > max) { err = -1; std::stringstream s; s << "The total number of elements '" << (dims[0] * dims[1] * dims[2]) << "' is greater than this program can hold. Try the 64 bit version."; setErrorCondition(err); addErrorMessage(getHumanLabel(), s.str(), -1); return; } if(dims[0] > max || dims[1] > max || dims[2] > max) { err = -1; std::stringstream s; s << "One of the dimensions is greater than the max index for this sysem. Try the 64 bit version."; s << " dim[0]=" << dims[0] << " dim[1]=" << dims[1] << " dim[2]=" << dims[2]; setErrorCondition(err); addErrorMessage(getHumanLabel(), s.str(), -1); return; } /* ************ End Sanity Check *************************** */ size_t dcDims[3] = { dims[0], dims[1], dims[2] }; m->setDimensions(dcDims); m->setResolution(res); //Now Calculate our "subvolume" of slices, ie, those start and end values that the user selected from the GUI dcDims[2] = m_ZEndIndex - m_ZStartIndex + 1; m->setDimensions(dcDims); manufacturer = volumeInfoReader->getManufacturer(); m_RefFrameZDir = volumeInfoReader->getStackingOrder(); m_SampleTransformationAngle = volumeInfoReader->getSampleTransformationAngle(); m_SampleTransformationAxis = volumeInfoReader->getSampleTransformationAxis(); m_EulerTransformationAngle = volumeInfoReader->getEulerTransformationAngle(); m_EulerTransformationAxis = volumeInfoReader->getEulerTransformationAxis(); volumeInfoReader = H5EbsdVolumeInfo::NullPointer(); } H5EbsdVolumeReader::Pointer ebsdReader; if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0) { ebsdReader = initTSLEbsdVolumeReader(); } else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0) { ebsdReader = initHKLEbsdVolumeReader(); } else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0) { ebsdReader = initHEDMEbsdVolumeReader(); } else { setErrorCondition(-1); std::string msg("Could not determine or match a supported manufacturer from the data file."); msg = msg.append("Supported manufacturer codes are: ").append(Ebsd::Ctf::Manufacturer); msg = msg.append(", ").append(Ebsd::Ang::Manufacturer).append(" and ").append(Ebsd::Mic::Manufacturer); addErrorMessage(getHumanLabel(), msg, -1); return; } // Sanity Check the Error Condition or the state of the EBSD Reader Object. if(getErrorCondition() < 0 || NULL == ebsdReader.get()) { return; } // Initialize all the arrays with some default values int64_t totalPoints = m->getTotalPoints(); ss.str(""); ss << " - Initializing " << totalPoints << " voxels"; notifyStatusMessage(ss.str()); ss.str(""); ss << " - Reading Ebsd Data from file"; notifyStatusMessage(ss.str()); ebsdReader->setSliceStart(m_ZStartIndex); ebsdReader->setSliceEnd(m_ZEndIndex); ebsdReader->readAllArrays(false); ebsdReader->setArraysToRead(m_SelectedVoxelCellArrays); err = ebsdReader->loadData(m->getXPoints(), m->getYPoints(), m->getZPoints(), m_RefFrameZDir); if(err < 0) { setErrorCondition(err); PipelineMessage em (getHumanLabel(), "Error Loading Data from Ebsd Data file.", -1); addErrorMessage(em); return; } typedef DataArray<unsigned int> XTalStructArrayType; GET_PREREQ_DATA(m, DREAM3D, EnsembleData, CrystalStructures, ss, -304, unsigned int, XTalStructArrayType, m->getNumEnsembleTuples(), 1) GET_PREREQ_DATA(m, DREAM3D, EnsembleData, LatticeConstants, ss, -305, float, FloatArrayType, m->getNumEnsembleTuples(), 6) // Copy the data from the pointers embedded in the reader object into our data container (Cell array). if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0) { copyTSLArrays(ebsdReader.get()); } else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0) { copyHKLArrays(ebsdReader.get()); } else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0) { copyHEDMArrays(ebsdReader.get()); } else { std::string msg("Could not determine or match a supported manufacturer from the data file."); msg = msg.append("Supported manufacturer codes are: ").append(Ebsd::Ctf::Manufacturer); msg = msg.append(" and ").append(Ebsd::Ang::Manufacturer); addErrorMessage(getHumanLabel(), msg, -10001); return; } if(m_UseTransformations == true) { if(m_EulerTransformationAngle > 0) { FloatVec3Widget_t eulerAxis; eulerAxis.x = m_EulerTransformationAxis[0]; eulerAxis.y = m_EulerTransformationAxis[1]; eulerAxis.z = m_EulerTransformationAxis[2]; RotateEulerRefFrame::Pointer rot_Euler = RotateEulerRefFrame::New(); rot_Euler->setObservers(this->getObservers()); rot_Euler->setVoxelDataContainer(getVoxelDataContainer()); rot_Euler->setRotationAngle(m_EulerTransformationAngle); rot_Euler->setRotationAxis(eulerAxis); rot_Euler->execute(); } if(m_SampleTransformationAngle > 0) { FloatVec3Widget_t sampleAxis; sampleAxis.x = m_SampleTransformationAxis[0]; sampleAxis.y = m_SampleTransformationAxis[1]; sampleAxis.z = m_SampleTransformationAxis[2]; RotateSampleRefFrame::Pointer rot_Sample = RotateSampleRefFrame::New(); rot_Sample->setObservers(this->getObservers()); rot_Sample->setVoxelDataContainer(getVoxelDataContainer()); rot_Sample->setRotationAngle(m_SampleTransformationAngle); rot_Sample->setRotationAxis(sampleAxis); rot_Sample->setsliceBySlice(true); rot_Sample->execute(); } } // If there is an error set this to something negative and also set a message ss.str(""); ss << getHumanLabel() << " Completed"; notifyStatusMessage(ss.str()); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ReadH5Ebsd::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if (NULL == m) { ss.str(""); ss << getHumanLabel() << "The VoxelDataContainer was NULL and this is NOT allowed. There is an error in the programming. Please contact the developers"; setErrorCondition(-1); addErrorMessage(getHumanLabel(), ss.str(), -1); return; } if (m_InputFile.empty() == true && m_Manufacturer == Ebsd::UnknownManufacturer) { ss.str(""); ss << getHumanLabel() << ": Either the H5Ebsd file must exist or the Manufacturer must be set"; setErrorCondition(-1); addErrorMessage(getHumanLabel(), ss.str(), -1); } else if (MXAFileInfo::exists(m_InputFile) == false) { ss << "The input file does not exist."; setErrorCondition(-388); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } else if (m_InputFile.empty() == false) { H5EbsdVolumeInfo::Pointer reader = H5EbsdVolumeInfo::New(); reader->setFileName(m_InputFile); int err = reader->readVolumeInfo(); if (err < 0) { ss << getHumanLabel() << ": Error reading VolumeInfo from H5Ebsd File"; setErrorCondition(-1); addErrorMessage(getHumanLabel(), ss.str(), -1); return; } std::string manufacturer = reader->getManufacturer(); if(manufacturer.compare(Ebsd::Ang::Manufacturer) == 0) { m_Manufacturer = Ebsd::TSL; } else if(manufacturer.compare(Ebsd::Ctf::Manufacturer) == 0) { m_Manufacturer = Ebsd::HKL; } else if(manufacturer.compare(Ebsd::Mic::Manufacturer) == 0) { m_Manufacturer = Ebsd::HEDM; } else { ss << getHumanLabel() << ": Original Data source could not be determined. It should be TSL, HKL or HEDM"; setErrorCondition(-1); addErrorMessage(getHumanLabel(), ss.str(), -1); return; } int64_t dims[3]; float res[3]; reader->getDimsAndResolution(dims[0], dims[1], dims[2], res[0], res[1], res[2]); /* Sanity check what we are trying to load to make sure it can fit in our address space. * Note that this does not guarantee the user has enough left, just that the * size of the volume can fit in the address space of the program */ #if (CMP_SIZEOF_SSIZE_T==4) int64_t max = std::numeric_limits<size_t>::max(); #else int64_t max = std::numeric_limits<int64_t>::max(); #endif if(dims[0] * dims[1] * dims[2] > max) { err = -1; std::stringstream s; s << "The total number of elements '" << (dims[0] * dims[1] * dims[2]) << "' is greater than this program can hold. Try the 64 bit version."; setErrorCondition(err); addErrorMessage(getHumanLabel(), s.str(), -1); return; } if(dims[0] > max || dims[1] > max || dims[2] > max) { err = -1; std::stringstream s; s << "One of the dimensions is greater than the max index for this sysem. Try the 64 bit version."; s << " dim[0]=" << dims[0] << " dim[1]=" << dims[1] << " dim[2]=" << dims[2]; setErrorCondition(err); addErrorMessage(getHumanLabel(), s.str(), -1); return; } /* ************ End Sanity Check *************************** */ size_t dcDims[3] = { dims[0], dims[1], dims[2] }; m->setDimensions(dcDims); m->setResolution(res); m->setOrigin(0.0f, 0.0f, 0.0f); } H5EbsdVolumeReader::Pointer reader; std::vector<std::string> names; if (m_Manufacturer == Ebsd::TSL) { AngFields fields; reader = H5AngVolumeReader::New(); names = fields.getFilterFields<std::vector<std::string> > (); } else if (m_Manufacturer == Ebsd::HKL) { CtfFields fields; reader = H5CtfVolumeReader::New(); names = fields.getFilterFields<std::vector<std::string> > (); } else if (m_Manufacturer == Ebsd::HEDM) { MicFields fields; reader = H5MicVolumeReader::New(); names = fields.getFilterFields<std::vector<std::string> > (); } else { ss << getHumanLabel() << ": Original Data source could not be determined. It should be TSL or HKL"; setErrorCondition(-1); addErrorMessage(getHumanLabel(), ss.str(), -1); return; } for (size_t i = 0; i < names.size(); ++i) { if (reader->getPointerType(names[i]) == Ebsd::Int32) { Int32ArrayType::Pointer array = Int32ArrayType::CreateArray(voxels, names[i]); m->addCellData(names[i], array); } else if (reader->getPointerType(names[i]) == Ebsd::Float) { FloatArrayType::Pointer array = FloatArrayType::CreateArray(voxels, names[i]); m->addCellData(names[i], array); } } CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, CellEulerAngles, ss, float, FloatArrayType, 0, voxels, 3) CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, CellPhases, ss, int32_t, Int32ArrayType, 0, voxels, 1) typedef DataArray<unsigned int> XTalStructArrayType; CREATE_NON_PREREQ_DATA(m, DREAM3D, EnsembleData, CrystalStructures, ss, unsigned int, XTalStructArrayType, Ebsd::CrystalStructure::UnknownCrystalStructure, ensembles, 1) CREATE_NON_PREREQ_DATA(m, DREAM3D, EnsembleData, LatticeConstants, ss, float, FloatArrayType, 0.0, ensembles, 6) StringDataArray::Pointer materialNames = StringDataArray::CreateArray(1, DREAM3D::EnsembleData::MaterialName); m->addEnsembleData( DREAM3D::EnsembleData::MaterialName, materialNames); ADD_HELP_INDEX_ENTRY(EnsembleData, MaterialName, XTalStructArrayType, 1); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImportR3DStack::execute() { int err = 0; setErrorCondition(err); dataCheck(false,1,1,1); if (getErrorCondition() < 0) { notifyErrorMessage("There is a problem with the data check", getErrorCondition()); } VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); std::stringstream ss; m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z); int x = 0; int y = 0; readXYSize(x, y); if (x < 1 || y < 1) { setErrorCondition(-1000); notifyErrorMessage("At least one dimension is less than 1", getErrorCondition()); } size_t numSlices = m_ZEndIndex - m_ZStartIndex + 1; size_t totalVoxels = numSlices * x * y; // Create a new array, eventually substituting this into the DataContainer later on. Int32ArrayType::Pointer grainIdsPtr = Int32ArrayType::CreateArray(totalVoxels, 1, DREAM3D::CellData::GrainIds); grainIdsPtr->initializeWithZeros(); m_GrainIds = grainIdsPtr->GetPointer(0); // Get the pointer to the front of the array int32_t* currentPositionPtr = m_GrainIds; bool ok = false; int pixelBytes = 0; int totalPixels = 0; int height = 0; int width = 0; size_t index = 0; int64_t z = m_ZStartIndex; m->setDimensions(x,y,numSlices); for (std::vector<std::string>::iterator filepath = m_R3DFileList.begin(); filepath != m_R3DFileList.end(); ++filepath) { QString R3DFName = QString::fromStdString(*filepath); ss.str(""); ss << "Importing file " << R3DFName.toStdString(); notifyStatusMessage(ss.str()); QByteArray buf; QFile in(R3DFName); if (!in.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QString("R3D file could not be opened: ") + R3DFName; setErrorCondition(-14000); notifyErrorMessage(msg.toStdString(), getErrorCondition()); } buf = in.readLine(); // Read first line which is the x and y sizes QList<QByteArray> tokens = buf.split(','); width = tokens.at(0).toInt(); height = tokens.at(1).toInt(); int32_t value = 0; for(qint32 i = 0; i < height; ++i) { buf = in.readLine(); tokens = buf.split(','); if (tokens.size() != width+2) { notifyStatusMessage("A file did not have the correct width partilcuar line"); break; } for(int j = 1; j < width+1; j++) { currentPositionPtr[index] = tokens[j].toInt(&ok, 10); ++index; if (!ok) { setErrorCondition(-2004); notifyErrorMessage("Width dimension entry was not an integer", getErrorCondition()); break; } } if (in.atEnd() == true && i < height - 2) { notifyStatusMessage("A file did not have the correct height"); break; } } ++z; if(getCancel() == true) { notifyStatusMessage("Conversion was Canceled"); return; } } // OVer write any GrainIds array that is already in the DataContainer getVoxelDataContainer()->addCellData(DREAM3D::CellData::GrainIds, grainIdsPtr); /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }