mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge topic 'new_connected_components'
027036700 use CastAndCallScalarField 2540fb1b2 Merge branch 'master' into new_connected_components 578f980ac Merge branch 'master' into new_connected_components ee1b752e8 Merge branch 'master' into new_connected_components de66d93d0 Add ALL_BACKENDS 77650a9ca migrate connected components filters Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Acked-by: Kenneth Moreland <morelandkd@ornl.gov> Merge-request: !2675
This commit is contained in:
commit
a876af59fc
@ -22,6 +22,7 @@ vtkm_add_instantiations(ClipWithImplicitFunctionInstantiations
|
||||
)
|
||||
|
||||
set(deprecated_headers
|
||||
CellSetConnectivity.h
|
||||
CleanGrid.h
|
||||
CrossProduct.h
|
||||
DotProduct.h
|
||||
@ -33,6 +34,7 @@ set(deprecated_headers
|
||||
GenerateIds.h
|
||||
GhostCellRemove.h
|
||||
Histogram.h
|
||||
ImageConnectivity.h
|
||||
Mask.h
|
||||
MaskPoints.h
|
||||
NDEntropy.h
|
||||
@ -82,7 +84,6 @@ set(common_sources_device
|
||||
|
||||
set(extra_headers
|
||||
AmrArrays.h
|
||||
CellSetConnectivity.h
|
||||
ClipWithField.h
|
||||
ClipWithImplicitFunction.h
|
||||
ComputeMoments.h
|
||||
@ -91,7 +92,6 @@ set(extra_headers
|
||||
FieldSelection.h
|
||||
FieldToColors.h
|
||||
GhostCellClassify.h
|
||||
ImageConnectivity.h
|
||||
ImageDifference.h
|
||||
ImageMedian.h
|
||||
Lagrangian.h
|
||||
@ -126,7 +126,6 @@ set(extra_headers
|
||||
|
||||
set(extra_header_template_sources
|
||||
AmrArrays.hxx
|
||||
CellSetConnectivity.hxx
|
||||
ClipWithField.hxx
|
||||
ClipWithImplicitFunction.hxx
|
||||
ClipWithFieldExternInstantiations.h
|
||||
@ -135,7 +134,6 @@ set(extra_header_template_sources
|
||||
CoordinateSystemTransform.hxx
|
||||
FieldToColors.hxx
|
||||
GhostCellClassify.hxx
|
||||
ImageConnectivity.hxx
|
||||
ImageDifference.hxx
|
||||
ImageMedian.hxx
|
||||
Lagrangian.hxx
|
||||
@ -302,6 +300,7 @@ target_link_libraries(vtkm_filter PUBLIC INTERFACE
|
||||
install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME})
|
||||
|
||||
add_subdirectory(clean_grid)
|
||||
add_subdirectory(connected_components)
|
||||
add_subdirectory(density_estimate)
|
||||
add_subdirectory(entity_extraction)
|
||||
add_subdirectory(internal)
|
||||
|
@ -7,54 +7,34 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_filter_CellSetConnectivity_h
|
||||
#define vtk_m_filter_CellSetConnectivity_h
|
||||
|
||||
#ifndef vtkm_m_filter_CellSetConnectivity_h
|
||||
#define vtkm_m_filter_CellSetConnectivity_h
|
||||
|
||||
#include <vtkm/filter/FilterDataSet.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/filter/connected_components/CellSetConnectivity.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
/// \brief Finds groups of cells that are connected together through their topology.
|
||||
///
|
||||
/// Finds and labels groups of cells that are connected together through their topology.
|
||||
/// Two cells are considered connected if they share an edge. CellSetConnectivity identifies some
|
||||
/// number of components and assigns each component a unique integer.
|
||||
/// The result of the filter is a cell field of type vtkm::Id with the default name of 'component'.
|
||||
/// Each entry in the cell field will be a number that identifies to which component the cell belongs.
|
||||
class CellSetConnectivity : public vtkm::filter::FilterDataSet<CellSetConnectivity>
|
||||
|
||||
VTKM_DEPRECATED(1.8,
|
||||
"Use vtkm/filter/connected_components/CellSetConnectivity.h instead of "
|
||||
"vtkm/filter/CellSetConnectivity.h.")
|
||||
inline void CellSetConnectivity_deprecated() {}
|
||||
|
||||
inline void CellSetConnectivity_deprecated_warning()
|
||||
{
|
||||
public:
|
||||
using SupportedTypes = vtkm::TypeListScalarAll;
|
||||
VTKM_CONT CellSetConnectivity();
|
||||
CellSetConnectivity_deprecated();
|
||||
}
|
||||
|
||||
void SetOutputFieldName(const std::string& name) { this->OutputFieldName = name; }
|
||||
|
||||
VTKM_CONT
|
||||
const std::string& GetOutputFieldName() const { return this->OutputFieldName; }
|
||||
|
||||
|
||||
template <typename Policy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
|
||||
vtkm::filter::PolicyBase<Policy> policy);
|
||||
|
||||
template <typename Policy>
|
||||
VTKM_CONT bool MapFieldOntoOutput(vtkm::cont::DataSet& result,
|
||||
const vtkm::cont::Field& field,
|
||||
const vtkm::filter::PolicyBase<Policy>&)
|
||||
{
|
||||
result.AddField(field);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string OutputFieldName;
|
||||
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::connected_components::CellSetConnectivity.")
|
||||
CellSetConnectivity : public vtkm::filter::connected_components::CellSetConnectivity
|
||||
{
|
||||
using connected_components::CellSetConnectivity::CellSetConnectivity;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <vtkm/filter/CellSetConnectivity.hxx>
|
||||
}
|
||||
} // namespace vtkm::filter
|
||||
|
||||
#endif //vtkm_m_filter_CellSetConnectivity_h
|
||||
#endif //vtk_m_filter_CellSetConnectivity_h
|
||||
|
@ -1,42 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtkm_m_filter_CellSetConnectivity_hxx
|
||||
#define vtkm_m_filter_CellSetConnectivity_hxx
|
||||
|
||||
#include <vtkm/filter/CreateResult.h>
|
||||
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
VTKM_CONT CellSetConnectivity::CellSetConnectivity()
|
||||
: OutputFieldName("component")
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Policy>
|
||||
inline VTKM_CONT vtkm::cont::DataSet CellSetConnectivity::DoExecute(
|
||||
const vtkm::cont::DataSet& input,
|
||||
vtkm::filter::PolicyBase<Policy> policy)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(
|
||||
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this), component);
|
||||
|
||||
return CreateResultFieldCell(input, component, this->GetOutputFieldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtkm_m_filter_CellSetConnectivity_hxx
|
@ -7,43 +7,34 @@
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_ImageConnectivity_h
|
||||
#define vtk_m_filter_ImageConnectivity_h
|
||||
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
#include <vtkm/worklet/connectivities/ImageConnectivity.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/filter/connected_components/ImageConnectivity.h>
|
||||
|
||||
/// \brief Groups connected points that have the same field value
|
||||
///
|
||||
///
|
||||
/// The ImageConnectivity filter finds groups of points that have the same field value and are
|
||||
/// connected together through their topology. Any point is considered to be connected to its Moore neighborhood:
|
||||
/// 8 neighboring points for 2D and 27 neighboring points for 3D. As the name implies, ImageConnectivity only
|
||||
/// works on data with a structured cell set. You will get an error if you use any other type of cell set.
|
||||
/// The active field passed to the filter must be associated with the points.
|
||||
/// The result of the filter is a point field of type vtkm::Id. Each entry in the point field will be a number that
|
||||
/// identifies to which region it belongs. By default, this output point field is named “component”.
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
class ImageConnectivity : public vtkm::filter::FilterField<ImageConnectivity>
|
||||
|
||||
VTKM_DEPRECATED(1.8,
|
||||
"Use vtkm/filter/connected_components/ImageConnectivity.h instead of "
|
||||
"vtkm/filter/ImageConnectivity.h.")
|
||||
inline void ImageConnectivity_deprecated() {}
|
||||
|
||||
inline void ImageConnectivity_deprecated_warning()
|
||||
{
|
||||
public:
|
||||
using SupportedTypes = vtkm::TypeListScalarAll;
|
||||
ImageConnectivity_deprecated();
|
||||
}
|
||||
|
||||
VTKM_CONT inline ImageConnectivity() { this->SetOutputFieldName("component"); }
|
||||
|
||||
template <typename T, typename StorageType, typename DerivedPolicy>
|
||||
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
|
||||
const vtkm::cont::ArrayHandle<T, StorageType>& field,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>&);
|
||||
class VTKM_DEPRECATED(1.8, "Use vtkm::filter::connected_components::ImageConnectivity.")
|
||||
ImageConnectivity : public vtkm::filter::connected_components::ImageConnectivity
|
||||
{
|
||||
using connected_components::ImageConnectivity::ImageConnectivity;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::filter
|
||||
|
||||
#include <vtkm/filter/ImageConnectivity.hxx>
|
||||
|
||||
#endif //vtk_m_filter_ImageConnectivity_h
|
||||
|
@ -1,42 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_ImageConnectivity_hxx
|
||||
#define vtk_m_filter_ImageConnectivity_hxx
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
|
||||
template <typename T, typename StorageType, typename DerivedPolicy>
|
||||
inline VTKM_CONT vtkm::cont::DataSet ImageConnectivity::DoExecute(
|
||||
const vtkm::cont::DataSet& input,
|
||||
const vtkm::cont::ArrayHandle<T, StorageType>& field,
|
||||
const vtkm::filter::FieldMetadata& fieldMetadata,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
|
||||
{
|
||||
if (!fieldMetadata.IsPointField())
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Active field for ImageConnectivity must be a point field.");
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
|
||||
vtkm::worklet::connectivity::ImageConnectivity().Run(
|
||||
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this), field, component);
|
||||
|
||||
auto result = CreateResult(input, component, this->GetOutputFieldName(), fieldMetadata);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
34
vtkm/filter/connected_components/CMakeLists.txt
Normal file
34
vtkm/filter/connected_components/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
set(connected_components_headers
|
||||
CellSetConnectivity.h
|
||||
ImageConnectivity.h
|
||||
)
|
||||
set(connected_components_sources_device
|
||||
CellSetConnectivity.cxx
|
||||
ImageConnectivity.cxx
|
||||
)
|
||||
|
||||
vtkm_library(
|
||||
NAME vtkm_filter_connected_components
|
||||
HEADERS ${connected_components_headers}
|
||||
DEVICE_SOURCES ${connected_components_sources_device}
|
||||
USE_VTKM_JOB_POOL
|
||||
)
|
||||
|
||||
target_link_libraries(vtkm_filter_connected_components PRIVATE vtkm_worklet PUBLIC vtkm_filter_core)
|
||||
target_link_libraries(vtkm_filter PUBLIC INTERFACE vtkm_filter_connected_components)
|
||||
|
||||
add_subdirectory(worklet)
|
||||
|
||||
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
|
||||
if (VTKm_ENABLE_TESTING)
|
||||
add_subdirectory(testing)
|
||||
endif ()
|
34
vtkm/filter/connected_components/CellSetConnectivity.cxx
Normal file
34
vtkm/filter/connected_components/CellSetConnectivity.cxx
Normal file
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/filter/CreateResult.h>
|
||||
#include <vtkm/filter/connected_components/CellSetConnectivity.h>
|
||||
#include <vtkm/filter/connected_components/worklet/CellSetConnectivity.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace connected_components
|
||||
{
|
||||
VTKM_CONT vtkm::cont::DataSet CellSetConnectivity::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(input.GetCellSet(), component);
|
||||
|
||||
auto output = CreateResultFieldCell(input, component, this->GetOutputFieldName());
|
||||
this->MapFieldsOntoOutput(input, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
} // namespace connected_components
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
46
vtkm/filter/connected_components/CellSetConnectivity.h
Normal file
46
vtkm/filter/connected_components/CellSetConnectivity.h
Normal file
@ -0,0 +1,46 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_connected_components_CellSetConnectivity_h
|
||||
#define vtk_m_filter_connected_components_CellSetConnectivity_h
|
||||
|
||||
#include <vtkm/filter/NewFilterField.h>
|
||||
#include <vtkm/filter/connected_components/vtkm_filter_connected_components_export.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace connected_components
|
||||
{
|
||||
/// \brief Finds groups of cells that are connected together through their topology.
|
||||
///
|
||||
/// Finds and labels groups of cells that are connected together through their topology.
|
||||
/// Two cells are considered connected if they share an edge. CellSetConnectivity identifies some
|
||||
/// number of components and assigns each component a unique integer.
|
||||
/// The result of the filter is a cell field of type vtkm::Id with the default name of 'component'.
|
||||
/// Each entry in the cell field will be a number that identifies to which component the cell belongs.
|
||||
class VTKM_FILTER_CONNECTED_COMPONENTS_EXPORT CellSetConnectivity
|
||||
: public vtkm::filter::NewFilterField
|
||||
{
|
||||
public:
|
||||
VTKM_CONT CellSetConnectivity() { this->SetOutputFieldName("component"); }
|
||||
|
||||
private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
|
||||
std::string OutputFieldName;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtk_m_filter_connected_components_CellSetConnectivity_h
|
45
vtkm/filter/connected_components/ImageConnectivity.cxx
Normal file
45
vtkm/filter/connected_components/ImageConnectivity.cxx
Normal file
@ -0,0 +1,45 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/filter/CreateResult.h>
|
||||
#include <vtkm/filter/connected_components/ImageConnectivity.h>
|
||||
#include <vtkm/filter/connected_components/worklet/ImageConnectivity.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace connected_components
|
||||
{
|
||||
VTKM_CONT vtkm::cont::DataSet ImageConnectivity::DoExecute(const vtkm::cont::DataSet& input)
|
||||
{
|
||||
const auto& field = this->GetFieldFromDataSet(input);
|
||||
|
||||
if (!field.IsFieldPoint())
|
||||
{
|
||||
throw vtkm::cont::ErrorBadValue("Active field for ImageConnectivity must be a point field.");
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
|
||||
auto resolveType = [&](const auto& concrete) {
|
||||
vtkm::worklet::connectivity::ImageConnectivity().Run(input.GetCellSet(), concrete, component);
|
||||
};
|
||||
const auto& fieldArray = field.GetData();
|
||||
this->CastAndCallScalarField(fieldArray, resolveType);
|
||||
|
||||
auto output = CreateResultFieldPoint(input, component, this->GetOutputFieldName());
|
||||
this->MapFieldsOntoOutput(input, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
} // namespace connected_components
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
47
vtkm/filter/connected_components/ImageConnectivity.h
Normal file
47
vtkm/filter/connected_components/ImageConnectivity.h
Normal file
@ -0,0 +1,47 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#ifndef vtk_m_filter_connected_components_ImageConnectivity_h
|
||||
#define vtk_m_filter_connected_components_ImageConnectivity_h
|
||||
|
||||
#include <vtkm/filter/NewFilterField.h>
|
||||
#include <vtkm/filter/connected_components/vtkm_filter_connected_components_export.h>
|
||||
|
||||
/// \brief Groups connected points that have the same field value
|
||||
///
|
||||
///
|
||||
/// The ImageConnectivity filter finds groups of points that have the same field value and are
|
||||
/// connected together through their topology. Any point is considered to be connected to its Moore neighborhood:
|
||||
/// 8 neighboring points for 2D and 27 neighboring points for 3D. As the name implies, ImageConnectivity only
|
||||
/// works on data with a structured cell set. You will get an error if you use any other type of cell set.
|
||||
/// The active field passed to the filter must be associated with the points.
|
||||
/// The result of the filter is a point field of type vtkm::Id. Each entry in the point field will be a number that
|
||||
/// identifies to which region it belongs. By default, this output point field is named “component”.
|
||||
namespace vtkm
|
||||
{
|
||||
namespace filter
|
||||
{
|
||||
namespace connected_components
|
||||
{
|
||||
class VTKM_FILTER_CONNECTED_COMPONENTS_EXPORT ImageConnectivity
|
||||
: public vtkm::filter::NewFilterField
|
||||
{
|
||||
public:
|
||||
VTKM_CONT ImageConnectivity() { this->SetOutputFieldName("component"); }
|
||||
|
||||
private:
|
||||
VTKM_CONT
|
||||
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
|
||||
};
|
||||
} // namespace connected_components
|
||||
} // namespace filter
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_filter_connected_components_ImageConnectivity_h
|
27
vtkm/filter/connected_components/testing/CMakeLists.txt
Normal file
27
vtkm/filter/connected_components/testing/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestCellSetConnectivityFilter.cxx
|
||||
UnitTestImageConnectivityFilter.cxx
|
||||
)
|
||||
|
||||
set(libraries
|
||||
vtkm_filter_contour
|
||||
vtkm_filter_connected_components
|
||||
vtkm_source
|
||||
)
|
||||
|
||||
vtkm_unit_tests(
|
||||
SOURCES ${unit_tests}
|
||||
LIBRARIES ${libraries}
|
||||
ALL_BACKENDS # uses vtkm::cont::Algorithm
|
||||
USE_VTKM_JOB_POOL
|
||||
)
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/CellSetConnectivity.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/filter/connected_components/CellSetConnectivity.h>
|
||||
#include <vtkm/source/Tangle.h>
|
||||
|
||||
namespace
|
||||
@ -34,7 +34,7 @@ public:
|
||||
filter.SetActiveField("tangle");
|
||||
vtkm::cont::DataSet iso = filter.Execute(dataSet);
|
||||
|
||||
vtkm::filter::CellSetConnectivity connectivity;
|
||||
vtkm::filter::connected_components::CellSetConnectivity connectivity;
|
||||
const vtkm::cont::DataSet output = connectivity.Execute(iso);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
||||
@ -52,7 +52,7 @@ public:
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet5();
|
||||
|
||||
vtkm::filter::CellSetConnectivity connectivity;
|
||||
vtkm::filter::connected_components::CellSetConnectivity connectivity;
|
||||
const vtkm::cont::DataSet output = connectivity.Execute(dataSet);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
||||
@ -69,7 +69,7 @@ public:
|
||||
void TestUniformDataSet() const
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::filter::CellSetConnectivity connectivity;
|
||||
vtkm::filter::connected_components::CellSetConnectivity connectivity;
|
||||
const vtkm::cont::DataSet output = connectivity.Execute(dataSet);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
@ -8,7 +8,7 @@
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/filter/ImageConnectivity.h>
|
||||
#include <vtkm/filter/connected_components/ImageConnectivity.h>
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
@ -39,7 +39,7 @@ void TestImageConnectivity()
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = MakeTestDataSet();
|
||||
|
||||
vtkm::filter::ImageConnectivity connectivity;
|
||||
vtkm::filter::connected_components::ImageConnectivity connectivity;
|
||||
connectivity.SetActiveField("color");
|
||||
|
||||
const vtkm::cont::DataSet outputData = connectivity.Execute(dataSet);
|
0
vtkm/worklet/connectivities/CMakeLists.txt → vtkm/filter/connected_components/worklet/CMakeLists.txt
0
vtkm/worklet/connectivities/CMakeLists.txt → vtkm/filter/connected_components/worklet/CMakeLists.txt
@ -10,8 +10,8 @@
|
||||
#ifndef vtk_m_worklet_connectivity_CellSetConnectivity_h
|
||||
#define vtk_m_worklet_connectivity_CellSetConnectivity_h
|
||||
|
||||
#include <vtkm/worklet/connectivities/CellSetDualGraph.h>
|
||||
#include <vtkm/worklet/connectivities/GraphConnectivity.h>
|
||||
#include <vtkm/filter/connected_components/worklet/CellSetDualGraph.h>
|
||||
#include <vtkm/filter/connected_components/worklet/GraphConnectivity.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
@ -12,9 +12,9 @@
|
||||
#define vtk_m_worklet_connectivity_graph_connectivity_h
|
||||
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/worklet/connectivities/CellSetDualGraph.h>
|
||||
#include <vtkm/worklet/connectivities/InnerJoin.h>
|
||||
#include <vtkm/worklet/connectivities/UnionFind.h>
|
||||
#include <vtkm/filter/connected_components/worklet/CellSetDualGraph.h>
|
||||
#include <vtkm/filter/connected_components/worklet/InnerJoin.h>
|
||||
#include <vtkm/filter/connected_components/worklet/UnionFind.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
@ -11,14 +11,15 @@
|
||||
#ifndef vtk_m_worklet_connectivity_ImageConnectivity_h
|
||||
#define vtk_m_worklet_connectivity_ImageConnectivity_h
|
||||
|
||||
#include <vtkm/cont/Algorithm.h>
|
||||
#include <vtkm/cont/Invoker.h>
|
||||
#include <vtkm/cont/UncertainArrayHandle.h>
|
||||
#include <vtkm/cont/UncertainCellSet.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
#include <vtkm/worklet/WorkletPointNeighborhood.h>
|
||||
|
||||
#include <vtkm/worklet/connectivities/InnerJoin.h>
|
||||
#include <vtkm/worklet/connectivities/UnionFind.h>
|
||||
#include <vtkm/filter/connected_components/worklet/InnerJoin.h>
|
||||
#include <vtkm/filter/connected_components/worklet/UnionFind.h>
|
||||
|
||||
|
||||
namespace vtkm
|
||||
@ -41,7 +42,7 @@ public:
|
||||
using ExecutionSignature = void(Boundary, _2, _3, _4);
|
||||
|
||||
|
||||
// compOut is a "linear" alias of neightborComp such that we can update component labels
|
||||
// compOut is a "linear" alias of neighborComp such that we can update component labels
|
||||
template <typename Boundary,
|
||||
typename NeighborComp,
|
||||
typename NeighborColor,
|
||||
@ -80,7 +81,7 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
// Single pass connected component algorithm from
|
||||
// Jaiganesh, Jayadharini, and Martin Burtscher.
|
||||
@ -153,8 +154,8 @@ public:
|
||||
.CastAndCall(ResolveUnknownCellSet(), pixels, componentsOut);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace connectivity
|
||||
} // namespace worklet
|
||||
} // namespace vtkm
|
||||
|
||||
#endif // vtk_m_worklet_connectivity_ImageConnectivity_h
|
@ -15,7 +15,6 @@ set(headers
|
||||
set(unit_tests
|
||||
UnitTestCellAverageFilter.cxx
|
||||
UnitTestCellMeasuresFilter.cxx
|
||||
UnitTestCellSetConnectivityFilter.cxx
|
||||
UnitTestClipWithFieldFilter.cxx
|
||||
UnitTestClipWithImplicitFunctionFilter.cxx
|
||||
UnitTestContourFilter.cxx
|
||||
@ -30,7 +29,6 @@ set(unit_tests
|
||||
UnitTestGradientExplicit.cxx
|
||||
UnitTestGradientUniform.cxx
|
||||
UnitTestGhostCellClassify.cxx
|
||||
UnitTestImageConnectivityFilter.cxx
|
||||
UnitTestImageDifferenceFilter.cxx
|
||||
UnitTestImageMedianFilter.cxx
|
||||
UnitTestLagrangianFilter.cxx
|
||||
|
@ -110,7 +110,6 @@ add_subdirectory(internal)
|
||||
add_subdirectory(cellmetrics)
|
||||
add_subdirectory(clip)
|
||||
add_subdirectory(colorconversion)
|
||||
add_subdirectory(connectivities)
|
||||
add_subdirectory(contour)
|
||||
add_subdirectory(contourtree)
|
||||
add_subdirectory(contourtree_augmented)
|
||||
|
@ -19,8 +19,6 @@ set(unit_tests
|
||||
UnitTestCellAverage.cxx
|
||||
UnitTestCellDeepCopy.cxx
|
||||
UnitTestCellGradient.cxx
|
||||
UnitTestCellSetConnectivity.cxx
|
||||
UnitTestCellSetDualGraph.cxx
|
||||
UnitTestCellMeasure.cxx
|
||||
UnitTestClipping.cxx
|
||||
UnitTestContour.cxx
|
||||
@ -31,9 +29,6 @@ set(unit_tests
|
||||
UnitTestCosmoTools.cxx
|
||||
UnitTestDescriptiveStatistics.cxx
|
||||
UnitTestFieldStatistics.cxx
|
||||
UnitTestGraphConnectivity.cxx
|
||||
UnitTestInnerJoin.cxx
|
||||
UnitTestImageConnectivity.cxx
|
||||
UnitTestKeys.cxx
|
||||
UnitTestMagnitude.cxx
|
||||
UnitTestMaskIndices.cxx
|
||||
@ -43,7 +38,6 @@ set(unit_tests
|
||||
UnitTestOrientNormals.cxx
|
||||
UnitTestParticleAdvection.cxx
|
||||
UnitTestPointElevation.cxx
|
||||
UnitTestPointerJumping.cxx
|
||||
UnitTestPointGradient.cxx
|
||||
UnitTestPointTransform.cxx
|
||||
UnitTestProbe.cxx
|
||||
|
@ -1,88 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/filter/Contour.h>
|
||||
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
|
||||
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/source/Tangle.h>
|
||||
|
||||
class TestCellSetConnectivity
|
||||
{
|
||||
public:
|
||||
void TestTangleIsosurface() const
|
||||
{
|
||||
vtkm::Id3 dims(4, 4, 4);
|
||||
vtkm::source::Tangle tangle(dims);
|
||||
vtkm::cont::DataSet dataSet = tangle.Execute();
|
||||
|
||||
vtkm::filter::Contour filter;
|
||||
filter.SetGenerateNormals(true);
|
||||
filter.SetMergeDuplicatePoints(true);
|
||||
filter.SetIsoValue(0, 0.1);
|
||||
filter.SetActiveField("tangle");
|
||||
vtkm::cont::DataSet outputData = filter.Execute(dataSet);
|
||||
|
||||
auto cellSet = outputData.GetCellSet().AsCellSet<vtkm::cont::CellSetSingleType<>>();
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
||||
|
||||
using Algorithm = vtkm::cont::Algorithm;
|
||||
Algorithm::Sort(componentArray);
|
||||
Algorithm::Unique(componentArray);
|
||||
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 8,
|
||||
"Wrong number of connected components");
|
||||
}
|
||||
|
||||
void TestExplicitDataSet() const
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet5();
|
||||
|
||||
auto cellSet = dataSet.GetCellSet().AsCellSet<vtkm::cont::CellSetExplicit<>>();
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
||||
|
||||
using Algorithm = vtkm::cont::Algorithm;
|
||||
Algorithm::Sort(componentArray);
|
||||
Algorithm::Unique(componentArray);
|
||||
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1,
|
||||
"Wrong number of connected components");
|
||||
}
|
||||
|
||||
void TestUniformDataSet() const
|
||||
{
|
||||
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1();
|
||||
|
||||
auto cellSet = dataSet.GetCellSet();
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
||||
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
||||
|
||||
using Algorithm = vtkm::cont::Algorithm;
|
||||
Algorithm::Sort(componentArray);
|
||||
Algorithm::Unique(componentArray);
|
||||
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1,
|
||||
"Wrong number of connected components");
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
this->TestTangleIsosurface();
|
||||
this->TestExplicitDataSet();
|
||||
this->TestUniformDataSet();
|
||||
}
|
||||
};
|
||||
|
||||
int UnitTestCellSetConnectivity(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestCellSetConnectivity(), argc, argv);
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/ArrayHandleGroupVecVariable.h>
|
||||
#include <vtkm/cont/ConvertNumComponentsToOffsets.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
|
||||
#include <vtkm/worklet/connectivities/CellSetDualGraph.h>
|
||||
|
||||
class TestCellSetDualGraph
|
||||
{
|
||||
private:
|
||||
using GroupedConnectivityArrayType =
|
||||
vtkm::cont::ArrayHandleGroupVecVariable<vtkm::cont::ArrayHandle<vtkm::Id>,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id>>;
|
||||
|
||||
static GroupedConnectivityArrayType MakeGroupedConnectivity(
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivity,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> counts)
|
||||
{
|
||||
return GroupedConnectivityArrayType(connectivity,
|
||||
vtkm::cont::ConvertNumComponentsToOffsets(counts));
|
||||
}
|
||||
|
||||
static bool TestConnectivity(GroupedConnectivityArrayType computedConnectivityArray,
|
||||
GroupedConnectivityArrayType expectedConnectivityArray)
|
||||
{
|
||||
auto computedConnections = computedConnectivityArray.ReadPortal();
|
||||
auto expectedConnections = expectedConnectivityArray.ReadPortal();
|
||||
|
||||
vtkm::Id numItems = computedConnections.GetNumberOfValues();
|
||||
if (numItems != expectedConnections.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (vtkm::Id itemIndex = 0; itemIndex < numItems; ++itemIndex)
|
||||
{
|
||||
auto computed = computedConnections.Get(itemIndex);
|
||||
auto expected = expectedConnections.Get(itemIndex);
|
||||
vtkm::IdComponent numConnections = computed.GetNumberOfComponents();
|
||||
if (numConnections != expected.GetNumberOfComponents())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// computed and expected are Vec-like objects that should represent the same thing.
|
||||
// However, although both should have the same indices, they may be in different
|
||||
// orders.
|
||||
std::set<vtkm::Id> computedSet;
|
||||
std::set<vtkm::Id> expectedSet;
|
||||
for (vtkm::IdComponent componentIndex = 0; componentIndex < numConnections; ++componentIndex)
|
||||
{
|
||||
computedSet.insert(computed[componentIndex]);
|
||||
expectedSet.insert(expected[componentIndex]);
|
||||
}
|
||||
if (computedSet != expectedSet)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
void TestTriangleMesh() const
|
||||
{
|
||||
auto connectivity = vtkm::cont::make_ArrayHandle<vtkm::Id>(
|
||||
{ 0, 2, 4, 1, 3, 5, 2, 6, 4, 5, 3, 7, 2, 9, 6, 4, 6, 8 });
|
||||
|
||||
vtkm::cont::CellSetSingleType<> cellSet;
|
||||
cellSet.Fill(10, vtkm::CELL_SHAPE_TRIANGLE, 3, connectivity);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> numIndicesArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> indexOffsetArray;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> connectivityArray;
|
||||
|
||||
vtkm::worklet::connectivity::CellSetDualGraph().Run(
|
||||
cellSet, numIndicesArray, indexOffsetArray, connectivityArray);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedNumIndices =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 3, 1, 1, 1 });
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal_portals(numIndicesArray.ReadPortal(), expectedNumIndices.ReadPortal()));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedIndexOffset =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1, 2, 5, 6, 7 });
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal_portals(indexOffsetArray.ReadPortal(), expectedIndexOffset.ReadPortal()));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedConnectivity =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 2, 3, 0, 4, 5, 1, 2, 2 });
|
||||
VTKM_TEST_ASSERT(
|
||||
TestConnectivity(MakeGroupedConnectivity(connectivityArray, numIndicesArray),
|
||||
MakeGroupedConnectivity(expectedConnectivity, numIndicesArray)));
|
||||
}
|
||||
|
||||
void operator()() const { this->TestTriangleMesh(); }
|
||||
};
|
||||
|
||||
int UnitTestCellSetDualGraph(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestCellSetDualGraph(), argc, argv);
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/worklet/connectivities/GraphConnectivity.h>
|
||||
|
||||
class AdjacentDifference : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(FieldIn index, WholeArrayIn counts, FieldOut outputCount);
|
||||
using ExecutionSignature = void(_1, _2, _3);
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename WholeArrayType>
|
||||
VTKM_EXEC void operator()(const vtkm::Id& index,
|
||||
const WholeArrayType& counts,
|
||||
int& difference) const
|
||||
{
|
||||
difference = counts.Get(index + 1) - counts.Get(index);
|
||||
}
|
||||
};
|
||||
|
||||
class SameComponent : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(FieldIn start,
|
||||
FieldIn degree,
|
||||
WholeArrayIn conns,
|
||||
WholeArrayIn comps,
|
||||
AtomicArrayInOut same);
|
||||
using ExecutionSignature = void(WorkIndex, _1, _2, _3, _4, _5);
|
||||
|
||||
template <typename Conn, typename Comp, typename AtomicSame>
|
||||
VTKM_EXEC void operator()(vtkm::Id index,
|
||||
int start,
|
||||
int degree,
|
||||
const Conn& conns,
|
||||
const Comp& comps,
|
||||
AtomicSame& same) const
|
||||
{
|
||||
for (vtkm::Id offset = start; offset < start + degree; ++offset)
|
||||
{
|
||||
vtkm::Id neighbor = conns.Get(offset);
|
||||
if (comps.Get(index) != comps.Get(neighbor))
|
||||
{
|
||||
same.Set(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TestGraphConnectivity
|
||||
{
|
||||
public:
|
||||
void TestECL_CC(const std::string& filename, int ncomps) const
|
||||
{
|
||||
auto pathname =
|
||||
vtkm::cont::testing::Testing::GetTestDataBasePath() + "/third_party/ecl_cc/" + filename;
|
||||
std::ifstream stream(pathname, std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
int nnodes;
|
||||
stream.read(reinterpret_cast<char*>(&nnodes), sizeof(nnodes));
|
||||
|
||||
int nedges;
|
||||
stream.read(reinterpret_cast<char*>(&nedges), sizeof(nedges));
|
||||
|
||||
// CSR, there is one more element in offsets thant the actual number of nodes.
|
||||
std::vector<int> offsets(nnodes + 1);
|
||||
std::vector<int> conns(nedges);
|
||||
|
||||
stream.read(reinterpret_cast<char*>(offsets.data()), (nnodes + 1) * sizeof(int));
|
||||
stream.read(reinterpret_cast<char*>(conns.data()), nedges * sizeof(int));
|
||||
|
||||
vtkm::cont::ArrayHandle<int> counts_h;
|
||||
vtkm::cont::Invoker invoke;
|
||||
invoke(AdjacentDifference{},
|
||||
vtkm::cont::make_ArrayHandleCounting(0, 1, nnodes),
|
||||
vtkm::cont::make_ArrayHandle<int>(offsets, vtkm::CopyFlag::On),
|
||||
counts_h);
|
||||
|
||||
offsets.pop_back();
|
||||
vtkm::cont::ArrayHandle<int> offsets_h =
|
||||
vtkm::cont::make_ArrayHandle(offsets, vtkm::CopyFlag::On);
|
||||
|
||||
vtkm::cont::ArrayHandle<int> conns_h = vtkm::cont::make_ArrayHandle(conns, vtkm::CopyFlag::Off);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> comps_h;
|
||||
vtkm::worklet::connectivity::GraphConnectivity().Run(counts_h, offsets_h, conns_h, comps_h);
|
||||
|
||||
VTKM_TEST_ASSERT(vtkm::cont::Algorithm::Reduce(comps_h, vtkm::Id(0), vtkm::Maximum{}) ==
|
||||
ncomps - 1,
|
||||
"number of components mismatch");
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::UInt32> atomicSame;
|
||||
atomicSame.Allocate(1);
|
||||
atomicSame.WritePortal().Set(0, 1);
|
||||
|
||||
invoke(SameComponent{}, offsets_h, counts_h, conns_h, comps_h, atomicSame);
|
||||
VTKM_TEST_ASSERT(atomicSame.ReadPortal().Get(0) == 1,
|
||||
"Neighboring nodes don't have the same component id");
|
||||
}
|
||||
|
||||
void TestECL_CC_DataSets() const { TestECL_CC("internet.egr", 1); }
|
||||
|
||||
void TestSimpleGraph() const
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> counts_h =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 2, 2, 2 });
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> offsets_h =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1, 2, 4, 6 });
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> conn_h =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 2, 4, 0, 3, 2, 4, 1, 3 });
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> comps;
|
||||
|
||||
vtkm::worklet::connectivity::GraphConnectivity().Run(counts_h, offsets_h, conn_h, comps);
|
||||
|
||||
for (int i = 0; i < comps.GetNumberOfValues(); i++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(comps.ReadPortal().Get(i) == 0, "Components has unexpected value.");
|
||||
}
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
TestSimpleGraph();
|
||||
TestECL_CC_DataSets();
|
||||
}
|
||||
};
|
||||
|
||||
int UnitTestGraphConnectivity(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestGraphConnectivity(), argc, argv);
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <vtkm/worklet/connectivities/ImageConnectivity.h>
|
||||
|
||||
class TestImageConnectivity
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::Algorithm;
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
CCL_CUDA8x4();
|
||||
CCL_CUDA8x8();
|
||||
Valentine();
|
||||
}
|
||||
|
||||
void CCL_CUDA8x4() const
|
||||
{
|
||||
// example image from Connected Component Labeling in CUDA by OndˇrejˇŚtava,
|
||||
// Bedˇrich Beneˇ
|
||||
std::vector<vtkm::UInt8> pixels(8 * 4, 0);
|
||||
pixels[3] = pixels[4] = pixels[10] = pixels[11] = 1;
|
||||
pixels[1] = pixels[9] = pixels[16] = pixels[17] = pixels[24] = pixels[25] = 1;
|
||||
pixels[7] = pixels[15] = pixels[21] = pixels[23] = pixels[28] = pixels[29] = pixels[30] =
|
||||
pixels[31] = 1;
|
||||
|
||||
vtkm::cont::DataSetBuilderUniform builder;
|
||||
vtkm::cont::DataSet data = builder.Create(vtkm::Id3(8, 4, 1));
|
||||
|
||||
auto colorField = vtkm::cont::make_FieldPoint(
|
||||
"color", vtkm::cont::make_ArrayHandle(pixels, vtkm::CopyFlag::On));
|
||||
data.AddField(colorField);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
vtkm::worklet::connectivity::ImageConnectivity().Run(
|
||||
data.GetCellSet().AsCellSet<vtkm::cont::CellSetStructured<2>>(),
|
||||
colorField.GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::UInt8>>(),
|
||||
component);
|
||||
|
||||
std::vector<vtkm::Id> componentExpected = { 0, 1, 2, 1, 1, 3, 3, 4, 0, 1, 1, 1, 3, 3, 3, 4,
|
||||
1, 1, 3, 3, 3, 4, 3, 4, 1, 1, 3, 3, 4, 4, 4, 4 };
|
||||
|
||||
|
||||
std::size_t i = 0;
|
||||
for (vtkm::Id index = 0; index < component.GetNumberOfValues(); index++, i++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(component.ReadPortal().Get(index) == componentExpected[i],
|
||||
"Components has unexpected value.");
|
||||
}
|
||||
}
|
||||
|
||||
void CCL_CUDA8x8() const
|
||||
{
|
||||
// example from Figure 35.7 of Connected Component Labeling in CUDA by OndˇrejˇŚtava,
|
||||
// Bedˇrich Beneˇ
|
||||
auto pixels = vtkm::cont::make_ArrayHandle<vtkm::UInt8>({
|
||||
0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
|
||||
1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1,
|
||||
1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
|
||||
});
|
||||
|
||||
vtkm::cont::DataSetBuilderUniform builder;
|
||||
vtkm::cont::DataSet data = builder.Create(vtkm::Id3(8, 8, 1));
|
||||
|
||||
auto colorField = vtkm::cont::make_FieldPoint("color", pixels);
|
||||
data.AddField(colorField);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
vtkm::worklet::connectivity::ImageConnectivity().Run(
|
||||
data.GetCellSet().AsCellSet<vtkm::cont::CellSetStructured<2>>(),
|
||||
colorField.GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::UInt8>>(),
|
||||
component);
|
||||
|
||||
std::vector<vtkm::UInt8> componentExpected = { 0, 1, 1, 1, 0, 1, 1, 2, 0, 0, 0, 1, 0, 1, 1, 2,
|
||||
0, 1, 1, 0, 0, 1, 1, 2, 0, 1, 0, 0, 0, 1, 1, 2,
|
||||
0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
|
||||
0, 1, 0, 1, 1, 1, 3, 3, 0, 1, 1, 1, 1, 1, 3, 3 };
|
||||
|
||||
for (vtkm::Id i = 0; i < component.GetNumberOfValues(); ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(component.ReadPortal().Get(i) == componentExpected[size_t(i)],
|
||||
"Components has unexpected value.");
|
||||
}
|
||||
}
|
||||
|
||||
void Valentine() const
|
||||
{
|
||||
// Sample image by VALENTINE PELTIER
|
||||
|
||||
// clang-format off
|
||||
auto pixels = vtkm::cont::make_ArrayHandle<vtkm::UInt8>( {
|
||||
1, 1, 0, 1, 0, 0,
|
||||
0, 0, 0, 1, 1, 0,
|
||||
1, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 0, 0,
|
||||
0, 1, 0, 1, 1, 1,
|
||||
1, 1, 0, 0, 1, 0,
|
||||
});
|
||||
// clang-format on
|
||||
|
||||
vtkm::cont::DataSetBuilderUniform builder;
|
||||
vtkm::cont::DataSet data = builder.Create(vtkm::Id3(6, 6, 1));
|
||||
|
||||
auto colorField = vtkm::cont::make_FieldPoint("color", pixels);
|
||||
data.AddField(colorField);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> component;
|
||||
vtkm::worklet::connectivity::ImageConnectivity().Run(
|
||||
data.GetCellSet().AsCellSet<vtkm::cont::CellSetStructured<2>>(),
|
||||
colorField.GetData().AsArrayHandle<vtkm::cont::ArrayHandle<vtkm::UInt8>>(),
|
||||
component);
|
||||
|
||||
// clang-format off
|
||||
std::vector<vtkm::UInt8> componentExpected = {
|
||||
0, 0, 1, 2, 1, 1,
|
||||
1, 1, 1, 2, 2, 1,
|
||||
2, 2, 1, 2, 1, 2,
|
||||
2, 1, 2, 1, 1, 1,
|
||||
1, 2, 1, 2, 2, 2,
|
||||
2, 2, 1, 1, 2, 3
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
for (vtkm::Id i = 0; i < component.GetNumberOfValues(); ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(component.ReadPortal().Get(i) == componentExpected[size_t(i)],
|
||||
"Components has unexpected value.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int UnitTestImageConnectivity(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestImageConnectivity(), argc, argv);
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/worklet/connectivities/InnerJoin.h>
|
||||
|
||||
|
||||
class TestInnerJoin
|
||||
{
|
||||
public:
|
||||
static bool TestJoinedValues(const vtkm::cont::ArrayHandle<vtkm::Id>& computedValuesArray,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& expectedValuesArray,
|
||||
const vtkm::cont::ArrayHandle<vtkm::Id>& originalKeysArray)
|
||||
{
|
||||
auto computedValues = computedValuesArray.ReadPortal();
|
||||
auto expectedValues = expectedValuesArray.ReadPortal();
|
||||
auto originalKeys = originalKeysArray.ReadPortal();
|
||||
if (computedValues.GetNumberOfValues() != expectedValues.GetNumberOfValues())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (vtkm::Id valueIndex = 0; valueIndex < computedValues.GetNumberOfValues(); ++valueIndex)
|
||||
{
|
||||
vtkm::Id computed = computedValues.Get(valueIndex);
|
||||
vtkm::Id expected = expectedValues.Get(valueIndex);
|
||||
|
||||
// The join algorithm uses some key/value sorts that are unstable. Thus, for keys
|
||||
// that are repeated in the original input, the computed and expected values may be
|
||||
// swapped in the results associated with those keys. To test correctly, the values
|
||||
// we computed for are actually indices into the original keys array. Thus, if both
|
||||
// computed and expected are different indices that point to the same original key,
|
||||
// then the algorithm is still correct.
|
||||
vtkm::Id computedKey = originalKeys.Get(computed);
|
||||
vtkm::Id expectedKey = originalKeys.Get(expected);
|
||||
if (computedKey != expectedKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestTwoArrays() const
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> keysAOriginal =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 8, 3, 6, 8, 9, 5, 12, 10, 14 });
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> keysBOriginal =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 7, 11, 9, 8, 5, 1, 0, 5 });
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> keysA;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> keysB;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> valuesA;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> valuesB;
|
||||
|
||||
vtkm::cont::ArrayCopy(keysAOriginal, keysA);
|
||||
vtkm::cont::ArrayCopy(keysBOriginal, keysB);
|
||||
vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(keysA.GetNumberOfValues()), valuesA);
|
||||
vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleIndex(keysB.GetNumberOfValues()), valuesB);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> joinedIndex;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> outA;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> outB;
|
||||
|
||||
vtkm::worklet::connectivity::InnerJoin().Run(
|
||||
keysA, valuesA, keysB, valuesB, joinedIndex, outA, outB);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedIndex =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 5, 5, 8, 8, 9 });
|
||||
VTKM_TEST_ASSERT(test_equal_portals(joinedIndex.ReadPortal(), expectedIndex.ReadPortal()));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedOutA =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 5, 5, 0, 3, 4 });
|
||||
VTKM_TEST_ASSERT(TestJoinedValues(outA, expectedOutA, keysAOriginal));
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> expectedOutB =
|
||||
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 4, 7, 3, 3, 2 });
|
||||
VTKM_TEST_ASSERT(TestJoinedValues(outB, expectedOutB, keysBOriginal));
|
||||
}
|
||||
|
||||
void operator()() const { this->TestTwoArrays(); }
|
||||
};
|
||||
|
||||
int UnitTestInnerJoin(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestInnerJoin(), argc, argv);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/ArrayCopy.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/worklet/connectivities/UnionFind.h>
|
||||
|
||||
void TestLinear()
|
||||
{
|
||||
const vtkm::Id N = 100;
|
||||
auto counting = vtkm::cont::make_ArrayHandleCounting(-1, 1, N - 1);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> parents;
|
||||
vtkm::cont::ArrayCopy(counting, parents);
|
||||
parents.WritePortal().Set(0, 0);
|
||||
|
||||
vtkm::cont::Invoker invoker;
|
||||
invoker(vtkm::worklet::connectivity::PointerJumping{}, parents);
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal_ArrayHandles(vtkm::cont::ArrayHandleConstant<vtkm::Id>(0, N - 1), parents));
|
||||
}
|
||||
|
||||
void TestPointerJumping()
|
||||
{
|
||||
TestLinear();
|
||||
}
|
||||
|
||||
int UnitTestPointerJumping(int argc, char* argv[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestPointerJumping, argc, argv);
|
||||
}
|
Loading…
Reference in New Issue
Block a user