2021-12-03 20:44:51 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
//
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_filter_NewFilter_h
|
|
|
|
#define vtk_m_filter_NewFilter_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
#include <vtkm/cont/Invoker.h>
|
|
|
|
#include <vtkm/cont/Logging.h>
|
|
|
|
#include <vtkm/cont/PartitionedDataSet.h>
|
|
|
|
|
|
|
|
#include <vtkm/filter/FieldSelection.h>
|
2022-08-11 17:43:49 +00:00
|
|
|
#include <vtkm/filter/TaskQueue.h>
|
2021-12-03 20:44:51 +00:00
|
|
|
#include <vtkm/filter/vtkm_filter_core_export.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
/// \brief base class for all filters.
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// This is the base class for all filters. To add a new filter, one can subclass this (or any of
|
|
|
|
/// the existing subclasses e.g. FilterField, FilterParticleAdvection, etc.) and implement relevant
|
|
|
|
/// methods.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \section FilterUsage Usage
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// To execute a filter, one typically calls the `auto result = filter.Execute(input)`. Typical
|
|
|
|
/// usage is as follows:
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \code{cpp}
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// // create the concrete subclass (e.g. Contour).
|
|
|
|
/// vtkm::filter::contour::Contour contour;
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// // select fields to map to the output, if different from default which is to map all input
|
|
|
|
/// // fields.
|
|
|
|
/// contour.SetFieldToPass({"var1", "var2"});
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// // execute the filter on vtkm::cont::DataSet.
|
|
|
|
/// vtkm::cont::DataSet dsInput = ...
|
2021-12-10 00:28:44 +00:00
|
|
|
/// auto outputDS = contour.Execute(dsInput);
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// // or, execute on a vtkm::cont::PartitionedDataSet
|
|
|
|
/// vtkm::cont::PartitionedDataSet mbInput = ...
|
2021-12-10 00:28:44 +00:00
|
|
|
/// auto outputMB = contour.Execute(mbInput);
|
2021-12-03 20:44:51 +00:00
|
|
|
/// \endcode
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// `Execute` methods take in the input DataSet or PartitionedDataSet to process and return the
|
|
|
|
/// result. The type of the result is same as the input type, thus `Execute(DataSet&)` returns
|
|
|
|
/// a DataSet while `Execute(PartitionedDataSet&)` returns a PartitionedDataSet.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// `Execute` simply calls the pure virtual function `DoExecute(DataSet&)` which is the main
|
|
|
|
/// extension point of the Filter interface. Filter developer needs to override
|
|
|
|
/// `DoExecute(DataSet)` to implement the business logic of filtering operations on a single
|
|
|
|
/// DataSet.
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// The default implementation of `Execute(PartitionedDataSet&)` is merely provided for
|
2021-12-13 19:17:15 +00:00
|
|
|
/// convenience. Internally, it calls `DoExecutePartitions(PartitionedDataSet)` to iterate DataSets
|
2021-12-10 00:28:44 +00:00
|
|
|
/// of a PartitionedDataSet and pass each individual DataSets to `DoExecute(DataSet&)`,
|
|
|
|
/// possibly in a multi-threaded setting. Developer of `DoExecute(DataSet&)` needs to indicate
|
|
|
|
/// the thread-safeness of `DoExecute(DataSet&)` by overriding the `CanThread()` virtual method
|
|
|
|
/// which by default returns `true`.
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// In the case that filtering on a PartitionedDataSet can not be simply implemented as a
|
|
|
|
/// for-each loop on the component DataSets, filter implementor needs to override the
|
2021-12-13 19:17:15 +00:00
|
|
|
/// `DoExecutePartitions(PartitionedDataSet&)`. See the implementation of
|
2021-12-04 02:13:06 +00:00
|
|
|
/// `FilterParticleAdvection::Execute(PartitionedDataSet&)` for an example.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \section FilterSubclassing Subclassing
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// In many uses cases, one subclasses one of the immediate subclasses of this class such as
|
|
|
|
/// FilterField, FilterParticleAdvection, etc. Those may impose additional constraints on the
|
|
|
|
/// methods to implement in the subclasses. Here, we describes the things to consider when directly
|
|
|
|
/// subclassing vtkm::filter::NewFilter.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-04 02:13:06 +00:00
|
|
|
/// \subsection FilterExecution Execute
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// A concrete subclass of Filter must provide `DoExecute` implementation that provides the meat
|
|
|
|
/// for the filter i.e. the implementation for the filter's data processing logic. There are two
|
|
|
|
/// signatures available; which one to implement depends on the nature of the filter.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// Let's consider simple filters that do not need to do anything special to handle
|
|
|
|
/// PartitionedDataSet e.g. clip, contour, etc. These are the filters where executing the filter
|
|
|
|
/// on a PartitionedDataSet simply means executing the filter on one partition at a time and
|
|
|
|
/// packing the output for each iteration info the result PartitionedDataSet. For such filters,
|
|
|
|
/// one must implement the following signature.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \code{cpp}
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input);
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \endcode
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// The role of this method is to execute on the input dataset and generate the result and return
|
|
|
|
/// it. If there are any errors, the subclass must throw an exception
|
|
|
|
/// (e.g. `vtkm::cont::ErrorFilterExecution`).
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// In this simple case, the NewFilter superclass handles iterating over multiple partitions in the
|
|
|
|
/// input PartitionedDataSet and calling `DoExecute(DataSet&)` iteratively.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// The aforementioned approach is also suitable for filters that need special handling for
|
|
|
|
/// PartitionedDataSets that requires certain cross DataSet operations (usually scatter/gather
|
|
|
|
/// and reduction on DataSets) before and/or after the per DataSet operation. This can be done by
|
2021-12-13 19:17:15 +00:00
|
|
|
/// overriding `DoExecutePartitions(PartitionedDataSet&)` while calling to the base class
|
|
|
|
/// `DoExecutePartitions(PartitionedDataSet&) as helper function for iteration on DataSets.
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \code{cpp}
|
2021-12-13 19:17:15 +00:00
|
|
|
/// vtkm::cont::PartitionedDataSet FooFilter::DoExecutePartitions(
|
2021-12-10 00:28:44 +00:00
|
|
|
/// const vtkm::cont::PartitionedDataSet& input)
|
|
|
|
/// {
|
|
|
|
/// // Do pre execute stuff, e.g. scattering to each DataSet
|
2021-12-13 19:17:15 +00:00
|
|
|
/// auto output = this->NewFilter::DoExecutePartitions(input);
|
2021-12-10 00:28:44 +00:00
|
|
|
/// // Do post execute stuff, e.g gather/reduce from DataSets
|
|
|
|
/// return output;
|
|
|
|
/// }
|
2021-12-03 20:44:51 +00:00
|
|
|
/// \endcode
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// For more complex filters, like streamlines, particle tracking, where the processing of
|
|
|
|
/// PartitionedDataSets cannot be modelled as mapping and reduction operation on DataSet, one
|
2021-12-13 19:17:15 +00:00
|
|
|
/// needs fully implement `DoExecutePartitions(PartitionedDataSet&)`. Now the subclass is given
|
|
|
|
/// full control over the execution, including any mapping of fields to output (described in next
|
|
|
|
/// sub-section).
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2022-01-27 00:11:11 +00:00
|
|
|
/// \subsection Creating results and mapping fields
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-04 02:13:06 +00:00
|
|
|
/// For subclasses that map input fields into output fields, the implementation of its
|
2022-01-27 00:11:11 +00:00
|
|
|
/// `DoExecute(DataSet&)` should create the `DataSet` to be returned with a call to
|
|
|
|
/// `NewFilter::CreateResult` or a similar method in a subclass (such as
|
|
|
|
/// `NewFilterField::CreateResultField`).
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
|
|
|
/// \code{cpp}
|
2021-12-10 00:28:44 +00:00
|
|
|
/// VTKM_CONT DataSet SomeFilter::DoExecute(const vtkm::cont::DataSet& input)
|
2021-12-04 02:13:06 +00:00
|
|
|
/// {
|
2022-01-27 00:11:11 +00:00
|
|
|
/// vtkm::cont::UnknownCellSet outCellSet;
|
|
|
|
/// outCellSet = ... // Generation of the new CellSet
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// // Mapper is a callable object (function object, lambda, etc.) that takes an input Field
|
|
|
|
/// // and maps it to an output Field and then add the output Field to the output DataSet
|
|
|
|
/// auto mapper = [](auto& outputDs, const auto& inputField) {
|
|
|
|
/// auto outputField = ... // Business logic for mapping input field to output field
|
|
|
|
/// output.AddField(outputField);
|
|
|
|
/// };
|
2022-01-27 00:11:11 +00:00
|
|
|
/// // This passes coordinate systems directly from input to output. If the points of
|
|
|
|
/// // the cell set change at all, they will have to be mapped by hand.
|
2022-10-31 17:22:37 +00:00
|
|
|
/// return this->CreateResult(input, outCellSet, mapper);
|
2021-12-04 02:13:06 +00:00
|
|
|
/// }
|
|
|
|
/// \endcode
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2022-01-27 00:11:11 +00:00
|
|
|
/// In addition to creating a new `DataSet` filled with the proper cell structure and coordinate
|
|
|
|
/// systems, `CreateResult` iterates through each `FieldToPass` in the input DataSet and calls the
|
|
|
|
/// FieldMapper to map the input Field to output Field. For simple filters that just pass on input
|
2021-12-04 02:13:06 +00:00
|
|
|
/// fields to the output DataSet without any computation, an overload of
|
2022-01-27 00:11:11 +00:00
|
|
|
/// `CreateResult(const vtkm::cont::DataSet& input)` is also
|
2021-12-10 00:28:44 +00:00
|
|
|
/// provided as a convenience that uses the default mapper which trivially adds input Field to
|
2022-01-27 00:11:11 +00:00
|
|
|
/// output DataSet (via a shallow copy).
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// \subsection FilterThreadSafety CanThread
|
|
|
|
///
|
2021-12-10 00:28:44 +00:00
|
|
|
/// By default, the implementation of `DoExecute(DataSet&)` should model a *pure function*, i.e. it
|
2021-12-04 02:13:06 +00:00
|
|
|
/// does not have any mutable shared state. This makes it thread-safe by default and allows
|
2021-12-13 19:17:15 +00:00
|
|
|
/// the default implementation of `DoExecutePartitions(PartitionedDataSet&)` to be simply a parallel
|
|
|
|
/// for-each, thus facilitates multi-threaded execution without any lock.
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// Many legacy (VTKm 1.x) filter implementations needed to store states between the mesh generation
|
|
|
|
/// phase and field mapping phase of filter execution, for example, parameters for field
|
|
|
|
/// interpolation. The shared mutable states were mostly stored as mutable data members of the
|
|
|
|
/// filter class (either in terms of ArrayHandle or some kind of Worket). The new filter interface,
|
2021-12-10 00:28:44 +00:00
|
|
|
/// by combining the two phases into a single call to `DoExecute(DataSet&)`, we have eliminated most
|
2021-12-04 02:13:06 +00:00
|
|
|
/// of the cases that require such shared mutable states. New implementations of filters that
|
|
|
|
/// require passing information between these two phases can now use local variables within the
|
2021-12-10 00:28:44 +00:00
|
|
|
/// `DoExecute(DataSet&)`. For example:
|
2021-12-03 20:44:51 +00:00
|
|
|
///
|
2021-12-04 02:13:06 +00:00
|
|
|
/// \code{cpp}
|
|
|
|
/// struct SharedState; // shared states between mesh generation and field mapping.
|
2021-12-10 00:28:44 +00:00
|
|
|
/// VTKM_CONT DataSet ThreadSafeFilter::DoExecute(const vtkm::cont::DataSet& input)
|
2021-12-04 02:13:06 +00:00
|
|
|
/// {
|
|
|
|
/// // Mutable states that was a data member of the filter is now a local variable.
|
|
|
|
/// // Each invocation of Execute(DataSet) in the multi-threaded execution of
|
|
|
|
/// // Execute(PartitionedDataSet&) will have a copy of `states` on each thread's stack
|
|
|
|
/// // thus making it thread-safe.
|
|
|
|
/// SharedStates states;
|
|
|
|
///
|
2022-10-31 17:22:37 +00:00
|
|
|
/// vtkm::cont::CellSetExplicit<> cellSet;
|
|
|
|
/// cellSet = ... // Generation of the new DataSet and store interpolation parameters in `states`
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// // Lambda capture of `states`, effectively passing the shared states to the Mapper.
|
|
|
|
/// auto mapper = [&states](auto& outputDs, const auto& inputField) {
|
|
|
|
/// auto outputField = ... // Use `states` for mapping input field to output field
|
|
|
|
/// output.AddField(outputField);
|
|
|
|
/// };
|
2022-10-31 17:22:37 +00:00
|
|
|
/// this->CreateOutput(input, cellSet, mapper);
|
2021-12-04 02:13:06 +00:00
|
|
|
///
|
|
|
|
/// return output;
|
|
|
|
/// }
|
2021-12-03 20:44:51 +00:00
|
|
|
/// \endcode
|
|
|
|
///
|
2021-12-04 02:13:06 +00:00
|
|
|
/// In the rare cases that filter implementation can not be made thread-safe, the implementation
|
|
|
|
/// needs to override the `CanThread()` virtual method to return `false`. The default
|
|
|
|
/// `Execute(PartitionedDataSet&)` implementation will fallback to a serial for loop execution.
|
|
|
|
///
|
|
|
|
/// \subsection FilterThreadScheduling DoExecute
|
|
|
|
/// The default multi-threaded execution of `Execute(PartitionedDataSet&)` uses a simple FIFO queue
|
|
|
|
/// of DataSet and pool of *worker* threads. Implementation of Filter subclass can override the
|
2021-12-13 19:17:15 +00:00
|
|
|
/// `DoExecutePartitions(PartitionedDataSet)` virtual method to provide implementation specific
|
|
|
|
/// scheduling policy. The default number of *worker* threads in the pool are determined by the
|
2021-12-04 02:13:06 +00:00
|
|
|
/// `DetermineNumberOfThreads()` virtual method using several backend dependent heuristic.
|
|
|
|
/// Implementations of Filter subclass can also override
|
|
|
|
/// `DetermineNumberOfThreads()` to provide implementation specific heuristic.
|
|
|
|
///
|
2021-12-03 20:44:51 +00:00
|
|
|
class VTKM_FILTER_CORE_EXPORT NewFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2021-12-04 02:13:06 +00:00
|
|
|
virtual ~NewFilter();
|
2021-12-03 20:44:51 +00:00
|
|
|
|
|
|
|
VTKM_CONT
|
2021-12-04 02:13:06 +00:00
|
|
|
virtual bool CanThread() const;
|
2021-12-03 20:44:51 +00:00
|
|
|
|
2022-08-10 20:06:42 +00:00
|
|
|
VTKM_CONT
|
|
|
|
void SetThreadsPerCPU(vtkm::Id numThreads) { this->NumThreadsPerCPU = numThreads; }
|
|
|
|
VTKM_CONT
|
|
|
|
void SetThreadsPerGPU(vtkm::Id numThreads) { this->NumThreadsPerGPU = numThreads; }
|
|
|
|
|
2022-08-11 17:43:49 +00:00
|
|
|
VTKM_CONT
|
2022-08-16 14:59:22 +00:00
|
|
|
vtkm::Id GetThreadsPerCPU() const { return this->NumThreadsPerCPU; }
|
2022-08-11 17:43:49 +00:00
|
|
|
VTKM_CONT
|
2022-08-16 14:59:22 +00:00
|
|
|
vtkm::Id GetThreadsPerGPU() const { return this->NumThreadsPerGPU; }
|
2022-08-11 17:43:49 +00:00
|
|
|
|
2021-12-03 20:44:51 +00:00
|
|
|
VTKM_CONT
|
|
|
|
bool GetRunMultiThreadedFilter() const
|
|
|
|
{
|
|
|
|
return this->CanThread() && this->RunFilterWithMultipleThreads;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
void SetRunMultiThreadedFilter(bool val)
|
|
|
|
{
|
|
|
|
if (this->CanThread())
|
|
|
|
this->RunFilterWithMultipleThreads = val;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string msg =
|
|
|
|
"Multi threaded filter not supported for " + std::string(typeid(*this).name());
|
|
|
|
VTKM_LOG_S(vtkm::cont::LogLevel::Info, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 02:29:48 +00:00
|
|
|
///@{
|
2021-12-03 20:44:51 +00:00
|
|
|
/// \brief Specify which fields get passed from input to output.
|
|
|
|
///
|
|
|
|
/// After a filter successfully executes and returns a new data set, fields are mapped from
|
|
|
|
/// input to output. Depending on what operation the filter does, this could be a simple shallow
|
|
|
|
/// copy of an array, or it could be a computed operation. You can control which fields are
|
|
|
|
/// passed (and equivalently which are not) with this parameter.
|
|
|
|
///
|
|
|
|
/// By default, all fields are passed during execution.
|
|
|
|
///
|
|
|
|
VTKM_CONT
|
|
|
|
void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass)
|
|
|
|
{
|
|
|
|
this->FieldsToPass = fieldsToPass;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
void SetFieldsToPass(const vtkm::filter::FieldSelection& fieldsToPass,
|
2022-03-17 20:45:25 +00:00
|
|
|
vtkm::filter::FieldSelection::Mode mode)
|
2021-12-03 20:44:51 +00:00
|
|
|
{
|
|
|
|
this->FieldsToPass = fieldsToPass;
|
|
|
|
this->FieldsToPass.SetMode(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
void SetFieldsToPass(
|
|
|
|
const std::string& fieldname,
|
|
|
|
vtkm::cont::Field::Association association,
|
2022-03-17 20:45:25 +00:00
|
|
|
vtkm::filter::FieldSelection::Mode mode = vtkm::filter::FieldSelection::Mode::Select)
|
2021-12-03 20:44:51 +00:00
|
|
|
{
|
|
|
|
this->SetFieldsToPass({ fieldname, association }, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
const vtkm::filter::FieldSelection& GetFieldsToPass() const { return this->FieldsToPass; }
|
|
|
|
VTKM_CONT
|
|
|
|
vtkm::filter::FieldSelection& GetFieldsToPass() { return this->FieldsToPass; }
|
2022-09-09 02:29:48 +00:00
|
|
|
///@}
|
2021-12-03 20:44:51 +00:00
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
///@{
|
|
|
|
/// \brief Specify whether to always pass coordinate systems.
|
|
|
|
///
|
|
|
|
/// `CoordinateSystem`s in a `DataSet` are really just point fields marked as being a
|
|
|
|
/// coordinate system. Thus, a coordinate system is passed if and only if the associated
|
|
|
|
/// field is passed.
|
|
|
|
///
|
|
|
|
/// By default, the filter will pass all fields associated with a coordinate system
|
|
|
|
/// regardless of the `FieldsToPass` marks the field as passing. If this option is set
|
|
|
|
/// to `false`, then coordinate systems will only be passed if it is marked so by
|
|
|
|
/// `FieldsToPass`.
|
|
|
|
VTKM_CONT void SetPassCoordinateSystems(bool flag) { this->PassCoordinateSystems = flag; }
|
|
|
|
VTKM_CONT bool GetPassCoordinateSystems() const { return this->PassCoordinateSystems; }
|
|
|
|
///@}
|
|
|
|
|
2022-09-09 02:29:48 +00:00
|
|
|
///@{
|
2021-12-03 20:44:51 +00:00
|
|
|
/// Executes the filter on the input and produces a result dataset.
|
|
|
|
///
|
|
|
|
/// On success, this the dataset produced. On error, vtkm::cont::ErrorExecution will be thrown.
|
2021-12-04 02:13:06 +00:00
|
|
|
VTKM_CONT vtkm::cont::DataSet Execute(const vtkm::cont::DataSet& input);
|
2022-09-09 02:29:48 +00:00
|
|
|
///@}
|
2021-12-03 20:44:51 +00:00
|
|
|
|
2022-09-09 02:29:48 +00:00
|
|
|
///@{
|
2021-12-03 20:44:51 +00:00
|
|
|
/// Executes the filter on the input PartitionedDataSet and produces a result PartitionedDataSet.
|
|
|
|
///
|
|
|
|
/// On success, this the dataset produced. On error, vtkm::cont::ErrorExecution will be thrown.
|
2021-12-04 02:13:06 +00:00
|
|
|
VTKM_CONT vtkm::cont::PartitionedDataSet Execute(const vtkm::cont::PartitionedDataSet& input);
|
2022-09-09 02:29:48 +00:00
|
|
|
///@}
|
2021-12-03 20:44:51 +00:00
|
|
|
|
|
|
|
// FIXME: Is this actually materialize? Are there different kinds of Invoker?
|
|
|
|
/// Specify the vtkm::cont::Invoker to be used to execute worklets by
|
|
|
|
/// this filter instance. Overriding the default allows callers to control
|
|
|
|
/// which device adapters a filter uses.
|
|
|
|
void SetInvoker(vtkm::cont::Invoker inv) { this->Invoke = inv; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
vtkm::cont::Invoker Invoke;
|
|
|
|
|
2022-01-27 00:11:11 +00:00
|
|
|
/// \brief Create the output data set for `DoExecute`.
|
|
|
|
///
|
|
|
|
/// This form of `CreateResult` will create an output data set with the same cell
|
|
|
|
/// structure and coordinate system as the input and pass all fields (as requested
|
|
|
|
/// by the `Filter` state).
|
|
|
|
///
|
|
|
|
/// \param[in] inDataSet The input data set being modified (usually the one passed into
|
|
|
|
/// `DoExecute`). The returned `DataSet` is filled with the cell set, coordinate system, and
|
|
|
|
/// fields of `inDataSet` (as selected by the `FieldsToPass` state of the filter).
|
|
|
|
///
|
|
|
|
VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet) const;
|
2022-08-26 16:03:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// \brief Create the output data set for `DoExecute`.
|
|
|
|
///
|
|
|
|
/// This form of `CreateResult` will create an output PartitionedDataSet with the
|
|
|
|
/// same partitions and pass all PartitionedDataSet fields (as requested by the
|
|
|
|
/// `Filter` state).
|
|
|
|
///
|
|
|
|
/// \param[in] input The input data set being modified (usually the one passed into
|
|
|
|
/// `DoExecute`).
|
|
|
|
/// \param[in] resultPartitions The output data created by the filter. Fields from the input are
|
|
|
|
/// passed onto the return result partition as requested by the `Filter` state.
|
|
|
|
///
|
|
|
|
VTKM_CONT vtkm::cont::PartitionedDataSet CreateResult(
|
|
|
|
const vtkm::cont::PartitionedDataSet& input,
|
|
|
|
const vtkm::cont::PartitionedDataSet& resultPartitions) const;
|
|
|
|
|
|
|
|
/// \brief Create the output data set for `DoExecute`.
|
|
|
|
///
|
|
|
|
/// This form of `CreateResult` will create an output PartitionedDataSet with the
|
|
|
|
/// same partitions and pass all PartitionedDataSet fields (as requested by the
|
|
|
|
/// `Filter` state).
|
|
|
|
///
|
|
|
|
/// \param[in] input The input data set being modified (usually the one passed into
|
|
|
|
/// `DoExecute`).
|
|
|
|
/// \param[in] resultPartitions The output data created by the filter. Fields from the input are
|
|
|
|
/// passed onto the return result partition as requested by the `Filter` state.
|
|
|
|
/// \param[in] fieldMapper A function or functor that takes a `PartitionedDataSet` as its first
|
|
|
|
/// argument and a `Field` as its second argument. The `PartitionedDataSet` is the data being
|
|
|
|
/// created and will eventually be returned by `CreateResult`. The `Field` comes from `input`.
|
|
|
|
///
|
|
|
|
template <typename FieldMapper>
|
2022-08-26 12:55:54 +00:00
|
|
|
VTKM_CONT vtkm::cont::PartitionedDataSet CreateResult(
|
|
|
|
const vtkm::cont::PartitionedDataSet& input,
|
2022-08-26 16:03:20 +00:00
|
|
|
const vtkm::cont::PartitionedDataSet& resultPartitions,
|
|
|
|
FieldMapper&& fieldMapper) const
|
|
|
|
{
|
2022-08-29 11:06:05 +00:00
|
|
|
vtkm::cont::PartitionedDataSet output(resultPartitions.GetPartitions());
|
2022-10-31 17:22:37 +00:00
|
|
|
this->MapFieldsOntoOutput(input, this->GetFieldsToPass(), output, fieldMapper);
|
2022-08-26 16:03:20 +00:00
|
|
|
return output;
|
|
|
|
}
|
2022-01-27 00:11:11 +00:00
|
|
|
|
|
|
|
/// \brief Create the output data set for `DoExecute`.
|
|
|
|
///
|
|
|
|
/// This form of `CreateResult` will create an output data set with the given `CellSet`. You must
|
|
|
|
/// also provide a field mapper function, which is a function that takes the output `DataSet`
|
|
|
|
/// being created and a `Field` from the input and then applies any necessary transformations to
|
|
|
|
/// the field array and adds it to the `DataSet`.
|
|
|
|
///
|
|
|
|
/// \param[in] inDataSet The input data set being modified (usually the one passed
|
|
|
|
/// into `DoExecute`). The returned `DataSet` is filled with fields of `inDataSet`
|
|
|
|
/// (as selected by the `FieldsToPass` state of the filter).
|
|
|
|
/// \param[in] resultCellSet The `CellSet` of the output will be set to this.
|
|
|
|
/// \param[in] fieldMapper A function or functor that takes a `DataSet` as its first
|
|
|
|
/// argument and a `Field` as its second argument. The `DataSet` is the data being
|
|
|
|
/// created and will eventually be returned by `CreateResult`. The `Field` comes from
|
|
|
|
/// `inDataSet`. The function should map the `Field` to match `resultCellSet` and then
|
|
|
|
/// add the resulting field to the `DataSet`. If the mapping is not possible, then
|
|
|
|
/// the function should do nothing.
|
|
|
|
///
|
|
|
|
template <typename FieldMapper>
|
|
|
|
VTKM_CONT vtkm::cont::DataSet CreateResult(const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::UnknownCellSet& resultCellSet,
|
|
|
|
FieldMapper&& fieldMapper) const
|
2021-12-03 20:44:51 +00:00
|
|
|
{
|
2022-01-27 00:11:11 +00:00
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.SetCellSet(resultCellSet);
|
2022-10-31 17:22:37 +00:00
|
|
|
this->MapFieldsOntoOutput(inDataSet, this->GetFieldsToPass(), outDataSet, fieldMapper);
|
2022-01-27 00:11:11 +00:00
|
|
|
return outDataSet;
|
|
|
|
}
|
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
///@{
|
2022-01-27 00:11:11 +00:00
|
|
|
/// \brief Create the output data set for `DoExecute`.
|
|
|
|
///
|
|
|
|
/// This form of `CreateResult` will create an output data set with the given `CellSet`
|
|
|
|
/// and `CoordinateSystem`. You must also provide a field mapper function, which is a
|
|
|
|
/// function that takes the output `DataSet` being created and a `Field` from the input
|
|
|
|
/// and then applies any necessary transformations to the field array and adds it to
|
|
|
|
/// the `DataSet`.
|
|
|
|
///
|
|
|
|
/// \param[in] inDataSet The input data set being modified (usually the one passed
|
|
|
|
/// into `DoExecute`). The returned `DataSet` is filled with fields of `inDataSet`
|
|
|
|
/// (as selected by the `FieldsToPass` state of the filter).
|
|
|
|
/// \param[in] resultCellSet The `CellSet` of the output will be set to this.
|
|
|
|
/// \param[in] resultCoordSystem This `CoordinateSystem` will be added to the output.
|
|
|
|
/// \param[in] fieldMapper A function or functor that takes a `DataSet` as its first
|
|
|
|
/// argument and a `Field` as its second argument. The `DataSet` is the data being
|
|
|
|
/// created and will eventually be returned by `CreateResult`. The `Field` comes from
|
|
|
|
/// `inDataSet`. The function should map the `Field` to match `resultCellSet` and then
|
|
|
|
/// add the resulting field to the `DataSet`. If the mapping is not possible, then
|
|
|
|
/// the function should do nothing.
|
|
|
|
///
|
|
|
|
template <typename FieldMapper>
|
2022-10-31 17:22:37 +00:00
|
|
|
VTKM_CONT vtkm::cont::DataSet CreateResultCoordinateSystem(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::UnknownCellSet& resultCellSet,
|
|
|
|
const vtkm::cont::CoordinateSystem& resultCoordSystem,
|
|
|
|
FieldMapper&& fieldMapper) const
|
2021-12-03 20:44:51 +00:00
|
|
|
{
|
2022-10-31 17:22:37 +00:00
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.SetCellSet(resultCellSet);
|
|
|
|
outDataSet.AddCoordinateSystem(resultCoordSystem);
|
|
|
|
vtkm::filter::FieldSelection fieldSelection = this->GetFieldsToPass();
|
|
|
|
fieldSelection.AddField(resultCoordSystem, vtkm::filter::FieldSelection::Mode::Exclude);
|
|
|
|
this->MapFieldsOntoOutput(inDataSet, fieldSelection, outDataSet, fieldMapper);
|
|
|
|
return outDataSet;
|
2021-12-03 20:44:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
template <typename FieldMapper>
|
|
|
|
VTKM_CONT vtkm::cont::DataSet CreateResultCoordinateSystem(
|
|
|
|
const vtkm::cont::DataSet& inDataSet,
|
|
|
|
const vtkm::cont::UnknownCellSet& resultCellSet,
|
|
|
|
const std::string& coordsName,
|
|
|
|
const vtkm::cont::UnknownArrayHandle& coordsData,
|
|
|
|
FieldMapper&& fieldMapper) const
|
|
|
|
{
|
|
|
|
return this->CreateResultCoordinateSystem(
|
|
|
|
inDataSet,
|
|
|
|
resultCellSet,
|
|
|
|
vtkm::cont::CoordinateSystem{ coordsName, coordsData },
|
|
|
|
fieldMapper);
|
|
|
|
}
|
|
|
|
///@}
|
|
|
|
|
2022-01-22 15:39:10 +00:00
|
|
|
VTKM_CONT virtual vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inData) = 0;
|
2022-01-17 16:18:42 +00:00
|
|
|
VTKM_CONT virtual vtkm::cont::PartitionedDataSet DoExecutePartitions(
|
|
|
|
const vtkm::cont::PartitionedDataSet& inData);
|
|
|
|
|
2022-05-18 11:59:07 +00:00
|
|
|
private:
|
2022-10-31 17:22:37 +00:00
|
|
|
template <typename FieldMapper>
|
|
|
|
VTKM_CONT void MapFieldsOntoOutput(const vtkm::cont::DataSet& input,
|
|
|
|
const vtkm::filter::FieldSelection& fieldSelection,
|
|
|
|
vtkm::cont::DataSet& output,
|
|
|
|
FieldMapper&& fieldMapper) const
|
|
|
|
{
|
2022-11-09 14:36:04 +00:00
|
|
|
// Basic field mapping
|
2022-10-31 17:22:37 +00:00
|
|
|
for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc)
|
|
|
|
{
|
|
|
|
auto field = input.GetField(cc);
|
|
|
|
if (fieldSelection.IsFieldSelected(field))
|
|
|
|
{
|
|
|
|
fieldMapper(output, field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 14:36:04 +00:00
|
|
|
// Check if the ghost levels have been copied. If so, set so on the output.
|
|
|
|
if (input.HasGhostCellField())
|
|
|
|
{
|
|
|
|
const std::string& ghostFieldName = input.GetGhostCellFieldName();
|
|
|
|
if (output.HasCellField(ghostFieldName) && (output.GetGhostCellFieldName() != ghostFieldName))
|
|
|
|
{
|
|
|
|
output.SetGhostCellFieldName(ghostFieldName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
for (vtkm::IdComponent csIndex = 0; csIndex < input.GetNumberOfCoordinateSystems(); ++csIndex)
|
|
|
|
{
|
|
|
|
auto coords = input.GetCoordinateSystem(csIndex);
|
|
|
|
if (!output.HasCoordinateSystem(coords.GetName()))
|
|
|
|
{
|
2022-11-09 14:36:04 +00:00
|
|
|
if (!output.HasPointField(coords.GetName()) && this->GetPassCoordinateSystems())
|
2022-10-31 17:22:37 +00:00
|
|
|
{
|
|
|
|
fieldMapper(output, coords);
|
|
|
|
}
|
|
|
|
if (output.HasPointField(coords.GetName()))
|
|
|
|
{
|
|
|
|
output.AddCoordinateSystem(coords.GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FieldMapper>
|
|
|
|
VTKM_CONT void MapFieldsOntoOutput(const vtkm::cont::PartitionedDataSet& input,
|
|
|
|
const vtkm::filter::FieldSelection& fieldSelection,
|
|
|
|
vtkm::cont::PartitionedDataSet& output,
|
2022-01-27 00:11:11 +00:00
|
|
|
FieldMapper&& fieldMapper) const
|
2021-12-04 02:13:06 +00:00
|
|
|
{
|
2022-01-27 00:11:11 +00:00
|
|
|
for (vtkm::IdComponent cc = 0; cc < input.GetNumberOfFields(); ++cc)
|
|
|
|
{
|
|
|
|
auto field = input.GetField(cc);
|
2022-10-31 17:22:37 +00:00
|
|
|
if (fieldSelection.IsFieldSelected(field))
|
2022-01-27 00:11:11 +00:00
|
|
|
{
|
|
|
|
fieldMapper(output, field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-04 02:13:06 +00:00
|
|
|
|
2022-05-16 20:55:14 +00:00
|
|
|
VTKM_CONT
|
|
|
|
virtual vtkm::Id DetermineNumberOfThreads(const vtkm::cont::PartitionedDataSet& input);
|
|
|
|
|
|
|
|
|
2022-03-17 20:45:25 +00:00
|
|
|
vtkm::filter::FieldSelection FieldsToPass = vtkm::filter::FieldSelection::Mode::All;
|
2022-10-31 17:22:37 +00:00
|
|
|
bool PassCoordinateSystems = true;
|
2021-12-03 20:44:51 +00:00
|
|
|
bool RunFilterWithMultipleThreads = false;
|
2022-08-10 20:06:42 +00:00
|
|
|
vtkm::Id NumThreadsPerCPU = 4;
|
|
|
|
vtkm::Id NumThreadsPerGPU = 8;
|
2021-12-03 20:44:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::filter
|
|
|
|
|
|
|
|
#endif
|