Compile most frequently used VTK-m filters into a library

VTK-m now provides the following filters with the default policy
as part of the vtkm_filter library:
  - CellAverage
  - CleanGrid
  - ClipWithField
  - ClipWithImplicitFunction
  - Contour
  - ExternalFaces
  - ExtractStructured
  - PointAverage
  - Threshold
  - VectorMagnitude

By building these as a library we hope to provide faster compile
times for consumers of VTK-m when using common configurations.
This commit is contained in:
Robert Maynard 2019-09-09 09:39:23 -04:00
parent d1d61b9ebc
commit 8520d70e0d
47 changed files with 840 additions and 637 deletions

@ -142,7 +142,6 @@ using UnstructuredCellList =
using AllCellList = vtkm::ListTagJoin<StructuredCellList, UnstructuredCellList>; using AllCellList = vtkm::ListTagJoin<StructuredCellList, UnstructuredCellList>;
using CoordinateList = vtkm::ListTagBase<vtkm::Vec3f_32, vtkm::Vec3f_64>;
class BenchmarkFilterPolicy : public vtkm::filter::PolicyBase<BenchmarkFilterPolicy> class BenchmarkFilterPolicy : public vtkm::filter::PolicyBase<BenchmarkFilterPolicy>
{ {
@ -152,8 +151,6 @@ public:
using StructuredCellSetList = StructuredCellList; using StructuredCellSetList = StructuredCellList;
using UnstructuredCellSetList = UnstructuredCellList; using UnstructuredCellSetList = UnstructuredCellList;
using AllCellSetList = AllCellList; using AllCellSetList = AllCellList;
using CoordinateTypeList = CoordinateList;
}; };
// Class implementing all filter benchmarks: // Class implementing all filter benchmarks:
@ -307,7 +304,7 @@ class BenchmarkFilters
{ {
Timer timer{ DeviceAdapter() }; Timer timer{ DeviceAdapter() };
timer.Start(); timer.Start();
auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); auto result = this->Filter.Execute(InputDataSet);
(void)result; (void)result;
return timer.GetElapsedTime(); return timer.GetElapsedTime();
} }
@ -374,7 +371,7 @@ class BenchmarkFilters
{ {
Timer timer{ DeviceAdapter() }; Timer timer{ DeviceAdapter() };
timer.Start(); timer.Start();
auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); auto result = this->Filter.Execute(InputDataSet);
(void)result; (void)result;
return timer.GetElapsedTime(); return timer.GetElapsedTime();
} }
@ -400,7 +397,7 @@ class BenchmarkFilters
{ {
Timer timer{ DeviceAdapter() }; Timer timer{ DeviceAdapter() };
timer.Start(); timer.Start();
auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); auto result = this->Filter.Execute(InputDataSet);
(void)result; (void)result;
return timer.GetElapsedTime(); return timer.GetElapsedTime();
} }
@ -501,7 +498,7 @@ class BenchmarkFilters
{ {
Timer timer{ DeviceAdapter() }; Timer timer{ DeviceAdapter() };
timer.Start(); timer.Start();
auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); auto result = this->Filter.Execute(InputDataSet);
(void)result; (void)result;
return timer.GetElapsedTime(); return timer.GetElapsedTime();
} }
@ -547,7 +544,7 @@ class BenchmarkFilters
{ {
Timer timer{ DeviceAdapter() }; Timer timer{ DeviceAdapter() };
timer.Start(); timer.Start();
auto result = this->Filter.Execute(InputDataSet, BenchmarkFilterPolicy()); auto result = this->Filter.Execute(InputDataSet);
(void)result; (void)result;
return timer.GetElapsedTime(); return timer.GetElapsedTime();
} }
@ -954,7 +951,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec
vtkm::filter::PointAverage avg; vtkm::filter::PointAverage avg;
avg.SetActiveField(CellScalarsName, vtkm::cont::Field::Association::CELL_SET); avg.SetActiveField(CellScalarsName, vtkm::cont::Field::Association::CELL_SET);
avg.SetOutputFieldName("GeneratedPointScalars"); avg.SetOutputFieldName("GeneratedPointScalars");
auto outds = avg.Execute(InputDataSet, BenchmarkFilterPolicy()); auto outds = avg.Execute(InputDataSet);
InputDataSet.AddField( InputDataSet.AddField(
outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS)); outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS));
PointScalarsName = "GeneratedPointScalars"; PointScalarsName = "GeneratedPointScalars";
@ -977,7 +974,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec
vtkm::filter::VectorMagnitude mag; vtkm::filter::VectorMagnitude mag;
mag.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::POINTS); mag.SetActiveField(PointVectorsName, vtkm::cont::Field::Association::POINTS);
mag.SetOutputFieldName("GeneratedPointScalars"); mag.SetOutputFieldName("GeneratedPointScalars");
auto outds = mag.Execute(InputDataSet, BenchmarkFilterPolicy()); auto outds = mag.Execute(InputDataSet);
InputDataSet.AddField( InputDataSet.AddField(
outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS)); outds.GetField("GeneratedPointScalars", vtkm::cont::Field::Association::POINTS));
PointScalarsName = "GeneratedPointScalars"; PointScalarsName = "GeneratedPointScalars";
@ -999,7 +996,7 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec
vtkm::filter::CellAverage avg; vtkm::filter::CellAverage avg;
avg.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS); avg.SetActiveField(PointScalarsName, vtkm::cont::Field::Association::POINTS);
avg.SetOutputFieldName("GeneratedCellScalars"); avg.SetOutputFieldName("GeneratedCellScalars");
auto outds = avg.Execute(InputDataSet, BenchmarkFilterPolicy()); auto outds = avg.Execute(InputDataSet);
InputDataSet.AddField( InputDataSet.AddField(
outds.GetField("GeneratedCellScalars", vtkm::cont::Field::Association::CELL_SET)); outds.GetField("GeneratedCellScalars", vtkm::cont::Field::Association::CELL_SET));
CellScalarsName = "GeneratedCellScalars"; CellScalarsName = "GeneratedCellScalars";

@ -0,0 +1,73 @@
# Provide pre-built filters in the vtkm_filter library.
VTK-m now provides the following pre built versions of
the following filters as part of the vtkm_filter library,
when executed with the default types.
- CellAverage
- CleanGrid
- ClipWithField
- ClipWithImplicitFunction
- Contour
- ExternalFaces
- ExtractStuctured
- PointAverage
- Threshold
- VectorMagnitude
The decision on providing a subset of filters as a library
was based on balancing the resulting library size and cross domain
applicibaility of the filter. So the initial set of algorithms
have been selected by looking at what is commonly used by
current VTK-m consuming applications.
By default types we mean that no explicit user policy has been
passed to the `Execute` method on these filters. For example
the following will use the pre-build `Threshold` and `CleanGrid`
filters:
```cpp
vtkm::cont::DataSet input = ...;
//convert input to an unstructured grid
vtkm::filter::CleanGrid clean;
auto cleaned = clean.Execute(input);
vtkm::filter::Threshold threshold;
threshold.SetLowerThreshold(60.1);
threshold.SetUpperThreshold(60.1);
threshold.SetActiveField("pointvar");
threshold.SetFieldsToPass("cellvar");
auto output = threshold.Execute(cleaned);
...
```
While the following, even though it is a subset of the default
policy will need to be compiled by the consuming library by
including the relevant `.hxx` files
```cpp
#include <vtkm/filter/CleanGrid.hxx>
#include <vtkm/filter/Threshold.hxx>
...
struct CustomPolicy : vtkm::filter::PolicyBase<CustomPolicy>
{
// Defaults are the same as PolicyDefault expect for the field types
using FieldTypeList = vtkm::ListTagBase<vtkm::FloatDefault, vtkm::Vec3f>;
};
...
vtkm::cont::DataSet input = ...;
//convert input to an unstructured grid
vtkm::filter::CleanGrid clean;
auto cleaned = clean.Execute(input, CustomPolicy{});
vtkm::filter::Threshold threshold;
threshold.SetLowerThreshold(60.1);
threshold.SetUpperThreshold(60.1);
threshold.SetActiveField("pointvar");
threshold.SetFieldsToPass("cellvar");
auto output = threshold.Execute(cleaned, CustomPolicy{});
...
```

