Skip to content

Commit

Permalink
Utilities updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Aug 20, 2024
1 parent 3e3244d commit 5c4354c
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ IFilter::PreflightResult RemoveFlaggedEdgesFilter::preflightImpl(const DataStruc
{
return {MakeErrorResult<OutputActions>(-5651, fmt::format("'{}' must have edge data attribute matrix", pInitialGeometryPathValue.toString()))};
}
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcEdgeAttrMatPtr, selectedEdgeArrays, reducedEdgeAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcEdgeAttrMatPtr, selectedEdgeArrays, reducedEdgeAttributeMatrixPath, resultOutputActions);
}
else if(pEdgeArrayHandling == detail::k_CopyAllEdgeArraysIdx)
{
Expand All @@ -154,7 +154,7 @@ IFilter::PreflightResult RemoveFlaggedEdgesFilter::preflightImpl(const DataStruc
if(getChildrenResult.has_value())
{
selectedEdgeArrays = getChildrenResult.value();
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcEdgeAttrMatPtr, selectedEdgeArrays, reducedEdgeAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcEdgeAttrMatPtr, selectedEdgeArrays, reducedEdgeAttributeMatrixPath, resultOutputActions);
}
}
}
Expand All @@ -170,7 +170,7 @@ IFilter::PreflightResult RemoveFlaggedEdgesFilter::preflightImpl(const DataStruc
{
return {MakeErrorResult<OutputActions>(-5653, fmt::format("'{}' must have Vertex data attribute matrix", pInitialGeometryPathValue.toString()))};
}
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
}
else if(pVertexArrayHandling == detail::k_CopyAllVertexArraysIdx)
{
Expand All @@ -184,7 +184,7 @@ IFilter::PreflightResult RemoveFlaggedEdgesFilter::preflightImpl(const DataStruc
if(getChildrenResult.has_value())
{
selectedVertexArrays = getChildrenResult.value();
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ IFilter::PreflightResult RemoveFlaggedTrianglesFilter::preflightImpl(const DataS
{
return {MakeErrorResult<OutputActions>(-5251, fmt::format("'{}' must have face data attribute matrix", pInitialGeometryPathValue.toString()))};
}
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcTriangleAttrMatPtr, selectedTriangleArrays, reducedFaceAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcTriangleAttrMatPtr, selectedTriangleArrays, reducedFaceAttributeMatrixPath, resultOutputActions);
}
else if(pTriangleArrayHandling == detail::k_CopyAllTriangleArraysIdx)
{
Expand All @@ -162,7 +162,7 @@ IFilter::PreflightResult RemoveFlaggedTrianglesFilter::preflightImpl(const DataS
if(getChildrenResult.has_value())
{
selectedTriangleArrays = getChildrenResult.value();
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcTriangleAttrMatPtr, selectedTriangleArrays, reducedFaceAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcTriangleAttrMatPtr, selectedTriangleArrays, reducedFaceAttributeMatrixPath, resultOutputActions);
}
}
}
Expand All @@ -178,7 +178,7 @@ IFilter::PreflightResult RemoveFlaggedTrianglesFilter::preflightImpl(const DataS
{
return {MakeErrorResult<OutputActions>(-5553, fmt::format("'{}' must have Vertex data attribute matrix", pInitialGeometryPathValue.toString()))};
}
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
}
else if(pVertexArrayHandling == detail::k_CopyAllVertexArraysIdx)
{
Expand All @@ -192,7 +192,7 @@ IFilter::PreflightResult RemoveFlaggedTrianglesFilter::preflightImpl(const DataS
if(getChildrenResult.has_value())
{
selectedVertexArrays = getChildrenResult.value();
TransferGeometryElementData::createDataArrayActions<INodeGeometry1D>(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
TransferGeometryElementData::CreateDataArrayActions(dataStructure, srcVertexAttrMatPtr, selectedVertexArrays, reducedVertexAttributeMatrixPath, resultOutputActions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ class AbstractDataParser
AbstractDataParser& operator=(const AbstractDataParser&) = delete; // Copy Assignment Not Implemented
AbstractDataParser& operator=(AbstractDataParser&&) = delete; // Move Assignment

std::string columnName() const
[[nodiscard]] std::string columnName() const
{
return m_ColumnName;
}

usize columnIndex() const
[[nodiscard]] usize columnIndex() const
{
return m_ColumnIndex;
}

const IDataArray& dataArray() const
[[nodiscard]] const IDataArray& dataArray() const
{
return m_DataArray;
}
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/Utilities/AlignSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Result<> AlignSections::execute(const SizeVec3& udims)
}

// -----------------------------------------------------------------------------
Result<> AlignSections::readDream3dShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts) const
Result<> AlignSections::readDream3dShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts)
{
std::ifstream inFile;
inFile.open(file);
Expand Down Expand Up @@ -199,7 +199,7 @@ Result<> AlignSections::readDream3dShiftsFile(const std::filesystem::path& file,
return MakeErrorResult(-84750, message);
}
std::istringstream temp(line);
iss.swap(temp); // reset the stream to beginning so we can read in the formatted tokens
iss.swap(temp); // reset the stream to beginning, so we can read in the formatted tokens
iss >> slice >> slice2 >> newXShift >> newYShift >> xShift >> yShift;
xShifts[iter] = xShifts[iter - 1] + newXShift;
yShifts[iter] = yShifts[iter - 1] + newYShift;
Expand All @@ -209,7 +209,7 @@ Result<> AlignSections::readDream3dShiftsFile(const std::filesystem::path& file,
}

// -----------------------------------------------------------------------------
Result<> AlignSections::readUserShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts) const
Result<> AlignSections::readUserShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts)
{
int64 slice = 0;
int64 newXShift = 0, newYShift = 0;
Expand All @@ -235,7 +235,7 @@ Result<> AlignSections::readUserShiftsFile(const std::filesystem::path& file, in
return MakeErrorResult(-84750, message);
}
std::istringstream temp(line);
iss.swap(temp); // reset the stream to beginning so we can read in the formatted tokens
iss.swap(temp); // reset the stream to beginning, so we can read in the formatted tokens
inFile >> slice >> newXShift >> newYShift;
xShifts[iter] = xShifts[iter - 1] + newXShift;
yShifts[iter] = yShifts[iter - 1] + newYShift;
Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/Utilities/AlignSections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SIMPLNX_EXPORT AlignSections
* @param yShifts
* @return Whether or not the x and y shifts were successfully found
*/
Result<> readDream3dShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts) const;
static Result<> readDream3dShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts) ;

/**
* @brief This will read in a shifts file defined by the user and populate the shifts parameters with the values as int64 numbers.
Expand All @@ -64,7 +64,7 @@ class SIMPLNX_EXPORT AlignSections
* @param yShifts
* @return Whether or not the x and y shifts were successfully found
*/
Result<> readUserShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts) const;
static Result<> readUserShiftsFile(const std::filesystem::path& file, int64 zDim, std::vector<int64_t>& xShifts, std::vector<int64_t>& yShifts);

