diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.cpp index e091abcc97..9b38f1e6b1 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.cpp @@ -84,35 +84,50 @@ Result<> CombineStlFiles::operator()() DataStructure tempDataStructure; std::vector paths; const std::string ext(".stl"); + // Just count up the stl files in the directory + size_t index = 0; for(const auto& entry : std::filesystem::directory_iterator{m_InputValues->StlFilesPath}) { - if(fs::is_regular_file(entry) && entry.path().extension() == ext) - paths.emplace_back(entry.path().filename()); + if(fs::is_regular_file(entry) && StringUtilities::toLower(entry.path().extension().string()) == ext) + { + paths.emplace_back(entry); + } } - int32 currentIndex = 0; - for(const auto& dirEntry : std::filesystem::directory_iterator{m_InputValues->StlFilesPath}) + // Sort the paths for something sort of reasonable. + std::sort(paths.begin(), paths.end()); + + auto pCellFeatureAttributeMatrixPath = m_InputValues->TriangleDataContainerName.createChildPath(m_InputValues->CellFeatureAttributeMatrixName); + auto activeArrayPath = pCellFeatureAttributeMatrixPath.createChildPath(m_InputValues->ActiveArrayName); + auto fileListPath = pCellFeatureAttributeMatrixPath.createChildPath(m_InputValues->FileListArrayName); + + auto activeArray = m_DataStructure.getDataRefAs(activeArrayPath); + activeArray[0] = 0; + auto fileListStrArray = m_DataStructure.getDataRefAs(fileListPath); + + int32 currentIndex = 1; + for(const auto& filePath : paths) { + std::string stlFilePath = filePath.string(); if(getCancel()) { return {}; } - const fs::path& stlFilePath = dirEntry.path(); - m_MessageHandler(IFilter::Message::Type::Info, fmt::format("({}/{}) Reading {}", currentIndex++, paths.size(), stlFilePath.string())); - - if(fs::is_regular_file(stlFilePath) && StringUtilities::toLower(stlFilePath.extension().string()) == ".stl") + fileListStrArray[currentIndex] = stlFilePath; + activeArray[currentIndex] = 1; + m_MessageHandler(IFilter::Message::Type::Info, fmt::format("({}/{}) Reading {}", currentIndex, paths.size(), stlFilePath)); + currentIndex++; + + ReadStlFileFilter stlFileReader; + Arguments args; + args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(stlFilePath)); + args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(DataPath({filePath.stem().string()}))); + auto executeResult = stlFileReader.execute(tempDataStructure, args); + if(executeResult.result.invalid()) { - ReadStlFileFilter stlFileReader; - Arguments args; - args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(stlFilePath)); - args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(DataPath({stlFilePath.stem().string()}))); - auto executeResult = stlFileReader.execute(tempDataStructure, args); - if(executeResult.result.invalid()) - { - return executeResult.result; - } + return executeResult.result; } } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.hpp index 769e00c586..5c55bb0c5b 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CombineStlFiles.hpp @@ -5,6 +5,7 @@ #include "simplnx/DataStructure/DataPath.hpp" #include "simplnx/DataStructure/DataStructure.hpp" #include "simplnx/Filter/IFilter.hpp" +#include "simplnx/Parameters/DataObjectNameParameter.hpp" #include "simplnx/Parameters/FileSystemPathParameter.hpp" #include "simplnx/Parameters/StringParameter.hpp" @@ -21,6 +22,9 @@ struct SIMPLNXCORE_EXPORT CombineStlFilesInputValues bool LabelFaces; DataPath VertexFileIndexArrayPath; bool LabelVertices; + DataObjectNameParameter::ValueType CellFeatureAttributeMatrixName; + DataObjectNameParameter::ValueType ActiveArrayName; + DataObjectNameParameter::ValueType FileListArrayName; }; /** diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.cpp index 31735c756d..0c3de7c2e5 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.cpp @@ -5,7 +5,9 @@ #include "simplnx/DataStructure/DataPath.hpp" #include "simplnx/DataStructure/Geometry/TriangleGeom.hpp" #include "simplnx/Filter/Actions/CreateArrayAction.hpp" +#include "simplnx/Filter/Actions/CreateAttributeMatrixAction.hpp" #include "simplnx/Filter/Actions/CreateGeometry2DAction.hpp" +#include "simplnx/Filter/Actions/CreateStringArrayAction.hpp" #include "simplnx/Parameters/ArrayCreationParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/DataGroupCreationParameter.hpp" @@ -83,6 +85,14 @@ Parameters CombineStlFilesFilter::parameters() const params.insert(std::make_unique(k_VertexAttributeMatrixName_Key, "Vertex Attribute Matrix", "The name of the vertex level attribute matrix to be created with the geometry", TriangleGeom::k_VertexDataName)); + params.insertSeparator(Parameters::Separator{"Output Feature Data"}); + params.insert(std::make_unique(k_CellFeatureAttributeMatrixName_Key, "Feature Attribute Matrix", "The name of the created feature attribute matrix", "Cell Feature Data")); + params.insert(std::make_unique( + k_ActiveArrayName_Key, "Active", + "Specifies if the Feature is still in the sample (true if the Feature is in the sample and false if it is not). At the end of the Filter, all Features will be Active", "Active")); + params.insert( + std::make_unique(k_FileListName_Key, "File List Array", "The path to a String array that will store the input paths of each file that was read.", "STL File List")); + return params; } @@ -130,6 +140,7 @@ IFilter::PreflightResult CombineStlFilesFilter::preflightImpl(const DataStructur CreateTriangleGeometryAction::k_DefaultVerticesName, CreateTriangleGeometryAction::k_DefaultFacesName); resultOutputActions.value().appendAction(std::move(createTriangleGeometryAction)); } + DataPath faceAttributeMatrixDataPath = pTriangleDataContainerNameValue.createChildPath(pFaceAttributeMatrixNameValue); // Create the Triangle Normals path { @@ -154,6 +165,25 @@ IFilter::PreflightResult CombineStlFilesFilter::preflightImpl(const DataStructur resultOutputActions.value().appendAction(std::move(createArrayAction)); } + { + auto pCellFeatureAttributeMatrixName = filterArgs.value(k_CellFeatureAttributeMatrixName_Key); + auto pActiveArrayName = filterArgs.value(k_ActiveArrayName_Key); + auto fileListArrayName = filterArgs.value(k_FileListName_Key); + + auto pCellFeatureAttributeMatrixPath = pTriangleDataContainerNameValue.createChildPath(pCellFeatureAttributeMatrixName); + auto activeArrayPath = pCellFeatureAttributeMatrixPath.createChildPath(pActiveArrayName); + auto fileListPath = pCellFeatureAttributeMatrixPath.createChildPath(fileListArrayName); + + // Create output feature data structure items + auto createFeatureGroupAction = std::make_unique(pCellFeatureAttributeMatrixPath, std::vector{stlFiles.size() + 1}); + auto createActiveAction = std::make_unique(DataType::uint8, std::vector{stlFiles.size() + 1}, std::vector{1}, activeArrayPath); + auto createFileListAction = std::make_unique(std::vector{stlFiles.size() + 1}, fileListPath); + + resultOutputActions.value().appendAction(std::move(createFeatureGroupAction)); + resultOutputActions.value().appendAction(std::move(createActiveAction)); + resultOutputActions.value().appendAction(std::move(createFileListAction)); + } + return {std::move(resultOutputActions), std::move(preflightUpdatedValues)}; } @@ -176,6 +206,10 @@ Result<> CombineStlFilesFilter::executeImpl(DataStructure& dataStructure, const inputValues.LabelVertices = filterArgs.value(k_LabelVertices_Key); inputValues.VertexFileIndexArrayPath = DataPath({inputValues.TriangleDataContainerName.getTargetName(), pVertexAttributeMatrixNameValue, filterArgs.value(k_VertexLabelName_Key)}); + inputValues.CellFeatureAttributeMatrixName = filterArgs.value(k_CellFeatureAttributeMatrixName_Key); + inputValues.ActiveArrayName = filterArgs.value(k_ActiveArrayName_Key); + inputValues.FileListArrayName = filterArgs.value(k_FileListName_Key); + return CombineStlFiles(dataStructure, messageHandler, shouldCancel, &inputValues)(); } diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.hpp index 495a9a1aa1..5782be98fd 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CombineStlFilesFilter.hpp @@ -33,6 +33,9 @@ class SIMPLNXCORE_EXPORT CombineStlFilesFilter : public IFilter static inline constexpr StringLiteral k_FaceLabelName_Key = "face_label_name"; static inline constexpr StringLiteral k_LabelVertices_Key = "label_vertices"; static inline constexpr StringLiteral k_VertexLabelName_Key = "vertex_label_name"; + static inline constexpr StringLiteral k_CellFeatureAttributeMatrixName_Key = "cell_feature_attribute_matrix_name"; + static inline constexpr StringLiteral k_ActiveArrayName_Key = "active_array_name"; + static inline constexpr StringLiteral k_FileListName_Key = "output_file_list_path"; /** * @brief Reads SIMPL json and converts it simplnx Arguments.