Skip to content

Commit fb17053

Browse files
committed
Optimize by requiring "Part Ids". Parallel by PartId.
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 5d22556 commit fb17053

7 files changed

Lines changed: 267 additions & 139 deletions

File tree

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RegularGridSampleSurfaceMesh.cpp

Lines changed: 235 additions & 119 deletions
Large diffs are not rendered by default.

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/RegularGridSampleSurfaceMesh.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
#include "simplnx/DataStructure/DataPath.hpp"
66
#include "simplnx/DataStructure/DataStructure.hpp"
77
#include "simplnx/Filter/IFilter.hpp"
8-
#include "simplnx/Parameters/ArrayCreationParameter.hpp"
9-
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
10-
#include "simplnx/Parameters/ChoicesParameter.hpp"
11-
#include "simplnx/Parameters/DataGroupCreationParameter.hpp"
128
#include "simplnx/Parameters/VectorParameter.hpp"
139
#include "simplnx/Utilities/SampleSurfaceMesh.hpp"
1410

11+
#include <set>
12+
1513
namespace nx::core
1614
{
1715
struct SIMPLNXCORE_EXPORT RegularGridSampleSurfaceMeshInputValues
@@ -23,6 +21,7 @@ struct SIMPLNXCORE_EXPORT RegularGridSampleSurfaceMeshInputValues
2321
DataPath SurfaceMeshFaceLabelsArrayPath;
2422
DataPath ImageGeometryOutputPath;
2523
DataPath FeatureIdsArrayPath;
24+
DataPath SurfaceMeshPartIdsArrayPath;
2625
};
2726

