// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MultiOtsuThreshold::execute() { //int err = 0; dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //get dims size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->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]), }; //wrap input as itk image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); if(m_Slice) { //define 2d histogram generator typedef itk::OtsuMultipleThresholdsImageFilter< ImageProcessing::DefaultSliceType, ImageProcessing::DefaultSliceType > ThresholdType; ThresholdType::Pointer otsuThresholder = ThresholdType::New(); //wrap output buffer as image ImageProcessing::DefaultImageType::Pointer outputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_NewCellArray); //loop over slices for(int i = 0; i < dims[2]; i++) { //get slice ImageProcessing::DefaultSliceType::Pointer slice = ITKUtilitiesType::ExtractSlice(inputImage, ImageProcessing::ZSlice, i); //threshold otsuThresholder->SetInput(slice); otsuThresholder->SetNumberOfThresholds(m_Levels); otsuThresholder->SetLabelOffset(1); //execute filters try { otsuThresholder->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::OtsuMultipleThresholdsImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } //copy back into volume ITKUtilitiesType::SetSlice(outputImage, otsuThresholder->GetOutput(), ImageProcessing::ZSlice, i); } } else { typedef itk::OtsuMultipleThresholdsImageFilter< ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType > ThresholdType; ThresholdType::Pointer otsuThresholder = ThresholdType::New(); otsuThresholder->SetInput(inputImage); otsuThresholder->SetNumberOfThresholds(m_Levels); otsuThresholder->SetLabelOffset(1); ITKUtilitiesType::SetITKFilterOutput(otsuThresholder->GetOutput(), m_NewCellArrayPtr.lock()); //execute filters try { otsuThresholder->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::OtsuMultipleThresholdsImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } } //array name changing/cleanup if(m_SaveAsNewArray == false) { AttributeMatrix::Pointer attrMat = m->getAttributeMatrix(m_SelectedCellArrayPath.getAttributeMatrixName()); attrMat->removeAttributeArray(m_SelectedCellArrayPath.getDataArrayName()); attrMat->renameAttributeArray(m_NewCellArrayName, m_SelectedCellArrayPath.getDataArrayName()); } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CopyFeatureArrayToElementArray::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Validate that the selected InArray has tuples equal to the largest // Feature Id; the filter would not crash otherwise, but the user should // be notified of unanticipated behavior ; this cannot be done in the dataCheck since // we don't have acces to the data yet int32_t numFeatures = static_cast<int32_t>(m_InArrayPtr.lock()->getNumberOfTuples()); bool mismatchedFeatures = false; int32_t largestFeature = 0; size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); for (size_t i = 0; i < totalPoints; i ++) { if (m_FeatureIds[i] > largestFeature) { largestFeature = m_FeatureIds[i]; if (largestFeature >= numFeatures) { mismatchedFeatures = true; break; } } } if (mismatchedFeatures == true) { QString ss = QObject::tr("The number of Features in the InArray array (%1) is larger than the largest Feature Id in the FeatureIds array").arg(numFeatures); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (largestFeature != (numFeatures - 1)) { QString ss = QObject::tr("The number of Features in the InArray array (%1) does not match the largest Feature Id in the FeatureIds array").arg(numFeatures); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } IDataArray::Pointer p = IDataArray::NullPointer(); if (TemplateHelpers::CanDynamicCast<Int8ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt8ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint8_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int16ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt16ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint16_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int32ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt32ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint32_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<Int64ArrayType>()(m_InArrayPtr.lock())) { p = copyData<int64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<UInt64ArrayType>()(m_InArrayPtr.lock())) { p = copyData<uint64_t>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<FloatArrayType>()(m_InArrayPtr.lock())) { p = copyData<float>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<DoubleArrayType>()(m_InArrayPtr.lock())) { p = copyData<double>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else if (TemplateHelpers::CanDynamicCast<BoolArrayType>()(m_InArrayPtr.lock())) { p = copyData<bool>(m_InArrayPtr.lock(), totalPoints, m_FeatureIds); } else { QString ss = QObject::tr("The selected array was of unsupported type. The path is %1").arg(m_SelectedFeatureArrayPath.serialize()); setErrorCondition(-14000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (p.get() != NULL) { p->setName(getCreatedArrayName()); AttributeMatrix::Pointer am = getDataContainerArray()->getAttributeMatrix(getFeatureIdsArrayPath()); am->addAttributeArray(p->getName(), p); } notifyStatusMessage(getHumanLabel(), "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"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t LosAlamosFFTWriter::writeFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName()); int32_t err = 0; size_t dims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(dims); float res[3] = { 0.0f, 0.0f, 0.0f }; m->getGeometryAs<ImageGeom>()->getResolution(res); float origin[3] = { 0.0f, 0.0f, 0.0f }; m->getGeometryAs<ImageGeom>()->getOrigin(origin); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputFile()); QDir parentPath(fi.path()); if (!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } FILE* f = fopen(getOutputFile().toLatin1().data(), "wb"); if (NULL == f) { QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } float phi1 = 0.0f, phi = 0.0f, phi2 = 0.0f; int32_t featureId = 0; int32_t phaseId = 0; size_t index = 0; for (size_t z = 0; z < dims[2]; ++z) { for (size_t y = 0; y < dims[1]; ++y) { for (size_t x = 0; x < dims[0]; ++x) { index = (z * dims[0] * dims[1]) + (dims[0] * y) + x; phi1 = m_CellEulerAngles[index * 3] * 180.0 * SIMPLib::Constants::k_1OverPi; phi = m_CellEulerAngles[index * 3 + 1] * 180.0 * SIMPLib::Constants::k_1OverPi; phi2 = m_CellEulerAngles[index * 3 + 2] * 180.0 * SIMPLib::Constants::k_1OverPi; featureId = m_FeatureIds[index]; phaseId = m_CellPhases[index]; fprintf(f, "%.3f %.3f %.3f %lu %lu %lu %d %d\n", phi1, phi, phi2, x + 1, y + 1, z + 1, featureId, phaseId); } } } fclose(f); notifyStatusMessage(getHumanLabel(), "Complete"); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AbaqusSurfaceMeshWriter::execute() { int32_t err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputFile()); QDir parentPath = fi.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); setErrorCondition(-8005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>(); // Store all the unique Spins std::set<int32_t> uniqueSpins; for (int64_t i = 0; i < triangleGeom->getNumberOfTris(); i++) { uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2]); uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2 + 1]); } FILE* f = fopen(m_OutputFile.toLatin1().data(), "wb"); ScopedFileMonitor fileMonitor(f); err = writeHeader(f, triangleGeom->getNumberOfVertices(), triangleGeom->getNumberOfTris(), uniqueSpins.size() - 1); if(err < 0) { QString ss = QObject::tr("Error writing header for file '%1'").arg(m_OutputFile); setErrorCondition(-8001); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeNodes(f); if(err < 0) { QString ss = QObject::tr("Error writing nodes for file '%1'").arg(m_OutputFile); setErrorCondition(-8002); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeTriangles(f); if(err < 0) { QString ss = QObject::tr("Error writing triangles for file '%1'").arg(m_OutputFile); setErrorCondition(-8003); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } err = writeFeatures(f); if(err < 0) { QString ss = QObject::tr("Error writing Features for file '%1'").arg(m_OutputFile); setErrorCondition(-8004); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VisualizeGBCDGMT::dataCheck() { setErrorCondition(0); initialize(); getDataContainerArray()->getPrereqGeometryFromDataContainer<TriangleGeom, AbstractFilter>(this, getGBCDArrayPath().getDataContainerName()); if (getOutputFile().isEmpty() == true) { QString ss = QObject::tr( "The output file must be set"); setErrorCondition(-1000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } QFileInfo fi(getOutputFile()); QDir parentPath = fi.path(); if (parentPath.exists() == false && getInPreflight()) { QString ss = QObject::tr( "The directory path for the output file does not exist. DREAM.3D will attempt to create this path during execution of the filter"); notifyWarningMessage(getHumanLabel(), ss, -1); } if (fi.suffix().compare("") == 0) { setOutputFile(getOutputFile().append(".dat")); } // Make sure the file name ends with _1 so the GMT scripts work correctly QString fName = fi.baseName(); if (fName.endsWith("_1") == false) { fName = fName + "_1"; QString absPath = fi.absolutePath() + "/" + fName + ".dat"; setOutputFile(absPath); } QVector<size_t> cDims(1, 1); m_CrystalStructuresPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<unsigned int>, AbstractFilter>(this, getCrystalStructuresArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_CrystalStructuresPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ IDataArray::Pointer tmpGBCDPtr = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, getGBCDArrayPath()); if(getErrorCondition() < 0) { return; } if (NULL != tmpGBCDPtr.get()) { QVector<size_t> cDims = tmpGBCDPtr->getComponentDimensions(); m_GBCDPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<double>, AbstractFilter>(this, getGBCDArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_GBCDPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_GBCD = m_GBCDPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ } if (NULL != m_GBCDPtr.lock().get() && getPhaseOfInterest() >= m_GBCDPtr.lock()->getNumberOfTuples()) { QString ss = QObject::tr("The phase index is larger than the number of Ensembles").arg(ClassName()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void WriteStatsGenOdfAngleFile::execute() { int err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } // Figure out how many unique phase values we have by looping over all the phase values int64_t totalPoints = m_CellPhasesPtr.lock()->getNumberOfTuples(); std::set<int32_t> uniquePhases; for (int64_t i = 0; i < totalPoints; i++) { uniquePhases.insert(m_CellPhases[i]); } uniquePhases.erase(0); // remove Phase 0 as this is a Special Phase for DREAM3D std::vector<QFile*> oFiles; QFileInfo fi(getOutputFile()); QString absPath = fi.absolutePath(); QString fname = fi.completeBaseName(); QString suffix = fi.suffix(); for (std::set<int32_t>::iterator iter = uniquePhases.begin(); iter != uniquePhases.end(); iter++) { /* Let the GUI know we are done with this filter */ QString ss = QObject::tr("Writing file for phase '%1'").arg(*iter); notifyStatusMessage(getHumanLabel(), ss); QString absFilePath = absPath + "/" + fname + "_Phase_" + QString::number(*iter) + "." + suffix; QFile file(absFilePath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { setErrorCondition(-99000); QString ss = QObject::tr("Error creating output file '%1'").arg(absFilePath); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QTextStream out(&file); // Dry run to figure out how many lines we are going to have int32_t lineCount = determineOutputLineCount(totalPoints, *iter); int err = writeOutputFile(out, lineCount, totalPoints, *iter); if (err < 0) { setErrorCondition(-99001); QString ss = QObject::tr("Error writing output file '%1'").arg(absFilePath); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } out.flush(); file.close(); // Close the file } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void YSChoiAbaqusReader::dataCheck() { DataArrayPath tempPath; setErrorCondition(0); DataContainer::Pointer m = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getDataContainerName()); if(getErrorCondition() < 0) { return; } ImageGeom::Pointer image = ImageGeom::CreateGeometry(DREAM3D::Geometry::ImageGeometry); m->setGeometry(image); QVector<size_t> tDims(3, 0); AttributeMatrix::Pointer cellAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::Cell); if(getErrorCondition() < 0 || NULL == cellAttrMat.get()) { return; } tDims.resize(1); tDims[0] = 0; AttributeMatrix::Pointer cellFeatureAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellFeatureAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellFeature); if(getErrorCondition() < 0 || NULL == cellFeatureAttrMat.get()) { return; } AttributeMatrix::Pointer cellEnsembleAttrMat = m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellEnsembleAttributeMatrixName(), tDims, DREAM3D::AttributeMatrixType::CellEnsemble); if(getErrorCondition() < 0 || NULL == cellEnsembleAttrMat.get()) { return; } QFileInfo fi(getInputFile()); if (getInputFile().isEmpty() == true) { QString ss = QObject::tr("%1 needs the Input File Set and it was not.").arg(ClassName()); setErrorCondition(-387); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } else if (fi.exists() == false) { QString ss = QObject::tr("The input file does not exist"); setErrorCondition(-388); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } else { bool ok = false; //const unsigned int size(1024); // Read header from data file to figure out how many points there are QFile in(getInputFile()); if (!in.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QObject::tr("Abaqus file could not be opened: %1").arg(getInputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "", getErrorCondition()); return; } QString word; bool headerdone = false; int xpoints, ypoints, zpoints; float resx, resy, resz; while (headerdone == false) { QByteArray buf = in.readLine(); if (buf.startsWith(DIMS)) { QList<QByteArray> tokens = buf.split(' '); xpoints = tokens[1].toInt(&ok, 10); ypoints = tokens[2].toInt(&ok, 10); zpoints = tokens[3].toInt(&ok, 10); size_t dims[3] = { static_cast<size_t>(xpoints), static_cast<size_t>(ypoints), static_cast<size_t>(zpoints) }; m->getGeometryAs<ImageGeom>()->setDimensions(dims); m->getGeometryAs<ImageGeom>()->setOrigin(0, 0, 0); } if (RES == word) { QList<QByteArray> tokens = buf.split(' '); resx = tokens[1].toInt(&ok, 10); resy = tokens[2].toInt(&ok, 10); resz = tokens[3].toInt(&ok, 10); float res[3] = {resx, resy, resz}; m->getGeometryAs<ImageGeom>()->setResolution(res); } } } QVector<size_t> dims(1, 3); tempPath.update(getDataContainerName(), getCellAttributeMatrixName(), getCellEulerAnglesArrayName() ); m_CellEulerAnglesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CellEulerAnglesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CellEulerAngles = m_CellEulerAnglesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 4; tempPath.update(getDataContainerName(), getCellAttributeMatrixName(), getQuatsArrayName() ); m_QuatsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_QuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_Quats = m_QuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(getDataContainerName(), getCellFeatureAttributeMatrixName(), getAvgQuatsArrayName() ); m_AvgQuatsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<float>, AbstractFilter, float>(this, tempPath, 0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_AvgQuatsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_AvgQuats = m_AvgQuatsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ dims[0] = 1; tempPath.update(getDataContainerName(), getCellAttributeMatrixName(), getCellPhasesArrayName() ); m_CellPhasesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 1, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CellPhasesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CellPhases = m_CellPhasesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(getDataContainerName(), getCellFeatureAttributeMatrixName(), getSurfaceFeaturesArrayName() ); m_SurfaceFeaturesPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<bool>, AbstractFilter, bool>(this, tempPath, false, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_SurfaceFeaturesPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SurfaceFeatures = m_SurfaceFeaturesPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ tempPath.update(getDataContainerName(), getCellAttributeMatrixName(), getFeatureIdsArrayName() ); m_FeatureIdsPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_FeatureIdsPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FeatureIds = m_FeatureIdsPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ //typedef DataArray<unsigned int> XTalStructArrayType; tempPath.update(getDataContainerName(), getCellEnsembleAttributeMatrixName(), getCrystalStructuresArrayName() ); m_CrystalStructuresPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<uint32_t>, AbstractFilter, uint32_t>(this, tempPath, Ebsd::CrystalStructure::Cubic_High, dims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if( NULL != m_CrystalStructuresPtr.lock().get() ) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_CrystalStructures = m_CrystalStructuresPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ }
void YSChoiAbaqusReader::execute() { dataCheck(); DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); int xpoints, ypoints, zpoints, totalpoints = 0; float resx, resy, resz; float** *mat = NULL; //const unsigned int size(1024); // Read header from data file to figure out how many points there are QFile in(getInputFile()); if (!in.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QObject::tr("Abaqus file could not be opened: %1").arg(getInputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "", getErrorCondition()); return; } QString word; bool ok = false; bool headerdone = false; while (headerdone == false) { QByteArray buf = in.readLine(); if (buf.startsWith(DIMS)) { QList<QByteArray> tokens = buf.split(' '); xpoints = tokens[1].toInt(&ok, 10); ypoints = tokens[2].toInt(&ok, 10); zpoints = tokens[3].toInt(&ok, 10); totalpoints = xpoints * ypoints * zpoints; size_t dims[3] = { static_cast<size_t>(xpoints), static_cast<size_t>(ypoints), static_cast<size_t>(zpoints) }; m->getGeometryAs<ImageGeom>()->setDimensions(dims); m->getGeometryAs<ImageGeom>()->setOrigin(0, 0, 0); } if (buf.startsWith(RES)) { QList<QByteArray> tokens = buf.split(' '); resx = tokens[1].toInt(&ok, 10); resy = tokens[2].toInt(&ok, 10); resz = tokens[3].toInt(&ok, 10); float res[3] = {resx, resy, resz}; m->getGeometryAs<ImageGeom>()->setResolution(res); } if (buf.startsWith(LOOKUP)) { headerdone = true; word = QString(buf); } } // Read header from grain info file to figure out how many features there are QFile in2(getInputFeatureInfoFile()); if (!in2.open(QIODevice::ReadOnly | QIODevice::Text)) { QString msg = QObject::tr("Abaqus Feature Info file could not be opened: %1").arg(getInputFeatureInfoFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "", getErrorCondition()); return; } int numfeatures; QByteArray buf = in2.readLine(); numfeatures = buf.toInt(&ok, 10); buf = in2.readLine(); QList<QByteArray> tokens = buf.split(' '); // in2 >> word >> word >> word >> word >> word >> word; QVector<size_t> tDims(3, 0); tDims[0] = xpoints; tDims[1] = ypoints; tDims[2] = zpoints; m->getAttributeMatrix(getCellAttributeMatrixName())->resizeAttributeArrays(tDims); tDims.resize(1); tDims[0] = numfeatures + 1; m->getAttributeMatrix(getCellFeatureAttributeMatrixName())->resizeAttributeArrays(tDims); tDims[0] = 2; m->getAttributeMatrix(getCellEnsembleAttributeMatrixName())->resizeAttributeArrays(tDims); updateCellInstancePointers(); updateFeatureInstancePointers(); updateEnsembleInstancePointers(); //Read data file int gnum = 0; bool onedge = false; int col, row, plane; float value; for (int i = 0; i < totalpoints; i++) { mat[i] = new float *[3]; for(int j = 0; j < 3; j++) { mat[i][j] = new float [3]; } onedge = false; gnum = tokens[6].toInt(&ok, 10); col = i % xpoints; row = (i / xpoints) % ypoints; plane = i / (xpoints * ypoints); if (col == 0 || col == (xpoints - 1) || row == 0 || row == (ypoints - 1) || plane == 0 || plane == (zpoints - 1)) { onedge = true; } m_FeatureIds[i] = gnum; m_SurfaceFeatures[gnum] = onedge; } for (int iter1 = 0; iter1 < 3; iter1++) { for (int iter2 = 0; iter2 < 3; iter2++) { headerdone = false; while (headerdone == false) { buf = in2.readLine(); if (buf.startsWith(LOOKUP)) { headerdone = true; //in >> word; } } for (int i = 0; i < totalpoints; i++) { onedge = 0; value = buf.toInt(&ok, 10); mat[i][iter1][iter2] = value; } } } //Read feature info QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); avgQuats[0].x = 0.0; avgQuats[0].y = 0.0; avgQuats[0].z = 0.0; avgQuats[0].w = 0.0; for (int i = 1; i < numfeatures + 1; i++) { buf = in2.readLine(); tokens = buf.split(' '); gnum = tokens[0].toInt(&ok, 10); avgQuats[i].x = tokens[2].toFloat(&ok); avgQuats[i].y = tokens[3].toFloat(&ok); avgQuats[i].z = tokens[4].toFloat(&ok); avgQuats[i].w = tokens[5].toFloat(&ok); } QuatF q; QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float g[3][3]; for(int i = 0; i < (xpoints * ypoints * zpoints); i++) { for(int j = 0; j < 3; j++) { for(int k = 0; k < 3; k++) { g[j][k] = mat[i][j][k]; } } MatrixMath::Normalize3x3(g); q.w = static_cast<float>( sqrt((1.0 + g[0][0] + g[1][1] + g[2][2])) / 2.0 ); q.x = static_cast<float>( (g[1][2] - g[2][1]) / (4.0 * q.w) ); q.y = static_cast<float>( (g[2][0] - g[0][2]) / (4.0 * q.w) ); q.z = static_cast<float>( (g[0][1] - g[1][0]) / (4.0 * q.w) ); QuaternionMathF::Copy(q, quats[i]); FOrientArrayType eu(m_CellEulerAngles + (3 * i), 3); FOrientTransformsType::qu2eu(FOrientArrayType(q), eu); delete[] mat[i]; } delete[] mat; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindBoundaryCells::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); int64_t xPoints = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getXPoints()); int64_t yPoints = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getYPoints()); int64_t zPoints = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getZPoints()); int64_t neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; neighpoints[0] = -xPoints * yPoints; neighpoints[1] = -xPoints; neighpoints[2] = -1; neighpoints[3] = 1; neighpoints[4] = xPoints; neighpoints[5] = xPoints * yPoints; int32_t feature = 0; int32_t onsurf = 0; int32_t good = 0; int64_t neighbor = 0; int64_t zStride = 0, yStride = 0; for (int64_t i = 0; i < zPoints; i++) { zStride = i * xPoints * yPoints; for (int64_t j = 0; j < yPoints; j++) { yStride = j * xPoints; for (int64_t k = 0; k < xPoints; k++) { onsurf = 0; feature = m_FeatureIds[zStride + yStride + k]; if (feature > 0) { for (int64_t l = 0; l < 6; l++) { good = 1; neighbor = zStride + yStride + k + neighpoints[l]; if (l == 0 && i == 0) { good = 0; } if (l == 5 && i == (zPoints - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (yPoints - 1)) { good = 0; } if (l == 2 && k == 0) { good = 0; } if (l == 3 && k == (xPoints - 1)) { good = 0; } if (good == 1 && m_FeatureIds[neighbor] != feature && m_FeatureIds[neighbor] > 0) { onsurf++; } } } m_BoundaryCells[zStride + yStride + k] = onsurf; } } } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindKernelAvgMisorientations::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); QuatF q1 = QuaternionMathF::New(); QuatF q2 = QuaternionMathF::New(); QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); int32_t numVoxel = 0; // number of voxels in the feature... bool good = false; float w = 0.0f, totalmisorientation = 0.0f; float n1 = 0.0f, n2 = 0.0f, n3 = 0.0f; uint32_t phase1 = Ebsd::CrystalStructure::UnknownCrystalStructure; uint32_t phase2 = Ebsd::CrystalStructure::UnknownCrystalStructure; size_t udims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(udims); #if (CMP_SIZEOF_SIZE_T == 4) typedef int32_t DimType; #else typedef int64_t DimType; #endif DimType xPoints = static_cast<DimType>(udims[0]); DimType yPoints = static_cast<DimType>(udims[1]); DimType zPoints = static_cast<DimType>(udims[2]); DimType point = 0; size_t neighbor = 0; DimType jStride = 0; DimType kStride = 0; for (DimType col = 0; col < xPoints; col++) { for (DimType row = 0; row < yPoints; row++) { for (DimType plane = 0; plane < zPoints; plane++) { point = (plane * xPoints * yPoints) + (row * xPoints) + col; if (m_FeatureIds[point] > 0 && m_CellPhases[point] > 0) { totalmisorientation = 0.0f; numVoxel = 0; QuaternionMathF::Copy(quats[point], q1); phase1 = m_CrystalStructures[m_CellPhases[point]]; for (int32_t j = -m_KernelSize.z; j < m_KernelSize.z + 1; j++) { jStride = j * xPoints * yPoints; for (int32_t k = -m_KernelSize.y; k < m_KernelSize.y + 1; k++) { kStride = k * xPoints; for (int32_t l = -m_KernelSize.x; l < m_KernelSize.z + 1; l++) { good = true; neighbor = point + (jStride) + (kStride) + (l); if (plane + j < 0) { good = false; } else if (plane + j > zPoints - 1) { good = false; } else if (row + k < 0) { good = false; } else if (row + k > yPoints - 1) { good = false; } else if (col + l < 0) { good = false; } else if (col + l > xPoints - 1) { good = false; } if (good == true && m_FeatureIds[point] == m_FeatureIds[neighbor]) { w = std::numeric_limits<float>::max(); QuaternionMathF::Copy(quats[neighbor], q2); phase2 = m_CrystalStructures[m_CellPhases[neighbor]]; w = m_OrientationOps[phase1]->getMisoQuat(q1, q2, n1, n2, n3); w = w * (180.0f / SIMPLib::Constants::k_Pi); totalmisorientation = totalmisorientation + w; numVoxel++; } } } } m_KernelAverageMisorientations[point] = totalmisorientation / (float)numVoxel; if (numVoxel == 0) { m_KernelAverageMisorientations[point] = 0.0f; } } if (m_FeatureIds[point] == 0 || m_CellPhases[point] == 0) { m_KernelAverageMisorientations[point] = 0.0f; } } } } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindAvgCAxes::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); size_t totalFeatures = m_AvgCAxesPtr.lock()->getNumberOfTuples(); QuatF q1 = QuaternionMathF::New(); QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); float g1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float g1t[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float caxis[3] = { 0.0f, 0.0f, 1.0f }; float c1[3] = { 0.0f, 0.0f, 0.0f }; std::vector<int32_t> counter(totalFeatures, 0); float curCAxis[3] = { 0.0f, 0.0f, 0.0f }; size_t index = 0; float w = 0.0f; for (size_t i = 0; i < totalPoints; i++) { if (m_FeatureIds[i] > 0) { index = 3 * m_FeatureIds[i]; QuaternionMathF::Copy(quats[i], q1); FOrientArrayType om(9); FOrientTransformsType::qu2om(FOrientArrayType(q1), om); om.toGMatrix(g1); // transpose the g matricies so when caxis is multiplied by it // it will give the sample direction that the caxis is along MatrixMath::Transpose3x3(g1, g1t); MatrixMath::Multiply3x3with3x1(g1t, caxis, c1); // normalize so that the magnitude is 1 MatrixMath::Normalize3x1(c1); curCAxis[0] = m_AvgCAxes[index] / counter[m_FeatureIds[i]]; curCAxis[1] = m_AvgCAxes[index + 1] / counter[m_FeatureIds[i]]; curCAxis[2] = m_AvgCAxes[index + 2] / counter[m_FeatureIds[i]]; MatrixMath::Normalize3x1(curCAxis); w = GeometryMath::CosThetaBetweenVectors(c1, curCAxis); if (w < 0) { MatrixMath::Multiply3x1withConstant(c1, -1); } counter[m_FeatureIds[i]]++; m_AvgCAxes[index] += c1[0]; m_AvgCAxes[index + 1] += c1[1]; m_AvgCAxes[index + 2] += c1[2]; } } for (size_t i = 1; i < totalFeatures; i++) { if (counter[i] == 0) { m_AvgCAxes[3 * i] = 0; m_AvgCAxes[3 * i + 1] = 0; m_AvgCAxes[3 * i + 2] = 1; } else { m_AvgCAxes[3 * i] /= counter[i]; m_AvgCAxes[3 * i + 1] /= counter[i]; m_AvgCAxes[3 * i + 2] /= counter[i]; } } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t VtkStructuredPointsReader:: readFile() { int32_t err = 0; DataContainer::Pointer volDc = getDataContainerArray()->getDataContainer(getVolumeDataContainerName()); AttributeMatrix::Pointer volAm = volDc->getAttributeMatrix(getCellAttributeMatrixName()); DataContainer::Pointer vertDc = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); AttributeMatrix::Pointer vertAm = vertDc->getAttributeMatrix(getVertexAttributeMatrixName()); std::ifstream in(getInputFile().toLatin1().constData(), std::ios_base::in | std::ios_base::binary); if (!in.is_open()) { QString msg = QObject::tr("Error opening output file '%1'").arg(getInputFile()); setErrorCondition(-61003); notifyErrorMessage(getHumanLabel(), msg, getErrorCondition()); return -100; } QByteArray buf(kBufferSize, '\0'); char* buffer = buf.data(); err = readLine(in, buffer, kBufferSize); // Read Line 1 - VTK Version Info err = readLine(in, buffer, kBufferSize); // Read Line 2 - User Comment setComment(QString(buf)); err = readLine(in, buffer, kBufferSize); // Read Line 3 - BINARY or ASCII QString fileType(buf); if (fileType.startsWith("BINARY") == true) { setFileIsBinary(true); } else if (fileType.startsWith("ASCII") == true) { setFileIsBinary(false); } else { QString ss = QObject::tr("The file type of the VTK legacy file could not be determined. It should be 'ASCII' or 'BINARY' and should appear on line 3 of the file"); setErrorCondition(-61004); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } // Read Line 4 - Type of Dataset err = readLine(in, buffer, kBufferSize); QList<QByteArray> words = buf.split(' '); if (words.size() != 2) { QString ss = QObject::tr("Error reading the type of data set. Was expecting 2 words but got %1").arg(QString(buf)); setErrorCondition(-61005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } QString dataset(words.at(1)); dataset = dataset.trimmed(); setDatasetType(dataset); // Should be STRUCTURED_POINTS bool ok = false; err = readLine(in, buffer, kBufferSize); // Read Line 5 which is the Dimension values // But we need the 'extents' which is one less in all directions (unless dim=1) QVector<size_t> dims(3, 0); QList<QByteArray> tokens = buf.split(' '); dims[0] = tokens[1].toInt(&ok, 10); dims[1] = tokens[2].toInt(&ok, 10); dims[2] = tokens[3].toInt(&ok, 10); QVector<size_t> tDims(3, 0); tDims[0] = dims[0]; tDims[1] = dims[1]; tDims[2] = dims[2]; vertAm->setTupleDimensions(tDims); vertDc->getGeometryAs<ImageGeom>()->setDimensions(dims.data()); tDims[0] = dims[0] - 1; tDims[1] = dims[1] - 1; tDims[2] = dims[2] - 1; volAm->setTupleDimensions(tDims); volDc->getGeometryAs<ImageGeom>()->setDimensions(tDims.data()); err = readLine(in, buffer, kBufferSize); // Read Line 7 which is the Scaling values tokens = buf.split(' '); float resolution[3]; resolution[0] = tokens[1].toFloat(&ok); resolution[1] = tokens[2].toFloat(&ok); resolution[2] = tokens[3].toFloat(&ok); volDc->getGeometryAs<ImageGeom>()->setResolution(resolution); vertDc->getGeometryAs<ImageGeom>()->setResolution(resolution); err = readLine(in, buffer, kBufferSize); // Read Line 6 which is the Origin values tokens = buf.split(' '); float origin[3]; origin[0] = tokens[1].toFloat(&ok); origin[1] = tokens[2].toFloat(&ok); origin[2] = tokens[3].toFloat(&ok); volDc->getGeometryAs<ImageGeom>()->setOrigin(origin); vertDc->getGeometryAs<ImageGeom>()->setOrigin(origin); // Read the first key word which should be POINT_DATA or CELL_DATA err = readLine(in, buffer, kBufferSize); // Read Line 6 which is the first type of data we are going to read tokens = buf.split(' '); QString word = QString(tokens[0]); int32_t npts = 0, ncells = 0; int32_t numPts = 0; if ( word.startsWith("CELL_DATA") ) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVolumeDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getCellAttributeMatrixName()); ncells = tokens[1].toInt(&ok); if (m_CurrentAttrMat->getNumTuples() != ncells) { setErrorCondition(-61006); notifyErrorMessage(getHumanLabel(), QString("Number of cells does not match number of tuples in the Attribute Matrix"), getErrorCondition()); return getErrorCondition(); } this->readDataTypeSection(in, ncells, "point_data"); } else if ( word.startsWith("POINT_DATA") ) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getVertexDataContainerName()); m_CurrentAttrMat = m->getAttributeMatrix(getVertexAttributeMatrixName()); npts = tokens[1].toInt(&ok); if (m_CurrentAttrMat->getNumTuples() != npts) { setErrorCondition(-61007); notifyErrorMessage(getHumanLabel(), QString("Number of points does not match number of tuples in the Attribute Matrix"), getErrorCondition()); return getErrorCondition(); } this->readDataTypeSection(in, numPts, "cell_data"); } // Close the file since we are done with it. in.close(); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VtkStructuredPointsReader::dataCheck() { initialize(); setErrorCondition(0); QFileInfo fi(getInputFile()); if (getInputFile().isEmpty() == true) { QString ss = QObject::tr("The input file must be set"); setErrorCondition(-61000); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } else if (fi.exists() == false) { QString ss = QObject::tr("The input file does not exist"); setErrorCondition(-61001); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } // First shot Sanity Checks. if(!getReadCellData() && !getReadPointData()) { QString ss = QObject::tr("At least one of Read Point Data or Read Cell Data must be checked"); setErrorCondition(-61002); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } // Last chance sanity check if(getErrorCondition() < 0) { return; } // Create a Vertex Data Container even though we may remove it later. We need it later // on in order to set the proper AttributeMatrix DataContainer::Pointer pointData_DataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getVertexDataContainerName()); if(getErrorCondition() < 0 && NULL == pointData_DataContainer) { return; } ImageGeom::Pointer pointDataGeom = ImageGeom::CreateGeometry(getVertexDataContainerName()); pointData_DataContainer->setGeometry(pointDataGeom); QVector<size_t> tDims(1, 0); AttributeMatrix::Pointer pointAttrMat = pointData_DataContainer->createNonPrereqAttributeMatrix<AbstractFilter>(this, getVertexAttributeMatrixName(), tDims, SIMPL::AttributeMatrixType::Cell); if(getErrorCondition() < 0) { return; } // Create a Volume Data Container even though we may remove it later. We need it later // on in order to set the proper AttributeMatrix DataContainer::Pointer cellData_DataContainer = getDataContainerArray()->createNonPrereqDataContainer<AbstractFilter>(this, getVolumeDataContainerName()); if(getErrorCondition() < 0 && NULL == cellData_DataContainer) { return; } ImageGeom::Pointer cellDataGeom = ImageGeom::CreateGeometry(getVolumeDataContainerName()); cellData_DataContainer->setGeometry(cellDataGeom); tDims.resize(3); tDims[0] = 0; tDims[1] = 0; tDims[2] = 0; AttributeMatrix::Pointer cellAttrMat = cellData_DataContainer->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCellAttributeMatrixName(), tDims, SIMPL::AttributeMatrixType::Cell); if(getErrorCondition() < 0) { return; } // Scan through the file readFile(); // now check to see what the user wanted if (!getReadPointData()) { getDataContainerArray()->removeDataContainer(getVertexDataContainerName()); } if (!getReadCellData()) { getDataContainerArray()->removeDataContainer(getVolumeDataContainerName()); } // If there was no Cell Data, remove that dataContainer if (cellAttrMat->getNumAttributeArrays() == 0) { getDataContainerArray()->removeDataContainer(getVolumeDataContainerName()); } // If there were no Point Arrays then remove that dataContainer if (pointAttrMat->getNumAttributeArrays() == 0) { getDataContainerArray()->removeDataContainer(getVertexDataContainerName()); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VisualizeGBCDPoleFigure::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputFile()); QDir dir(fi.path()); if(!dir.mkpath(".")) { QString ss; ss = QObject::tr("Error creating parent path '%1'").arg(dir.path()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QFile file(getOutputFile()); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } FloatArrayType::Pointer gbcdDeltasArray = FloatArrayType::CreateArray(5, "GBCDDeltas"); gbcdDeltasArray->initializeWithZeros(); FloatArrayType::Pointer gbcdLimitsArray = FloatArrayType::CreateArray(10, "GBCDLimits"); gbcdLimitsArray->initializeWithZeros(); Int32ArrayType::Pointer gbcdSizesArray = Int32ArrayType::CreateArray(5, "GBCDSizes"); gbcdSizesArray->initializeWithZeros(); float* gbcdDeltas = gbcdDeltasArray->getPointer(0); int* gbcdSizes = gbcdSizesArray->getPointer(0); float* gbcdLimits = gbcdLimitsArray->getPointer(0); // Original Ranges from Dave R. //m_GBCDlimits[0] = 0.0f; //m_GBCDlimits[1] = cosf(1.0f*m_pi); //m_GBCDlimits[2] = 0.0f; //m_GBCDlimits[3] = 0.0f; //m_GBCDlimits[4] = cosf(1.0f*m_pi); //m_GBCDlimits[5] = 2.0f*m_pi; //m_GBCDlimits[6] = cosf(0.0f); //m_GBCDlimits[7] = 2.0f*m_pi; //m_GBCDlimits[8] = 2.0f*m_pi; //m_GBCDlimits[9] = cosf(0.0f); // Greg R. Ranges gbcdLimits[0] = 0.0f; gbcdLimits[1] = 0.0f; gbcdLimits[2] = 0.0f; gbcdLimits[3] = 0.0f; gbcdLimits[4] = 0.0f; gbcdLimits[5] = SIMPLib::Constants::k_PiOver2; gbcdLimits[6] = 1.0f; gbcdLimits[7] = SIMPLib::Constants::k_PiOver2; gbcdLimits[8] = 1.0f; gbcdLimits[9] = SIMPLib::Constants::k_2Pi; // reset the 3rd and 4th dimensions using the square grid approach gbcdLimits[3] = -sqrtf(SIMPLib::Constants::k_PiOver2); gbcdLimits[4] = -sqrtf(SIMPLib::Constants::k_PiOver2); gbcdLimits[8] = sqrtf(SIMPLib::Constants::k_PiOver2); gbcdLimits[9] = sqrtf(SIMPLib::Constants::k_PiOver2); // get num components of GBCD QVector<size_t> cDims = m_GBCDPtr.lock()->getComponentDimensions(); gbcdSizes[0] = cDims[0]; gbcdSizes[1] = cDims[1]; gbcdSizes[2] = cDims[2]; gbcdSizes[3] = cDims[3]; gbcdSizes[4] = cDims[4]; gbcdDeltas[0] = (gbcdLimits[5] - gbcdLimits[0]) / float(gbcdSizes[0]); gbcdDeltas[1] = (gbcdLimits[6] - gbcdLimits[1]) / float(gbcdSizes[1]); gbcdDeltas[2] = (gbcdLimits[7] - gbcdLimits[2]) / float(gbcdSizes[2]); gbcdDeltas[3] = (gbcdLimits[8] - gbcdLimits[3]) / float(gbcdSizes[3]); gbcdDeltas[4] = (gbcdLimits[9] - gbcdLimits[4]) / float(gbcdSizes[4]); float vec[3] = { 0.0f, 0.0f, 0.0f }; float vec2[3] = { 0.0f, 0.0f, 0.0f }; float rotNormal[3] = { 0.0f, 0.0f, 0.0f }; float rotNormal2[3] = { 0.0f, 0.0f, 0.0f }; float sqCoord[2] = { 0.0f, 0.0f }; float dg[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dgt[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dg1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dg2[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym2[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym2t[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float mis_euler1[3] = { 0.0f, 0.0f, 0.0f }; float misAngle = m_MisorientationRotation.angle * SIMPLib::Constants::k_PiOver180; float normAxis[3] = { m_MisorientationRotation.h, m_MisorientationRotation.k, m_MisorientationRotation.l }; MatrixMath::Normalize3x1(normAxis); // convert axis angle to matrix representation of misorientation FOrientArrayType om(9, 0.0f); FOrientTransformsType::ax2om(FOrientArrayType(normAxis[0], normAxis[1], normAxis[2], misAngle), om); om.toGMatrix(dg); // take inverse of misorientation variable to use for switching symmetry MatrixMath::Transpose3x3(dg, dgt); // Get our SpaceGroupOps pointer for the selected crystal structure SpaceGroupOps::Pointer orientOps = m_OrientationOps[m_CrystalStructures[m_PhaseOfInterest]]; // get number of symmetry operators int32_t n_sym = orientOps->getNumSymOps(); int32_t xpoints = 100; int32_t ypoints = 100; int32_t zpoints = 1; int32_t xpointshalf = xpoints / 2; int32_t ypointshalf = ypoints / 2; float xres = 2.0f / float(xpoints); float yres = 2.0f / float(ypoints); float zres = (xres + yres) / 2.0; float x = 0.0f, y = 0.0f; float sum = 0; int32_t count = 0; bool nhCheck = false; int32_t hemisphere = 0; int32_t shift1 = gbcdSizes[0]; int32_t shift2 = gbcdSizes[0] * gbcdSizes[1]; int32_t shift3 = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2]; int32_t shift4 = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2] * gbcdSizes[3]; int64_t totalGBCDBins = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2] * gbcdSizes[3] * gbcdSizes[4] * 2; QVector<size_t> dims(1, 1); DoubleArrayType::Pointer poleFigureArray = DoubleArrayType::NullPointer(); poleFigureArray = DoubleArrayType::CreateArray(xpoints * ypoints, dims, "PoleFigure"); poleFigureArray->initializeWithZeros(); double* poleFigure = poleFigureArray->getPointer(0); for (int32_t k = 0; k < ypoints; k++) { for (int32_t l = 0; l < xpoints; l++) { // get (x,y) for stereographic projection pixel x = float(l - xpointshalf) * xres + (xres / 2.0); y = float(k - ypointshalf) * yres + (yres / 2.0); if ((x * x + y * y) <= 1.0) { sum = 0.0f; count = 0; vec[2] = -((x * x + y * y) - 1) / ((x * x + y * y) + 1); vec[0] = x * (1 + vec[2]); vec[1] = y * (1 + vec[2]); MatrixMath::Multiply3x3with3x1(dgt, vec, vec2); // Loop over all the symetry operators in the given cystal symmetry for (int32_t i = 0; i < n_sym; i++) { //get symmetry operator1 orientOps->getMatSymOp(i, sym1); for (int32_t j = 0; j < n_sym; j++) { // get symmetry operator2 orientOps->getMatSymOp(j, sym2); MatrixMath::Transpose3x3(sym2, sym2t); // calculate symmetric misorientation MatrixMath::Multiply3x3with3x3(dg, sym2t, dg1); MatrixMath::Multiply3x3with3x3(sym1, dg1, dg2); // convert to euler angle FOrientArrayType eu(mis_euler1, 3); FOrientTransformsType::om2eu(FOrientArrayType(dg2), eu); if (mis_euler1[0] < SIMPLib::Constants::k_PiOver2 && mis_euler1[1] < SIMPLib::Constants::k_PiOver2 && mis_euler1[2] < SIMPLib::Constants::k_PiOver2) { mis_euler1[1] = cosf(mis_euler1[1]); // find bins in GBCD int32_t location1 = int32_t((mis_euler1[0] - gbcdLimits[0]) / gbcdDeltas[0]); int32_t location2 = int32_t((mis_euler1[1] - gbcdLimits[1]) / gbcdDeltas[1]); int32_t location3 = int32_t((mis_euler1[2] - gbcdLimits[2]) / gbcdDeltas[2]); //find symmetric poles using the first symmetry operator MatrixMath::Multiply3x3with3x1(sym1, vec, rotNormal); //get coordinates in square projection of crystal normal parallel to boundary normal nhCheck = getSquareCoord(rotNormal, sqCoord); // Note the switch to have theta in the 4 slot and cos(Phi) int he 3 slot int32_t location4 = int32_t((sqCoord[0] - gbcdLimits[3]) / gbcdDeltas[3]); int32_t location5 = int32_t((sqCoord[1] - gbcdLimits[4]) / gbcdDeltas[4]); if (location1 >= 0 && location2 >= 0 && location3 >= 0 && location4 >= 0 && location5 >= 0 && location1 < gbcdSizes[0] && location2 < gbcdSizes[1] && location3 < gbcdSizes[2] && location4 < gbcdSizes[3] && location5 < gbcdSizes[4]) { hemisphere = 0; if (nhCheck == false) { hemisphere = 1; } sum += m_GBCD[(m_PhaseOfInterest * totalGBCDBins) + 2 * ((location5 * shift4) + (location4 * shift3) + (location3 * shift2) + (location2 * shift1) + location1) + hemisphere]; count++; } } // again in second crystal reference frame // calculate symmetric misorientation MatrixMath::Multiply3x3with3x3(dgt, sym2, dg1); MatrixMath::Multiply3x3with3x3(sym1, dg1, dg2); // convert to euler angle FOrientTransformsType::om2eu(FOrientArrayType(dg2), eu); if (mis_euler1[0] < SIMPLib::Constants::k_PiOver2 && mis_euler1[1] < SIMPLib::Constants::k_PiOver2 && mis_euler1[2] < SIMPLib::Constants::k_PiOver2) { mis_euler1[1] = cosf(mis_euler1[1]); // find bins in GBCD int32_t location1 = int32_t((mis_euler1[0] - gbcdLimits[0]) / gbcdDeltas[0]); int32_t location2 = int32_t((mis_euler1[1] - gbcdLimits[1]) / gbcdDeltas[1]); int32_t location3 = int32_t((mis_euler1[2] - gbcdLimits[2]) / gbcdDeltas[2]); // find symmetric poles using the first symmetry operator MatrixMath::Multiply3x3with3x1(sym1, vec2, rotNormal2); // get coordinates in square projection of crystal normal parallel to boundary normal nhCheck = getSquareCoord(rotNormal2, sqCoord); // Note the switch to have theta in the 4 slot and cos(Phi) int he 3 slot int32_t location4 = int32_t((sqCoord[0] - gbcdLimits[3]) / gbcdDeltas[3]); int32_t location5 = int32_t((sqCoord[1] - gbcdLimits[4]) / gbcdDeltas[4]); if (location1 >= 0 && location2 >= 0 && location3 >= 0 && location4 >= 0 && location5 >= 0 && location1 < gbcdSizes[0] && location2 < gbcdSizes[1] && location3 < gbcdSizes[2] && location4 < gbcdSizes[3] && location5 < gbcdSizes[4]) { hemisphere = 0; if (nhCheck == false) { hemisphere = 1; } sum += m_GBCD[(m_PhaseOfInterest * totalGBCDBins) + 2 * ((location5 * shift4) + (location4 * shift3) + (location3 * shift2) + (location2 * shift1) + location1) + hemisphere]; count++; } } } } if (count > 0) { poleFigure[(k * xpoints) + l] = sum / float(count); } } } } FILE* f = NULL; f = fopen(m_OutputFile.toLatin1().data(), "wb"); if (NULL == f) { QString ss = QObject::tr("Error opening output file '%1'").arg(m_OutputFile); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } // Write the correct header fprintf(f, "# vtk DataFile Version 2.0\n"); fprintf(f, "data set from DREAM3D\n"); fprintf(f, "BINARY"); fprintf(f, "\n"); fprintf(f, "DATASET RECTILINEAR_GRID\n"); fprintf(f, "DIMENSIONS %d %d %d\n", xpoints + 1, ypoints + 1, zpoints + 1); // Write the Coords writeCoords(f, "X_COORDINATES", "float", xpoints + 1, (-float(xpoints)*xres / 2.0f), xres); writeCoords(f, "Y_COORDINATES", "float", ypoints + 1, (-float(ypoints)*yres / 2.0f), yres); writeCoords(f, "Z_COORDINATES", "float", zpoints + 1, (-float(zpoints)*zres / 2.0f), zres); int32_t total = xpoints * ypoints * zpoints; fprintf(f, "CELL_DATA %d\n", total); fprintf(f, "SCALARS %s %s 1\n", "Intensity", "float"); fprintf(f, "LOOKUP_TABLE default\n"); { float* gn = new float[total]; float t; count = 0; for (int32_t j = 0; j < ypoints; j++) { for (int32_t i = 0; i < xpoints; i++) { t = float(poleFigure[(j * xpoints) + i]); SIMPLib::Endian::FromSystemToBig::convert(t); gn[count] = t; count++; } } size_t totalWritten = fwrite(gn, sizeof(float), (total), f); delete[] gn; if (totalWritten != (total)) { QString ss = QObject::tr("Error writing binary VTK data to file '%1'").arg(m_OutputFile); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); fclose(f); return; } } fclose(f); /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindGBCD::execute() { setErrorCondition(0); dataCheckVoxel(); if(getErrorCondition() < 0) { return; } // order here matters...because we are going to use the size of the crystal structures out of the dataCheckVoxel to size the faceAttrMat in dataCheckSurfaceMesh dataCheckSurfaceMesh(); if(getErrorCondition() < 0) { return; } #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif size_t totalPhases = m_CrystalStructuresPtr.lock()->getNumberOfTuples(); size_t totalFaces = m_SurfaceMeshFaceLabelsPtr.lock()->getNumberOfTuples(); size_t faceChunkSize = 50000; size_t numMisoReps = 576 * 4; if (totalFaces < faceChunkSize) { faceChunkSize = totalFaces; } // call the sizeGBCD function with proper chunkSize and numMisoReps to get Bins array set up properly sizeGBCD(faceChunkSize, numMisoReps); int32_t totalGBCDBins = m_GbcdSizes[0] * m_GbcdSizes[1] * m_GbcdSizes[2] * m_GbcdSizes[3] * m_GbcdSizes[4] * 2; uint64_t millis = QDateTime::currentMSecsSinceEpoch(); uint64_t currentMillis = millis; uint64_t startMillis = millis; uint64_t estimatedTime = 0; float timeDiff = 0.0f; startMillis = QDateTime::currentMSecsSinceEpoch(); int32_t hemisphere = 0; //create an array to hold the total face area for each phase and initialize the array to 0.0 DoubleArrayType::Pointer totalFaceAreaPtr = DoubleArrayType::CreateArray(totalPhases, "totalFaceArea"); totalFaceAreaPtr->initializeWithValue(0.0); double* totalFaceArea = totalFaceAreaPtr->getPointer(0); QString ss = QObject::tr("Calculating GBCD || 0/%1 Completed").arg(totalFaces); for (size_t i = 0; i < totalFaces; i = i + faceChunkSize) { if(getCancel() == true) { return; } if (i + faceChunkSize >= totalFaces) { faceChunkSize = totalFaces - i; } m_GbcdBinsArray->initializeWithValue(-1); #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(i, i + faceChunkSize), CalculateGBCDImpl(i, numMisoReps, m_SurfaceMeshFaceLabelsPtr.lock(), m_SurfaceMeshFaceNormalsPtr.lock(), m_FeatureEulerAnglesPtr.lock(), m_FeaturePhasesPtr.lock(), m_CrystalStructuresPtr.lock(), m_GbcdBinsArray, m_GbcdHemiCheckArray, m_GbcdDeltasArray, m_GbcdSizesArray, m_GbcdLimitsArray), tbb::auto_partitioner()); } else #endif { CalculateGBCDImpl serial(i, numMisoReps, m_SurfaceMeshFaceLabelsPtr.lock(), m_SurfaceMeshFaceNormalsPtr.lock(), m_FeatureEulerAnglesPtr.lock(), m_FeaturePhasesPtr.lock(), m_CrystalStructuresPtr.lock(), m_GbcdBinsArray, m_GbcdHemiCheckArray, m_GbcdDeltasArray, m_GbcdSizesArray, m_GbcdLimitsArray); serial.generate(i, i + faceChunkSize); } currentMillis = QDateTime::currentMSecsSinceEpoch(); if (currentMillis - millis > 1000) { QString ss = QObject::tr("Calculating GBCD || Triangles %1/%2 Completed").arg(i).arg(totalFaces); timeDiff = ((float)i / (float)(currentMillis - startMillis)); estimatedTime = (float)(totalFaces - i) / timeDiff; ss = ss + QObject::tr(" || Est. Time Remain: %1").arg(DREAM3D::convertMillisToHrsMinSecs(estimatedTime)); millis = QDateTime::currentMSecsSinceEpoch(); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); } if(getCancel() == true) { return; } int32_t phase = 0; int32_t feature = 0; double area = 0.0; for (size_t j = 0; j < faceChunkSize; j++) { area = m_SurfaceMeshFaceAreas[i + j]; feature = m_SurfaceMeshFaceLabels[2 * (i + j)]; phase = m_FeaturePhases[feature]; for (size_t k = 0; k < numMisoReps; k++) { if (m_GbcdBins[(j * numMisoReps) + (k)] >= 0) { hemisphere = 0; if (m_HemiCheck[(j * numMisoReps) + k] == false) { hemisphere = 1; } m_GBCD[(phase * totalGBCDBins) + (2 * m_GbcdBins[(j * numMisoReps) + (k)] + hemisphere)] += area; totalFaceArea[phase] += area; } } } } ss = QObject::tr("Starting GBCD Normalization"); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); for (int32_t i = 0; i < totalPhases; i++) { size_t phaseShift = i * totalGBCDBins; double MRDfactor = double(totalGBCDBins) / totalFaceArea[i]; for (int32_t j = 0; j < totalGBCDBins; j++) { m_GBCD[phaseShift + j] *= MRDfactor; } } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QString FilterParameterWidgetCodeGenerator::generateSetupFilterParameters() { return " parameters.push_back(FilterParameter::New(\"" + getHumanLabel() + "\", \"" + getPropertyName() + "\", FilterParameterWidgetType::FilterParameterWidget, get" + getPropertyName() + "(), false));"; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSectionsFeatureCentroid::find_shifts(std::vector<int64_t>& xshifts, std::vector<int64_t>& yshifts) { DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); std::ofstream outFile; if (getWriteAlignmentShifts() == true) { outFile.open(getAlignmentShiftFileName().toLatin1().data()); } size_t udims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->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]), }; int64_t newxshift = 0; int64_t newyshift = 0; int64_t count = 0; DimType slice = 0; DimType point = 0; float xRes = m->getGeometryAs<ImageGeom>()->getXRes(); float yRes = m->getGeometryAs<ImageGeom>()->getYRes(); std::vector<float> xCentroid(dims[2], 0.0f); std::vector<float> yCentroid(dims[2], 0.0f); for (DimType iter = 0; iter < dims[2]; iter++) { count = 0; xCentroid[iter] = 0; yCentroid[iter] = 0; QString ss = QObject::tr("Aligning Sections || Determining Shifts || %1% Complete").arg(((float)iter / dims[2]) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); slice = static_cast<int>( (dims[2] - 1) - iter ); for (DimType l = 0; l < dims[1]; l++) { for (DimType n = 0; n < dims[0]; n++) { point = ((slice) * dims[0] * dims[1]) + (l * dims[0]) + n; if (m_GoodVoxels[point] == true) { xCentroid[iter] = xCentroid[iter] + (float(n) * xRes); yCentroid[iter] = yCentroid[iter] + (float(l) * yRes); count++; } } } xCentroid[iter] = xCentroid[iter] / float(count); yCentroid[iter] = yCentroid[iter] / float(count); } for (DimType iter = 1; iter < dims[2]; iter++) { slice = (dims[2] - 1) - iter; if (m_UseReferenceSlice == true) { xshifts[iter] = static_cast<int64_t>((xCentroid[iter] - xCentroid[m_ReferenceSlice]) / xRes); yshifts[iter] = static_cast<int64_t>((yCentroid[iter] - yCentroid[m_ReferenceSlice]) / yRes); } else { xshifts[iter] = xshifts[iter - 1] + static_cast<int64_t>((xCentroid[iter] - xCentroid[iter - 1]) / xRes); yshifts[iter] = yshifts[iter - 1] + static_cast<int64_t>((yCentroid[iter] - yCentroid[iter - 1]) / yRes); } if (getWriteAlignmentShifts() == true) { outFile << slice << " " << slice + 1 << " " << newxshift << " " << newyshift << " " << xshifts[iter] << " " << yshifts[iter] << " " << xCentroid[iter] << " " << yCentroid[iter] << std::endl; } } if (getWriteAlignmentShifts() == true) { outFile.close(); } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void VisualizeGBCDGMT::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getGBCDArrayPath().getDataContainerName()); // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path QFileInfo fi(getOutputFile()); QDir dir(fi.path()); if (!dir.mkpath(".")) { QString ss; ss = QObject::tr("Error creating parent path '%1'").arg(dir.path()); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QFile file(getOutputFile()); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } FloatArrayType::Pointer gbcdDeltasArray = FloatArrayType::CreateArray(5, "GBCDDeltas"); gbcdDeltasArray->initializeWithZeros(); FloatArrayType::Pointer gbcdLimitsArray = FloatArrayType::CreateArray(10, "GBCDLimits"); gbcdLimitsArray->initializeWithZeros(); Int32ArrayType::Pointer gbcdSizesArray = Int32ArrayType::CreateArray(5, "GBCDSizes"); gbcdSizesArray->initializeWithZeros(); float* gbcdDeltas = gbcdDeltasArray->getPointer(0); int32_t* gbcdSizes = gbcdSizesArray->getPointer(0); float* gbcdLimits = gbcdLimitsArray->getPointer(0); // Original Ranges from Dave R. //m_GBCDlimits[0] = 0.0f; //m_GBCDlimits[1] = cosf(1.0f*m_pi); //m_GBCDlimits[2] = 0.0f; //m_GBCDlimits[3] = 0.0f; //m_GBCDlimits[4] = cosf(1.0f*m_pi); //m_GBCDlimits[5] = 2.0f*m_pi; //m_GBCDlimits[6] = cosf(0.0f); //m_GBCDlimits[7] = 2.0f*m_pi; //m_GBCDlimits[8] = 2.0f*m_pi; //m_GBCDlimits[9] = cosf(0.0f); // Greg R. Ranges gbcdLimits[0] = 0.0f; gbcdLimits[1] = 0.0f; gbcdLimits[2] = 0.0f; gbcdLimits[3] = -sqrtf(SIMPLib::Constants::k_Pi / 2.0f); gbcdLimits[4] = -sqrtf(SIMPLib::Constants::k_Pi / 2.0f); gbcdLimits[5] = SIMPLib::Constants::k_Pi / 2.0f; gbcdLimits[6] = 1.0f; gbcdLimits[7] = SIMPLib::Constants::k_Pi / 2.0f; gbcdLimits[8] = sqrtf(SIMPLib::Constants::k_Pi / 2.0f); gbcdLimits[9] = sqrtf(SIMPLib::Constants::k_Pi / 2.0f); // get num components of GBCD QVector<size_t> cDims = m_GBCDPtr.lock()->getComponentDimensions(); gbcdSizes[0] = cDims[0]; gbcdSizes[1] = cDims[1]; gbcdSizes[2] = cDims[2]; gbcdSizes[3] = cDims[3]; gbcdSizes[4] = cDims[4]; gbcdDeltas[0] = (gbcdLimits[5] - gbcdLimits[0]) / float(gbcdSizes[0]); gbcdDeltas[1] = (gbcdLimits[6] - gbcdLimits[1]) / float(gbcdSizes[1]); gbcdDeltas[2] = (gbcdLimits[7] - gbcdLimits[2]) / float(gbcdSizes[2]); gbcdDeltas[3] = (gbcdLimits[8] - gbcdLimits[3]) / float(gbcdSizes[3]); gbcdDeltas[4] = (gbcdLimits[9] - gbcdLimits[4]) / float(gbcdSizes[4]); float vec[3] = { 0.0f, 0.0f, 0.0f }; float vec2[3] = { 0.0f, 0.0f, 0.0f }; float rotNormal[3] = { 0.0f, 0.0f, 0.0f }; float rotNormal2[3] = { 0.0f, 0.0f, 0.0f }; float sqCoord[2] = { 0.0f, 0.0f }; float dg[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dgt[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dg1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float dg2[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym1[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym2[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float sym2t[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float mis_euler1[3] = { 0.0f, 0.0f, 0.0f }; float misAngle = m_MisorientationRotation.angle * SIMPLib::Constants::k_PiOver180; float normAxis[3] = { m_MisorientationRotation.h, m_MisorientationRotation.k, m_MisorientationRotation.l }; MatrixMath::Normalize3x1(normAxis); // convert axis angle to matrix representation of misorientation FOrientArrayType om(9, 0.0f); FOrientTransformsType::ax2om(FOrientArrayType(normAxis[0], normAxis[1], normAxis[2], misAngle), om); om.toGMatrix(dg); // take inverse of misorientation variable to use for switching symmetry MatrixMath::Transpose3x3(dg, dgt); // Get our SpaceGroupOps pointer for the selected crystal structure SpaceGroupOps::Pointer orientOps = m_OrientationOps[m_CrystalStructures[m_PhaseOfInterest]]; // get number of symmetry operators int32_t n_sym = orientOps->getNumSymOps(); int32_t thetaPoints = 120; int32_t phiPoints = 30; float thetaRes = 360.0f / float(thetaPoints); float phiRes = 90.0f / float(phiPoints); float theta = 0.0f, phi = 0.0f; float thetaRad = 0.0f, phiRad = 0.0f; float degToRad = SIMPLib::Constants::k_PiOver180; float sum = 0.0f; int32_t count = 0; bool nhCheck = false; int32_t hemisphere = 0; int32_t shift1 = gbcdSizes[0]; int32_t shift2 = gbcdSizes[0] * gbcdSizes[1]; int32_t shift3 = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2]; int32_t shift4 = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2] * gbcdSizes[3]; int64_t totalGBCDBins = gbcdSizes[0] * gbcdSizes[1] * gbcdSizes[2] * gbcdSizes[3] * gbcdSizes[4] * 2; std::vector<float> gmtValues; for (int32_t k = 0; k < phiPoints + 1; k++) { for (int32_t l = 0; l < thetaPoints + 1; l++) { // get (x,y) for stereographic projection pixel theta = float(l) * thetaRes; phi = float(k) * phiRes; thetaRad = theta * degToRad; phiRad = phi * degToRad; sum = 0.0f; count = 0; vec[0] = sinf(phiRad) * cosf(thetaRad); vec[1] = sinf(phiRad) * sinf(thetaRad); vec[2] = cosf(phiRad); MatrixMath::Multiply3x3with3x1(dgt, vec, vec2); // Loop over all the symetry operators in the given cystal symmetry for (int32_t i = 0; i < n_sym; i++) { // get symmetry operator1 orientOps->getMatSymOp(i, sym1); for (int32_t j = 0; j < n_sym; j++) { // get symmetry operator2 orientOps->getMatSymOp(j, sym2); MatrixMath::Transpose3x3(sym2, sym2t); // calculate symmetric misorientation MatrixMath::Multiply3x3with3x3(dg, sym2t, dg1); MatrixMath::Multiply3x3with3x3(sym1, dg1, dg2); // convert to euler angle FOrientArrayType mEuler(mis_euler1, 3); FOrientTransformsType::om2eu(FOrientArrayType(dg2), mEuler); if (mis_euler1[0] < SIMPLib::Constants::k_PiOver2 && mis_euler1[1] < SIMPLib::Constants::k_PiOver2 && mis_euler1[2] < SIMPLib::Constants::k_PiOver2) { mis_euler1[1] = cosf(mis_euler1[1]); // find bins in GBCD int32_t location1 = int32_t((mis_euler1[0] - gbcdLimits[0]) / gbcdDeltas[0]); int32_t location2 = int32_t((mis_euler1[1] - gbcdLimits[1]) / gbcdDeltas[1]); int32_t location3 = int32_t((mis_euler1[2] - gbcdLimits[2]) / gbcdDeltas[2]); // find symmetric poles using the first symmetry operator MatrixMath::Multiply3x3with3x1(sym1, vec, rotNormal); // get coordinates in square projection of crystal normal parallel to boundary normal nhCheck = getSquareCoord(rotNormal, sqCoord); // Note the switch to have theta in the 4 slot and cos(Phi) int he 3 slot int32_t location4 = int32_t((sqCoord[0] - gbcdLimits[3]) / gbcdDeltas[3]); int32_t location5 = int32_t((sqCoord[1] - gbcdLimits[4]) / gbcdDeltas[4]); if (location1 >= 0 && location2 >= 0 && location3 >= 0 && location4 >= 0 && location5 >= 0 && location1 < gbcdSizes[0] && location2 < gbcdSizes[1] && location3 < gbcdSizes[2] && location4 < gbcdSizes[3] && location5 < gbcdSizes[4]) { hemisphere = 0; if (nhCheck == false) { hemisphere = 1; } sum += m_GBCD[(m_PhaseOfInterest * totalGBCDBins) + 2 * ((location5 * shift4) + (location4 * shift3) + (location3 * shift2) + (location2 * shift1) + location1) + hemisphere]; count++; } } // again in second crystal reference frame // calculate symmetric misorientation MatrixMath::Multiply3x3with3x3(dgt, sym2, dg1); MatrixMath::Multiply3x3with3x3(sym1, dg1, dg2); // convert to euler angle FOrientTransformsType::om2eu(FOrientArrayType(dg2), mEuler); if (mis_euler1[0] < SIMPLib::Constants::k_PiOver2 && mis_euler1[1] < SIMPLib::Constants::k_PiOver2 && mis_euler1[2] < SIMPLib::Constants::k_PiOver2) { mis_euler1[1] = cosf(mis_euler1[1]); // find bins in GBCD int32_t location1 = int32_t((mis_euler1[0] - gbcdLimits[0]) / gbcdDeltas[0]); int32_t location2 = int32_t((mis_euler1[1] - gbcdLimits[1]) / gbcdDeltas[1]); int32_t location3 = int32_t((mis_euler1[2] - gbcdLimits[2]) / gbcdDeltas[2]); // find symmetric poles using the first symmetry operator MatrixMath::Multiply3x3with3x1(sym1, vec2, rotNormal2); // get coordinates in square projection of crystal normal parallel to boundary normal nhCheck = getSquareCoord(rotNormal2, sqCoord); // Note the switch to have theta in the 4 slot and cos(Phi) int he 3 slot int32_t location4 = int32_t((sqCoord[0] - gbcdLimits[3]) / gbcdDeltas[3]); int32_t location5 = int32_t((sqCoord[1] - gbcdLimits[4]) / gbcdDeltas[4]); if (location1 >= 0 && location2 >= 0 && location3 >= 0 && location4 >= 0 && location5 >= 0 && location1 < gbcdSizes[0] && location2 < gbcdSizes[1] && location3 < gbcdSizes[2] && location4 < gbcdSizes[3] && location5 < gbcdSizes[4]) { hemisphere = 0; if (nhCheck == false) { hemisphere = 1; } sum += m_GBCD[(m_PhaseOfInterest * totalGBCDBins) + 2 * ((location5 * shift4) + (location4 * shift3) + (location3 * shift2) + (location2 * shift1) + location1) + hemisphere]; count++; } } } } gmtValues.push_back(theta); gmtValues.push_back((90.0f - phi)); gmtValues.push_back(sum / float(count)); } } FILE* f = NULL; f = fopen(m_OutputFile.toLatin1().data(), "wb"); if (NULL == f) { QString ss = QObject::tr("Error opening output file '%1'").arg(m_OutputFile); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } // Remember to use the original Angle in Degrees!!!! fprintf(f, "%.1f %.1f %.1f %.1f\n", m_MisorientationRotation.h, m_MisorientationRotation.k, m_MisorientationRotation.l, m_MisorientationRotation.angle); size_t size = gmtValues.size() / 3; for (size_t i = 0; i < size; i++) { fprintf(f, "%f %f %f\n", gmtValues[3 * i], gmtValues[3 * i + 1], gmtValues[3 * i + 2]); } fclose(f); /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void WriteTriangleGeometry::execute() { int err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer dataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerSelection()); TriangleGeom::Pointer triangleGeom = dataContainer->getGeometryAs<TriangleGeom>(); QString geometryType = triangleGeom->getGeometryTypeAsString(); float* nodes = triangleGeom->getVertexPointer(0); int64_t* triangles = triangleGeom->getTriPointer(0); qint64 numNodes = triangleGeom->getNumberOfVertices(); qint64 maxNodeId = numNodes - 1; int64_t numTriangles = triangleGeom->getNumberOfTris(); // ++++++++++++++ Write the Nodes File +++++++++++++++++++++++++++++++++++++++++++ // Make sure any directory path is also available as the user may have just typed // in a path without actually creating the full path notifyStatusMessage(getHumanLabel(), "Writing Nodes Text File"); QFileInfo fi(getOutputNodesFile()); QDir parentPath = fi.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); notifyErrorMessage(getHumanLabel(), ss, -1); setErrorCondition(-1); return; } FILE* nodesFile = NULL; nodesFile = fopen(getOutputNodesFile().toLatin1().data(), "wb"); if (NULL == nodesFile) { setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "Error opening Nodes file for writing", -100); return; } fprintf(nodesFile, "# All lines starting with '#' are comments\n"); fprintf(nodesFile, "# DREAM.3D Nodes file\n"); fprintf(nodesFile, "# DREAM.3D Version %s\n", SIMPLib::Version::Complete().toLatin1().constData()); fprintf(nodesFile, "# Node Data is X Y Z space delimited.\n"); fprintf(nodesFile, "Node Count: %lld\n", numNodes); for (int i = 0; i < numNodes; i++) { fprintf(nodesFile, "%8.5f %8.5f %8.5f\n", nodes[i * 3], nodes[i * 3 + 1], nodes[i * 3 + 2]); } fclose(nodesFile); // ++++++++++++++ Write the Triangles File +++++++++++++++++++++++++++++++++++++++++++ notifyStatusMessage(getHumanLabel(), "Writing Triangles Text File"); QFileInfo triFI(getOutputTrianglesFile()); parentPath = triFI.path(); if(!parentPath.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath.absolutePath()); notifyErrorMessage(getHumanLabel(), ss, -1); setErrorCondition(-1); return; } FILE* triFile = fopen(getOutputTrianglesFile().toLatin1().data(), "wb"); if (NULL == triFile) { setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), "Error opening Triangles file for writing", -100); return; } fprintf(triFile, "# All lines starting with '#' are comments\n"); fprintf(triFile, "# DREAM.3D Triangle file\n"); fprintf(triFile, "# DREAM.3D Version %s\n", SIMPLib::Version::Complete().toLatin1().constData()); fprintf(triFile, "# Each Triangle consists of 3 Node Ids.\n"); fprintf(triFile, "# NODE IDs START AT 0.\n"); fprintf(triFile, "Geometry Type: %s\n", geometryType.toLatin1().constData()); fprintf(triFile, "Node Count: %lld\n", numNodes); fprintf(triFile, "Max Node Id: %lld\n", maxNodeId ); fprintf(triFile, "Triangle Count: %lld\n", (long long int)(numTriangles)); int n1, n2, n3; for (int64_t j = 0; j < numTriangles; ++j) { n1 = triangles[j * 3]; n2 = triangles[j * 3 + 1]; n3 = triangles[j * 3 + 2]; fprintf(triFile, "%d %d %d\n", n1, n2, n3); } fclose(triFile); /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void RotateSampleRefFrame::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); float rotAngle = m_RotationAngle * SIMPLib::Constants::k_Pi / 180.0; int64_t xp = 0, yp = 0, zp = 0; float xRes = 0.0f, yRes = 0.0f, zRes = 0.0f; int64_t xpNew = 0, ypNew = 0, zpNew = 0; float xResNew = 0.0f, yResNew = 0.0f, zResNew = 0.0f; RotateSampleRefFrameImplArg_t params; xp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getXPoints()); xRes = m->getGeometryAs<ImageGeom>()->getXRes(); yp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getYPoints()); yRes = m->getGeometryAs<ImageGeom>()->getYRes(); zp = static_cast<int64_t>(m->getGeometryAs<ImageGeom>()->getZPoints()); zRes = m->getGeometryAs<ImageGeom>()->getZRes(); params.xp = xp; params.xRes = xRes; params.yp = yp; params.yRes = yRes; params.zp = zp; params.zRes = zRes; size_t col = 0, row = 0, plane = 0; float rotMat[3][3] = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }; float coords[3] = { 0.0f, 0.0f, 0.0f }; float newcoords[3] = { 0.0f, 0.0f, 0.0f }; float xMin = std::numeric_limits<float>::max(); float xMax = std::numeric_limits<float>::min(); float yMin = std::numeric_limits<float>::max(); float yMax = std::numeric_limits<float>::min(); float zMin = std::numeric_limits<float>::max(); float zMax = std::numeric_limits<float>::min(); FOrientArrayType om(9); FOrientTransformsType::ax2om(FOrientArrayType(m_RotationAxis.x, m_RotationAxis.y, m_RotationAxis.z, rotAngle), om); om.toGMatrix(rotMat); for (int32_t i = 0; i < 8; i++) { if (i == 0) { col = 0, row = 0, plane = 0; } if (i == 1) { col = xp - 1, row = 0, plane = 0; } if (i == 2) { col = 0, row = yp - 1, plane = 0; } if (i == 3) { col = xp - 1, row = yp - 1, plane = 0; } if (i == 4) { col = 0, row = 0, plane = zp - 1; } if (i == 5) { col = xp - 1, row = 0, plane = zp - 1; } if (i == 6) { col = 0, row = yp - 1, plane = zp - 1; } if (i == 7) { col = xp - 1, row = yp - 1, plane = zp - 1; } coords[0] = static_cast<float>(col * xRes); coords[1] = static_cast<float>(row * yRes); coords[2] = static_cast<float>(plane * zRes); MatrixMath::Multiply3x3with3x1(rotMat, coords, newcoords); if (newcoords[0] < xMin) { xMin = newcoords[0]; } if (newcoords[0] > xMax) { xMax = newcoords[0]; } if (newcoords[1] < yMin) { yMin = newcoords[1]; } if (newcoords[1] > yMax) { yMax = newcoords[1]; } if (newcoords[2] < zMin) { zMin = newcoords[2]; } if (newcoords[2] > zMax) { zMax = newcoords[2]; } } float xAxis[3] = {1, 0, 0}; float yAxis[3] = {0, 1, 0}; float zAxis[3] = {0, 0, 1}; float xAxisNew[3] = { 0.0f, 0.0f, 0.0f }; float yAxisNew[3] = { 0.0f, 0.0f, 0.0f }; float zAxisNew[3] = { 0.0f, 0.0f, 0.0f }; MatrixMath::Multiply3x3with3x1(rotMat, xAxis, xAxisNew); MatrixMath::Multiply3x3with3x1(rotMat, yAxis, yAxisNew); MatrixMath::Multiply3x3with3x1(rotMat, zAxis, zAxisNew); float closestAxis = 0.0f; xResNew = xRes; closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, xAxisNew)); if (fabs(GeometryMath::CosThetaBetweenVectors(yAxis, xAxisNew)) > closestAxis) { xResNew = yRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, xAxisNew)); } if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)) > closestAxis) { xResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)); } yResNew = yRes; closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, yAxisNew)); if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)) > closestAxis) { yResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)); } if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)) > closestAxis) { yResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)); } zResNew = zRes; closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, zAxisNew)); if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)) > closestAxis) { zResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)); } if (fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)) > closestAxis) { zResNew = yRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)); } xpNew = static_cast<int64_t>(nearbyint((xMax - xMin) / xResNew) + 1); ypNew = static_cast<int64_t>(nearbyint((yMax - yMin) / yResNew) + 1); zpNew = static_cast<int64_t>(nearbyint((zMax - zMin) / zResNew) + 1); params.xpNew = xpNew; params.xResNew = xResNew; params.xMinNew = xMin; params.ypNew = ypNew; params.yResNew = yResNew; params.yMinNew = yMin; params.zpNew = zpNew; params.zResNew = zResNew; params.zMinNew = zMin; int64_t newNumCellTuples = params.xpNew * params.ypNew * params.zpNew; DataArray<int64_t>::Pointer newIndiciesPtr = DataArray<int64_t>::CreateArray(newNumCellTuples, "_INTERNAL_USE_ONLY_RotateSampleRef_NewIndicies"); newIndiciesPtr->initializeWithValue(-1); int64_t* newindicies = newIndiciesPtr->getPointer(0); #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range3d<int64_t, int64_t, int64_t>(0, params.zpNew, 0, params.ypNew, 0, params.xpNew), RotateSampleRefFrameImpl(newIndiciesPtr, ¶ms, rotMat, m_SliceBySlice), tbb::auto_partitioner()); } else #endif { RotateSampleRefFrameImpl serial(newIndiciesPtr, ¶ms, rotMat, m_SliceBySlice); serial.convert(0, params.zpNew, 0, params.ypNew, 0, params.xpNew); } // This could technically be parallelized also where each thread takes an array to adjust. Except // that the DataContainer is NOT thread safe or re-entrant so that would actually be a BAD idea. QString attrMatName = getCellAttributeMatrixPath().getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); // resize attribute matrix QVector<size_t> tDims(3); tDims[0] = params.xpNew; tDims[1] = params.ypNew; tDims[2] = params.zpNew; m->getAttributeMatrix(attrMatName)->resizeAttributeArrays(tDims); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*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. IDataArray::Pointer data = p->createNewArray(newNumCellTuples, p->getComponentDimensions(), p->getName()); void* source = NULL; void* destination = NULL; int64_t newIndicies_I = 0; int32_t nComp = data->getNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(newNumCellTuples); i++) { newIndicies_I = newindicies[i]; if(newIndicies_I >= 0) { source = p->getVoidPointer((nComp * newIndicies_I)); if (NULL == source) { QString ss = QObject::tr("The index is outside the bounds of the source array"); setErrorCondition(-11004); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } destination = data->getVoidPointer((data->getNumberOfComponents() * i)); ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents()); } else { data->initializeTuple(i, 0); } } m->getAttributeMatrix(attrMatName)->addAttributeArray(*iter, data); } m->getGeometryAs<ImageGeom>()->setResolution(params.xResNew, params.yResNew, params.zResNew); m->getGeometryAs<ImageGeom>()->setDimensions(params.xpNew, params.ypNew, params.zpNew); m->getGeometryAs<ImageGeom>()->setOrigin(xMin, yMin, zMin); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void Hex2SqrConverter::execute() { std::stringstream ss; herr_t err = 0; std::vector<int> indices; // Loop on Each EBSD File float total = static_cast<float>( m_ZEndIndex - m_ZStartIndex ); int progress = 0; int64_t z = m_ZStartIndex; /* There is a frailness about the z index and the file list. The programmer * using this code MUST ensure that the list of files that is sent into this * class is in the appropriate order to match up with the z index (slice index) * otherwise the import will have subtle errors. The programmer is urged NOT to * simply gather a list from the file system as those lists are sorted in such * a way that if the number of digits appearing in the filename are NOT the same * then the list will be wrong, ie, this example: * * slice_1.ang * slice_2.ang * .... * slice_10.ang * * Most, if not ALL C++ libraries when asked for that list will return the list * sorted like the following: * * slice_1.ang * slice_10.ang * slice_2.ang * * which is going to cause problems because the data is going to be placed * into the HDF5 file at the wrong index. YOU HAVE BEEN WARNED. */ // int totalSlicesImported = 0; for (std::vector<std::string>::iterator filepath = m_EbsdFileList.begin(); filepath != m_EbsdFileList.end(); ++filepath) { std::string ebsdFName = *filepath; progress = static_cast<int>( z - m_ZStartIndex ); progress = (int)(100.0f * (float)(progress) / total); std::string msg = "Converting File: " + ebsdFName; ss.str(""); notifyStatusMessage(msg.c_str()); // Write the Manufacturer of the OIM file here // This list will grow to be the number of EBSD file formats we support std::string ext = MXAFileInfo::extension(ebsdFName); std::string base = MXAFileInfo::fileNameWithOutExtension(ebsdFName); std::string path = MXAFileInfo::parentPath(ebsdFName); if(ext.compare(Ebsd::Ang::FileExt) == 0) { AngReader reader; reader.setFileName(ebsdFName); reader.setReadHexGrid(true); int err = reader.readFile(); if(err < 0 && err != -600) { addErrorMessage(getHumanLabel(), reader.getErrorMessage(), reader.getErrorCode()); setErrorCondition(reader.getErrorCode()); return; } else if(reader.getGrid().find(Ebsd::Ang::SquareGrid) == 0) { ss.str(""); ss << "Ang File is already a square grid: " << ebsdFName; setErrorCondition(-55000); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); return; } else { if (err == -600) { notifyWarningMessage( reader.getErrorMessage(), reader.getErrorCode() ); } std::string origHeader = reader.getOriginalHeader(); if (origHeader.empty() == true) { ss.str(); ss << "Header could not be retrieved: " << ebsdFName; setErrorCondition(-55001); addErrorMessage(getHumanLabel(), ss.str(), getErrorCondition()); } char buf[kBufferSize]; std::stringstream in(origHeader); std::string newEbsdFName = path + "/Sqr_" + base + "." + ext; std::ofstream outFile; outFile.open(newEbsdFName.c_str()); m_HeaderIsComplete = false; float HexXStep = reader.getXStep(); float HexYStep = reader.getYStep(); int HexNumColsOdd = reader.getNumOddCols(); int HexNumColsEven = reader.getNumEvenCols(); int HexNumRows = reader.getNumRows(); m_NumCols = (HexNumColsOdd*HexXStep)/m_XResolution; m_NumRows = (HexNumRows*HexYStep)/m_YResolution; float xSqr, ySqr, xHex1, yHex1, xHex2, yHex2; int point, point1, point2; int row1, row2, col1, col2; float dist1, dist2; float* phi1 = reader.getPhi1Pointer(); float* PHI = reader.getPhiPointer(); float* phi2 = reader.getPhi2Pointer(); float* ci = reader.getConfidenceIndexPointer(); float* iq = reader.getImageQualityPointer(); float* semsig = reader.getSEMSignalPointer(); float* fit = reader.getFitPointer(); int* phase = reader.getPhaseDataPointer(); while (!in.eof()) { std::string line; ::memset(buf, 0, kBufferSize); in.getline(buf, kBufferSize); line = modifyAngHeaderLine(buf, kBufferSize); if(m_HeaderIsComplete == false) outFile << line << std::endl; } for(int j = 0; j < m_NumRows; j++) { for(int i = 0; i < m_NumCols; i++) { xSqr = float(i)*m_XResolution; ySqr = float(j)*m_YResolution; row1 = ySqr/(HexYStep); yHex1 = row1*HexYStep; row2 = row1 + 1; yHex2 = row2*HexYStep; if(row1%2 == 0) { col1 = xSqr/(HexXStep); xHex1 = col1*HexXStep; point1 = ((row1/2)*HexNumColsEven) + ((row1/2)*HexNumColsOdd) + col1; col2 = (xSqr-(HexXStep/2.0))/(HexXStep); xHex2 = col2*HexXStep + (HexXStep/2.0); point2 = ((row1/2)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col2; } else { col1 = (xSqr-(HexXStep/2.0))/(HexXStep); xHex1 = col1*HexXStep + (HexXStep/2.0); point1 = ((row1/2)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col1; col2 = xSqr/(HexXStep); xHex2 = col2*HexXStep; point2 = (((row1/2)+1)*HexNumColsEven) + (((row1/2)+1)*HexNumColsOdd) + col2; } dist1 = ((xSqr-xHex1)*(xSqr-xHex1)) + ((ySqr-yHex1)*(ySqr-yHex1)); dist2 = ((xSqr-xHex2)*(xSqr-xHex2)) + ((ySqr-yHex2)*(ySqr-yHex2)); if(dist1 <= dist2 || row1 == (HexNumRows-1)) {point = point1;} else {point = point2;} outFile << " " << phi1[point] << " " << PHI[point] << " " << phi2[point] << " " << xSqr << " " << ySqr << " " << iq[point] << " " << ci[point] << " " << phase[point] << " " << semsig[point] << " " << fit[point] << " " << std::endl; } } } } else if(ext.compare(Ebsd::Ctf::FileExt) == 0) { std::cout << "Ctf files are not on a hexagonal grid and do not need to be converted." << std::endl; } else { err = -1; ss.str(""); ss << "The File extension was not detected correctly"; addErrorMessage(getHumanLabel(), ss.str(), err); setErrorCondition(-1); return; } } notifyStatusMessage("Import Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ReadStlFile::readFile() { DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(m_SurfaceMeshDataContainerName); // Open File FILE* f = fopen(m_StlFilePath.toLatin1().data(), "rb"); if (NULL == f) { setErrorCondition(-1003); notifyErrorMessage(getHumanLabel(), "Error opening STL file", -1003); return; } // Read Header char h[80]; int32_t triCount = 0; fread(h, sizeof(int32_t), 20, f); fread(&triCount, sizeof(int32_t), 1, f); TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>(); triangleGeom->resizeTriList(triCount); triangleGeom->resizeVertexList(triCount * 3); float* nodes = triangleGeom->getVertexPointer(0); int64_t* triangles = triangleGeom->getTriPointer(0); // Resize the triangle attribute matrix to hold the normals and update the normals pointer QVector<size_t> tDims(1, triCount); sm->getAttributeMatrix(getFaceAttributeMatrixName())->resizeAttributeArrays(tDims); updateFaceInstancePointers(); // Read the triangles static const size_t k_StlElementCount = 12; float v[k_StlElementCount]; unsigned short attr; for (int32_t t = 0; t < triCount; ++t) { fread(reinterpret_cast<void*>(v), sizeof(float), k_StlElementCount, f); fread(reinterpret_cast<void*>(&attr), sizeof(unsigned short), 1, f); if (attr > 0) { std::vector<unsigned char> buffer(attr); // Allocate a buffer for the STL attribute data to be placed into fread( reinterpret_cast<void*>(&(buffer.front())), attr, 1, f); // Read the bytes into the buffer so that we can skip it. } if(v[3] < m_minXcoord) { m_minXcoord = v[3]; } if(v[3] > m_maxXcoord) { m_maxXcoord = v[3]; } if(v[4] < m_minYcoord) { m_minYcoord = v[4]; } if(v[4] > m_maxYcoord) { m_maxYcoord = v[4]; } if(v[5] < m_minZcoord) { m_minZcoord = v[5]; } if(v[5] > m_maxZcoord) { m_maxZcoord = v[5]; } if(v[6] < m_minXcoord) { m_minXcoord = v[6]; } if(v[6] > m_maxXcoord) { m_maxXcoord = v[6]; } if(v[7] < m_minYcoord) { m_minYcoord = v[7]; } if(v[7] > m_maxYcoord) { m_maxYcoord = v[7]; } if(v[8] < m_minZcoord) { m_minZcoord = v[8]; } if(v[8] > m_maxZcoord) { m_maxZcoord = v[8]; } if(v[9] < m_minXcoord) { m_minXcoord = v[9]; } if(v[9] > m_maxXcoord) { m_maxXcoord = v[9]; } if(v[10] < m_minYcoord) { m_minYcoord = v[10]; } if(v[10] > m_maxYcoord) { m_maxYcoord = v[10]; } if(v[11] < m_minZcoord) { m_minZcoord = v[11]; } if(v[11] > m_maxZcoord) { m_maxZcoord = v[11]; } m_FaceNormals[3 * t + 0] = v[0]; m_FaceNormals[3 * t + 1] = v[1]; m_FaceNormals[3 * t + 2] = v[2]; nodes[3 * (3 * t + 0) + 0] = v[3]; nodes[3 * (3 * t + 0) + 1] = v[4]; nodes[3 * (3 * t + 0) + 2] = v[5]; nodes[3 * (3 * t + 1) + 0] = v[6]; nodes[3 * (3 * t + 1) + 1] = v[7]; nodes[3 * (3 * t + 1) + 2] = v[8]; nodes[3 * (3 * t + 2) + 0] = v[9]; nodes[3 * (3 * t + 2) + 1] = v[10]; nodes[3 * (3 * t + 2) + 2] = v[11]; triangles[t * 3] = 3 * t + 0; triangles[t * 3 + 1] = 3 * t + 1; triangles[t * 3 + 2] = 3 * t + 2; } return; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void MoveData::dataCheck() { setErrorCondition(0); DataArrayPath amSrcPath = getAttributeMatrixSource(); DataArrayPath amDestPath = getAttributeMatrixDestination(); DataArrayPath daSrcPath = getDataArraySource(); if (getWhatToMove() == k_MoveAttributeMatrix) { DataContainer::Pointer amDestDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getDataContainerDestination()); DataContainer::Pointer amSrcDataContainer = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, amSrcPath.getDataContainerName()); AttributeMatrix::Pointer amSrcAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, amSrcPath, -301); if(getErrorCondition() < 0) { return; } if (amSrcDataContainer->getName() == amDestDataContainer->getName()) { QString ss = QObject::tr("The source and destination Data Container are the same. Is this what you meant to do?"); notifyWarningMessage(getHumanLabel(), ss, getErrorCondition()); return; } amDestDataContainer->addAttributeMatrix(amSrcAttributeMatrix->getName(), amSrcAttributeMatrix); amSrcDataContainer->removeAttributeMatrix(amSrcAttributeMatrix->getName()); } else if (getWhatToMove() == k_MoveDataArray ) { AttributeMatrix::Pointer daSrcAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, daSrcPath, -301); AttributeMatrix::Pointer daDestAttributeMatrix = getDataContainerArray()->getPrereqAttributeMatrixFromPath<AbstractFilter>(this, amDestPath, -301); IDataArray::Pointer daSrcDataArray = getDataContainerArray()->getPrereqIDataArrayFromPath<IDataArray, AbstractFilter>(this, daSrcPath); if(getErrorCondition() < 0) { return; } if (daDestAttributeMatrix->getNumTuples() != daSrcDataArray->getNumberOfTuples()) { setErrorCondition(-11019); QString ss = QObject::tr("The number of tuples of source Attribute Array (%1) and destination Attribute Matrix (%2) do not match").arg(daSrcDataArray->getNumberOfTuples()).arg(daDestAttributeMatrix->getNumTuples()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } else if (daSrcAttributeMatrix->getName() == daDestAttributeMatrix->getName()) { QString ss = QObject::tr("The source and destination Attribute Matrix are the same. Is this what you meant to do?"); notifyWarningMessage(getHumanLabel(), ss, getErrorCondition()); return; } daDestAttributeMatrix->addAttributeArray(daSrcPath.getDataArrayName(), daSrcDataArray); daSrcAttributeMatrix->removeAttributeArray(daSrcPath.getDataArrayName()); } else { setErrorCondition(-11020); QString ss = QObject::tr("Neither an Attribute Matrix nor an Attribute Array was selected to be moved"); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t AbaqusSurfaceMeshWriter::writeFeatures(FILE* f) { //*Elset, elset=Feature1 //1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 int32_t err = 0; TriangleGeom::Pointer triangleGeo = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); int64_t nTriangles = triangleGeo->getNumberOfTris(); // Store all the unique Spins std::set<int32_t> uniqueSpins; for (int64_t i = 0; i < nTriangles; i++) { uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2]); uniqueSpins.insert(m_SurfaceMeshFaceLabels[i * 2 + 1]); } int32_t spin = 0; //Loop over the unique Spins for (std::set<int32_t>::iterator spinIter = uniqueSpins.begin(); spinIter != uniqueSpins.end(); ++spinIter ) { spin = *spinIter; if (spin < 0) { continue; } fprintf(f, "*ELSET, ELSET=Feature%d\n", spin); { QString ss = QObject::tr("Writing ELSET for Feature Id %1").arg(spin); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); } // Loop over all the triangles for this spin int64_t lineCount = 0; for (int64_t t = 0; t < nTriangles; ++t) { if (m_SurfaceMeshFaceLabels[t * 2] != spin && m_SurfaceMeshFaceLabels[t * 2 + 1] != spin) { continue; // We do not match either spin so move to the next triangle } // Only print 15 Triangles per line if (lineCount == 15) { fprintf (f, ", %lld\n", (long long int)(t)); lineCount = 0; } else if(lineCount == 0) // First value on the line { fprintf(f, "%lld", (long long int)(t)); lineCount++; } else { fprintf(f, ", %lld", (long long int)(t)); lineCount++; } } // Make sure we have a new line at the end of the section if (lineCount != 0) { fprintf(f, "\n"); } } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t LaplacianSmoothing::edgeBasedSmoothing() { int32_t err = 0; DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceDataContainerName()); IGeometry2D::Pointer surfaceMesh = sm->getGeometryAs<IGeometry2D>(); float* verts = surfaceMesh->getVertexPointer(0); int64_t nvert = surfaceMesh->getNumberOfVertices(); // Generate the Lambda Array err = generateLambdaArray(); if (err < 0) { setErrorCondition(-557); notifyErrorMessage(getHumanLabel(), "Error generating the lambda array", getErrorCondition()); return err; } // Get a Pointer to the Lambda array for conveneince DataArray<float>::Pointer lambdas = getLambdaArray(); float* lambda = lambdas->getPointer(0); // Generate the Unique Edges if (NULL == surfaceMesh->getEdges().get()) { err = surfaceMesh->findEdges(); } if (err < 0) { setErrorCondition(-560); notifyErrorMessage(getHumanLabel(), "Error retrieving the shared edge list", getErrorCondition()); return getErrorCondition(); } int64_t* uedges = surfaceMesh->getEdgePointer(0); int64_t nedges = surfaceMesh->getNumberOfEdges(); DataArray<int32_t>::Pointer numConnections = DataArray<int32_t>::CreateArray(nvert, "_INTERNAL_USE_ONLY_Laplacian_Smoothing_NumberConnections_Array"); numConnections->initializeWithZeros(); int32_t* ncon = numConnections->getPointer(0); QVector<size_t> cDims(1, 3); DataArray<double>::Pointer deltaArray = DataArray<double>::CreateArray(nvert, cDims, "_INTERNAL_USE_ONLY_Laplacian_Smoothing_Delta_Array"); deltaArray->initializeWithZeros(); double* delta = deltaArray->getPointer(0); double dlta = 0.0; for (int32_t q = 0; q < m_IterationSteps; q++) { if (getCancel() == true) { return -1; } QString ss = QObject::tr("Iteration %1").arg(q); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); for (int64_t i = 0; i < nedges; i++) { int64_t in1 = uedges[2 * i]; // row of the first vertex int64_t in2 = uedges[2 * i + 1]; // row the second vertex for (int32_t j = 0; j < 3; j++) { BOOST_ASSERT( static_cast<size_t>(3 * in1 + j) < static_cast<size_t>(nvert * 3) ); BOOST_ASSERT( static_cast<size_t>(3 * in2 + j) < static_cast<size_t>(nvert * 3) ); dlta = verts[3 * in2 + j] - verts[3 * in1 + j]; delta[3 * in1 + j] += dlta; delta[3 * in2 + j] += -1.0 * dlta; } ncon[in1] += 1; ncon[in2] += 1; } float ll = 0.0f; for (int64_t i = 0; i < nvert; i++) { for (int32_t j = 0; j < 3; j++) { int64_t in0 = 3 * i + j; dlta = delta[in0] / ncon[i]; ll = lambda[i]; verts[3 * i + j] += ll * dlta; delta[in0] = 0.0; // reset for next iteration } ncon[i] = 0; // reset for next iteration } } return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindFaceAverage::dataCheckSurfaceMesh(bool preflight, size_t voxels, size_t fields, size_t ensembles) { setErrorCondition(0); std::stringstream ss; SurfaceMeshDataContainer* sm = getSurfaceMeshDataContainer(); if(NULL == sm) { addErrorMessage(getHumanLabel(), "SurfaceMeshDataContainer is missing", -383); setErrorCondition(-383); } else { // We MUST have Triangles defined. if(sm->getFaces().get() == NULL) { addErrorMessage(getHumanLabel(), "SurfaceMesh DataContainer missing Triangles", -385); setErrorCondition(-385); } else { GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshGrainFaceId, ss, -387, int32_t, Int32ArrayType, fields, 1) if(1==m_AverageMethod) { GET_PREREQ_DATA(sm, DREAM3D, FaceData, SurfaceMeshTriangleAreas, ss, -387, double, DoubleArrayType, fields, 1) } if(m_SelectedFaceArrayName.empty() == true) { setErrorCondition(-11000); addErrorMessage(getHumanLabel(), "An array from the Face Data Container must be selected.", getErrorCondition()); } else if(preflight) { IDataArray::Pointer inputData = sm->getFaceData(m_SelectedFaceArrayName); if (NULL == inputData.get()) { ss.str(""); ss << "Selected array '" << m_SelectedFaceArrayName << "' does not exist in the Surface Mesh Data Container. Was it spelled correctly?"; setErrorCondition(-11001); notifyErrorMessage(ss.str(), getErrorCondition()); return; } int numberOfComponents = inputData->GetNumberOfComponents(); std::string dType = inputData->getTypeAsString(); IDataArray::Pointer p = IDataArray::NullPointer(); if (dType.compare("int8_t") == 0) { p = Int8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint8_t") == 0) { p = UInt8ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int16_t") == 0) { p = Int16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint16_t") == 0) { p = UInt16ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int32_t") == 0) { p = Int32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint32_t") == 0) { p = UInt32ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("int64_t") == 0) { p = Int64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("uint64_t") == 0) { p = UInt64ArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("float") == 0) { p = FloatArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("double") == 0) { p = DoubleArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } else if (dType.compare("bool") == 0) { p = BoolArrayType::CreateArray(1, numberOfComponents, m_SelectedFaceArrayName); } sm->addFieldData(p->GetName(), p); } } }
void LaplacianSmoothing::writeVTKFile(const QString& outputVtkFile) { DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceDataContainerName()); /* Place all your code to execute your filter here. */ VertexArray& nodes = *(sm->getVertices()); int nNodes = nodes.getNumberOfTuples(); bool m_WriteBinaryFile = true; FILE* vtkFile = NULL; vtkFile = fopen(outputVtkFile.toLatin1().data(), "wb"); if (NULL == vtkFile) { setErrorCondition(-90123); QString ss = QObject::tr("Error creating file '%1'").arg(outputVtkFile); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } Detail::ScopedFileMonitor vtkFileMonitor(vtkFile); fprintf(vtkFile, "# vtk DataFile Version 2.0\n"); fprintf(vtkFile, "Data set from DREAM.3D Surface Meshing Module\n"); if (m_WriteBinaryFile) { fprintf(vtkFile, "BINARY\n"); } else { fprintf(vtkFile, "ASCII\n"); } fprintf(vtkFile, "DATASET POLYDATA\n"); fprintf(vtkFile, "POINTS %d float\n", nNodes); float pos[3] = {0.0f, 0.0f, 0.0f}; size_t totalWritten = 0; // Write the POINTS data (Vertex) for (int i = 0; i < nNodes; i++) { VertexArray::Vert_t& n = nodes[i]; // Get the current Node // if (m_SurfaceMeshNodeType[i] > 0) { pos[0] = static_cast<float>(n.pos[0]); pos[1] = static_cast<float>(n.pos[1]); pos[2] = static_cast<float>(n.pos[2]); if (m_WriteBinaryFile == true) { DREAM3D::Endian::FromSystemToBig::convert<float>(pos[0]); DREAM3D::Endian::FromSystemToBig::convert<float>(pos[1]); DREAM3D::Endian::FromSystemToBig::convert<float>(pos[2]); totalWritten = fwrite(pos, sizeof(float), 3, vtkFile); if (totalWritten != sizeof(float) * 3) { } } else { fprintf(vtkFile, "%4.4f %4.4f %4.4f\n", pos[0], pos[1], pos[2]); // Write the positions to the output file } } } // Write the triangle indices into the vtk File FaceArray& triangles = *(sm->getFaces()); int triangleCount = 0; int end = triangles.getNumberOfTuples(); int featureInterest = 9; for(int i = 0; i < end; ++i) { //FaceArray::Face_t* tri = triangles.getPointer(i); if (m_SurfaceMeshFaceLabels[i * 2] == featureInterest || m_SurfaceMeshFaceLabels[i * 2 + 1] == featureInterest) { ++triangleCount; } } int tData[4]; // Write the CELLS Data // int start = 3094380; // int end = 3094450; // int triangleCount = end - start; qDebug() << "---------------------------------------------------------------------------" << "\n"; qDebug() << outputVtkFile << "\n"; fprintf(vtkFile, "\nPOLYGONS %d %d\n", triangleCount, (triangleCount * 4)); for (int tid = 0; tid < end; ++tid) { //FaceArray::Face_t* tri = triangles.getPointer(tid); if (m_SurfaceMeshFaceLabels[tid * 2] == featureInterest || m_SurfaceMeshFaceLabels[tid * 2 + 1] == featureInterest) { tData[1] = triangles[tid].verts[0]; tData[2] = triangles[tid].verts[1]; tData[3] = triangles[tid].verts[2]; // qDebug() << tid << "\n " << nodes[tData[1]].coord[0] << " " << nodes[tData[1]].coord[1] << " " << nodes[tData[1]].coord[2] << "\n"; // qDebug() << " " << nodes[tData[2]].coord[0] << " " << nodes[tData[2]].coord[1] << " " << nodes[tData[2]].coord[2] << "\n"; // qDebug() << " " << nodes[tData[3]].coord[0] << " " << nodes[tData[3]].coord[1] << " " << nodes[tData[3]].coord[2] << "\n"; if (m_WriteBinaryFile == true) { tData[0] = 3; // Push on the total number of entries for this entry DREAM3D::Endian::FromSystemToBig::convert<int>(tData[0]); DREAM3D::Endian::FromSystemToBig::convert<int>(tData[1]); // Index of Vertex 0 DREAM3D::Endian::FromSystemToBig::convert<int>(tData[2]); // Index of Vertex 1 DREAM3D::Endian::FromSystemToBig::convert<int>(tData[3]); // Index of Vertex 2 fwrite(tData, sizeof(int), 4, vtkFile); } else { fprintf(vtkFile, "3 %d %d %d\n", tData[1], tData[2], tData[3]); } } } fprintf(vtkFile, "\n"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CombineAttributeMatrices::dataCheck() { setErrorCondition(0); DataArrayPath tempPath; DataContainer::Pointer m = getDataContainerArray()->getPrereqDataContainer<AbstractFilter>(this, getFirstAttributeMatrixPath().getDataContainerName(), false); if (getErrorCondition() < 0 || NULL == m.get()) { return; } if (getFirstAttributeMatrixPath().getDataContainerName().compare(getSecondAttributeMatrixPath().getDataContainerName()) != 0) { QString ss = QObject::tr("The selected attribute matrices must be in the same data container and currently are not"); setErrorCondition(-5557); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (getFirstAttributeMatrixPath().getAttributeMatrixName().compare(getSecondAttributeMatrixPath().getAttributeMatrixName()) == 0) { QString ss = QObject::tr("The selected attribute matrices must be different and currently are the same"); setErrorCondition(-5558); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } AttributeMatrix::Pointer firstAttrMat = m->getPrereqAttributeMatrix(this, getFirstAttributeMatrixPath().getAttributeMatrixName(), -301); AttributeMatrix::Pointer secondAttrMat = m->getPrereqAttributeMatrix(this, getSecondAttributeMatrixPath().getAttributeMatrixName(), -301); if (getErrorCondition() < 0) { return; } if (firstAttrMat->getType() != secondAttrMat->getType()) { QString ss = QObject::tr("The selected attribute matrices must be of the same type (ie Feature) and currently are not"); setErrorCondition(-5559); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } if (getErrorCondition() < 0) { return; } //Note that the minus 1 in the totalTuples calculation is to account for the fact that the zeroth tuple in the two attribute matrices should only be counted once, not twice. //All Feature or Ensemble AMs should start from 1 and the zeroth tuple can be combined in the two AMs size_t totalTuples = firstAttrMat->getNumTuples() + secondAttrMat->getNumTuples() - 1; QVector<size_t> tDims(1, totalTuples); m->createNonPrereqAttributeMatrix<AbstractFilter>(this, getCombinedAttributeMatrixName(), tDims, firstAttrMat->getType()); if (getErrorCondition() < 0) { return; } AttributeMatrix::Pointer combinedAttrMat = m->getAttributeMatrix(getCombinedAttributeMatrixName()); QVector<size_t> cDims(1, 1); m_FirstIndexPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getFirstIndexArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_FirstIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_FirstIndex = m_FirstIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } m_SecondIndexPtr = getDataContainerArray()->getPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter>(this, getSecondIndexArrayPath(), cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_SecondIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_SecondIndex = m_SecondIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } // Create arrays on the reference grid to hold data present on the sampling grid QList<QString> fArrayNames = firstAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = fArrayNames.begin(); iter != fArrayNames.end(); ++iter) { tempPath.update(getFirstAttributeMatrixPath().getDataContainerName(), getCombinedAttributeMatrixName(), *iter); IDataArray::Pointer tmpDataArray = firstAttrMat->getPrereqIDataArray<IDataArray, AbstractFilter>(this, *iter, -90001); if (getErrorCondition() >= 0) { QVector<size_t> cDims = tmpDataArray->getComponentDimensions(); TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, cDims, tmpDataArray); } } QList<QString> sArrayNames = secondAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = sArrayNames.begin(); iter != sArrayNames.end(); ++iter) { tempPath.update(getSecondAttributeMatrixPath().getDataContainerName(), getCombinedAttributeMatrixName(), *iter); IDataArray::Pointer tmpDataArray = secondAttrMat->getPrereqIDataArray<IDataArray, AbstractFilter>(this, *iter, -90001); if (getErrorCondition() >= 0) { if (fArrayNames.contains(*iter) == false) { QVector<size_t> cDims = tmpDataArray->getComponentDimensions(); TemplateHelpers::CreateNonPrereqArrayFromArrayType()(this, tempPath, cDims, tmpDataArray); } } } tempPath.update(getFirstIndexArrayPath().getDataContainerName(), getFirstIndexArrayPath().getAttributeMatrixName(), getNewIndexArrayName()); m_NewIndexPtr = getDataContainerArray()->createNonPrereqArrayFromPath<DataArray<int32_t>, AbstractFilter, int32_t>(this, tempPath, 0, cDims); /* Assigns the shared_ptr<> to an instance variable that is a weak_ptr<> */ if (NULL != m_NewIndexPtr.lock().get()) /* Validate the Weak Pointer wraps a non-NULL pointer to a DataArray<T> object */ { m_NewIndex = m_NewIndexPtr.lock()->getPointer(0); } /* Now assign the raw pointer to data from the DataArray<T> object */ if (getErrorCondition() < 0) { return; } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void EmptyFilter::dataCheck() { QString ss = QObject::tr("This filter does nothing and was was inserted as a place holder for filter '%1' that does not exist anymore.").arg(getOriginalFilterName()); setErrorCondition(-9999); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); }