Skip to content

Commit

Permalink
more data store updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Aug 9, 2024
1 parent 9c5b726 commit 68095e4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace
{
std::array<float32, 9> ax2om(const std::array<float32, 4>& a)
{
std::array<float32, 9> res;
std::array<float32, 9> res = {};
float32 q = 0.0L;
float32 c = 0.0L;
float32 s = 0.0L;
Expand Down Expand Up @@ -71,6 +71,59 @@ ImageRotationUtilities::Matrix3fR toGMatrix(std::array<float32, 9> om)
g(2, 2) = om[8];
return g;
}

// -----------------------------------------------------------------------------
char determineIntersectCoord(const std::array<float32, 2>& p1, const std::array<float32, 2>& q1, const std::array<float32, 2>& p2, const std::array<float32, 2>& 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

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -98,8 +151,8 @@ Result<> CreateAMScanPaths::operator()()
auto& CADLayers = m_DataStructure.getDataRefAs<EdgeGeom>(m_InputValues->CADSliceDataContainerName);
INodeGeometry1D::SharedEdgeList& CADLayerEdges = CADLayers.getEdgesRef();
INodeGeometry0D::SharedVertexList& CADLayerVerts = CADLayers.getVerticesRef();
auto& cadSliceIds = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->CADSliceIdsArrayPath);
auto& cadRegionIds = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->CADRegionIdsArrayPath);
auto& cadSliceIds = m_DataStructure.getDataAs<Int32Array>(m_InputValues->CADSliceIdsArrayPath)->getDataStoreRef();
auto& cadRegionIds = m_DataStructure.getDataAs<Int32Array>(m_InputValues->CADRegionIdsArrayPath)->getDataStoreRef();
usize numCADLayerEdges = CADLayers.getNumberOfEdges();
usize numCADLayerVerts = CADLayers.getNumberOfVertices();
int32 numCADLayers = 0;
Expand Down Expand Up @@ -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<INodeGeometry0D::SharedVertexList::value_type>& hatchVerts = fitHatches.getVertices()->getDataStoreRef();
AbstractDataStore<INodeGeometry1D::SharedEdgeList::value_type>& hatches = fitHatches.getEdges()->getDataStoreRef();
std::vector<usize> tDims(1, numHatchVerts);
fitHatches.getVertexAttributeMatrix()->resizeTuples(tDims);
tDims[0] = hatchCount;
fitHatches.getEdgeAttributeMatrix()->resizeTuples(tDims);

auto& times =
m_DataStructure.getDataRefAs<Float64Array>(m_InputValues->HatchDataContainerName.createChildPath(m_InputValues->VertexAttributeMatrixName).createChildPath(m_InputValues->TimeArrayName));
auto& times = m_DataStructure.getDataAs<Float64Array>(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<Float32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->PowersArrayName));
auto& hatchSliceIds = m_DataStructure.getDataRefAs<Int32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->CADSliceIdsArrayPath.getTargetName()));
auto& hatchRegionIds = m_DataStructure.getDataRefAs<Int32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->RegionIdsArrayName));
auto& powers = m_DataStructure.getDataAs<Float32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->PowersArrayName))->getDataStoreRef();
auto& hatchSliceIds = m_DataStructure.getDataAs<Int32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->CADSliceIdsArrayPath.getTargetName()))->getDataStoreRef();
auto& hatchRegionIds = m_DataStructure.getDataAs<Int32Array>(hatchAttributeMatrixPath.createChildPath(m_InputValues->RegionIdsArrayName))->getDataStoreRef();

if(getCancel())
{
Expand Down Expand Up @@ -608,56 +661,3 @@ Result<> CreateAMScanPaths::operator()()

return {};
}

