diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp index 7d5facbd67..d8c0d86996 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp @@ -6,6 +6,7 @@ #include "complex/Utilities/ParallelDataAlgorithm.hpp" #include +#include using namespace complex; @@ -34,10 +35,24 @@ class FindNeighborhoodsImpl { start = 1; } - for(size_t i = start; i < end; i++) + int32 progInt = 0.0f; + auto startTime = std::chrono::steady_clock::now(); + + for(size_t featureIdx = start; featureIdx < end; featureIdx++) { + progInt = static_cast(featureIdx) / static_cast(m_TotalFeatures) * 100.0f; + auto now = std::chrono::steady_clock::now(); + // Only send updates every 1 second + if(std::chrono::duration_cast(now - startTime).count() > 1000) + { + std::string message = fmt::format("Finding Neighborhood for FeatureId:{}", featureIdx); + //m_MessageHandler(complex::IFilter::ProgressMessage{complex::IFilter::Message::Type::Info, message, progInt}); + std::cout << message<< "\n"; + startTime = std::chrono::steady_clock::now(); + } + incCount++; - if(incCount == increment || i == end - 1) + if(incCount == increment || featureIdx == end - 1) { incCount = 0; m_Filter->updateProgress(increment, m_TotalFeatures); @@ -46,12 +61,12 @@ class FindNeighborhoodsImpl { break; } - bin1x = m_Bins[3 * i]; - bin1y = m_Bins[3 * i + 1]; - bin1z = m_Bins[3 * i + 2]; - criticalDistance1 = m_CriticalDistance[i]; + bin1x = m_Bins[3 * featureIdx]; + bin1y = m_Bins[3 * featureIdx + 1]; + bin1z = m_Bins[3 * featureIdx + 2]; + criticalDistance1 = m_CriticalDistance[featureIdx]; - for(size_t j = i + 1; j < m_TotalFeatures; j++) + for(size_t j = featureIdx + 1; j < m_TotalFeatures; j++) { bin2x = m_Bins[3 * j]; bin2y = m_Bins[3 * j + 1]; @@ -64,12 +79,12 @@ class FindNeighborhoodsImpl if(dBinX < criticalDistance1 && dBinY < criticalDistance1 && dBinZ < criticalDistance1) { - m_Filter->updateNeighborHood(i, j); + m_Filter->updateNeighborHood(featureIdx, j); } if(dBinX < criticalDistance2 && dBinY < criticalDistance2 && dBinZ < criticalDistance2) { - m_Filter->updateNeighborHood(j, i); + m_Filter->updateNeighborHood(j, featureIdx); } } } @@ -185,7 +200,7 @@ Result<> FindNeighborhoods::operator()() ParallelDataAlgorithm parallelAlgorithm; parallelAlgorithm.setRange(Range(0, totalFeatures)); - parallelAlgorithm.setParallelizationEnabled(false); + parallelAlgorithm.setParallelizationEnabled(m_InputValues->ParallelExecution); parallelAlgorithm.execute(FindNeighborhoodsImpl(this, totalFeatures, centroids, bins, criticalDistance)); // Output Variables diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.hpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.hpp index 550b5900d8..843624c58f 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.hpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.hpp @@ -22,6 +22,7 @@ struct COMPLEXCORE_EXPORT FindNeighborhoodsInputValues DataPath NeighborhoodsArrayName; DataPath NeighborhoodListArrayName; DataPath InputImageGeometry; + bool ParallelExecution; }; /** diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp index 078f80f00d..3517f81444 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp @@ -10,6 +10,7 @@ #include "complex/Parameters/DataObjectNameParameter.hpp" #include "complex/Parameters/GeometrySelectionParameter.hpp" #include "complex/Parameters/NumberParameter.hpp" +#include "complex/Parameters/BoolParameter.hpp" using namespace complex; @@ -53,6 +54,9 @@ Parameters FindNeighborhoodsFilter::parameters() const // Create the parameter descriptors that are needed for this filter params.insertSeparator(Parameters::Separator{"Input Parameters"}); + params.insertLinkableParameter(std::make_unique(k_Parallel_Key, "Parallel Execution", "Runs the filter using multiple cores where possible", false)); + + params.insert(std::make_unique(k_MultiplesOfAverage_Key, "Multiples of Average Diameter", "Defines the search radius to use when looking for 'neighboring' Features", 1.0F)); params.insert(std::make_unique(k_SelectedImageGeometry_Key, "Selected Image Geometry", "The target geometry", DataPath({"Data Container"}), @@ -140,7 +144,7 @@ Result<> FindNeighborhoodsFilter::executeImpl(DataStructure& dataStructure, cons const std::atomic_bool& shouldCancel) const { FindNeighborhoodsInputValues inputValues; - + inputValues.ParallelExecution = filterArgs.value(k_Parallel_Key); inputValues.MultiplesOfAverage = filterArgs.value(k_MultiplesOfAverage_Key); inputValues.EquivalentDiametersArrayPath = filterArgs.value(k_EquivalentDiametersArrayPath_Key); inputValues.FeaturePhasesArrayPath = filterArgs.value(k_FeaturePhasesArrayPath_Key); diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.hpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.hpp index 1a437d4f1d..6269b9a729 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.hpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.hpp @@ -31,6 +31,7 @@ class COMPLEXCORE_EXPORT FindNeighborhoodsFilter : public IFilter static inline constexpr StringLiteral k_NeighborhoodsArrayName_Key = "neighborhoods_array_name"; static inline constexpr StringLiteral k_NeighborhoodListArrayName_Key = "neighborhood_list_array_name"; static inline constexpr StringLiteral k_SelectedImageGeometry_Key = "selected_image_geometry_path"; + static inline constexpr StringLiteral k_Parallel_Key = "parallel_execution"; /** * @brief Returns the name of the filter. diff --git a/src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp b/src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp index fcfcec029c..b63ce186a2 100644 --- a/src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp +++ b/src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp @@ -74,3 +74,34 @@ TEST_CASE("ComplexCore::FindNeighborhoods", "[ComplexCore][FindNeighborhoods]") WriteTestDataStructure(dataStructure, fs::path(fmt::format("{}/find_neighborhoods.dream3d", unit_test::k_BinaryTestOutputDir))); #endif } + +// +//TEST_CASE("ComplexCore::FindNeighborhoods Debug", "[ComplexCore][FindNeighborhoods]") +//{ +// +// // Read the Small IN100 Data set +// auto baseDataFilePath = fs::path(fmt::format("/tmp/7_after.dream3d")); +// DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); +// +// // Compare the k_Neighborhoods output array with those precalculated from the file +// { +// const DataPath exemplarPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/Neighborhoods").value(); +// const DataPath parallelPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/Neighborhoods Parallel").value(); +// UnitTest::CompareArrays(dataStructure.getDataAs(exemplarPath), dataStructure.getDataAs(parallelPath)); +// } +// +// // Compare the k_NeighborhoodList output neighborlist with those precalculated from the file +// { +// const DataPath exemplarPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/NeighborhoodList").value(); +// const DataPath parallelPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/NeighborhoodList Parallel").value(); +// +// UnitTest::CompareNeighborLists(dataStructure.getDataAs>(exemplarPath), dataStructure.getDataAs>(parallelPath)); +// } +// +//// Write the DataStructure out to the file system +//#ifdef COMPLEX_WRITE_TEST_OUTPUT +// WriteTestDataStructure(dataStructure, fs::path(fmt::format("{}/find_neighborhoods.dream3d", unit_test::k_BinaryTestOutputDir))); +//#endif +//} + +