// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FlattenImage::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); //int err = 0; int numImageComp = 1; IDataArray::Pointer iDataArray = m->getCellData(m_ImageDataArrayName); if(NULL != iDataArray.get()) { UInt8ArrayType* imageDataPtr = UInt8ArrayType::SafePointerDownCast(iDataArray.get()); if (NULL != imageDataPtr) { numImageComp = imageDataPtr->GetNumberOfComponents(); } } GET_PREREQ_DATA(m, DREAM3D, CellData, ImageData, ss, -301, unsigned char, UCharArrayType, voxels, numImageComp) // if(err == -301) // { // setErrorCondition(0); // err = 0; // GET_PREREQ_DATA(m, DREAM3D, CellData, ImageData, ss, -302, unsigned char, UCharArrayType, voxels, 3) // } CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, FlatImageData, ss, int32_t, Int32ArrayType, 0, voxels, 1) }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsList::find_shifts(std::vector<int> &xshifts, std::vector<int> &yshifts) { VoxelDataContainer* m = getVoxelDataContainer(); //int64_t totalPoints = m->totalPoints(); std::ifstream inFile; inFile.open(m_InputFile.c_str()); size_t udims[3] = {0,0,0}; m->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]), }; int slice; int newxshift, newyshift; for (DimType iter = 1; iter < dims[2]; iter++) { inFile >> slice >> newxshift >> newyshift; xshifts[iter] = xshifts[iter-1] + newxshift; yshifts[iter] = yshifts[iter-1] + newyshift; } inFile.close(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 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 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 Threshold::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if(m_SelectedCellArrayName.empty() == true) { setErrorCondition(-11000); ss << "An array from the Voxel Data Container must be selected."; addErrorMessage(getHumanLabel(),ss.str(),getErrorCondition()); } else { m_RawImageDataArrayName=m_SelectedCellArrayName; GET_PREREQ_DATA(m, DREAM3D, CellData, RawImageData, ss, -300, ImageProcessing::DefaultPixelType, ImageProcessing::DefaultArrayType, voxels, 1) if(m_OverwriteArray) { } else { CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, ProcessedImageData, ss, ImageProcessing::DefaultPixelType, ImageProcessing::DefaultArrayType, 0, voxels, 1) m->renameCellData(m_ProcessedImageDataArrayName, m_NewCellArrayName); } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsFeature::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); size_t numgrains = m->getNumFieldTuples(); size_t numensembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, numgrains, numensembles); if (getErrorCondition() < 0) { return; } AlignSections::execute(); // If there is an error set this to something negative and also set a message notifyStatusMessage("Aligning Sections Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FlattenImage::execute() { VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); int64_t totalPoints = m->getTotalPoints(); size_t numgrains = m->getNumFieldTuples(); size_t numensembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, numgrains, numensembles); if (getErrorCondition() < 0) { return; } float Rfactor = 1.0; float Gfactor = 1.0; float Bfactor = 1.0; if (m_FlattenMethod == DREAM3D::FlattenImageMethod::Average) { Rfactor = 1.0/3.0; Gfactor = 1.0/3.0; Bfactor = 1.0/3.0; } else if (m_FlattenMethod == DREAM3D::FlattenImageMethod::Luminosity) { Rfactor = 0.21; Gfactor = 0.72; Bfactor = 0.07; } #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif size_t comp = m->getCellData(m_ImageDataArrayName)->GetNumberOfComponents(); // std::cout << "FlattenImage: " << m_ConversionFactor << std::endl; #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(0, totalPoints), FlattenImageImpl(m_ImageData, m_FlatImageData, Rfactor, Gfactor, Bfactor, comp), tbb::auto_partitioner()); } else #endif { FlattenImageImpl serial(m_ImageData, m_FlatImageData, Rfactor, Gfactor, Bfactor, comp); serial.convert(0, totalPoints); } 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); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int VoxelDataContainerWriter::writeEnsembleData(hid_t dcGid) { std::stringstream ss; int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); // Write the Ensemble data err = H5Utilities::createGroupsFromPath(H5_ENSEMBLE_DATA_GROUP_NAME, dcGid); if(err < 0) { ss.str(""); ss << "Error creating HDF Group " << H5_ENSEMBLE_DATA_GROUP_NAME << std::endl; setErrorCondition(-66); notifyErrorMessage( ss.str(), err); H5Gclose(dcGid); // Close the Data Container Group return err; } err = H5Lite::writeStringAttribute(dcGid, H5_ENSEMBLE_DATA_GROUP_NAME, H5_NAME, H5_ENSEMBLE_DATA_DEFAULT); hid_t ensembleGid = H5Gopen(dcGid, H5_ENSEMBLE_DATA_GROUP_NAME, H5P_DEFAULT); if(err < 0) { ss.str(""); ss << "Error opening ensemble Group " << H5_ENSEMBLE_DATA_GROUP_NAME << std::endl; setErrorCondition(-67); notifyErrorMessage( ss.str(), err); H5Gclose(dcGid); // Close the Data Container Group return err; } NameListType names = m->getEnsembleArrayNameList(); for (NameListType::iterator iter = names.begin(); iter != names.end(); ++iter) { IDataArray::Pointer array = m->getEnsembleData(*iter); err = array->writeH5Data(ensembleGid); if(err < 0) { ss.str(""); ss << "Error writing Ensemble array '" << *iter << "' to the HDF5 File"; notifyErrorMessage( ss.str(), err); setErrorCondition(err); H5Gclose(ensembleGid); // Close the Cell Group H5Gclose(dcGid); // Close the Data Container Group return err; } } H5Gclose(ensembleGid); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ReadH5Ebsd::copyHEDMArrays(H5EbsdVolumeReader* ebsdReader) { float* f1 = NULL; float* f2 = NULL; float* f3 = NULL; int* phasePtr = NULL; FloatArrayType::Pointer fArray = FloatArrayType::NullPointer(); Int32ArrayType::Pointer iArray = Int32ArrayType::NullPointer(); VoxelDataContainer* m = getVoxelDataContainer(); int64_t totalPoints = m->getTotalPoints(); if (m_SelectedVoxelCellArrays.find(m_CellEulerAnglesArrayName) != m_SelectedVoxelCellArrays.end() ) { // radianconversion = M_PI / 180.0; f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler1)); f2 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler2)); f3 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Euler3)); fArray = FloatArrayType::CreateArray(totalPoints * 3, DREAM3D::CellData::EulerAngles); fArray->SetNumberOfComponents(3); float* cellEulerAngles = fArray->GetPointer(0); for (int64_t i = 0; i < totalPoints; i++) { cellEulerAngles[3 * i] = f1[i]; cellEulerAngles[3 * i + 1] = f2[i]; cellEulerAngles[3 * i + 2] = f3[i]; } m->addCellData(DREAM3D::CellData::EulerAngles, fArray); } if (m_SelectedVoxelCellArrays.find(m_CellPhasesArrayName) != m_SelectedVoxelCellArrays.end() ) { phasePtr = reinterpret_cast<int*>(ebsdReader->getPointerByName(Ebsd::Mic::Phase)); iArray = Int32ArrayType::CreateArray(totalPoints, DREAM3D::CellData::Phases); iArray->SetNumberOfComponents(1); ::memcpy(iArray->GetPointer(0), phasePtr, sizeof(int32_t) * totalPoints); m->addCellData(DREAM3D::CellData::Phases, iArray); } if (m_SelectedVoxelCellArrays.find(Ebsd::Mic::Confidence) != m_SelectedVoxelCellArrays.end() ) { f1 = reinterpret_cast<float*>(ebsdReader->getPointerByName(Ebsd::Mic::Confidence)); fArray = FloatArrayType::CreateArray(totalPoints, Ebsd::Mic::Confidence); fArray->SetNumberOfComponents(1); ::memcpy(fArray->GetPointer(0), f1, sizeof(float) * totalPoints); m->addCellData(Ebsd::Mic::Confidence, fArray); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AvizoRectilinearCoordinateWriter::execute() { int err = 0; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path std::string parentPath = MXAFileInfo::parentPath(m_OutputFile); if(!MXADir::mkdir(parentPath, true)) { std::stringstream ss; ss << "Error creating parent path '" << parentPath << "'"; notifyErrorMessage(ss.str(), -1); setErrorCondition(-1); return; } int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); size_t totalEnsembleTuples = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, totalFields, totalEnsembleTuples); MXAFileWriter64 writer(m_OutputFile); if(false == writer.initWriter()) { std::stringstream ss; ss << "Error opening file '" << parentPath << "'"; notifyErrorMessage(ss.str(), -1); setErrorCondition(-1); return; } std::string header = generateHeader(); writer.writeString(header); err = writeData(writer); /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int VoxelDataContainerWriter::writeFaceData(hid_t dcGid) { std::stringstream ss; int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); // Write the Voxel Data err = H5Utilities::createGroupsFromPath(H5_FACE_DATA_GROUP_NAME, dcGid); if(err < 0) { ss.str(""); ss << "Error creating HDF Group " << H5_FACE_DATA_GROUP_NAME << std::endl; setErrorCondition(-63); notifyErrorMessage( ss.str(), err); H5Gclose(dcGid); // Close the Data Container Group return err; } hid_t FaceGroupId = H5Gopen(dcGid, H5_FACE_DATA_GROUP_NAME, H5P_DEFAULT); if(err < 0) { ss.str(""); ss << "Error writing string attribute to HDF Group " << H5_FACE_DATA_GROUP_NAME << std::endl; setErrorCondition(-64); notifyErrorMessage( ss.str(), err); H5Gclose(dcGid); // Close the Data Container Group return err; } NameListType names = m->getFaceArrayNameList(); for (NameListType::iterator iter = names.begin(); iter != names.end(); ++iter) { ss.str(""); ss << "Writing Face Data '" << *iter << "' to HDF5 File" << std::endl; notifyStatusMessage(ss.str()); IDataArray::Pointer array = m->getFaceData(*iter); err = array->writeH5Data(FaceGroupId); if(err < 0) { ss.str(""); ss << "Error writing array '" << *iter << "' to the HDF5 File"; notifyErrorMessage( ss.str(), err); setErrorCondition(err); H5Gclose(FaceGroupId); // Close the Face Group H5Gclose(dcGid); // Close the Data Container Group return err; } } H5Gclose(FaceGroupId); // Close the Face Group return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 UpdateCellQuats::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); std::stringstream ss; int64_t totalPoints = m->getTotalPoints(); //getting the 5 component quaternions from the data container and down-casting them IDataArray::Pointer Quats5 = m->getCellData(DREAM3D::CellData::Quats); if(Quats5->GetNumberOfComponents() != 5) { notifyErrorMessage("The Quats array did not contain 5 components", -999); return; } DataArray<float>* quats5 = DataArray<float>::SafePointerDownCast(Quats5.get()); float* quats5ptr = quats5->GetPointer(0); //creating the 4 component quaternions in the data container CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, Quats, ss, float, FloatArrayType, 0, totalPoints, 4) if (getErrorCondition() < 0) { return; } //copying the 5 component quaternions into the new 4 component quaternions // This is a special case for dealing with this conversion. If you are dealing with // quaternions then DO NOT USE THIS CODE as an example. Use another filter instead. for (int i = 0; i < totalPoints; i++) { for(int j=0;j<4;j++) { m_Quats[4*i+j] = quats5ptr[5*i+(j+1)]; } } notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindAxisODF::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); int err = 0; GET_PREREQ_DATA(m, DREAM3D, FieldData, AxisEulerAngles, ss, -301, float, FloatArrayType, fields, 3) TEST_PREREQ_DATA(m, DREAM3D, FieldData, SurfaceFields, err, -302, bool, BoolArrayType, fields, 1) if(err == -302) { setErrorCondition(0); FindSurfaceGrains::Pointer find_surfacefields = FindSurfaceGrains::New(); find_surfacefields->setObservers(this->getObservers()); find_surfacefields->setVoxelDataContainer(getVoxelDataContainer()); if(preflight == true) find_surfacefields->preflight(); if(preflight == false) find_surfacefields->execute(); } GET_PREREQ_DATA(m, DREAM3D, FieldData, SurfaceFields, ss, -302, bool, BoolArrayType, fields, 1) err = 0; TEST_PREREQ_DATA(m, DREAM3D, FieldData, FieldPhases, err, -303, int32_t, Int32ArrayType, fields, 1) if(err == -303) { setErrorCondition(0); FindGrainPhases::Pointer find_grainphases = FindGrainPhases::New(); find_grainphases->setObservers(this->getObservers()); find_grainphases->setVoxelDataContainer(getVoxelDataContainer()); if(preflight == true) find_grainphases->preflight(); if(preflight == false) find_grainphases->execute(); } GET_PREREQ_DATA(m, DREAM3D, FieldData, FieldPhases, ss, -303, int32_t, Int32ArrayType, fields, 1) typedef DataArray<unsigned int> PhaseTypeArrayType; GET_PREREQ_DATA(m, DREAM3D, EnsembleData, PhaseTypes, ss, -307, unsigned int, PhaseTypeArrayType, ensembles, 1) m_StatsDataArray = StatsDataArray::SafeObjectDownCast<IDataArray*, StatsDataArray*>(m->getEnsembleData(DREAM3D::EnsembleData::Statistics).get()); if(m_StatsDataArray == NULL) { StatsDataArray::Pointer p = StatsDataArray::New(); m_StatsDataArray = p.get(); m_StatsDataArray->fillArrayWithNewStatsData(ensembles, m_PhaseTypes); m->addEnsembleData(DREAM3D::EnsembleData::Statistics, p); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void RotateEulerRefFrame::execute() { VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); int64_t totalPoints = m->getTotalPoints(); size_t numgrains = m->getNumFieldTuples(); size_t numensembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, numgrains, numensembles); if (getErrorCondition() < 0) { return; } #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(0, totalPoints), RotateEulerRefFrameImpl(m_CellEulerAngles, m_RotationAngle, m_RotationAxis), tbb::auto_partitioner()); } else #endif { RotateEulerRefFrameImpl serial(m_CellEulerAngles, m_RotationAngle, m_RotationAxis); serial.convert(0, totalPoints); } notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindCellQuats::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); std::stringstream ss; int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); size_t totalEnsembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, totalFields, totalEnsembles); if (getErrorCondition() < 0) { return; } QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); QuatF qr; int phase = -1; for (int i = 0; i < totalPoints; i++) { phase = m_CellPhases[i]; OrientationMath::EulertoQuat(qr, m_CellEulerAngles[3 * i], m_CellEulerAngles[3 * i + 1], m_CellEulerAngles[3 * i + 2]); QuaternionMathF::UnitQuaternion(qr); if (m_CrystalStructures[phase] == Ebsd::CrystalStructure::UnknownCrystalStructure) { QuaternionMathF::Identity(qr); } QuaternionMathF::Copy(qr, quats[i]); } notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void PerPhaseMinSize::remove_smallgrains() { VoxelDataContainer* m = getVoxelDataContainer(); int64_t totalPoints = m->getTotalPoints(); bool good = false; int gnum; int numgrains = m->getNumFieldTuples(); std::vector<int> voxcounts; voxcounts.resize(numgrains,0); for (int64_t i = 0; i < totalPoints; i++) { gnum = m_GrainIds[i]; if(gnum >= 0) voxcounts[gnum]++; } for (size_t i = 1; i < static_cast<size_t>(numgrains); i++) { m_Active[i] = true; if(voxcounts[i] >= getMinAllowedGrainSize() || m_FieldPhases[i] != m_PhaseNumber) good = true; } if(good == false) { setErrorCondition(-1); notifyErrorMessage("The minimum size is larger than the largest Field. All Fields would be removed. The filter has quit.", -1); return; } for (int64_t i = 0; i < totalPoints; i++) { gnum = m_GrainIds[i]; if(voxcounts[gnum] < getMinAllowedGrainSize() && m_CellPhases[i] == m_PhaseNumber && gnum > 0) { m_GrainIds[i] = -1; m_Active[gnum] = false; } } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFieldMapToCellArray::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); IDataArray::Pointer data = m->getCellData(m_SelectedCellDataArrayName); if (NULL == data.get()) { ss.str(""); ss << "Selected array '" << m_SelectedCellDataArrayName << "' does not exist in the Voxel Data Container. Was it spelled correctly?"; setErrorCondition(-11001); addErrorMessage(getHumanLabel(),ss.str(),getErrorCondition()); return; } std::string dType = data->getTypeAsString(); IDataArray::Pointer p = IDataArray::NullPointer(); if (dType.compare("int32_t") == 0) { DataArray<int32_t>* field = DataArray<int32_t>::SafePointerDownCast(data.get()); m_SelectedCellData = field->GetPointer(0); } else { ss.str(""); ss << "Selected array '" << m_SelectedCellDataArrayName << "' is not an Integer array. Is this the array you want to use?"; setErrorCondition(-11001); addErrorMessage(getHumanLabel(),ss.str(),getErrorCondition()); return; } m->clearFieldData(); BoolArrayType::Pointer active = BoolArrayType::CreateArray(fields, 1, DREAM3D::FieldData::Active); // bool* mActive = m_Active->GetPointer(0); m->addFieldData(DREAM3D::FieldData::Active, active); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ClearData::execute() { int err = 0; setErrorCondition(err); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); dataCheck(false, m->getTotalPoints(), m->getNumFieldTuples(), m->getNumEnsembleTuples()); if(getErrorCondition() < 0) { return; } size_t udims[3] = { 0, 0, 0 }; m->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]), }; int index; std::list<std::string> voxelArrayNames = m->getCellArrayNameList(); for (int k = m_ZMin; k < m_ZMax+1; k++) { for (int j = m_YMin; j < m_YMax+1; j++) { for (int i = m_XMin; i < m_XMax+1; i++) { index = (k * dims[0] * dims[1]) + (j * dims[0]) + i; for (std::list<std::string>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { std::string name = *iter; IDataArray::Pointer p = m->getCellData(*iter); p->InitializeTuple(index,0); } } } } notifyStatusMessage("Completed"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ConvertData::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); IDataArray::Pointer iArray = m->getCellData(m_SelectedCellArrayName); bool completed = false; // UInt8ArrayType* uint8Ptr = UInt8ArrayType::SafePointerDownCast(iArray.get()); // if (uint8Ptr != NULL) // { // Detail::ConvertData<UInt8ArrayType>(uint8Ptr, m, m_ScalarType); // } CHECK_AND_CONVERT(UInt8ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(Int8ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(UInt16ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(Int16ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(UInt32ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(Int32ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(UInt64ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(Int64ArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(FloatArrayType, m, m_ScalarType, iArray, m_OutputArrayName) CHECK_AND_CONVERT(DoubleArrayType, m, m_ScalarType, iArray, m_OutputArrayName) /* Let the GUI know we are done with this filter */ notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void LinkFieldMapToCellArray::execute() { VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); int64_t voxels = m->getTotalPoints(); int64_t fields = m->getNumFieldTuples(); dataCheck(false, voxels, fields, m->getNumEnsembleTuples()); if (getErrorCondition() < 0) { return; } //int err = 0; std::stringstream ss; m->clearFieldData(); int maxIndex = 0; std::vector<bool> active; for(int64_t i=0;i<voxels;i++) { int index = m_SelectedCellData[i]; if((index+1) > maxIndex) { active.resize(index+1); active[index] = true; maxIndex = index+1; } } BoolArrayType::Pointer m_Active = BoolArrayType::CreateArray(maxIndex, 1, DREAM3D::FieldData::Active); bool* mActive = m_Active->GetPointer(0); for(int i=0;i<maxIndex;i++) { mActive[i] = active[i]; } m->addFieldData(DREAM3D::FieldData::Active, m_Active); notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int DxReader::readFile() { std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if (NULL == m) { ss.clear(); ss << "DataContainer Pointer was NULL and Must be valid." << __FILE__ << "("<<__LINE__<<")"; addErrorMessage(getHumanLabel(), ss.str(), -5); setErrorCondition(-5); return -1; } std::string delimeters(", ;\t"); /* delimeters to split the data */ std::vector<std::string> tokens; /* vector to store the split data */ int error, spin; /* dummy variables */ bool finished_header, finished_data; finished_header = true; finished_data = false; size_t index = 0; size_t totalPoints = m->getTotalPoints(); // Remove the array that we are about to create first as a 'datacheck()' was called from the super class's 'execute' // method which is performed before this function. This will cause an error -501 because the array with the name // m_GrainIdsArrayName already exists but of size 1, not the size we are going to read. So we get rid of the array m->removeCellData(m_GrainIdsArrayName); // Rerun the data check in order to allocate the array to store the data from the .dx file. // dataCheck(false, totalPoints, m->getNumFieldTuples(), m->getNumEnsembleTuples()); CREATE_NON_PREREQ_DATA(m, DREAM3D, CellData, GrainIds, ss, int32_t, Int32ArrayType, 0, totalPoints, 1) if (getErrorCondition() < 0) { m_InStream.close(); return -1; } for (std::string line; std::getline(m_InStream, line);) { // Get the remaining lines of the header and ignore tokens.clear(); error = 0; tokenize(line, tokens, delimeters); size_t total = m->getTotalPoints(); if( index == total || ( finished_header && tokens.size() != 0 && tokens[0] == "attribute") ) { finished_data = true; } // Allocate the DataArray at this point: if(finished_header && !finished_data) { for (size_t in_spins = 0; in_spins < tokens.size(); in_spins++) { error += sscanf(tokens[in_spins].c_str(), "%d", &spin); m_GrainIds[index] = spin; ++index; } } } if(index != static_cast<size_t>(m->getTotalPoints())) { ss.clear(); ss << "ERROR: data size does not match header dimensions" << std::endl; ss << "\t" << index << "\t" << m->getTotalPoints() << std::endl; setErrorCondition(-495); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); m_InStream.close(); return getErrorCondition(); } tokens.clear(); m_InStream.close(); // Find the unique set of grain ids // std::set<int32_t> grainIdSet; // for (int64_t i = 0; i < totalPoints; ++i) // { // grainIdSet.insert(m_GrainIds[i]); // } // for (std::set<int32_t>::iterator iter = grainIdSet.begin(); iter != grainIdSet.end(); ++iter ) // { // std::cout << "Grain ID: " << (*iter) << std::endl; // } notifyStatusMessage("Complete"); return 0; }
//----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- 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 CropVolumePipeline::execute() { VoxelDataContainer* m = getVoxelDataContainer(); float m_MisorientationTolerance = 5.0f; float m_AlignMisorientationTolerance = 5.0f; float m_Zres = 4.0f; int m_MinAllowedGrainSize = 10; int m_MinNumNeighbors = 1; int m_PhaseNumberMinSize = 1; int m_NumIterations_Erode = 3; int NUM_OF_CROPS = getNumLinesinFile(m_InputFile); std::vector<int> m_Xmin(NUM_OF_CROPS+1, 0); std::vector<int> m_Ymin(NUM_OF_CROPS+1, 0); std::vector<int> m_Zmin(NUM_OF_CROPS+1, 0); std::vector<int> m_Xmax(NUM_OF_CROPS+1, 0); std::vector<int> m_Ymax(NUM_OF_CROPS+1, 0); std::vector<int> m_Zmax(NUM_OF_CROPS+1, 0); get_max_and_min_xyz_for_crop(m_Xmax, m_Ymax, m_Zmax, m_Xmin, m_Ymin, m_Zmin); /* int m_Zmin = 1 ; int m_Xmax = 495; int m_Ymax = 355; int m_Zmax = 163;*/ for (DimType i = 1; i < NUM_OF_CROPS+1; i++) { // Create our Pipeline object FilterPipeline::Pointer pipeline = FilterPipeline::New(); // updateProgressAndMessage(("Loading Slices"), 10); ReadH5Ebsd::Pointer read_h5ebsd = ReadH5Ebsd::New(); read_h5ebsd->setH5EbsdFile(getH5EbsdFile()); //read_h5ebsd->setRefFrameZDir(Ebsd::LowtoHigh); read_h5ebsd->setZStartIndex(getZStartIndex()); read_h5ebsd->setZEndIndex(getZEndIndex()); read_h5ebsd->setPTypes(getPhaseTypes()); read_h5ebsd->setQualityMetricFilters(getQualityMetricFilters()); read_h5ebsd->setVoxelDataContainer(m); read_h5ebsd->execute(); pipeline->pushBack(read_h5ebsd); ConvertEulerAngles::Pointer convert_euler = ConvertEulerAngles::New(); convert_euler->setConversionType(DREAM3D::EulerAngleConversionType::DegreesToRadians); convert_euler->setVoxelDataContainer(m); convert_euler->execute(); pipeline->pushBack(convert_euler); AlignSectionsMisorientation::Pointer align_sections = AlignSectionsMisorientation::New(); align_sections->setMisorientationTolerance(m_AlignMisorientationTolerance); align_sections->setVoxelDataContainer(m); align_sections->execute(); pipeline->pushBack(align_sections); CropVolume::Pointer crop_volume = CropVolume::New(); crop_volume->setXMin(m_Xmin[i]); crop_volume->setYMin(m_Ymin[i]); crop_volume->setZMin(m_Zmin[i]); crop_volume->setXMax(m_Xmax[i]); crop_volume->setYMax(m_Ymax[i]); crop_volume->setZMax(m_Zmax[i]); crop_volume->setRenumberGrains(false); crop_volume->setVoxelDataContainer(m); crop_volume->execute(); pipeline->pushBack(crop_volume); RegularizeZSpacing::Pointer regularize_z = RegularizeZSpacing::New(); regularize_z->setInputFile(getZ_spacingfile()); regularize_z->setZRes(m_Zres); regularize_z->setVoxelDataContainer(m); regularize_z->execute(); pipeline->pushBack(regularize_z); EBSDSegmentGrains::Pointer ebsdsegment_grains = EBSDSegmentGrains::New(); ebsdsegment_grains->setMisorientationTolerance(m_MisorientationTolerance); ebsdsegment_grains->setVoxelDataContainer(m); ebsdsegment_grains->execute(); pipeline->pushBack(ebsdsegment_grains); OpenCloseBadData::Pointer erode_dilate = OpenCloseBadData::New(); erode_dilate->setDirection(1); // 1 is erode. erode_dilate->setNumIterations(m_NumIterations_Erode); erode_dilate->setVoxelDataContainer(m); erode_dilate->execute(); pipeline->pushBack(erode_dilate); FindNeighbors::Pointer find_neighbors = FindNeighbors::New(); find_neighbors->setVoxelDataContainer(m); find_neighbors->execute(); pipeline->pushBack(find_neighbors); PerPhaseMinSize::Pointer min_size = PerPhaseMinSize::New(); min_size->setMinAllowedGrainSize(m_MinAllowedGrainSize); min_size->setPhaseNumber(m_PhaseNumberMinSize); min_size->setVoxelDataContainer(m); min_size->execute(); pipeline->pushBack(min_size); MinNeighbors::Pointer min_neighbors = MinNeighbors::New(); min_neighbors->setMinNumNeighbors(m_MinNumNeighbors); min_neighbors->setVoxelDataContainer(m); min_neighbors->execute(); pipeline->pushBack(min_neighbors); FindSizes::Pointer find_sizes = FindSizes::New(); //find_sizes->setDistributionType(DREAM3D::DistributionType::Beta); find_sizes->setVoxelDataContainer(m); find_sizes->execute(); pipeline->pushBack(find_sizes); FindShapes::Pointer find_shapes = FindShapes::New(); //find_shapes->setDistributionType(DREAM3D::DistributionType::Beta); find_shapes->setVoxelDataContainer(m); find_shapes->execute(); pipeline->pushBack(find_shapes); FieldDataCSVWriter::Pointer field_data_write_csv = FieldDataCSVWriter::New(); std::string field_csv = "D:/IN100_run1/DREAM3D_files/crop_line_"+ convertIntToString(i) +".csv"; field_data_write_csv->setFieldDataFile(field_csv); field_data_write_csv->setVoxelDataContainer(m); field_data_write_csv->execute(); pipeline->pushBack(field_data_write_csv); bool m_WriteVtkFile = true ; bool m_WriteBinaryVTKFiles= true ; bool m_WriteGrainID= true; bool m_WritePhaseId= true ; bool m_WriteIPFColor= true ; bool m_WriteGoodVoxels= true ; bool m_WriteGrainSizes = true ; bool m_WriteBandContrasts = true ; VtkRectilinearGridWriter::Pointer vtkWriter = VtkRectilinearGridWriter::New(); if(m_WriteVtkFile) { std::string vtk_file = "D:/IN100_run1/DREAM3D_files/crop_line_" + convertIntToString(i) + ".vtk"; vtkWriter->setOutputFile(vtk_file); vtkWriter->setWriteGrainIds(m_WriteGrainID); vtkWriter->setWritePhaseIds(m_WritePhaseId); vtkWriter->setWriteBandContrasts(m_WriteBandContrasts); vtkWriter->setWriteGoodVoxels(m_WriteGoodVoxels); vtkWriter->setWriteIPFColors(m_WriteIPFColor); vtkWriter->setWriteBinaryFile(m_WriteBinaryVTKFiles); vtkWriter->setWriteBinaryFile(m_WriteGrainSizes); vtkWriter->setVoxelDataContainer(m); vtkWriter->execute(); pipeline->pushBack(vtkWriter); } DataContainerWriter::Pointer writer = DataContainerWriter::New(); std::string dream_3d_file = "D:/IN100_run1/DREAM3D_files/crop_line_" + convertIntToString(i) + ".dream3d"; writer->setOutputFile(dream_3d_file); writer->setVoxelDataContainer(m); pipeline->pushBack(writer); writer->execute(); // std::cout << "********* RUNNING PIPELINE **********************" << std::endl; // // pipeline->run(); pipeline->clear(); //delete [] m; m->clearCellData(); m->clearEnsembleData(); m->clearFieldData(); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void IdentifySample::execute() { setErrorCondition(0); // int err = 0; VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } int64_t totalPoints = m->getTotalPoints(); dataCheck(false, totalPoints, m->getNumFieldTuples(), m->getNumEnsembleTuples()); if (getErrorCondition() < 0 && getErrorCondition() != -305) { return; } setErrorCondition(0); size_t udims[3] = {0,0,0}; m->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 neighpoints[6]; DimType xp = dims[0]; DimType yp = dims[1]; DimType zp = dims[2]; neighpoints[0] = -(xp * yp); neighpoints[1] = -xp; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = xp; neighpoints[5] = (xp * yp); std::vector<int> currentvlist; std::vector<bool> checked; checked.resize(totalPoints,false); std::vector<bool> Sample; Sample.resize(totalPoints,false); std::vector<bool> notSample; notSample.resize(totalPoints,false); int biggestBlock = 0; size_t count; int good; int neighbor; DimType column, row, plane; int index; for (int i = 0; i < totalPoints; i++) { if(checked[i] == false && m_GoodVoxels[i] == false) { currentvlist.push_back(i); count = 0; while (count < currentvlist.size()) { index = currentvlist[count]; column = index % xp; row = (index / xp) % yp; plane = index / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( index + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && checked[neighbor] == false && m_GoodVoxels[neighbor] == false) { currentvlist.push_back(neighbor); checked[neighbor] = true; } } count++; } if(static_cast<int>(currentvlist.size()) >= biggestBlock) { biggestBlock = currentvlist.size(); for(int j = 0; j < totalPoints; j++) { notSample[j] = false; } for(size_t j = 0; j < currentvlist.size(); j++) { notSample[currentvlist[j]] = true; } } currentvlist.clear(); } } for (int i = 0; i < totalPoints; i++) { if (notSample[i] == false && m_GoodVoxels[i] == false) m_GoodVoxels[i] = true; else if (notSample[i] == true && m_GoodVoxels[i] == true) m_GoodVoxels[i] = false; } notSample.clear(); checked.clear(); biggestBlock = 0; checked.resize(totalPoints,false); for (int i = 0; i < totalPoints; i++) { if(checked[i] == false && m_GoodVoxels[i] == true) { currentvlist.push_back(i); count = 0; while (count < currentvlist.size()) { index = currentvlist[count]; column = index % xp; row = (index / xp) % yp; plane = index / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( index + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && checked[neighbor] == false && m_GoodVoxels[neighbor] == true) { currentvlist.push_back(neighbor); checked[neighbor] = true; } } count++; } if(static_cast<int>(currentvlist.size()) >= biggestBlock) { biggestBlock = currentvlist.size(); for(int j = 0; j < totalPoints; j++) { Sample[j] = false; } for(size_t j = 0; j < currentvlist.size(); j++) { Sample[currentvlist[j]] = true; } } currentvlist.clear(); } } for (int i = 0; i < totalPoints; i++) { if (Sample[i] == false && m_GoodVoxels[i] == true) m_GoodVoxels[i] = false; else if (Sample[i] == true && m_GoodVoxels[i] == false) m_GoodVoxels[i] = true; } Sample.clear(); checked.clear(); /* std::vector<bool> change; change.resize(totalPoints,false); for (int i = 0; i < totalPoints; i++) { if(m_GoodVoxels[i] == false) { column = i % xp; row = (i / xp) % yp; plane = i / (xp * yp); for (int j = 0; j < 6; j++) { good = 1; neighbor = static_cast<int>( i + neighpoints[j] ); if(j == 0 && plane == 0) good = 0; if(j == 5 && plane == (zp - 1)) good = 0; if(j == 1 && row == 0) good = 0; if(j == 4 && row == (yp - 1)) good = 0; if(j == 2 && column == 0) good = 0; if(j == 3 && column == (xp - 1)) good = 0; if(good == 1 && m_GoodVoxels[neighbor] == true) { change[i] = true; } } } } for(int j = 0; j < totalPoints; j++) { if(change[j] == true) m_GoodVoxels[j] = true; } change.clear(); */ // If there is an error set this to something negative and also set a message notifyStatusMessage("Identifying Sample Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SegmentGrains::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); std::stringstream ss; if(NULL == m) { setErrorCondition(-1); ss << " DataContainer was NULL"; addErrorMessage(getHumanLabel(), ss.str(), -1); return; } size_t udims[3] = { 0, 0, 0 }; m->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]), }; size_t gnum = 1; int seed = 0; int neighbor; bool good = 0; DimType col, row, plane; size_t size = 0; size_t initialVoxelsListSize = 1000; std::vector<int> voxelslist(initialVoxelsListSize, -1); DimType neighpoints[6]; neighpoints[0] = -(dims[0] * dims[1]); neighpoints[1] = -dims[0]; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = dims[0]; neighpoints[5] = (dims[0] * dims[1]); // Burn volume with tight orientation tolerance to simulate simultaneous growth/aglomeration while (seed >= 0) { seed = getSeed(gnum); if(seed >= 0) { size = 0; voxelslist[size] = seed; size++; for (size_t j = 0; j < size; ++j) { // Get the current Voxel size_t currentpoint = voxelslist[j]; // Figure out the Row, Col & Plane the voxel is located in col = currentpoint % dims[0]; row = (currentpoint / dims[0]) % dims[1]; plane = currentpoint / (dims[0] * dims[1]); // Now loop over its 6 neighbors for (int i = 0; i < 6; i++) { good = true; neighbor = currentpoint + neighpoints[i]; // Make sure we have a valid neighbor taking into account the edges of the volume if(i == 0 && plane == 0) good = false; if(i == 5 && plane == (dims[2] - 1)) good = false; if(i == 1 && row == 0) good = false; if(i == 4 && row == (dims[1] - 1)) good = false; if(i == 2 && col == 0) good = false; if(i == 3 && col == (dims[0] - 1)) good = false; if(good == true) { // We got a good voxel to check so check to see if it can be grouped with this point if(determineGrouping(currentpoint, neighbor, gnum) == true) { // The voxel can be grouped with this voxel so add it to the list of voxels for this grain voxelslist[size] = neighbor; // Increment the size of the list which affects the "j" loop size++; // Sanity check the size of the voxelslist vector. If it is not large enough, double the size of the vector if(size >= voxelslist.size()) { voxelslist.resize(size + size, -1); // The resize is a hit but the doubling mitigates the penalty somewhat } } } } } voxelslist.clear(); voxelslist.resize(initialVoxelsListSize, -1); gnum++; ss.str(""); ss << "Total Grains: " << gnum; if(gnum%100 == 0) notifyStatusMessage(ss.str()); if (getCancel() == true) { setErrorCondition(-1); break; } } } // If there is an error set this to something negative and also set a message notifyStatusMessage("Completed"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ClearData::dataCheck(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; VoxelDataContainer* m = getVoxelDataContainer(); if (getXMax() < getXMin()) { ss.str(""); ss << "X Max (" << getXMax() << ") less than X Min (" << getXMin() << ")"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getYMax() < getYMin()) { ss.str(""); ss << "Y Max (" << getYMax() << ") less than Y Min (" << getYMin() << ")"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getZMax() < getZMin()) { ss.str(""); ss << "Z Max (" << getZMax() << ") less than Z Min (" << getZMin() << ")"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getXMin() < 0) { ss.str(""); ss << "X Min (" << getXMin() << ") less than 0"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getYMin() < 0) { ss.str(""); ss << "Y Min (" << getYMin() << ") less than 0"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getZMin() < 0) { ss.str(""); ss <<"Z Min (" << getZMin() << ") less than 0"; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getXMax() > (static_cast<int64_t>(m->getXPoints())-1)) { ss.str(""); ss << "The X Max you entered of " << getXMax() << " is greater than your Max X Point of " << static_cast<int64_t>(m->getXPoints())-1; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5555); } if (getYMax() > (static_cast<int64_t>(m->getYPoints())-1)) { ss.str(""); ss << "The Y Max you entered of " << getYMax() << " is greater than your Max Y Point of " << static_cast<int64_t>(m->getYPoints())-1; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5556); } if (getZMax() > (static_cast<int64_t>(m->getZPoints())-1)) { ss.str(""); ss << "The Z Max you entered of " << getZMax() << ") greater than your Max Z Point of " << static_cast<int64_t>(m->getZPoints())-1; addErrorMessage(getHumanLabel(), ss.str(), -5555); setErrorCondition(-5557); } }