// -----------------------------------------------------------------------------
char CreateAMScanPaths::determineIntersectCoord(const std::array<float32, 2>& p1, const std::array<float32, 2>& q1, const std::array<float32, 2>& p2, const std::array<float32, 2>& 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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace nx::core
{

struct SIMPLNXCORE_EXPORT CreateAMScanPathsInputValues
{
float32 StripeWidth;
Expand Down Expand Up @@ -50,9 +49,6 @@ class SIMPLNXCORE_EXPORT CreateAMScanPaths

const std::atomic_bool& getCancel();

protected:
char determineIntersectCoord(const std::array<float32, 2>& p1, const std::array<float32, 2>& q1, const std::array<float32, 2>& p2, const std::array<float32, 2>& q2, float32& coordX);

private:
DataStructure& m_DataStructure;
const CreateAMScanPathsInputValues* m_InputValues = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,40 @@ template <typename T>
class CreateColorMapImpl
{
public:
CreateColorMapImpl(const DataArray<T>& arrayPtr, const std::vector<float32>& binPoints, const std::vector<float32>& controlPoints, int numControlColors, UInt8Array& colorArray,
CreateColorMapImpl(const AbstractDataStore<T>& arrayStore, const std::vector<float32>& binPoints, const std::vector<float32>& controlPoints, int numControlColors, UInt8AbstractDataStore& colorStore,
const nx::core::IDataArray* goodVoxels, const std::vector<uint8>& 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 <typename K>
void convert(size_t start, size_t end) const
void convert(usize start, usize end) const
{
using MaskArrayType = DataArray<K>;
const MaskArrayType* maskArray = nullptr;
if(nullptr != m_GoodVoxels)
{
maskArray = dynamic_cast<const MaskArrayType*>(m_GoodVoxels);
}
auto& colorArrayDS = m_ColorArray.getDataStoreRef();

for(size_t i = start; i < end; i++)
{
Expand All @@ -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<float32>(m_ArrayPtr[i] - m_ArrayMin)) / static_cast<float32>((m_ArrayMax - m_ArrayMin));
const float32 nValue = (static_cast<float32>(m_ArrayStore[i] - m_ArrayMin)) / static_cast<float32>((m_ArrayMax - m_ArrayMin));

int rightBinIndex = findRightBinIndex(nValue, m_BinPoints);

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -154,13 +153,13 @@ class CreateColorMapImpl
}

private:
const DataArray<T>& m_ArrayPtr;
const AbstractDataStore<T>& m_ArrayStore;
const std::vector<float32>& m_BinPoints;
T m_ArrayMin;
T m_ArrayMax;
int m_NumControlColors;
const std::vector<float32>& m_ControlPoints;
UInt8Array& m_ColorArray;
UInt8AbstractDataStore& m_ColorStore;
const nx::core::IDataArray* m_GoodVoxels = nullptr;
const std::vector<uint8>& m_InvalidColor;
};
Expand Down Expand Up @@ -189,18 +188,18 @@ struct GenerateColorArrayFunctor
binPoint = (binPoint - binMin) / (binMax - binMin);
}

auto& colorArray = dataStructure.getDataRefAs<UInt8Array>(inputValues->RgbArrayPath);
auto& colorArray = dataStructure.getDataAs<UInt8Array>(inputValues->RgbArrayPath)->getDataStoreRef();

nx::core::IDataArray* goodVoxelsArray = nullptr;
if(inputValues->UseMask)
{
goodVoxelsArray = dataStructure.getDataAs<IDataArray>(inputValues->MaskArrayPath);
}

const DataArray<ScalarType>& arrayRef = dataStructure.getDataRefAs<DataArray<ScalarType>>(inputValues->SelectedDataArrayPath);
const AbstractDataStore<ScalarType>& arrayRef = dataStructure.getDataAs<DataArray<ScalarType>>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64>& neighbors,
const std::shared_ptr<IDataArray>& dataArrayPtr)
ErodeDilateBadDataTransferDataImpl(ErodeDilateBadData* filterAlg, usize totalPoints, ChoicesParameter::ValueType operation, const Int32AbstractDataStore& featureIds,
const std::vector<int64>& neighbors, const std::shared_ptr<IDataArray>& dataArrayPtr)
: m_FilterAlg(filterAlg)
, m_TotalPoints(totalPoints)
, m_Operation(operation)
Expand Down Expand Up @@ -63,7 +63,7 @@ class ErodeDilateBadDataTransferDataImpl
ChoicesParameter::ValueType m_Operation = 0;
std::vector<int64> m_Neighbors;
const std::shared_ptr<IDataArray> m_DataArrayPtr;
const Int32Array& m_FeatureIds;
const Int32AbstractDataStore& m_FeatureIds;
};
} // namespace

Expand Down Expand Up @@ -94,7 +94,7 @@ void ErodeDilateBadData::updateProgress(const std::string& progMessage)
// -----------------------------------------------------------------------------
Result<> ErodeDilateBadData::operator()()
{
const auto& featureIds = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->FeatureIdsArrayPath);
const auto& featureIds = m_DataStructure.getDataAs<Int32Array>(m_InputValues->FeatureIdsArrayPath)->getDataStoreRef();
const usize totalPoints = featureIds.getNumberOfTuples();

std::vector<int64> neighbors(totalPoints, -1);
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "simplnx/Utilities/FilterUtilities.hpp"

using namespace nx::core;

namespace
{
struct DataArrayCopyTupleFunctor
{
template <typename T>
Expand All @@ -17,6 +18,7 @@ struct DataArrayCopyTupleFunctor
outputArray.copyTuple(sourceIndex, targetIndex);
}
};
} // namespace

// -----------------------------------------------------------------------------
ErodeDilateCoordinationNumber::ErodeDilateCoordinationNumber(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel,
Expand Down Expand Up @@ -191,10 +193,10 @@ Result<> ErodeDilateCoordinationNumber::operator()()
}
for(int64 zIndex = 0; zIndex < dims[2]; zIndex++)
{
const int64 zStride = static_cast<int64>(dims[0] * dims[1] * zIndex);
const auto zStride = static_cast<int64>(dims[0] * dims[1] * zIndex);
for(int64 yIndex = 0; yIndex < dims[1]; yIndex++)
{
const int64 yStride = static_cast<int64>(dims[0] * yIndex);
const auto yStride = static_cast<int64>(dims[0] * yIndex);
for(int64 xIndex = 0; xIndex < dims[0]; xIndex++)
{
const int64 voxelIndex = zStride + yStride + xIndex;
Expand Down

0 comments on commit 68095e4

Please sign in to comment.