Skip to content

Commit

Permalink
[1 broken test] All algorithms complete, rework of IDataArray to type…
Browse files Browse the repository at this point in the history
…d store that avoids extra dynamic cast
  • Loading branch information
nyoungbq committed Aug 15, 2024
1 parent a8d81f9 commit 45398c1
Show file tree
Hide file tree
Showing 48 changed files with 507 additions and 856 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace nx::core;

namespace
{
template <typename DataArrayType>
template <typename Type>
class GenerateHistogramFromData
{
public:
Expand All @@ -33,8 +33,8 @@ class GenerateHistogramFromData

void operator()() const
{
const auto& inputArray = dynamic_cast<const DataArray<DataArrayType>&>(m_InputArray).getDataStoreRef();
auto end = inputArray.getSize();
const auto& inputStore = m_InputArray.getIDataStoreRefAs<AbstractDataStore<Type>>();
auto end = inputStore.getSize();

// tuple visualization: Histogram = {(bin maximum, count), (bin maximum, count), ... }
float64 min = 0.0;
Expand All @@ -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<float64>(*minMax.first) - 1); // ensure upper limit encapsulates max value
max = (static_cast<float64>(*minMax.second) + 1); // ensure lower limit encapsulates min value
}
Expand All @@ -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]++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ComputeKMeansTemplate
ComputeKMeansTemplate(ComputeKMeans* filter, const IDataArray* inputIDataArray, IDataArray* meansIDataArray, const std::unique_ptr<MaskCompare>& maskDataArray, usize numClusters,
Int32AbstractDataStore& fIds, ClusterUtilities::DistanceMetric distMetric, std::mt19937_64::result_type seed)
: m_Filter(filter)
, m_InputArray(dynamic_cast<const DataArrayT*>(inputIDataArray)->getDataStoreRef())
, m_Means(dynamic_cast<DataArrayT*>(meansIDataArray)->getDataStoreRef())
, m_InputArray(inputIDataArray->getIDataStoreRefAs<AbstractDataStoreT>())
, m_Means(meansIDataArray->getIDataStoreRefAs<AbstractDataStoreT>())
, m_Mask(maskDataArray)
, m_NumClusters(numClusters)
, m_FeatureIds(fIds)
Expand Down Expand Up @@ -100,7 +100,6 @@ class ComputeKMeansTemplate
}

