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

[WIP] DEBUG: Changes to allow easier debugging of the FindNeighborHoods filter #696

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 @@ -6,6 +6,7 @@
#include "complex/Utilities/ParallelDataAlgorithm.hpp"

#include <cmath>
#include <chrono>

using namespace complex;

Expand Down Expand Up @@ -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<float>(featureIdx) / static_cast<float>(m_TotalFeatures) * 100.0f;
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("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);
Expand All @@ -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];
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct COMPLEXCORE_EXPORT FindNeighborhoodsInputValues
DataPath NeighborhoodsArrayName;
DataPath NeighborhoodListArrayName;
DataPath InputImageGeometry;
bool ParallelExecution;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<BoolParameter>(k_Parallel_Key, "Parallel Execution", "Runs the filter using multiple cores where possible", false));


params.insert(std::make_unique<Float32Parameter>(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<GeometrySelectionParameter>(k_SelectedImageGeometry_Key, "Selected Image Geometry", "The target geometry", DataPath({"Data Container"}),
Expand Down Expand Up @@ -140,7 +144,7 @@ Result<> FindNeighborhoodsFilter::executeImpl(DataStructure& dataStructure, cons
const std::atomic_bool& shouldCancel) const
{
FindNeighborhoodsInputValues inputValues;

inputValues.ParallelExecution = filterArgs.value<bool>(k_Parallel_Key);
inputValues.MultiplesOfAverage = filterArgs.value<float32>(k_MultiplesOfAverage_Key);
inputValues.EquivalentDiametersArrayPath = filterArgs.value<DataPath>(k_EquivalentDiametersArrayPath_Key);
inputValues.FeaturePhasesArrayPath = filterArgs.value<DataPath>(k_FeaturePhasesArrayPath_Key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32>(dataStructure.getDataAs<IDataArray>(exemplarPath), dataStructure.getDataAs<IDataArray>(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<int32>(dataStructure.getDataAs<NeighborList<int32>>(exemplarPath), dataStructure.getDataAs<NeighborList<int32>>(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
//}