diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AddBadData.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AddBadData.cpp index 000a522679..0c183f01ab 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AddBadData.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AddBadData.cpp @@ -5,7 +5,6 @@ #include "simplnx/Utilities/DataGroupUtilities.hpp" #include "simplnx/Utilities/FilterUtilities.hpp" -#include #include using namespace nx::core; @@ -17,7 +16,7 @@ struct InitializeTupleToZeroFunctor template void operator()(DataStructure& dataStructure, const DataPath& arrayPath, usize index) { - dataStructure.getDataRefAs>(arrayPath).initializeTuple(index, 0); + dataStructure.getDataAsUnsafe>(arrayPath)->initializeTuple(index, 0); } }; } // namespace @@ -43,19 +42,17 @@ const std::atomic_bool& AddBadData::getCancel() // ----------------------------------------------------------------------------- Result<> AddBadData::operator()() { - std::random_device randomDevice; // Will be used to obtain a seed for the random number engine - std::mt19937 generator(randomDevice()); // Standard mersenne_twister_engine seeded with rd() - generator.seed(m_InputValues->SeedValue); + std::mt19937 generator(m_InputValues->SeedValue); // Standard mersenne_twister_engine seeded std::uniform_real_distribution distribution(0.0F, 1.0F); - auto& imgGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); - auto& GBEuclideanDistances = m_DataStructure.getDataRefAs(m_InputValues->GBEuclideanDistancesArrayPath); + const auto& imgGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); + const auto& GBEuclideanDistances = m_DataStructure.getDataRefAs(m_InputValues->GBEuclideanDistancesArrayPath).getDataStoreRef(); auto childArrayPaths = GetAllChildArrayDataPaths(m_DataStructure, imgGeom.getCellDataPath()); auto voxelArrayPaths = childArrayPaths.has_value() ? childArrayPaths.value() : std::vector{}; float32 random = 0.0f; - size_t totalPoints = GBEuclideanDistances.getSize(); + const size_t totalPoints = GBEuclideanDistances.getSize(); for(size_t i = 0; i < totalPoints; ++i) { if(m_InputValues->BoundaryNoise && GBEuclideanDistances[i] < 1) @@ -65,7 +62,7 @@ Result<> AddBadData::operator()() { for(const auto& voxelArrayPath : voxelArrayPaths) { - ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAs(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i); + ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAsUnsafe(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i); } } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp index 4a0c2bf2b1..2dfb4b6c32 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp @@ -53,10 +53,10 @@ std::vector AlignSectionsList::getSelectedDataPaths() const // ----------------------------------------------------------------------------- Result<> AlignSectionsList::findShifts(std::vector& xShifts, std::vector& yShifts) { - auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); + const auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); SizeVec3 udims = imageGeom.getDimensions(); - int64 zDim = static_cast(udims[2]); + auto zDim = static_cast(udims[2]); Result<> results = {}; if(m_InputValues->DREAM3DAlignmentFile) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ApplyTransformationToGeometry.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ApplyTransformationToGeometry.cpp index 61b235f6da..070f2c6c8c 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ApplyTransformationToGeometry.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ApplyTransformationToGeometry.cpp @@ -129,7 +129,7 @@ Result<> ApplyTransformationToGeometry::applyImageGeometryTransformation() // ----------------------------------------------------------------------------- Result<> ApplyTransformationToGeometry::applyNodeGeometryTransformation() { - INodeGeometry0D& nodeGeometry0D = m_DataStructure.getDataRefAs(m_InputValues->SelectedGeometryPath); + auto& nodeGeometry0D = m_DataStructure.getDataRefAs(m_InputValues->SelectedGeometryPath); IGeometry::SharedVertexList& vertexList = nodeGeometry0D.getVerticesRef(); @@ -159,7 +159,7 @@ Result<> ApplyTransformationToGeometry::operator()() } case detail::k_PrecomputedTransformationMatrixIdx: // Transformation matrix from array { - const Float32Array& precomputed = m_DataStructure.getDataRefAs(m_InputValues->ComputedTransformationMatrix); + const auto& precomputed = m_DataStructure.getDataAsUnsafe(m_InputValues->ComputedTransformationMatrix)->getDataStoreRef(); m_TransformationMatrix = ImageRotationUtilities::CopyPrecomputedToTransformationMatrix(precomputed); break; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.cpp index 8e98f28b70..a0d4f26642 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.cpp @@ -44,7 +44,7 @@ struct CreateCalculatorArrayFunctor template CalculatorItem::Pointer operator()(DataStructure& dataStructure, bool allocate, const IDataArray* iDataArrayPtr) { - const DataArray* inputDataArray = dynamic_cast*>(iDataArrayPtr); + const auto* inputDataArray = dynamic_cast*>(iDataArrayPtr); CalculatorItem::Pointer itemPtr = CalculatorArray::New(dataStructure, inputDataArray, ICalculatorArray::Array, allocate); return itemPtr; } @@ -55,15 +55,22 @@ struct CopyArrayFunctor template void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray) { + const auto& inputDataStore = inputArray->getDataStoreRef(); if(nullptr != inputArray) { - DataArray& convertedArray = dataStructure.getDataRefAs>(calculatedArrayPath); + auto& convertedDataStore = dataStructure.getDataAsUnsafe>(calculatedArrayPath)->getDataStoreRef(); - int count = inputArray->getSize(); - for(int i = 0; i < count; i++) + const usize count = inputDataStore.getSize(); + for(usize i = 0; i < count; i++) { - double val = (*inputArray)[i]; - convertedArray[i] = val; + if constexpr(std::is_same_v) + { + convertedDataStore[i] = inputDataStore[i]; + } + else + { + convertedDataStore[i] = static_cast(inputDataStore[i]); + } } } } @@ -74,11 +81,17 @@ struct InitializeArrayFunctor template void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray) { - DataArray& convertedArray = dataStructure.getDataRefAs>(calculatedArrayPath); + auto& convertedDataStore = dataStructure.getDataAsUnsafe>(calculatedArrayPath)->getDataStoreRef(); if(nullptr != inputArray && inputArray->getSize() == 1) { - const T& initializeValue = inputArray->at(0); - convertedArray.fill(initializeValue); + if constexpr(std::is_same_v) + { + convertedDataStore.fill(inputArray->at(0)); + } + else + { + convertedDataStore.fill(static_cast(inputArray->at(0))); + } } } }; @@ -318,14 +331,13 @@ std::vector ArrayCalculatorParser::getRegularExpressionMatches() std::vector itemList; // Match all array names that start with two alphabetical characters and have spaces. Match all numbers, decimal or integer. // Match one letter array names. Match all special character operators. - std::regex regExp("(\"((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)*(\\w|\\d){1,1})?|\\S)\")|(((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)" - "*(\\w|\\d){1,1})?|\\S))"); + std::regex regExp(R"lit(("((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)")|(((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)))lit"); auto regExpMatchBegin = std::sregex_iterator(m_InfixEquation.begin(), m_InfixEquation.end(), regExp); auto regExpMatchEnd = std::sregex_iterator(); for(std::sregex_iterator i = regExpMatchBegin; i != regExpMatchEnd; ++i) { - std::smatch match = *i; + const std::smatch& match = *i; itemList.push_back(match.str()); } @@ -436,7 +448,7 @@ Result<> ArrayCalculatorParser::parseCommaOperator(std::string token, std::vecto // For example, if we have root( 4*4, 2*3 ), then we need it to be root( (4*4), (2*3) ) parsedInfix.push_back(RightParenthesisItem::New()); - std::vector::iterator iter = parsedInfix.end(); + auto iter = parsedInfix.end(); iter--; while(iter != parsedInfix.begin()) { @@ -473,7 +485,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector(tokenArrayPath); + const auto* dataArray = m_DataStructure.getDataAs(tokenArrayPath); if(firstArray_NumTuples < 0 && firstArray_Name.empty()) { firstArray_NumTuples = dataArray->getNumberOfTuples(); @@ -491,7 +503,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector ArrayCalculatorParser::checkForAmbiguousArrayName(std::string strItem, std::string warningMsg) +Result<> ArrayCalculatorParser::checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg) { if(m_IsPreflight && ContainsDataArrayName(m_DataStructure, m_SelectedGroupPath, strItem)) { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.hpp index 6b1a9c68c8..32f46372bf 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ArrayCalculator.hpp @@ -42,7 +42,7 @@ class SIMPLNXCORE_EXPORT ArrayCalculatorParser Result<> parseIndexOperator(std::string token, std::vector& parsedInfix); Result<> parseCommaOperator(std::string token, std::vector& parsedInfix); Result<> parseArray(std::string token, std::vector& parsedInfix); - Result<> checkForAmbiguousArrayName(std::string strItem, std::string warningMsg); + Result<> checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg); private: const DataStructure& m_DataStructure; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp index 8938c9c0ef..dba304bb2c 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp @@ -45,6 +45,74 @@ namespace nx::core { +namespace +{ +/** + * @brief extractPatchData Extracts out the needed data values from the global arrays + * @param triId The seed triangle Id + * @param triPatch The group of triangles being used + * @param data The data to extract from + * @return Shared pointer to the extracted data + */ +std::shared_ptr extractPatchData(int64_t triId, CalculateTriangleGroupCurvatures::UniqueFaceIds_t& triPatch, Float64AbstractDataStore& data) +{ + IDataStore::ShapeType cDims = {3ULL}; + + for(auto iter = triPatch.begin(); iter != triPatch.end();) + { + int64_t t = *iter; + + if(std::isnan(data[t * 3]) || std::isnan(data[t * 3 + 1]) || std::isnan(data[t * 3 + 2])) + { + iter = triPatch.erase(iter); + if(*iter == triId) + { + triId = *(triPatch.begin()); + } + } + else + { + ++iter; + } + } + + if(triPatch.empty()) + { + return nullptr; + } + + size_t totalTuples = triPatch.size(); + if(triPatch.count(triId) == 0) + { + totalTuples++; + } + + IDataStore::ShapeType tupleShape = {totalTuples}; + std::optional initValue = {}; + std::shared_ptr extractedData = std::make_shared(tupleShape, cDims, initValue); + // This little chunk makes sure the current seed triangles centroid and normal data appear + // first in the returned arrays which makes the next steps a tad easier. + int32_t i = 0; + extractedData->setComponent(i, 0, data[triId * 3]); + extractedData->setComponent(i, 1, data[triId * 3 + 1]); + extractedData->setComponent(i, 2, data[triId * 3 + 2]); + ++i; + triPatch.erase(triId); + + for(int64_t t : triPatch) + { + extractedData->setComponent(i, 0, data[t * 3]); + extractedData->setComponent(i, 1, data[t * 3 + 1]); + extractedData->setComponent(i, 2, data[t * 3 + 2]); + ++i; + } + triPatch.insert(triId); + + extractedData->resizeTuples({triPatch.size()}); // Resize the TriPatch DataArray + return extractedData; +} +} // namespace + // ----------------------------------------------------------------------------- CalculateTriangleGroupCurvatures::CalculateTriangleGroupCurvatures(FeatureFaceCurvature* filter, int64_t nring, std::vector triangleIds, bool useNormalsForCurveFitting, Float64Array* principleCurvature1, Float64Array* principleCurvature2, Float64Array* principleDirection1, @@ -53,7 +121,7 @@ CalculateTriangleGroupCurvatures::CalculateTriangleGroupCurvatures(FeatureFaceCu Float64Array* surfaceMeshTriangleCentroids, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) : m_Filter(filter) , m_NRing(nring) -, m_TriangleIds(triangleIds) +, m_TriangleIds(std::move(triangleIds)) , m_UseNormalsForCurveFitting(useNormalsForCurveFitting) , m_PrincipleCurvature1(principleCurvature1) , m_PrincipleCurvature2(principleCurvature2) @@ -91,7 +159,7 @@ void subtractVector3d(Float64AbstractDataStore& data, double* v) // ----------------------------------------------------------------------------- void CalculateTriangleGroupCurvatures::operator()() const { - if(m_TriangleIds.size() == 0) + if(m_TriangleIds.empty()) { return; } @@ -184,7 +252,7 @@ void CalculateTriangleGroupCurvatures::operator()() const // Translate the patch to the 0,0,0 origin double sub[3] = {patchCentroids->getComponentValue(0, 0), patchCentroids->getComponentValue(0, 1), patchCentroids->getComponentValue(0, 2)}; - subtractVector3d(*patchCentroids.get(), sub); + subtractVector3d(*patchCentroids, sub); double np[3] = {patchNormals->getComponentValue(0, 0), patchNormals->getComponentValue(0, 1), patchNormals->getComponentValue(0, 2)}; @@ -330,64 +398,4 @@ void CalculateTriangleGroupCurvatures::operator()() const // Send some feedback m_Filter->sendThreadSafeProgressMessage(1); } - -// ----------------------------------------------------------------------------- -std::shared_ptr CalculateTriangleGroupCurvatures::extractPatchData(int64_t triId, UniqueFaceIds_t& triPatch, Float64AbstractDataStore& data) const -{ - IDataStore::ShapeType cDims = {3ULL}; - - for(auto iter = triPatch.begin(); iter != triPatch.end();) - { - int64_t t = *iter; - - if(std::isnan(data[t * 3]) || std::isnan(data[t * 3 + 1]) || std::isnan(data[t * 3 + 2])) - { - iter = triPatch.erase(iter); - if(*iter == triId) - { - triId = *(triPatch.begin()); - } - } - else - { - ++iter; - } - } - - if(triPatch.empty()) - { - return nullptr; - } - - size_t totalTuples = triPatch.size(); - if(triPatch.count(triId) == 0) - { - totalTuples++; - } - - IDataStore::ShapeType tupleShape = {totalTuples}; - std::optional initValue = {}; - std::shared_ptr extractedData = std::make_shared(tupleShape, cDims, initValue); - // This little chunk makes sure the current seed triangles centroid and normal data appear - // first in the returned arrays which makes the next steps a tad easier. - int32_t i = 0; - extractedData->setComponent(i, 0, data[triId * 3]); - extractedData->setComponent(i, 1, data[triId * 3 + 1]); - extractedData->setComponent(i, 2, data[triId * 3 + 2]); - ++i; - triPatch.erase(triId); - - for(UniqueFaceIds_t::iterator iter = triPatch.begin(); iter != triPatch.end(); ++iter) - { - int64_t t = *iter; - extractedData->setComponent(i, 0, data[t * 3]); - extractedData->setComponent(i, 1, data[t * 3 + 1]); - extractedData->setComponent(i, 2, data[t * 3 + 2]); - ++i; - } - triPatch.insert(triId); - - extractedData->resizeTuples({triPatch.size()}); // Resize the TriPatch DataArray - return extractedData; -} } // namespace nx::core diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.hpp index 4ff73f0c34..1e8fd744f9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.hpp @@ -65,16 +65,6 @@ class SIMPLNXCORE_EXPORT CalculateTriangleGroupCurvatures using UniqueFaceIds_t = std::set; -protected: - /** - * @brief extractPatchData Extracts out the needed data values from the global arrays - * @param triId The seed triangle Id - * @param triPatch The group of triangles being used - * @param data The data to extract from - * @return Shared pointer to the extracted data - */ - std::shared_ptr extractPatchData(int64_t triId, UniqueFaceIds_t& triPatch, Float64AbstractDataStore& data) const; - private: FeatureFaceCurvature* m_Filter = nullptr; int64_t m_NRing; diff --git a/src/simplnx/Utilities/AlignSections.cpp b/src/simplnx/Utilities/AlignSections.cpp index a7549d2dc4..ae869004af 100644 --- a/src/simplnx/Utilities/AlignSections.cpp +++ b/src/simplnx/Utilities/AlignSections.cpp @@ -158,7 +158,6 @@ Result<> AlignSections::execute(const SizeVec3& udims) m_MessageHandler(fmt::format("Updating DataArray '{}'", cellArrayPath.toString())); auto& cellArray = m_DataStructure.getDataRefAs(cellArrayPath); - ExecuteParallelFunction(cellArray.getDataType(), taskRunner, this, udims, xShifts, yShifts, cellArray); } // This will spill over if the number of DataArrays to process does not divide evenly by the number of threads. diff --git a/src/simplnx/Utilities/ImageRotationUtilities.cpp b/src/simplnx/Utilities/ImageRotationUtilities.cpp index aad749340c..fd82f236a8 100644 --- a/src/simplnx/Utilities/ImageRotationUtilities.cpp +++ b/src/simplnx/Utilities/ImageRotationUtilities.cpp @@ -140,7 +140,7 @@ std::string GenerateTransformationMatrixDescription(const ImageRotationUtilities } //------------------------------------------------------------------------------ -ImageRotationUtilities::Matrix4fR CopyPrecomputedToTransformationMatrix(const Float32Array& precomputed) +ImageRotationUtilities::Matrix4fR CopyPrecomputedToTransformationMatrix(const AbstractDataStore& precomputed) { ImageRotationUtilities::Matrix4fR transformationMatrix; transformationMatrix.fill(0.0F); diff --git a/src/simplnx/Utilities/ImageRotationUtilities.hpp b/src/simplnx/Utilities/ImageRotationUtilities.hpp index 82d9169ffe..4c9257e612 100644 --- a/src/simplnx/Utilities/ImageRotationUtilities.hpp +++ b/src/simplnx/Utilities/ImageRotationUtilities.hpp @@ -69,7 +69,7 @@ SIMPLNX_EXPORT std::string GenerateTransformationMatrixDescription(const ImageRo * @param precomputed * @return */ -SIMPLNX_EXPORT Matrix4fR CopyPrecomputedToTransformationMatrix(const Float32Array& precomputed); +SIMPLNX_EXPORT Matrix4fR CopyPrecomputedToTransformationMatrix(const AbstractDataStore& precomputed); /** * @brief