@ -15,7 +15,7 @@ find_package(VTKm REQUIRED QUIET)
if(TARGET vtkm_rendering) if(TARGET vtkm_rendering)
add_executable(Demo Demo.cxx) add_executable(Demo Demo.cxx)
target_link_libraries(Demo PRIVATE vtkm_rendering) target_link_libraries(Demo PRIVATE vtkm_filter vtkm_rendering)
vtkm_add_target_information(Demo vtkm_add_target_information(Demo
DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS
DEVICE_SOURCES Demo.cxx) DEVICE_SOURCES Demo.cxx)

@ -13,8 +13,9 @@
#include <vtkm/cont/ArrayHandleExtrudeCoords.h> #include <vtkm/cont/ArrayHandleExtrudeCoords.h>
#include <vtkm/cont/CellSetExtrude.h> #include <vtkm/cont/CellSetExtrude.h>
#include <vtkm/cont/testing/Testing.h> #include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/CellAverage.h>
#include <vtkm/filter/PointAverage.h> #include <vtkm/filter/PointAverage.h>
#include <vtkm/filter/PointAverage.hxx>
#include <vtkm/filter/PolicyExtrude.h> #include <vtkm/filter/PolicyExtrude.h>
namespace namespace

@ -141,16 +141,26 @@ set(header_template_sources
ZFPCompressor3D.hxx ZFPCompressor3D.hxx
ZFPDecompressor3D.hxx ZFPDecompressor3D.hxx
) )
set(sources_device
CellAverage.cxx
CleanGrid.cxx
ClipWithField.cxx
ClipWithImplicitFunction.cxx
Contour.cxx
ExternalFaces.cxx
ExtractStructured.cxx
PointAverage.cxx
Threshold.cxx
VectorMagnitude.cxx
)
vtkm_declare_headers(${headers}) vtkm_library(
vtkm_declare_headers(${header_template_sources}) NAME vtkm_filter
TEMPLATE_SOURCES ${header_template_sources}
# Create an interface library for vtkm_filter. At some point, this will be replaced with a real HEADERS ${headers}
# library that contains pre-built filters. That would be created with the vtkm_library CMake DEVICE_SOURCES ${sources_device}
# function (defined in VTKmWrappers.cmake). )
add_library(vtkm_filter INTERFACE) target_link_libraries(vtkm_filter PUBLIC vtkm_worklet)
target_link_libraries(vtkm_filter INTERFACE vtkm_worklet)
install(TARGETS vtkm_filter EXPORT ${VTKm_EXPORT_NAME})
add_subdirectory(internal) add_subdirectory(internal)

@ -0,0 +1,22 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_CellAverage_cxx
#include <vtkm/filter/CellAverage.h>
#include <vtkm/filter/CellAverage.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(CellAverage);
}
}

@ -11,6 +11,9 @@
#ifndef vtk_m_filter_CellAverage_h #ifndef vtk_m_filter_CellAverage_h
#define vtk_m_filter_CellAverage_h #define vtk_m_filter_CellAverage_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/filter/FilterCell.h> #include <vtkm/filter/FilterCell.h>
#include <vtkm/worklet/CellAverage.h> #include <vtkm/worklet/CellAverage.h>
@ -25,24 +28,23 @@ namespace filter
/// The method of transformation is based on averaging the data /// The method of transformation is based on averaging the data
/// values of all points used by particular cell. /// values of all points used by particular cell.
/// ///
class CellAverage : public vtkm::filter::FilterCell<CellAverage> class VTKM_ALWAYS_EXPORT CellAverage : public vtkm::filter::FilterCell<CellAverage>
{ {
public: public:
VTKM_CONT
CellAverage();
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field, const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy> policy);
private: private:
vtkm::worklet::CellAverage Worklet; vtkm::worklet::CellAverage Worklet;
}; };
#ifndef vtkm_filter_CellAverage_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(CellAverage);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/CellAverage.hxx>
#endif // vtk_m_filter_CellAverage_h #endif // vtk_m_filter_CellAverage_h

@ -15,21 +15,13 @@ namespace vtkm
{ {
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT CellAverage::CellAverage()
: vtkm::filter::FilterCell<CellAverage>()
, Worklet()
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet CellAverage::DoExecute( inline VTKM_CONT vtkm::cont::DataSet CellAverage::DoExecute(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& inField, const vtkm::cont::ArrayHandle<T, StorageType>& inField,
const vtkm::filter::FieldMetadata& fieldMetadata, const vtkm::filter::FieldMetadata& fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
if (!fieldMetadata.IsPointField()) if (!fieldMetadata.IsPointField())
{ {

122
vtkm/filter/CleanGrid.cxx Normal file

@ -0,0 +1,122 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_CleanGrid_cxx
#include <vtkm/filter/CleanGrid.h>
#include <vtkm/filter/CleanGrid.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
CleanGrid::CleanGrid()
: CompactPointFields(true)
, MergePoints(true)
, Tolerance(1.0e-6)
, ToleranceIsAbsolute(false)
, RemoveDegenerateCells(true)
, FastMerge(true)
{
}
//-----------------------------------------------------------------------------
vtkm::cont::DataSet CleanGrid::GenerateOutput(const vtkm::cont::DataSet& inData,
vtkm::cont::CellSetExplicit<>& outputCellSet)
{
using VecId = std::size_t;
const VecId activeCoordIndex = static_cast<VecId>(this->GetActiveCoordinateSystemIndex());
const VecId numCoordSystems = static_cast<VecId>(inData.GetNumberOfCoordinateSystems());
std::vector<vtkm::cont::CoordinateSystem> outputCoordinateSystems(numCoordSystems);
// Start with a shallow copy of the coordinate systems
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outputCoordinateSystems[coordSystemIndex] =
inData.GetCoordinateSystem(static_cast<vtkm::IdComponent>(coordSystemIndex));
}
// Optionally adjust the cell set indices to remove all unused points
if (this->GetCompactPointFields())
{
this->PointCompactor.FindPointsStart();
this->PointCompactor.FindPoints(outputCellSet);
this->PointCompactor.FindPointsEnd();
outputCellSet = this->PointCompactor.MapCellSet(outputCellSet);
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outputCoordinateSystems[coordSystemIndex] =
vtkm::cont::CoordinateSystem(outputCoordinateSystems[coordSystemIndex].GetName(),
this->PointCompactor.MapPointFieldDeep(
outputCoordinateSystems[coordSystemIndex].GetData()));
}
}
// Optionally find and merge coincident points
if (this->GetMergePoints())
{
vtkm::cont::CoordinateSystem activeCoordSystem = outputCoordinateSystems[activeCoordIndex];
vtkm::Bounds bounds = activeCoordSystem.GetBounds();
vtkm::Float64 delta = this->GetTolerance();
if (!this->GetToleranceIsAbsolute())
{
delta *=
vtkm::Magnitude(vtkm::make_Vec(bounds.X.Length(), bounds.Y.Length(), bounds.Z.Length()));
}
auto coordArray = activeCoordSystem.GetData();
this->PointMerger.Run(delta, this->GetFastMerge(), bounds, coordArray);
activeCoordSystem = vtkm::cont::CoordinateSystem(activeCoordSystem.GetName(), coordArray);
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
if (coordSystemIndex == activeCoordIndex)
{
outputCoordinateSystems[coordSystemIndex] = activeCoordSystem;
}
else
{
outputCoordinateSystems[coordSystemIndex] = vtkm::cont::CoordinateSystem(
outputCoordinateSystems[coordSystemIndex].GetName(),
this->PointMerger.MapPointField(outputCoordinateSystems[coordSystemIndex].GetData()));
}
}
outputCellSet = this->PointMerger.MapCellSet(outputCellSet);
}
// Optionally remove degenerate cells
if (this->GetRemoveDegenerateCells())
{
outputCellSet = this->CellCompactor.Run(outputCellSet);
}
// Construct resulting data set with new cell sets
vtkm::cont::DataSet outData;
outData.SetCellSet(outputCellSet);
// Pass the coordinate systems
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outData.AddCoordinateSystem(outputCoordinateSystems[coordSystemIndex]);
}
return outData;
}
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(CleanGrid);
}
}

