// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeAngleRepresentation::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } int64_t totalPoints = static_cast<int64_t>(m_CellEulerAnglesPtr.lock()->getNumberOfTuples()); #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif float conversionFactor = 1.0f; if (m_ConversionType == DREAM3D::EulerAngleConversionType::DegreesToRadians) { conversionFactor = static_cast<float>( M_PI / 180.0f ); } else if (conversionFactor == DREAM3D::EulerAngleConversionType::RadiansToDegrees) { conversionFactor = static_cast<float>( 180.0f / M_PI ); } totalPoints *= 3; // qDebug() << "ChangeAngleRepresentation: " << m_ConversionFactor << "\n"; #ifdef DREAM3D_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(0, totalPoints), ChangeAngleRepresentationImpl(m_CellEulerAngles, conversionFactor), tbb::auto_partitioner()); } else #endif { ChangeAngleRepresentationImpl serial(m_CellEulerAngles, conversionFactor); serial.convert(0, totalPoints); } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InitializeData::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_CellAttributeMatrixPath.getDataContainerName()); 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]), }; int index; QString attrMatName = m_CellAttributeMatrixPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); for (int32_t k = m_ZMin; k < m_ZMax + 1; k++) { for (int32_t j = m_YMin; j < m_YMax + 1; j++) { for (int32_t i = m_XMin; i < m_XMax + 1; i++) { index = (k * dims[0] * dims[1]) + (j * dims[0]) + i; for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); p->initializeTuple(index, 0); } } } } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GroupMicroTextureRegions::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Convert user defined tolerance to radians. caxisTolerance = m_CAxisTolerance * SIMPLib::Constants::k_Pi / 180.0f; avgCaxes[0] = 0.0f; avgCaxes[1] = 0.0f; avgCaxes[2] = 0.0f; GroupFeatures::execute(); size_t totalFeatures = m_ActivePtr.lock()->getNumberOfTuples(); if (totalFeatures < 2) { setErrorCondition(-87000); notifyErrorMessage(getHumanLabel(), "The number of grouped Features was 0 or 1 which means no grouped Features were detected. A grouping value may be set too high", getErrorCondition()); return; } int64_t totalPoints = static_cast<int64_t>(m_FeatureIdsPtr.lock()->getNumberOfTuples()); for (int64_t k = 0; k < totalPoints; k++) { int32_t featurename = m_FeatureIds[k]; m_CellParentIds[k] = m_FeatureParentIds[featurename]; } // By default we randomize grains if (true == m_RandomizeParentIds) { randomizeFeatureIds(totalPoints, totalFeatures); } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindCellQuats::execute() { setErrorCondition(0); VoxelDataContainer* m = getVoxelDataContainer(); if(NULL == m) { setErrorCondition(-999); notifyErrorMessage("The DataContainer Object was NULL", -999); return; } setErrorCondition(0); std::stringstream ss; int64_t totalPoints = m->getTotalPoints(); size_t totalFields = m->getNumFieldTuples(); size_t totalEnsembles = m->getNumEnsembleTuples(); dataCheck(false, totalPoints, totalFields, totalEnsembles); if (getErrorCondition() < 0) { return; } QuatF* quats = reinterpret_cast<QuatF*>(m_Quats); QuatF qr; int phase = -1; for (int i = 0; i < totalPoints; i++) { phase = m_CellPhases[i]; OrientationMath::EulertoQuat(qr, m_CellEulerAngles[3 * i], m_CellEulerAngles[3 * i + 1], m_CellEulerAngles[3 * i + 2]); QuaternionMathF::UnitQuaternion(qr); if (m_CrystalStructures[phase] == Ebsd::CrystalStructure::UnknownCrystalStructure) { QuaternionMathF::Identity(qr); } QuaternionMathF::Copy(qr, quats[i]); } notifyStatusMessage("Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AvizoUniformCoordinateWriter::execute() { int err = 0; setErrorCondition(err); 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(m_OutputFile); QString parentPath = fi.path(); QDir dir; if(!dir.mkpath(parentPath)) { QString ss = QObject::tr("Error creating parent path '%1'").arg(parentPath); setErrorCondition(-1); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QFile writer(getOutputFile()); if (!writer.open(QIODevice::WriteOnly | QIODevice::Text)) { QString ss = QObject::tr("Avizo Output file could not be opened: %1").arg(getOutputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } QDataStream out(&writer); generateHeader(out); err = writeData(out); /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindEllipsoidError::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); float xRes = m->getGeometryAs<ImageGeom>()->getXRes(); float yRes = m->getGeometryAs<ImageGeom>()->getYRes(); float zRes = m->getGeometryAs<ImageGeom>()->getZRes(); scaleFactor = 1.0 / xRes; if(yRes > xRes && yRes > zRes) { scaleFactor = 1.0 / yRes; } if(zRes > xRes && zRes > yRes) { scaleFactor = 1.0 / zRes; } if(m->getGeometryAs<ImageGeom>()->getXPoints() > 1 && m->getGeometryAs<ImageGeom>()->getYPoints() > 1 && m->getGeometryAs<ImageGeom>()->getZPoints() > 1) { } if(m->getGeometryAs<ImageGeom>()->getXPoints() == 1 || m->getGeometryAs<ImageGeom>()->getYPoints() == 1 || m->getGeometryAs<ImageGeom>()->getZPoints() == 1) {find_error2D();} notifyStatusMessage(getHumanLabel(), "FindEllipsoidError Completed"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ExtractFlaggedFeatures::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } size_t totalFeatures = m_FlaggedFeaturesPtr.lock()->getNumberOfTuples(); find_feature_bounds(); QString newDCName = ""; CropImageGeometry::Pointer cropVol = CropImageGeometry::New(); for(size_t i = 1; i < totalFeatures; i++) { if(m_FlaggedFeatures[i] == true) { newDCName.clear(); newDCName = "Feature_" + QString::number(i); cropVol->setDataContainerArray(getDataContainerArray()); cropVol->setNewDataContainerName(newDCName); cropVol->setCellAttributeMatrixPath(m_FeatureIdsArrayPath); cropVol->setXMin(m_FeatureBounds[6 * i]); cropVol->setXMax(m_FeatureBounds[6 * i + 1]); cropVol->setYMin(m_FeatureBounds[6 * i + 2]); cropVol->setYMax(m_FeatureBounds[6 * i + 3]); cropVol->setZMin(m_FeatureBounds[6 * i + 4]); cropVol->setZMax(m_FeatureBounds[6 * i + 5]); cropVol->setRenumberFeatures(false); cropVol->setSaveAsNewDataContainer(true); cropVol->setUpdateOrigin(true); cropVol->execute(); } } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ClearDataMask::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_MaskArrayPath.getDataContainerName()); size_t totalPoints = m_MaskPtr.lock()->getNumberOfTuples(); // get list of array names QString attrMatName = m_MaskArrayPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); // convert to list of pointers std::vector<IDataArray::Pointer> arrayList; for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); arrayList.push_back(p); } int32_t numArrays = arrayList.size(); for (size_t i = 0; i < totalPoints; i++) { if (!m_Mask[i]) { for (int32_t j = 0; j < numArrays; j++) { arrayList[j]->initializeTuple(i, 0); } } } notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t SPParksWriter::writeHeader() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); size_t udims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(udims); size_t totalpoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); std::ofstream outfile; outfile.open(getOutputFile().toLatin1().data(), std::ios_base::binary); if (!outfile) { QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } outfile << "-" << "\n"; outfile << "3 dimension" << "\n"; outfile << totalpoints << " sites" << "\n"; outfile << "26 max neighbors" << "\n"; outfile << "0 " << udims[0] << " xlo xhi" << "\n"; outfile << "0 " << udims[1] << " ylo yhi" << "\n"; outfile << "0 " << udims[2] << " zlo zhi" << "\n"; outfile << "\n"; outfile << "Values" << "\n"; outfile << "\n"; outfile.close(); return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GenerateGeometryConnectivity::execute() { int32_t err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceDataContainerName()); IGeometry::Pointer geom = sm->getGeometry(); if (m_GenerateVertexTriangleLists == true || m_GenerateTriangleNeighbors == true) { notifyStatusMessage(getHumanLabel(), "Generating Vertex Element List"); err = geom->findElementsContainingVert(); if (err < 0) { setErrorCondition(-400); QString ss = QObject::tr("Error generating vertex element list for Geometry type %1").arg(geom->getGeometryTypeAsString()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } } if (m_GenerateTriangleNeighbors == true) { notifyStatusMessage(getHumanLabel(), "Generating Element Neighbors List"); err = geom->findElementNeighbors(); if (err < 0) { setErrorCondition(-401); QString ss = QObject::tr("Error generating element neighbor list for Geometry type %1").arg(geom->getGeometryTypeAsString()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t EnsembleInfoReader::readFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); AttributeMatrix::Pointer cellensembleAttrMat = m->getAttributeMatrix(getCellEnsembleAttributeMatrixName()); int32_t numphases = 0; QSettings settings(getInputFile(), QSettings::IniFormat); // The .ini or .txt input file settings.beginGroup("EnsembleInfo"); numphases = settings.value("Number_Phases").toInt(); // read number of phases from input file settings.endGroup(); if (0 == numphases) // Either the group name "EnsembleInfo" is incorrect or 0 was entered as the Number_Phases { QString ss = QObject::tr("Check the group name EnsembleInfo and that Number_Phases > 0"); setErrorCondition(-10003); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } // Figure out if we are reading contiguous groups std::vector<bool> visited(numphases + 1, false); visited[0] = true; //this is DREAM3D's internal, which is always visited. QVector<size_t> tDims(1, numphases + 1); cellensembleAttrMat->resizeAttributeArrays(tDims); updateEnsembleInstancePointers(); for (int32_t index = 1; index < numphases + 1; index++) { QString group = QString::number(index); settings.beginGroup(group); QString xtalString = settings.value(DREAM3D::StringConstants::CrystalStructure, "MissingCrystalStructure").toString(); QString phaseTypeString = settings.value(DREAM3D::StringConstants::PhaseType, "MissingPhaseType").toString(); // Check to make sure the user has something for each of the Crystal Structure and Phase Type if (xtalString.compare("MissingCrystalStructure") == 0) { QString ss = QObject::tr("Missing crystal structure for phase '%1'").arg(group); setErrorCondition(-10008); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } if (phaseTypeString.compare("MissingPhaseType") == 0) { QString ss = QObject::tr("Missing phase type for phase '%1'").arg(group); setErrorCondition(-10009); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } // Past that sanity check, so we have values, lets parse them QStringList values; values << xtalString << phaseTypeString; ensembleLookup(values); // Lookup number for the crystal number string and the phase type string read from the file // Check to see if the Crystal Structure string was valid if (m_crystruct == Ebsd::CrystalStructure::UnknownCrystalStructure) // The crystal structure name read from the file was not found in the lookup table { QString ss = QObject::tr("Incorrect crystal structure name '%1'").arg(xtalString); setErrorCondition(-10006); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } else { m_CrystalStructures[index] = m_crystruct; } // now check to see if the Phase type string was valid. if (m_ptype == DREAM3D::PhaseType::UnknownPhaseType) { QString ss = QObject::tr("Incorrect phase type name '%1'").arg(phaseTypeString); // The phase type name read from the file was not found in the lookup table setErrorCondition(-10007); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } else { m_PhaseTypes[index] = m_ptype; } visited[index] = true; // Close up this group settings.endGroup(); } //Make sure we visited all the groups. for(std::vector<bool>::size_type i = 0; i < visited.size(); i++) { if(visited[i] == false) { QString ss = QObject::tr("Phase '%1' did not have entries in the file. Phase numbering must start at 1 and no phases may be skipped").arg(i); // The phase type name read from the file was not found in the lookup table setErrorCondition(-10005); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return -1; } } notifyStatusMessage(getHumanLabel(), "Complete"); return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void InsertAtoms::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } // Validate that the selected AvgQuats array 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 numFeaturesIn = static_cast<int32_t>(m_AvgQuatsPtr.lock()->getNumberOfTuples()); bool mismatchedFeatures = true; int32_t largestFeature = 0; size_t numTuples = m_SurfaceMeshFaceLabelsPtr.lock()->getNumberOfTuples(); for (size_t i = 0; i < numTuples; i++) { if (m_SurfaceMeshFaceLabels[2 * i] > largestFeature) { largestFeature = m_SurfaceMeshFaceLabels[2 * i]; if (largestFeature >= numFeaturesIn) { mismatchedFeatures = true; break; } } else if (m_SurfaceMeshFaceLabels[2 * i + 1] > largestFeature) { largestFeature = m_SurfaceMeshFaceLabels[2 * i + 1]; if (largestFeature >= numFeaturesIn) { mismatchedFeatures = true; break; } } } if (mismatchedFeatures == true) { QString ss = QObject::tr("The number of Features in the AvgQuats array (%1) is larger than the largest Feature Id in the SurfaceMeshFaceLabels array").arg(numFeaturesIn); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } if (largestFeature != (numFeaturesIn - 1)) { QString ss = QObject::tr("The number of Features in the AvgQuats array (%1) does not match the largest Feature Id in the SurfaceMeshFaceLabels array").arg(numFeaturesIn); setErrorCondition(-5555); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } FloatVec3_t latticeConstants; latticeConstants.x = m_LatticeConstants.x / 10000.0; latticeConstants.y = m_LatticeConstants.y / 10000.0; latticeConstants.z = m_LatticeConstants.z / 10000.0; DataContainer::Pointer sm = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName()); SIMPL_RANDOMNG_NEW() #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS tbb::task_scheduler_init init; bool doParallel = true; #endif // pull down faces TriangleGeom::Pointer triangleGeom = sm->getGeometryAs<TriangleGeom>(); int64_t numFaces = m_SurfaceMeshFaceLabelsPtr.lock()->getNumberOfTuples(); // create array to hold bounding vertices for each face FloatArrayType::Pointer llPtr = FloatArrayType::CreateArray(3, "Lower_Left_Internal_Use_Only"); FloatArrayType::Pointer urPtr = FloatArrayType::CreateArray(3, "Upper_Right_Internal_Use_Only"); float* ll = llPtr->getPointer(0); float* ur = urPtr->getPointer(0); VertexGeom::Pointer faceBBs = VertexGeom::CreateGeometry(2 * numFaces, "faceBBs"); // walk through faces to see how many features there are int32_t g1 = 0, g2 = 0; int32_t maxFeatureId = 0; for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > maxFeatureId) { maxFeatureId = g1; } if (g2 > maxFeatureId) { maxFeatureId = g2; } } // add one to account for feature 0 int32_t numFeatures = maxFeatureId + 1; // create a dynamic list array to hold face lists Int32Int32DynamicListArray::Pointer faceLists = Int32Int32DynamicListArray::New(); QVector<int32_t> linkCount(numFeatures, 0); // fill out lists with number of references to cells typedef boost::shared_array<int32_t> SharedInt32Array_t; SharedInt32Array_t linkLocPtr(new int32_t[numFaces]); int32_t* linkLoc = linkLocPtr.get(); ::memset(linkLoc, 0, numFaces * sizeof(int32_t)); // traverse data to determine number of faces belonging to each feature for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > 0) { linkCount[g1]++; } if (g2 > 0) { linkCount[g2]++; } } // now allocate storage for the faces faceLists->allocateLists(linkCount); // traverse data again to get the faces belonging to each feature for (int64_t i = 0; i < numFaces; i++) { g1 = m_SurfaceMeshFaceLabels[2 * i]; g2 = m_SurfaceMeshFaceLabels[2 * i + 1]; if (g1 > 0) { faceLists->insertCellReference(g1, (linkLoc[g1])++, i); } if (g2 > 0) { faceLists->insertCellReference(g2, (linkLoc[g2])++, i); } // find bounding box for each face GeometryMath::FindBoundingBoxOfFace(triangleGeom, i, ll, ur); faceBBs->setCoords(2 * i, ll); faceBBs->setCoords(2 * i + 1, ur); } // generate the list of sampling points fom subclass QVector<VertexGeom::Pointer> points(numFeatures); QVector<BoolArrayType::Pointer> inFeature(numFeatures); for (int32_t i = 0; i < numFeatures; i++) { points[i] = VertexGeom::CreateGeometry(0, "_INTERNAL_USE_ONLY_points"); inFeature[i] = BoolArrayType::CreateArray(0, "_INTERNAL_USE_ONLY_inside"); } QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); #ifdef SIMPLib_USE_PARALLEL_ALGORITHMS if (doParallel == true) { tbb::parallel_for(tbb::blocked_range<size_t>(0, numFeatures), InsertAtomsImpl(triangleGeom, faceLists, faceBBs, avgQuats, latticeConstants, m_Basis, points, inFeature), tbb::auto_partitioner()); } else #endif { InsertAtomsImpl serial(triangleGeom, faceLists, faceBBs, avgQuats, latticeConstants, m_Basis, points, inFeature); serial.checkPoints(0, numFeatures); } assign_points(points, inFeature); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ChangeResolution::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m; if(m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); } else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); } if(m->getGeometryAs<ImageGeom>()->getXRes() == m_Resolution.x && m->getGeometryAs<ImageGeom>()->getYRes() == m_Resolution.y && m->getGeometryAs<ImageGeom>()->getZRes() == m_Resolution.z) { return; } AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); size_t dims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(dims); float sizex = (dims[0]) * m->getGeometryAs<ImageGeom>()->getXRes(); float sizey = (dims[1]) * m->getGeometryAs<ImageGeom>()->getYRes(); float sizez = (dims[2]) * m->getGeometryAs<ImageGeom>()->getZRes(); size_t m_XP = size_t(sizex / m_Resolution.x); size_t m_YP = size_t(sizey / m_Resolution.y); size_t m_ZP = size_t(sizez / m_Resolution.z); if (m_XP == 0) { m_XP = 1; } if (m_YP == 0) { m_YP = 1; } if (m_ZP == 0) { m_ZP = 1; } size_t totalPoints = m_XP * m_YP * m_ZP; float x = 0.0f, y = 0.0f, z = 0.0f; size_t col = 0, row = 0, plane = 0; size_t index; size_t index_old; std::vector<size_t> newindicies(totalPoints); for (size_t i = 0; i < m_ZP; i++) { QString ss = QObject::tr("Changing Resolution - %1 Percent Complete").arg(((float)i / m->getGeometryAs<ImageGeom>()->getZPoints()) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); for (size_t j = 0; j < m_YP; j++) { for (size_t k = 0; k < m_XP; k++) { x = (k * m_Resolution.x); y = (j * m_Resolution.y); z = (i * m_Resolution.z); col = size_t(x / m->getGeometryAs<ImageGeom>()->getXRes()); row = size_t(y / m->getGeometryAs<ImageGeom>()->getYRes()); plane = size_t(z / m->getGeometryAs<ImageGeom>()->getZRes()); index_old = (plane * m->getGeometryAs<ImageGeom>()->getXPoints() * m->getGeometryAs<ImageGeom>()->getYPoints()) + (row * m->getGeometryAs<ImageGeom>()->getXPoints()) + col; index = (i * m_XP * m_YP) + (j * m_XP) + k; newindicies[index] = index_old; } } } QVector<size_t> tDims(3, 0); tDims[0] = m_XP; tDims[1] = m_YP; tDims[2] = m_ZP; AttributeMatrix::Pointer newCellAttrMat = AttributeMatrix::New(tDims, cellAttrMat->getName(), cellAttrMat->getType()); QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = cellAttrMat->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. At least in theory. IDataArray::Pointer data = p->createNewArray(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName()); data->resize(totalPoints); void* source = NULL; void* destination = NULL; size_t newIndicies_I = 0; int nComp = data->getNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++) { newIndicies_I = newindicies[i]; source = p->getVoidPointer((nComp * newIndicies_I)); destination = data->getVoidPointer((data->getNumberOfComponents() * i)); ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents()); } cellAttrMat->removeAttributeArray(*iter); newCellAttrMat->addAttributeArray(*iter, data); } m->getGeometryAs<ImageGeom>()->setResolution(m_Resolution.x, m_Resolution.y, m_Resolution.z); m->getGeometryAs<ImageGeom>()->setDimensions(m_XP, m_YP, m_ZP); m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat); // Feature Ids MUST already be renumbered. if (m_RenumberFeatures == true) { totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); AttributeMatrix::Pointer cellFeatureAttrMat = m->getAttributeMatrix(getCellFeatureAttributeMatrixPath().getAttributeMatrixName()); size_t totalFeatures = cellFeatureAttrMat->getNumTuples(); QVector<bool> activeObjects(totalFeatures, false); if (0 == totalFeatures) { notifyErrorMessage(getHumanLabel(), "The number of Features is 0 and should be greater than 0", -600); return; } updateCellInstancePointers(); // Find the unique set of feature ids for (size_t i = 0; i < totalPoints; ++i) { activeObjects[m_FeatureIds[i]] = true; } cellFeatureAttrMat->removeInactiveObjects(activeObjects, m_FeatureIdsPtr.lock()); } 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"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GenerateNodeTriangleConnectivity::preflight() { /* Place code here that sanity checks input arrays and input values. Look at some * of the other DREAM3DLib/Filters/.cpp files for sample codes */ dataCheck(true, 1, 1, 1); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void DxReader::preflight() { dataCheck(true, 1, 1, 1); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageCalculator::execute() { //int err = 0; dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath1().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath1().getAttributeMatrixName(); //wrap m_RawImageData as itk::image ImageProcessing::DefaultImageType::Pointer inputImage1 = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray1); ImageProcessing::DefaultImageType::Pointer inputImage2 = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray2); //define filters typedef itk::AddImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> AddType;// typedef itk::SubtractImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> SubtractType;// typedef itk::MultiplyImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> MultiplyType;// typedef itk::DivideImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> DivideType;// typedef itk::AndImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> AndType; typedef itk::OrImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> OrType; typedef itk::XorImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> XorType; typedef itk::MinimumImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> MinType; typedef itk::MaximumImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType> MaxType; typedef itk::BinaryFunctorImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType, ImageProcessing::Functor::Mean<ImageProcessing::DefaultPixelType> > MeanType; typedef itk::AbsoluteValueDifferenceImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> DifferenceType; //set up filters to cap image ranges typedef itk::UnaryFunctorImageFilter< ImageProcessing::FloatImageType, ImageProcessing::DefaultImageType, ImageProcessing::Functor::LimitsRound<ImageProcessing::FloatPixelType, ImageProcessing::DefaultPixelType> > LimitsRoundType; LimitsRoundType::Pointer limitsRound = LimitsRoundType::New(); //set up and run selected filter switch(m_Operator) { case 0://add { AddType::Pointer add = AddType::New(); add->SetInput1(inputImage1); add->SetInput2(inputImage2); limitsRound->SetInput(add->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 1://subtract { SubtractType::Pointer subtract = SubtractType::New(); subtract->SetInput1(inputImage1); subtract->SetInput2(inputImage2); limitsRound->SetInput(subtract->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 2://multiply { MultiplyType::Pointer multiply = MultiplyType::New(); multiply->SetInput1(inputImage1); multiply->SetInput2(inputImage2); limitsRound->SetInput(multiply->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 3://divide { DivideType::Pointer divide = DivideType::New(); divide->SetInput1(inputImage1); divide->SetInput2(inputImage2); limitsRound->SetInput(divide->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 4://and { AndType::Pointer andfilter = AndType::New(); andfilter->SetInput1(inputImage1); andfilter->SetInput2(inputImage2); ITKUtilitiesType::SetITKFilterOutput(andfilter->GetOutput(), m_NewCellArrayPtr.lock()); andfilter->Update(); } break; case 5://or { OrType::Pointer orfilter = OrType::New(); orfilter->SetInput1(inputImage1); orfilter->SetInput2(inputImage2); ITKUtilitiesType::SetITKFilterOutput(orfilter->GetOutput(), m_NewCellArrayPtr.lock()); orfilter->Update(); } break; case 6://xor { XorType::Pointer xorfilter = XorType::New(); xorfilter->SetInput1(inputImage1); xorfilter->SetInput2(inputImage2); ITKUtilitiesType::SetITKFilterOutput(xorfilter->GetOutput(), m_NewCellArrayPtr.lock()); xorfilter->Update(); } break; case 7://min { MinType::Pointer minimum = MinType::New(); minimum->SetInput1(inputImage1); minimum->SetInput2(inputImage2); ITKUtilitiesType::SetITKFilterOutput(minimum->GetOutput(), m_NewCellArrayPtr.lock()); minimum->Update(); } break; case 8://max { MaxType::Pointer maximum = MaxType::New(); maximum->SetInput1(inputImage1); maximum->SetInput2(inputImage2); ITKUtilitiesType::SetITKFilterOutput(maximum->GetOutput(), m_NewCellArrayPtr.lock()); maximum->Update(); } break; case 9://mean { MeanType::Pointer mean = MeanType::New(); mean->SetInput1(inputImage1); mean->SetInput2(inputImage2); limitsRound->SetInput(mean->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; case 10://difference { DifferenceType::Pointer difference = DifferenceType::New(); difference->SetInput1(inputImage1); difference->SetInput2(inputImage2); limitsRound->SetInput(difference->GetOutput()); ITKUtilitiesType::SetITKFilterOutput(limitsRound->GetOutput(), m_NewCellArrayPtr.lock()); limitsRound->Update(); } break; } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t SPParksWriter::writeFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_FeatureIdsArrayPath.getDataContainerName()); size_t udims[3] = {0, 0, 0}; m->getGeometryAs<ImageGeom>()->getDimensions(udims); size_t totalpoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); std::ofstream outfile; outfile.open(getOutputFile().toLatin1().data(), std::ios_base::binary | std::ios_base::app); if (!outfile) { QString ss = QObject::tr("Error opening output file '%1'").arg(getOutputFile()); setErrorCondition(-100); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return getErrorCondition(); } uint64_t millis = QDateTime::currentMSecsSinceEpoch(); uint64_t currentMillis = millis; uint64_t startMillis = millis; uint64_t estimatedTime = 0; float timeDiff = 0.0f; int64_t increment = static_cast<int64_t>(totalpoints * 0.01f); size_t count = 0; QString buf; QTextStream ss(&buf); // Buffer the output with 4096 Bytes which is typically the size of a "Block" on a // modern Hard Drive. This should speed up the writes considerably char buffer[4096]; outfile.rdbuf()->pubsetbuf(buffer, 4096); for (size_t k = 0; k < totalpoints; k++) { if (count % increment == 0) { currentMillis = QDateTime::currentMSecsSinceEpoch(); if (currentMillis - millis > 1000) { buf.clear(); ss << getMessagePrefix() << " " << static_cast<int>((float)(k) / (float)(totalpoints) * 100) << " % Completed "; timeDiff = ((float)k / (float)(currentMillis - startMillis)); estimatedTime = (float)(totalpoints - k) / timeDiff; ss << " || Est. Time Remain: " << DREAM3D::convertMillisToHrsMinSecs(estimatedTime); notifyStatusMessage(getHumanLabel(), buf ); millis = QDateTime::currentMSecsSinceEpoch(); } } count++; double temp0 = 0.0; double temp1 = 0.0; outfile << k + 1 << " " << m_FeatureIds[k] << " " << temp0 << " " << temp1 << "\n"; } outfile.close(); // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); return 0; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int32_t INLWriter::writeFile() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return getErrorCondition(); } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); 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 dir(fi.path()); if (!dir.mkpath(".")) { QString ss = QObject::tr("Error creating parent path '%1'").arg(fi.path()); 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; } // Write the header, Each line starts with a "#" symbol fprintf(f, "# File written from %s\r\n", SIMPLib::Version::PackageComplete().toLatin1().data()); fprintf(f, "# DateTime: %s\r\n", QDateTime::currentDateTime().toString().toLatin1().data()); fprintf(f, "# X_STEP: %f\r\n", res[0]); fprintf(f, "# Y_STEP: %f\r\n", res[1]); fprintf(f, "# Z_STEP: %f\r\n", res[2]); fprintf(f, "#\r\n"); fprintf(f, "# X_MIN: %f\r\n", origin[0]); fprintf(f, "# Y_MIN: %f\r\n", origin[1]); fprintf(f, "# Z_MIN: %f\r\n", origin[2]); fprintf(f, "#\r\n"); fprintf(f, "# X_MAX: %f\r\n", origin[0] + (dims[0]*res[0])); fprintf(f, "# Y_MAX: %f\r\n", origin[1] + (dims[1]*res[1])); fprintf(f, "# Z_MAX: %f\r\n", origin[2] + (dims[2]*res[2])); fprintf(f, "#\r\n"); fprintf(f, "# X_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[0])); fprintf(f, "# Y_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[1])); fprintf(f, "# Z_DIM: %llu\r\n", static_cast<long long unsigned int>(dims[2])); fprintf(f, "#\r\n"); StringDataArray* materialNames = m_MaterialNamePtr.lock().get(); #if 0 -------------------------------------------- - # Phase_1: MOX with 30% Pu # Symmetry_1: 43 # Features_1: 4 # # Phase_2: Brahman # Symmetry_2: 62 # Features_2: 6 # # Phase_3: Void # Symmetry_3: 22 # Features_3: 1 # # Total_Features: 11 -------------------------------------------- - #endif uint32_t symmetry = 0; int32_t count = static_cast<int32_t>(materialNames->getNumberOfTuples()); for (int32_t i = 1; i < count; ++i) { QString matName = materialNames->getValue(i); fprintf(f, "# Phase_%d: %s\r\n", i, matName.toLatin1().data()); symmetry = m_CrystalStructures[i]; symmetry = mapCrystalSymmetryToTslSymmetry(symmetry); fprintf(f, "# Symmetry_%d: %u\r\n", i, symmetry); fprintf(f, "# Features_%d: %d\r\n", i, m_NumFeatures[i]); fprintf(f, "#\r\n"); } std::set<int32_t> uniqueFeatureIds; for (size_t i = 0; i < totalPoints; ++i) { uniqueFeatureIds.insert(m_FeatureIds[i]); } count = static_cast<int32_t>(uniqueFeatureIds.size()); fprintf(f, "# Num_Features: %d \r\n", count); fprintf(f, "#\r\n"); // fprintf(f, "# Column 1-3: phi1, PHI, phi2 (orientation of point in radians)\r\n"); // fprintf(f, "# Column 4-6: x, y, z (coordinates of point in microns)\r\n"); // fprintf(f, "# Column 7: Feature ID\r\n"); // fprintf(f, "# Column 8: Phase ID\r\n"); fprintf(f, "# phi1 PHI phi2 x y z FeatureId PhaseId Symmetry\r\n"); float phi1 = 0.0f, phi = 0.0f, phi2 = 0.0f; float xPos = 0.0f, yPos = 0.0f, zPos = 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]; phi = m_CellEulerAngles[index * 3 + 1]; phi2 = m_CellEulerAngles[index * 3 + 2]; xPos = origin[0] + (x * res[0]); yPos = origin[1] + (y * res[1]); zPos = origin[2] + (z * res[2]); featureId = m_FeatureIds[index]; phaseId = m_CellPhases[index]; symmetry = m_CrystalStructures[phaseId]; if (phaseId > 0) { if (symmetry == Ebsd::CrystalStructure::Cubic_High) { symmetry = Ebsd::Ang::PhaseSymmetry::Cubic; } else if (symmetry == Ebsd::CrystalStructure::Hexagonal_High) { symmetry = Ebsd::Ang::PhaseSymmetry::DiHexagonal; } else { symmetry = Ebsd::Ang::PhaseSymmetry::UnknownSymmetry; } } else { symmetry = Ebsd::Ang::PhaseSymmetry::UnknownSymmetry; } fprintf(f, "%f %f %f %f %f %f %d %d %d\r\n", phi1, phi, phi2, xPos, yPos, zPos, featureId, phaseId, symmetry); } } } fclose(f); notifyStatusMessage(getHumanLabel(), "Complete"); return err; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void JumbleOrientations::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); int32_t totalFeatures = static_cast<int32_t>(m_FeaturePhasesPtr.lock()->getNumberOfTuples()); // Generate all the numbers up front const int32_t rangeMin = 1; const int32_t rangeMax = totalFeatures - 1; typedef boost::uniform_int<int32_t> NumberDistribution; typedef boost::mt19937 RandomNumberGenerator; typedef boost::variate_generator < RandomNumberGenerator&, NumberDistribution > Generator; NumberDistribution distribution(rangeMin, rangeMax); RandomNumberGenerator generator; Generator numberGenerator(generator, distribution); generator.seed(static_cast<boost::uint32_t>( QDateTime::currentMSecsSinceEpoch() )); // seed with the current time int32_t r = 0; float temp1 = 0.0f, temp2 = 0.0f, temp3 = 0.0f; //--- Shuffle elements by randomly exchanging each with one other. for (int32_t i = 1; i < totalFeatures; i++) { bool good = false; while (good == false) { good = true; r = numberGenerator(); // Random remaining position. if (r >= totalFeatures) { good = false; } if (m_FeaturePhases[i] != m_FeaturePhases[r]) { good = false; } } temp1 = m_FeatureEulerAngles[3 * i]; temp2 = m_FeatureEulerAngles[3 * i + 1]; temp3 = m_FeatureEulerAngles[3 * i + 2]; m_FeatureEulerAngles[3 * i] = m_FeatureEulerAngles[3 * r]; m_FeatureEulerAngles[3 * i + 1] = m_FeatureEulerAngles[3 * r + 1]; m_FeatureEulerAngles[3 * i + 2] = m_FeatureEulerAngles[3 * r + 2]; m_FeatureEulerAngles[3 * r] = temp1; m_FeatureEulerAngles[3 * r + 1] = temp2; m_FeatureEulerAngles[3 * r + 2] = temp3; } // Now adjust all the Euler angle values for each Voxel for (size_t i = 0; i < totalPoints; ++i) { m_CellEulerAngles[3 * i] = m_FeatureEulerAngles[3 * (m_FeatureIds[i])]; m_CellEulerAngles[3 * i + 1] = m_FeatureEulerAngles[3 * (m_FeatureIds[i]) + 1]; m_CellEulerAngles[3 * i + 2] = m_FeatureEulerAngles[3 * (m_FeatureIds[i]) + 2]; } QuatF* avgQuats = reinterpret_cast<QuatF*>(m_AvgQuats); for (int32_t i = 1; i < totalFeatures; i++) { FOrientArrayType quat(4, 0.0); FOrientTransformsType::eu2qu(FOrientArrayType(&(m_FeatureEulerAngles[3 * i]), 3), quat); QuaternionMathF::Copy(quat.toQuaternion(), avgQuats[i]); } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void UpdateCellQuats::preflight() { dataCheck(true, 1, 1, 1); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SobelEdge::execute() { dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //wrap m_RawImageData as itk::image ImageProcessing::DefaultImageType::Pointer inputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_SelectedCellArray); if(m_Slice) { //wrap output array ImageProcessing::DefaultImageType::Pointer outputImage = ITKUtilitiesType::CreateItkWrapperForDataPointer(m, attrMatName, m_NewCellArray); //get dimensions 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]), }; //create edge filter typedef itk::SobelEdgeDetectionImageFilter<ImageProcessing::DefaultSliceType, ImageProcessing::FloatSliceType> SobelFilterType; SobelFilterType::Pointer sobelFilter = SobelFilterType::New(); //convert result back to uint8 typedef itk::RescaleIntensityImageFilter<ImageProcessing::FloatSliceType, ImageProcessing::DefaultSliceType> RescaleImageType; RescaleImageType::Pointer rescaleFilter = RescaleImageType::New(); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); //loop over slices applying filters for(int i = 0; i < dims[2]; ++i) { QString ss = QObject::tr("Finding Edges On Slice: %1").arg(i + 1); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); //get slice ImageProcessing::DefaultSliceType::Pointer inputSlice = ITKUtilitiesType::ExtractSlice(inputImage, ImageProcessing::ZSlice, i); //run filters sobelFilter->SetInput(inputSlice); rescaleFilter->SetInput(sobelFilter->GetOutput()); //execute filters try { sobelFilter->Update(); rescaleFilter->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::SobelEdgeDetectionImageFilter filter. Error Message returned from ITK:\n %1").arg(err.GetDescription()); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); } //copy into volume ITKUtilitiesType::SetSlice(outputImage, rescaleFilter->GetOutput(), ImageProcessing::ZSlice, i); } } else { //create edge filter typedef itk::SobelEdgeDetectionImageFilter<ImageProcessing::DefaultImageType, ImageProcessing::FloatImageType> SobelFilterType; SobelFilterType::Pointer sobelFilter = SobelFilterType::New(); sobelFilter->SetInput(inputImage); //convert result back to uint8 typedef itk::RescaleIntensityImageFilter<ImageProcessing::FloatImageType, ImageProcessing::DefaultImageType> RescaleImageType; RescaleImageType::Pointer rescaleFilter = RescaleImageType::New(); rescaleFilter->SetInput(sobelFilter->GetOutput()); rescaleFilter->SetOutputMinimum(0); rescaleFilter->SetOutputMaximum(255); //have filter write to dream3d array instead of creating its own buffer ITKUtilitiesType::SetITKFilterOutput(rescaleFilter->GetOutput(), m_NewCellArrayPtr.lock()); //execute filters try { sobelFilter->Update(); rescaleFilter->Update(); } catch( itk::ExceptionObject& err ) { setErrorCondition(-5); QString ss = QObject::tr("Failed to execute itk::SobelEdgeDetectionImageFilter 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 ErodeDilateBadData::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getFeatureIdsArrayPath().getDataContainerName()); size_t totalPoints = m_FeatureIdsPtr.lock()->getNumberOfTuples(); Int32ArrayType::Pointer neighborsPtr = Int32ArrayType::CreateArray(totalPoints, "_INTERNAL_USE_ONLY_Neighbors"); m_Neighbors = neighborsPtr->getPointer(0); neighborsPtr->initializeWithValue(-1); 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]), }; int32_t good = 1; int64_t count = 0; int64_t kstride = 0, jstride = 0; int32_t featurename = 0, feature = 0; int32_t current = 0; int32_t most = 0; int64_t neighpoint = 0; size_t numfeatures = 0; for (size_t i = 0; i < totalPoints; i++) { featurename = m_FeatureIds[i]; if (featurename > numfeatures) { numfeatures = featurename; } } DimType neighpoints[6] = { 0, 0, 0, 0, 0, 0 }; 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]; QVector<int32_t> n(numfeatures + 1, 0); for (int32_t iteration = 0; iteration < m_NumIterations; iteration++) { for (DimType k = 0; k < dims[2]; k++) { kstride = dims[0] * dims[1] * k; for (DimType j = 0; j < dims[1]; j++) { jstride = dims[0] * j; for (DimType i = 0; i < dims[0]; i++) { count = kstride + jstride + i; featurename = m_FeatureIds[count]; if (featurename == 0) { current = 0; most = 0; for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && (k == 0 || m_ZDirOn == false)) { good = 0; } else if (l == 5 && (k == (dims[2] - 1) || m_ZDirOn == false)) { good = 0; } else if (l == 1 && (j == 0 || m_YDirOn == false)) { good = 0; } else if (l == 4 && (j == (dims[1] - 1) || m_YDirOn == false)) { good = 0; } else if (l == 2 && (i == 0 || m_XDirOn == false)) { good = 0; } else if (l == 3 && (i == (dims[0] - 1) || m_XDirOn == false)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; if (m_Direction == 0 && feature > 0) { m_Neighbors[neighpoint] = count; } if (feature > 0 && m_Direction == 1) { n[feature]++; current = n[feature]; if (current > most) { most = current; m_Neighbors[count] = neighpoint; } } } } if (m_Direction == 1) { for (int32_t l = 0; l < 6; l++) { good = 1; neighpoint = count + neighpoints[l]; if (l == 0 && k == 0) { good = 0; } if (l == 5 && k == (dims[2] - 1)) { good = 0; } if (l == 1 && j == 0) { good = 0; } if (l == 4 && j == (dims[1] - 1)) { good = 0; } if (l == 2 && i == 0) { good = 0; } if (l == 3 && i == (dims[0] - 1)) { good = 0; } if (good == 1) { feature = m_FeatureIds[neighpoint]; n[feature] = 0; } } } } } } } QString attrMatName = m_FeatureIdsArrayPath.getAttributeMatrixName(); QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames(); for (size_t j = 0; j < totalPoints; j++) { featurename = m_FeatureIds[j]; int32_t neighbor = m_Neighbors[j]; if (neighbor >= 0) { if ( (featurename == 0 && m_FeatureIds[neighbor] > 0 && m_Direction == 1) || (featurename > 0 && m_FeatureIds[neighbor] == 0 && m_Direction == 0)) { for(QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter); p->copyTuple(neighbor, j); } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void TestFilter::preflight() { /* Place code here that sanity checks input arrays and input values. Look at some * of the other DREAM3DLib/Filters/.cpp files for sample codes */ dataCheck(true, 1, 1, 1); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FindMaxima::execute() { QString ss; dataCheck(); if(getErrorCondition() < 0) { setErrorCondition(-10000); ss = QObject::tr("DataCheck did not pass during execute"); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } //get volume container DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getSelectedCellArrayPath().getDataContainerName()); QString attrMatName = getSelectedCellArrayPath().getAttributeMatrixName(); //get input data IDataArray::Pointer inputData = m_SelectedCellArrayPtr.lock(); //execute type dependant portion using a Private Implementation that takes care of figuring out if // we can work on the correct type and actually handling the algorithm execution. We pass in "this" so // that the private implementation can get access to the current object to pass up status notifications, // progress or handle "cancel" if needed. if(FindMaximaPrivate<int8_t>()(inputData)) { FindMaximaPrivate<int8_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint8_t>()(inputData) ) { FindMaximaPrivate<uint8_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int16_t>()(inputData) ) { FindMaximaPrivate<int16_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint16_t>()(inputData) ) { FindMaximaPrivate<uint16_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int32_t>()(inputData) ) { FindMaximaPrivate<int32_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint32_t>()(inputData) ) { FindMaximaPrivate<uint32_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<int64_t>()(inputData) ) { FindMaximaPrivate<int64_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<uint64_t>()(inputData) ) { FindMaximaPrivate<uint64_t>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<float>()(inputData) ) { FindMaximaPrivate<float>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else if(FindMaximaPrivate<double>()(inputData) ) { FindMaximaPrivate<double>::Execute(this, inputData, m_MinValue, m_NewCellArray, m, attrMatName); } else { setErrorCondition(-10001); ss = QObject::tr("A Supported DataArray type was not used for an input array."); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SurfaceMeshToNonconformalVtk::execute() { int err = 0; setErrorCondition(err); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_SurfaceMeshFaceLabelsArrayPath.getDataContainerName()); TriangleGeom::Pointer triangleGeom = getDataContainerArray()->getDataContainer(getSurfaceMeshFaceLabelsArrayPath().getDataContainerName())->getGeometryAs<TriangleGeom>(); float* nodes = triangleGeom->getVertexPointer(0); int64_t* triangles = triangleGeom->getTriPointer(0); qint64 numNodes = triangleGeom->getNumberOfVertices(); int64_t numTriangles = triangleGeom->getNumberOfTris(); // 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(getOutputVtkFile()); 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; } // Open the output VTK File for writing FILE* vtkFile = NULL; vtkFile = fopen(getOutputVtkFile().toLatin1().data(), "wb"); if (NULL == vtkFile) { QString ss = QObject::tr("Error creating file '%1'").arg(getOutputVtkFile()); setErrorCondition(-18542); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } ScopedFileMonitor vtkFileMonitor(vtkFile); notifyStatusMessage(getHumanLabel(), "Writing Vertex Data ...."); 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"); int numberWrittenNodes = 0; for (int i = 0; i < numNodes; i++) { // Node& n = nodes[i]; // Get the current Node if (m_SurfaceMeshNodeType[i] > 0) { ++numberWrittenNodes; } else { qDebug() << "Node Type Invalid: " << i << "::" << (int)(m_SurfaceMeshNodeType[i]) ;} } fprintf(vtkFile, "POINTS %d float\n", numberWrittenNodes); float pos[3] = {0.0f, 0.0f, 0.0f}; size_t totalWritten = 0; // Write the POINTS data (Vertex) for (int i = 0; i < numNodes; i++) { if (m_SurfaceMeshNodeType[i] > 0) { pos[0] = static_cast<float>(nodes[i * 3]); pos[1] = static_cast<float>(nodes[i * 3 + 1]); pos[2] = static_cast<float>(nodes[i * 3 + 2]); if (m_WriteBinaryFile == true) { SIMPLib::Endian::FromSystemToBig::convert(pos[0]); SIMPLib::Endian::FromSystemToBig::convert(pos[1]); SIMPLib::Endian::FromSystemToBig::convert(pos[2]); totalWritten = fwrite(pos, sizeof(float), 3, vtkFile); if(totalWritten != 3) {} } else { fprintf(vtkFile, "%f %f %f\n", pos[0], pos[1], pos[2]); // Write the positions to the output file } } } // Write the triangle indices into the vtk File notifyStatusMessage(getHumanLabel(), "Writing Faces ...."); int tData[4]; // Store all the unique Spins QMap<int32_t, int32_t> featureTriangleCount; for (int i = 0; i < numTriangles; i++) { if (featureTriangleCount.find(m_SurfaceMeshFaceLabels[i * 2]) == featureTriangleCount.end()) { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2]] = 1; } else { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2]]++; } if (featureTriangleCount.find(m_SurfaceMeshFaceLabels[i * 2 + 1]) == featureTriangleCount.end()) { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2 + 1]] = 1; } else { featureTriangleCount[m_SurfaceMeshFaceLabels[i * 2 + 1]]++; } } // Write the POLYGONS fprintf(vtkFile, "\nPOLYGONS %lld %lld\n", (long long int)(numTriangles * 2), (long long int)(numTriangles * 2 * 4)); size_t totalCells = 0; // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureTriangleCount.begin(); featureIter != featureTriangleCount.end(); ++featureIter) { totalCells += featureIter.value(); } Q_ASSERT(totalCells == (size_t)(numTriangles * 2) ); // Loop over all the features for(QMap<int32_t, int32_t>::iterator featureIter = featureTriangleCount.begin(); featureIter != featureTriangleCount.end(); ++featureIter) { int32_t gid = featureIter.key(); // The current Feature Id int32_t numTriToWrite = featureIter.value(); // The number of triangles for this feature uint8_t doWrite = 0; // Loop over all the triangles looking for the current feature id // this is probably sub-optimal as if we have 1000 features we are going to loop 1000 times but this will use the // least amount of memory. We could run a filter to group the triangles by feature but then we would need an // additional amount of memory equal to 3X the memory used for the triangle list because every triangle will be listed // twice. We could get some slightly better performance if we buffered 4K worth of data then wrote out that data // in one chunk versus what we are doing here. for (int j = 0; j < numTriangles; j++) { doWrite = 0; if (m_SurfaceMeshFaceLabels[j * 2] == gid ) { doWrite = 1; } else if (m_SurfaceMeshFaceLabels[j * 2 + 1] == gid) { doWrite = 2; } // We need to flip the winding of the triangle if (doWrite == 0) { continue; } // Labels in the triangle did match the current feature id. if (doWrite == 1) { tData[0] = 3; // Push on the total number of entries for this entry tData[1] = triangles[j * 3]; tData[2] = triangles[j * 3 + 1]; tData[3] = triangles[j * 3 + 2]; } else { tData[0] = 3; // Push on the total number of entries for this entry tData[1] = triangles[j * 3 + 2]; tData[2] = triangles[j * 3 + 1]; tData[3] = triangles[j * 3]; } if (m_WriteBinaryFile == true) { SIMPLib::Endian::FromSystemToBig::convert(tData[0]); SIMPLib::Endian::FromSystemToBig::convert(tData[1]); // Index of Vertex 0 SIMPLib::Endian::FromSystemToBig::convert(tData[2]); // Index of Vertex 1 SIMPLib::Endian::FromSystemToBig::convert(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]); } numTriToWrite--; } if (numTriToWrite != 0) { qDebug() << "Not enough triangles written: " << gid << "::" << numTriToWrite << " Total Triangles to Write " << featureIter.value(); } } // Write the POINT_DATA section err = writePointData(vtkFile); // Write the CELL_DATA section err = writeCellData(vtkFile, featureTriangleCount); fprintf(vtkFile, "\n"); setErrorCondition(0); notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void GrayToRGB::execute() { QString ss; dataCheck(); if(getErrorCondition() < 0) { setErrorCondition(-10000); ss = QObject::tr("DataCheck did not pass during execute"); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } //get volume container DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getRedArrayPath().getDataContainerName()); QString attrMatName = getRedArrayPath().getAttributeMatrixName(); //get input and output data IDataArray::Pointer redData = m_RedPtr.lock(); IDataArray::Pointer greenData = m_GreenPtr.lock(); IDataArray::Pointer blueData = m_BluePtr.lock(); IDataArray::Pointer outputData = m_NewCellArrayPtr.lock(); //execute type dependant portion using a Private Implementation that takes care of figuring out if // we can work on the correct type and actually handling the algorithm execution. We pass in "this" so // that the private implementation can get access to the current object to pass up status notifications, // progress or handle "cancel" if needed. if(GrayToRGBPrivate<int8_t>()(redData)) { GrayToRGBPrivate<int8_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<uint8_t>()(redData) ) { GrayToRGBPrivate<uint8_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<int16_t>()(redData) ) { GrayToRGBPrivate<int16_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<uint16_t>()(redData) ) { GrayToRGBPrivate<uint16_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<int32_t>()(redData) ) { GrayToRGBPrivate<int32_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<uint32_t>()(redData) ) { GrayToRGBPrivate<uint32_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<int64_t>()(redData) ) { GrayToRGBPrivate<int64_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<uint64_t>()(redData) ) { GrayToRGBPrivate<uint64_t>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<float>()(redData) ) { GrayToRGBPrivate<float>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else if(GrayToRGBPrivate<double>()(redData) ) { GrayToRGBPrivate<double>::Execute(this, redData, greenData, blueData, outputData, m, attrMatName); } else { setErrorCondition(-10001); ss = QObject::tr("A Supported DataArray type was not used for an input array."); notifyErrorMessage(getHumanLabel(), ss, getErrorCondition()); return; } //array name changing/cleanup AttributeMatrix::Pointer attrMat = m->getAttributeMatrix(m_RedArrayPath.getAttributeMatrixName()); attrMat->addAttributeArray(getNewCellArrayName(), outputData); /* Let the GUI know we are done with this filter */ notifyStatusMessage(getHumanLabel(), "Complete"); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AlignSections::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName()); size_t dims[3] = { 0, 0, 0 }; m->getGeometryAs<ImageGeom>()->getDimensions(dims); int64_t xspot = 0, yspot = 0; int64_t newPosition = 0; int64_t currentPosition = 0; std::vector<int64_t> xshifts(dims[2], 0); std::vector<int64_t> yshifts(dims[2], 0); find_shifts(xshifts, yshifts); QList<QString> voxelArrayNames = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArrayNames(); size_t progIncrement = dims[2] / 100; size_t prog = 1; size_t progressInt = 0; size_t slice = 0; for (size_t i = 1; i < dims[2]; i++) { if (i > prog) { progressInt = ((float)i / dims[2]) * 100.0f; QString ss = QObject::tr("Transferring Cell Data || %1% Complete").arg(progressInt); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); prog = prog + progIncrement; } if (getCancel() == true) { return; } slice = (dims[2] - 1) - i; for (size_t l = 0; l < dims[1]; l++) { for (size_t n = 0; n < dims[0]; n++) { if (yshifts[i] >= 0) { yspot = l; } else if (yshifts[i] < 0) { yspot = dims[1] - 1 - l; } if (xshifts[i] >= 0) { xspot = n; } else if (xshifts[i] < 0) { xspot = dims[0] - 1 - n; } newPosition = (slice * dims[0] * dims[1]) + (yspot * dims[0]) + xspot; currentPosition = (slice * dims[0] * dims[1]) + ((yspot + yshifts[i]) * dims[0]) + (xspot + xshifts[i]); if ((yspot + yshifts[i]) >= 0 && (yspot + yshifts[i]) <= static_cast<int64_t>(dims[1]) - 1 && (xspot + xshifts[i]) >= 0 && (xspot + xshifts[i]) <= static_cast<int64_t>(dims[0]) - 1) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArray(*iter); p->copyTuple( static_cast<size_t>(currentPosition), static_cast<size_t>(newPosition)); } } if ((yspot + yshifts[i]) < 0 || (yspot + yshifts[i]) > static_cast<int64_t>(dims[1] - 1) || (xspot + xshifts[i]) < 0 || (xspot + xshifts[i]) > static_cast<int64_t>(dims[0]) - 1) { for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArray(*iter); EXECUTE_FUNCTION_TEMPLATE(this, initializeArrayValues, p, p, newPosition) } } } } } // If there is an error set this to something negative and also set a message notifyStatusMessage(getHumanLabel(), "Complete"); }
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 WarpRegularGrid::execute() { setErrorCondition(0); dataCheck(); if(getErrorCondition() < 0) { return; } DataContainer::Pointer m; if (m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); } else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); } AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); AttributeMatrix::Pointer newCellAttrMat = cellAttrMat->deepCopy(); 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); size_t totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements(); float x = 0.0f, y = 0.0f, z = 0.0f; float newX = 0.0f, newY = 0.0f; int col = 0.0f, row = 0.0f, plane = 0.0f; size_t index; size_t index_old; std::vector<size_t> newindicies(totalPoints); std::vector<bool> goodPoint(totalPoints, true); for (size_t i = 0; i < dims[2]; i++) { QString ss = QObject::tr("Warping Data - %1 Percent Complete").arg(((float)i / dims[2]) * 100); notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss); for (size_t j = 0; j < dims[1]; j++) { for (size_t k = 0; k < dims[0]; k++) { x = static_cast<float>((k * res[0])); y = static_cast<float>((j * res[1])); z = static_cast<float>((i * res[2])); index = (i * dims[0] * dims[1]) + (j * dims[0]) + k; determine_warped_coordinates(x, y, newX, newY); col = newX / res[0]; row = newY / res[1]; plane = i; index_old = (plane * dims[0] * dims[1]) + (row * dims[0]) + col; newindicies[index] = index_old; if (col > 0 && col < dims[0] && row > 0 && row < dims[1]) { goodPoint[index] = true; } else { goodPoint[index] = false; } } } } QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames(); for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter) { IDataArray::Pointer p = cellAttrMat->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. At least in theory IDataArray::Pointer data = p->createNewArray(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName()); data->resize(totalPoints); void* source = NULL; void* destination = NULL; size_t newIndicies_I = 0; int nComp = data->getNumberOfComponents(); for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++) { newIndicies_I = newindicies[i]; if(goodPoint[i] == true) { source = p->getVoidPointer((nComp * newIndicies_I)); destination = data->getVoidPointer((data->getNumberOfComponents() * i)); ::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents()); } else { int var = 0; data->initializeTuple(i, &var); } } cellAttrMat->removeAttributeArray(*iter); newCellAttrMat->addAttributeArray(*iter, data); } m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName()); m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat); notifyStatusMessage(getHumanLabel(), "Complete"); }