Skip to content

Commit

Permalink
BUG: STLFileReader/Writer - Fix crash when reading certain kinds of S…
Browse files Browse the repository at this point in the history
…TL Files. Fix output path when writing (#701)

* STLFileReader: Fix crash when all points are on a single plane.

Signed-off-by: Michael Jackson <[email protected]>
(cherry picked from commit 734fc82)

* WriteSTLFile: Ensure output path is created when executing filter.

Signed-off-by: Michael Jackson <[email protected]>
(cherry picked from commit 5e43278)
  • Loading branch information
imikejackson authored Sep 26, 2023
1 parent f77af9c commit 42bd7f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,18 @@ Result<> StlFileReader::eliminate_duplicate_nodes()
int32_t bin = 0, xBin = 0, yBin = 0, zBin = 0;
for(size_t i = 0; i < nNodes; i++)
{
xBin = static_cast<int32_t>((vertices[i * 3] - m_MinMaxCoords[0]) / stepX);
yBin = static_cast<int32_t>((vertices[i * 3 + 1] - m_MinMaxCoords[2]) / stepY);
zBin = static_cast<int32_t>((vertices[i * 3 + 2] - m_MinMaxCoords[4]) / stepZ);
if(stepX != 0.0)
{
xBin = static_cast<int32_t>((vertices[i * 3] - m_MinMaxCoords[0]) / stepX);
}
if(stepY != 0.0)
{
yBin = static_cast<int32_t>((vertices[i * 3 + 1] - m_MinMaxCoords[2]) / stepY);
}
if(zBin != 0.0)
{
zBin = static_cast<int32_t>((vertices[i * 3 + 2] - m_MinMaxCoords[4]) / stepZ);
}
if(xBin == 100)
{
xBin = 99;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "WriteStlFile.hpp"

#include "complex/DataStructure/Geometry/TriangleGeom.hpp"
#include "complex/Utilities/FilterUtilities.hpp"
#include "complex/Utilities/StringUtilities.hpp"

using namespace complex;
Expand Down Expand Up @@ -65,7 +66,15 @@ Result<> WriteStlFile::operator()()
const IGeometry::MeshIndexArrayType& triangles = triangleGeom.getFacesRef();
const IGeometry::MeshIndexType nTriangles = triangleGeom.getNumberOfFaces();
const auto& featureIds = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->FeatureIdsPath);
// const auto& normals = m_DataStructure.getDataRefAs<Float32Array>(m_InputValues->FaceNormalsPath);

const std::filesystem::path outputPath = m_InputValues->OutputStlDirectory;
// Make sure any directory path is also available as the user may have just typed
// in a path without actually creating the full path
Result<> createDirectoriesResult = complex::CreateOutputDirectories(outputPath);
if(createDirectoriesResult.invalid())
{
return createDirectoriesResult;
}

// Store all the unique Spins
std::map<int32, int32> uniqueGrainIdToPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,6 @@ IFilter::PreflightResult WriteStlFileFilter::preflightImpl(const DataStructure&
return MakePreflightErrorResult(-27873, fmt::format("Feature Ids Array doesn't exist at: {}", pFeatureIdsPathValue.toString()));
}

// if(auto* normals = dataStructure.getDataAs<Float32Array>(pFaceNormalsPathValue); normals == nullptr)
// {
// return MakePreflightErrorResult(-27874, fmt::format("Face Normals Array doesn't exist at: {}", pFaceNormalsPathValue.toString()));
// }

if(!exists(pOutputStlDirectoryValue))
{
return MakePreflightErrorResult(-27875, fmt::format("Directory {} doesn't exist.", pOutputStlDirectoryValue.string()));
}

// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
}
Expand Down

0 comments on commit 42bd7f1

Please sign in to comment.