private:
DataStructure& m_DataStructure;
Expand Down
68 changes: 12 additions & 56 deletions src/simplnx/Utilities/ArrayThreshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ constexpr StringLiteral k_ArrayType = "array";
constexpr StringLiteral k_CollectionType = "collection";
} // namespace

IArrayThreshold::IArrayThreshold()
IArrayThreshold::IArrayThreshold() = default;
IArrayThreshold::IArrayThreshold(const IArrayThreshold& other) = default;

{
}
IArrayThreshold::IArrayThreshold(const IArrayThreshold& other)
IArrayThreshold::IArrayThreshold(IArrayThreshold&& other) noexcept
: m_IsInverted(other.m_IsInverted)
, m_UnionType(other.m_UnionType)
{
}
IArrayThreshold::IArrayThreshold(IArrayThreshold&& other) noexcept
: m_IsInverted(std::move(other.m_IsInverted))
, m_UnionType(std::move(other.m_UnionType))
{
}
IArrayThreshold::~IArrayThreshold() = default;

bool IArrayThreshold::isInverted() const
Expand Down Expand Up @@ -68,18 +62,13 @@ ArrayThreshold::ArrayThreshold()

{
}
ArrayThreshold::ArrayThreshold(const ArrayThreshold& other)
: IArrayThreshold(other)
, m_ArrayPath(other.m_ArrayPath)
, m_Value(other.m_Value)
, m_Comparison(other.m_Comparison)
{
}
ArrayThreshold::ArrayThreshold(const ArrayThreshold& other) = default;

