Migrate MIR filter

This commit is contained in:
Li-Ta Lo 2022-05-16 09:21:00 -06:00
parent 3b8ead6cb2
commit 0a0e30858e
13 changed files with 73 additions and 145 deletions

@ -17,6 +17,7 @@
#include <vtkm/filter/vector_analysis/Gradient.h>
#include <functional>
namespace
{

@ -38,6 +38,7 @@ set(deprecated_headers
Mask.h
MaskPoints.h
MeshQuality.h
# MIRFilter.h
NDEntropy.h
NDHistogram.h
ParticleDensityCloudInCell.h
@ -102,7 +103,6 @@ set(extra_headers
ContourTreeUniform.h
Lagrangian.h
LagrangianStructures.h
MIRFilter.h
ParticleAdvection.h
Pathline.h
PathParticle.h
@ -118,7 +118,6 @@ set(extra_header_template_sources
ContourTreeUniform.hxx
Lagrangian.hxx
LagrangianStructures.hxx
MIRFilter.hxx
ParticleAdvection.hxx
Pathline.hxx
PathParticle.hxx

@ -12,6 +12,7 @@ set(contour_headers
ClipWithField.h
ClipWithImplicitFunction.h
Contour.h
MIRFilter.h
Slice.h
)
@ -19,6 +20,7 @@ set(contour_sources_device
ClipWithField.cxx
ClipWithImplicitFunction.cxx
Contour.cxx
MIRFilter.cxx
Slice.cxx
)

@ -8,39 +8,24 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_filter_MIRFilter_hxx
#define vtk_m_filter_MIRFilter_hxx
#include <vtkm/CellShape.h>
#include <vtkm/Types.h>
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/ArrayHandleView.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/filter/contour/worklet/clip/ClipTables.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/DispatcherReduceByKey.h>
#include <vtkm/worklet/Keys.h>
#include <vtkm/worklet/MIR.h>
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/WorkletReduceByKey.h>
#include <vtkm/filter/MapFieldPermutation.h>
#include <vtkm/filter/contour/MIRFilter.h>
#include <vtkm/filter/contour/worklet/MIR.h>
#include <vtkm/filter/mesh_info/worklet/MeshQuality.h>
#include <vtkm/worklet/Keys.h>
#include <vtkm/worklet/ScatterCounting.h>
namespace vtkm
{
/*
@ -50,31 +35,50 @@ namespace vtkm
*/
namespace filter
{
namespace contour
{
VTKM_CONT bool MIRFilter::DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field)
{
if (field.GetName().compare(this->pos_name) == 0 ||
field.GetName().compare(this->len_name) == 0 || field.GetName().compare(this->id_name) == 0 ||
field.GetName().compare(this->vf_name) == 0)
{
// Remember, we will map the field manually...
// Technically, this will be for all of them...thus ignore it
return false;
}
template <typename T, typename StorageType, typename StorageType2>
inline VTKM_CONT void MIRFilter::ProcessPointField(
const vtkm::cont::ArrayHandle<T, StorageType>& input,
vtkm::cont::ArrayHandle<T, StorageType2>& output)
{
vtkm::worklet::DestructPointWeightList destructWeightList;
this->Invoke(destructWeightList, this->MIRIDs, this->MIRWeights, input, output);
if (field.IsFieldPoint())
{
auto resolve = [&](const auto& concrete) {
using T = typename std::decay_t<decltype(concrete)>::ValueType;
vtkm::cont::ArrayHandle<T> outputArray;
vtkm::worklet::DestructPointWeightList destructWeightList;
this->Invoke(destructWeightList, this->MIRIDs, this->MIRWeights, concrete, outputArray);
result.AddPointField(field.GetName(), outputArray);
};
field.GetData()
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListField, VTKM_DEFAULT_STORAGE_LIST>(
resolve);
}
else if (field.IsFieldCell())
{
return vtkm::filter::MapFieldPermutation(field, this->filterCellInterp, result);
}
else
{
return false;
}
return false;
}
//-----------------------------------------------------------------------------
template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(
const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(const vtkm::cont::DataSet& input)
{
//{
//(void)input;
//(void)policy;
vtkm::worklet::CheckFor2D cellCheck;
vtkm::cont::ArrayHandle<vtkm::Id> count2D, count3D, countBad;
this->Invoke(cellCheck,
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
count2D,
count3D,
countBad);
this->Invoke(cellCheck, input.GetCellSet(), count2D, count3D, countBad);
vtkm::Id c2 = vtkm::cont::Algorithm::Reduce(count2D, vtkm::Id(0));
vtkm::Id c3 = vtkm::cont::Algorithm::Reduce(count3D, vtkm::Id(0));
vtkm::Id cB = vtkm::cont::Algorithm::Reduce(countBad, vtkm::Id(0));
@ -102,10 +106,7 @@ inline VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(
vtkm::worklet::MeshQuality getVol;
getVol.SetMetric(c3 > 0 ? vtkm::filter::mesh_info::CellMetric::Volume
: vtkm::filter::mesh_info::CellMetric::Area);
this->Invoke(getVol,
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this),
inputCoords.GetData(),
avgSizeTot);
this->Invoke(getVol, input.GetCellSet(), inputCoords.GetData(), avgSizeTot);
// First, load up all fields...
vtkm::cont::Field or_pos = input.GetField(this->pos_name);
vtkm::cont::Field or_len = input.GetField(this->len_name);
@ -306,10 +307,7 @@ inline VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(
vtkm::cont::ArrayCopy(vfsOut, vfsdata);
// Clean up the cells by calculating their volumes, and then calculate the relative error for each cell.
// Note that the total error needs to be rescaled by the number of cells to get the % error.
totalError =
totalError /
vtkm::Float64(
vtkm::filter::ApplyPolicyCellSet(input.GetCellSet(), policy, *this).GetNumberOfCells());
totalError = totalError / vtkm::Float64(input.GetCellSet().GetNumberOfCells());
this->error_scaling *= this->scaling_decay;
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
@ -323,11 +321,9 @@ inline VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(
vtkm::cont::ArrayCopy(pointWeights, this->MIRWeights);
} while ((++currentIterationNum <= this->max_iter) && totalError >= this->max_error);
// FIXME: where and how should we call DoMapeField?
return saved;
}
}
}
#endif
} // namespace contour
} // namespace filter
} // namespace vtkm

@ -11,16 +11,15 @@
#ifndef vtkm_m_filter_MIRFilter_h
#define vtkm_m_filter_MIRFilter_h
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/filter/NewFilterField.h>
#include <vtkm/filter/contour/vtkm_filter_contour_export.h>
namespace vtkm
{
namespace filter
{
namespace contour
{
/// @brief Calculates and subdivides a mesh based on the material interface reconstruction algorithm.
///
/// Subdivides a mesh given volume fraction information for each _cell_. It does this by applying a
@ -49,7 +48,7 @@ namespace filter
/// total error % of the entire dataset is less than the specified amount (defaults to 1.0, returns after first iteration). Finally,
/// the error scaling and scaling decay allows for setting how much the cell VFs should react to the delta between target and calculated cell VFs.
/// the error scaling will decay by the decay variable every iteration (multiplicitively).
class MIRFilter : public vtkm::filter::FilterDataSet<MIRFilter>
class VTKM_FILTER_CONTOUR_EXPORT MIRFilter : public vtkm::filter::NewFilterField
{
public:
/// @brief Sets the name of the offset/position cellset field in the dataset passed to the filter
@ -69,61 +68,9 @@ public:
/// @brief Sets the output cell-set field name for the filter
VTKM_CONT void SetOutputFieldName(std::string name) { this->OutputFieldName = name; }
template <typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy>);
template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input1,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
(void)result;
(void)input1;
(void)fieldMeta;
if (fieldMeta.GetName().compare(this->pos_name) == 0 ||
fieldMeta.GetName().compare(this->len_name) == 0 ||
fieldMeta.GetName().compare(this->id_name) == 0 ||
fieldMeta.GetName().compare(this->vf_name) == 0)
{
// Remember, we will map the field manually...
// Technically, this will be for all of them...thus ignore it
return false;
}
vtkm::cont::ArrayHandle<T> output;
if (fieldMeta.IsPointField())
{
this->ProcessPointField(input1, output);
}
else if (fieldMeta.IsCellField())
{
this->ProcessCellField(input1, output);
}
else
{
return false;
}
result.AddField(fieldMeta.AsField(output));
return true;
}
private:
// Linear storage requirement, scales with size of point output
template <typename T, typename StorageType, typename StorageType2>
VTKM_CONT void ProcessPointField(const vtkm::cont::ArrayHandle<T, StorageType>& input,
vtkm::cont::ArrayHandle<T, StorageType2>& output);
// NOTE: The below assumes that MIR will not change the cell values when subdividing.
template <typename T, typename StorageType, typename StorageType2>
VTKM_CONT void ProcessCellField(const vtkm::cont::ArrayHandle<T, StorageType>& input,
vtkm::cont::ArrayHandle<T, StorageType2>& output)
{
// Use a temporary permutation array to simplify the mapping:
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->filterCellInterp, input);
vtkm::cont::ArrayCopy(tmp, output);
}
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input) override;
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, const vtkm::cont::Field& field);
std::string pos_name;
std::string len_name;
@ -138,12 +85,8 @@ private:
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 8>> MIRWeights;
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 8>> MIRIDs;
};
}
}
#ifndef vtk_m_filter_MIRFilter_hxx
#include <vtkm/filter/MIRFilter.hxx>
#endif
} // namespace contour
} // namespace filter
} // namespace vtkm
#endif