private:
using DataArrayT = DataArray<T>;
using AbstractDataStoreT = AbstractDataStore<T>;
ComputeKMeans* m_Filter;
const AbstractDataStoreT& m_InputArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class KMedoidsTemplate
KMedoidsTemplate(ComputeKMedoids* filter, const IDataArray* inputIDataArray, IDataArray* medoidsIDataArray, const std::unique_ptr<MaskCompare>& maskDataArray, usize numClusters,
Int32AbstractDataStore& fIds, ClusterUtilities::DistanceMetric distMetric, std::mt19937_64::result_type seed)
: m_Filter(filter)
, m_InputArray(dynamic_cast<const DataArrayT*>(inputIDataArray)->getDataStoreRef())
, m_Medoids(dynamic_cast<DataArrayT*>(medoidsIDataArray)->getDataStoreRef())
, m_InputArray(inputIDataArray->getIDataStoreRefAs<AbstractDataStore<T>>())
, m_Medoids(medoidsIDataArray->getIDataStoreRefAs<AbstractDataStore<T>>())
, m_Mask(maskDataArray)
, m_NumClusters(numClusters)
, m_FeatureIds(fIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,22 @@ struct DBSCANFunctor
{
if(useRandom)
{
DBSCANTemplate<T, true, true>(filter, dynamic_cast<const DataArray<T>&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
DBSCANTemplate<T, true, true>(filter, inputIDataArray.getIDataStoreRefAs<AbstractDataStore<T>>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
}
else
{
DBSCANTemplate<T, true, false>(filter, dynamic_cast<const DataArray<T>&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
DBSCANTemplate<T, true, false>(filter, inputIDataArray.getIDataStoreRefAs<AbstractDataStore<T>>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
}
}
else
{
if(useRandom)
{
DBSCANTemplate<T, false, true>(filter, dynamic_cast<const DataArray<T>&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
DBSCANTemplate<T, false, true>(filter, inputIDataArray.getIDataStoreRefAs<AbstractDataStore<T>>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
}
else
{
DBSCANTemplate<T, false, false>(filter, dynamic_cast<const DataArray<T>&>(inputIDataArray).getDataStoreRef(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
DBSCANTemplate<T, false, false>(filter, inputIDataArray.getIDataStoreRefAs<AbstractDataStore<T>>(), maskCompare, fIds.getDataStoreRef(), epsilon, minPoints, distMetric, seed)();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct RemoveComponentsFunctor
template <class ScalarType>
void operator()(IDataArray* originalArray, IDataArray* resizedArray, usize componentIndexToRemove) // Due to logic structure originalArray cannot be const
{
const auto& originalStoreRef = dynamic_cast<const DataArray<ScalarType>*>(originalArray)->getDataStoreRef();
auto& resizedStoreRef = dynamic_cast<DataArray<ScalarType>*>(resizedArray)->getDataStoreRef();
const auto& originalStoreRef = originalArray->getIDataStoreRefAs<AbstractDataStore<ScalarType>>();
auto& resizedStoreRef = resizedArray->getIDataStoreRefAs<AbstractDataStore<ScalarType>>();

const usize originalTupleCount = originalStoreRef.getNumberOfTuples();
const usize originalCompCount = originalStoreRef.getNumberOfComponents();
Expand Down Expand Up @@ -42,8 +42,8 @@ struct ExtractComponentsFunctor
template <class ScalarType>
void operator()(IDataArray* inputArray, IDataArray* extractedCompArray, usize componentIndexToExtract) // Due to logic structure inputArray cannot be const
{
const auto& inputStoreRef = dynamic_cast<const DataArray<ScalarType>*>(inputArray)->getDataStoreRef();
auto& extractedStoreRef = dynamic_cast<DataArray<ScalarType>*>(extractedCompArray)->getDataStoreRef();
const auto& inputStoreRef = inputArray->getIDataStoreRefAs<AbstractDataStore<ScalarType>>();
auto& extractedStoreRef = extractedCompArray->getIDataStoreRefAs<AbstractDataStore<ScalarType>>();

const usize inputTupleCount = inputStoreRef.getNumberOfTuples();
const usize inputCompCount = inputStoreRef.getNumberOfComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ struct CopyDataFunctor
template <typename T>
void operator()(const IDataArray* srcIArray, IDataArray* destIArray, const std::vector<bool>& maskArray)
{
using DataArrayType = DataArray<T>;

const auto& srcArray = dynamic_cast<const DataArrayType*>(srcIArray)->getDataStoreRef();
auto& destArray = dynamic_cast<DataArrayType*>(destIArray)->getDataStoreRef();
const auto& srcArray = srcIArray->getIDataStoreRefAs<AbstractDataStore<T>>();
auto& destArray = destIArray->getIDataStoreRefAs<AbstractDataStore<T>>();

bool useMask = !maskArray.empty();
usize destTupleIdx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct FillBadDataUpdateTuplesFunctor
template <typename T>
void operator()(const Int32AbstractDataStore& featureIds, IDataArray* outputIDataArray, const std::vector<int32>& neighbors)
{
auto& outputStore = dynamic_cast<DataArray<T>*>(outputIDataArray)->getDataStoreRef();
auto& outputStore = outputIDataArray->getIDataStoreRefAs<AbstractDataStore<T>>();
FillBadDataUpdateTuples(featureIds, outputStore, neighbors);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ExecuteFlyingEdgesFunctor
template <typename T>
void operator()(const ImageGeom& image, const IDataArray* iDataArray, float64 isoVal, TriangleGeom& triangleGeom, Float32AbstractDataStore& normals, AttributeMatrix& normAM)
{
FlyingEdgesAlgorithm flyingEdges = FlyingEdgesAlgorithm<T>(image, dynamic_cast<const DataArray<T>*>(iDataArray)->getDataStoreRef(), static_cast<T>(isoVal), triangleGeom, normals);
FlyingEdgesAlgorithm flyingEdges = FlyingEdgesAlgorithm<T>(image, iDataArray->getIDataStoreRefAs<AbstractDataStore<T>>(), static_cast<T>(isoVal), triangleGeom, normals);
flyingEdges.pass1();
flyingEdges.pass2();
flyingEdges.pass3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& m_Nod
triangleGeom->getFaceAttributeMatrix()->resizeTuples({triangleCount});
triangleGeom->getVertexAttributeMatrix()->resizeTuples(tDims);

auto& faceLabelsArray = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->FaceLabelsDataPath);
auto& faceLabelsStore = faceLabelsArray.getDataStoreRef();
auto& faceLabelsStore = m_DataStructure.getDataAs<Int32Array>(m_InputValues->FaceLabelsDataPath)->getDataStoreRef();

// Resize the NodeTypes array
auto& nodeTypes = m_DataStructure.getDataAs<Int8Array>(m_InputValues->NodeTypesDataPath)->getDataStoreRef();
Expand Down Expand Up @@ -1012,7 +1011,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1025,7 +1024,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1061,7 +1060,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1074,7 +1073,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1110,7 +1109,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1123,7 +1122,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1159,7 +1158,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1172,7 +1171,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1216,7 +1215,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1236,7 +1235,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1272,7 +1271,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1285,7 +1284,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1328,7 +1327,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1348,7 +1347,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1384,7 +1383,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1397,7 +1396,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down Expand Up @@ -1440,7 +1439,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand All @@ -1460,7 +1459,7 @@ void QuickSurfaceMesh::createNodesAndTriangles(std::vector<MeshIndexType>& 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++;
Expand Down
Loading

0 comments on commit 45398c1

Please sign in to comment.