Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fixes to several filters as reported by users #699

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -57,10 +57,11 @@ Parameters RegularGridSampleSurfaceMeshFilter::parameters() const
params.insertSeparator(Parameters::Separator{"Parameters"});
params.insert(std::make_unique<VectorUInt64Parameter>(k_Dimensions_Key, "Dimensions (Voxels)", "The dimensions of the created Image geometry", std::vector<uint64>{128, 128, 128},
std::vector<std::string>{"x", "y", "z"}));
params.insert(
std::make_unique<VectorFloat32Parameter>(k_Spacing_Key, "Spacing", "The spacing of the created Image geometry", std::vector<float32>{1.0F, 1.0F, 1.0F}, std::vector<std::string>{"x", "y", "z"}));
params.insert(
std::make_unique<VectorFloat32Parameter>(k_Origin_Key, "Origin", "The origin of the created Image geometry", std::vector<float32>{0.0F, 0.0F, 0.0F}, std::vector<std::string>{"x", "y", "z"}));
params.insert(
std::make_unique<VectorFloat32Parameter>(k_Spacing_Key, "Spacing", "The spacing of the created Image geometry", std::vector<float32>{1.0F, 1.0F, 1.0F}, std::vector<std::string>{"x", "y", "z"}));

params.insert(std::make_unique<ChoicesParameter>(k_LengthUnit_Key, "Length Units (For Description Only)", "The units to be displayed below", to_underlying(IGeometry::LengthUnit::Micrometer),
IGeometry::GetAllLengthUnitStrings()));

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
29 changes: 25 additions & 4 deletions src/complex/Utilities/Math/GeometryMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ char RayIntersectsTriangle(const Ray<T>& ray, const complex::Point3D<T>& p0, con
* @return bool
*/
template <typename T>
char IsPointInPolyhedron(const complex::TriangleGeom& faces, const std::vector<int32>& faceIds, const std::vector<BoundingBox3D<T>>& faceBBs, const Point3D<T>& point,
char IsPointInPolyhedron(const complex::TriangleGeom& triangleGeom, const std::vector<int32>& faceIds, const std::vector<BoundingBox3D<T>>& faceBBs, const Point3D<T>& point,
const complex::BoundingBox3D<T>& bounds, T radius)
{
usize iter = 0, crossings = 0;
Expand All @@ -542,6 +542,16 @@ char IsPointInPolyhedron(const complex::TriangleGeom& faces, const std::vector<i
generator.seed(seed);
std::uniform_real_distribution<T> distribution(0.0, 1.0);

const IGeometry::SharedVertexList& vertexListRef = triangleGeom.getVerticesRef();
const IGeometry::SharedFaceList& faceListRef = triangleGeom.getFacesRef();

const auto& vertexListDataStore = vertexListRef.getDataStoreRef();
const auto& faceListDataStore = faceListRef.getDataStoreRef();

Point3D<T> v0;
Point3D<T> v1;
Point3D<T> v2;

usize numFaces = faceIds.size();
while(iter++ < numFaces)
{
Expand Down Expand Up @@ -570,9 +580,20 @@ char IsPointInPolyhedron(const complex::TriangleGeom& faces, const std::vector<i
}
else
{
std::array<Point3D<T>, 3> coords;
faces.getFaceCoordinates(faceIds[face], coords);
code = RayIntersectsTriangle(ray, coords[0], coords[1], coords[2]);
// std::array<Point3D<T>, 3> coords;
// triangleGeom.getFaceCoordinates(faceIds[face], coords);
Comment on lines +583 to +584
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// std::array<Point3D<T>, 3> coords;
// triangleGeom.getFaceCoordinates(faceIds[face], coords);

usize faceId = static_cast<usize>(faceIds[face]);

usize vertId = faceListDataStore[faceId * 3];
v0 = {vertexListDataStore[vertId * 3], vertexListDataStore[vertId * 3 + 1], vertexListDataStore[vertId * 3 + 2]};

vertId = faceListDataStore[faceId * 3 + 1];
v1 = {vertexListDataStore[vertId * 3], vertexListDataStore[vertId * 3 + 1], vertexListDataStore[vertId * 3 + 2]};

vertId = faceListDataStore[faceId * 3 + 2];
v2 = {vertexListDataStore[vertId * 3], vertexListDataStore[vertId * 3 + 1], vertexListDataStore[vertId * 3 + 2]};

code = RayIntersectsTriangle(ray, v0, v1, v2);
}

/* If ray is degenerate, then goto outer while to generate another. */
Expand Down
46 changes: 27 additions & 19 deletions src/complex/Utilities/SampleSurfaceMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class SampleSurfaceMeshImplByPoints

void checkPoints(usize start, usize end) const
{
auto startTime = std::chrono::steady_clock::now();

usize iter = m_FeatureId;

// find bounding box for current feature
Expand All @@ -115,6 +117,15 @@ class SampleSurfaceMeshImplByPoints
// check points in vertex array to see if they are in the bounding box of the feature
for(usize i = start; i < end; i++)
{
auto now = std::chrono::steady_clock::now();
// Only send updates every 1 second
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - startTime).count() > 1000)
{
std::string message = fmt::format("{}", i);
m_Filter->sendThreadSafeProgressMessage(i, i - start, m_Points.size());
startTime = std::chrono::steady_clock::now();
}

Point3Df point = m_Points[i];
if(m_PolyIds[i] == 0)
{
Expand All @@ -126,11 +137,6 @@ class SampleSurfaceMeshImplByPoints
}
pointsVisited++;

// Send some feedback
if(pointsVisited % 1000 == 0)
{
m_Filter->sendThreadSafeProgressMessage(m_FeatureId, 1000, m_Points.size());
}
// Check for the filter being cancelled.
if(m_ShouldCancel)
{
Expand Down Expand Up @@ -288,8 +294,11 @@ Result<> SampleSurfaceMesh::execute(SampleSurfaceMeshInputValues& inputValues)
{
for(int32 featureId = 0; featureId < numFeatures; featureId++)
{
updateProgress(fmt::format("Sampling FeatureID: {} ", featureId));

ParallelDataAlgorithm dataAlg;
dataAlg.setRange(0, points.size());
dataAlg.setParallelizationEnabled(true);
dataAlg.execute(SampleSurfaceMeshImplByPoints(this, triangleGeom, faceLists[featureId], faceBBs, points, featureId, polyIds, m_ShouldCancel));
}
}
Expand All @@ -306,21 +315,20 @@ void SampleSurfaceMesh::sendThreadSafeProgressMessage(usize featureId, usize num

m_ProgressCounter += numCompleted;
auto now = std::chrono::steady_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(m_InitialTime - now).count();
if(diff > 1000)
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - m_LastUpdateTime).count() > 1000)
{
std::string progMessage = fmt::format("Feature {} | Points Completed: {} of {}", featureId, m_ProgressCounter, totalFeatures);
float inverseRate = static_cast<float>(diff) / static_cast<float>(m_ProgressCounter - m_LastProgressInt);
auto remainMillis = std::chrono::milliseconds(static_cast<int64>(inverseRate * (totalFeatures - m_ProgressCounter)));
auto secs = std::chrono::duration_cast<std::chrono::seconds>(remainMillis);
remainMillis -= std::chrono::duration_cast<std::chrono::milliseconds>(secs);
auto mins = std::chrono::duration_cast<std::chrono::minutes>(secs);
secs -= std::chrono::duration_cast<std::chrono::seconds>(mins);
auto hour = std::chrono::duration_cast<std::chrono::hours>(mins);
mins -= std::chrono::duration_cast<std::chrono::minutes>(hour);
progMessage += fmt::format(" || Est. Time Remain: {} hours {} minutes {} seconds", hour.count(), mins.count(), secs.count());
std::string progMessage = fmt::format("{}", m_ProgressCounter);
// float inverseRate = static_cast<float>(diff) / static_cast<float>(m_ProgressCounter - m_LastProgressInt);
// auto remainMillis = std::chrono::milliseconds(static_cast<int64>(inverseRate * (totalFeatures - m_ProgressCounter)));
// auto secs = std::chrono::duration_cast<std::chrono::seconds>(remainMillis);
// remainMillis -= std::chrono::duration_cast<std::chrono::milliseconds>(secs);
// auto mins = std::chrono::duration_cast<std::chrono::minutes>(secs);
// secs -= std::chrono::duration_cast<std::chrono::seconds>(mins);
// auto hour = std::chrono::duration_cast<std::chrono::hours>(mins);
// mins -= std::chrono::duration_cast<std::chrono::minutes>(hour);
// progMessage += fmt::format(" || Est. Time Remain: {} hours {} minutes {} seconds", hour.count(), mins.count(), secs.count());
Comment on lines +321 to +329
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// float inverseRate = static_cast<float>(diff) / static_cast<float>(m_ProgressCounter - m_LastProgressInt);
// auto remainMillis = std::chrono::milliseconds(static_cast<int64>(inverseRate * (totalFeatures - m_ProgressCounter)));
// auto secs = std::chrono::duration_cast<std::chrono::seconds>(remainMillis);
// remainMillis -= std::chrono::duration_cast<std::chrono::milliseconds>(secs);
// auto mins = std::chrono::duration_cast<std::chrono::minutes>(secs);
// secs -= std::chrono::duration_cast<std::chrono::seconds>(mins);
// auto hour = std::chrono::duration_cast<std::chrono::hours>(mins);
// mins -= std::chrono::duration_cast<std::chrono::minutes>(hour);
// progMessage += fmt::format(" || Est. Time Remain: {} hours {} minutes {} seconds", hour.count(), mins.count(), secs.count());

m_MessageHandler({IFilter::Message::Type::Info, progMessage});
m_InitialTime = std::chrono::steady_clock::now();
m_LastProgressInt = m_ProgressCounter;
m_LastUpdateTime = std::chrono::steady_clock::now();
// m_LastProgressInt = m_ProgressCounter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// m_LastProgressInt = m_ProgressCounter;

}
}
2 changes: 1 addition & 1 deletion src/complex/Utilities/SampleSurfaceMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class COMPLEX_EXPORT SampleSurfaceMesh
mutable std::mutex m_ProgressMessage_Mutex;
usize m_ProgressCounter = 0;
usize m_LastProgressInt = 0;
std::chrono::steady_clock::time_point m_InitialTime = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point m_LastUpdateTime = std::chrono::steady_clock::now();
};
} // namespace complex
Loading