@ -10,6 +10,8 @@
#ifndef vtk_m_filter_CleanGrid_h #ifndef vtk_m_filter_CleanGrid_h
#define vtk_m_filter_CleanGrid_h #define vtk_m_filter_CleanGrid_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/PointMerge.h> #include <vtkm/worklet/PointMerge.h>
@ -35,10 +37,10 @@ namespace filter
/// \todo Add a feature to merge points that are coincident or within a /// \todo Add a feature to merge points that are coincident or within a
/// tolerance. /// tolerance.
/// ///
class CleanGrid : public vtkm::filter::FilterDataSet<CleanGrid> class VTKM_ALWAYS_EXPORT CleanGrid : public vtkm::filter::FilterDataSet<CleanGrid>
{ {
public: public:
VTKM_CONT VTKM_FILTER_EXPORT
CleanGrid(); CleanGrid();
/// When the CompactPointFields flag is true, the filter will identify any /// When the CompactPointFields flag is true, the filter will identify any
@ -85,15 +87,41 @@ public:
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData, VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData,
vtkm::filter::PolicyBase<Policy> policy); vtkm::filter::PolicyBase<Policy> policy);
template <typename ValueType, typename Storage, typename Policy> template <typename ValueType, typename Storage, typename Policy>
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<ValueType, Storage>& input, const vtkm::cont::ArrayHandle<ValueType, Storage>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<Policy>); vtkm::filter::PolicyBase<Policy>)
{
if (fieldMeta.IsPointField() && (this->GetCompactPointFields() || this->GetMergePoints()))
{
vtkm::cont::ArrayHandle<ValueType> compactedArray;
if (this->GetCompactPointFields())
{
compactedArray = this->PointCompactor.MapPointFieldDeep(input);
if (this->GetMergePoints())
{
compactedArray = this->PointMerger.MapPointField(compactedArray);
}
}
else if (this->GetMergePoints())
{
compactedArray = this->PointMerger.MapPointField(input);
}
result.AddField(fieldMeta.AsField(compactedArray));
}
else if (fieldMeta.IsCellField() && this->GetRemoveDegenerateCells())
{
result.AddField(fieldMeta.AsField(this->CellCompactor.ProcessCellField(input)));
}
else
{
result.AddField(fieldMeta.AsField(input));
}
template <typename ValueType, typename Storage> return true;
VTKM_CONT vtkm::cont::ArrayHandle<ValueType> MapPointField( }
const vtkm::cont::ArrayHandle<ValueType, Storage>& inArray) const;
private: private:
bool CompactPointFields; bool CompactPointFields;
@ -103,13 +131,19 @@ private:
bool RemoveDegenerateCells; bool RemoveDegenerateCells;
bool FastMerge; bool FastMerge;
VTKM_FILTER_EXPORT vtkm::cont::DataSet GenerateOutput(
const vtkm::cont::DataSet& inData,
vtkm::cont::CellSetExplicit<>& outputCellSet);
vtkm::worklet::RemoveUnusedPoints PointCompactor; vtkm::worklet::RemoveUnusedPoints PointCompactor;
vtkm::worklet::RemoveDegenerateCells CellCompactor; vtkm::worklet::RemoveDegenerateCells CellCompactor;
vtkm::worklet::PointMerge PointMerger; vtkm::worklet::PointMerge PointMerger;
}; };
#ifndef vtkm_filter_CleanGrid_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(CleanGrid);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/CleanGrid.hxx>
#endif //vtk_m_filter_CleanGrid_h #endif //vtk_m_filter_CleanGrid_h

@ -20,24 +20,11 @@ namespace vtkm
namespace filter namespace filter
{ {
inline VTKM_CONT CleanGrid::CleanGrid()
: CompactPointFields(true)
, MergePoints(true)
, Tolerance(1.0e-6)
, ToleranceIsAbsolute(false)
, RemoveDegenerateCells(true)
, FastMerge(true)
{
}
template <typename Policy> template <typename Policy>
inline VTKM_CONT vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::DataSet& inData, inline VTKM_CONT vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::DataSet& inData,
vtkm::filter::PolicyBase<Policy> policy) vtkm::filter::PolicyBase<Policy> policy)
{ {
using CellSetType = vtkm::cont::CellSetExplicit<>; using CellSetType = vtkm::cont::CellSetExplicit<>;
using VecId = std::size_t;
VecId activeCoordIndex = static_cast<VecId>(this->GetActiveCoordinateSystemIndex());
CellSetType outputCellSet; CellSetType outputCellSet;
// Do a deep copy of the cells to new CellSetExplicit structures // Do a deep copy of the cells to new CellSetExplicit structures
@ -78,122 +65,7 @@ inline VTKM_CONT vtkm::cont::DataSet CleanGrid::DoExecute(const vtkm::cont::Data
deducedCellSet.ReleaseResourcesExecution(); deducedCellSet.ReleaseResourcesExecution();
} }
return this->GenerateOutput(inData, outputCellSet);
VecId numCoordSystems = static_cast<VecId>(inData.GetNumberOfCoordinateSystems());
std::vector<vtkm::cont::CoordinateSystem> outputCoordinateSystems(numCoordSystems);
// Start with a shallow copy of the coordinate systems
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outputCoordinateSystems[coordSystemIndex] =
inData.GetCoordinateSystem(static_cast<vtkm::IdComponent>(coordSystemIndex));
}
// Optionally adjust the cell set indices to remove all unused points
if (this->GetCompactPointFields())
{
this->PointCompactor.FindPointsStart();
this->PointCompactor.FindPoints(outputCellSet);
this->PointCompactor.FindPointsEnd();
outputCellSet = this->PointCompactor.MapCellSet(outputCellSet);
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outputCoordinateSystems[coordSystemIndex] =
vtkm::cont::CoordinateSystem(outputCoordinateSystems[coordSystemIndex].GetName(),
this->PointCompactor.MapPointFieldDeep(
outputCoordinateSystems[coordSystemIndex].GetData()));
}
}
// Optionally find and merge coincident points
if (this->GetMergePoints())
{
vtkm::cont::CoordinateSystem activeCoordSystem = outputCoordinateSystems[activeCoordIndex];
vtkm::Bounds bounds = activeCoordSystem.GetBounds();
vtkm::Float64 delta = this->GetTolerance();
if (!this->GetToleranceIsAbsolute())
{
delta *=
vtkm::Magnitude(vtkm::make_Vec(bounds.X.Length(), bounds.Y.Length(), bounds.Z.Length()));
}
auto coordArray = activeCoordSystem.GetData();
this->PointMerger.Run(delta, this->GetFastMerge(), bounds, coordArray);
activeCoordSystem = vtkm::cont::CoordinateSystem(activeCoordSystem.GetName(), coordArray);
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
if (coordSystemIndex == activeCoordIndex)
{
outputCoordinateSystems[coordSystemIndex] = activeCoordSystem;
}
else
{
outputCoordinateSystems[coordSystemIndex] = vtkm::cont::CoordinateSystem(
outputCoordinateSystems[coordSystemIndex].GetName(),
this->PointMerger.MapPointField(outputCoordinateSystems[coordSystemIndex].GetData()));
}
}
outputCellSet = this->PointMerger.MapCellSet(outputCellSet);
}
// Optionally remove degenerate cells
if (this->GetRemoveDegenerateCells())
{
outputCellSet = this->CellCompactor.Run(outputCellSet);
}
// Construct resulting data set with new cell sets
vtkm::cont::DataSet outData;
outData.SetCellSet(outputCellSet);
// Pass the coordinate systems
for (VecId coordSystemIndex = 0; coordSystemIndex < numCoordSystems; ++coordSystemIndex)
{
outData.AddCoordinateSystem(outputCoordinateSystems[coordSystemIndex]);
}
return outData;
}
template <typename ValueType, typename Storage, typename Policy>
inline VTKM_CONT bool CleanGrid::DoMapField(
vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<ValueType, Storage>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<Policy>)
{
if (fieldMeta.IsPointField() && (this->GetCompactPointFields() || this->GetMergePoints()))
{
vtkm::cont::ArrayHandle<ValueType> compactedArray;
if (this->GetCompactPointFields())
{
compactedArray = this->PointCompactor.MapPointFieldDeep(input);
if (this->GetMergePoints())
{
compactedArray = this->PointMerger.MapPointField(compactedArray);
}
}
else if (this->GetMergePoints())
{
compactedArray = this->PointMerger.MapPointField(input);
}
result.AddField(fieldMeta.AsField(compactedArray));
}
else if (fieldMeta.IsCellField() && this->GetRemoveDegenerateCells())
{
result.AddField(fieldMeta.AsField(this->CellCompactor.ProcessCellField(input)));
}
else
{
result.AddField(fieldMeta.AsField(input));
}
return true;
} }
} }
} }

