Skip to content

Commit

Permalink
store updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Jul 12, 2024
1 parent e01fbb2 commit 44a2c2a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,84 @@ struct CombineAttributeArraysImpl
{

template <typename DataType>
Result<> operator()(const CombineAttributeArraysInputValues* inputValues, std::vector<DataObject*>& inputArraysVec, DataObject* outputArrayPtr)
Result<> operator()(bool normalize, std::vector<DataObject*>& inputArraysVec, DataObject* outputArrayPtr)
{
using OutputArrayType = DataArray<DataType>;
using InputArrayType = DataArray<DataType>;
using InputDataStoreType = AbstractDataStore<DataType>;
using OutputDataStoreType = AbstractDataStore<DataType>;

auto& outputArray = dynamic_cast<OutputArrayType&>(*outputArrayPtr);
int32_t numArrays = inputArraysVec.size();
OutputDataStoreType& outputDataStore = dynamic_cast<OutputArrayType*>(outputArrayPtr)->getDataStoreRef();
usize numArrays = inputArraysVec.size();
if(numArrays == 0)
{
return MakeWarningVoidResult(1, "No arrays were selected to combine.");
}

std::vector<InputArrayType*> inputArrays;

for(size_t i = 0; i < numArrays; i++)
for(usize i = 0; i < numArrays; i++)
{
inputArrays.push_back(dynamic_cast<InputArrayType*>(inputArraysVec[i]));
}

size_t numTuples = inputArrays[0]->getNumberOfTuples();
size_t stackedDims = outputArray.getNumberOfComponents();
size_t arrayOffset = 0;
size_t numComps = 0;
usize numTuples = inputArrays[0]->getNumberOfTuples();
usize stackedDims = outputDataStore.getNumberOfComponents();
usize arrayOffset = 0;
usize numComps = 0;

if(inputValues->NormalizeData)
if(normalize)
{
std::vector<DataType> maxValues(stackedDims, std::numeric_limits<DataType>::lowest());
std::vector<DataType> minValues(stackedDims, std::numeric_limits<DataType>::max());

for(size_t i = 0; i < numArrays; i++)
for(usize i = 0; i < numArrays; i++)
{
InputArrayType& inputArray = *inputArrays[i]; // Get a reference var to the current input array
const InputDataStoreType& inputDataStore = inputArrays[i]->getDataStoreRef(); // Get a reference var to the current input array

numComps = inputArray.getNumberOfComponents();
numComps = inputDataStore.getNumberOfComponents();
if(i > 0)
{
arrayOffset += inputArrays[i - 1]->getNumberOfComponents();
}
for(size_t j = 0; j < numTuples; j++)
for(usize j = 0; j < numTuples; j++)
{
for(size_t k = 0; k < numComps; k++)
for(usize k = 0; k < numComps; k++)
{
if(inputArray[numComps * j + k] > maxValues[arrayOffset + k])
if(inputDataStore[numComps * j + k] > maxValues[arrayOffset + k])
{
maxValues[arrayOffset + k] = inputArray[numComps * j + k];
maxValues[arrayOffset + k] = inputDataStore[numComps * j + k];
}
if(inputArray[numComps * j + k] < minValues[arrayOffset + k])
if(inputDataStore[numComps * j + k] < minValues[arrayOffset + k])
{
minValues[arrayOffset + k] = inputArray[numComps * j + k];
minValues[arrayOffset + k] = inputDataStore[numComps * j + k];
}
}
}
}

arrayOffset = 0;

for(size_t i = 0; i < numTuples; i++)
for(usize i = 0; i < numTuples; i++)
{
for(size_t j = 0; j < numArrays; j++)
for(usize j = 0; j < numArrays; j++)
{
InputArrayType& inputArray = *inputArrays[j]; // Get a reference var to the current input array
const InputDataStoreType& inputDataStore = inputArrays[j]->getDataStoreRef(); // Get a reference var to the current input array

numComps = inputArray.getNumberOfComponents();
numComps = inputDataStore.getNumberOfComponents();
if(j > 0)
{
arrayOffset += inputArrays[j - 1]->getNumberOfComponents();
}
for(size_t k = 0; k < numComps; k++)
for(usize k = 0; k < numComps; k++)
{
if(maxValues[arrayOffset + k] == minValues[arrayOffset + k])
{
outputArray[stackedDims * i + (arrayOffset) + k] = static_cast<DataType>(0);
outputDataStore[stackedDims * i + (arrayOffset) + k] = static_cast<DataType>(0);
}
else
{
outputArray[stackedDims * i + (arrayOffset) + k] = (inputArray[numComps * i + k] - minValues[arrayOffset + k]) / (maxValues[arrayOffset + k] - minValues[arrayOffset + k]);
outputDataStore[stackedDims * i + (arrayOffset) + k] = (inputDataStore[numComps * i + k] - minValues[arrayOffset + k]) / (maxValues[arrayOffset + k] - minValues[arrayOffset + k]);
}
}
}
Expand All @@ -100,18 +102,18 @@ struct CombineAttributeArraysImpl
}
else
{
size_t outputNumComps = outputArray.getNumberOfComponents();
size_t compsWritten = 0;
usize outputNumComps = outputDataStore.getNumberOfComponents();
usize compsWritten = 0;
for(const auto* inputArrayPtr : inputArrays)
{
const InputArrayType& inputArray = *inputArrayPtr; // Get a reference var to the current input array
size_t numInputComps = inputArray.getNumberOfComponents();
const InputDataStoreType& inputDataStore = inputArrayPtr->getDataStoreRef(); // Get a reference var to the current input array
usize numInputComps = inputDataStore.getNumberOfComponents();

for(size_t tupleIndex = 0; tupleIndex < numTuples; tupleIndex++)
for(usize tupleIndex = 0; tupleIndex < numTuples; tupleIndex++)
{
for(size_t compIndex = 0; compIndex < numInputComps; compIndex++)
for(usize compIndex = 0; compIndex < numInputComps; compIndex++)
{
outputArray[tupleIndex * outputNumComps + compsWritten + compIndex] = inputArray[tupleIndex * numInputComps + compIndex];
outputDataStore[tupleIndex * outputNumComps + compsWritten + compIndex] = inputDataStore[tupleIndex * numInputComps + compIndex];
}
}
compsWritten += numInputComps;
Expand Down Expand Up @@ -157,5 +159,5 @@ Result<> CombineAttributeArrays::operator()()

auto& outputArray = m_DataStructure.getDataRefAs<IDataArray>(m_InputValues->StackedDataArrayPath);

return ExecuteDataFunction(CombineAttributeArraysImpl{}, outputArray.getDataType(), m_InputValues, inputArrays, m_DataStructure.getData(m_InputValues->StackedDataArrayPath));
return ExecuteDataFunction(CombineAttributeArraysImpl{}, outputArray.getDataType(), m_InputValues->NormalizeData, inputArrays, m_DataStructure.getData(m_InputValues->StackedDataArrayPath));
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class CombineStlImpl
public:
CombineStlImpl(UInt64Array& destTriArray, Float32Array& destVerticesArray, Float64Array& destFaceNormalsArray, const UInt64Array& inputTriArray, const Float32Array& inputVerticesArray,
const Float64Array& inputFaceNormalsArray, usize triTupleOffset, usize vertexTupleOffset, usize faceNormalsTupleOffset)
: m_DestTriangles(destTriArray)
, m_DestVertices(destVerticesArray)
, m_DestFaceNormals(destFaceNormalsArray)
, m_InputTriangles(inputTriArray)
, m_InputVertices(inputVerticesArray)
, m_InputFaceNormals(inputFaceNormalsArray)
: m_DestTriangles(destTriArray.getDataStoreRef())
, m_DestVertices(destVerticesArray.getDataStoreRef())
, m_DestFaceNormals(destFaceNormalsArray.getDataStoreRef())
, m_InputTriangles(inputTriArray.getDataStoreRef())
, m_InputVertices(inputVerticesArray.getDataStoreRef())
, m_InputFaceNormals(inputFaceNormalsArray.getDataStoreRef())
, m_TriTupleOffset(triTupleOffset)
, m_VerticesTupleOffset(vertexTupleOffset)
, m_FaceNormalsTupleOffset(faceNormalsTupleOffset)
Expand All @@ -47,12 +47,12 @@ class CombineStlImpl
}

private:
UInt64Array& m_DestTriangles;
Float32Array& m_DestVertices;
Float64Array& m_DestFaceNormals;
const UInt64Array& m_InputTriangles;
const Float32Array& m_InputVertices;
const Float64Array& m_InputFaceNormals;
AbstractDataStore<uint64>& m_DestTriangles;
AbstractDataStore<float32>& m_DestVertices;
AbstractDataStore<float64>& m_DestFaceNormals;
const AbstractDataStore<uint64>& m_InputTriangles;
const AbstractDataStore<float32>& m_InputVertices;
const AbstractDataStore<float64>& m_InputFaceNormals;
usize m_TriTupleOffset;
usize m_VerticesTupleOffset;
usize m_FaceNormalsTupleOffset;
Expand Down Expand Up @@ -155,39 +155,37 @@ Result<> CombineStlFiles::operator()()
INodeGeometry2D::SharedFaceList& currentSharedFaceList = currentGeometry->getFacesRef();
usize currentGeomNumTriangles = currentGeometry->getNumberOfFaces();
usize currentGeomNumVertices = currentGeometry->getNumberOfVertices();
for(usize triIndex = 0; triIndex < currentGeomNumTriangles; triIndex++)
{
currentSharedFaceList[3 * triIndex + 0] += triCounter;
currentSharedFaceList[3 * triIndex + 1] += triCounter;
currentSharedFaceList[3 * triIndex + 2] += triCounter;
auto& currentSFLStore = currentSharedFaceList.getDataStoreRef();
for(usize triIndex = 0; triIndex < currentGeomNumTriangles; triIndex++)
{
currentSFLStore[3 * triIndex + 0] += triCounter;
currentSFLStore[3 * triIndex + 1] += triCounter;
currentSFLStore[3 * triIndex + 2] += triCounter;
}
triCounter += currentGeomNumVertices;
}
triCounter += currentGeomNumVertices;
INodeGeometry0D::SharedVertexList& curVertices = currentGeometry->getVerticesRef();
auto& curFaceNormals = tempDataStructure.getDataRefAs<Float64Array>(currentGeometry->getFaceAttributeMatrixDataPath().createChildPath("Face Normals"));

if(m_InputValues->LabelFaces)
{
auto& faceLabels = m_DataStructure.getDataRefAs<UInt32Array>(m_InputValues->FaceFileIndexArrayPath);
// for(usize tuple = faceLabelOffset; tuple < faceLabelOffset + currentGeomNumTriangles; tuple++)
// {
// faceLabels[tuple] = fileIndex;
// }
std::fill(faceLabels.begin() + faceLabelOffset, faceLabels.begin() + faceLabelOffset + currentGeomNumTriangles, fileIndex);
// Type checked in preflight; Unsafe acceptable; pointer for speed
auto* faceLabelsStore = m_DataStructure.getDataAsUnsafe<UInt32Array>(m_InputValues->FaceFileIndexArrayPath)->getDataStore();
std::fill(faceLabelsStore->begin() + faceLabelOffset, faceLabelsStore->begin() + faceLabelOffset + currentGeomNumTriangles, fileIndex);
}

faceLabelOffset += currentGeomNumTriangles;

if(m_InputValues->LabelVertices)
{
auto& vertexLabels = m_DataStructure.getDataRefAs<UInt32Array>(m_InputValues->VertexFileIndexArrayPath);
// for(usize tuple = vertexLabelOffset; tuple < vertexLabelOffset + currentGeomNumVertices; tuple++)
// {
// vertexLabels[tuple] = fileIndex;
// }
std::fill(vertexLabels.begin() + vertexLabelOffset, vertexLabels.begin() + vertexLabelOffset + currentGeomNumVertices, fileIndex);
// Type checked in preflight; Unsafe acceptable; pointer for speed
auto* vertexLabels = m_DataStructure.getDataAsUnsafe<UInt32Array>(m_InputValues->VertexFileIndexArrayPath)->getDataStore();
std::fill(vertexLabels->begin() + vertexLabelOffset, vertexLabels->begin() + vertexLabelOffset + currentGeomNumVertices, fileIndex);
}
vertexLabelOffset += currentGeomNumVertices;

INodeGeometry0D::SharedVertexList& curVertices = currentGeometry->getVerticesRef();
auto& curFaceNormals = tempDataStructure.getDataRefAs<Float64Array>(currentGeometry->getFaceAttributeMatrixDataPath().createChildPath("Face Normals"));

taskRunner.execute(CombineStlImpl{triangles, vertices, combinedFaceNormals, currentSharedFaceList, curVertices, curFaceNormals, triOffset, vertexOffset, faceNormalsOffset});

triOffset += currentGeomNumTriangles * 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "simplnx/Utilities/ParallelAlgorithmUtilities.hpp"
#include "simplnx/Utilities/ParallelTaskAlgorithm.hpp"

#include <algorithm>
#include <chrono>
#include <tuple>

Expand All @@ -19,7 +18,7 @@ template <typename DataArrayType>
class GenerateHistogramFromData
{
public:
GenerateHistogramFromData(ComputeArrayHistogram& filter, const int32 numBins, const IDataArray& inputArray, Float64Array& histogram, std::atomic<usize>& overflow,
GenerateHistogramFromData(ComputeArrayHistogram& filter, const int32 numBins, const IDataArray& inputArray, AbstractDataStore<float64>& histogram, std::atomic<usize>& overflow,
std::tuple<bool, float64, float64>& range, size_t progressIncrement)
: m_Filter(filter)
, m_NumBins(numBins)
Expand All @@ -34,7 +33,7 @@ class GenerateHistogramFromData

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

// tuple visualization: Histogram = {(bin maximum, count), (bin maximum, count), ... }
Expand Down Expand Up @@ -96,7 +95,7 @@ class GenerateHistogramFromData
const int32 m_NumBins = 1;
std::tuple<bool, float64, float64>& m_Range;
const IDataArray& m_InputArray;
Float64Array& m_Histogram;
AbstractDataStore<float64>& m_Histogram;
std::atomic<usize>& m_Overflow;
size_t m_ProgressIncrement = 100;
};
Expand Down Expand Up @@ -167,7 +166,7 @@ Result<> ComputeArrayHistogram::operator()()
return {};
}
const auto& inputData = m_DataStructure.getDataRefAs<IDataArray>(selectedArrayPaths[i]);
auto& histogram = m_DataStructure.getDataRefAs<DataArray<float64>>(m_InputValues->CreatedHistogramDataPaths.at(i));
auto& histogram = m_DataStructure.getDataAs<DataArray<float64>>(m_InputValues->CreatedHistogramDataPaths.at(i))->getDataStoreRef();
ExecuteParallelFunction<GenerateHistogramFromData>(inputData.getDataType(), taskRunner, *this, numBins, inputData, histogram, overflow, range, progressIncrement);

if(overflow > 0)
Expand Down
Loading

0 comments on commit 44a2c2a

Please sign in to comment.