Skip to content

Commit

Permalink
ENH: Combine STL Files messaging. Change File Index type to Int32
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Jul 22, 2024
1 parent c3be139 commit 250f1ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const std::atomic_bool& CombineStlFiles::getCancel()
Result<> CombineStlFiles::operator()()
{
DataStructure tempDataStructure;
std::vector<fs::path> paths;
const std::string ext(".stl");
// Just count up the stl files in the directory
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());
}

int32 currentIndex = 0;
for(const auto& dirEntry : std::filesystem::directory_iterator{m_InputValues->StlFilesPath})
{
if(getCancel())
Expand All @@ -90,6 +100,8 @@ Result<> CombineStlFiles::operator()()
}

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")
{
ReadStlFileFilter stlFileReader;
Expand Down Expand Up @@ -144,6 +156,8 @@ Result<> CombineStlFiles::operator()()
usize faceLabelOffset = 0;
usize vertexLabelOffset = 0;

m_MessageHandler(IFilter::Message::Type::Info, fmt::format("Moving final triangle geometry data..."));

// Loop over each temp geometry and copy the data into the destination geometry
for(auto* currentGeometry : stlGeometries)
{
Expand All @@ -167,23 +181,15 @@ Result<> CombineStlFiles::operator()()

if(m_InputValues->LabelFaces)
{
auto& faceLabels = m_DataStructure.getDataRefAs<UInt32Array>(m_InputValues->FaceFileIndexArrayPath);
// for(usize tuple = faceLabelOffset; tuple < faceLabelOffset + currentGeomNumTriangles; tuple++)
// {
// faceLabels[tuple] = fileIndex;
// }
auto& faceLabels = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->FaceFileIndexArrayPath);
std::fill(faceLabels.begin() + faceLabelOffset, faceLabels.begin() + faceLabelOffset + currentGeomNumTriangles, fileIndex);
}

faceLabelOffset += currentGeomNumTriangles;

if(m_InputValues->LabelVertices)
{
auto& vertexLabels = m_DataStructure.getDataRefAs<UInt32Array>(m_InputValues->VertexFileIndexArrayPath);
// for(usize tuple = vertexLabelOffset; tuple < vertexLabelOffset + currentGeomNumVertices; tuple++)
// {
// vertexLabels[tuple] = fileIndex;
// }
auto& vertexLabels = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->VertexFileIndexArrayPath);
std::fill(vertexLabels.begin() + vertexLabelOffset, vertexLabels.begin() + vertexLabelOffset + currentGeomNumVertices, fileIndex);
}
vertexLabelOffset += currentGeomNumVertices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ Parameters CombineStlFilesFilter::parameters() const
params.insert(std::make_unique<FileSystemPathParameter>(k_StlFilesPath_Key, "Path to STL Files", "The path to the folder containing all the STL files to be combined", fs::path(""),
FileSystemPathParameter::ExtensionsType{}, FileSystemPathParameter::PathType::InputDir));

params.insertLinkableParameter(std::make_unique<BoolParameter>(k_LabelFaces_Key, "Label Triangles", "When true, each triangle will get an index associated with the index of the STL file", true));
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceLabelName_Key, "Created Face Labels", "The name of the face labels data array", "FileIndex"));
params.insertLinkableParameter(
std::make_unique<BoolParameter>(k_LabelFaces_Key, "Generate Triangle Part Numbers", "When true, each triangle will get an index associated with the index of the STL file", true));
params.insert(std::make_unique<DataObjectNameParameter>(k_FaceLabelName_Key, "Created Part Number Array", "The name of the part numbers data array", "Part Number"));
params.linkParameters(k_LabelFaces_Key, k_FaceLabelName_Key, true);

params.insertLinkableParameter(std::make_unique<BoolParameter>(k_LabelVertices_Key, "Label Vertices", "When true, each vertex will get an index associated with the index of the STL file", true));
params.insert(std::make_unique<DataObjectNameParameter>(k_VertexLabelName_Key, "Created Vertex Labels", "The name of the vertex labels data array", "FileIndex"));
params.insertLinkableParameter(
std::make_unique<BoolParameter>(k_LabelVertices_Key, "Generate Vertex Part Numbers", "When true, each vertex will get an index associated with the index of the STL file", true));
params.insert(std::make_unique<DataObjectNameParameter>(k_VertexLabelName_Key, "Created Part Number Labels", "The name of the part numbers data array", "Part Number"));
params.linkParameters(k_LabelVertices_Key, k_VertexLabelName_Key, true);

params.insertSeparator(Parameters::Separator{"Output Geometry"});
Expand Down Expand Up @@ -140,15 +142,15 @@ IFilter::PreflightResult CombineStlFilesFilter::preflightImpl(const DataStructur
if(createFaceLabels)
{
auto facePath = faceAttributeMatrixDataPath.createChildPath(faceLabelsName);
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::uint32, std::vector<usize>{1}, std::vector<usize>{1}, facePath);
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::int32, std::vector<usize>{1}, std::vector<usize>{1}, facePath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}

// If the user wants to label the vertices
if(createVertexLabels)
{
auto vertexPath = pTriangleDataContainerNameValue.createChildPath(pVertexAttributeMatrixNameValue).createChildPath(vertexLabelsName);
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::uint32, std::vector<usize>{1}, std::vector<usize>{1}, vertexPath);
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::int32, std::vector<usize>{1}, std::vector<usize>{1}, vertexPath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}

Expand Down

0 comments on commit 250f1ad

Please sign in to comment.