// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AdjustVolumeOrigin::execute() { VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); std::stringstream ss; // Set the Voxel Volume First, since this is easy if (m_ApplyToVoxelVolume ==true) { m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z); } if (m_ApplyToSurfaceMesh == true) { updateSurfaceMesh(); } if (m_ApplyToSolidMesh == true) { updatesSolidMesh(); } notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void DxReader::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()); } CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, GrainIds, ss, int32_t, Int32ArrayType, 0, voxels, 1) m->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->setOrigin(m_Origin.x, m_Origin.y, m_Origin.z); if (m_InStream.is_open() == true) { m_InStream.close(); } // We need to read the header of the input file to get the dimensions m_InStream.open(getInputFile().c_str(), std::ios_base::binary); if(!m_InStream) { ss.clear(); ss << " Runtime Error. The input file '" << getInputFile() << "' could not be" << " opened for reading. Do you have access to this file?"; setErrorCondition(-49800); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); return; } int error = readHeader(); m_InStream.close(); if (error < 0) { setErrorCondition(error); ss.clear(); ss << "Error occurred trying to parse the dimensions from the input file. Is the input file a Dx file?"; addErrorMessage(getHumanLabel(), ss.str(), -11000); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 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::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"); }