Skip to content

Commit

Permalink
ENH/BUG: Data Array to Store, Speed Optimizations, Code Cleanup (Simp…
Browse files Browse the repository at this point in the history
…lnxCore) (BlueQuartzSoftware#1017)

* extraneous code removal and AbstractDataStore integration for SimplnxCore and main simplnx Utility Files
* moved various free functions to an anonymous namespaces
* bug fix where duplicate nodes were being ignored on STL file read in in the Z dimension
* [1 broken test] All algorithms complete, rework of IDataArray to typed store that avoids extra dynamic cast
* Fix Write Stl bug accidentally introduced
* Utilities updates
* Fix Accidental Boolean Fallthrough
  • Loading branch information
nyoungbq authored and imikejackson committed Aug 23, 2024
1 parent 053699f commit 8031818
Show file tree
Hide file tree
Showing 221 changed files with 2,606 additions and 3,744 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "simplnx/DataStructure/DataPath.hpp"
#include "simplnx/DataStructure/Geometry/ImageGeom.hpp"
#include "simplnx/Filter/Actions/CreateArrayAction.hpp"
#include "simplnx/Filter/Actions/EmptyAction.hpp"
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/BoolParameter.hpp"
#include "simplnx/Parameters/DataObjectNameParameter.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "simplnx/Utilities/DataGroupUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"

#include <chrono>
#include <random>

using namespace nx::core;
Expand All @@ -17,7 +16,7 @@ struct InitializeTupleToZeroFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& arrayPath, usize index)
{
dataStructure.getDataRefAs<DataArray<T>>(arrayPath).initializeTuple(index, 0);
dataStructure.getDataAsUnsafe<DataArray<T>>(arrayPath)->initializeTuple(index, 0);
}
};
} // namespace
Expand All @@ -43,19 +42,17 @@ const std::atomic_bool& AddBadData::getCancel()
// -----------------------------------------------------------------------------
Result<> AddBadData::operator()()
{
std::random_device randomDevice; // Will be used to obtain a seed for the random number engine
std::mt19937 generator(randomDevice()); // Standard mersenne_twister_engine seeded with rd()
generator.seed(m_InputValues->SeedValue);
std::mt19937 generator(m_InputValues->SeedValue); // Standard mersenne_twister_engine seeded
std::uniform_real_distribution<float32> distribution(0.0F, 1.0F);

auto& imgGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
auto& GBEuclideanDistances = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->GBEuclideanDistancesArrayPath);
const auto& imgGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
const auto& GBEuclideanDistances = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->GBEuclideanDistancesArrayPath).getDataStoreRef();

auto childArrayPaths = GetAllChildArrayDataPaths(m_DataStructure, imgGeom.getCellDataPath());
auto voxelArrayPaths = childArrayPaths.has_value() ? childArrayPaths.value() : std::vector<DataPath>{};

