Skip to content

Commit

Permalink
Store the File List as Feature Data.
Browse files Browse the repository at this point in the history
The Part Number array and the File List are linked via the Part Number Value.

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Jul 29, 2024
1 parent 5d1ccc8 commit e04b179
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,50 @@ Result<> CombineStlFiles::operator()()
DataStructure tempDataStructure;
std::vector<fs::path> 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<UInt8Array>(activeArrayPath);
activeArray[0] = 0;
auto fileListStrArray = m_DataStructure.getDataRefAs<StringArray>(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<FileSystemPathParameter::ValueType>(stlFilePath));
args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any<DataPath>(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<FileSystemPathParameter::ValueType>(stlFilePath));
args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any<DataPath>(DataPath({stlFilePath.stem().string()})));
auto executeResult = stlFileReader.execute(tempDataStructure, args);
if(executeResult.result.invalid())
{
return executeResult.result;
}
return executeResult.result;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -21,6 +22,9 @@ struct SIMPLNXCORE_EXPORT CombineStlFilesInputValues
bool LabelFaces;
DataPath VertexFileIndexArrayPath;
bool LabelVertices;
DataObjectNameParameter::ValueType CellFeatureAttributeMatrixName;
DataObjectNameParameter::ValueType ActiveArrayName;
DataObjectNameParameter::ValueType FileListArrayName;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,6 +85,14 @@ Parameters CombineStlFilesFilter::parameters() const
params.insert(std::make_unique<DataObjectNameParameter>(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<DataObjectNameParameter>(k_CellFeatureAttributeMatrixName_Key, "Feature Attribute Matrix", "The name of the created feature attribute matrix", "Cell Feature Data"));
params.insert(std::make_unique<DataObjectNameParameter>(
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<DataObjectNameParameter>(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;
}

Expand Down Expand Up @@ -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
{
Expand All @@ -154,6 +165,25 @@ IFilter::PreflightResult CombineStlFilesFilter::preflightImpl(const DataStructur
resultOutputActions.value().appendAction(std::move(createArrayAction));
}

{
auto pCellFeatureAttributeMatrixName = filterArgs.value<std::string>(k_CellFeatureAttributeMatrixName_Key);
auto pActiveArrayName = filterArgs.value<std::string>(k_ActiveArrayName_Key);
auto fileListArrayName = filterArgs.value<std::string>(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<CreateAttributeMatrixAction>(pCellFeatureAttributeMatrixPath, std::vector<usize>{stlFiles.size() + 1});
auto createActiveAction = std::make_unique<CreateArrayAction>(DataType::uint8, std::vector<usize>{stlFiles.size() + 1}, std::vector<usize>{1}, activeArrayPath);
auto createFileListAction = std::make_unique<CreateStringArrayAction>(std::vector<size_t>{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)};
}

Expand All @@ -176,6 +206,10 @@ Result<> CombineStlFilesFilter::executeImpl(DataStructure& dataStructure, const
inputValues.LabelVertices = filterArgs.value<BoolParameter::ValueType>(k_LabelVertices_Key);
inputValues.VertexFileIndexArrayPath = DataPath({inputValues.TriangleDataContainerName.getTargetName(), pVertexAttributeMatrixNameValue, filterArgs.value<std::string>(k_VertexLabelName_Key)});

inputValues.CellFeatureAttributeMatrixName = filterArgs.value<std::string>(k_CellFeatureAttributeMatrixName_Key);
inputValues.ActiveArrayName = filterArgs.value<std::string>(k_ActiveArrayName_Key);
inputValues.FileListArrayName = filterArgs.value<std::string>(k_FileListName_Key);

return CombineStlFiles(dataStructure, messageHandler, shouldCancel, &inputValues)();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e04b179

Please sign in to comment.