ArrayThreshold::ArrayThreshold(ArrayThreshold&& other) noexcept
: IArrayThreshold(std::move(other))
, m_ArrayPath(std::move(other.m_ArrayPath))
, m_Value(std::move(other.m_Value))
, m_Comparison(std::move(other.m_Comparison))
, m_Value(other.m_Value)
, m_Comparison(other.m_Comparison)
{
}
ArrayThreshold::~ArrayThreshold() = default;
Expand All @@ -101,8 +90,8 @@ ArrayThreshold& ArrayThreshold::operator=(ArrayThreshold&& other) noexcept
setUnionOperator(other.getUnionOperator());

m_ArrayPath = std::move(other.m_ArrayPath);
m_Value = std::move(other.m_Value);
m_Comparison = std::move(other.m_Comparison);
m_Value = other.m_Value;
m_Comparison = other.m_Comparison;

return *this;
}
Expand Down Expand Up @@ -139,37 +128,6 @@ std::set<DataPath> ArrayThreshold::getRequiredPaths() const
return {getArrayPath()};
}

template <typename T>
bool checkArrayThreshold(const DataArray<T>* dataArray, ArrayThreshold::ComparisonValue value, ArrayThreshold::ComparisonType comparison, usize tupleId)
{
const auto dataStore = dataArray->getDataStore();
const auto numComponents = dataStore->getNumberOfComponents();

auto tuplePos = tupleId * numComponents;
T tupleValue = 0;
for(usize i = tuplePos; i < tuplePos + numComponents; i++)
{
// Avoid overflow
tupleValue += dataStore->getValue(i) / static_cast<double>(numComponents);
}

bool threshold = false;
switch(comparison)
{
case ArrayThreshold::ComparisonType::GreaterThan:
threshold = (tupleValue > value);
break;
case ArrayThreshold::ComparisonType::LessThan:
threshold = (tupleValue < value);
break;
default:
threshold = false;
break;
}

return threshold;
}