@ -0,0 +1,22 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_Clip_cxx
#include <vtkm/filter/ClipWithField.h>
#include <vtkm/filter/ClipWithField.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ClipWithField);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_ClipWithField_h #ifndef vtk_m_filter_ClipWithField_h
#define vtk_m_filter_ClipWithField_h #define vtk_m_filter_ClipWithField_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterDataSetWithField.h> #include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/Clip.h> #include <vtkm/worklet/Clip.h>
@ -24,14 +26,11 @@ namespace filter
/// value are considered outside, and will be discarded. All points that are greater /// value are considered outside, and will be discarded. All points that are greater
/// are kept. /// are kept.
/// The resulting geometry will not be water tight. /// The resulting geometry will not be water tight.
class ClipWithField : public vtkm::filter::FilterDataSetWithField<ClipWithField> class VTKM_ALWAYS_EXPORT ClipWithField : public vtkm::filter::FilterDataSetWithField<ClipWithField>
{ {
public: public:
using SupportedTypes = vtkm::TypeListTagScalarAll; using SupportedTypes = vtkm::TypeListTagScalarAll;
VTKM_CONT
ClipWithField();
VTKM_CONT VTKM_CONT
void SetClipValue(vtkm::Float64 value) { this->ClipValue = value; } void SetClipValue(vtkm::Float64 value) { this->ClipValue = value; }
@ -53,16 +52,38 @@ public:
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy); vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> output;
if (fieldMeta.IsPointField())
{
output = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
output = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(output));
return true;
}
private: private:
vtkm::Float64 ClipValue; vtkm::Float64 ClipValue = 0;
vtkm::worklet::Clip Worklet; vtkm::worklet::Clip Worklet;
bool Invert; bool Invert = false;
}; };
#ifndef vtkm_filter_Clip_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithField);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/ClipWithField.hxx>
#endif // vtk_m_filter_ClipWithField_h #endif // vtk_m_filter_ClipWithField_h

@ -18,16 +18,6 @@ namespace vtkm
{ {
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT ClipWithField::ClipWithField()
: vtkm::filter::FilterDataSetWithField<ClipWithField>()
, ClipValue(0)
, Worklet()
, Invert(false)
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute(
@ -60,33 +50,5 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute(
output.AddCoordinateSystem(outputCoords); output.AddCoordinateSystem(outputCoords);
return output; return output;
} }
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT bool ClipWithField::DoMapField(
vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> output;
if (fieldMeta.IsPointField())
{
output = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
output = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(output));
return true;
}
} }
} // end namespace vtkm::filter } // end namespace vtkm::filter

@ -0,0 +1,22 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_ClipWithImplicitFunction_cxx
#include <vtkm/filter/ClipWithImplicitFunction.h>
#include <vtkm/filter/ClipWithImplicitFunction.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ClipWithImplicitFunction);
}
}

@ -7,10 +7,11 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
#ifndef vtk_m_filter_ClipWithImplicitFunction_h #ifndef vtk_m_filter_ClipWithImplicitFunction_h
#define vtk_m_filter_ClipWithImplicitFunction_h #define vtk_m_filter_ClipWithImplicitFunction_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/cont/ImplicitFunctionHandle.h> #include <vtkm/cont/ImplicitFunctionHandle.h>
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/Clip.h> #include <vtkm/worklet/Clip.h>
@ -25,11 +26,10 @@ namespace filter
/// Clip a dataset using a given implicit function value, such as vtkm::Sphere /// Clip a dataset using a given implicit function value, such as vtkm::Sphere
/// or vtkm::Frustum. /// or vtkm::Frustum.
/// The resulting geometry will not be water tight. /// The resulting geometry will not be water tight.
class ClipWithImplicitFunction : public vtkm::filter::FilterDataSet<ClipWithImplicitFunction> class VTKM_ALWAYS_EXPORT ClipWithImplicitFunction
: public vtkm::filter::FilterDataSet<ClipWithImplicitFunction>
{ {
public: public:
ClipWithImplicitFunction();
void SetImplicitFunction(const vtkm::cont::ImplicitFunctionHandle& func) void SetImplicitFunction(const vtkm::cont::ImplicitFunctionHandle& func)
{ {
this->Function = func; this->Function = func;
@ -41,7 +41,7 @@ public:
template <typename DerivedPolicy> template <typename DerivedPolicy>
vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy> policy);
//Map a new field onto the resulting dataset after running the filter. //Map a new field onto the resulting dataset after running the filter.
//This call is only valid after Execute has been called. //This call is only valid after Execute has been called.
@ -49,16 +49,39 @@ public:
bool DoMapField(vtkm::cont::DataSet& result, bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> output;
if (fieldMeta.IsPointField())
{
output = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
output = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(output));
return true;
}
private: private:
vtkm::cont::ImplicitFunctionHandle Function; vtkm::cont::ImplicitFunctionHandle Function;
vtkm::worklet::Clip Worklet; vtkm::worklet::Clip Worklet;
bool Invert; bool Invert = false;
}; };
#ifndef vtkm_filter_ClipWithImplicitFunction_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithImplicitFunction);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/ClipWithImplicitFunction.hxx>
#endif // vtk_m_filter_ClipWithImplicitFunction_h #endif // vtk_m_filter_ClipWithImplicitFunction_h

@ -17,16 +17,10 @@ namespace vtkm
namespace filter namespace filter
{ {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ClipWithImplicitFunction::ClipWithImplicitFunction()
: Invert(false)
{
}
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
//get the cells and coordinates of the dataset //get the cells and coordinates of the dataset
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(); const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
@ -48,34 +42,5 @@ inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute(
return output; return output;
} }
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline bool ClipWithImplicitFunction::DoMapField(
vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
vtkm::cont::ArrayHandle<T> output;
if (fieldMeta.IsPointField())
{
output = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
output = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(output));
return true;
}
} }
} // end namespace vtkm::filter } // end namespace vtkm::filter

75
vtkm/filter/Contour.cxx Normal file

