Skip to content

Commit

Permalink
ENH: Changed STLFileReader filter to allow user setting of FaceNormal…
Browse files Browse the repository at this point in the history
…s. (#680)

* ENH: Changed STLFileReader filter to allow user setting of FaceNormals.

* remove ability to set the SharedVertexList and SharedTriangleList names. Those
should stay constant where possible.
* The parameter key values also changed which may mess up some pipelines and the
python bindings.

---------

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Sep 2, 2023
1 parent b8a3d45 commit e51d69f
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"pipeline": [
{
"args": {
"geometry_data_path": "Blade",
"triangle_geometry_name": "Blade",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/ASTMD638_specimen.stl"
Expand All @@ -19,7 +19,7 @@
},
{
"args": {
"geometry_data_path": "Blade [Rotation]",
"triangle_geometry_name": "Blade [Rotation]",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/ASTMD638_specimen.stl"
Expand Down Expand Up @@ -90,7 +90,7 @@
},
{
"args": {
"geometry_data_path": "Blade [Translation]",
"triangle_geometry_name": "Blade [Translation]",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/ASTMD638_specimen.stl"
Expand Down Expand Up @@ -161,7 +161,7 @@
},
{
"args": {
"geometry_data_path": "Blade [Scale]",
"triangle_geometry_name": "Blade [Scale]",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/ASTMD638_specimen.stl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"pipeline": [
{
"args": {
"geometry_data_path": "[Triangle Geometry]",
"triangle_geometry_name": "[Triangle Geometry]",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/Cylinder.stl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"pipeline": [
{
"args": {
"geometry_data_path": "[Triangle Geometry]",
"triangle_geometry_name": "[Triangle Geometry]",
"scale_factor": 1.0,
"scale_output": false,
"stl_file_path": "Data/STL_Models/ASTMD638_specimen.stl"
Expand All @@ -31,7 +31,7 @@
},
{
"args": {
"surface_mesh_triangle_normals_array_path": "Face Normals",
"surface_mesh_triangle_normals_array_path": "Face Normals (Calculated)",
"tri_geometry_data_path": "[Triangle Geometry]"
},
"comments": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Result<> CombineStlFiles::operator()()
StlFileReaderFilter stlFileReader;
Arguments args;
args.insertOrAssign(StlFileReaderFilter::k_StlFilePath_Key, std::make_any<FileSystemPathParameter::ValueType>(stlFilePath));
args.insertOrAssign(StlFileReaderFilter::k_GeometryDataPath_Key, std::make_any<DataPath>(DataPath({stlFilePath.stem().string()})));
args.insertOrAssign(StlFileReaderFilter::k_TriangleGeometryName_Key, std::make_any<DataPath>(DataPath({stlFilePath.stem().string()})));
auto executeResult = stlFileReader.execute(tempDataStructure, args);
if(executeResult.result.invalid())
{
Expand Down Expand Up @@ -151,7 +151,7 @@ Result<> CombineStlFiles::operator()()
}
triCounter += geom->getNumberOfVertices();
INodeGeometry0D::SharedVertexList& curVertices = geom->getVerticesRef();
auto& curFaceNormals = tempDataStructure.getDataRefAs<Float64Array>(geom->getFaceAttributeMatrixDataPath().createChildPath(StlFileReaderFilter::k_FaceNormals));
auto& curFaceNormals = tempDataStructure.getDataRefAs<Float64Array>(geom->getFaceAttributeMatrixDataPath().createChildPath("Face Normals"));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ Parameters FeatureFaceCurvatureFilter::parameters() const
params.insert(std::make_unique<ArraySelectionParameter>(k_FaceLabels_Key, "Face Labels", "", DataPath(), ArraySelectionParameter::AllowedTypes{DataType::int32},
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{2}}));
params.insert(std::make_unique<ArraySelectionParameter>(k_FeatureFaceIds_Key, "Feature Face IDs", "", DataPath(), ArraySelectionParameter::AllowedTypes{DataType::int32},
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{{1}}}));
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{1}}));
params.insert(std::make_unique<ArraySelectionParameter>(k_FaceNormals_Key, "Feature Normals", "", DataPath(), ArraySelectionParameter::AllowedTypes{DataType::float64},
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{{3}}}));
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{3}}));
params.insert(std::make_unique<ArraySelectionParameter>(k_FaceCentroids_Key, "Face Centroids", "", DataPath(), ArraySelectionParameter::AllowedTypes{DataType::float64},
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{{3}}}));
ArraySelectionParameter::AllowedComponentShapes{IArray::ShapeType{3}}));

params.insert(std::make_unique<ArrayCreationParameter>(k_PrincipalCurvature1_Key, "Principal Curvature 1", "", DataPath()));
params.insert(std::make_unique<ArrayCreationParameter>(k_PrincipalCurvature2_Key, "Principal Curvature 2", "", DataPath()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ Parameters QuickSurfaceMeshFilter::parameters() const
params.insertSeparator(Parameters::Separator{"Created Vertex Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_VertexDataGroupName_Key, "Vertex Data [AttributeMatrix]",
"The complete path to the DataGroup where the Vertex Data of the Triangle Geometry will be created", INodeGeometry0D::k_VertexDataName));
params.insert(std::make_unique<DataObjectNameParameter>(k_NodeTypesArrayName_Key, "NodeType", "The complete path to the Array specifying the type of node in the Triangle Geometry", "NodeTypes"));
params.insert(std::make_unique<DataObjectNameParameter>(k_NodeTypesArrayName_Key, "NodeType", "The name of the Array specifying the type of node in the Triangle Geometry", "NodeTypes"));

params.insertSeparator(Parameters::Separator{"Created Face Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceDataGroupName_Key, "Face Data [AttributeMatrix]",
"The complete path to the DataGroup where the Face Data of the Triangle Geometry will be created", INodeGeometry2D::k_FaceDataName));
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceLabelsArrayName_Key, "Face Labels",
"The complete path to the Array specifying which Features are on either side of each Face in the Triangle Geometry", "FaceLabels"));
"The name of the Array specifying which Features are on either side of each Face in the Triangle Geometry", "FaceLabels"));
params.insertSeparator(Parameters::Separator{"Created Face Feature Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceFeatureAttributeMatrixName_Key, "Face Feature Data [AttributeMatrix]",
"The complete path to the DataGroup where the Feature Data will be stored.", INodeGeometry1D::k_FaceFeatureAttributeMatrix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "complex/Filter/Actions/CreateGeometry2DAction.hpp"
#include "complex/Parameters/BoolParameter.hpp"
#include "complex/Parameters/DataGroupCreationParameter.hpp"
#include "complex/Parameters/DataObjectNameParameter.hpp"
#include "complex/Parameters/FileSystemPathParameter.hpp"
#include "complex/Parameters/NumberParameter.hpp"
#include "complex/Parameters/StringParameter.hpp"
Expand Down Expand Up @@ -65,18 +66,23 @@ Parameters StlFileReaderFilter::parameters() const
params.insert(std::make_unique<FileSystemPathParameter>(k_StlFilePath_Key, "STL File", "Input STL File", fs::path(""), FileSystemPathParameter::ExtensionsType{".stl"},
FileSystemPathParameter::PathType::InputFile));

params.insertSeparator(Parameters::Separator{"Created Objects"});
params.insertSeparator(Parameters::Separator{"Created Triangle Geometry"});
params.insert(
std::make_unique<DataGroupCreationParameter>(k_TriangleGeometryName_Key, "Created Triangle Geometry", "The name of the created Triangle Geometry", DataPath({"TriangleDataContainer"})));

params.insert(std::make_unique<DataGroupCreationParameter>(k_GeometryDataPath_Key, "Geometry Name [Data Group]", "The complete path to the DataGroup containing the created Geometry data",
DataPath({"[Triangle Geometry]"})));
params.insertSeparator(Parameters::Separator{"Created Vertex Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_VertexAttributeMatrix_Key, "Vertex Data [AttributeMatrix]",
"The name of the AttributeMatrix where the Vertex Data of the Triangle Geometry will be created", INodeGeometry0D::k_VertexDataName));

params.insert(std::make_unique<StringParameter>(k_VertexMatrix_Key, "Vertex Matrix Name", "Name of the created Vertex Attribute Matrix", INodeGeometry0D::k_VertexDataName));
params.insert(std::make_unique<StringParameter>(k_FaceMatrix_Key, "Face Matrix Name", "Name of the created Face Attribute Matrix", INodeGeometry2D::k_FaceDataName));
params.insertSeparator(Parameters::Separator{"Created Face Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceAttributeMatrix_Key, "Face Data [AttributeMatrix]",
"The name of the AttributeMatrix where the Face Data of the Triangle Geometry will be created", INodeGeometry2D::k_FaceDataName));
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceNormalsName_Key, "Face Labels", "The name of the triangle normals data array", "Face Normals"));