nlohmann::json ArrayThreshold::toJson() const
{
auto json = IArrayThreshold::toJson();
Expand Down Expand Up @@ -213,11 +171,9 @@ ArrayThresholdSet::ArrayThresholdSet()
: IArrayThreshold()
{
}
ArrayThresholdSet::ArrayThresholdSet(const ArrayThresholdSet& other)
: IArrayThreshold(other)
, m_Thresholds(other.m_Thresholds)
{
}

ArrayThresholdSet::ArrayThresholdSet(const ArrayThresholdSet& other) = default;

ArrayThresholdSet::ArrayThresholdSet(ArrayThresholdSet&& other) noexcept
: IArrayThreshold(std::move(other))
, m_Thresholds(std::move(other.m_Thresholds))
Expand Down
25 changes: 12 additions & 13 deletions src/simplnx/Utilities/ArrayThreshold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace nx::core
class SIMPLNX_EXPORT IArrayThreshold
{
public:
using MaskValue = bool;
enum class UnionOperator : uint8
{
And,
Expand All @@ -32,15 +31,15 @@ class SIMPLNX_EXPORT IArrayThreshold
IArrayThreshold(IArrayThreshold&& other) noexcept;
virtual ~IArrayThreshold();

bool isInverted() const;
[[nodiscard]] bool isInverted() const;
void setInverted(bool inverted);

UnionOperator getUnionOperator() const;
[[nodiscard]] UnionOperator getUnionOperator() const;
void setUnionOperator(UnionOperator unionType);

virtual std::set<DataPath> getRequiredPaths() const = 0;
[[nodiscard]] virtual std::set<DataPath> getRequiredPaths() const = 0;

virtual nlohmann::json toJson() const;
[[nodiscard]] virtual nlohmann::json toJson() const;

private:
bool m_IsInverted{false};
Expand Down Expand Up @@ -70,18 +69,18 @@ class SIMPLNX_EXPORT ArrayThreshold : public IArrayThreshold
ArrayThreshold& operator=(const ArrayThreshold& other);
ArrayThreshold& operator=(ArrayThreshold&& other) noexcept;

DataPath getArrayPath() const;
[[nodiscard]] DataPath getArrayPath() const;
void setArrayPath(const DataPath& path);

ComparisonValue getComparisonValue() const;
[[nodiscard]] ComparisonValue getComparisonValue() const;
void setComparisonValue(ComparisonValue value);

ComparisonType getComparisonType() const;
[[nodiscard]] ComparisonType getComparisonType() const;
void setComparisonType(ComparisonType comparison);

std::set<DataPath> getRequiredPaths() const override;
[[nodiscard]] std::set<DataPath> getRequiredPaths() const override;

nlohmann::json toJson() const override;
[[nodiscard]] nlohmann::json toJson() const override;
static std::shared_ptr<ArrayThreshold> FromJson(const nlohmann::json& json);

private:
Expand All @@ -106,12 +105,12 @@ class SIMPLNX_EXPORT ArrayThresholdSet : public IArrayThreshold
ArrayThresholdSet& operator=(const ArrayThresholdSet& other);
ArrayThresholdSet& operator=(ArrayThresholdSet&& other) noexcept;

CollectionType getArrayThresholds() const;
[[nodiscard]] CollectionType getArrayThresholds() const;
void setArrayThresholds(const CollectionType& thresholds);

std::set<DataPath> getRequiredPaths() const override;
[[nodiscard]] std::set<DataPath> getRequiredPaths() const override;

nlohmann::json toJson() const override;
[[nodiscard]] nlohmann::json toJson() const override;
static std::shared_ptr<ArrayThresholdSet> FromJson(const nlohmann::json& json);

private:
Expand Down
16 changes: 15 additions & 1 deletion src/simplnx/Utilities/DataArrayUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,20 @@ void transferElementData(DataStructure& m_DataStructure, AttributeMatrix& destCe
}
taskRunner.wait(); // This will spill over if the number of DataArrays to process does not divide evenly by the number of threads.
}
} // namespace TransferGeometryElementData

void CreateDataArrayActions(const DataStructure& dataStructure, const AttributeMatrix* sourceAttrMatPtr, const MultiArraySelectionParameter::ValueType& selectedArrayPaths,
const DataPath& reducedGeometryPathAttrMatPath, Result<OutputActions>& resultOutputActions)
{
// Now loop over each array in selectedEdgeArrays and create the corresponding arrays
// in the destination geometry's attribute matrix
for(const auto& dataPath : selectedArrayPaths)
{
const auto& srcArray = dataStructure.getDataRefAs<IDataArray>(dataPath);
DataType dataType = srcArray.getDataType();
IDataStore::ShapeType componentShape = srcArray.getIDataStoreRef().getComponentShape();
DataPath dataArrayPath = reducedGeometryPathAttrMatPath.createChildPath(srcArray.getName());
resultOutputActions.value().appendAction(std::make_unique<CreateArrayAction>(dataType, sourceAttrMatPtr->getShape(), std::move(componentShape), dataArrayPath));
}
}
} // namespace TransferGeometryElementData
} // namespace nx::core
Loading

0 comments on commit 5c4354c

Please sign in to comment.