@ -0,0 +1,75 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_Contour_cxx
#include <vtkm/filter/Contour.h>
#include <vtkm/filter/Contour.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT Contour::Contour()
: vtkm::filter::FilterDataSetWithField<Contour>()
, IsoValues()
, GenerateNormals(false)
, AddInterpolationEdgeIds(false)
, ComputeFastNormalsForStructured(false)
, ComputeFastNormalsForUnstructured(true)
, NormalArrayName("normals")
, InterpolationEdgeIdsArrayName("edgeIds")
, Worklet()
{
// todo: keep an instance of marching cubes worklet as a member variable
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT void Contour::SetNumberOfIsoValues(vtkm::Id num)
{
if (num >= 0)
{
this->IsoValues.resize(static_cast<std::size_t>(num));
}
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT vtkm::Id Contour::GetNumberOfIsoValues() const
{
return static_cast<vtkm::Id>(this->IsoValues.size());
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT void Contour::SetIsoValue(vtkm::Id index, vtkm::Float64 v)
{
std::size_t i = static_cast<std::size_t>(index);
if (i >= this->IsoValues.size())
{
this->IsoValues.resize(i + 1);
}
this->IsoValues[i] = v;
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT void Contour::SetIsoValues(const std::vector<vtkm::Float64>& values)
{
this->IsoValues = values;
}
//-----------------------------------------------------------------------------
VTKM_FILTER_EXPORT vtkm::Float64 Contour::GetIsoValue(vtkm::Id index) const
{
return this->IsoValues[static_cast<std::size_t>(index)];
}
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Contour);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_Contour_h #ifndef vtk_m_filter_Contour_h
#define vtk_m_filter_Contour_h #define vtk_m_filter_Contour_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterDataSetWithField.h> #include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/Contour.h> #include <vtkm/worklet/Contour.h>
@ -25,30 +27,30 @@ namespace filter
/// Multiple contour values must be specified to generate the isosurfaces. /// Multiple contour values must be specified to generate the isosurfaces.
/// @warning /// @warning
/// This filter is currently only supports 3D volumes. /// This filter is currently only supports 3D volumes.
class Contour : public vtkm::filter::FilterDataSetWithField<Contour> class VTKM_ALWAYS_EXPORT Contour : public vtkm::filter::FilterDataSetWithField<Contour>
{ {
public: public:
using SupportedTypes = vtkm::ListTagBase<vtkm::UInt8, vtkm::Int8, vtkm::Float32, vtkm::Float64>; using SupportedTypes = vtkm::ListTagBase<vtkm::UInt8, vtkm::Int8, vtkm::Float32, vtkm::Float64>;
VTKM_CONT VTKM_FILTER_EXPORT
Contour(); Contour();
VTKM_CONT VTKM_FILTER_EXPORT
void SetNumberOfIsoValues(vtkm::Id num); void SetNumberOfIsoValues(vtkm::Id num);
VTKM_CONT VTKM_FILTER_EXPORT
vtkm::Id GetNumberOfIsoValues() const; vtkm::Id GetNumberOfIsoValues() const;
VTKM_CONT VTKM_FILTER_EXPORT
void SetIsoValue(vtkm::Float64 v) { this->SetIsoValue(0, v); } void SetIsoValue(vtkm::Float64 v) { this->SetIsoValue(0, v); }
VTKM_CONT VTKM_FILTER_EXPORT
void SetIsoValue(vtkm::Id index, vtkm::Float64); void SetIsoValue(vtkm::Id index, vtkm::Float64);
VTKM_CONT VTKM_FILTER_EXPORT
void SetIsoValues(const std::vector<vtkm::Float64>& values); void SetIsoValues(const std::vector<vtkm::Float64>& values);
VTKM_CONT VTKM_FILTER_EXPORT
vtkm::Float64 GetIsoValue(vtkm::Id index) const; vtkm::Float64 GetIsoValue(vtkm::Id index) const;
/// Set/Get whether the points generated should be unique for every triangle /// Set/Get whether the points generated should be unique for every triangle
@ -104,10 +106,10 @@ public:
const std::string& GetNormalArrayName() const { return this->NormalArrayName; } const std::string& GetNormalArrayName() const { return this->NormalArrayName; }
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field, const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy> policy);
//Map a new field onto the resulting dataset after running the filter //Map a new field onto the resulting dataset after running the filter
//this call is only valid //this call is only valid
@ -115,7 +117,27 @@ public:
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy>)
{
vtkm::cont::ArrayHandle<T> fieldArray;
if (fieldMeta.IsPointField())
{
fieldArray = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
fieldArray = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(fieldArray));
return true;
}
private: private:
std::vector<vtkm::Float64> IsoValues; std::vector<vtkm::Float64> IsoValues;
@ -127,9 +149,11 @@ private:
std::string InterpolationEdgeIdsArrayName; std::string InterpolationEdgeIdsArrayName;
vtkm::worklet::Contour Worklet; vtkm::worklet::Contour Worklet;
}; };
#ifndef vtkm_filter_Contour_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(Contour);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/Contour.hxx>
#endif // vtk_m_filter_Contour_h #endif // vtk_m_filter_Contour_h

@ -25,7 +25,7 @@ namespace
{ {
template <typename CellSetList> template <typename CellSetList>
bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellset) inline bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase<CellSetList>& cellset)
{ {
if (cellset.template IsType<vtkm::cont::CellSetStructured<1>>() || if (cellset.template IsType<vtkm::cont::CellSetStructured<1>>() ||
cellset.template IsType<vtkm::cont::CellSetStructured<2>>() || cellset.template IsType<vtkm::cont::CellSetStructured<2>>() ||
@ -37,66 +37,13 @@ bool IsCellSetStructured(const vtkm::cont::DynamicCellSetBase<CellSetList>& cell
} }
} // anonymous namespace } // anonymous namespace
//-----------------------------------------------------------------------------
inline VTKM_CONT Contour::Contour()
: vtkm::filter::FilterDataSetWithField<Contour>()
, IsoValues()
, GenerateNormals(false)
, AddInterpolationEdgeIds(false)
, ComputeFastNormalsForStructured(false)
, ComputeFastNormalsForUnstructured(true)
, NormalArrayName("normals")
, InterpolationEdgeIdsArrayName("edgeIds")
, Worklet()
{
// todo: keep an instance of marching cubes worklet as a member variable
}
//-----------------------------------------------------------------------------
inline void Contour::SetNumberOfIsoValues(vtkm::Id num)
{
if (num >= 0)
{
this->IsoValues.resize(static_cast<std::size_t>(num));
}
}
//-----------------------------------------------------------------------------
inline vtkm::Id Contour::GetNumberOfIsoValues() const
{
return static_cast<vtkm::Id>(this->IsoValues.size());
}
//-----------------------------------------------------------------------------
inline void Contour::SetIsoValue(vtkm::Id index, vtkm::Float64 v)
{
std::size_t i = static_cast<std::size_t>(index);
if (i >= this->IsoValues.size())
{
this->IsoValues.resize(i + 1);
}
this->IsoValues[i] = v;
}
//-----------------------------------------------------------------------------
inline void Contour::SetIsoValues(const std::vector<vtkm::Float64>& values)
{
this->IsoValues = values;
}
//-----------------------------------------------------------------------------
inline vtkm::Float64 Contour::GetIsoValue(vtkm::Id index) const
{
return this->IsoValues[static_cast<std::size_t>(index)];
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute( inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field, const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
if (fieldMeta.IsPointField() == false) if (fieldMeta.IsPointField() == false)
{ {
@ -203,32 +150,5 @@ inline VTKM_CONT vtkm::cont::DataSet Contour::DoExecute(
return output; return output;
} }
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT bool Contour::DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
vtkm::cont::ArrayHandle<T> fieldArray;
if (fieldMeta.IsPointField())
{
fieldArray = this->Worklet.ProcessPointField(input);
}
else if (fieldMeta.IsCellField())
{
fieldArray = this->Worklet.ProcessCellField(input);
}
else
{
return false;
}
//use the same meta data as the input so we get the same field name, etc.
result.AddField(fieldMeta.AsField(fieldArray));
return true;
}
} }
} // namespace vtkm::filter } // namespace vtkm::filter

@ -0,0 +1,71 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_ExternalFaces_cxx
#include <vtkm/filter/ExternalFaces.h>
#include <vtkm/filter/ExternalFaces.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
ExternalFaces::ExternalFaces()
: vtkm::filter::FilterDataSet<ExternalFaces>()
, CompactPoints(false)
, Worklet()
{
this->SetPassPolyData(true);
}
//-----------------------------------------------------------------------------
vtkm::cont::DataSet ExternalFaces::GenerateOutput(const vtkm::cont::DataSet& input,
vtkm::cont::CellSetExplicit<>& outCellSet)
{
//This section of ExternalFaces is independent of any input so we can build it
//into the vtkm_filter library
//3. Check the fields of the dataset to see what kinds of fields are present so
// we can free the cell mapping array if it won't be needed.
const vtkm::Id numFields = input.GetNumberOfFields();
bool hasCellFields = false;
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx)
{
auto f = input.GetField(fieldIdx);
hasCellFields = f.IsFieldCell();
}
if (!hasCellFields)
{
this->Worklet.ReleaseCellMapArrays();
}
//4. create the output dataset
vtkm::cont::DataSet output;
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
if (this->CompactPoints)
{
this->Compactor.SetCompactPointFields(true);
this->Compactor.SetMergePoints(false);
return this->Compactor.Execute(output, PolicyDefault{});
}
else
{
return output;
}
}
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ExternalFaces);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_ExternalFaces_h #ifndef vtk_m_filter_ExternalFaces_h
#define vtk_m_filter_ExternalFaces_h #define vtk_m_filter_ExternalFaces_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/CleanGrid.h> #include <vtkm/filter/CleanGrid.h>
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExternalFaces.h> #include <vtkm/worklet/ExternalFaces.h>
@ -28,10 +30,10 @@ namespace filter
/// @warning /// @warning
/// This filter is currently only supports propagation of point properties /// This filter is currently only supports propagation of point properties
/// ///
class ExternalFaces : public vtkm::filter::FilterDataSet<ExternalFaces> class VTKM_ALWAYS_EXPORT ExternalFaces : public vtkm::filter::FilterDataSet<ExternalFaces>
{ {
public: public:
VTKM_CONT VTKM_FILTER_EXPORT
ExternalFaces(); ExternalFaces();
// When CompactPoints is set, instead of copying the points and point fields // When CompactPoints is set, instead of copying the points and point fields
@ -63,17 +65,45 @@ public:
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy); vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
if (fieldMeta.IsPointField())
{
if (this->CompactPoints)
{
return this->Compactor.DoMapField(result, input, fieldMeta, policy);
}
else
{
result.AddField(fieldMeta.AsField(input));
return true;
}
}
else if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> fieldArray;
fieldArray = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(fieldArray));
return true;
}
public: return false;
}
private:
bool CompactPoints; bool CompactPoints;
bool PassPolyData; bool PassPolyData;
VTKM_FILTER_EXPORT vtkm::cont::DataSet GenerateOutput(const vtkm::cont::DataSet& input,
vtkm::cont::CellSetExplicit<>& outCellSet);
vtkm::filter::CleanGrid Compactor; vtkm::filter::CleanGrid Compactor;
vtkm::worklet::ExternalFaces Worklet; vtkm::worklet::ExternalFaces Worklet;
}; };
#ifndef vtkm_filter_ExternalFaces_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(ExternalFaces);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/ExternalFaces.hxx>
#endif // vtk_m_filter_ExternalFaces_h #endif // vtk_m_filter_ExternalFaces_h