float32 random = 0.0f;
size_t totalPoints = GBEuclideanDistances.getSize();
const size_t totalPoints = GBEuclideanDistances.getSize();
for(size_t i = 0; i < totalPoints; ++i)
{
if(m_InputValues->BoundaryNoise && GBEuclideanDistances[i] < 1)
Expand All @@ -65,7 +62,7 @@ Result<> AddBadData::operator()()
{
for(const auto& voxelArrayPath : voxelArrayPaths)
{
ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAs<IDataArray>(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i);
ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAsUnsafe<IDataArray>(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ std::vector<DataPath> AlignSectionsList::getSelectedDataPaths() const
// -----------------------------------------------------------------------------
Result<> AlignSectionsList::findShifts(std::vector<int64>& xShifts, std::vector<int64>& yShifts)
{
auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
const auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);

SizeVec3 udims = imageGeom.getDimensions();
int64 zDim = static_cast<int64>(udims[2]);
auto zDim = static_cast<int64>(udims[2]);

Result<> results = {};
if(m_InputValues->DREAM3DAlignmentFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Result<> ApplyTransformationToGeometry::applyImageGeometryTransformation()
// -----------------------------------------------------------------------------
Result<> ApplyTransformationToGeometry::applyNodeGeometryTransformation()
{
INodeGeometry0D& nodeGeometry0D = m_DataStructure.getDataRefAs<INodeGeometry0D>(m_InputValues->SelectedGeometryPath);
auto& nodeGeometry0D = m_DataStructure.getDataRefAs<INodeGeometry0D>(m_InputValues->SelectedGeometryPath);

IGeometry::SharedVertexList& vertexList = nodeGeometry0D.getVerticesRef();

Expand Down Expand Up @@ -159,7 +159,7 @@ Result<> ApplyTransformationToGeometry::operator()()
}
case detail::k_PrecomputedTransformationMatrixIdx: // Transformation matrix from array
{
const Float32Array& precomputed = m_DataStructure.getDataRefAs<Float32Array>(m_InputValues->ComputedTransformationMatrix);
const auto& precomputed = m_DataStructure.getDataAsUnsafe<Float32Array>(m_InputValues->ComputedTransformationMatrix)->getDataStoreRef();
m_TransformationMatrix = ImageRotationUtilities::CopyPrecomputedToTransformationMatrix(precomputed);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct CreateCalculatorArrayFunctor
template <typename T>
CalculatorItem::Pointer operator()(DataStructure& dataStructure, bool allocate, const IDataArray* iDataArrayPtr)
{
const DataArray<T>* inputDataArray = dynamic_cast<const DataArray<T>*>(iDataArrayPtr);
const auto* inputDataArray = dynamic_cast<const DataArray<T>*>(iDataArrayPtr);
CalculatorItem::Pointer itemPtr = CalculatorArray<T>::New(dataStructure, inputDataArray, ICalculatorArray::Array, allocate);
return itemPtr;
}
Expand All @@ -55,15 +55,22 @@ struct CopyArrayFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray)
{
const auto& inputDataStore = inputArray->getDataStoreRef();
if(nullptr != inputArray)
{
DataArray<T>& convertedArray = dataStructure.getDataRefAs<DataArray<T>>(calculatedArrayPath);
auto& convertedDataStore = dataStructure.getDataAsUnsafe<DataArray<T>>(calculatedArrayPath)->getDataStoreRef();

int count = inputArray->getSize();
for(int i = 0; i < count; i++)
const usize count = inputDataStore.getSize();
for(usize i = 0; i < count; i++)
{
double val = (*inputArray)[i];
convertedArray[i] = val;
if constexpr(std::is_same_v<float64, T>)
{
convertedDataStore[i] = inputDataStore[i];
}
else
{
convertedDataStore[i] = static_cast<T>(inputDataStore[i]);
}
}
}
}
Expand All @@ -74,11 +81,17 @@ struct InitializeArrayFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray)
{
DataArray<T>& convertedArray = dataStructure.getDataRefAs<DataArray<T>>(calculatedArrayPath);
auto& convertedDataStore = dataStructure.getDataAsUnsafe<DataArray<T>>(calculatedArrayPath)->getDataStoreRef();
if(nullptr != inputArray && inputArray->getSize() == 1)
{
const T& initializeValue = inputArray->at(0);
convertedArray.fill(initializeValue);
if constexpr(std::is_same_v<float64, T>)
{
convertedDataStore.fill(inputArray->at(0));
}
else
{
convertedDataStore.fill(static_cast<T>(inputArray->at(0)));
}
}
}
};
Expand Down Expand Up @@ -318,14 +331,13 @@ std::vector<std::string> ArrayCalculatorParser::getRegularExpressionMatches()
std::vector<std::string> itemList;
// Match all array names that start with two alphabetical characters and have spaces. Match all numbers, decimal or integer.
// Match one letter array names. Match all special character operators.
std::regex regExp("(\"((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)*(\\w|\\d){1,1})?|\\S)\")|(((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)"
"*(\\w|\\d){1,1})?|\\S))");
std::regex regExp(R"lit(("((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)")|(((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)))lit");

auto regExpMatchBegin = std::sregex_iterator(m_InfixEquation.begin(), m_InfixEquation.end(), regExp);
auto regExpMatchEnd = std::sregex_iterator();
for(std::sregex_iterator i = regExpMatchBegin; i != regExpMatchEnd; ++i)
{
std::smatch match = *i;
const std::smatch& match = *i;
itemList.push_back(match.str());
}

Expand Down Expand Up @@ -436,7 +448,7 @@ Result<> ArrayCalculatorParser::parseCommaOperator(std::string token, std::vecto
// For example, if we have root( 4*4, 2*3 ), then we need it to be root( (4*4), (2*3) )
parsedInfix.push_back(RightParenthesisItem::New());

std::vector<CalculatorItem::Pointer>::iterator iter = parsedInfix.end();
auto iter = parsedInfix.end();
iter--;
while(iter != parsedInfix.begin())
{
Expand Down Expand Up @@ -473,7 +485,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector<Calcul
}

DataPath tokenArrayPath = m_SelectedGroupPath.empty() ? DataPath({token}) : m_SelectedGroupPath.createChildPath(token);
const IDataArray* dataArray = m_DataStructure.getDataAs<IDataArray>(tokenArrayPath);
const auto* dataArray = m_DataStructure.getDataAs<IDataArray>(tokenArrayPath);
if(firstArray_NumTuples < 0 && firstArray_Name.empty())
{
firstArray_NumTuples = dataArray->getNumberOfTuples();
Expand All @@ -491,7 +503,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector<Calcul
}

// -----------------------------------------------------------------------------
Result<> ArrayCalculatorParser::checkForAmbiguousArrayName(std::string strItem, std::string warningMsg)
Result<> ArrayCalculatorParser::checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg)
{
if(m_IsPreflight && ContainsDataArrayName(m_DataStructure, m_SelectedGroupPath, strItem))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SIMPLNXCORE_EXPORT ArrayCalculatorParser
Result<> parseIndexOperator(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> parseCommaOperator(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> parseArray(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> checkForAmbiguousArrayName(std::string strItem, std::string warningMsg);
Result<> checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg);

private:
const DataStructure& m_DataStructure;
Expand Down
Loading

0 comments on commit 8031818

Please sign in to comment.