params.insert(std::make_unique<StringParameter>(k_SharedVertexMatrix_Key, "Shared Vertex Matrix Name", "Name of the created Shared Vertex Attribute Matrix",
CreateTriangleGeometryAction::k_DefaultVerticesName));
params.insert(
std::make_unique<StringParameter>(k_SharedFaceMatrix_Key, "Shared Face Matrix Name", "Name of the created Shared Face Attribute Matrix", CreateTriangleGeometryAction::k_DefaultFacesName));
// params.insert(std::make_unique<StringParameter>(k_SharedVertexMatrix_Key, "Shared Vertex Matrix Name", "Name of the created Shared Vertex Attribute Matrix",
// CreateTriangleGeometryAction::k_DefaultVerticesName));
// params.insert(
// std::make_unique<StringParameter>(k_SharedFaceMatrix_Key, "Shared Face Matrix Name", "Name of the created Shared Face Attribute Matrix", CreateTriangleGeometryAction::k_DefaultFacesName));

return params;
}
Expand All @@ -91,17 +97,11 @@ IFilter::UniquePointer StlFileReaderFilter::clone() const
IFilter::PreflightResult StlFileReaderFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
{
/**
* These are the values that were gathered from the UI or the pipeline file or
* otherwise passed into the filter. These are here for your convenience. If you
* do not need some of them remove them.
*/
auto pStlFilePathValue = filterArgs.value<FileSystemPathParameter::ValueType>(k_StlFilePath_Key);
auto pTriangleGeometryPath = filterArgs.value<DataPath>(k_GeometryDataPath_Key);
auto vertexMatrixName = filterArgs.value<std::string>(k_VertexMatrix_Key);
auto faceMatrixName = filterArgs.value<std::string>(k_FaceMatrix_Key);
auto sharedVertexMatrixName = filterArgs.value<std::string>(k_SharedVertexMatrix_Key);
auto sharedFaceMatrixName = filterArgs.value<std::string>(k_SharedFaceMatrix_Key);
auto pTriangleGeometryPath = filterArgs.value<DataPath>(k_TriangleGeometryName_Key);
auto vertexMatrixName = filterArgs.value<std::string>(k_VertexAttributeMatrix_Key);
auto faceMatrixName = filterArgs.value<std::string>(k_FaceAttributeMatrix_Key);
auto faceNormalsName = filterArgs.value<std::string>(k_FaceNormalsName_Key);

PreflightResult preflightResult;

Expand Down Expand Up @@ -155,9 +155,9 @@ IFilter::PreflightResult StlFileReaderFilter::preflightImpl(const DataStructure&
// past this point, we are going to scope each section so that we don't accidentally introduce bugs

// Create the Triangle Geometry action and store it
auto createTriangleGeometryAction =
std::make_unique<CreateTriangleGeometryAction>(pTriangleGeometryPath, numTriangles, 1, vertexMatrixName, faceMatrixName, sharedVertexMatrixName, sharedFaceMatrixName);
auto faceNormalsPath = createTriangleGeometryAction->getFaceDataPath().createChildPath(k_FaceNormals);
auto createTriangleGeometryAction = std::make_unique<CreateTriangleGeometryAction>(pTriangleGeometryPath, numTriangles, 1, vertexMatrixName, faceMatrixName,
CreateTriangleGeometryAction::k_DefaultVerticesName, CreateTriangleGeometryAction::k_DefaultFacesName);
auto faceNormalsPath = createTriangleGeometryAction->getFaceDataPath().createChildPath(faceNormalsName);
resultOutputActions.value().appendAction(std::move(createTriangleGeometryAction));
// Create the face Normals DataArray action and store it
auto createArrayAction = std::make_unique<CreateArrayAction>(complex::DataType::float64, std::vector<usize>{static_cast<usize>(numTriangles)}, std::vector<usize>{3}, faceNormalsPath);
Expand All @@ -175,12 +175,18 @@ Result<> StlFileReaderFilter::executeImpl(DataStructure& data, const Arguments&
const std::atomic_bool& shouldCancel) const
{
auto pStlFilePathValue = filterArgs.value<FileSystemPathParameter::ValueType>(k_StlFilePath_Key);
auto pTriangleGeometryPath = filterArgs.value<DataPath>(k_GeometryDataPath_Key);
auto pFaceDataGroupPath = pTriangleGeometryPath.createChildPath(INodeGeometry2D::k_FaceDataName);
auto pFaceNormalsPath = pFaceDataGroupPath.createChildPath(k_FaceNormals);
auto pTriangleGeometryPath = filterArgs.value<DataPath>(k_TriangleGeometryName_Key);
auto vertexMatrixName = filterArgs.value<std::string>(k_VertexAttributeMatrix_Key);
auto faceMatrixName = filterArgs.value<std::string>(k_FaceAttributeMatrix_Key);
auto faceNormalsName = filterArgs.value<std::string>(k_FaceNormalsName_Key);

auto pFaceDataGroupPath = pTriangleGeometryPath.createChildPath(faceMatrixName);

auto pFaceNormalsPath = pFaceDataGroupPath.createChildPath(faceNormalsName);

auto scaleOutput = filterArgs.value<bool>(k_ScaleOutput);
auto scaleFactor = filterArgs.value<float32>(k_ScaleFactor);

// The actual STL File Reading is placed in a separate class `StlFileReader`
Result<> result = StlFileReader(data, pStlFilePathValue, pTriangleGeometryPath, pFaceDataGroupPath, pFaceNormalsPath, scaleOutput, scaleFactor, shouldCancel)();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ class COMPLEXCORE_EXPORT StlFileReaderFilter : public IFilter
StlFileReaderFilter& operator=(StlFileReaderFilter&&) noexcept = delete;

// Parameter Keys
static inline constexpr StringLiteral k_StlFilePath_Key = "stl_file_path";
static inline constexpr StringLiteral k_GeometryDataPath_Key = "geometry_data_path";

static inline constexpr StringLiteral k_FaceGroupDataPath_Key = "face_data_path";
static inline constexpr StringLiteral k_FaceNormalsDataPath_Key = "face_normals_data_path";
static inline constexpr StringLiteral k_ScaleOutput = "scale_output";
static inline constexpr StringLiteral k_ScaleFactor = "scale_factor";
static inline constexpr StringLiteral k_VertexMatrix_Key = "vertex_matrix";
static inline constexpr StringLiteral k_FaceMatrix_Key = "face_matrix";
static inline constexpr StringLiteral k_SharedVertexMatrix_Key = "shared_vertex_matrix";
static inline constexpr StringLiteral k_SharedFaceMatrix_Key = "shared_face_matrix";
static inline constexpr StringLiteral k_StlFilePath_Key = "stl_file_path";

static inline constexpr StringLiteral k_TriangleGeometryName_Key = "triangle_geometry_name";

static inline constexpr StringLiteral k_VertexAttributeMatrix_Key = "vertex_attribute_matrix";
static inline constexpr StringLiteral k_FaceAttributeMatrix_Key = "face_attribute_matrix";

static inline constexpr StringLiteral k_FaceNormals = "FaceNormals";
static inline constexpr StringLiteral k_FaceNormalsName_Key = "face_normals_data_path";

/**
* @brief Returns the name of the filter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST_CASE("ComplexCore::ApproximatePointCloudHull: Instantiate Filter", "[Approx

// Create default Parameters for the filter.
args.insertOrAssign(StlFileReaderFilter::k_StlFilePath_Key, std::make_any<FileSystemPathParameter::ValueType>(fs::path(inputFile)));
args.insertOrAssign(StlFileReaderFilter::k_GeometryDataPath_Key, std::make_any<DataPath>(triangleGeomDataPath));
args.insertOrAssign(StlFileReaderFilter::k_TriangleGeometryName_Key, std::make_any<DataPath>(triangleGeomDataPath));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST_CASE("ComplexCore::CalculateTriangleAreasFilter", "[ComplexCore][CalculateT

// Create default Parameters for the filter.
args.insertOrAssign(StlFileReaderFilter::k_StlFilePath_Key, std::make_any<FileSystemPathParameter::ValueType>(fs::path(inputFile)));
args.insertOrAssign(StlFileReaderFilter::k_GeometryDataPath_Key, std::make_any<DataPath>(triangleGeomDataPath));
args.insertOrAssign(StlFileReaderFilter::k_TriangleGeometryName_Key, std::make_any<DataPath>(triangleGeomDataPath));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/ComplexCore/test/CombineStlFilesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST_CASE("ComplexCore::CombineStlFilesFilter: Valid Filter Execution", "[Comple
args.insertOrAssign(CombineStlFilesFilter::k_StlFilesPath_Key, std::make_any<FileSystemPathParameter::ValueType>(fs::path(inputStlDir)));
args.insertOrAssign(CombineStlFilesFilter::k_TriangleDataContainerName_Key, std::make_any<DataPath>(k_ComputedTriangleDataContainerName));
args.insertOrAssign(CombineStlFilesFilter::k_FaceAttributeMatrixName_Key, std::make_any<std::string>(k_FaceData));
args.insertOrAssign(CombineStlFilesFilter::k_FaceNormalsArrayName_Key, std::make_any<std::string>(k_FaceNormals));
args.insertOrAssign(CombineStlFilesFilter::k_FaceNormalsArrayName_Key, std::make_any<std::string>("Face Normals"));
args.insertOrAssign(CombineStlFilesFilter::k_VertexAttributeMatrixName_Key, std::make_any<std::string>(k_VertexData));

// Preflight the filter and check result
Expand All @@ -58,7 +58,7 @@ TEST_CASE("ComplexCore::CombineStlFilesFilter: Valid Filter Execution", "[Comple
REQUIRE(computedTriangleGeom.getFaceAttributeMatrix()->getShape() == exemplarTriangleGeom.getFaceAttributeMatrix()->getShape());

UnitTest::CompareArrays<float64>(dataStructure, k_ExemplarTriangleDataContainerName.createChildPath(k_FaceData).createChildPath(k_FaceNormals),
k_ComputedTriangleDataContainerName.createChildPath(k_FaceData).createChildPath(k_FaceNormals));
k_ComputedTriangleDataContainerName.createChildPath(k_FaceData).createChildPath("Face Normals"));
}

TEST_CASE("ComplexCore::CombineStlFilesFilter: InValid Filter Execution")
Expand Down
Loading

0 comments on commit e51d69f

Please sign in to comment.