@ -13,33 +13,6 @@ namespace vtkm
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT ExternalFaces::ExternalFaces()
: vtkm::filter::FilterDataSet<ExternalFaces>()
, CompactPoints(false)
, Worklet()
{
this->SetPassPolyData(true);
}
namespace
{
template <typename BasePolicy>
struct CellSetExplicitPolicy : public BasePolicy
{
using AllCellSetList = vtkm::cont::CellSetListTagExplicitDefault;
};
template <typename DerivedPolicy>
inline vtkm::filter::PolicyBase<CellSetExplicitPolicy<DerivedPolicy>> GetCellSetExplicitPolicy(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
return vtkm::filter::PolicyBase<CellSetExplicitPolicy<DerivedPolicy>>();
}
} // anonymous namespace
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet ExternalFaces::DoExecute( inline VTKM_CONT vtkm::cont::DataSet ExternalFaces::DoExecute(
@ -64,68 +37,7 @@ inline VTKM_CONT vtkm::cont::DataSet ExternalFaces::DoExecute(
this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetUnstructured(cells, policy), outCellSet); this->Worklet.Run(vtkm::filter::ApplyPolicyCellSetUnstructured(cells, policy), outCellSet);
} }
//3. Check the fields of the dataset to see what kinds of fields are present so return this->GenerateOutput(input, outCellSet);
// we can free the cell mapping array if it won't be needed.
const vtkm::Id numFields = input.GetNumberOfFields();
bool hasCellFields = false;
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields && !hasCellFields; ++fieldIdx)
{
auto f = input.GetField(fieldIdx);
hasCellFields = f.IsFieldCell();
}
if (!hasCellFields)
{
this->Worklet.ReleaseCellMapArrays();
}
//4. create the output dataset
vtkm::cont::DataSet output;
output.SetCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
if (this->CompactPoints)
{
this->Compactor.SetCompactPointFields(true);
this->Compactor.SetMergePoints(false);
return this->Compactor.DoExecute(output, GetCellSetExplicitPolicy(policy));
}
else
{
return output;
}
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT bool ExternalFaces::DoMapField(
vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy)
{
if (fieldMeta.IsPointField())
{
if (this->CompactPoints)
{
return this->Compactor.DoMapField(result, input, fieldMeta, policy);
}
else
{
result.AddField(fieldMeta.AsField(input));
return true;
}
}
else if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> fieldArray;
fieldArray = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(fieldArray));
return true;
}
return false;
} }
} }
} }

@ -11,24 +11,6 @@
#include <vtkm/cont/CoordinateSystem.h> #include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DynamicCellSet.h> #include <vtkm/cont/DynamicCellSet.h>
namespace
{
// Needed to CompactPoints
template <typename BasePolicy>
struct CellSetSingleTypePolicy : public BasePolicy
{
using AllCellSetList = vtkm::cont::CellSetListTagUnstructured;
};
template <typename DerivedPolicy>
inline vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>> GetCellSetSingleTypePolicy(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
return vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>>();
}
}
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
@ -71,7 +53,7 @@ inline vtkm::cont::DataSet ExtractPoints::DoExecute(const vtkm::cont::DataSet& i
{ {
this->Compactor.SetCompactPointFields(true); this->Compactor.SetCompactPointFields(true);
this->Compactor.SetMergePoints(false); this->Compactor.SetMergePoints(false);
return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); return this->Compactor.Execute(output, PolicyDefault{});
} }
else else
{ {

@ -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.
//============================================================================
#define vtkm_filter_ExtractStructured_cxx
#include <vtkm/filter/ExtractStructured.h>
#include <vtkm/filter/ExtractStructured.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
ExtractStructured::ExtractStructured()
: vtkm::filter::FilterDataSet<ExtractStructured>()
, VOI(vtkm::RangeId3(0, -1, 0, -1, 0, -1))
, SampleRate(vtkm::Id3(1, 1, 1))
, IncludeBoundary(false)
, IncludeOffset(false)
, Worklet()
{
}
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(ExtractStructured);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_ExtractStructured_h #ifndef vtk_m_filter_ExtractStructured_h
#define vtk_m_filter_ExtractStructured_h #define vtk_m_filter_ExtractStructured_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/ExtractStructured.h> #include <vtkm/worklet/ExtractStructured.h>
@ -34,10 +36,10 @@ namespace filter
/// for image processing, subsampling large volumes to reduce data size, or /// for image processing, subsampling large volumes to reduce data size, or
/// extracting regions of a volume with interesting data. /// extracting regions of a volume with interesting data.
/// ///
class ExtractStructured : public vtkm::filter::FilterDataSet<ExtractStructured> class VTKM_ALWAYS_EXPORT ExtractStructured : public vtkm::filter::FilterDataSet<ExtractStructured>
{ {
public: public:
VTKM_CONT VTKM_FILTER_EXPORT
ExtractStructured(); ExtractStructured();
// Set the bounding box for the volume of interest // Set the bounding box for the volume of interest
@ -90,7 +92,27 @@ public:
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy); vtkm::filter::PolicyBase<DerivedPolicy>)
{
if (fieldMeta.IsPointField())
{
vtkm::cont::ArrayHandle<T> output = this->Worklet.ProcessPointField(input);
result.AddField(fieldMeta.AsField(output));
return true;
}
// cell data must be scattered to the cells created per input cell
if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> output = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(output));
return true;
}
return false;
}
private: private:
vtkm::RangeId3 VOI; vtkm::RangeId3 VOI;
@ -99,9 +121,12 @@ private:
bool IncludeOffset; bool IncludeOffset;
vtkm::worklet::ExtractStructured Worklet; vtkm::worklet::ExtractStructured Worklet;
}; };
#ifndef vtkm_filter_ExtractStructured_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(ExtractStructured);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/ExtractStructured.hxx>
#endif // vtk_m_filter_ExtractStructured_h #endif // vtk_m_filter_ExtractStructured_h

@ -12,18 +12,6 @@ namespace vtkm
{ {
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT ExtractStructured::ExtractStructured()
: vtkm::filter::FilterDataSet<ExtractStructured>()
, VOI(vtkm::RangeId3(0, -1, 0, -1, 0, -1))
, SampleRate(vtkm::Id3(1, 1, 1))
, IncludeBoundary(false)
, IncludeOffset(false)
, Worklet()
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet ExtractStructured::DoExecute( inline VTKM_CONT vtkm::cont::DataSet ExtractStructured::DoExecute(
@ -47,33 +35,5 @@ inline VTKM_CONT vtkm::cont::DataSet ExtractStructured::DoExecute(
output.AddCoordinateSystem(outputCoordinates); output.AddCoordinateSystem(outputCoordinates);
return output; return output;
} }
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT bool ExtractStructured::DoMapField(
vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
if (fieldMeta.IsPointField())
{
vtkm::cont::ArrayHandle<T> output = this->Worklet.ProcessPointField(input);
result.AddField(fieldMeta.AsField(output));
return true;
}
// cell data must be scattered to the cells created per input cell
if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> output = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(output));
return true;
}
return false;
}
} }
} }

