From 45398c1aec321cb47232b1152cc57af9912a3464 Mon Sep 17 00:00:00 2001 From: nyoungbq Date: Thu, 15 Aug 2024 17:20:56 -0400 Subject: [PATCH] [1 broken test] All algorithms complete, rework of IDataArray to typed store that avoids extra dynamic cast --- .../Algorithms/ComputeArrayHistogram.cpp | 10 +- .../Filters/Algorithms/ComputeKMeans.cpp | 5 +- .../Filters/Algorithms/ComputeKMedoids.cpp | 4 +- .../SimplnxCore/Filters/Algorithms/DBSCAN.cpp | 8 +- .../Algorithms/ExtractComponentAsArray.cpp | 8 +- .../Algorithms/ExtractVertexGeometry.cpp | 6 +- .../Filters/Algorithms/FillBadData.cpp | 2 +- .../Filters/Algorithms/FlyingEdges3D.cpp | 2 +- .../Filters/Algorithms/QuickSurfaceMesh.cpp | 39 ++-- .../Algorithms/RemoveFlaggedFeatures.cpp | 16 +- ...aceElementAttributesWithNeighborValues.cpp | 52 +++-- .../Filters/Algorithms/ResampleImageGeom.cpp | 1 - .../Algorithms/ScalarSegmentFeatures.cpp | 45 ++--- .../Filters/Algorithms/SharedFeatureFace.cpp | 30 ++- .../Filters/Algorithms/Silhouette.cpp | 21 +- .../Algorithms/SliceTriangleGeometry.cpp | 81 ++++---- .../Algorithms/SliceTriangleGeometry.hpp | 5 +- .../Algorithms/SplitAttributeArray.cpp | 16 +- .../Filters/Algorithms/SurfaceNets.cpp | 76 +------- .../Filters/Algorithms/TriangleCentroid.cpp | 15 +- .../Filters/Algorithms/TupleTransfer.cpp | 66 +++---- .../Filters/Algorithms/TupleTransfer.hpp | 4 +- .../UncertainRegularGridSampleSurfaceMesh.cpp | 4 +- .../Algorithms/WriteAbaqusHexahedron.cpp | 8 +- .../WriteAvizoRectilinearCoordinate.cpp | 4 +- .../WriteAvizoUniformCoordinate.cpp | 4 +- .../Filters/Algorithms/WriteLosAlamosFFT.cpp | 12 +- .../Filters/Algorithms/WriteStlFile.cpp | 156 ++------------- .../Filters/Algorithms/WriteStlFile.hpp | 2 +- .../Algorithms/WriteVtkRectilinearGrid.cpp | 15 +- .../Algorithms/WriteVtkRectilinearGrid.hpp | 2 +- .../Algorithms/WriteVtkStructuredPoints.cpp | 47 +---- .../Filters/ConditionalSetValueFilter.cpp | 8 +- .../Filters/CropImageGeometryFilter.cpp | 16 +- .../Filters/CropVertexGeometryFilter.cpp | 18 +- ...rnalSurfacesFromTriangleGeometryFilter.cpp | 35 ++-- .../Filters/InitializeDataFilter.cpp | 48 ++--- ...terpolatePointCloudToRegularGridFilter.cpp | 3 +- .../Filters/MultiThresholdObjectsFilter.cpp | 38 ++-- .../Filters/RemoveFlaggedVerticesFilter.cpp | 13 +- .../Filters/RequireMinNumNeighborsFilter.cpp | 32 ++-- .../RequireMinimumSizeFeaturesFilter.cpp | 63 +++--- .../RobustAutomaticThresholdFilter.cpp | 101 +++------- .../src/SimplnxCore/utils/VtkUtilities.hpp | 179 +++++++++--------- src/simplnx/Utilities/DataGroupUtilities.cpp | 13 +- src/simplnx/Utilities/DataGroupUtilities.hpp | 3 +- src/simplnx/Utilities/SampleSurfaceMesh.cpp | 12 +- src/simplnx/Utilities/SamplingUtils.hpp | 15 +- 48 files changed, 507 insertions(+), 856 deletions(-) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayHistogram.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayHistogram.cpp index bb7051f1a5..6d55d00267 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayHistogram.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayHistogram.cpp @@ -14,7 +14,7 @@ using namespace nx::core; namespace { -template +template class GenerateHistogramFromData { public: @@ -33,8 +33,8 @@ class GenerateHistogramFromData void operator()() const { - const auto& inputArray = dynamic_cast&>(m_InputArray).getDataStoreRef(); - auto end = inputArray.getSize(); + const auto& inputStore = m_InputArray.getIDataStoreRefAs>(); + auto end = inputStore.getSize(); // tuple visualization: Histogram = {(bin maximum, count), (bin maximum, count), ... } float64 min = 0.0; @@ -46,7 +46,7 @@ class GenerateHistogramFromData } else { - auto minMax = std::minmax_element(inputArray.begin(), inputArray.end()); + auto minMax = std::minmax_element(inputStore.begin(), inputStore.end()); min = (static_cast(*minMax.first) - 1); // ensure upper limit encapsulates max value max = (static_cast(*minMax.second) + 1); // ensure lower limit encapsulates min value } @@ -71,7 +71,7 @@ class GenerateHistogramFromData { return; } - const auto bin = std::floor((inputArray[i] - min) / increment); + const auto bin = std::floor((inputStore[i] - min) / increment); if((bin >= 0) && (bin < m_NumBins)) { m_Histogram[bin * 2 + 1]++; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMeans.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMeans.cpp index 0628776cac..be68fba71f 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMeans.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMeans.cpp @@ -18,8 +18,8 @@ class ComputeKMeansTemplate ComputeKMeansTemplate(ComputeKMeans* filter, const IDataArray* inputIDataArray, IDataArray* meansIDataArray, const std::unique_ptr& maskDataArray, usize numClusters, Int32AbstractDataStore& fIds, ClusterUtilities::DistanceMetric distMetric, std::mt19937_64::result_type seed) : m_Filter(filter) - , m_InputArray(dynamic_cast(inputIDataArray)->getDataStoreRef()) - , m_Means(dynamic_cast(meansIDataArray)->getDataStoreRef()) + , m_InputArray(inputIDataArray->getIDataStoreRefAs()) + , m_Means(meansIDataArray->getIDataStoreRefAs()) , m_Mask(maskDataArray) , m_NumClusters(numClusters) , m_FeatureIds(fIds) @@ -100,7 +100,6 @@ class ComputeKMeansTemplate } private: - using DataArrayT = DataArray; using AbstractDataStoreT = AbstractDataStore; ComputeKMeans* m_Filter; const AbstractDataStoreT& m_InputArray; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMedoids.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMedoids.cpp index 2da9d69a06..2291e75516 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMedoids.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeKMedoids.cpp @@ -18,8 +18,8 @@ class KMedoidsTemplate KMedoidsTemplate(ComputeKMedoids* filter, const IDataArray* inputIDataArray, IDataArray* medoidsIDataArray, const std::unique_ptr& maskDataArray, usize numClusters, Int32AbstractDataStore& fIds, ClusterUtilities::DistanceMetric distMetric, std::mt19937_64::result_type seed) : m_Filter(filter) - , m_InputArray(dynamic_cast(inputIDataArray)->getDataStoreRef()) - , m_Medoids(dynamic_cast(medoidsIDataArray)->getDataStoreRef()) + , m_InputArray(inputIDataArray->getIDataStoreRefAs>()) + , m_Medoids(medoidsIDataArray->getIDataStoreRefAs>()) , m_Mask(maskDataArray) , m_NumClusters(numClusters) , m_FeatureIds(fIds) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/DBSCAN.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/DBSCAN.cpp index a36303bd4d..83d9df7526 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/DBSCAN.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/DBSCAN.cpp @@ -306,22 +306,22 @@ struct DBSCANFunctor { if(useRandom) { - DBSCANTemplate(filter, dynamic_cast&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); + DBSCANTemplate(filter, inputIDataArray.getIDataStoreRefAs>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); } else { - DBSCANTemplate(filter, dynamic_cast&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); + DBSCANTemplate(filter, inputIDataArray.getIDataStoreRefAs>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); } } else { if(useRandom) { - DBSCANTemplate(filter, dynamic_cast&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); + DBSCANTemplate(filter, inputIDataArray.getIDataStoreRefAs>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); } else { - DBSCANTemplate(filter, dynamic_cast&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); + DBSCANTemplate(filter, inputIDataArray.getIDataStoreRefAs>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)(); } } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractComponentAsArray.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractComponentAsArray.cpp index 71a8ffcebd..12726dc980 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractComponentAsArray.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractComponentAsArray.cpp @@ -12,8 +12,8 @@ struct RemoveComponentsFunctor template void operator()(IDataArray* originalArray, IDataArray* resizedArray, usize componentIndexToRemove) // Due to logic structure originalArray cannot be const { - const auto& originalStoreRef = dynamic_cast*>(originalArray)->getDataStoreRef(); - auto& resizedStoreRef = dynamic_cast*>(resizedArray)->getDataStoreRef(); + const auto& originalStoreRef = originalArray->getIDataStoreRefAs>(); + auto& resizedStoreRef = resizedArray->getIDataStoreRefAs>(); const usize originalTupleCount = originalStoreRef.getNumberOfTuples(); const usize originalCompCount = originalStoreRef.getNumberOfComponents(); @@ -42,8 +42,8 @@ struct ExtractComponentsFunctor template void operator()(IDataArray* inputArray, IDataArray* extractedCompArray, usize componentIndexToExtract) // Due to logic structure inputArray cannot be const { - const auto& inputStoreRef = dynamic_cast*>(inputArray)->getDataStoreRef(); - auto& extractedStoreRef = dynamic_cast*>(extractedCompArray)->getDataStoreRef(); + const auto& inputStoreRef = inputArray->getIDataStoreRefAs>(); + auto& extractedStoreRef = extractedCompArray->getIDataStoreRefAs>(); const usize inputTupleCount = inputStoreRef.getNumberOfTuples(); const usize inputCompCount = inputStoreRef.getNumberOfComponents(); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractVertexGeometry.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractVertexGeometry.cpp index cb931c421b..4e6de1ad0a 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractVertexGeometry.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExtractVertexGeometry.cpp @@ -25,10 +25,8 @@ struct CopyDataFunctor template void operator()(const IDataArray* srcIArray, IDataArray* destIArray, const std::vector& maskArray) { - using DataArrayType = DataArray; - - const auto& srcArray = dynamic_cast(srcIArray)->getDataStoreRef(); - auto& destArray = dynamic_cast(destIArray)->getDataStoreRef(); + const auto& srcArray = srcIArray->getIDataStoreRefAs>(); + auto& destArray = destIArray->getIDataStoreRefAs>(); bool useMask = !maskArray.empty(); usize destTupleIdx = 0; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FillBadData.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FillBadData.cpp index 70ea9183f1..7439536db8 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FillBadData.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FillBadData.cpp @@ -41,7 +41,7 @@ struct FillBadDataUpdateTuplesFunctor template void operator()(const Int32AbstractDataStore& featureIds, IDataArray* outputIDataArray, const std::vector& neighbors) { - auto& outputStore = dynamic_cast*>(outputIDataArray)->getDataStoreRef(); + auto& outputStore = outputIDataArray->getIDataStoreRefAs>(); FillBadDataUpdateTuples(featureIds, outputStore, neighbors); } }; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FlyingEdges3D.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FlyingEdges3D.cpp index 9a4738b583..44559792d5 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FlyingEdges3D.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/FlyingEdges3D.cpp @@ -12,7 +12,7 @@ struct ExecuteFlyingEdgesFunctor template void operator()(const ImageGeom& image, const IDataArray* iDataArray, float64 isoVal, TriangleGeom& triangleGeom, Float32AbstractDataStore& normals, AttributeMatrix& normAM) { - FlyingEdgesAlgorithm flyingEdges = FlyingEdgesAlgorithm(image, dynamic_cast*>(iDataArray)->getDataStoreRef(), static_cast(isoVal), triangleGeom, normals); + FlyingEdgesAlgorithm flyingEdges = FlyingEdgesAlgorithm(image, iDataArray->getIDataStoreRefAs>(), static_cast(isoVal), triangleGeom, normals); flyingEdges.pass1(); flyingEdges.pass2(); flyingEdges.pass3(); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMesh.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMesh.cpp index 8b9c26a3d2..4319b1891a 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMesh.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMesh.cpp @@ -956,8 +956,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod triangleGeom->getFaceAttributeMatrix()->resizeTuples({triangleCount}); triangleGeom->getVertexAttributeMatrix()->resizeTuples(tDims); - auto& faceLabelsArray = m_DataStructure.getDataRefAs(m_InputValues->FaceLabelsDataPath); - auto& faceLabelsStore = faceLabelsArray.getDataStoreRef(); + auto& faceLabelsStore = m_DataStructure.getDataAs(m_InputValues->FaceLabelsDataPath)->getDataStoreRef(); // Resize the NodeTypes array auto& nodeTypes = m_DataStructure.getDataAs(m_InputValues->NodeTypesDataPath)->getDataStoreRef(); @@ -1012,7 +1011,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1025,7 +1024,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1061,7 +1060,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1074,7 +1073,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1110,7 +1109,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1123,7 +1122,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1159,7 +1158,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1172,7 +1171,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1216,7 +1215,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh1, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh1, point, faceLabelsStore); } triangleIndex++; @@ -1236,7 +1235,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh1, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh1, point, faceLabelsStore); } triangleIndex++; @@ -1272,7 +1271,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1285,7 +1284,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1328,7 +1327,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh2, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh2, point, faceLabelsStore); } triangleIndex++; @@ -1348,7 +1347,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh2, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh2, point, faceLabelsStore); } triangleIndex++; @@ -1384,7 +1383,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1397,7 +1396,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, point, point, faceLabelsStore); } triangleIndex++; @@ -1440,7 +1439,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh3, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh3, point, faceLabelsStore); } triangleIndex++; @@ -1460,7 +1459,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector& m_Nod for(size_t dataVectorIndex = 0; dataVectorIndex < m_InputValues->SelectedDataArrayPaths.size(); dataVectorIndex++) { - tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh3, point, faceLabelsArray); + tupleTransferFunctions[dataVectorIndex]->transfer(triangleIndex, neigh3, point, faceLabelsStore); } triangleIndex++; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RemoveFlaggedFeatures.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RemoveFlaggedFeatures.cpp index 0878f261df..f560c6e042 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RemoveFlaggedFeatures.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RemoveFlaggedFeatures.cpp @@ -14,9 +14,8 @@ using namespace nx::core; namespace { -bool IdentifyNeighbors(ImageGeom& imageGeom, Int32Array& featureIds, std::vector& storageArray, const std::atomic_bool& shouldCancel, RemoveFlaggedFeatures* filter) +bool IdentifyNeighbors(ImageGeom& imageGeom, Int32AbstractDataStore& featureIds, std::vector& storageArray, const std::atomic_bool& shouldCancel, RemoveFlaggedFeatures* filter) { - const usize totalPoints = featureIds.getNumberOfTuples(); SizeVec3 uDims = imageGeom.getDimensions(); int64 dims[3] = {static_cast(uDims[0]), static_cast(uDims[1]), static_cast(uDims[2])}; @@ -28,7 +27,7 @@ bool IdentifyNeighbors(ImageGeom& imageGeom, Int32Array& featureIds, std::vector auto progressIncrement = dims[2] / 100; usize progressCounter = 0; int32 featureName; - int64 kStride = 0, jStride = 0; + int64 kStride, jStride; for(int64 k = 0; k < dims[2]; k++) { if(shouldCancel) @@ -56,8 +55,7 @@ bool IdentifyNeighbors(ImageGeom& imageGeom, Int32Array& featureIds, std::vector continue; } shouldLoop = true; - int32 neighbor; - int32 current = 0; + int32 current; int32 most = 0; std::vector numHits(6, 0); std::vector discoveredFeatures = {}; @@ -121,7 +119,7 @@ bool IdentifyNeighbors(ImageGeom& imageGeom, Int32Array& featureIds, std::vector return shouldLoop; } -std::vector FlagFeatures(Int32Array& featureIds, std::unique_ptr& flaggedFeatures, const bool fillRemovedFeatures) +std::vector FlagFeatures(Int32AbstractDataStore& featureIds, std::unique_ptr& flaggedFeatures, const bool fillRemovedFeatures) { bool good = false; usize totalPoints = featureIds.getNumberOfTuples(); @@ -161,7 +159,7 @@ std::vector FlagFeatures(Int32Array& featureIds, std::unique_ptr& neighbors, std::vector>& voxelArrays, const std::atomic_bool& shouldCancel) +void FindVoxelArrays(const Int32AbstractDataStore& featureIds, const std::vector& neighbors, std::vector>& voxelArrays, const std::atomic_bool& shouldCancel) { const usize totalPoints = featureIds.getNumberOfTuples(); @@ -287,7 +285,7 @@ void RemoveFlaggedFeatures::sendThreadSafeProgressMessage(size_t counter) // ----------------------------------------------------------------------------- Result<> RemoveFlaggedFeatures::operator()() { - auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); auto function = static_cast(m_InputValues->ExtractFeatures); @@ -402,7 +400,7 @@ Result<> RemoveFlaggedFeatures::operator()() if(m_InputValues->FillRemovedFeatures) { - bool shouldLoop = false; + bool shouldLoop; usize count = 0; do { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReplaceElementAttributesWithNeighborValues.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReplaceElementAttributesWithNeighborValues.cpp index 0bdc0fca6d..89f3f4ff98 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReplaceElementAttributesWithNeighborValues.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReplaceElementAttributesWithNeighborValues.cpp @@ -23,9 +23,9 @@ class IComparisonFunctor IComparisonFunctor& operator=(const IComparisonFunctor&) = delete; // Copy Assignment Not Implemented IComparisonFunctor& operator=(IComparisonFunctor&&) = delete; // Move Assignment Not Implemented - virtual bool compare(T left, T right) const = 0; - virtual bool compare1(T left, T right) const = 0; - virtual bool compare2(T left, T right) const = 0; + [[nodiscard]] virtual bool compare(T left, T right) const = 0; + [[nodiscard]] virtual bool compare1(T left, T right) const = 0; + [[nodiscard]] virtual bool compare2(T left, T right) const = 0; }; template @@ -40,15 +40,15 @@ class LessThanComparison : public IComparisonFunctor LessThanComparison& operator=(const LessThanComparison&) = delete; // Copy Assignment Not Implemented LessThanComparison& operator=(LessThanComparison&&) = delete; // Move Assignment Not Implemented - bool compare(T left, T right) const override + [[nodiscard]] bool compare(T left, T right) const override { return left < right; } - bool compare1(T left, T right) const override + [[nodiscard]] bool compare1(T left, T right) const override { return left >= right; } - bool compare2(T left, T right) const override + [[nodiscard]] bool compare2(T left, T right) const override { return left > right; } @@ -65,15 +65,15 @@ class GreaterThanComparison : public IComparisonFunctor GreaterThanComparison& operator=(const GreaterThanComparison&) = delete; // Copy Assignment Not Implemented GreaterThanComparison& operator=(GreaterThanComparison&&) = delete; // Move Assignment Not Implemented - bool compare(T left, T right) const override + [[nodiscard]] bool compare(T left, T right) const override { return left > right; } - bool compare1(T left, T right) const override + [[nodiscard]] bool compare1(T left, T right) const override { return left <= right; } - bool compare2(T left, T right) const override + [[nodiscard]] bool compare2(T left, T right) const override { return left < right; } @@ -82,8 +82,8 @@ class GreaterThanComparison : public IComparisonFunctor struct ExecuteTemplate { template - void CompareValues(std::shared_ptr>& comparator, const DataArray& inputArray, int64 neighbor, float thresholdValue, float32& best, std::vector& bestNeighbor, - size_t i) const + void CompareValues(std::shared_ptr>& comparator, const AbstractDataStore& inputArray, int64 neighbor, float thresholdValue, float32& best, + std::vector& bestNeighbor, size_t i) const { if(comparator->compare1(inputArray[neighbor], thresholdValue) && comparator->compare2(inputArray[neighbor], best)) { @@ -93,14 +93,12 @@ struct ExecuteTemplate } template - void operator()(const ImageGeom& imageGeom, IDataArray& inputIDataArray, int32 comparisonAlgorithm, float thresholdValue, bool loopUntilDone, const std::atomic_bool& shouldCancel, + void operator()(const ImageGeom& imageGeom, IDataArray* inputIDataArray, int32 comparisonAlgorithm, float thresholdValue, bool loopUntilDone, const std::atomic_bool& shouldCancel, const IFilter::MessageHandler& messageHandler) { - using DataArrayType = DataArray; + const auto& inputStore = inputIDataArray->getIDataStoreRefAs>(); - const auto& inputArray = dynamic_cast(inputIDataArray); - - const size_t totalPoints = inputArray.getNumberOfTuples(); + const size_t totalPoints = inputStore.getNumberOfTuples(); Vec3 udims = imageGeom.getDimensions(); std::array dims = { @@ -140,48 +138,48 @@ struct ExecuteTemplate break; } - int64 progIncrement = static_cast(totalPoints / 50); + auto progIncrement = static_cast(totalPoints / 50); int64 prog = 1; int64 progressInt = 0; for(size_t i = 0; i < totalPoints; i++) { - if(comparator->compare(inputArray[i], thresholdValue)) + if(comparator->compare(inputStore[i], thresholdValue)) { column = i % dims[0]; row = (i / dims[0]) % dims[1]; plane = i / (dims[0] * dims[1]); count++; - float32 best = inputArray[i]; + float32 best = inputStore[i]; neighbor = static_cast(i) + neighborPoints[0]; if(plane != 0) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } neighbor = static_cast(i) + neighborPoints[1]; if(row != 0) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } neighbor = static_cast(i) + neighborPoints[2]; if(column != 0) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } neighbor = static_cast(i) + neighborPoints[3]; if(column != (dims[0] - 1)) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } neighbor = static_cast(i) + neighborPoints[4]; if(row != (dims[1] - 1)) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } neighbor = static_cast(i) + neighborPoints[5]; if(plane != (dims[2] - 1)) { - CompareValues(comparator, inputArray, neighbor, thresholdValue, best, bestNeighbor, i); + CompareValues(comparator, inputStore, neighbor, thresholdValue, best, bestNeighbor, i); } } if(int64_t(i) > prog) @@ -254,10 +252,10 @@ const std::atomic_bool& ReplaceElementAttributesWithNeighborValues::getCancel() Result<> ReplaceElementAttributesWithNeighborValues::operator()() { - auto& srcIDataArray = m_DataStructure.getDataRefAs(m_InputValues->InputArrayPath); + auto* srcIDataArray = m_DataStructure.getDataAs(m_InputValues->InputArrayPath); const auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->SelectedImageGeometryPath); - ExecuteDataFunction(ExecuteTemplate{}, srcIDataArray.getDataType(), imageGeom, srcIDataArray, m_InputValues->SelectedComparison, m_InputValues->MinConfidence, m_InputValues->Loop, m_ShouldCancel, + ExecuteDataFunction(ExecuteTemplate{}, srcIDataArray->getDataType(), imageGeom, srcIDataArray, m_InputValues->SelectedComparison, m_InputValues->MinConfidence, m_InputValues->Loop, m_ShouldCancel, m_MessageHandler); return {}; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ResampleImageGeom.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ResampleImageGeom.cpp index 40cf3d4680..f825ef2f85 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ResampleImageGeom.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ResampleImageGeom.cpp @@ -9,7 +9,6 @@ #include "simplnx/Utilities/ParallelDataAlgorithm.hpp" #include "simplnx/Utilities/ParallelTaskAlgorithm.hpp" #include "simplnx/Utilities/SamplingUtils.hpp" -#include "simplnx/Utilities/StringUtilities.hpp" using namespace nx::core; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ScalarSegmentFeatures.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ScalarSegmentFeatures.cpp index 1e94c4154b..e5ca576237 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ScalarSegmentFeatures.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ScalarSegmentFeatures.cpp @@ -1,5 +1,7 @@ #include "ScalarSegmentFeatures.hpp" +#include + #include "simplnx/DataStructure/DataStore.hpp" #include "simplnx/DataStructure/Geometry/IGridGeometry.hpp" #include "simplnx/Filter/Actions/CreateArrayAction.hpp" @@ -14,9 +16,6 @@ using namespace nx::core; namespace { - -constexpr StringLiteral k_CompareFunctKey = "Compare Function"; - constexpr int64 k_IncorrectInputArray = -600; constexpr int64 k_MissingInputArray = -601; constexpr int64 k_MissingOrIncorrectGoodVoxelsArray = -602; @@ -30,12 +29,13 @@ class TSpecificCompareFunctorBool : public SegmentFeatures::CompareFunctor using DataArrayType = BoolArray; CX_DEFAULT_CONSTRUCTORS(TSpecificCompareFunctorBool) - TSpecificCompareFunctorBool(IDataArray* data, int64 length, bool tolerance, AbstractDataStore* featureIds) + TSpecificCompareFunctorBool(IDataArray* data, int64 length, AbstractDataStore* featureIds) : m_Length(length) , m_FeatureIdsArray(featureIds) , m_Data(dynamic_cast(data)) { } + TSpecificCompareFunctorBool() = default; ~TSpecificCompareFunctorBool() override = default; bool operator()(int64 referencePoint, int64 neighborPoint, int32 gnum) override @@ -54,9 +54,6 @@ class TSpecificCompareFunctorBool : public SegmentFeatures::CompareFunctor return false; } -protected: - TSpecificCompareFunctorBool() = default; - private: int64 m_Length = 0; // Length of the Data Array AbstractDataStore* m_FeatureIdsArray = nullptr; // The Feature Ids @@ -79,9 +76,10 @@ class TSpecificCompareFunctor : public SegmentFeatures::CompareFunctor : m_Length(length) , m_Tolerance(tolerance) , m_FeatureIdsArray(featureIds) - , m_Data(dynamic_cast(data)->getDataStoreRef()) + , m_Data(data->getIDataStoreRefAs()) { } + TSpecificCompareFunctor() = default; ~TSpecificCompareFunctor() override = default; bool operator()(int64 referencePoint, int64 neighborPoint, int32 gnum) override @@ -111,9 +109,6 @@ class TSpecificCompareFunctor : public SegmentFeatures::CompareFunctor return false; } -protected: - TSpecificCompareFunctor() = default; - private: int64 m_Length = 0; // Length of the Data Array T m_Tolerance = static_cast(0); // The tolerance of the comparison @@ -153,7 +148,7 @@ Result<> ScalarSegmentFeatures::operator()() m_FeatureIdsArray = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath); m_FeatureIdsArray->fill(0); // initialize the output array with zeros - IDataArray* inputDataArray = m_DataStructure.getDataAs(m_InputValues->InputDataPath); + auto* inputDataArray = m_DataStructure.getDataAs(m_InputValues->InputDataPath); size_t inDataPoints = inputDataArray->getNumberOfTuples(); nx::core::DataType dataType = inputDataArray->getDataType(); @@ -170,7 +165,7 @@ Result<> ScalarSegmentFeatures::operator()() break; } case nx::core::DataType::boolean: { - m_CompareFunctor = std::make_shared(inputDataArray, inDataPoints, static_cast(m_InputValues->ScalarTolerance), featureIds); + m_CompareFunctor = std::make_shared(inputDataArray, inDataPoints, featureIds); break; } case nx::core::DataType::int16: { @@ -210,7 +205,7 @@ Result<> ScalarSegmentFeatures::operator()() } if(inputDataArray->getNumberOfComponents() != 1) { - m_CompareFunctor = std::shared_ptr(new SegmentFeatures::CompareFunctor()); // The default CompareFunctor which ALWAYS returns false for the comparison + m_CompareFunctor = std::make_shared(); // The default CompareFunctor which ALWAYS returns false for the comparison } // Run the segmentation algorithm @@ -227,9 +222,9 @@ Result<> ScalarSegmentFeatures::operator()() cellFeaturesAM.resizeTuples(tDims); // This will resize the active array // make sure all values are initialized and "re-reserve" index 0 - auto* activeArray = m_DataStructure.getDataAs(m_InputValues->ActiveArrayPath); - activeArray->getDataStore()->fill(1); - (*activeArray)[0] = 0; + auto& activeStore = m_DataStructure.getDataAs(m_InputValues->ActiveArrayPath)->getDataStoreRef(); + activeStore.fill(1); + activeStore[0] = 0; // Randomize the feature Ids for purely visual clarify. Having random Feature Ids // allows users visualizing the data to better discern each grain otherwise the coloring @@ -250,23 +245,23 @@ int64_t ScalarSegmentFeatures::getSeed(int32 gnum, int64 nextSeed) const int64 seed = -1; // start with the next voxel after the last seed - auto randpoint = static_cast(nextSeed); - while(seed == -1 && randpoint < totalPoints) + auto randPoint = static_cast(nextSeed); + while(seed == -1 && randPoint < totalPoints) { - if(featureIds->getValue(randpoint) == 0) // If the GrainId of the voxel is ZERO then we can use this as a seed point + if(featureIds->getValue(randPoint) == 0) // If the GrainId of the voxel is ZERO then we can use this as a seed point { - if(!m_InputValues->UseMask || m_GoodVoxels->isTrue(randpoint)) + if(!m_InputValues->UseMask || m_GoodVoxels->isTrue(randPoint)) { - seed = randpoint; + seed = randPoint; } else { - randpoint += 1; + randPoint += 1; } } else { - randpoint += 1; + randPoint += 1; } } if(seed >= 0) @@ -279,7 +274,7 @@ int64_t ScalarSegmentFeatures::getSeed(int32 gnum, int64 nextSeed) const // ----------------------------------------------------------------------------- bool ScalarSegmentFeatures::determineGrouping(int64 referencepoint, int64 neighborpoint, int32 gnum) const { - auto featureIds = m_FeatureIdsArray->getDataStore(); + auto* featureIds = m_FeatureIdsArray->getDataStore(); if(featureIds->getValue(neighborpoint) == 0 && (!m_InputValues->UseMask || m_GoodVoxels->isTrue(neighborpoint))) { CompareFunctor* func = m_CompareFunctor.get(); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SharedFeatureFace.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SharedFeatureFace.cpp index f9184b4e2e..eb63e9c1c6 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SharedFeatureFace.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SharedFeatureFace.cpp @@ -1,7 +1,6 @@ #include "SharedFeatureFace.hpp" #include "simplnx/DataStructure/DataArray.hpp" -#include "simplnx/DataStructure/DataGroup.hpp" #include "simplnx/DataStructure/Geometry/TriangleGeom.hpp" #include "simplnx/Utilities/DataArrayUtilities.hpp" #include "simplnx/Utilities/ParallelDataAlgorithm.hpp" @@ -24,7 +23,7 @@ uint64 ConvertToUInt64(uint32 highWord, uint32 lowWord) class SharedFeatureFaceImpl { public: - SharedFeatureFaceImpl(const std::vector>& faceLabelVector, Int32Array& surfaceMeshFeatureFaceLabels, Int32Array& surfaceMeshFeatureFaceNumTriangles, + SharedFeatureFaceImpl(const std::vector>& faceLabelVector, Int32AbstractDataStore& surfaceMeshFeatureFaceLabels, Int32AbstractDataStore& surfaceMeshFeatureFaceNumTriangles, std::map& faceSizeMap, const std::atomic_bool& shouldCancel) : m_FaceLabelVector(faceLabelVector) , m_SurfaceMeshFeatureFaceLabels(surfaceMeshFeatureFaceLabels) @@ -56,8 +55,8 @@ class SharedFeatureFaceImpl private: const std::vector>& m_FaceLabelVector; - Int32Array& m_SurfaceMeshFeatureFaceLabels; - Int32Array& m_SurfaceMeshFeatureFaceNumTriangles; + Int32AbstractDataStore& m_SurfaceMeshFeatureFaceLabels; + Int32AbstractDataStore& m_SurfaceMeshFeatureFaceNumTriangles; std::map& m_FaceSizeMap; const std::atomic_bool& m_ShouldCancel; }; @@ -67,8 +66,7 @@ using Int64Distribution = std::uniform_int_distribution; // ----------------------------------------------------------------------------- SeedGenerator initializeStaticVoxelSeedGenerator(Int64Distribution& distribution, const int64 rangeMin, const int64 rangeMax) { - SeedGenerator generator; - generator.seed(SeedGenerator::default_seed); + SeedGenerator generator(SeedGenerator::default_seed); distribution = std::uniform_int_distribution(rangeMin, rangeMax); return generator; @@ -83,8 +81,8 @@ void RandomizeFaceIds(nx::core::Int32Array& featureIds, uint64 totalFeatures, In auto generator = initializeStaticVoxelSeedGenerator(distribution, rangeMin, rangeMax); DataStructure tmpStructure; - auto rndNumbers = Int64Array::CreateWithStore>(tmpStructure, std::string("_INTERNAL_USE_ONLY_NewFeatureIds"), std::vector{totalFeatures}, std::vector{1}); - auto rndStore = rndNumbers->getDataStore(); + auto* rndNumbers = Int64Array::CreateWithStore>(tmpStructure, std::string("_INTERNAL_USE_ONLY_NewFeatureIds"), std::vector{totalFeatures}, std::vector{1}); + auto* rndStore = rndNumbers->getDataStore(); for(int64 i = 0; i < totalFeatures; ++i) { @@ -107,7 +105,7 @@ void RandomizeFaceIds(nx::core::Int32Array& featureIds, uint64 totalFeatures, In rndStore->setValue(r, temp); } - // Now adjust all the Grain Id values for each Voxel + // Now adjust all the GrainId values for each Voxel auto featureIdsStore = featureIds.getDataStore(); uint64 totalPoints = featureIds.getNumberOfTuples(); for(int64 i = 0; i < totalPoints; ++i) @@ -152,7 +150,7 @@ Result<> SharedFeatureFace::operator()() int32 index = 1; std::vector> faceLabelVector; - faceLabelVector.emplace_back(std::pair(0, 0)); + faceLabelVector.emplace_back(0, 0); // Loop through all the Triangles and figure out how many triangles we have in each one. for(usize t = 0; t < totalPoints; ++t) @@ -177,7 +175,7 @@ Result<> SharedFeatureFace::operator()() faceSizeMap[faceId64] = 1; faceIdMap[faceId64] = index; surfaceMeshFeatureFaceIds[t] = index; - faceLabelVector.emplace_back(std::pair(high, low)); + faceLabelVector.emplace_back(high, low); ++index; } else @@ -196,10 +194,10 @@ Result<> SharedFeatureFace::operator()() std::vector tDims = {static_cast(index)}; faceFeatureAttrMat.resizeTuples(tDims); - auto& surfaceMeshFeatureFaceLabels = m_DataStructure.getDataRefAs(m_InputValues->FeatureFaceLabelsArrayPath); - auto& surfaceMeshFeatureFaceNumTriangles = m_DataStructure.getDataRefAs(m_InputValues->FeatureFaceNumTrianglesArrayPath); - surfaceMeshFeatureFaceLabels.getDataStore()->resizeTuples(tDims); - surfaceMeshFeatureFaceNumTriangles.getDataStore()->resizeTuples(tDims); + auto& surfaceMeshFeatureFaceLabels = m_DataStructure.getDataAs(m_InputValues->FeatureFaceLabelsArrayPath)->getDataStoreRef(); + auto& surfaceMeshFeatureFaceNumTriangles = m_DataStructure.getDataAs(m_InputValues->FeatureFaceNumTrianglesArrayPath)->getDataStoreRef(); + surfaceMeshFeatureFaceLabels.resizeTuples(tDims); + surfaceMeshFeatureFaceNumTriangles.resizeTuples(tDims); // For smaller data sets having data parallelization ON actually runs slower due to // all the overhead of the threads. We are just going to turn this off for @@ -213,7 +211,7 @@ Result<> SharedFeatureFace::operator()() if(m_InputValues->ShouldRandomizeFeatureIds) { const int64 rangeMin = 0; - const int64 rangeMax = static_cast(surfaceMeshFeatureFaceNumTriangles.getNumberOfTuples() - 1); + const auto rangeMax = static_cast(surfaceMeshFeatureFaceNumTriangles.getNumberOfTuples() - 1); Int64Distribution distribution; initializeStaticVoxelSeedGenerator(distribution, rangeMin, rangeMax); ::RandomizeFaceIds(surfaceMeshFeatureFaceIds, index, distribution); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/Silhouette.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/Silhouette.cpp index 03b1806d1d..34393f9f3e 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/Silhouette.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/Silhouette.cpp @@ -26,9 +26,9 @@ class SilhouetteTemplate return Pointer(static_cast(nullptr)); } - SilhouetteTemplate(const IDataArray& inputIDataArray, Float64Array& outputDataArray, const std::unique_ptr& maskDataArray, usize numClusters, const Int32Array& featureIds, - ClusterUtilities::DistanceMetric distMetric) - : m_InputData(dynamic_cast(inputIDataArray)) + SilhouetteTemplate(const IDataArray& inputIDataArray, Float64AbstractDataStore& outputDataArray, const std::unique_ptr& maskDataArray, usize numClusters, + const Int32AbstractDataStore& featureIds, ClusterUtilities::DistanceMetric distMetric) + : m_InputData(inputIDataArray.getIDataStoreRefAs()) , m_OutputData(outputDataArray) , m_Mask(maskDataArray) , m_NumClusters(numClusters) @@ -121,10 +121,10 @@ class SilhouetteTemplate } private: - using DataArrayT = DataArray; - const DataArrayT& m_InputData; - Float64Array& m_OutputData; - const Int32Array& m_FeatureIds; + using AbstractDataStoreT = AbstractDataStore; + const AbstractDataStoreT& m_InputData; + Float64AbstractDataStore& m_OutputData; + const Int32AbstractDataStore& m_FeatureIds; const std::unique_ptr& m_Mask; usize m_NumClusters; ClusterUtilities::DistanceMetric m_DistMetric; @@ -158,7 +158,7 @@ const std::atomic_bool& Silhouette::getCancel() // ----------------------------------------------------------------------------- Result<> Silhouette::operator()() { - auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); std::unordered_set uniqueIds; usize numTuples = featureIds.getNumberOfTuples(); @@ -179,7 +179,8 @@ Result<> Silhouette::operator()() std::string message = fmt::format("Mask Array DataPath does not exist or is not of the correct type (Bool | UInt8) {}", m_InputValues->MaskArrayPath.toString()); return MakeErrorResult(-54080, message); } - RunTemplateClass(clusteringArray.getDataType(), clusteringArray, m_DataStructure.getDataRefAs(m_InputValues->SilhouetteArrayPath), - maskCompare, uniqueIds.size(), featureIds, m_InputValues->DistanceMetric); + RunTemplateClass(clusteringArray.getDataType(), clusteringArray, + m_DataStructure.getDataAs(m_InputValues->SilhouetteArrayPath)->getDataStoreRef(), maskCompare, uniqueIds.size(), featureIds, + m_InputValues->DistanceMetric); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.cpp index 03c5adc380..49e7b7e9f0 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.cpp @@ -7,6 +7,35 @@ using namespace nx::core; +namespace +{ +// ----------------------------------------------------------------------------- +char RayIntersectsPlane(const float32 d, const std::array& q, const std::array& r, std::array& p) +{ + const float64 rqDelZ = r[2] - q[2]; + const float64 dqDelZ = d - q[2]; + const float64 t = dqDelZ / rqDelZ; + for(int i = 0; i < 3; i++) + { + p[i] = q[i] + (t * (r[i] - q[i])); + } + if(t > 0.0 && t < 1.0) + { + return '1'; + } + if(t == 0.0) + { + return 'q'; + } + if(t == 1.0) + { + return 'r'; + } + + return '0'; +} +} // namespace + // ----------------------------------------------------------------------------- SliceTriangleGeometry::SliceTriangleGeometry(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, SliceTriangleGeometryInputValues* inputValues) @@ -39,8 +68,8 @@ Result<> SliceTriangleGeometry::operator()() return MakeErrorResult(-62101, "Error retrieving the shared edge list"); } - INodeGeometry2D::SharedFaceList& tris = triangle.getFacesRef(); - INodeGeometry0D::SharedVertexList& triVerts = triangle.getVerticesRef(); + TriStore& tris = triangle.getFaces()->getDataStoreRef(); + VertsStore& triVerts = triangle.getVertices()->getDataStoreRef(); usize numTris = triangle.getNumberOfFaces(); usize numTriVerts = triangle.getNumberOfVertices(); @@ -65,23 +94,23 @@ Result<> SliceTriangleGeometry::operator()() std::vector regionIds; // Get an object reference to the pointer - const auto* triRegionId = m_DataStructure.getDataAs(m_InputValues->RegionIdArrayPath); + const auto& triRegionId = m_DataStructure.getDataAs(m_InputValues->RegionIdArrayPath)->getDataStoreRef(); int32 edgeCounter = 0; for(usize i = 0; i < numTris; i++) { int32 regionId = 0; - // get region Id of this triangle (if they are available) + // get regionId of this triangle (if they are available) if(m_InputValues->HaveRegionIds) { - regionId = (*triRegionId)[i]; + regionId = triRegionId[i]; } // determine which slices would hit the triangle auto minTriDim = std::numeric_limits::max(); float32 maxTriDim = -minTriDim; for(usize j = 0; j < 3; j++) { - int64 vert = tris[3 * i + j]; + TriStore::value_type vert = tris[3 * i + j]; if(minTriDim > triVerts[3 * vert + 2]) { minTriDim = triVerts[3 * vert + 2]; @@ -140,11 +169,11 @@ Result<> SliceTriangleGeometry::operator()() r[2] = triVerts[3 * tris[3 * i + 1] + 2]; if(q[2] > r[2]) { - val = rayIntersectsPlane(d, r, q, p); + val = RayIntersectsPlane(d, r, q, p); } else { - val = rayIntersectsPlane(d, q, r, p); + val = RayIntersectsPlane(d, q, r, p); } if(val == '1') { @@ -165,11 +194,11 @@ Result<> SliceTriangleGeometry::operator()() r[2] = triVerts[3 * tris[3 * i + 2] + 2]; if(q[2] > r[2]) { - val = rayIntersectsPlane(d, r, q, p); + val = RayIntersectsPlane(d, r, q, p); } else { - val = rayIntersectsPlane(d, q, r, p); + val = RayIntersectsPlane(d, q, r, p); } if(val == '1') { @@ -190,11 +219,11 @@ Result<> SliceTriangleGeometry::operator()() q[2] = triVerts[3 * tris[3 * i + 1] + 2]; if(q[2] > r[2]) { - val = rayIntersectsPlane(d, r, q, p); + val = RayIntersectsPlane(d, r, q, p); } else { - val = rayIntersectsPlane(d, q, r, p); + val = RayIntersectsPlane(d, q, r, p); } if(val == '1') { @@ -314,33 +343,7 @@ Result<> SliceTriangleGeometry::operator()() } // ----------------------------------------------------------------------------- -char SliceTriangleGeometry::rayIntersectsPlane(const float d, const std::array& q, const std::array& r, std::array& p) -{ - const float64 rqDelZ = r[2] - q[2]; - const float64 dqDelZ = d - q[2]; - const float64 t = dqDelZ / rqDelZ; - for(int i = 0; i < 3; i++) - { - p[i] = q[i] + (t * (r[i] - q[i])); - } - if(t > 0.0 && t < 1.0) - { - return '1'; - } - if(t == 0.0) - { - return 'q'; - } - if(t == 1.0) - { - return 'r'; - } - - return '0'; -} - -// ----------------------------------------------------------------------------- -usize SliceTriangleGeometry::determineBoundsAndNumSlices(float32& minDim, float32& maxDim, usize numTris, INodeGeometry2D::SharedFaceList& tris, INodeGeometry0D::SharedVertexList& triVerts) +usize SliceTriangleGeometry::determineBoundsAndNumSlices(float32& minDim, float32& maxDim, usize numTris, TriStore& tris, VertsStore& triVerts) { for(usize i = 0; i < numTris; i++) { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.hpp index 88ace92f7f..43e385952c 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.hpp @@ -51,8 +51,9 @@ class SIMPLNXCORE_EXPORT SliceTriangleGeometry const std::atomic_bool& getCancel(); protected: - char rayIntersectsPlane(float32 d, const std::array& q, const std::array& r, std::array& p); - usize determineBoundsAndNumSlices(float32& minDim, float32& maxDim, usize numTris, INodeGeometry2D::SharedFaceList& tris, INodeGeometry0D::SharedVertexList& triVerts); + using TriStore = AbstractDataStore; + using VertsStore = AbstractDataStore; + usize determineBoundsAndNumSlices(float32& minDim, float32& maxDim, usize numTris, TriStore& tris, VertsStore& triVerts); private: DataStructure& m_DataStructure; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SplitAttributeArray.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SplitAttributeArray.cpp index c8ad3c06b4..5c9223f093 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SplitAttributeArray.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SplitAttributeArray.cpp @@ -11,20 +11,20 @@ namespace struct SplitArraysFunctor { template - void operator()(DataStructure& dataStructure, const SplitAttributeArrayInputValues* inputValues) + void operator()(DataStructure& dataStructure, const IDataArray* inputIDataArray, const SplitAttributeArrayInputValues* inputValues) { - auto& inputArray = dataStructure.getDataRefAs>(inputValues->InputArrayPath); - usize numTuples = inputArray.getNumberOfTuples(); - usize numComponents = inputArray.getNumberOfComponents(); + const auto& inputStore = inputIDataArray->getIDataStoreRefAs>(); + usize numTuples = inputStore.getNumberOfTuples(); + usize numComponents = inputStore.getNumberOfComponents(); for(const auto& j : inputValues->ExtractComponents) { std::string arrayName = inputValues->InputArrayPath.getTargetName() + inputValues->SplitArraysSuffix + StringUtilities::number(j); DataPath splitArrayPath = inputValues->InputArrayPath.replaceName(arrayName); - auto& splitArray = dataStructure.getDataRefAs>(splitArrayPath); + auto& splitStore = dataStructure.getDataAs>(splitArrayPath)->getDataStoreRef(); for(usize i = 0; i < numTuples; i++) { - splitArray[i] = inputArray[numComponents * i + j]; + splitStore[i] = inputStore[numComponents * i + j]; } } } @@ -52,9 +52,9 @@ const std::atomic_bool& SplitAttributeArray::getCancel() // ----------------------------------------------------------------------------- Result<> SplitAttributeArray::operator()() { - auto& inputArray = m_DataStructure.getDataRefAs(m_InputValues->InputArrayPath); + auto* inputArray = m_DataStructure.getDataAs(m_InputValues->InputArrayPath); - ExecuteDataFunction(SplitArraysFunctor{}, inputArray.getDataType(), m_DataStructure, m_InputValues); + ExecuteDataFunction(SplitArraysFunctor{}, inputArray->getDataType(), m_DataStructure, inputArray, m_InputValues); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SurfaceNets.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SurfaceNets.cpp index 4a96461b1e..81beb435e0 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SurfaceNets.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SurfaceNets.cpp @@ -16,37 +16,6 @@ using namespace nx::core; namespace { -// -// Private data class for storing quad data during OBJ data generation -// -class MMQuad -{ -public: - MMQuad() - : m_VertexIndices{-1, -1, -1, -1} - , m_Labels{0, 0} - { - } - MMQuad(std::array vi, std::array labels) - : m_VertexIndices{vi[0], vi[1], vi[2], vi[3]} - , m_Labels{labels[0], labels[1]} - { - } - - void getVertexIndices(std::array& vertexIndices) - { - std::copy(m_VertexIndices.begin(), m_VertexIndices.end(), vertexIndices.begin()); - } - void getLabels(std::array& labels) - { - std::copy(m_Labels.begin(), m_Labels.end(), labels.begin()); - } - -private: - std::array m_VertexIndices; - std::array m_Labels; -}; - struct VertexData { int VertexId; @@ -102,43 +71,6 @@ void getQuadTriangleIDs(std::array& vData, bool isQuadFrontFacing triangleVtxIDs[4] = vData[2].VertexId; triangleVtxIDs[5] = vData[3].VertexId; } - -void exportObjFiles(MMSurfaceNet* m_surfaceNet) -{ - if(m_surfaceNet == nullptr) - { - return; - } - std::shared_ptr const geometry = std::make_shared(m_surfaceNet); - - // Export an OBJ file for each material to the specified path - std::vector const materials = geometry->labels(); - for(const auto& itMatIdx : materials) - { - if(itMatIdx > 20 && itMatIdx < 65530) - { - continue; - } - const std::string filename = fmt::format("surface_mash_test_{}.obj", itMatIdx); - std::cout << "Export file Obj file: " << filename << "\n"; - std::ofstream stream(filename, std::ios_base::binary); - if(stream.is_open()) - { - const MMGeometryOBJ::OBJData data = geometry->objData(itMatIdx); - stream << "# vertices for feature id " << itMatIdx << "\n"; - for(const auto& vertex : data.vertexPositions) - { - stream << "v " << (vertex)[0] << ' ' << (vertex)[1] << ' ' << (vertex)[2] << "\n"; - } - stream << "# triangles for feature id " << itMatIdx << "\n"; - for(const auto& face : data.triangles) - { - stream << "f " << (face)[0] << ' ' << (face)[1] << ' ' << (face)[2] << "\n"; - } - } - } -} - } // namespace // ----------------------------------------------------------------------------- SurfaceNets::SurfaceNets(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, SurfaceNetsInputValues* inputValues) @@ -165,7 +97,7 @@ Result<> SurfaceNets::operator()() auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->GridGeomDataPath); // Get the Created Triangle Geometry - TriangleGeom& triangleGeom = m_DataStructure.getDataRefAs(m_InputValues->TriangleGeometryPath); + auto& triangleGeom = m_DataStructure.getDataRefAs(m_InputValues->TriangleGeometryPath); auto gridDimensions = imageGeom.getDimensions(); auto voxelSize = imageGeom.getSpacing(); @@ -173,7 +105,7 @@ Result<> SurfaceNets::operator()() IntVec3 arraySize(static_cast(gridDimensions[0]), static_cast(gridDimensions[1]), static_cast(gridDimensions[2])); - Int32Array& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); using LabelType = int32; std::vector labels(featureIds.getNumberOfTuples()); @@ -205,7 +137,7 @@ Result<> SurfaceNets::operator()() triangleGeom.getVertexAttributeMatrix()->resizeTuples({static_cast(nodeCount)}); // Remove and then insert a properly sized int8 for the NodeTypes - Int8Array& nodeTypes = m_DataStructure.getDataRefAs(m_InputValues->NodeTypesDataPath); + auto& nodeTypes = m_DataStructure.getDataAs(m_InputValues->NodeTypesDataPath)->getDataStoreRef(); nodeTypes.resizeTuples({static_cast(nodeCount)}); Point3Df position = {0.0f, 0.0f, 0.0f}; @@ -287,7 +219,7 @@ Result<> SurfaceNets::operator()() triangleGeom.getFaceAttributeMatrix()->resizeTuples({triangleCount}); // Resize the face labels Int32Array - Int32Array& faceLabels = m_DataStructure.getDataRefAs(m_InputValues->FaceLabelsDataPath); + auto& faceLabels = m_DataStructure.getDataAs(m_InputValues->FaceLabelsDataPath)->getDataStoreRef(); faceLabels.resizeTuples({triangleCount}); // Create a vector of TupleTransferFunctions for each of the Triangle Face to VertexType Data Arrays diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TriangleCentroid.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TriangleCentroid.cpp index 0a668fcf73..d738b941a9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TriangleCentroid.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TriangleCentroid.cpp @@ -1,7 +1,6 @@ #include "TriangleCentroid.hpp" #include "simplnx/DataStructure/DataArray.hpp" -#include "simplnx/DataStructure/DataGroup.hpp" #include "simplnx/DataStructure/Geometry/IGeometry.hpp" #include "simplnx/DataStructure/Geometry/TriangleGeom.hpp" #include "simplnx/Utilities/Math/MatrixMath.hpp" @@ -19,7 +18,7 @@ namespace class CalculateCentroidsImpl { public: - CalculateCentroidsImpl(const TriangleGeom* triangleGeom, Float64Array* centroids, const std::atomic_bool& shouldCancel) + CalculateCentroidsImpl(const TriangleGeom* triangleGeom, Float64AbstractDataStore& centroids, const std::atomic_bool& shouldCancel) : m_TriangleGeom(triangleGeom) , m_Centroids(centroids) , m_ShouldCancel(shouldCancel) @@ -39,9 +38,9 @@ class CalculateCentroidsImpl std::array vertCoords; m_TriangleGeom->getFaceCoordinates(triangleIndex, vertCoords); - (*m_Centroids)[triangleIndex * 3] = (vertCoords[0].getX() + vertCoords[1].getX() + vertCoords[2].getX()) / 3.0F; - (*m_Centroids)[triangleIndex * 3 + 1] = (vertCoords[0].getY() + vertCoords[1].getY() + vertCoords[2].getY()) / 3.0F; - (*m_Centroids)[triangleIndex * 3 + 2] = (vertCoords[0].getZ() + vertCoords[1].getZ() + vertCoords[2].getZ()) / 3.0F; + m_Centroids[triangleIndex * 3] = (vertCoords[0].getX() + vertCoords[1].getX() + vertCoords[2].getX()) / 3.0F; + m_Centroids[triangleIndex * 3 + 1] = (vertCoords[0].getY() + vertCoords[1].getY() + vertCoords[2].getY()) / 3.0F; + m_Centroids[triangleIndex * 3 + 2] = (vertCoords[0].getZ() + vertCoords[1].getZ() + vertCoords[2].getZ()) / 3.0F; } } @@ -52,7 +51,7 @@ class CalculateCentroidsImpl private: const TriangleGeom* m_TriangleGeom = nullptr; - Float64Array* m_Centroids = nullptr; + Float64AbstractDataStore& m_Centroids; const std::atomic_bool& m_ShouldCancel; }; } // namespace @@ -83,12 +82,12 @@ Result<> TriangleCentroid::operator()() const AttributeMatrix& faceAttributeMatrix = triangleGeom->getFaceAttributeMatrixRef(); const DataPath pCentroidsPath = m_InputValues->TriangleGeometryDataPath.createChildPath(faceAttributeMatrix.getName()).createChildPath(m_InputValues->CentroidsArrayName); - auto* centroidsArray = m_DataStructure.getDataAs(pCentroidsPath); + auto& centroidsStore = m_DataStructure.getDataAs(pCentroidsPath)->getDataStoreRef(); // Parallel algorithm to calculate the centroids ParallelDataAlgorithm dataAlg; dataAlg.setRange(0ULL, static_cast(triangleGeom->getNumberOfFaces())); - dataAlg.execute(CalculateCentroidsImpl(triangleGeom, centroidsArray, m_ShouldCancel)); + dataAlg.execute(CalculateCentroidsImpl(triangleGeom, centroidsStore, m_ShouldCancel)); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.cpp index 364811a48d..b99a4f062b 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.cpp @@ -2,55 +2,57 @@ namespace nx::core { - void AddTupleTransferInstance(DataStructure& dataStructure, const DataPath& selectedDataPath, const DataPath& createdDataPath, std::vector>& tupleTransferFunctions) { auto* inputDataArray = dataStructure.getDataAs(selectedDataPath); - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) + switch(inputDataArray->getDataType()) { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::int8: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::uint8: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::int16: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::uint16: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::int32: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::uint32: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::int64: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::uint64: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::float32: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { - tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + case DataType::float64: { + tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; } - if(TemplateHelpers::CanDynamicCast()(inputDataArray)) - { + case DataType::boolean: { tupleTransferFunctions.push_back(std::make_shared>(dataStructure, selectedDataPath, createdDataPath)); + break; + } } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.hpp index 505b243bfd..700be14986 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/TupleTransfer.hpp @@ -35,7 +35,7 @@ class SIMPLNXCORE_EXPORT AbstractTupleTransfer virtual void transfer(size_t faceIndex, size_t firstcIndex) = 0; - virtual void transfer(size_t faceIndex, size_t firstcIndex, size_t secondcIndex, DataArray& faceLabels) = 0; + virtual void transfer(size_t faceIndex, size_t firstcIndex, size_t secondcIndex, AbstractDataStore& faceLabels) = 0; protected: AbstractTupleTransfer() = default; @@ -106,7 +106,7 @@ class TransferTuple : public AbstractTupleTransfer } } - void transfer(size_t faceIndex, size_t firstcIndex, size_t secondcIndex, DataArray& faceLabels) override + void transfer(size_t faceIndex, size_t firstcIndex, size_t secondcIndex, AbstractDataStore& faceLabels) override { // Only copy the data if the FaceLabel is NOT -1, indicating that the data is NOT on the exterior if(faceLabels[faceIndex * 2] != -1) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/UncertainRegularGridSampleSurfaceMesh.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/UncertainRegularGridSampleSurfaceMesh.cpp index 073ba9d6a3..83773119cd 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/UncertainRegularGridSampleSurfaceMesh.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/UncertainRegularGridSampleSurfaceMesh.cpp @@ -36,9 +36,7 @@ void UncertainRegularGridSampleSurfaceMesh::generatePoints(std::vector points.reserve(dims[0] * dims[1] * dims[2]); - 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); for(usize k = 0; k < dims[2]; k++) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAbaqusHexahedron.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAbaqusHexahedron.cpp index d7a43d5214..b978029e3e 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAbaqusHexahedron.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAbaqusHexahedron.cpp @@ -187,7 +187,7 @@ int32 writeElems(WriteAbaqusHexahedron* filter, const std::string& fileName, con return err; } -int32 writeElset(WriteAbaqusHexahedron* filter, const std::string& fileName, size_t totalPoints, const Int32Array& featureIds, const std::atomic_bool& shouldCancel) +int32 writeElset(WriteAbaqusHexahedron* filter, const std::string& fileName, size_t totalPoints, const Int32AbstractDataStore& featureIds, const std::atomic_bool& shouldCancel) { int32 err = 0; FILE* f = fopen(fileName.c_str(), "wb"); @@ -217,7 +217,7 @@ int32 writeElset(WriteAbaqusHexahedron* filter, const std::string& fileName, siz usize elementPerLine = 0; fprintf(f, "\n*Elset, elset=Grain%d_set\n", voxelId); - for(usize i = 0; i < featureIds.size(); i++) + for(usize i = 0; i < featureIds.getSize(); i++) { if(featureIds[i] == voxelId) { @@ -290,7 +290,7 @@ int32 writeMaster(const std::string& file, const std::string& jobName, const std return err; } -int32 writeSects(const std::string& file, const Int32Array& featureIds, int32 hourglassStiffness) +int32 writeSects(const std::string& file, const Int32AbstractDataStore& featureIds, int32 hourglassStiffness) { int32 err = 0; FILE* f = fopen(file.c_str(), "wb"); @@ -361,7 +361,7 @@ void WriteAbaqusHexahedron::sendMessage(const std::string& message) Result<> WriteAbaqusHexahedron::operator()() { auto& imageGeom = m_DataStructure.getDataRefAs(m_InputValues->ImageGeometryPath); - auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); Vec3 cDims = imageGeom.getDimensions(); usize pDims[3] = {cDims[0] + 1, cDims[1] + 1, cDims[2] + 1}; Vec3 origin = imageGeom.getOrigin(); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoRectilinearCoordinate.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoRectilinearCoordinate.cpp index b8c88b3db9..b56d8b54eb 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoRectilinearCoordinate.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoRectilinearCoordinate.cpp @@ -84,12 +84,12 @@ Result<> WriteAvizoRectilinearCoordinate::writeData(FILE* outputFile) const fprintf(outputFile, "@1 # FeatureIds in z, y, x with X moving fastest, then Y, then Z\n"); - const auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + const auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getIDataStoreRefAs>(); const usize totalPoints = featureIds.getNumberOfTuples(); if(m_InputValues->WriteBinaryFile) { - fwrite(featureIds.getIDataStoreAs()->data(), sizeof(int32_t), totalPoints, outputFile); + fwrite(featureIds.data(), sizeof(int32_t), totalPoints, outputFile); } else { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoUniformCoordinate.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoUniformCoordinate.cpp index 263d2091e5..092e0c46a7 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoUniformCoordinate.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteAvizoUniformCoordinate.cpp @@ -87,12 +87,12 @@ Result<> WriteAvizoUniformCoordinate::writeData(FILE* outputFile) const { fprintf(outputFile, "@1\n"); - const auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + const auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getIDataStoreRefAs>(); const usize totalPoints = featureIds.getNumberOfTuples(); if(m_InputValues->WriteBinaryFile) { - fwrite(featureIds.getIDataStoreAs()->data(), sizeof(int32), totalPoints, outputFile); + fwrite(featureIds.data(), sizeof(int32), totalPoints, outputFile); } else { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLosAlamosFFT.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLosAlamosFFT.cpp index 93b6b12e06..ed4865c1a9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLosAlamosFFT.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteLosAlamosFFT.cpp @@ -56,9 +56,9 @@ Result<> WriteLosAlamosFFT::operator()() SizeVec3 dims = m_DataStructure.getDataAs(m_InputValues->ImageGeomPath)->getDimensions(); - auto& cellEulerAngles = m_DataStructure.getDataRefAs(m_InputValues->CellEulerAnglesArrayPath); - auto& cellPhases = m_DataStructure.getDataRefAs(m_InputValues->CellPhasesArrayPath); - auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + auto& cellEulerAngles = m_DataStructure.getDataAs(m_InputValues->CellEulerAnglesArrayPath)->getDataStoreRef(); + auto& cellPhases = m_DataStructure.getDataAs(m_InputValues->CellPhasesArrayPath)->getDataStoreRef(); + auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); float phi1 = 0.0f, phi = 0.0f, phi2 = 0.0f; @@ -69,9 +69,9 @@ Result<> WriteLosAlamosFFT::operator()() for(usize x = 0; x < dims[0]; ++x) { usize index = (z * dims[0] * dims[1]) + (dims[0] * y) + x; - phi1 = cellEulerAngles[index * 3] * 180.0 * Constants::k_1OverPiD; - phi = cellEulerAngles[index * 3 + 1] * 180.0 * Constants::k_1OverPiD; - phi2 = cellEulerAngles[index * 3 + 2] * 180.0 * Constants::k_1OverPiD; + phi1 = cellEulerAngles[index * 3] * 180.0f * Constants::k_1OverPiF; + phi = cellEulerAngles[index * 3 + 1] * 180.0f * Constants::k_1OverPiF; + phi2 = cellEulerAngles[index * 3 + 2] * 180.0f * Constants::k_1OverPiF; file << fmt::format("{:.3f} {:.3f} {:.3f} {} {} {} {} {}\n", phi1, phi, phi2, static_cast<::ull>(x + 1), static_cast<::ull>(y + 1), static_cast<::ull>(z + 1), featureIds[index], cellPhases[index]); } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.cpp index efe418a18c..2cb412b747 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.cpp @@ -19,7 +19,10 @@ using namespace nx::core; namespace { -Result<> SingleWriteOutStl(const fs::path& path, const IGeometry::MeshIndexType numTriangles, const std::string&& header, const IGeometry::MeshIndexArrayType& triangles, const Float32Array& vertices) +using TriStore = AbstractDataStore; +using VertexStore = AbstractDataStore; + +Result<> SingleWriteOutStl(const fs::path& path, const IGeometry::MeshIndexType numTriangles, const std::string&& header, const TriStore& triangles, const VertexStore& vertices) { Result<> result; @@ -119,142 +122,14 @@ Result<> SingleWriteOutStl(const fs::path& path, const IGeometry::MeshIndexType return result; } -/** - * @brief - * @param path - * @param numTriangles - * @param header - * @param triangles - * @param vertices - * @param featureIds - * @param featureId - * @return - */ -Result<> MultiWriteOutStl(const fs::path& path, const IGeometry::MeshIndexType numTriangles, const std::string&& header, const IGeometry::MeshIndexArrayType& triangles, const Float32Array& vertices, - const Int32Array& featureIds, const int32 featureId) -{ - Result<> result; - // Create output file writer in binary write out mode to ensure cross-compatibility - FILE* filePtr = fopen(path.string().c_str(), "wb"); - - if(filePtr == nullptr) - { - fclose(filePtr); - return {MakeWarningVoidResult(-27876, fmt::format("Error Opening STL File. Unable to create temp file at path '{}' for original file '{}'", path.string(), path.filename().string()))}; - } - - int32 triCount = 0; - - { // Scope header output processing to keep overhead low and increase readability - if(header.size() >= 80) - { - result = MakeWarningVoidResult(-27874, - fmt::format("Warning: Writing STL File '{}'. Header was over the 80 characters supported by STL. Length of header: {}. Only the first 80 bytes will be written.", - path.filename().string(), header.length())); - } - - std::array stlFileHeader = {}; - stlFileHeader.fill(0); - size_t headLength = 80; - if(header.length() < 80) - { - headLength = static_cast(header.length()); - } - - // std::string c_str = header; - memcpy(stlFileHeader.data(), header.data(), headLength); - // Return the number of bytes written - which should be 80 - fwrite(stlFileHeader.data(), 1, 80, filePtr); - } - - fwrite(&triCount, 1, 4, filePtr); - triCount = 0; // Reset this to Zero. Increment for every triangle written - - size_t totalWritten = 0; - std::array vecA = {0.0f, 0.0f, 0.0f}; - std::array vecB = {0.0f, 0.0f, 0.0f}; - - std::array data = {}; - nonstd::span normalPtr(reinterpret_cast(data.data()), 3); - nonstd::span vert1Ptr(reinterpret_cast(data.data() + 12), 3); - nonstd::span vert2Ptr(reinterpret_cast(data.data() + 24), 3); - nonstd::span vert3Ptr(reinterpret_cast(data.data() + 36), 3); - nonstd::span attrByteCountPtr(reinterpret_cast(data.data() + 48), 2); - attrByteCountPtr[0] = 0; - - const usize numComps = featureIds.getNumberOfComponents(); - // Loop over all the triangles for this spin - for(IGeometry::MeshIndexType triangle = 0; triangle < numTriangles; ++triangle) - { - // Get the true indices of the 3 nodes - IGeometry::MeshIndexType nId0 = triangles[triangle * 3]; - IGeometry::MeshIndexType nId1 = triangles[triangle * 3 + 1]; - IGeometry::MeshIndexType nId2 = triangles[triangle * 3 + 2]; - - if(featureIds[triangle * numComps] == featureId) - { - // winding = 0; // 0 = Write it using forward spin - } - else if(numComps > 1 && featureIds[triangle * numComps + 1] == featureId) - { - // Switch the 2 node indices - IGeometry::MeshIndexType temp = nId1; - nId1 = nId2; - nId2 = temp; - } - else - { - continue; // We do not match either spin so move to the next triangle - } - - vert1Ptr[0] = static_cast(vertices[nId0 * 3]); - vert1Ptr[1] = static_cast(vertices[nId0 * 3 + 1]); - vert1Ptr[2] = static_cast(vertices[nId0 * 3 + 2]); - - vert2Ptr[0] = static_cast(vertices[nId1 * 3]); - vert2Ptr[1] = static_cast(vertices[nId1 * 3 + 1]); - vert2Ptr[2] = static_cast(vertices[nId1 * 3 + 2]); - - vert3Ptr[0] = static_cast(vertices[nId2 * 3]); - vert3Ptr[1] = static_cast(vertices[nId2 * 3 + 1]); - vert3Ptr[2] = static_cast(vertices[nId2 * 3 + 2]); - - // Compute the normal - vecA[0] = vert2Ptr[0] - vert1Ptr[0]; - vecA[1] = vert2Ptr[1] - vert1Ptr[1]; - vecA[2] = vert2Ptr[2] - vert1Ptr[2]; - - vecB[0] = vert3Ptr[0] - vert1Ptr[0]; - vecB[1] = vert3Ptr[1] - vert1Ptr[1]; - vecB[2] = vert3Ptr[2] - vert1Ptr[2]; - - MatrixMath::CrossProduct(vecA.data(), vecB.data(), normalPtr.data()); - MatrixMath::Normalize3x1(normalPtr.data()); - - totalWritten = fwrite(data.data(), 1, 50, filePtr); - if(totalWritten != 50) - { - fclose(filePtr); - return {MakeWarningVoidResult( - -27873, fmt::format("Error Writing STL File '{}': Not enough bytes written for triangle {}. Only {} bytes written of 50 bytes", path.filename().string(), triCount, totalWritten))}; - } - triCount++; - } - - fseek(filePtr, 80L, SEEK_SET); - fwrite(reinterpret_cast(&triCount), 1, 4, filePtr); - fclose(filePtr); - return result; -} - /** * @brief This class provides an interface to write the STL Files in parallel */ class MultiWriteStlFileImpl { public: - MultiWriteStlFileImpl(WriteStlFile* filter, const fs::path path, const IGeometry::MeshIndexType numTriangles, const std::string header, const IGeometry::MeshIndexArrayType& triangles, - const Float32Array& vertices, const Int32Array& featureIds, const int32 featureId) + MultiWriteStlFileImpl(WriteStlFile* filter, const fs::path path, const IGeometry::MeshIndexType numTriangles, const std::string header, const TriStore& triangles, const VertexStore& vertices, + const Int32AbstractDataStore& featureIds, const int32 featureId) : m_Filter(filter) , m_Path(path) , m_NumTriangles(numTriangles) @@ -389,9 +264,9 @@ class MultiWriteStlFileImpl const fs::path m_Path; const IGeometry::MeshIndexType m_NumTriangles; const std::string m_Header; - const IGeometry::MeshIndexArrayType& m_Triangles; - const Float32Array& m_Vertices; - const Int32Array& m_FeatureIds; + const TriStore& m_Triangles; + const VertexStore& m_Vertices; + const Int32AbstractDataStore& m_FeatureIds; const int32 m_FeatureId; }; } // namespace @@ -418,8 +293,8 @@ const std::atomic_bool& WriteStlFile::getCancel() Result<> WriteStlFile::operator()() { const auto& triangleGeom = m_DataStructure.getDataRefAs(m_InputValues->TriangleGeomPath); - const Float32Array& vertices = triangleGeom.getVerticesRef(); - const IGeometry::MeshIndexArrayType& triangles = triangleGeom.getFacesRef(); + const ::VertexStore& vertices = triangleGeom.getVertices()->getDataStoreRef(); + const ::TriStore& triangles = triangleGeom.getFaces()->getDataStoreRef(); const IGeometry::MeshIndexType nTriangles = triangleGeom.getNumberOfFaces(); auto groupingType = static_cast(m_InputValues->GroupingType); @@ -474,11 +349,10 @@ Result<> WriteStlFile::operator()() // Store a list of Atomic Files, so we can clean up or finish depending on the outcome of all the writes std::vector> fileList; + const auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsPath)->getDataStoreRef(); if(groupingType == GroupingType::Features) { - const auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsPath); - // Faster and more memory efficient since we don't need phases std::unordered_set uniqueGrainIds(featureIds.cbegin(), featureIds.cend()); @@ -507,8 +381,6 @@ Result<> WriteStlFile::operator()() if(groupingType == GroupingType::FeaturesAndPhases) { - const auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsPath); - std::map uniqueGrainIdToPhase; const auto& featurePhases = m_DataStructure.getDataRefAs(m_InputValues->FeaturePhasesPath); @@ -545,7 +417,7 @@ Result<> WriteStlFile::operator()() // Group Triangles by Part Number which is a single component Int32 Array if(groupingType == GroupingType::PartNumber) { - const auto& partNumbers = m_DataStructure.getDataRefAs(m_InputValues->PartNumberPath); + const auto& partNumbers = m_DataStructure.getDataAs(m_InputValues->PartNumberPath)->getDataStoreRef(); // Faster and more memory efficient since we don't need phases // Build up a list of the unique Part Numbers std::unordered_set uniquePartNumbers(partNumbers.cbegin(), partNumbers.cend()); @@ -587,7 +459,7 @@ Result<> WriteStlFile::operator()() } // ----------------------------------------------------------------------------- -void WriteStlFile::sendThreadSafeProgressMessage(Result<> result) +void WriteStlFile::sendThreadSafeProgressMessage(Result<>&& result) { std::lock_guard guard(m_ProgressMessage_Mutex); if(result.invalid()) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.hpp index b99aec26c2..da08384724 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteStlFile.hpp @@ -51,7 +51,7 @@ class SIMPLNXCORE_EXPORT WriteStlFile const std::atomic_bool& getCancel(); - void sendThreadSafeProgressMessage(Result<> result); + void sendThreadSafeProgressMessage(Result<>&& result); private: DataStructure& m_DataStructure; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp index 9779444ce3..3bccbbf4f3 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp @@ -7,14 +7,8 @@ #include "SimplnxCore/utils/VtkUtilities.hpp" -#include - using namespace nx::core; -namespace -{ -} // namespace - // ----------------------------------------------------------------------------- WriteVtkRectilinearGrid::WriteVtkRectilinearGrid(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, WriteVtkRectilinearGridInputValues* inputValues) @@ -42,7 +36,6 @@ Result<> WriteVtkRectilinearGrid::operator()() FloatVec3 res = imageGeom.getSpacing(); FloatVec3 origin = imageGeom.getOrigin(); - int err = 0; FILE* outputFile = nullptr; outputFile = fopen(m_InputValues->OutputFile.string().c_str(), "wb"); if(nullptr == outputFile) @@ -54,17 +47,17 @@ Result<> WriteVtkRectilinearGrid::operator()() writeVtkHeader(outputFile); // Write the Coordinate Points - Result<> writeCoordsResults = writeCoords(outputFile, "X_COORDINATES", "float", dims[0] + 1, origin[0] - res[0] * 0.5f, (float)(dims[0] + 1 * res[0]), res[0]); + Result<> writeCoordsResults = writeCoords(outputFile, "X_COORDINATES", "float", dims[0] + 1, origin[0] - res[0] * 0.5f, res[0]); if(writeCoordsResults.invalid()) { return MergeResults(writeCoordsResults, MakeErrorResult(-2075, fmt::format("Error writing X Coordinates in vtk file {}'\n ", m_InputValues->OutputFile.string()))); } - writeCoordsResults = writeCoords(outputFile, "Y_COORDINATES", "float", dims[1] + 1, origin[1] - res[1] * 0.5f, (float)(dims[1] + 1 * res[1]), res[1]); + writeCoordsResults = writeCoords(outputFile, "Y_COORDINATES", "float", dims[1] + 1, origin[1] - res[1] * 0.5f, res[1]); if(writeCoordsResults.invalid()) { return MergeResults(writeCoordsResults, MakeErrorResult(-2076, fmt::format("Error writing Y Coordinates in vtk file %s'\n ", m_InputValues->OutputFile.string()))); } - writeCoordsResults = writeCoords(outputFile, "Z_COORDINATES", "float", dims[2] + 1, origin[2] - res[2] * 0.5f, (float)(dims[2] + 1 * res[2]), res[2]); + writeCoordsResults = writeCoords(outputFile, "Z_COORDINATES", "float", dims[2] + 1, origin[2] - res[2] * 0.5f, res[2]); if(writeCoordsResults.invalid()) { return MergeResults(writeCoordsResults, MakeErrorResult(-2077, fmt::format("Error writing Z Coordinates in vtk file %s'\n ", m_InputValues->OutputFile.string()))); @@ -110,7 +103,7 @@ void WriteVtkRectilinearGrid::writeVtkHeader(FILE* outputFile) const // ----------------------------------------------------------------------------- template -Result<> WriteVtkRectilinearGrid::writeCoords(FILE* outputFile, const std::string& axis, const std::string& type, int64 nPoints, T min, T max, T step) +Result<> WriteVtkRectilinearGrid::writeCoords(FILE* outputFile, const std::string& axis, const std::string& type, int64 nPoints, T min, T step) { fprintf(outputFile, "%s %lld %s\n", axis.c_str(), static_cast(nPoints), type.c_str()); if(m_InputValues->WriteBinaryFile) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.hpp index 1d8ffeed6f..2ac2a4f08a 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.hpp @@ -56,7 +56,7 @@ class SIMPLNXCORE_EXPORT WriteVtkRectilinearGrid * @param binary Whether or not to write the vtk file data in binary */ template - Result<> writeCoords(FILE* outputFile, const std::string& axis, const std::string& type, int64 nPoints, T min, T max, T step); + Result<> writeCoords(FILE* outputFile, const std::string& axis, const std::string& type, int64 nPoints, T min, T step); private: DataStructure& m_DataStructure; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp index b6fa2bdaef..d3d4e37a47 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp @@ -9,11 +9,6 @@ using namespace nx::core; -namespace -{ - -} // namespace - // ----------------------------------------------------------------------------- WriteVtkStructuredPoints::WriteVtkStructuredPoints(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, WriteVtkStructuredPointsInputValues* inputValues) @@ -65,49 +60,13 @@ Result<> WriteVtkStructuredPoints::operator()() outStrm << fmt::format("ORIGIN {} {} {}\n", origin[0], origin[1], origin[2]); outStrm << fmt::format("CELL_DATA {}\n", dims[0] * dims[1] * dims[2]); - Result<> result; + Result<> result; for(const auto& arrayPath : m_InputValues->SelectedDataArrayPaths) { m_MessageHandler({nx::core::IFilter::Message::Type::Info, fmt::format("Writing {}", arrayPath.toString())}); - IDataArray& dataArray = m_DataStructure.getDataRefAs(arrayPath); - auto dataType = dataArray.getDataType(); - - switch(dataType) - { - case DataType::int8: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::uint8: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::int16: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::uint16: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::int32: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::uint32: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::int64: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::uint64: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::float32: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - case DataType::float64: - MergeResults(result, writeVtkData(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); - break; - default: - MergeResults(result, MakeErrorResult(-666666, "The chosen scalar type is not supported by this filter.")); - } + auto& dataArray = m_DataStructure.getDataRefAs(arrayPath); + result = MergeResults(result, ExecuteNeighborFunction(WriteVtkDataFunctor{}, dataArray.getDataType(), outStrm, dataArray, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); } return result; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ConditionalSetValueFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ConditionalSetValueFilter.cpp index 641fd5c7ec..eb8b0bf337 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ConditionalSetValueFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ConditionalSetValueFilter.cpp @@ -39,18 +39,18 @@ struct ReplaceValueInArrayFunctor template void operator()(IDataArray& workingArray, const std::string& removeValue, const std::string& replaceValue) { - auto& dataArray = dynamic_cast&>(workingArray); + auto& dataStore = workingArray.getIDataStoreRefAs>(); auto removeVal = convertFromStringToType(removeValue); auto replaceVal = convertFromStringToType(replaceValue); - const auto size = dataArray.getNumberOfTuples() * dataArray.getNumberOfComponents(); + const auto size = dataStore.getNumberOfTuples() * dataStore.getNumberOfComponents(); for(usize index = 0; index < size; index++) { - if(dataArray[index] == removeVal) + if(dataStore[index] == removeVal) { - dataArray[index] = replaceVal; + dataStore[index] = replaceVal; } } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp index 2f26294bd2..c9aa0580ba 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp @@ -72,8 +72,8 @@ class CropImageGeomDataArray { public: CropImageGeomDataArray(const IDataArray& oldCellArray, IDataArray& newCellArray, const ImageGeom& srcImageGeom, std::array bounds, const std::atomic_bool& shouldCancel) - : m_OldCellArray(dynamic_cast&>(oldCellArray)) - , m_NewCellArray(dynamic_cast&>(newCellArray)) + : m_OldCellStore(oldCellArray.getIDataStoreRefAs>()) + , m_NewCellStore(newCellArray.getIDataStoreRefAs>()) , m_SrcImageGeom(srcImageGeom) , m_Bounds(bounds) , m_ShouldCancel(shouldCancel) @@ -95,11 +95,9 @@ class CropImageGeomDataArray protected: void convert() const { - size_t numComps = m_OldCellArray.getNumberOfComponents(); - const auto& oldCellData = m_OldCellArray.getDataStoreRef(); + size_t numComps = m_OldCellStore.getNumberOfComponents(); - auto& dataStore = m_NewCellArray.getDataStoreRef(); - std::fill(dataStore.begin(), dataStore.end(), static_cast(-1)); + m_NewCellStore.fill(static_cast(-1)); auto srcDims = m_SrcImageGeom.getDimensions(); @@ -117,7 +115,7 @@ class CropImageGeomDataArray uint64 srcIndex = (srcDims[0] * srcDims[1] * zIndex) + (srcDims[0] * yIndex) + xIndex; for(size_t compIndex = 0; compIndex < numComps; compIndex++) { - dataStore.setValue(destTupleIndex * numComps + compIndex, oldCellData.getValue(srcIndex * numComps + compIndex)); + m_NewCellStore.setValue(destTupleIndex * numComps + compIndex, m_OldCellStore.getValue(srcIndex * numComps + compIndex)); } destTupleIndex++; } @@ -126,8 +124,8 @@ class CropImageGeomDataArray } private: - const DataArray& m_OldCellArray; - DataArray& m_NewCellArray; + const AbstractDataStore& m_OldCellStore; + AbstractDataStore& m_NewCellStore; const ImageGeom& m_SrcImageGeom; std::array m_Bounds; const std::atomic_bool& m_ShouldCancel; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropVertexGeometryFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropVertexGeometryFilter.cpp index 5601ab7d16..80f9a6549c 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropVertexGeometryFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropVertexGeometryFilter.cpp @@ -21,14 +21,12 @@ namespace struct CopyDataToCroppedGeometryFunctor { template - void operator()(const IDataArray& inDataRef, IDataArray& outDataRef, const std::vector& croppedPoints) + void operator()(const IDataArray* inDataRef, IDataArray* outDataRef, const std::vector& croppedPoints) { - const DataArray& inputDataArray = dynamic_cast&>(inDataRef); - const auto& inputData = inputDataArray.getDataStoreRef(); - DataArray& croppedDataArray = dynamic_cast&>(outDataRef); - auto& croppedData = croppedDataArray.getDataStoreRef(); + const auto& inputData = inDataRef->getIDataStoreRefAs>(); + auto& croppedData = outDataRef->getIDataStoreRefAs>(); - usize nComps = inDataRef.getNumberOfComponents(); + usize nComps = inDataRef->getNumberOfComponents(); for(std::vector::size_type i = 0; i < croppedPoints.size(); i++) { @@ -214,7 +212,7 @@ Result<> CropVertexGeometryFilter::executeImpl(DataStructure& dataStructure, con auto zMax = posMax[2]; auto& vertices = dataStructure.getDataRefAs(vertexGeomPath); - int64 numVerts = static_cast(vertices.getNumberOfVertices()); + auto numVerts = static_cast(vertices.getNumberOfVertices()); auto* verticesPtr = vertices.getVertices(); auto& allVerts = verticesPtr->getDataStoreRef(); std::vector croppedPoints; @@ -257,10 +255,10 @@ Result<> CropVertexGeometryFilter::executeImpl(DataStructure& dataStructure, con { DataPath destArrayPath(croppedVertexDataPath.createChildPath(targetArrayPath.getTargetName())); - const auto& srcArray = dataStructure.getDataRefAs(targetArrayPath); - auto& destArray = dataStructure.getDataRefAs(destArrayPath); + const auto* srcArray = dataStructure.getDataAs(targetArrayPath); + auto* destArray = dataStructure.getDataAs(destArrayPath); - ExecuteDataFunction(CopyDataToCroppedGeometryFunctor{}, srcArray.getDataType(), srcArray, destArray, croppedPoints); + ExecuteDataFunction(CopyDataToCroppedGeometryFunctor{}, srcArray->getDataType(), srcArray, destArray, croppedPoints); } return {}; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractInternalSurfacesFromTriangleGeometryFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractInternalSurfacesFromTriangleGeometryFilter.cpp index cd3739a6a1..dceb55ce78 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractInternalSurfacesFromTriangleGeometryFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractInternalSurfacesFromTriangleGeometryFilter.cpp @@ -38,15 +38,13 @@ void hashCombine(usize& seed, const T& obj) struct CopyDataFunctor { template - void operator()(IDataArray& inDataPtr, IDataArray& outDataPtr, std::unordered_map& elementMap) const + void operator()(IDataArray* inDataPtr, IDataArray* outDataPtr, std::unordered_map& elementMap) const { - auto& inputDataPtr = dynamic_cast&>(inDataPtr); - AbstractDataStore& inputData = inputDataPtr.getDataStoreRef(); - auto croppedDataPtr = dynamic_cast&>(outDataPtr); - AbstractDataStore& outputData = croppedDataPtr.getDataStoreRef(); + auto& inputData = inDataPtr->getIDataStoreRefAs>(); + auto& outputData = outDataPtr->getIDataStoreRefAs>(); - usize nTuples = outDataPtr.getNumberOfTuples(); - usize nComps = inDataPtr.getNumberOfComponents(); + usize nTuples = outDataPtr->getNumberOfTuples(); + usize nComps = inDataPtr->getNumberOfComponents(); usize tmpIndex = 0; usize ptrIndex = 0; @@ -66,10 +64,10 @@ struct RemoveFlaggedVerticesFunctor { // copy data to masked geometry template - void operator()(IDataArray& inputDataPtr, IDataArray& outputDataArray, const std::vector& indexMapping) const + void operator()(IDataArray* inputDataPtr, IDataArray* outputDataArray, const std::vector& indexMapping) const { - auto& inputData = dynamic_cast&>(inputDataPtr); - auto& outputData = dynamic_cast&>(outputDataArray); + auto& inputData = inputDataPtr->getIDataStoreRefAs>(); + auto& outputData = outputDataArray->getIDataStoreRefAs>(); usize nComps = inputData.getNumberOfComponents(); IGeometry::MeshIndexType notSeen = std::numeric_limits::max(); @@ -297,7 +295,7 @@ Result<> ExtractInternalSurfacesFromTriangleGeometryFilter::executeImpl(DataStru MeshIndexType currentNewTriIndex = 0; MeshIndexType currentNewVertIndex = 0; - // Loop over all of the triangles mapping the triangle and the vertices to the new array locations + // Loop over all the triangles mapping the triangle and the vertices to the new array locations for(MeshIndexType triIndex = 0; triIndex < numTris; triIndex++) { MeshIndexType v0Index = triangles[3 * triIndex + 0]; @@ -385,20 +383,20 @@ Result<> ExtractInternalSurfacesFromTriangleGeometryFilter::executeImpl(DataStru for(const auto& targetArrayPath : copyVertexPaths) { DataPath destinationPath = internalTrianglesPath.createChildPath(vertexDataName).createChildPath(targetArrayPath.getTargetName()); - auto& src = dataStructure.getDataRefAs(targetArrayPath); - auto& dest = dataStructure.getDataRefAs(destinationPath); + auto* src = dataStructure.getDataAs(targetArrayPath); + auto* dest = dataStructure.getDataAs(destinationPath); - ExecuteDataFunction(RemoveFlaggedVerticesFunctor{}, src.getDataType(), src, dest, vertNewIndex); + ExecuteDataFunction(RemoveFlaggedVerticesFunctor{}, src->getDataType(), src, dest, vertNewIndex); } for(const auto& targetArrayPath : copyTrianglePaths) { DataPath destinationPath = internalTrianglesPath.createChildPath(faceDataName).createChildPath(targetArrayPath.getTargetName()); - auto& src = dataStructure.getDataRefAs(targetArrayPath); - auto& dest = dataStructure.getDataRefAs(destinationPath); - dest.getIDataStore()->resizeTuples({currentNewTriIndex}); + auto* src = dataStructure.getDataAs(targetArrayPath); + auto* dest = dataStructure.getDataAs(destinationPath); + dest->resizeTuples({currentNewTriIndex}); - ExecuteDataFunction(RemoveFlaggedVerticesFunctor{}, src.getDataType(), src, dest, triNewIndex); + ExecuteDataFunction(RemoveFlaggedVerticesFunctor{}, src->getDataType(), src, dest, triNewIndex); } return {}; @@ -410,7 +408,6 @@ namespace SIMPL { constexpr StringLiteral k_TriangleDataContainerNameKey = "TriangleDataContainerName"; constexpr StringLiteral k_NodeTypesArrayPathKey = "NodeTypesArrayPath"; -constexpr StringLiteral k_InternalTrianglesNameKey = "InternalTrianglesName"; } // namespace SIMPL } // namespace diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InitializeDataFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InitializeDataFilter.cpp index 872bce3c80..f6e637dc72 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InitializeDataFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InitializeDataFilter.cpp @@ -66,9 +66,9 @@ using AdditionT = IncrementalOptions; using SubtractionT = IncrementalOptions; template -void ValueFill(DataArray& dataArray, const std::vector& stringValues) +void ValueFill(AbstractDataStore& dataStore, const std::vector& stringValues) { - usize numComp = dataArray.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free + usize numComp = dataStore.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free if(numComp > 1) { @@ -79,13 +79,13 @@ void ValueFill(DataArray& dataArray, const std::vector& stringVa values.emplace_back(ConvertTo::convert(str).value()); } - usize numTup = dataArray.getNumberOfTuples(); + usize numTup = dataStore.getNumberOfTuples(); for(usize tup = 0; tup < numTup; tup++) { for(usize comp = 0; comp < numComp; comp++) { - dataArray[tup * numComp + comp] = values[comp]; + dataStore[tup * numComp + comp] = values[comp]; } } } @@ -93,14 +93,14 @@ void ValueFill(DataArray& dataArray, const std::vector& stringVa { Result result = ConvertTo::convert(stringValues[0]); T value = result.value(); - dataArray.fill(value); + dataStore.fill(value); } } template -void IncrementalFill(DataArray& dataArray, const std::vector& startValues, const std::vector& stepValues) +void IncrementalFill(AbstractDataStore& dataStore, const std::vector& startValues, const std::vector& stepValues) { - usize numComp = dataArray.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free + usize numComp = dataStore.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free std::vector values(numComp); std::vector steps(numComp); @@ -116,13 +116,13 @@ void IncrementalFill(DataArray& dataArray, const std::vector& st } } - usize numTup = dataArray.getNumberOfTuples(); + usize numTup = dataStore.getNumberOfTuples(); if constexpr(std::is_same_v) { for(usize comp = 0; comp < numComp; comp++) { - dataArray[comp] = values[comp]; + dataStore[comp] = values[comp]; if constexpr(IncrementalOptions::UsingAddition) { @@ -138,7 +138,7 @@ void IncrementalFill(DataArray& dataArray, const std::vector& st { for(usize comp = 0; comp < numComp; comp++) { - dataArray[tup * numComp + comp] = values[comp]; + dataStore[tup * numComp + comp] = values[comp]; } } } @@ -149,7 +149,7 @@ void IncrementalFill(DataArray& dataArray, const std::vector& st { for(usize comp = 0; comp < numComp; comp++) { - dataArray[tup * numComp + comp] = values[comp]; + dataStore[tup * numComp + comp] = values[comp]; if constexpr(IncrementalOptions::UsingAddition) { @@ -165,9 +165,9 @@ void IncrementalFill(DataArray& dataArray, const std::vector& st } template -void RandomFill(std::vector& dist, DataArray& dataArray, const uint64 seed, const bool standardizeSeed) +void RandomFill(std::vector& dist, AbstractDataStore& dataStore, const uint64 seed, const bool standardizeSeed) { - usize numComp = dataArray.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free + usize numComp = dataStore.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free std::vector generators(numComp, std::mt19937_64{}); @@ -176,7 +176,7 @@ void RandomFill(std::vector& dist, DataArray& dataArray, const generators[comp].seed((standardizeSeed ? seed : seed + comp)); // If standardizing seed all generators use the same else, use modified seeds } - usize numTup = dataArray.getNumberOfTuples(); + usize numTup = dataStore.getNumberOfTuples(); for(usize tup = 0; tup < numTup; tup++) { @@ -186,23 +186,23 @@ void RandomFill(std::vector& dist, DataArray& dataArray, const { if constexpr(Ranged) { - dataArray[tup * numComp + comp] = static_cast(dist[comp](generators[comp])); + dataStore[tup * numComp + comp] = static_cast(dist[comp](generators[comp])); } if constexpr(!Ranged) { if constexpr(std::is_signed_v) { - dataArray[tup * numComp + comp] = static_cast(dist[comp](generators[comp]) * (std::numeric_limits::max() - 1) * (((rand() & 1) == 0) ? 1 : -1)); + dataStore[tup * numComp + comp] = static_cast(dist[comp](generators[comp]) * (std::numeric_limits::max() - 1) * (((rand() & 1) == 0) ? 1 : -1)); } if constexpr(!std::is_signed_v) { - dataArray[tup * numComp + comp] = static_cast(dist[comp](generators[comp]) * std::numeric_limits::max()); + dataStore[tup * numComp + comp] = static_cast(dist[comp](generators[comp]) * std::numeric_limits::max()); } } } if constexpr(!std::is_floating_point_v) { - dataArray[tup * numComp + comp] = static_cast(dist[comp](generators[comp])); + dataStore[tup * numComp + comp] = static_cast(dist[comp](generators[comp])); } } } @@ -292,16 +292,16 @@ struct FillArrayFunctor template void operator()(IDataArray& iDataArray, const InitializeDataInputValues& inputValues) { - auto& dataArray = dynamic_cast&>(iDataArray); - usize numComp = dataArray.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free + auto& dataStore = iDataArray.getIDataStoreRefAs>(); + usize numComp = dataStore.getNumberOfComponents(); // We checked that the values string is greater than max comps size so proceed check free switch(inputValues.initType) { case InitializeType::FillValue: { - return ::ValueFill(dataArray, standardizeMultiComponent(numComp, inputValues.stringValues)); + return ::ValueFill(dataStore, standardizeMultiComponent(numComp, inputValues.stringValues)); } case InitializeType::Incremental: { - return ::FillIncForwarder(inputValues.stepType, dataArray, standardizeMultiComponent(numComp, inputValues.startValues), standardizeMultiComponent(numComp, inputValues.stepValues)); + return ::FillIncForwarder(inputValues.stepType, dataStore, standardizeMultiComponent(numComp, inputValues.startValues), standardizeMultiComponent(numComp, inputValues.stepValues)); } case InitializeType::Random: { std::vector range; @@ -321,7 +321,7 @@ struct FillArrayFunctor range.push_back(true); } } - return ::FillRandomForwarder(range, numComp, dataArray, inputValues.seed, inputValues.standardizeSeed); + return ::FillRandomForwarder(range, numComp, dataStore, inputValues.seed, inputValues.standardizeSeed); } case InitializeType::RangedRandom: { auto randBegin = standardizeMultiComponent(numComp, inputValues.randBegin); @@ -335,7 +335,7 @@ struct FillArrayFunctor result = ConvertTo::convert(randEnd[comp]); range.push_back(result.value()); } - return ::FillRandomForwarder(range, numComp, dataArray, inputValues.seed, inputValues.standardizeSeed); + return ::FillRandomForwarder(range, numComp, dataStore, inputValues.seed, inputValues.standardizeSeed); } } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InterpolatePointCloudToRegularGridFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InterpolatePointCloudToRegularGridFilter.cpp index 595f26c115..d061a9c8d0 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InterpolatePointCloudToRegularGridFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/InterpolatePointCloudToRegularGridFilter.cpp @@ -30,8 +30,7 @@ struct MapPointCloudDataByKernelFunctor template void operator()(IDataArray* source, INeighborList* dynamic, std::vector& kernelVals, const int64 kernel[3], const usize dims[3], usize curX, usize curY, usize curZ, usize vertIdx) { - auto* inputDataArray = dynamic_cast*>(source); - auto& inputData = inputDataArray->getDataStoreRef(); + auto& inputData = source->getIDataStoreRefAs>(); auto* interpolatedDataPtr = dynamic_cast*>(dynamic); usize index = 0; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/MultiThresholdObjectsFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/MultiThresholdObjectsFilter.cpp index b4cf48507b..0771a0663f 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/MultiThresholdObjectsFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/MultiThresholdObjectsFilter.cpp @@ -36,7 +36,7 @@ class ThresholdFilterHelper * @brief */ template - void filterDataLessThan(const DataArray& m_Input, T trueValue, T falseValue) + void filterDataLessThan(const AbstractDataStore& m_Input, T trueValue, T falseValue) { size_t m_NumValues = m_Input.getNumberOfTuples(); T value = static_cast(m_ComparisonValue); @@ -50,7 +50,7 @@ class ThresholdFilterHelper * @brief */ template - void filterDataGreaterThan(const DataArray& m_Input, T trueValue, T falseValue) + void filterDataGreaterThan(const AbstractDataStore& m_Input, T trueValue, T falseValue) { size_t m_NumValues = m_Input.getNumberOfTuples(); T value = static_cast(m_ComparisonValue); @@ -64,7 +64,7 @@ class ThresholdFilterHelper * @brief */ template - void filterDataEqualTo(const DataArray& m_Input, T trueValue, T falseValue) + void filterDataEqualTo(const AbstractDataStore& m_Input, T trueValue, T falseValue) { size_t m_NumValues = m_Input.getNumberOfTuples(); T value = static_cast(m_ComparisonValue); @@ -78,7 +78,7 @@ class ThresholdFilterHelper * @brief */ template - void filterDataNotEqualTo(const DataArray& m_Input, T trueValue, T falseValue) + void filterDataNotEqualTo(const AbstractDataStore& m_Input, T trueValue, T falseValue) { size_t m_NumValues = m_Input.getNumberOfTuples(); T value = static_cast(m_ComparisonValue); @@ -89,7 +89,7 @@ class ThresholdFilterHelper } template - void filterData(const DataArray& input, Type trueValue, Type falseValue) + void filterData(const AbstractDataStore& input, Type trueValue, Type falseValue) { if(m_ComparisonOperator == ArrayThreshold::ComparisonType::LessThan) { @@ -131,8 +131,8 @@ struct ExecuteThresholdHelper template void operator()(ThresholdFilterHelper& helper, const IDataArray& iDataArray, Type trueValue, Type falseValue) { - const auto& dataArray = dynamic_cast&>(iDataArray); - helper.template filterData(dataArray, trueValue, falseValue); + const auto& dataStore = iDataArray.getIDataStoreRefAs>(); + helper.template filterData(dataStore, trueValue, falseValue); } }; @@ -145,7 +145,7 @@ struct ExecuteThresholdHelper * @param inverse */ template -void InsertThreshold(usize numItems, DataArray& currentArray, nx::core::IArrayThreshold::UnionOperator unionOperator, std::vector& newArrayPtr, bool inverse, T trueValue, T falseValue) +void InsertThreshold(usize numItems, AbstractDataStore& currentStore, nx::core::IArrayThreshold::UnionOperator unionOperator, std::vector& newArrayPtr, bool inverse, T trueValue, T falseValue) { for(usize i = 0; i < numItems; i++) { @@ -157,11 +157,11 @@ void InsertThreshold(usize numItems, DataArray& currentArray, nx::core::IArra if(nx::core::IArrayThreshold::UnionOperator::Or == unionOperator) { - currentArray[i] = (currentArray[i] == trueValue || newArrayPtr[i] == trueValue) ? trueValue : falseValue; + currentStore[i] = (currentStore[i] == trueValue || newArrayPtr[i] == trueValue) ? trueValue : falseValue; } - else if(currentArray[i] == falseValue || newArrayPtr[i] == falseValue) + else if(currentStore[i] == falseValue || newArrayPtr[i] == falseValue) { - currentArray[i] = falseValue; + currentStore[i] = falseValue; } } } @@ -177,10 +177,10 @@ void ThresholdValue(std::shared_ptr& comparisonValue, DataStruct } // Traditionally we would do a check to ensure we get a valid pointer, I'm forgoing that check because it // was essentially done in the preflight part. - auto& outputResultArray = dataStructure.getDataRefAs>(outputResultArrayPath); + auto& outputResultStore = dataStructure.getDataAs>(outputResultArrayPath)->getDataStoreRef(); // Get the total number of tuples, create and initialize an array with FALSE to use for these results - size_t totalTuples = outputResultArray.getNumberOfTuples(); + size_t totalTuples = outputResultStore.getNumberOfTuples(); std::vector tempResultVector(totalTuples, falseValue); nx::core::ArrayThreshold::ComparisonType compOperator = comparisonValue->getComparisonType(); @@ -204,13 +204,13 @@ void ThresholdValue(std::shared_ptr& comparisonValue, DataStruct // copy the temp uint8 vector to the final uint8 result array for(size_t i = 0; i < totalTuples; i++) { - outputResultArray[i] = tempResultVector[i]; + outputResultStore[i] = tempResultVector[i]; } } else { // insert into current threshold - InsertThreshold(totalTuples, outputResultArray, unionOperator, tempResultVector, inverse, trueValue, falseValue); + InsertThreshold(totalTuples, outputResultStore, unionOperator, tempResultVector, inverse, trueValue, falseValue); } } @@ -266,10 +266,10 @@ void ThresholdSet(std::shared_ptr& inputComparisonSet, DataSt // Traditionally we would do a check to ensure we get a valid pointer, I'm forgoing that check because it // was essentially done in the preflight part. - auto& outputResultArray = dataStructure.getDataRefAs>(outputResultArrayPath); + auto& outputResultStore = dataStructure.getDataAs>(outputResultArrayPath)->getDataStoreRef(); // Get the total number of tuples, create and initialize an array with FALSE to use for these results - size_t totalTuples = outputResultArray.getNumberOfTuples(); + size_t totalTuples = outputResultStore.getNumberOfTuples(); std::vector tempResultVector(totalTuples, falseValue); T firstValueFound = 0; @@ -300,13 +300,13 @@ void ThresholdSet(std::shared_ptr& inputComparisonSet, DataSt // copy the temp uint8 vector to the final uint8 result array for(size_t i = 0; i < totalTuples; i++) { - outputResultArray[i] = tempResultVector[i]; + outputResultStore[i] = tempResultVector[i]; } } else { // insert into current threshold - InsertThreshold(totalTuples, outputResultArray, inputComparisonSet->getUnionOperator(), tempResultVector, inverse, trueValue, falseValue); + InsertThreshold(totalTuples, outputResultStore, inputComparisonSet->getUnionOperator(), tempResultVector, inverse, trueValue, falseValue); } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RemoveFlaggedVerticesFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RemoveFlaggedVerticesFilter.cpp index 6b94adc0c0..e13ac5b96f 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RemoveFlaggedVerticesFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RemoveFlaggedVerticesFilter.cpp @@ -32,13 +32,12 @@ struct RemoveFlaggedVerticesFunctor template void operator()(const IDataArray& sourceIDataArray, IDataArray& destIDataArray, const std::unique_ptr& maskCompare, size_t numVerticesToKeep) const { - using DataArrayType = DataArray; - const auto& sourceDataArray = dynamic_cast(sourceIDataArray); - auto& destinationDataArray = dynamic_cast(destIDataArray); - destinationDataArray.getDataStore()->resizeTuples({numVerticesToKeep}); + const auto& sourceDataStore = sourceIDataArray.getIDataStoreRefAs>(); + auto& destinationDataStore = destIDataArray.getIDataStoreRefAs>(); + destinationDataStore.resizeTuples({numVerticesToKeep}); - const usize numInputTuples = sourceDataArray.getNumberOfTuples(); - const usize nComps = sourceDataArray.getNumberOfComponents(); + const usize numInputTuples = sourceDataStore.getNumberOfTuples(); + const usize nComps = sourceDataStore.getNumberOfComponents(); usize destTupleIndex = 0; for(usize inputIndex = 0; inputIndex < numInputTuples; inputIndex++) { @@ -48,7 +47,7 @@ struct RemoveFlaggedVerticesFunctor { const usize sourceIndex = (nComps * inputIndex) + compIdx; const usize destinationIndex = (nComps * destTupleIndex) + compIdx; - destinationDataArray[destinationIndex] = sourceDataArray[sourceIndex]; + destinationDataStore[destinationIndex] = sourceDataStore[sourceIndex]; } destTupleIndex++; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinNumNeighborsFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinNumNeighborsFilter.cpp index 147eb34e81..b5bbf91bba 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinNumNeighborsFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinNumNeighborsFilter.cpp @@ -4,7 +4,6 @@ #include "simplnx/DataStructure/Geometry/ImageGeom.hpp" #include "simplnx/Filter/Actions/DeleteDataAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" -#include "simplnx/Parameters/AttributeMatrixSelectionParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/GeometrySelectionParameter.hpp" #include "simplnx/Parameters/MultiArraySelectionParameter.hpp" @@ -17,10 +16,8 @@ namespace nx::core { namespace { -constexpr int64 k_TupleCountInvalidError = -250; constexpr int64 k_MissingFeaturePhasesError = -251; constexpr int32 k_InconsistentTupleCount = -252; -constexpr int32 k_FetchChildArrayError = -5559; Result<> assignBadPoints(DataStructure& dataStructure, const Arguments& args, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) { @@ -30,9 +27,8 @@ Result<> assignBadPoints(DataStructure& dataStructure, const Arguments& args, co auto ignoredVoxelArrayPaths = args.value>(RequireMinNumNeighborsFilter::k_IgnoredVoxelArrays_Key); auto cellDataAttrMatrix = featureIdsPath.getParent(); - auto& featureIdsArray = dataStructure.getDataRefAs(featureIdsPath); + auto& featureIds = dataStructure.getDataAs(featureIdsPath)->getDataStoreRef(); auto& numNeighborsArray = dataStructure.getDataRefAs(numNeighborsPath); - auto& featureIds = featureIdsArray.getDataStoreRef(); auto applyToSinglePhase = args.value(RequireMinNumNeighborsFilter::k_ApplyToSinglePhase_Key); Int32Array* featurePhasesArray = nullptr; @@ -42,7 +38,7 @@ Result<> assignBadPoints(DataStructure& dataStructure, const Arguments& args, co featurePhasesArray = dataStructure.getDataAs(featurePhasesPath); } - usize totalPoints = featureIdsArray.getNumberOfTuples(); + usize totalPoints = featureIds.getNumberOfTuples(); SizeVec3 udims = dataStructure.getDataRefAs(imageGeomPath).getDimensions(); // This was checked up in the execute function (which is called before this function) @@ -250,11 +246,8 @@ nonstd::expected, Error> mergeContainedFeatures(DataStructure& auto phaseNumber = args.value(RequireMinNumNeighborsFilter::k_PhaseNumber_Key); - auto& featureIdsArray = dataStructure.getDataRefAs(featureIdsPath); - auto& numNeighborsArray = dataStructure.getDataRefAs(numNeighborsPath); - - auto& featureIds = featureIdsArray.getDataStoreRef(); - auto& numNeighbors = numNeighborsArray.getDataStoreRef(); + auto& featureIds = dataStructure.getDataAs(featureIdsPath)->getDataStoreRef(); + auto& numNeighbors = dataStructure.getDataAs(numNeighborsPath)->getDataStoreRef(); auto applyToSinglePhase = args.value(RequireMinNumNeighborsFilter::k_ApplyToSinglePhase_Key); Int32Array* featurePhasesArray = nullptr; @@ -266,7 +259,7 @@ nonstd::expected, Error> mergeContainedFeatures(DataStructure& bool good = false; usize totalPoints = dataStructure.getDataRefAs(imageGeomPath).getNumberOfCells(); - usize totalFeatures = numNeighborsArray.getNumberOfTuples(); + usize totalFeatures = numNeighbors.getNumberOfTuples(); std::vector activeObjects(totalFeatures, true); @@ -407,7 +400,7 @@ IFilter::PreflightResult RequireMinNumNeighborsFilter::preflightImpl(const DataS std::vector dataArrayPaths; std::vector cDims = {1}; - auto& featureIdsArray = dataStructure.getDataRefAs(featureIdsPath); + auto& featureIds = dataStructure.getDataRefAs(featureIdsPath); auto& numNeighborsArray = dataStructure.getDataRefAs(numNeighborsPath); dataArrayPaths.push_back(numNeighborsPath); @@ -462,10 +455,9 @@ Result<> RequireMinNumNeighborsFilter::executeImpl(DataStructure& dataStructure, // we don't have access to the data yet if(applyToSinglePhase) { - auto& featurePhasesArray = dataStructure.getDataRefAs(featurePhasesPath); - auto& featurePhases = featurePhasesArray.getDataStoreRef(); + auto& featurePhases = dataStructure.getDataAs(featurePhasesPath)->getDataStoreRef(); - usize numFeatures = featurePhasesArray.getNumberOfTuples(); + usize numFeatures = featurePhases.getNumberOfTuples(); bool unavailablePhase = true; for(usize i = 0; i < numFeatures; i++) { @@ -506,13 +498,13 @@ Result<> RequireMinNumNeighborsFilter::executeImpl(DataStructure& dataStructure, return assignBadPointsResult; } - auto& featureIdsArray = dataStructure.getDataRefAs(featureIdsPath); + auto& featureIdsStore = dataStructure.getDataAs(featureIdsPath)->getDataStoreRef(); auto numNeighborsPath = args.value(RequireMinNumNeighborsFilter::k_NumNeighborsPath_Key); - auto& numNeighborsArray = dataStructure.getDataRefAs(numNeighborsPath); + auto* numNeighborsArray = dataStructure.getDataAs(numNeighborsPath); DataPath cellFeatureGroupPath = numNeighborsPath.getParent(); - size_t currentFeatureCount = numNeighborsArray.getNumberOfTuples(); + size_t currentFeatureCount = numNeighborsArray->getNumberOfTuples(); auto activeObjects = activeObjectsResult.value(); int32 count = 0; @@ -523,7 +515,7 @@ Result<> RequireMinNumNeighborsFilter::executeImpl(DataStructure& dataStructure, std::string message = fmt::format("Feature Count Changed: Previous: {} New: {}", currentFeatureCount, count); messageHandler(nx::core::IFilter::Message{nx::core::IFilter::Message::Type::Info, message}); - nx::core::RemoveInactiveObjects(dataStructure, cellFeatureGroupPath, activeObjects, featureIdsArray, currentFeatureCount, messageHandler, shouldCancel); + nx::core::RemoveInactiveObjects(dataStructure, cellFeatureGroupPath, activeObjects, featureIdsStore, currentFeatureCount, messageHandler, shouldCancel); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinimumSizeFeaturesFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinimumSizeFeaturesFilter.cpp index cae48b7e63..e39b953eca 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinimumSizeFeaturesFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RequireMinimumSizeFeaturesFilter.cpp @@ -5,7 +5,6 @@ #include "simplnx/Filter/Actions/DeleteDataAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" -#include "simplnx/Parameters/DataPathSelectionParameter.hpp" #include "simplnx/Parameters/GeometrySelectionParameter.hpp" #include "simplnx/Parameters/NumberParameter.hpp" #include "simplnx/Utilities/DataGroupUtilities.hpp" @@ -29,15 +28,11 @@ namespace constexpr int32 k_BadMinAllowedFeatureSize = -5555; constexpr int32 k_BadNumCellsPath = -5556; constexpr int32 k_ParentlessPathError = -5557; -constexpr int32 k_NeighborListRemoval = -5558; -constexpr int32 k_FetchChildArrayError = -5559; -void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPath, SizeVec3 dimensions, const NumCellsArrayType& numCellsArrayRef) +void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPath, SizeVec3 dimensions, const NumCellsArrayType::store_type& numCellsStoreRef) { - FeatureIdsArrayType* featureIdsPtr = dataStructure.getDataAs(featureIdsPath); - - usize totalPoints = featureIdsPtr->getNumberOfTuples(); - FeatureIdsArrayType::store_type* featureIds = featureIdsPtr->getDataStore(); + FeatureIdsArrayType::store_type* featureIds = dataStructure.getDataAs(featureIdsPath)->getDataStore(); + usize totalPoints = featureIds->getNumberOfTuples(); std::array dims = { static_cast(dimensions[0]), @@ -45,7 +40,7 @@ void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPa static_cast(dimensions[2]), }; - std::vector neighbors(totalPoints * featureIdsPtr->getNumberOfComponents(), -1); + std::vector neighbors(totalPoints * featureIds->getNumberOfComponents(), -1); int32 good = 1; int32 current = 0; @@ -61,7 +56,7 @@ void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPa int32 featurename = 0; int32 feature = 0; int32 neighbor = 0; - std::vector n(numCellsArrayRef.getNumberOfTuples(), 0); + std::vector n(numCellsStoreRef.getNumberOfTuples(), 0); while(counter != 0) { @@ -165,7 +160,7 @@ void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPa } } DataPath attrMatPath = featureIdsPath.getParent(); - BaseGroup* parentGroup = dataStructure.getDataAs(attrMatPath); + auto* parentGroup = dataStructure.getDataAs(attrMatPath); std::vector voxelArrayNames; for(const auto& [identifier, sharedChild] : *parentGroup) { @@ -187,7 +182,7 @@ void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPa for(auto& voxelArrayName : voxelArrayNames) { auto arrayPath = attrMatPath.createChildPath(voxelArrayName); - IDataArray* arr = dataStructure.getDataAs(arrayPath); + auto* arr = dataStructure.getDataAs(arrayPath); arr->copyTuple(neighbor, j); } } @@ -197,23 +192,15 @@ void assign_badpoints(DataStructure& dataStructure, const DataPath& featureIdsPa } // ----------------------------------------------------------------------------- -std::vector remove_smallfeatures(FeatureIdsArrayType& featureIdsArrayRef, const NumCellsArrayType& numCellsArrayRef, const PhasesArrayType* featurePhaseArrayPtr, int32_t phaseNumber, - bool applyToSinglePhase, int64 minAllowedFeatureSize, Error& errorReturn) +std::vector remove_smallfeatures(FeatureIdsArrayType::store_type& featureIdsStoreRef, const NumCellsArrayType::store_type& numCells, const PhasesArrayType::store_type* featurePhases, + int32_t phaseNumber, bool applyToSinglePhase, int64 minAllowedFeatureSize, Error& errorReturn) { - size_t totalPoints = featureIdsArrayRef.getNumberOfTuples(); - FeatureIdsArrayType::store_type& featureIdsStoreRef = featureIdsArrayRef.getDataStoreRef(); + size_t totalPoints = featureIdsStoreRef.getNumberOfTuples(); bool good = false; int32 gnum; - size_t totalFeatures = numCellsArrayRef.getNumberOfTuples(); - const NumCellsArrayType::store_type& numCells = numCellsArrayRef.getDataStoreRef(); - - const PhasesArrayType::store_type* featurePhases = nullptr; - if(applyToSinglePhase) - { - featurePhases = featurePhaseArrayPtr->getDataStore(); - } + size_t totalFeatures = numCells.getNumberOfTuples(); std::vector activeObjects(totalFeatures, true); @@ -336,12 +323,12 @@ IFilter::PreflightResult RequireMinimumSizeFeaturesFilter::preflightImpl(const D return {nonstd::make_unexpected(std::vector{Error{-k_BadMinAllowedFeatureSize, ss}})}; } - const FeatureIdsArrayType* featureIdsPtr = dataStructure.getDataAs(featureIdsPath); + const auto* featureIdsPtr = dataStructure.getDataAs(featureIdsPath); if(featureIdsPtr == nullptr) { return {nonstd::make_unexpected(std::vector{Error{k_BadNumCellsPath, "FeatureIds not provided as an Int32 Array."}})}; } - const NumCellsArrayType* numCellsPtr = dataStructure.getDataAs(numCellsPath); + const auto* numCellsPtr = dataStructure.getDataAs(numCellsPath); if(numCellsPtr == nullptr) { return {nonstd::make_unexpected(std::vector{Error{k_BadNumCellsPath, "Num Cells not provided as an Int32 Array."}})}; @@ -350,7 +337,7 @@ IFilter::PreflightResult RequireMinimumSizeFeaturesFilter::preflightImpl(const D if(applyToSinglePhase) { - const PhasesArrayType* featurePhasesPtr = dataStructure.getDataAs(featurePhasesPath); + const auto* featurePhasesPtr = dataStructure.getDataAs(featurePhasesPath); if(featurePhasesPtr != nullptr) { dataArrayPaths.push_back(featurePhasesPath); @@ -360,7 +347,7 @@ IFilter::PreflightResult RequireMinimumSizeFeaturesFilter::preflightImpl(const D dataStructure.validateNumberOfTuples(dataArrayPaths); DataPath featureGroupDataPath = numCellsPath.getParent(); - const BaseGroup* featureDataGroup = dataStructure.getDataAs(featureGroupDataPath); + const auto* featureDataGroup = dataStructure.getDataAs(featureGroupDataPath); if(nullptr == featureDataGroup) { return {nonstd::make_unexpected(std::vector{Error{k_ParentlessPathError, "The provided NumCells DataPath does not have a parent."}})}; @@ -397,18 +384,16 @@ Result<> RequireMinimumSizeFeaturesFilter::executeImpl(DataStructure& dataStruct auto minAllowedFeatureSize = args.value(k_MinAllowedFeaturesSize_Key); auto phaseNumber = args.value(k_PhaseNumber_Key); - PhasesArrayType* featurePhasesArray = applyToSinglePhase ? dataStructure.getDataAs(featurePhasesPath) : nullptr; + PhasesArrayType::store_type* featurePhases = applyToSinglePhase ? dataStructure.getDataAs(featurePhasesPath)->getDataStore() : nullptr; - FeatureIdsArrayType& featureIdsArrayRef = dataStructure.getDataRefAs(featureIdsPath); - FeatureIdsArrayType::store_type& featureIdsStoreRef = featureIdsArrayRef.getDataStoreRef(); + FeatureIdsArrayType::store_type& featureIdsStoreRef = dataStructure.getDataAs(featureIdsPath)->getDataStoreRef(); - NumCellsArrayType& numCellsArrayRef = dataStructure.getDataRefAs(numCellsPath); + auto& numCellsArrayRef = dataStructure.getDataRefAs(numCellsPath); NumCellsArrayType::store_type& numCellsStoreRef = numCellsArrayRef.getDataStoreRef(); - if(applyToSinglePhase) + if(applyToSinglePhase && featurePhases != nullptr) { - usize numFeatures = featurePhasesArray->getNumberOfTuples(); - auto featurePhases = featurePhasesArray->getDataStore(); + usize numFeatures = featurePhases->getNumberOfTuples(); bool unavailablePhase = true; for(size_t i = 0; i < numFeatures; i++) @@ -428,14 +413,14 @@ Result<> RequireMinimumSizeFeaturesFilter::executeImpl(DataStructure& dataStruct } Error errorReturn; - std::vector activeObjects = remove_smallfeatures(featureIdsArrayRef, numCellsArrayRef, featurePhasesArray, phaseNumber, applyToSinglePhase, minAllowedFeatureSize, errorReturn); + std::vector activeObjects = remove_smallfeatures(featureIdsStoreRef, numCellsStoreRef, featurePhases, phaseNumber, applyToSinglePhase, minAllowedFeatureSize, errorReturn); if(errorReturn.code < 0) { return {nonstd::make_unexpected(std::vector{errorReturn})}; } - ImageGeom& imageGeom = dataStructure.getDataRefAs(imageGeomPath); - assign_badpoints(dataStructure, featureIdsPath, imageGeom.getDimensions(), numCellsArrayRef); + auto& imageGeom = dataStructure.getDataRefAs(imageGeomPath); + assign_badpoints(dataStructure, featureIdsPath, imageGeom.getDimensions(), numCellsStoreRef); DataPath cellFeatureGroupPath = numCellsPath.getParent(); size_t currentFeatureCount = numCellsStoreRef.getNumberOfTuples(); @@ -451,7 +436,7 @@ Result<> RequireMinimumSizeFeaturesFilter::executeImpl(DataStructure& dataStruct std::string message = fmt::format("Feature Count Changed: Previous: {} New: {}", currentFeatureCount, count); messageHandler(nx::core::IFilter::Message{nx::core::IFilter::Message::Type::Info, message}); - nx::core::RemoveInactiveObjects(dataStructure, cellFeatureGroupPath, activeObjects, featureIdsArrayRef, currentFeatureCount, messageHandler, shouldCancel); + nx::core::RemoveInactiveObjects(dataStructure, cellFeatureGroupPath, activeObjects, featureIdsStoreRef, currentFeatureCount, messageHandler, shouldCancel); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RobustAutomaticThresholdFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RobustAutomaticThresholdFilter.cpp index 0a7ae21c83..c0a93f951e 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RobustAutomaticThresholdFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RobustAutomaticThresholdFilter.cpp @@ -6,6 +6,7 @@ #include "simplnx/Filter/Actions/CreateArrayAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" +#include "simplnx/Utilities/FilterUtilities.hpp" #include "simplnx/Utilities/SIMPLConversion.hpp" #include "simplnx/Parameters/DataObjectNameParameter.hpp" @@ -18,83 +19,37 @@ namespace constexpr int32 k_IncorrectInputArrayType = -2363; constexpr int32 k_InconsistentTupleCount = -2364; -template -void FindThreshold(const DataArray& inputArray, const Float32Array& gradMagnitudeArray, BoolArray& maskArray) +struct FindThresholdFunctor { - const AbstractDataStore& inputData = inputArray.getDataStoreRef(); - const AbstractDataStore& gradMag = gradMagnitudeArray.getDataStoreRef(); - AbstractDataStore& maskStore = maskArray.getDataStoreRef(); - - usize numTuples = inputArray.getNumberOfTuples(); - float numerator = 0; - float denominator = 0; - - for(usize i = 0; i < numTuples; i++) + template + void operator()(const IDataArray* inputObject, const Float32AbstractDataStore& gradMag, BoolAbstractDataStore& maskStore) { - numerator += (inputData.getValue(i) * gradMag.getValue(i)); - denominator += gradMag.getValue(i); - } + const auto& inputData = inputObject->getIDataStoreRefAs>(); + usize numTuples = inputData.getNumberOfTuples(); + float numerator = 0; + float denominator = 0; - float threshold = numerator / denominator; - - for(usize i = 0; i < numTuples; i++) - { - if(inputData.getValue(i) < threshold) + for(usize i = 0; i < numTuples; i++) { - maskStore.setValue(i, 0); + numerator += (inputData.getValue(i) * gradMag.getValue(i)); + denominator += gradMag.getValue(i); } - else - { - maskStore.setValue(i, 1); - } - } -} - -void FindThreshold(const IDataArray& inputObject, const Float32Array& gradMagnitudeArray, BoolArray& maskArray) -{ - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } + float threshold = numerator / denominator; - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); - } - if(auto inputArray = dynamic_cast(&inputObject); inputArray != nullptr) - { - FindThreshold(*inputArray, gradMagnitudeArray, maskArray); + for(usize i = 0; i < numTuples; i++) + { + if(inputData.getValue(i) < threshold) + { + maskStore.setValue(i, false); + } + else + { + maskStore.setValue(i, true); + } + } } -} +}; } // namespace namespace nx::core @@ -197,11 +152,11 @@ Result<> RobustAutomaticThresholdFilter::executeImpl(DataStructure& dataStructur auto gradientArrayPath = args.value(k_GradientMagnitudePath_Key); auto createdMaskName = args.value(k_ArrayCreationName_Key); - const auto& inputArray = dataStructure.getDataRefAs(inputArrayPath); - const auto& gradientArray = dataStructure.getDataRefAs(gradientArrayPath); - auto& maskArray = dataStructure.getDataRefAs(inputArrayPath.replaceName(createdMaskName)); + const auto* inputArray = dataStructure.getDataAs(inputArrayPath); + const auto& gradientStore = dataStructure.getDataAs(gradientArrayPath)->getDataStoreRef(); + auto& maskStore = dataStructure.getDataAs(inputArrayPath.replaceName(createdMaskName))->getDataStoreRef(); - FindThreshold(inputArray, gradientArray, maskArray); + ExecuteNeighborFunction(FindThresholdFunctor{}, inputArray->getDataType(), inputArray, gradientStore, maskStore); return {}; } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/VtkUtilities.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/VtkUtilities.hpp index 4134739be4..3a68099737 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/VtkUtilities.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/VtkUtilities.hpp @@ -9,7 +9,7 @@ static constexpr usize k_BufferDumpVal = 1000000; // ----------------------------------------------------------------------------- template -std::string TypeForPrimitive(T value, const IFilter::MessageHandler& messageHandler) +std::string TypeForPrimitive(const IFilter::MessageHandler& messageHandler) { if constexpr(std::is_same_v) { @@ -122,14 +122,14 @@ std::string TypeForPrimitive(T value, const IFilter::MessageHandler& messageHand return "char"; } - messageHandler(IFilter::Message::Type::Info, fmt::format("Error: TypeForPrimitive - Unknown Type: ", typeid(value).name())); - if(const char* name = typeid(value).name(); nullptr != name && name[0] == 'l') + messageHandler(IFilter::Message::Type::Info, fmt::format("Error: TypeForPrimitive - Unknown Type: ", typeid(T).name())); + if(const char* name = typeid(T).name(); nullptr != name && name[0] == 'l') { messageHandler( IFilter::Message::Type::Info, fmt::format( "You are using 'long int' as a type which is not 32/64 bit safe. It is suggested you use one of the H5SupportTypes defined in such as int32_t or uint32_t.", - typeid(value).name())); + typeid(T).name())); } return ""; } @@ -140,16 +140,17 @@ struct WriteVtkDataArrayFunctor template void operator()(FILE* outputFile, bool binary, DataStructure& dataStructure, const DataPath& arrayPath, const IFilter::MessageHandler& messageHandler) { - auto& dataArray = dataStructure.getDataRefAs>(arrayPath); + auto* dataArray = dataStructure.getDataAs>(arrayPath); + auto& dataStore = dataArray->template getIDataStoreRefAs>(); - messageHandler(IFilter::Message::Type::Info, fmt::format("Writing Cell Data {}", dataArray.getName())); + messageHandler(IFilter::Message::Type::Info, fmt::format("Writing Cell Data {}", arrayPath.getTargetName())); - const usize totalElements = dataArray.getSize(); - const int numComps = static_cast(dataArray.getNumberOfComponents()); - std::string dName = dataArray.getName(); + const usize totalElements = dataStore.getSize(); + const int numComps = static_cast(dataStore.getNumberOfComponents()); + std::string dName = arrayPath.getTargetName(); dName = StringUtilities::replace(dName, " ", "_"); - const std::string vtkTypeString = TypeForPrimitive(dataArray[0], messageHandler); + const std::string vtkTypeString = TypeForPrimitive(messageHandler); bool useIntCast = false; if(vtkTypeString == "unsigned_char" || vtkTypeString == "char") { @@ -162,13 +163,13 @@ struct WriteVtkDataArrayFunctor { if constexpr(endian::little == endian::native) { - dataArray.byteSwapElements(); + dataArray->byteSwapElements(); } - fwrite(dataArray.template getIDataStoreAs>()->data(), sizeof(T), totalElements, outputFile); + fwrite(dataStore.data(), sizeof(T), totalElements, outputFile); fprintf(outputFile, "\n"); if constexpr(endian::little == endian::native) { - dataArray.byteSwapElements(); + dataArray->byteSwapElements(); } } else @@ -183,19 +184,15 @@ struct WriteVtkDataArrayFunctor } if(useIntCast) { - buffer.append(fmt::format(" {:d}", static_cast(dataArray[i]))); + buffer.append(fmt::format(" {:d}", static_cast(dataStore[i]))); } - else if constexpr(std::is_same_v) + else if constexpr(std::is_floating_point_v) { - buffer.append(fmt::format(" {:f}", dataArray[i])); - } - else if constexpr(std::is_same_v) - { - buffer.append(fmt::format(" {:f}", dataArray[i])); + buffer.append(fmt::format(" {:f}", dataStore[i])); } else { - buffer.append(fmt::format(" {}", dataArray[i])); + buffer.append(fmt::format(" {}", dataStore[i])); } // If the buffer is within 32 bytes of the reserved size, then dump // the contents to the file. @@ -215,7 +212,7 @@ struct WriteVtkDataArrayFunctor template inline std::string ConvertDataTypeToVtkDataType() noexcept { - if constexpr(std::is_same_v) + if constexpr(std::is_same_v || std::is_same_v) { return "char"; } @@ -255,98 +252,94 @@ inline std::string ConvertDataTypeToVtkDataType() noexcept { return "double"; } - else if constexpr(std::is_same_v) - { - return "char"; - } else { static_assert(dependent_false, "ConvertDataTypeToVtkDataType: Unsupported type"); } } -template -Result<> writeVtkData(std::ofstream& outStrm, DataStructure& dataStructure, const DataPath& dataPath, bool binary, const nx::core::IFilter::MessageHandler& messageHandler, - const std::atomic_bool& shouldCancel) +struct WriteVtkDataFunctor { - using DataArrayType = DataArray; - using DataStoreType = typename DataArrayType::store_type; - - auto& dataArrayRef = dataStructure.getDataRefAs(dataPath); - - auto& dataStoreRef = dataArrayRef.getIDataStoreRef(); - - std::string name = StringUtilities::replace(dataArrayRef.getName(), " ", "_"); - - outStrm << "SCALARS " << name << " " << ConvertDataTypeToVtkDataType() << " " << dataArrayRef.getNumberOfComponents() << "\n"; - outStrm << "LOOKUP_TABLE default\n"; - - if(binary) + template + Result<> operator()(std::ofstream& outStrm, IDataArray& iDataArray, bool binary, const nx::core::IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) { - // Swap to big Endian... because - if constexpr(endian::little == endian::native) - { - dataArrayRef.byteSwapElements(); - } + using DataArrayType = DataArray; + using DataStoreType = typename DataArrayType::store_type; - auto result = dataStoreRef.writeBinaryFile(outStrm); - if(result.first != 0) - { - } + auto& dataArrayRef = dynamic_cast(iDataArray); + const auto& dataStoreRef = dataArrayRef.getDataStoreRef(); - // Swap back to little endian - if constexpr(endian::little == endian::native) - { - dataArrayRef.byteSwapElements(); - } - } - else - { - const size_t k_DefaultElementsPerLine = 10; - auto start = std::chrono::steady_clock::now(); - auto numTuples = dataStoreRef.getSize(); - size_t currentItemCount = 0; + std::string name = StringUtilities::replace(dataArrayRef.getName(), " ", "_"); + + outStrm << "SCALARS " << name << " " << ConvertDataTypeToVtkDataType() << " " << dataArrayRef.getNumberOfComponents() << "\n"; + outStrm << "LOOKUP_TABLE default\n"; - for(size_t idx = 0; idx < numTuples; idx++) + if(binary) { - auto now = std::chrono::steady_clock::now(); - if(std::chrono::duration_cast(now - start).count() > 1000) + // Swap to big Endian... because + if constexpr(endian::little == endian::native) { - auto string = fmt::format("Processing {}: {}% completed", dataArrayRef.getName(), static_cast(100 * static_cast(idx) / static_cast(numTuples))); - messageHandler(IFilter::Message::Type::Info, string); - start = now; - if(shouldCancel) - { - return {}; - } + dataArrayRef.byteSwapElements(); } - if constexpr(std::is_same_v || std::is_same_v) + auto result = dataStoreRef.writeBinaryFile(outStrm); + if(result.first != 0) { - outStrm << static_cast(dataArrayRef[idx]); } - else if constexpr(std::is_same_v || std::is_same_v) - { - outStrm << fmt::format("{}", dataArrayRef[idx]); - } - else - { - outStrm << dataArrayRef[idx]; - } - if(currentItemCount < k_DefaultElementsPerLine - 1) + + // Swap back to little endian + if constexpr(endian::little == endian::native) { - outStrm << ' '; - currentItemCount++; + dataArrayRef.byteSwapElements(); } - else + } + else + { + const size_t k_DefaultElementsPerLine = 10; + auto start = std::chrono::steady_clock::now(); + auto numTuples = dataStoreRef.getSize(); + size_t currentItemCount = 0; + + for(size_t idx = 0; idx < numTuples; idx++) { - outStrm << "\n"; - currentItemCount = 0; + auto now = std::chrono::steady_clock::now(); + if(std::chrono::duration_cast(now - start).count() > 1000) + { + auto string = fmt::format("Processing {}: {}% completed", dataArrayRef.getName(), static_cast(100 * static_cast(idx) / static_cast(numTuples))); + messageHandler(IFilter::Message::Type::Info, string); + start = now; + if(shouldCancel) + { + return {}; + } + } + + if constexpr(std::is_same_v || std::is_same_v) + { + outStrm << static_cast(dataArrayRef[idx]); + } + else if constexpr(std::is_same_v || std::is_same_v) + { + outStrm << fmt::format("{}", dataArrayRef[idx]); + } + else + { + outStrm << dataArrayRef[idx]; + } + if(currentItemCount < k_DefaultElementsPerLine - 1) + { + outStrm << ' '; + currentItemCount++; + } + else + { + outStrm << "\n"; + currentItemCount = 0; + } } } + outStrm << "\n"; // Always end with a new line for binary data + return {}; } - outStrm << "\n"; // Always end with a new line for binary data - return {}; -} - +}; } // namespace nx::core diff --git a/src/simplnx/Utilities/DataGroupUtilities.cpp b/src/simplnx/Utilities/DataGroupUtilities.cpp index 7c800200dd..a4051f2f25 100644 --- a/src/simplnx/Utilities/DataGroupUtilities.cpp +++ b/src/simplnx/Utilities/DataGroupUtilities.cpp @@ -5,11 +5,9 @@ namespace nx::core { -bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& featureDataGroupPath, const std::vector& activeObjects, Int32Array& cellFeatureIds, size_t currentFeatureCount, - const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) +bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& featureDataGroupPath, const std::vector& activeObjects, Int32AbstractDataStore& cellFeatureIds, + size_t currentFeatureCount, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) { - bool acceptableMatrix = true; - // Get the DataGroup that holds all the feature Data const auto* featureLevelBaseGroup = dataStructure.getDataAs(featureDataGroupPath); @@ -36,7 +34,7 @@ bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& feature } } size_t totalTuples = currentFeatureCount; - if(activeObjects.size() == totalTuples && acceptableMatrix) + if(activeObjects.size() == totalTuples) { size_t goodCount = 1; std::vector newNames(totalTuples, 0); @@ -83,13 +81,12 @@ bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& feature // Loop over all the points and correct all the feature names size_t totalPoints = cellFeatureIds.getNumberOfTuples(); - auto& featureIds = cellFeatureIds.getDataStoreRef(); bool featureIdsChanged = false; for(size_t i = 0; i < totalPoints; i++) { - if(featureIds[i] >= 0 && featureIds[i] < newNames.size()) + if(cellFeatureIds[i] >= 0 && cellFeatureIds[i] < newNames.size()) { - featureIds[i] = static_cast(newNames[featureIds[i]]); + cellFeatureIds[i] = static_cast(newNames[cellFeatureIds[i]]); featureIdsChanged = true; } if(shouldCancel) diff --git a/src/simplnx/Utilities/DataGroupUtilities.hpp b/src/simplnx/Utilities/DataGroupUtilities.hpp index 63364ac0a0..ee34db2ea3 100644 --- a/src/simplnx/Utilities/DataGroupUtilities.hpp +++ b/src/simplnx/Utilities/DataGroupUtilities.hpp @@ -12,7 +12,6 @@ namespace nx::core { - /** * @brief RemoveInactiveObjects This assumes a single Dimension TupleShape, i.e., a Linear array, (1D) * @@ -26,7 +25,7 @@ namespace nx::core * @param shouldCancel * @return */ -SIMPLNX_EXPORT bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& featureDataGroupPath, const std::vector& activeObjects, Int32Array& cellFeatureIds, +SIMPLNX_EXPORT bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& featureDataGroupPath, const std::vector& activeObjects, Int32AbstractDataStore& cellFeatureIds, size_t currentFeatureCount, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel); /** diff --git a/src/simplnx/Utilities/SampleSurfaceMesh.cpp b/src/simplnx/Utilities/SampleSurfaceMesh.cpp index 7672edb20b..7ae231e498 100644 --- a/src/simplnx/Utilities/SampleSurfaceMesh.cpp +++ b/src/simplnx/Utilities/SampleSurfaceMesh.cpp @@ -18,7 +18,7 @@ class SampleSurfaceMeshImpl { public: SampleSurfaceMeshImpl(SampleSurfaceMesh* filter, const TriangleGeom& faces, const std::vector>& faceIds, const std::vector& faceBBs, - const std::vector& points, Int32Array& polyIds, const std::atomic_bool& shouldCancel) + const std::vector& points, Int32AbstractDataStore& polyIds, const std::atomic_bool& shouldCancel) : m_Filter(filter) , m_Faces(faces) , m_FaceIds(faceIds) @@ -79,7 +79,7 @@ class SampleSurfaceMeshImpl const std::vector>& m_FaceIds; const std::vector& m_FaceBBs; const std::vector& m_Points; - Int32Array& m_PolyIds; + Int32AbstractDataStore& m_PolyIds; const std::atomic_bool& m_ShouldCancel; }; @@ -88,7 +88,7 @@ class SampleSurfaceMeshImplByPoints { public: SampleSurfaceMeshImplByPoints(SampleSurfaceMesh* filter, const TriangleGeom& faces, const std::vector& faceIds, const std::vector& faceBBs, - const std::vector& points, const usize featureId, Int32Array& polyIds, const std::atomic_bool& shouldCancel) + const std::vector& points, const usize featureId, Int32AbstractDataStore& polyIds, const std::atomic_bool& shouldCancel) : m_Filter(filter) , m_Faces(faces) , m_FaceIds(faceIds) @@ -148,7 +148,7 @@ class SampleSurfaceMeshImplByPoints const std::vector& m_FaceIds; const std::vector& m_FaceBBs; const std::vector& m_Points; - Int32Array& m_PolyIds; + Int32AbstractDataStore& m_PolyIds; const usize m_FeatureId = 0; const std::atomic_bool& m_ShouldCancel; }; @@ -175,7 +175,7 @@ void SampleSurfaceMesh::updateProgress(const std::string& progMessage) Result<> SampleSurfaceMesh::execute(SampleSurfaceMeshInputValues& inputValues) { auto& triangleGeom = m_DataStructure.getDataRefAs(inputValues.TriangleGeometryPath); - auto& faceLabelsSM = m_DataStructure.getDataRefAs(inputValues.SurfaceMeshFaceLabelsArrayPath); + auto& faceLabelsSM = m_DataStructure.getDataAs(inputValues.SurfaceMeshFaceLabelsArrayPath)->getDataStoreRef(); // pull down faces usize numFaces = faceLabelsSM.getNumberOfTuples(); @@ -277,7 +277,7 @@ Result<> SampleSurfaceMesh::execute(SampleSurfaceMeshInputValues& inputValues) generatePoints(points); // create array to hold which polyhedron (feature) each point falls in - auto& polyIds = m_DataStructure.getDataRefAs(inputValues.FeatureIdsArrayPath); + auto& polyIds = m_DataStructure.getDataAs(inputValues.FeatureIdsArrayPath)->getDataStoreRef(); updateProgress("Sampling triangle geometry ..."); diff --git a/src/simplnx/Utilities/SamplingUtils.hpp b/src/simplnx/Utilities/SamplingUtils.hpp index 493eb99e15..3b9d4d37d3 100644 --- a/src/simplnx/Utilities/SamplingUtils.hpp +++ b/src/simplnx/Utilities/SamplingUtils.hpp @@ -7,9 +7,7 @@ #include "simplnx/Filter/IFilter.hpp" #include "simplnx/Utilities/DataGroupUtilities.hpp" -namespace nx::core -{ -namespace Sampling +namespace nx::core::Sampling { inline Result<> RenumberFeatures(DataStructure& dataStructure, const DataPath& newGeomPath, const DataPath& destCellFeatAttributeMatrixPath, const DataPath& featureIdsArrayPath, const DataPath& destFeatureIdsArrayPath, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel = false) @@ -28,9 +26,7 @@ inline Result<> RenumberFeatures(DataStructure& dataStructure, const DataPath& n return MakeErrorResult(-600, "The number of Features is 0 and should be greater than 0"); } - auto& destFeatureIdsRef = dataStructure.getDataRefAs(destFeatureIdsArrayPath); - - auto& featureIds = destFeatureIdsRef.getDataStoreRef(); + auto& destFeatureIds = dataStructure.getDataAs(destFeatureIdsArrayPath)->getDataStoreRef(); // Find the unique set of feature ids for(usize i = 0; i < totalPoints; ++i) { @@ -39,7 +35,7 @@ inline Result<> RenumberFeatures(DataStructure& dataStructure, const DataPath& n break; } - int32 currentFeatureId = featureIds[i]; + int32 currentFeatureId = destFeatureIds[i]; if(currentFeatureId < 0) { std::string ss = fmt::format("FeatureIds values MUST be >= ZERO. Negative FeatureId found at index {} into the resampled feature ids array", i); @@ -58,12 +54,11 @@ inline Result<> RenumberFeatures(DataStructure& dataStructure, const DataPath& n } } - if(!RemoveInactiveObjects(dataStructure, destCellFeatAttributeMatrixPath, activeObjects, destFeatureIdsRef, totalFeatures, messageHandler, shouldCancel)) + if(!RemoveInactiveObjects(dataStructure, destCellFeatAttributeMatrixPath, activeObjects, destFeatureIds, totalFeatures, messageHandler, shouldCancel)) { std::string ss = fmt::format("An error occurred while trying to remove the inactive objects from Attribute Matrix '{}'", destCellFeatAttributeMatrixPath.toString()); return MakeErrorResult(-606, ss); } return {}; } -} // namespace Sampling -} // namespace nx::core +} // namespace nx::core::Sampling