From 8bb664de85b699620f851bf5e2e5a337c7a34cb0 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 17 Aug 2023 10:11:25 -0400 Subject: [PATCH] Support any cell type in MIR filter Previously, the MIR filter ran a check the dimensionality of the cells in its input data set to make sure they conformed to the algorithm. The only real reason this was necessary is because the `MeshQuality` filter can only check the size of either area or volume, and it has to know which one to check. However, the `CellMeasures` filter can compute the sizes of all types of cells simultaneously (as well as more cell types). By using this filter, the MIR filter can skip the cell type checks and support more mesh types. --- docs/changelog/mir-any-cell-type.md | 10 +++++++ vtkm/filter/contour/MIRFilter.cxx | 41 ++++---------------------- vtkm/filter/contour/worklet/MIR.h | 45 ----------------------------- 3 files changed, 16 insertions(+), 80 deletions(-) create mode 100644 docs/changelog/mir-any-cell-type.md diff --git a/docs/changelog/mir-any-cell-type.md b/docs/changelog/mir-any-cell-type.md new file mode 100644 index 000000000..354d9b6c8 --- /dev/null +++ b/docs/changelog/mir-any-cell-type.md @@ -0,0 +1,10 @@ +# Support any cell type in MIR filter + +Previously, the MIR filter ran a check the dimensionality of the cells in +its input data set to make sure they conformed to the algorithm. The only +real reason this was necessary is because the `MeshQuality` filter can only +check the size of either area or volume, and it has to know which one to +check. However, the `CellMeasures` filter can compute the sizes of all +types of cells simultaneously (as well as more cell types). By using this +filter, the MIR filter can skip the cell type checks and support more mesh +types. diff --git a/vtkm/filter/contour/MIRFilter.cxx b/vtkm/filter/contour/MIRFilter.cxx index 3ed9dabc5..5817f8827 100644 --- a/vtkm/filter/contour/MIRFilter.cxx +++ b/vtkm/filter/contour/MIRFilter.cxx @@ -21,18 +21,13 @@ #include #include -#include +#include #include #include namespace vtkm { -/* - Todos: - Enable some sort of cell culling, so if a cell doesn't have any work to do, it doesn't get called in future invocations of MIR - - */ namespace filter { namespace contour @@ -79,37 +74,13 @@ VTKM_CONT bool MIRFilter::DoMapField( //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(const vtkm::cont::DataSet& input) { - vtkm::worklet::CheckFor2D cellCheck; - vtkm::cont::ArrayHandle 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)); - if (cB > vtkm::Id(0)) - { - VTKM_LOG_S( - vtkm::cont::LogLevel::Fatal, - "Bad cell found in MIR filter input! Strictly only 2D -xor- 3D cell sets are permitted!"); - } - if (c2 > vtkm::Id(0) && c3 > vtkm::Id(0)) - { - VTKM_LOG_S( - vtkm::cont::LogLevel::Fatal, - "Bad cell mix found in MIR filter input! Input is not allowed to have both 2D and 3D cells."); - } - if (c2 == vtkm::Id(0) && c3 == vtkm::Id(0)) - { - VTKM_LOG_S(vtkm::cont::LogLevel::Fatal, - "No cells found for MIR filter! Please don't call me with nothing!"); - } - const vtkm::cont::CoordinateSystem inputCoords = input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()); vtkm::cont::ArrayHandle avgSizeTot; - vtkm::filter::mesh_info::MeshQuality getVol(c3 > 0 ? vtkm::filter::mesh_info::CellMetric::Volume - : vtkm::filter::mesh_info::CellMetric::Area); - getVol.SetOutputFieldName("size"); - vtkm::cont::ArrayCopyShallowIfPossible(getVol.Execute(input).GetCellField("size").GetData(), + vtkm::filter::mesh_info::CellMeasures getSize( + vtkm::filter::mesh_info::IntegrationType::AllMeasures); + getSize.SetCellMeasureName("size"); + vtkm::cont::ArrayCopyShallowIfPossible(getSize.Execute(input).GetCellField("size").GetData(), avgSizeTot); // First, load up all fields... vtkm::cont::Field or_pos = input.GetField(this->pos_name); @@ -275,7 +246,7 @@ VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(const vtkm::cont::DataSet& in // Hacking workaround to not clone an entire dataset. vtkm::cont::ArrayHandle avgSize; - vtkm::cont::ArrayCopyShallowIfPossible(getVol.Execute(saved).GetCellField("size").GetData(), + vtkm::cont::ArrayCopyShallowIfPossible(getSize.Execute(saved).GetCellField("size").GetData(), avgSize); vtkm::worklet::CalcError_C calcErrC; diff --git a/vtkm/filter/contour/worklet/MIR.h b/vtkm/filter/contour/worklet/MIR.h index 9cc8d5737..4ceea7af0 100644 --- a/vtkm/filter/contour/worklet/MIR.h +++ b/vtkm/filter/contour/worklet/MIR.h @@ -2304,51 +2304,6 @@ public: totalErrorOut = TEO(totalError); } }; -struct CheckFor2D : public vtkm::worklet::WorkletVisitCellsWithPoints -{ - using ControlSignature = void(CellSetIn, - FieldOutCell is2D, - FieldOutCell is3D, - FieldOutCell isOther); - using ExecutionSignature = void(CellShape, _2, _3, _4); - using InputDomain = _1; - template - VTKM_EXEC void operator()(const SHAPE shape, OO& is2D, OP& is3D, OQ& isOther) const - { - is2D = vtkm::Id(0); - is3D = vtkm::Id(0); - - if (shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::Id(6) // Tri strip? - || shape.Id == vtkm::Id(8) /* Pixel? */) - { - is2D = vtkm::Id(1); - } - else if (shape.Id == vtkm::Id(0) /*Empty*/ - || shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::Id(2) /* Poly Vertex? */) - { - isOther = vtkm::Id(1); - } - else if (shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::CellShapeIdToTag::Tag().Id || - shape.Id == vtkm::Id(11) /* Voxel? */) - { - is3D = vtkm::Id(1); - } - else - { - // Truly is other - isOther = vtkm::Id(1); - } - } -}; struct ConstructCellWeightList : public vtkm::worklet::WorkletMapField {