@ -279,5 +279,18 @@ private:
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#define VTKM_FILTER_EXPORT_EXECUTE_METHOD_WITH_POLICY(Name, Policy) \
extern template VTKM_FILTER_TEMPLATE_EXPORT vtkm::cont::PartitionedDataSet \
vtkm::filter::Filter<Name>::Execute(vtkm::cont::PartitionedDataSet const&, \
vtkm::filter::PolicyBase<Policy>)
#define VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD_WITH_POLICY(Name, Policy) \
template VTKM_FILTER_EXPORT vtkm::cont::PartitionedDataSet Filter<Name>::Execute( \
vtkm::cont::PartitionedDataSet const&, vtkm::filter::PolicyBase<Policy>)
#define VTKM_FILTER_EXPORT_EXECUTE_METHOD(Name) \
VTKM_FILTER_EXPORT_EXECUTE_METHOD_WITH_POLICY(Name, vtkm::filter::PolicyDefault)
#define VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Name) \
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD_WITH_POLICY(Name, vtkm::filter::PolicyDefault)
#include <vtkm/filter/Filter.hxx> #include <vtkm/filter/Filter.hxx>
#endif #endif

@ -264,7 +264,7 @@ inline VTKM_CONT vtkm::cont::PartitionedDataSet Filter<Derived>::Execute(
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template <typename Derived> template <typename Derived>
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Filter<Derived>::Execute( VTKM_CONT vtkm::cont::DataSet Filter<Derived>::Execute(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
@ -284,7 +284,7 @@ inline VTKM_CONT vtkm::cont::DataSet Filter<Derived>::Execute(
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template <typename Derived> template <typename Derived>
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::PartitionedDataSet Filter<Derived>::Execute( VTKM_CONT vtkm::cont::PartitionedDataSet Filter<Derived>::Execute(
const vtkm::cont::PartitionedDataSet& input, const vtkm::cont::PartitionedDataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {

@ -46,7 +46,7 @@ inline VTKM_CONT FilterField<Derived>::~FilterField()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename Derived> template <typename Derived>
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution( VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
vtkm::filter::PolicyBase<DerivedPolicy> policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
@ -67,7 +67,7 @@ inline VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename Derived> template <typename Derived>
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution( VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::cont::Field& field, const vtkm::cont::Field& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
@ -89,7 +89,7 @@ inline VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename Derived> template <typename Derived>
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution( VTKM_CONT vtkm::cont::DataSet FilterField<Derived>::PrepareForExecution(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::cont::CoordinateSystem& field, const vtkm::cont::CoordinateSystem& field,
vtkm::filter::PolicyBase<DerivedPolicy> policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)

@ -328,7 +328,7 @@ inline VTKM_CONT vtkm::cont::DataSet GhostCellRemove::DoExecute(
extract.SetFieldsToPass(this->GetActiveFieldName(), extract.SetFieldsToPass(this->GetActiveFieldName(),
vtkm::filter::FieldSelection::MODE_EXCLUDE); vtkm::filter::FieldSelection::MODE_EXCLUDE);
auto output = extract.Execute(input, vtkm::filter::GhostCellRemovePolicy()); auto output = extract.Execute(input);
return output; return output;
} }
} }

@ -11,7 +11,6 @@
#ifndef vtk_m_filter_Mask_h #ifndef vtk_m_filter_Mask_h
#define vtk_m_filter_Mask_h #define vtk_m_filter_Mask_h
#include <vtkm/filter/CleanGrid.h>
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/Mask.h> #include <vtkm/worklet/Mask.h>

@ -8,24 +8,6 @@
// PURPOSE. See the above copyright notice for more information. // PURPOSE. See the above copyright notice for more information.
//============================================================================ //============================================================================
namespace
{
// Needed to CompactPoints
template <typename BasePolicy>
struct CellSetSingleTypePolicy : public BasePolicy
{
using AllCellSetList = vtkm::cont::CellSetListTagUnstructured;
};
template <typename DerivedPolicy>
inline vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>> GetCellSetSingleTypePolicy(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
return vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>>();
}
}
namespace vtkm namespace vtkm
{ {
namespace filter namespace filter
@ -64,7 +46,7 @@ inline VTKM_CONT vtkm::cont::DataSet MaskPoints::DoExecute(
{ {
this->Compactor.SetCompactPointFields(true); this->Compactor.SetCompactPointFields(true);
this->Compactor.SetMergePoints(false); this->Compactor.SetMergePoints(false);
return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); return this->Compactor.Execute(output, PolicyDefault{});
} }
else else
{ {

@ -0,0 +1,22 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_PointAverage_cxx
#include <vtkm/filter/PointAverage.h>
#include <vtkm/filter/PointAverage.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(PointAverage);
}
}

@ -11,6 +11,9 @@
#ifndef vtk_m_filter_PointAverage_h #ifndef vtk_m_filter_PointAverage_h
#define vtk_m_filter_PointAverage_h #define vtk_m_filter_PointAverage_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/filter/FilterCell.h> #include <vtkm/filter/FilterCell.h>
#include <vtkm/worklet/PointAverage.h> #include <vtkm/worklet/PointAverage.h>
@ -24,24 +27,23 @@ namespace filter
/// specified per cell) into point data (i.e., data specified at cell /// specified per cell) into point data (i.e., data specified at cell
/// points). The method of transformation is based on averaging the data /// points). The method of transformation is based on averaging the data
/// values of all cells using a particular point. /// values of all cells using a particular point.
class PointAverage : public vtkm::filter::FilterCell<PointAverage> class VTKM_ALWAYS_EXPORT PointAverage : public vtkm::filter::FilterCell<PointAverage>
{ {
public: public:
VTKM_CONT
PointAverage();
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input, VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field, const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy); vtkm::filter::PolicyBase<DerivedPolicy> policy);
private: private:
vtkm::worklet::PointAverage Worklet; vtkm::worklet::PointAverage Worklet;
}; };
#ifndef vtkm_filter_PointAverage_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(PointAverage);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/PointAverage.hxx>
#endif // vtk_m_filter_PointAverage_h #endif // vtk_m_filter_PointAverage_h

@ -16,20 +16,13 @@ namespace vtkm
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT PointAverage::PointAverage()
: vtkm::filter::FilterCell<PointAverage>()
, Worklet()
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet PointAverage::DoExecute( inline VTKM_CONT vtkm::cont::DataSet PointAverage::DoExecute(
const vtkm::cont::DataSet& input, const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& inField, const vtkm::cont::ArrayHandle<T, StorageType>& inField,
const vtkm::filter::FieldMetadata& fieldMetadata, const vtkm::filter::FieldMetadata& fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy) vtkm::filter::PolicyBase<DerivedPolicy> policy)
{ {
if (!fieldMetadata.IsCellField()) if (!fieldMetadata.IsCellField())
{ {

21
vtkm/filter/Threshold.cxx Normal file

@ -0,0 +1,21 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_Threshold_cxx
#include <vtkm/filter/Threshold.h>
#include <vtkm/filter/Threshold.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(Threshold);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_Threshold_h #ifndef vtk_m_filter_Threshold_h
#define vtk_m_filter_Threshold_h #define vtk_m_filter_Threshold_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterDataSetWithField.h> #include <vtkm/filter/FilterDataSetWithField.h>
#include <vtkm/worklet/Threshold.h> #include <vtkm/worklet/Threshold.h>
@ -28,14 +30,11 @@ namespace filter
/// filter is an permutation of the input dataset. /// filter is an permutation of the input dataset.
/// ///
/// You can threshold either on point or cell fields /// You can threshold either on point or cell fields
class Threshold : public vtkm::filter::FilterDataSetWithField<Threshold> class VTKM_ALWAYS_EXPORT Threshold : public vtkm::filter::FilterDataSetWithField<Threshold>
{ {
public: public:
using SupportedTypes = vtkm::TypeListTagScalarAll; using SupportedTypes = vtkm::TypeListTagScalarAll;
VTKM_CONT
Threshold();
VTKM_CONT VTKM_CONT
void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; } void SetLowerThreshold(vtkm::Float64 value) { this->LowerValue = value; }
VTKM_CONT VTKM_CONT
@ -58,16 +57,36 @@ public:
VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result, VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input, const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy> policy); vtkm::filter::PolicyBase<DerivedPolicy>)
{
if (fieldMeta.IsPointField())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(fieldMeta.AsField(input));
return true;
}
else if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> out = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(out));
return true;
}
else
{
return false;
}
}
private: private:
double LowerValue; double LowerValue = 0;
double UpperValue; double UpperValue = 0;
vtkm::worklet::Threshold Worklet; vtkm::worklet::Threshold Worklet;
}; };
#ifndef vtkm_filter_Threshold_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(Threshold);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/Threshold.hxx>
#endif // vtk_m_filter_Threshold_h #endif // vtk_m_filter_Threshold_h

@ -44,14 +44,6 @@ namespace vtkm
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT Threshold::Threshold()
: vtkm::filter::FilterDataSetWithField<Threshold>()
, LowerValue(0)
, UpperValue(0)
{
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute( inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute(
@ -72,30 +64,5 @@ inline VTKM_CONT vtkm::cont::DataSet Threshold::DoExecute(
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()));
return output; return output;
} }
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT bool Threshold::DoMapField(vtkm::cont::DataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
vtkm::filter::PolicyBase<DerivedPolicy>)
{
if (fieldMeta.IsPointField())
{
//we copy the input handle to the result dataset, reusing the metadata
result.AddField(fieldMeta.AsField(input));
return true;
}
else if (fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T> out = this->Worklet.ProcessCellField(input);
result.AddField(fieldMeta.AsField(out));
return true;
}
else
{
return false;
}
}
} }
} }

@ -12,21 +12,6 @@
namespace namespace
{ {
// Needed to CompactPoints
template <typename BasePolicy>
struct CellSetSingleTypePolicy : public BasePolicy
{
using AllCellSetList = vtkm::cont::CellSetListTagUnstructured;
};
template <typename DerivedPolicy>
inline vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>> GetCellSetSingleTypePolicy(
const vtkm::filter::PolicyBase<DerivedPolicy>&)
{
return vtkm::filter::PolicyBase<CellSetSingleTypePolicy<DerivedPolicy>>();
}
// Predicate for values less than minimum // Predicate for values less than minimum
class ValuesBelow class ValuesBelow
{ {
@ -191,7 +176,7 @@ inline VTKM_CONT vtkm::cont::DataSet ThresholdPoints::DoExecute(
{ {
this->Compactor.SetCompactPointFields(true); this->Compactor.SetCompactPointFields(true);
this->Compactor.SetMergePoints(true); this->Compactor.SetMergePoints(true);
return this->Compactor.DoExecute(output, GetCellSetSingleTypePolicy(policy)); return this->Compactor.Execute(output, PolicyDefault{});
} }
else else
{ {

@ -0,0 +1,31 @@
//============================================================================
// 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.
//============================================================================
#define vtkm_filter_VectorMagnitude_cxx
#include <vtkm/filter/VectorMagnitude.h>
#include <vtkm/filter/VectorMagnitude.hxx>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
VectorMagnitude::VectorMagnitude()
: vtkm::filter::FilterField<VectorMagnitude>()
, Worklet()
{
this->SetOutputFieldName("magnitude");
}
//-----------------------------------------------------------------------------
VTKM_FILTER_INSTANTIATE_EXECUTE_METHOD(VectorMagnitude);
}
}

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_VectorMagnitude_h #ifndef vtk_m_filter_VectorMagnitude_h
#define vtk_m_filter_VectorMagnitude_h #define vtk_m_filter_VectorMagnitude_h
#include <vtkm/filter/vtkm_filter_export.h>
#include <vtkm/filter/FilterField.h> #include <vtkm/filter/FilterField.h>
#include <vtkm/worklet/Magnitude.h> #include <vtkm/worklet/Magnitude.h>
@ -19,13 +21,13 @@ namespace vtkm
namespace filter namespace filter
{ {
class VectorMagnitude : public vtkm::filter::FilterField<VectorMagnitude> class VTKM_ALWAYS_EXPORT VectorMagnitude : public vtkm::filter::FilterField<VectorMagnitude>
{ {
public: public:
//currently the VectorMagnitude filter only works on vector data. //currently the VectorMagnitude filter only works on vector data.
using SupportedTypes = vtkm::TypeListTagVecCommon; using SupportedTypes = vtkm::TypeListTagVecCommon;
VTKM_CONT VTKM_FILTER_EXPORT
VectorMagnitude(); VectorMagnitude();
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
@ -37,9 +39,10 @@ public:
private: private:
vtkm::worklet::Magnitude Worklet; vtkm::worklet::Magnitude Worklet;
}; };
#ifndef vtkm_filter_VectorMagnitude_cxx
VTKM_FILTER_EXPORT_EXECUTE_METHOD(VectorMagnitude);
#endif
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#include <vtkm/filter/VectorMagnitude.hxx>
#endif // vtk_m_filter_VectorMagnitude_h #endif // vtk_m_filter_VectorMagnitude_h

@ -15,14 +15,6 @@ namespace vtkm
namespace filter namespace filter
{ {
//-----------------------------------------------------------------------------
inline VTKM_CONT VectorMagnitude::VectorMagnitude()
: vtkm::filter::FilterField<VectorMagnitude>()
, Worklet()
{
this->SetOutputFieldName("magnitude");
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute( inline VTKM_CONT vtkm::cont::DataSet VectorMagnitude::DoExecute(

@ -18,6 +18,7 @@
#include <vtkm/filter/CleanGrid.h> #include <vtkm/filter/CleanGrid.h>
#include <vtkm/filter/Contour.h> #include <vtkm/filter/Contour.h>
#include <vtkm/filter/Contour.hxx>
#include <vtkm/source/Tangle.h> #include <vtkm/source/Tangle.h>
namespace vtkm_ut_mc_filter namespace vtkm_ut_mc_filter

@ -244,12 +244,12 @@ void TestWithStructuredData()
contour.SetGenerateNormals(true); contour.SetGenerateNormals(true);
contour.SetComputeFastNormalsForStructured(true); contour.SetComputeFastNormalsForStructured(true);
contour.SetNormalArrayName("normals"); contour.SetNormalArrayName("normals");
dataSet = contour.Execute(dataSet, SplitSharpTestPolicy{}); dataSet = contour.Execute(dataSet);
// Compute cell normals: // Compute cell normals:
vtkm::filter::CellAverage cellNormals; vtkm::filter::CellAverage cellNormals;
cellNormals.SetActiveField("normals", vtkm::cont::Field::Association::POINTS); cellNormals.SetActiveField("normals", vtkm::cont::Field::Association::POINTS);
dataSet = cellNormals.Execute(dataSet, SplitSharpTestPolicy{}); dataSet = cellNormals.Execute(dataSet);
// Split sharp edges: // Split sharp edges:
std::cout << dataSet.GetNumberOfCells() << std::endl; std::cout << dataSet.GetNumberOfCells() << std::endl;

@ -89,7 +89,7 @@ set(unit_tests
vtkm_unit_tests( vtkm_unit_tests(
SOURCES ${unit_tests} SOURCES ${unit_tests}
LIBRARIES vtkm_worklet vtkm_source LIBRARIES vtkm_source vtkm_worklet vtkm_filter
ALL_BACKENDS ALL_BACKENDS
) )
if (TARGET vtkm::cuda) if (TARGET vtkm::cuda)

@ -73,7 +73,7 @@ vtkm::cont::DataSet CreateDataSet(bool pointNormals, bool cellNormals)
contour.SetIsoValue(192); contour.SetIsoValue(192);
contour.SetMergeDuplicatePoints(true); contour.SetMergeDuplicatePoints(true);
contour.SetGenerateNormals(false); contour.SetGenerateNormals(false);
dataSet = contour.Execute(dataSet, TestPolicy{}); dataSet = contour.Execute(dataSet);
vtkm::filter::SurfaceNormals normals; vtkm::filter::SurfaceNormals normals;
normals.SetGeneratePointNormals(pointNormals); normals.SetGeneratePointNormals(pointNormals);