diff --git a/examples/multi_backend/MultiDeviceGradient.hxx b/examples/multi_backend/MultiDeviceGradient.hxx index c7ceb9562..db3362f7f 100644 --- a/examples/multi_backend/MultiDeviceGradient.hxx +++ b/examples/multi_backend/MultiDeviceGradient.hxx @@ -17,6 +17,7 @@ #include +#include namespace { diff --git a/vtkm/filter/CMakeLists.txt b/vtkm/filter/CMakeLists.txt index 7452728e0..e922fbf55 100644 --- a/vtkm/filter/CMakeLists.txt +++ b/vtkm/filter/CMakeLists.txt @@ -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 diff --git a/vtkm/filter/contour/CMakeLists.txt b/vtkm/filter/contour/CMakeLists.txt index 32665ff70..3cb61881f 100644 --- a/vtkm/filter/contour/CMakeLists.txt +++ b/vtkm/filter/contour/CMakeLists.txt @@ -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 ) diff --git a/vtkm/filter/MIRFilter.hxx b/vtkm/filter/contour/MIRFilter.cxx similarity index 87% rename from vtkm/filter/MIRFilter.hxx rename to vtkm/filter/contour/MIRFilter.cxx index 31e0df296..2fb7a6423 100644 --- a/vtkm/filter/MIRFilter.hxx +++ b/vtkm/filter/contour/MIRFilter.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 #include #include #include #include -#include -#include #include -#include #include #include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include +#include +#include + 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 -inline VTKM_CONT void MIRFilter::ProcessPointField( - const vtkm::cont::ArrayHandle& input, - vtkm::cont::ArrayHandle& 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::ValueType; + vtkm::cont::ArrayHandle outputArray; + vtkm::worklet::DestructPointWeightList destructWeightList; + this->Invoke(destructWeightList, this->MIRIDs, this->MIRWeights, concrete, outputArray); + result.AddPointField(field.GetName(), outputArray); + }; + field.GetData() + .CastAndCallForTypesWithFloatFallback( + resolve); + } + else if (field.IsFieldCell()) + { + return vtkm::filter::MapFieldPermutation(field, this->filterCellInterp, result); + } + else + { + return false; + } + + return false; } + //----------------------------------------------------------------------------- -template -inline VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute( - const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase policy) +VTKM_CONT vtkm::cont::DataSet MIRFilter::DoExecute(const vtkm::cont::DataSet& input) { - //{ - //(void)input; - //(void)policy; vtkm::worklet::CheckFor2D cellCheck; vtkm::cont::ArrayHandle 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 diff --git a/vtkm/filter/MIRFilter.h b/vtkm/filter/contour/MIRFilter.h similarity index 67% rename from vtkm/filter/MIRFilter.h rename to vtkm/filter/contour/MIRFilter.h index 7f328b3e6..178a65ac7 100644 --- a/vtkm/filter/MIRFilter.h +++ b/vtkm/filter/contour/MIRFilter.h @@ -11,16 +11,15 @@ #ifndef vtkm_m_filter_MIRFilter_h #define vtkm_m_filter_MIRFilter_h -#include -#include - -#include -#include +#include +#include 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 +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 - VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, - vtkm::filter::PolicyBase); - - template - VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, - const vtkm::cont::ArrayHandle& input1, - const vtkm::filter::FieldMetadata& fieldMeta, - vtkm::filter::PolicyBase) - { - (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 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 - VTKM_CONT void ProcessPointField(const vtkm::cont::ArrayHandle& input, - vtkm::cont::ArrayHandle& output); - - // NOTE: The below assumes that MIR will not change the cell values when subdividing. - template - VTKM_CONT void ProcessCellField(const vtkm::cont::ArrayHandle& input, - vtkm::cont::ArrayHandle& 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> MIRWeights; vtkm::cont::ArrayHandle> MIRIDs; }; -} - -} - -#ifndef vtk_m_filter_MIRFilter_hxx -#include -#endif +} // namespace contour +} // namespace filter +} // namespace vtkm #endif diff --git a/vtkm/filter/contour/testing/CMakeLists.txt b/vtkm/filter/contour/testing/CMakeLists.txt index 074296d30..027a3563d 100644 --- a/vtkm/filter/contour/testing/CMakeLists.txt +++ b/vtkm/filter/contour/testing/CMakeLists.txt @@ -12,6 +12,7 @@ set(unit_tests UnitTestClipWithImplicitFunctionFilter.cxx UnitTestContourFilter.cxx UnitTestContourFilterNormals.cxx + UnitTestMIRFilter.cxx ) set(libraries diff --git a/vtkm/filter/testing/UnitTestMIRFilter.cxx b/vtkm/filter/contour/testing/UnitTestMIRFilter.cxx similarity index 97% rename from vtkm/filter/testing/UnitTestMIRFilter.cxx rename to vtkm/filter/contour/testing/UnitTestMIRFilter.cxx index b42e84801..810fa2b6c 100644 --- a/vtkm/filter/testing/UnitTestMIRFilter.cxx +++ b/vtkm/filter/contour/testing/UnitTestMIRFilter.cxx @@ -8,14 +8,15 @@ // PURPOSE. See the above copyright notice for more information. //============================================================================ +#include #include #include #include #include -#include - +#include #include +#include #include @@ -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"); diff --git a/vtkm/filter/contour/worklet/CMakeLists.txt b/vtkm/filter/contour/worklet/CMakeLists.txt index ef7b8a204..4c97cf5b1 100644 --- a/vtkm/filter/contour/worklet/CMakeLists.txt +++ b/vtkm/filter/contour/worklet/CMakeLists.txt @@ -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}) diff --git a/vtkm/worklet/MIR.h b/vtkm/filter/contour/worklet/MIR.h similarity index 99% rename from vtkm/worklet/MIR.h rename to vtkm/filter/contour/worklet/MIR.h index 43afed24e..804df1905 100644 --- a/vtkm/worklet/MIR.h +++ b/vtkm/filter/contour/worklet/MIR.h @@ -42,7 +42,7 @@ #include #include -#include +#include namespace vtkm { diff --git a/vtkm/worklet/mir/CMakeLists.txt b/vtkm/filter/contour/worklet/mir/CMakeLists.txt similarity index 100% rename from vtkm/worklet/mir/CMakeLists.txt rename to vtkm/filter/contour/worklet/mir/CMakeLists.txt diff --git a/vtkm/worklet/mir/MIRTables.h b/vtkm/filter/contour/worklet/mir/MIRTables.h similarity index 100% rename from vtkm/worklet/mir/MIRTables.h rename to vtkm/filter/contour/worklet/mir/MIRTables.h diff --git a/vtkm/filter/testing/CMakeLists.txt b/vtkm/filter/testing/CMakeLists.txt index 06efb1acf..8c0a5e132 100644 --- a/vtkm/filter/testing/CMakeLists.txt +++ b/vtkm/filter/testing/CMakeLists.txt @@ -22,7 +22,6 @@ set(unit_tests UnitTestLagrangianStructuresFilter.cxx UnitTestMapFieldMergeAverage.cxx UnitTestMapFieldPermutation.cxx - UnitTestMIRFilter.cxx UnitTestMultiBlockFilter.cxx UnitTestPartitionedDataSetFilters.cxx UnitTestProbe.cxx diff --git a/vtkm/worklet/CMakeLists.txt b/vtkm/worklet/CMakeLists.txt index 5d617fbbe..61d1b295d 100644 --- a/vtkm/worklet/CMakeLists.txt +++ b/vtkm/worklet/CMakeLists.txt @@ -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)