@ -12,6 +12,7 @@ set(unit_tests
UnitTestClipWithImplicitFunctionFilter.cxx
UnitTestContourFilter.cxx
UnitTestContourFilterNormals.cxx
UnitTestMIRFilter.cxx
)
set(libraries

@ -8,14 +8,15 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/MIRFilter.h>
#include <vtkm/filter/contour/MIRFilter.h>
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <stdio.h>
@ -204,7 +205,7 @@ void TestMIRVenn250()
data.AddField(
vtkm::cont::Field("scatter_vfs", vtkm::cont::Field::Association::WholeMesh, matVFs));
vtkm::filter::MIRFilter mir;
vtkm::filter::contour::MIRFilter mir;
mir.SetIDWholeSetName("scatter_ids");
mir.SetPositionCellSetName("scatter_pos");
mir.SetLengthCellSetName("scatter_len");
@ -229,7 +230,7 @@ void TestMIRSynthetic()
{
vtkm::cont::DataSet ds = GetTestDataSet();
vtkm::filter::MIRFilter mir;
vtkm::filter::contour::MIRFilter mir;
mir.SetIDWholeSetName("scatter_ids");
mir.SetPositionCellSetName("scatter_pos");
mir.SetLengthCellSetName("scatter_len");

@ -10,25 +10,13 @@
set(headers
Clip.h
contour/CommonState.h
Contour.h
contour/FieldPropagation.h
contour/FlyingEdges.h
contour/FlyingEdgesHelpers.h
contour/FlyingEdgesPass1.h
contour/FlyingEdgesPass2.h
contour/FlyingEdgesPass4.h
contour/FlyingEdgesPass4Common.h
contour/FlyingEdgesPass4X.h
contour/FlyingEdgesPass4XWithNormals.h
contour/FlyingEdgesPass4Y.h
contour/FlyingEdgesTables.h
contour/MarchingCellTables.h
contour/MarchingCells.h
MIR.h
)
add_subdirectory(clip)
add_subdirectory(contour)
add_subdirectory(mir)
#-----------------------------------------------------------------------------
vtkm_declare_headers(${headers})

@ -42,7 +42,7 @@
#include <vtkm/worklet/WorkletReduceByKey.h>
#include <vtkm/filter/contour/worklet/clip/ClipTables.h>
#include <vtkm/worklet/mir/MIRTables.h>
#include <vtkm/filter/contour/worklet/mir/MIRTables.h>
namespace vtkm
{

@ -22,7 +22,6 @@ set(unit_tests
UnitTestLagrangianStructuresFilter.cxx
UnitTestMapFieldMergeAverage.cxx
UnitTestMapFieldPermutation.cxx
UnitTestMIRFilter.cxx
UnitTestMultiBlockFilter.cxx
UnitTestPartitionedDataSetFilters.cxx
UnitTestProbe.cxx

@ -29,7 +29,6 @@ set(headers
MaskIndices.h
MaskNone.h
MaskSelect.h
MIR.h
NDimsHistMarginalization.h
Normalize.h
ParticleAdvection.h
@ -83,7 +82,6 @@ add_subdirectory(contourtree_augmented)
add_subdirectory(contourtree_distributed)
add_subdirectory(cosmotools)
add_subdirectory(lcs)
add_subdirectory(mir)
add_subdirectory(splatkernels)
add_subdirectory(spatialstructure)
add_subdirectory(wavelets)