2827
/**
@@ -42,11 +41,11 @@ class SIMPLNXCORE_EXPORT RegularGridSampleSurfaceMesh : public SampleSurfaceMesh
4241

4342
Result<> operator()();
4443

45-
const std::atomic_bool& getCancel();
46-
void sendThreadSafeUpdate(Int32Array& m_FeatureIds, const std::vector<int32>& rasterBuffer, usize offset);
44+
void sendThreadSafeUpdate(const std::vector<int32>& rasterBuffer, usize offset);
4745

4846
protected:
4947
void generatePoints(std::vector<Point3Df>& points) override;
48+
void processSlice(int32 m_CurrentSliceId, usize m_ImageGeomIdx, const std::set<int32>& uniquePartIds);
5049

5150
private:
5251
DataStructure& m_DataStructure;
@@ -56,8 +55,10 @@ class SIMPLNXCORE_EXPORT RegularGridSampleSurfaceMesh : public SampleSurfaceMesh
5655

5756
// Thread safe Progress Message
5857
mutable std::mutex m_ProgressMessage_Mutex;
59-
usize m_ProgressCounter = 0;
60-
usize m_LastProgressInt = 0;
58+
usize m_LayerCompleted = 0;
59+
usize m_TotalSlices = 0;
60+
// usize m_LastProgressInt = 0;
6161
std::chrono::steady_clock::time_point m_InitialTime = std::chrono::steady_clock::now();
62+
Int32Array* m_FeatureIdsDataStorePtr = nullptr;
6263
};
6364
} // namespace nx::core

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/SliceTriangleGeometry.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Result<> SliceTriangleGeometry::operator()()
5151
zEnd = boundingBox.getMaxPoint()[2];
5252
}
5353

54+
m_MessageHandler({IFilter::Message::Type::Info, fmt::format("Slicing triangle geometry")});
55+
5456
// The majority of the algorithm to slice the triangle geometry is in this function
5557
GeometryUtilities::SliceTriangleReturnType sliceTriangleResult =
5658
GeometryUtilities::SliceTriangleGeometry(triangle, m_ShouldCancel, m_InputValues->SliceRange, zStart, zEnd, m_InputValues->SliceResolution, triRegionIdPtr);
@@ -84,6 +86,8 @@ Result<> SliceTriangleGeometry::operator()()
8486
triRegionIds->fill(0);
8587
}
8688

89+
m_MessageHandler({IFilter::Message::Type::Info, fmt::format("Setting Feature Ids")});
90+
8791
for(usize i = 0; i < numEdges; i++)
8892
{
8993
edges[2 * i] = 2 * i;
@@ -101,12 +105,16 @@ Result<> SliceTriangleGeometry::operator()()
101105
}
102106
}
103107

108+
m_MessageHandler({IFilter::Message::Type::Info, fmt::format("Removing duplicate nodes...")});
109+
104110
Result<> result = GeometryUtilities::EliminateDuplicateNodes<EdgeGeom>(edgeGeom);
105111
if(result.invalid())
106112
{
107113
return result;
108114
}
109115

116+
m_MessageHandler({IFilter::Message::Type::Info, fmt::format("Removing duplicate edges...")});
117+
110118
// REMOVE DUPLICATE EDGES FROM THE GENERATED EDGE GEOMETRY
111119
// Remember to also fix up the sliceIds and regionIds arrays
112120
using UniqueEdges = std::set<std::pair<uint64, uint64>>;

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RegularGridSampleSurfaceMeshFilter.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Parameters RegularGridSampleSurfaceMeshFilter::parameters() const
9999
params.insert(std::make_unique<GeometrySelectionParameter>(k_ExistingImageGeomPath_Key, "Image Geometry", "The path to the existing image geometry to use", DataPath{},
100100
GeometrySelectionParameter::AllowedTypes{GeometrySelectionParameter::AllowedType::Image}));
101101

102+
params.insert(std::make_unique<ArraySelectionParameter>(k_SurfaceMeshPartNumbersArrayPath_Key, "Part Numbers", "Array specifying the part number that the triangle belongs to.", DataPath{},
103+
ArraySelectionParameter::AllowedTypes{nx::core::DataType::int32}, ArraySelectionParameter::AllowedComponentShapes{{1}}));
104+
102105
params.insertSeparator(Parameters::Separator{"Output Image Geometry"});
103106
params.insert(std::make_unique<DataGroupCreationParameter>(k_ImageGeomPath_Key, "Image Geometry", "The name and path for the image geometry to be created", DataPath{}));
104107
params.insertSeparator(Parameters::Separator{"Output Cell Attribute Matrix"});
@@ -145,8 +148,8 @@ IFilter::PreflightResult RegularGridSampleSurfaceMeshFilter::preflightImpl(const
145148
auto triangleGeometryPath = filterArgs.value<DataPath>(k_TriangleGeometryPath_Key);
146149
auto geometryOptionIndex = filterArgs.value<ChoicesParameter::ValueType>(k_UseExistingGeometry_Key);
147150
auto existingImageGeomPathValue = filterArgs.value<DataPath>(k_ExistingImageGeomPath_Key);
148-
149151
GeometryOption geometryOption = ConvertIndexToGeometryOption(geometryOptionIndex);
152+
auto partNumbersPath = filterArgs.value<DataPath>(k_SurfaceMeshPartNumbersArrayPath_Key);
150153

151154
nx::core::Result<OutputActions> resultOutputActions;
152155
std::vector<PreflightValue> preflightUpdatedValues;
@@ -203,7 +206,6 @@ IFilter::PreflightResult RegularGridSampleSurfaceMeshFilter::preflightImpl(const
203206
DataPath pSliceDataContainerNameValue({fmt::format(".{}_sliced", triangleGeometryPath.getTargetName())});
204207
std::string pEdgeAttributeMatrixNameValue("EdgeAttributeMatrix");
205208
std::string pSliceIdArrayNameValue("SliceIds");
206-
DataPath pRegionIdArrayPathValue({"NOT USED"});
207209
std::string pSliceAttributeMatrixNameValue("SliceAttributeMatrix");
208210
// create the edge geometry
209211
{
@@ -225,9 +227,13 @@ IFilter::PreflightResult RegularGridSampleSurfaceMeshFilter::preflightImpl(const
225227
auto createAttributeMatrixAction = std::make_unique<CreateAttributeMatrixAction>(featureSliceAttrMatPath, tDims);
226228
resultOutputActions.value().appendAction(std::move(createAttributeMatrixAction));
227229
}
228-
229-
auto deferredDeleteGeometryAction = std::make_unique<DeleteDataAction>(pSliceDataContainerNameValue);
230-
resultOutputActions.value().appendDeferredAction(std::move(deferredDeleteGeometryAction));
230+
{
231+
DataPath path = pSliceDataContainerNameValue.createChildPath(pEdgeAttributeMatrixNameValue).createChildPath(partNumbersPath.getTargetName());
232+
auto createArray = std::make_unique<CreateArrayAction>(DataType::int32, tDims, compDims, path);
233+
resultOutputActions.value().appendAction(std::move(createArray));
234+
}
235+
// auto deferredDeleteGeometryAction = std::make_unique<DeleteDataAction>(pSliceDataContainerNameValue);
236+
// resultOutputActions.value().appendDeferredAction(std::move(deferredDeleteGeometryAction));
231237
}
232238
/////////////////////////////////////////////////////////////////////////////
233239

@@ -269,6 +275,9 @@ Result<> RegularGridSampleSurfaceMeshFilter::executeImpl(DataStructure& dataStru
269275

270276
inputValues.TriangleGeometryPath = filterArgs.value<DataPath>(k_TriangleGeometryPath_Key);
271277
inputValues.SurfaceMeshFaceLabelsArrayPath = filterArgs.value<DataPath>(k_SurfaceMeshFaceLabelsArrayPath_Key);
278+
// inputValues.FeatureIdsArrayPath =
279+
// filterArgs.value<DataPath>(k_ImageGeomPath_Key).createChildPath(filterArgs.value<std::string>(k_CellAMName_Key)).createChildPath(filterArgs.value<std::string>(k_FeatureIdsArrayName_Key));
280+
inputValues.SurfaceMeshPartIdsArrayPath = filterArgs.value<DataPath>(k_SurfaceMeshPartNumbersArrayPath_Key);
272281

273282
return RegularGridSampleSurfaceMesh(dataStructure, messageHandler, shouldCancel, &inputValues)();
274283
}

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/RegularGridSampleSurfaceMeshFilter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SIMPLNXCORE_EXPORT RegularGridSampleSurfaceMeshFilter : public IFilter
4242
UseExisting = 1
4343
};
4444

45+
static inline constexpr StringLiteral k_SurfaceMeshPartNumbersArrayPath_Key = "surface_mesh_part_numbers_array_path";
4546
/**
4647
* @brief Reads SIMPL json and converts it simplnx Arguments.
4748
* @param json

src/simplnx/Utilities/ParallelTaskAlgorithm.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ void ParallelTaskAlgorithm::wait()
3838
#ifdef SIMPLNX_ENABLE_MULTICORE
3939
// This will spill over if the number of files to process does not divide evenly by the number of threads.
4040
m_TaskGroup.wait();
41-
m_CurThreads = 0;
4241
#endif
4342
}

src/simplnx/Utilities/ParallelTaskAlgorithm.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class SIMPLNX_EXPORT ParallelTaskAlgorithm : public IParallelAlgorithm
5353
if(getParallelizationEnabled())
5454
{
5555
m_TaskGroup.run(body);
56-
m_CurThreads++;
57-
if(m_CurThreads >= m_MaxThreads)
58-
{
59-
wait();
60-
}
6156
}
6257
else
6358
#endif
@@ -75,7 +70,6 @@ class SIMPLNX_EXPORT ParallelTaskAlgorithm : public IParallelAlgorithm
7570
#ifdef SIMPLNX_ENABLE_MULTICORE
7671
uint32_t m_MaxThreads = std::thread::hardware_concurrency();
7772
tbb::task_group m_TaskGroup;
78-
uint32_t m_CurThreads = 0;
7973
#else
8074
uint32_t m_MaxThreads = 1;
8175
#endif

0 commit comments

Comments
 (0)