Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: Inline Keyword and Anonymous Namespace Cleanup #1013

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ namespace fs = std::filesystem;

using namespace nx::core;

namespace RotateSampleRefFrame
{
// Parameter Keys
static inline constexpr nx::core::StringLiteral k_RotationRepresentation_Key = "rotation_representation";
static inline constexpr nx::core::StringLiteral k_RotationAxisAngle_Key = "rotation_axis";
static inline constexpr nx::core::StringLiteral k_RotationMatrix_Key = "rotation_matrix";
static inline constexpr nx::core::StringLiteral k_SelectedImageGeometryPath_Key = "input_image_geometry_path";
static inline constexpr nx::core::StringLiteral k_CreatedImageGeometry_Key = "output_image_geometry_path";
static inline constexpr nx::core::StringLiteral k_RotateSliceBySlice_Key = "rotate_slice_by_slice";
static inline constexpr nx::core::StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry";

// static inline constexpr nx::core::StringLiteral k_RotatedGeometryName = ".RotatedGeometry";

enum class RotationRepresentation : uint64_t
{
AxisAngle = 0,
RotationMatrix = 1
};

} // namespace RotateSampleRefFrame

namespace
{
const ChoicesParameter::Choices k_SliceOperationChoices = {"None", "Flip about X axis", "Flip about Y axis"};
Expand All @@ -63,6 +42,22 @@ const FilterHandle k_ColorToGrayScaleFilterHandle(k_ColorToGrayScaleFilterId, k_
const Uuid k_ResampleImageGeomFilterId = *Uuid::FromString("9783ea2c-4cf7-46de-ab21-b40d91a48c5b");
const FilterHandle k_ResampleImageGeomFilterHandle(k_ResampleImageGeomFilterId, k_SimplnxCorePluginId);

// Parameter Keys
constexpr StringLiteral k_RotationRepresentation_Key = "rotation_representation";
constexpr StringLiteral k_RotationAxisAngle_Key = "rotation_axis";
constexpr StringLiteral k_RotationMatrix_Key = "rotation_matrix";
constexpr StringLiteral k_SelectedImageGeometryPath_Key = "input_image_geometry_path";
constexpr StringLiteral k_CreatedImageGeometry_Key = "output_image_geometry_path";
constexpr StringLiteral k_RotateSliceBySlice_Key = "rotate_slice_by_slice";
constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry";
// constexpr StringLiteral k_RotatedGeometryName = ".RotatedGeometry";

enum class RotationRepresentation : uint64_t
{
AxisAngle = 0,
RotationMatrix = 1
};

// Make sure we can instantiate the RotateSampleRefFrame Filter
std::unique_ptr<IFilter> CreateRotateSampleRefFrameFilter()
{
Expand Down Expand Up @@ -137,7 +132,7 @@ namespace cxITKImportImageStackFilter
{
template <class T>
Result<> ReadImageStack(DataStructure& dataStructure, const DataPath& imageGeomPath, const std::string& cellDataName, const std::string& imageArrayName, const std::vector<std::string>& files,
ChoicesParameter::ValueType transformType, bool convertToGrayscale, VectorFloat32Parameter::ValueType luminosityValues, bool resample, float32 scalingFactor,
ChoicesParameter::ValueType transformType, bool convertToGrayscale, const VectorFloat32Parameter::ValueType& luminosityValues, bool resample, float32 scalingFactor,
const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel)
{
auto& imageGeom = dataStructure.getDataRefAs<ImageGeom>(imageGeomPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const Uuid k_SimplnxCorePluginId = *Uuid::FromString("05cc618b-781f-4ac0-b9ac-43
const Uuid k_ApplyTransformationToGeometryFilterId = *Uuid::FromString("f5bbc16b-3426-4ae0-b27b-ba7862dc40fe");
const FilterHandle k_ApplyTransformationToGeometryFilterHandle(k_ApplyTransformationToGeometryFilterId, k_SimplnxCorePluginId);

inline constexpr StringLiteral k_SelectedImageGeometryKey = "input_image_geometry_path";
inline constexpr StringLiteral k_CellAttributeMatrixPathKey = "cell_attribute_matrix_path";
inline constexpr StringLiteral k_TransformationTypeKey = "transformation_type_index";
inline constexpr StringLiteral k_ManualTransformationMatrixKey = "manual_transformation_matrix";
inline constexpr StringLiteral k_TranslateGeometryToGlobalOrigin_Key = "translate_geometry_to_global_origin";
constexpr StringLiteral k_SelectedImageGeometryKey = "input_image_geometry_path";
constexpr StringLiteral k_CellAttributeMatrixPathKey = "cell_attribute_matrix_path";
constexpr StringLiteral k_TransformationTypeKey = "transformation_type_index";
constexpr StringLiteral k_ManualTransformationMatrixKey = "manual_transformation_matrix";
constexpr StringLiteral k_TranslateGeometryToGlobalOrigin_Key = "translate_geometry_to_global_origin";

const nx::core::ChoicesParameter::ValueType k_ManualTransformationMatrixIdx = 2ULL;

Expand Down
18 changes: 9 additions & 9 deletions src/Plugins/ITKImageProcessing/test/MD5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,50 @@ documentation and/or software.
///////////////////////////////////////////////

// F, G, H and I are basic MD5 functions.
inline MD5::uint4 MD5::F(uint4 x, uint4 y, uint4 z)
MD5::uint4 MD5::F(uint4 x, uint4 y, uint4 z)
{
return ((x & y) | (~x & z));
}

inline MD5::uint4 MD5::G(uint4 x, uint4 y, uint4 z)
MD5::uint4 MD5::G(uint4 x, uint4 y, uint4 z)
{
return ((x & z) | (y & ~z));
}

inline MD5::uint4 MD5::H(uint4 x, uint4 y, uint4 z)
MD5::uint4 MD5::H(uint4 x, uint4 y, uint4 z)
{
return x ^ y ^ z;
}

inline MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z)
MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z)
{
return y ^ (x | ~z);
}

// rotate_left rotates x left n bits.
inline MD5::uint4 MD5::rotate_left(uint4 x, int n)
MD5::uint4 MD5::rotate_left(uint4 x, int n)
{
return (x << n) | (x >> (32 - n));
}

// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
// Rotation is separate from addition to prevent recomputation.
inline void MD5::FF(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
void MD5::FF(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
{
a = rotate_left(a + F(b, c, d) + x + ac, s) + b;
}

inline void MD5::GG(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
void MD5::GG(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
{
a = rotate_left(a + G(b, c, d) + x + ac, s) + b;
}

inline void MD5::HH(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
void MD5::HH(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
{
a = rotate_left(a + H(b, c, d) + x + ac, s) + b;
}

inline void MD5::II(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
void MD5::II(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac)
{
a = rotate_left(a + I(b, c, d) + x + ac, s) + b;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "simplnx/DataStructure/Geometry/ImageGeom.hpp"
#include "simplnx/DataStructure/StringArray.hpp"
#include "simplnx/Filter/IFilter.hpp"
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/ChoicesParameter.hpp"
#include "simplnx/Parameters/VectorParameter.hpp"

Expand All @@ -21,41 +20,23 @@
#include "EbsdLib/IO/TSL/AngFields.h"
#include "EbsdLib/IO/TSL/H5AngVolumeReader.h"

namespace RotateSampleRefFrame
namespace
{
// Parameter Keys
static inline constexpr nx::core::StringLiteral k_RotationRepresentation_Key = "rotation_representation_index";
static inline constexpr nx::core::StringLiteral k_RotationAxisAngle_Key = "rotation_axis_angle";
static inline constexpr nx::core::StringLiteral k_RotationMatrix_Key = "rotation_matrix";
static inline constexpr nx::core::StringLiteral k_SelectedImageGeometryPath_Key = "input_image_geometry_path";
static inline constexpr nx::core::StringLiteral k_CreatedImageGeometryPath_Key = "output_image_geometry_path";
static inline constexpr nx::core::StringLiteral k_RotateSliceBySlice_Key = "rotate_slice_by_slice";
static inline constexpr nx::core::StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry";

// static inline constexpr nx::core::StringLiteral k_RotatedGeometryName = ".RotatedGeometry";
constexpr nx::core::StringLiteral k_RotationRepresentation_Key = "rotation_representation_index";
constexpr nx::core::StringLiteral k_RotationAxisAngle_Key = "rotation_axis_angle";
constexpr nx::core::StringLiteral k_SelectedImageGeometryPath_Key = "input_image_geometry_path";
constexpr nx::core::StringLiteral k_CreatedImageGeometryPath_Key = "output_image_geometry_path";
constexpr nx::core::StringLiteral k_RotateSliceBySlice_Key = "rotate_slice_by_slice";
constexpr nx::core::StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry";
// constexpr nx::core::StringLiteral k_RotatedGeometryName = ".RotatedGeometry";

enum class RotationRepresentation : uint64_t
{
AxisAngle = 0,
RotationMatrix = 1
};

} // namespace RotateSampleRefFrame

namespace RenameDataObjectFilter
{
static inline constexpr nx::core::StringLiteral k_DataObject_Key = "data_object";
static inline constexpr nx::core::StringLiteral k_NewName_Key = "new_name";
} // namespace RenameDataObjectFilter

namespace DeleteDataFilter
{
static inline constexpr nx::core::StringLiteral k_DataPath_Key = "removed_data_path";
}

namespace
{

/**
* @brief loadInfo Reads the values for the phase type, crystal structure
* and precipitate fractions from the EBSD file.
Expand All @@ -72,7 +53,7 @@ nx::core::Result<> LoadInfo(const nx::core::ReadH5EbsdInputValues* mInputValues,
reader->setSliceEnd(mInputValues->endSlice);

std::vector<typename EbsdPhase::Pointer> phases = reader->getPhases();
if(phases.size() == 0)
if(phases.empty())
{
return {nx::core::MakeErrorResult(-50027, fmt::format("Error reading phase information from file '{}'.", mInputValues->inputFilePath))};
}
Expand All @@ -83,16 +64,16 @@ nx::core::Result<> LoadInfo(const nx::core::ReadH5EbsdInputValues* mInputValues,
nx::core::DataPath cellEnsembleMatrixPath = mInputValues->cellEnsembleMatrixPath;

nx::core::DataPath xtalDataPath = cellEnsembleMatrixPath.createChildPath(EbsdLib::EnsembleData::CrystalStructures);
nx::core::UInt32Array& xtalData = mDataStructure.getDataRefAs<nx::core::UInt32Array>(xtalDataPath);
auto& xtalData = mDataStructure.getDataRefAs<nx::core::UInt32Array>(xtalDataPath);
xtalData.getIDataStore()->resizeTuples(tDims);

nx::core::DataPath latticeDataPath = cellEnsembleMatrixPath.createChildPath(EbsdLib::EnsembleData::LatticeConstants);
nx::core::Float32Array& latticData = mDataStructure.getDataRefAs<nx::core::Float32Array>(latticeDataPath);
auto& latticData = mDataStructure.getDataRefAs<nx::core::Float32Array>(latticeDataPath);
latticData.getIDataStore()->resizeTuples(tDims);

// Reshape the Material Names here also.
nx::core::DataPath matNamesDataath = cellEnsembleMatrixPath.createChildPath(EbsdLib::EnsembleData::MaterialName);
nx::core::StringArray& matNameData = mDataStructure.getDataRefAs<nx::core::StringArray>(matNamesDataath);
auto& matNameData = mDataStructure.getDataRefAs<nx::core::StringArray>(matNamesDataath);
matNameData.resizeTuples(tDims);

// Initialize the zero'th element to unknowns. The other elements will
Expand Down Expand Up @@ -126,7 +107,7 @@ nx::core::Result<> LoadInfo(const nx::core::ReadH5EbsdInputValues* mInputValues,

template <typename H5EbsdReaderType, typename T>
void CopyData(nx::core::DataStructure& dataStructure, H5EbsdReaderType* ebsdReader, const std::vector<std::string>& arrayNames, std::set<std::string> selectedArrayNames,
nx::core::DataPath cellAttributeMatrixPath, size_t totalPoints)
const nx::core::DataPath& cellAttributeMatrixPath, size_t totalPoints)
{
using DataArrayType = nx::core::DataArray<T>;
for(const auto& arrayName : arrayNames)
Expand All @@ -135,7 +116,7 @@ void CopyData(nx::core::DataStructure& dataStructure, H5EbsdReaderType* ebsdRead
{
T* source = reinterpret_cast<T*>(ebsdReader->getPointerByName(arrayName));
nx::core::DataPath dataPath = cellAttributeMatrixPath.createChildPath(arrayName); // get the data from the DataStructure
DataArrayType& destination = dataStructure.getDataRefAs<DataArrayType>(dataPath);
auto& destination = dataStructure.getDataRefAs<DataArrayType>(dataPath);
for(size_t tupleIndex = 0; tupleIndex < totalPoints; tupleIndex++)
{
destination[tupleIndex] = source[tupleIndex];
Expand Down Expand Up @@ -209,7 +190,7 @@ nx::core::Result<> LoadEbsdData(const nx::core::ReadH5EbsdInputValues* mInputVal
// Get the Crystal Structure data which should have already been read from the file and copied to the array
nx::core::DataPath cellEnsembleMatrixPath = mInputValues->cellEnsembleMatrixPath;
nx::core::DataPath xtalDataPath = cellEnsembleMatrixPath.createChildPath(EbsdLib::EnsembleData::CrystalStructures);
nx::core::UInt32Array& xtalData = dataStructure.getDataRefAs<nx::core::UInt32Array>(xtalDataPath);
auto& xtalData = dataStructure.getDataRefAs<nx::core::UInt32Array>(xtalDataPath);

// Copy the Phase Values from the EBSDReader to the DataStructure
auto* phasePtr = reinterpret_cast<int32_t*>(ebsdReader->getPointerByName(eulerNames[3])); // get the phase data from the EbsdReader
Expand Down Expand Up @@ -285,8 +266,6 @@ ReadH5Ebsd::~ReadH5Ebsd() noexcept = default;
// -----------------------------------------------------------------------------
Result<> ReadH5Ebsd::operator()()
{
using FloatVec3Type = std::array<float, 3>;

// Get the Size and Spacing of the Volume
H5EbsdVolumeInfo::Pointer volumeInfoReader = H5EbsdVolumeInfo::New();
volumeInfoReader->setFileName(m_InputValues->inputFilePath);
Expand Down Expand Up @@ -397,13 +376,12 @@ Result<> ReadH5Ebsd::operator()()
}
Arguments args;

args.insertOrAssign(RotateSampleRefFrame::k_SelectedImageGeometryPath_Key, std::make_any<DataPath>(m_InputValues->dataContainerPath));
args.insertOrAssign(RotateSampleRefFrame::k_RemoveOriginalGeometry_Key, std::make_any<bool>(true));
args.insertOrAssign(::k_SelectedImageGeometryPath_Key, std::make_any<DataPath>(m_InputValues->dataContainerPath));
args.insertOrAssign(::k_RemoveOriginalGeometry_Key, std::make_any<bool>(true));

args.insertOrAssign(RotateSampleRefFrame::k_RotationRepresentation_Key, std::make_any<ChoicesParameter::ValueType>(to_underlying(RotateSampleRefFrame::RotationRepresentation::AxisAngle)));
args.insertOrAssign(RotateSampleRefFrame::k_RotationAxisAngle_Key,
std::make_any<VectorFloat32Parameter::ValueType>({sampleTransAxis[0], sampleTransAxis[1], sampleTransAxis[2], sampleTransAngle}));
args.insertOrAssign(RotateSampleRefFrame::k_RotateSliceBySlice_Key, std::make_any<bool>(true));
args.insertOrAssign(::k_RotationRepresentation_Key, std::make_any<ChoicesParameter::ValueType>(to_underlying(::RotationRepresentation::AxisAngle)));
args.insertOrAssign(::k_RotationAxisAngle_Key, std::make_any<VectorFloat32Parameter::ValueType>({sampleTransAxis[0], sampleTransAxis[1], sampleTransAxis[2], sampleTransAngle}));
args.insertOrAssign(::k_RotateSliceBySlice_Key, std::make_any<bool>(true));

// Preflight the filter and check result
m_MessageHandler(nx::core::IFilter::Message{IFilter::Message::Type::Info, fmt::format("Preflighting {}...", filter->humanName())});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ using namespace nx::core;

namespace
{
inline constexpr int32 k_MissingGeomError = -6800;
inline constexpr int32 k_MissingInputArray = -6801;
inline constexpr int32 k_IncorrectInputArray = -6802;
inline constexpr int32 k_InvalidNumTuples = -6803;
inline constexpr int32 k_InconsistentTupleCount = -6809;
constexpr int32 k_MissingGeomError = -6800;
constexpr int32 k_MissingInputArray = -6801;
constexpr int32 k_IncorrectInputArray = -6802;
constexpr int32 k_InvalidNumTuples = -6803;
constexpr int32 k_InconsistentTupleCount = -6809;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace
using FeatureIdsArrayType = Int32Array;
using GoodVoxelsArrayType = BoolArray;

inline constexpr int32 k_IncorrectInputArray = -7000;
inline constexpr int32 k_MissingInputArray = -7001;
inline constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -7002;
constexpr int32 k_IncorrectInputArray = -7000;
constexpr int32 k_MissingInputArray = -7001;
constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -7002;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace
using FeatureIdsArrayType = Int32Array;
using GoodVoxelsArrayType = BoolArray;

inline constexpr int32 k_MissingGeomError = -71440;
inline constexpr int32 k_IncorrectInputArray = -71441;
inline constexpr int32 k_MissingInputArray = -71442;
inline constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -71443;
constexpr int32 k_MissingGeomError = -71440;
constexpr int32 k_IncorrectInputArray = -71441;
constexpr int32 k_MissingInputArray = -71442;
constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -71443;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using namespace nx::core;

namespace
{
inline constexpr int32 k_IncorrectInputArray = -7100;
inline constexpr int32 k_MissingInputArray = -7101;
constexpr int32 k_IncorrectInputArray = -7100;
constexpr int32 k_MissingInputArray = -7101;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace
{
const ChoicesParameter::Choices k_Choices = {"To Scalar Vector ( w, [x, y, z] )", "To Vector Scalar ( [x, y, z], w )"};

inline constexpr int32 k_IncorrectInputArray = -7000;
inline constexpr int32 k_MissingInputArray = -7001;
constexpr int32 k_IncorrectInputArray = -7000;
constexpr int32 k_MissingInputArray = -7001;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ using namespace nx::core;

namespace
{
inline constexpr int32 k_MissingGeomError = -440;
inline constexpr int32 k_IncorrectInputArray = -600;
inline constexpr int32 k_MissingInputArray = -601;
inline constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -602;
constexpr int32 k_MissingGeomError = -440;
constexpr int32 k_IncorrectInputArray = -600;
constexpr int32 k_MissingInputArray = -601;
constexpr int32 k_MissingOrIncorrectGoodVoxelsArray = -602;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ using namespace nx::core;

namespace
{
inline constexpr int32 k_MissingGeomError = -580090;
inline constexpr int32 k_MissingInputArray = -580091;
inline constexpr int32 k_IncorrectInputArray = -580092;
inline constexpr int32 k_InvalidNumTuples = -580093;
constexpr int32 k_MissingGeomError = -580090;
constexpr int32 k_MissingInputArray = -580091;
constexpr int32 k_IncorrectInputArray = -580092;
constexpr int32 k_InvalidNumTuples = -580093;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
using namespace nx::core;
namespace
{
inline constexpr int32 k_IncorrectInputArray = -7300;
inline constexpr int32 k_MissingInputArray = -7301;
constexpr int32 k_IncorrectInputArray = -7300;
constexpr int32 k_MissingInputArray = -7301;
} // namespace

namespace nx::core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ using namespace nx::core::UnitTest;

namespace
{
inline constexpr StringLiteral k_FaceIPFColors("SurfaceMeshFaceIPFColors");
inline constexpr StringLiteral k_NXFaceIPFColors("NXFaceIPFColors");
constexpr StringLiteral k_FaceIPFColors("SurfaceMeshFaceIPFColors");
constexpr StringLiteral k_NXFaceIPFColors("NXFaceIPFColors");

DataPath smallIn100Group({nx::core::Constants::k_SmallIN100});
DataPath featureDataPath = smallIn100Group.createChildPath(nx::core::Constants::k_Grain_Data);
Expand Down
Loading
Loading