From 36036f51d59d28839d034da3ddecb95e1f3d56a6 Mon Sep 17 00:00:00 2001 From: nyoungbq Date: Fri, 26 Jul 2024 17:15:01 -0400 Subject: [PATCH] more data store updates --- .../Filters/Algorithms/CreateAMScanPaths.cpp | 126 +++++++++--------- .../Filters/Algorithms/CreateAMScanPaths.hpp | 4 - .../Filters/Algorithms/CreateColorMap.cpp | 47 ++++--- .../Filters/Algorithms/ErodeDilateBadData.cpp | 9 +- .../ErodeDilateCoordinationNumber.cpp | 8 +- 5 files changed, 96 insertions(+), 98 deletions(-) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.cpp index c789392b18..ee4795e840 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.cpp @@ -13,7 +13,7 @@ namespace { std::array ax2om(const std::array& a) { - std::array res; + std::array res = {}; float32 q = 0.0L; float32 c = 0.0L; float32 s = 0.0L; @@ -71,6 +71,59 @@ ImageRotationUtilities::Matrix3fR toGMatrix(std::array om) g(2, 2) = om[8]; return g; } + +// ----------------------------------------------------------------------------- +char determineIntersectCoord(const std::array& p1, const std::array& q1, const std::array& p2, const std::array& q2, float32& coordX) +{ + // assumes p1q1 is the hatch vector and p2q2 is the CAD edge + // also assumes the p1q1 is in x direction only so can just check y coords for potential intersection + float32 x1 = p1[0]; + float32 x2 = q1[0]; + float32 x3 = p2[0]; + float32 x4 = q2[0]; + float32 y1 = p1[1]; + // float32 y2 = q1[1]; + float32 y3 = p2[1]; + float32 y4 = q2[1]; + + if(y3 > y1 && y4 > y1) + { + return 'n'; + } + if(y3 < y1 && y4 < y1) + { + return 'n'; + } + if(y3 == y1 && y4 == y1) + { + return 'n'; + } + if(y3 == y1) + { + coordX = x3; + if(x3 >= x1 && x3 <= x2) + { + return 'c'; + } + return 'n'; + } + if(y4 == y1) + { + coordX = x4; + if(x4 >= x1 && x4 <= x2) + { + return 'd'; + } + return 'n'; + } + float32 frac = (y1 - y3) / (y4 - y3); + coordX = x3 + (frac * (x4 - x3)); + if(coordX >= x1 && coordX <= x2) + { + return 'i'; + } + return 'n'; +} } // namespace // ----------------------------------------------------------------------------- @@ -98,8 +151,8 @@ Result<> CreateAMScanPaths::operator()() auto& CADLayers = m_DataStructure.getDataRefAs(m_InputValues->CADSliceDataContainerName); INodeGeometry1D::SharedEdgeList& CADLayerEdges = CADLayers.getEdgesRef(); INodeGeometry0D::SharedVertexList& CADLayerVerts = CADLayers.getVerticesRef(); - auto& cadSliceIds = m_DataStructure.getDataRefAs(m_InputValues->CADSliceIdsArrayPath); - auto& cadRegionIds = m_DataStructure.getDataRefAs(m_InputValues->CADRegionIdsArrayPath); + auto& cadSliceIds = m_DataStructure.getDataAs(m_InputValues->CADSliceIdsArrayPath)->getDataStoreRef(); + auto& cadRegionIds = m_DataStructure.getDataAs(m_InputValues->CADRegionIdsArrayPath)->getDataStoreRef(); usize numCADLayerEdges = CADLayers.getNumberOfEdges(); usize numCADLayerVerts = CADLayers.getNumberOfVertices(); int32 numCADLayers = 0; @@ -519,19 +572,19 @@ Result<> CreateAMScanPaths::operator()() usize numHatchVerts = 2 * hatchCount; fitHatches.resizeVertexList(numHatchVerts); fitHatches.resizeEdgeList(hatchCount); - INodeGeometry0D::SharedVertexList& hatchVerts = fitHatches.getVerticesRef(); - INodeGeometry1D::SharedEdgeList& hatches = fitHatches.getEdgesRef(); + AbstractDataStore& hatchVerts = fitHatches.getVertices()->getDataStoreRef(); + AbstractDataStore& hatches = fitHatches.getEdges()->getDataStoreRef(); std::vector tDims(1, numHatchVerts); fitHatches.getVertexAttributeMatrix()->resizeTuples(tDims); tDims[0] = hatchCount; fitHatches.getEdgeAttributeMatrix()->resizeTuples(tDims); - auto& times = - m_DataStructure.getDataRefAs(m_InputValues->HatchDataContainerName.createChildPath(m_InputValues->VertexAttributeMatrixName).createChildPath(m_InputValues->TimeArrayName)); + auto& times = m_DataStructure.getDataAs(m_InputValues->HatchDataContainerName.createChildPath(m_InputValues->VertexAttributeMatrixName).createChildPath(m_InputValues->TimeArrayName)) + ->getDataStoreRef(); const DataPath hatchAttributeMatrixPath = m_InputValues->HatchDataContainerName.createChildPath(m_InputValues->HatchAttributeMatrixName); - auto& powers = m_DataStructure.getDataRefAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->PowersArrayName)); - auto& hatchSliceIds = m_DataStructure.getDataRefAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->CADSliceIdsArrayPath.getTargetName())); - auto& hatchRegionIds = m_DataStructure.getDataRefAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->RegionIdsArrayName)); + auto& powers = m_DataStructure.getDataAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->PowersArrayName))->getDataStoreRef(); + auto& hatchSliceIds = m_DataStructure.getDataAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->CADSliceIdsArrayPath.getTargetName()))->getDataStoreRef(); + auto& hatchRegionIds = m_DataStructure.getDataAs(hatchAttributeMatrixPath.createChildPath(m_InputValues->RegionIdsArrayName))->getDataStoreRef(); if(getCancel()) { @@ -608,56 +661,3 @@ Result<> CreateAMScanPaths::operator()() return {}; } - -// ----------------------------------------------------------------------------- -char CreateAMScanPaths::determineIntersectCoord(const std::array& p1, const std::array& q1, const std::array& p2, const std::array& q2, float32& coordX) -{ - // assumes p1q1 is the hatch vector and p2q2 is the CAD edge - // also assumes the p1q1 is in x direction only so can just check y coords for potential intersection - float32 x1 = p1[0]; - float32 x2 = q1[0]; - float32 x3 = p2[0]; - float32 x4 = q2[0]; - float32 y1 = p1[1]; - // float32 y2 = q1[1]; - float32 y3 = p2[1]; - float32 y4 = q2[1]; - - if(y3 > y1 && y4 > y1) - { - return 'n'; - } - if(y3 < y1 && y4 < y1) - { - return 'n'; - } - if(y3 == y1 && y4 == y1) - { - return 'n'; - } - if(y3 == y1) - { - coordX = x3; - if(x3 >= x1 && x3 <= x2) - { - return 'c'; - } - return 'n'; - } - if(y4 == y1) - { - coordX = x4; - if(x4 >= x1 && x4 <= x2) - { - return 'd'; - } - return 'n'; - } - float32 frac = (y1 - y3) / (y4 - y3); - coordX = x3 + (frac * (x4 - x3)); - if(coordX >= x1 && coordX <= x2) - { - return 'i'; - } - return 'n'; -} diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.hpp index a4eef171ec..d2e9100b5d 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateAMScanPaths.hpp @@ -12,7 +12,6 @@ namespace nx::core { - struct SIMPLNXCORE_EXPORT CreateAMScanPathsInputValues { float32 StripeWidth; @@ -50,9 +49,6 @@ class SIMPLNXCORE_EXPORT CreateAMScanPaths const std::atomic_bool& getCancel(); -protected: - char determineIntersectCoord(const std::array& p1, const std::array& q1, const std::array& p2, const std::array& q2, float32& coordX); - private: DataStructure& m_DataStructure; const CreateAMScanPathsInputValues* m_InputValues = nullptr; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateColorMap.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateColorMap.cpp index 6b3019886b..d8fee0b92b 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateColorMap.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CreateColorMap.cpp @@ -40,33 +40,33 @@ template class CreateColorMapImpl { public: - CreateColorMapImpl(const DataArray& arrayPtr, const std::vector& binPoints, const std::vector& controlPoints, int numControlColors, UInt8Array& colorArray, + CreateColorMapImpl(const AbstractDataStore& arrayStore, const std::vector& binPoints, const std::vector& controlPoints, int numControlColors, UInt8AbstractDataStore& colorStore, const nx::core::IDataArray* goodVoxels, const std::vector& invalidColor) - : m_ArrayPtr(arrayPtr) + : m_ArrayStore(arrayStore) , m_BinPoints(binPoints) , m_NumControlColors(numControlColors) , m_ControlPoints(controlPoints) - , m_ColorArray(colorArray) - , m_ArrayMin(arrayPtr[0]) - , m_ArrayMax(arrayPtr[0]) + , m_ColorStore(colorStore) + , m_ArrayMin(arrayStore[0]) + , m_ArrayMax(arrayStore[0]) , m_GoodVoxels(goodVoxels) , m_InvalidColor(invalidColor) { - for(int i = 1; i < arrayPtr.getNumberOfTuples(); i++) + for(usize i = 1; i < arrayStore.getNumberOfTuples(); i++) { - if(arrayPtr[i] < m_ArrayMin) + if(arrayStore[i] < m_ArrayMin) { - m_ArrayMin = arrayPtr[i]; + m_ArrayMin = arrayStore[i]; } - if(arrayPtr[i] > m_ArrayMax) + if(arrayStore[i] > m_ArrayMax) { - m_ArrayMax = arrayPtr[i]; + m_ArrayMax = arrayStore[i]; } } } template - void convert(size_t start, size_t end) const + void convert(usize start, usize end) const { using MaskArrayType = DataArray; const MaskArrayType* maskArray = nullptr; @@ -74,7 +74,6 @@ class CreateColorMapImpl { maskArray = dynamic_cast(m_GoodVoxels); } - auto& colorArrayDS = m_ColorArray.getDataStoreRef(); for(size_t i = start; i < end; i++) { @@ -83,15 +82,15 @@ class CreateColorMapImpl { if(!(*maskArray)[i]) { - colorArrayDS.setComponent(i, 0, m_InvalidColor[0]); - colorArrayDS.setComponent(i, 1, m_InvalidColor[1]); - colorArrayDS.setComponent(i, 2, m_InvalidColor[2]); + m_ColorStore.setComponent(i, 0, m_InvalidColor[0]); + m_ColorStore.setComponent(i, 1, m_InvalidColor[1]); + m_ColorStore.setComponent(i, 2, m_InvalidColor[2]); continue; } } // Normalize value - const float32 nValue = (static_cast(m_ArrayPtr[i] - m_ArrayMin)) / static_cast((m_ArrayMax - m_ArrayMin)); + const float32 nValue = (static_cast(m_ArrayStore[i] - m_ArrayMin)) / static_cast((m_ArrayMax - m_ArrayMin)); int rightBinIndex = findRightBinIndex(nValue, m_BinPoints); @@ -128,9 +127,9 @@ class CreateColorMapImpl const unsigned char blueVal = (m_ControlPoints[leftBinIndex * k_ControlPointCompSize + 3] * (1.0 - currFraction) + m_ControlPoints[rightBinIndex * k_ControlPointCompSize + 3] * currFraction) * 255; - colorArrayDS.setComponent(i, 0, redVal); - colorArrayDS.setComponent(i, 1, greenVal); - colorArrayDS.setComponent(i, 2, blueVal); + m_ColorStore.setComponent(i, 0, redVal); + m_ColorStore.setComponent(i, 1, greenVal); + m_ColorStore.setComponent(i, 2, blueVal); } } @@ -154,13 +153,13 @@ class CreateColorMapImpl } private: - const DataArray& m_ArrayPtr; + const AbstractDataStore& m_ArrayStore; const std::vector& m_BinPoints; T m_ArrayMin; T m_ArrayMax; int m_NumControlColors; const std::vector& m_ControlPoints; - UInt8Array& m_ColorArray; + UInt8AbstractDataStore& m_ColorStore; const nx::core::IDataArray* m_GoodVoxels = nullptr; const std::vector& m_InvalidColor; }; @@ -189,7 +188,7 @@ struct GenerateColorArrayFunctor binPoint = (binPoint - binMin) / (binMax - binMin); } - auto& colorArray = dataStructure.getDataRefAs(inputValues->RgbArrayPath); + auto& colorArray = dataStructure.getDataAs(inputValues->RgbArrayPath)->getDataStoreRef(); nx::core::IDataArray* goodVoxelsArray = nullptr; if(inputValues->UseMask) @@ -197,10 +196,10 @@ struct GenerateColorArrayFunctor goodVoxelsArray = dataStructure.getDataAs(inputValues->MaskArrayPath); } - const DataArray& arrayRef = dataStructure.getDataRefAs>(inputValues->SelectedDataArrayPath); + const AbstractDataStore& arrayRef = dataStructure.getDataAs>(inputValues->SelectedDataArrayPath)->getDataStoreRef(); if(arrayRef.getNumberOfTuples() <= 0) { - return MakeErrorResult(-34381, fmt::format("Array {} is empty", arrayRef.getName())); + return MakeErrorResult(-34381, fmt::format("Array {} is empty", inputValues->SelectedDataArrayPath.getTargetName())); } ParallelDataAlgorithm dataAlg; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateBadData.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateBadData.cpp index c024810f1e..887ed2394f 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateBadData.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateBadData.cpp @@ -15,8 +15,8 @@ class ErodeDilateBadDataTransferDataImpl ErodeDilateBadDataTransferDataImpl() = delete; ErodeDilateBadDataTransferDataImpl(const ErodeDilateBadDataTransferDataImpl&) = default; - ErodeDilateBadDataTransferDataImpl(ErodeDilateBadData* filterAlg, usize totalPoints, ChoicesParameter::ValueType operation, const Int32Array& featureIds, const std::vector& neighbors, - const std::shared_ptr& dataArrayPtr) + ErodeDilateBadDataTransferDataImpl(ErodeDilateBadData* filterAlg, usize totalPoints, ChoicesParameter::ValueType operation, const Int32AbstractDataStore& featureIds, + const std::vector& neighbors, const std::shared_ptr& dataArrayPtr) : m_FilterAlg(filterAlg) , m_TotalPoints(totalPoints) , m_Operation(operation) @@ -63,7 +63,7 @@ class ErodeDilateBadDataTransferDataImpl ChoicesParameter::ValueType m_Operation = 0; std::vector m_Neighbors; const std::shared_ptr m_DataArrayPtr; - const Int32Array& m_FeatureIds; + const Int32AbstractDataStore& m_FeatureIds; }; } // namespace @@ -94,7 +94,7 @@ void ErodeDilateBadData::updateProgress(const std::string& progMessage) // ----------------------------------------------------------------------------- Result<> ErodeDilateBadData::operator()() { - const auto& featureIds = m_DataStructure.getDataRefAs(m_InputValues->FeatureIdsArrayPath); + const auto& featureIds = m_DataStructure.getDataAs(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef(); const usize totalPoints = featureIds.getNumberOfTuples(); std::vector neighbors(totalPoints, -1); @@ -234,6 +234,7 @@ Result<> ErodeDilateBadData::operator()() { continue; } + taskRunner.execute(ErodeDilateBadDataTransferDataImpl(this, totalPoints, m_InputValues->Operation, featureIds, neighbors, voxelArray)); } taskRunner.wait(); // This will spill over if the number of DataArrays to process does not divide evenly by the number of threads. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateCoordinationNumber.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateCoordinationNumber.cpp index 44702d5514..c11d7f94d8 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateCoordinationNumber.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ErodeDilateCoordinationNumber.cpp @@ -6,7 +6,8 @@ #include "simplnx/Utilities/FilterUtilities.hpp" using namespace nx::core; - +namespace +{ struct DataArrayCopyTupleFunctor { template @@ -17,6 +18,7 @@ struct DataArrayCopyTupleFunctor outputArray.copyTuple(sourceIndex, targetIndex); } }; +} // namespace // ----------------------------------------------------------------------------- ErodeDilateCoordinationNumber::ErodeDilateCoordinationNumber(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, @@ -191,10 +193,10 @@ Result<> ErodeDilateCoordinationNumber::operator()() } for(int64 zIndex = 0; zIndex < dims[2]; zIndex++) { - const int64 zStride = static_cast(dims[0] * dims[1] * zIndex); + const auto zStride = static_cast(dims[0] * dims[1] * zIndex); for(int64 yIndex = 0; yIndex < dims[1]; yIndex++) { - const int64 yStride = static_cast(dims[0] * yIndex); + const auto yStride = static_cast(dims[0] * yIndex); for(int64 xIndex = 0; xIndex < dims[0]; xIndex++) { const int64 voxelIndex = zStride + yStride + xIndex;