Skip to content
Snippets Groups Projects

Split up filter documentation into basic and advanced development

Merged Kenneth Moreland requested to merge kmorel/vtk-m-user-guide:basic-filter-impl into master
Files
2
+ 118
2
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/filter/FilterField.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace
@@ -13,7 +16,8 @@ constexpr vtkm::Id ARRAY_SIZE = 10;
//// BEGIN-EXAMPLE SimpleWorklet.cxx
////
//// LABEL Inherit
struct PoundsPerSquareInchToNewtonsPerSquareMeter : vtkm::worklet::WorkletMapField
struct PoundsPerSquareInchToNewtonsPerSquareMeterWorklet
: vtkm::worklet::WorkletMapField
{
//// LABEL ControlSignature
//// BEGIN-EXAMPLE ControlSignature.cxx
@@ -35,7 +39,22 @@ struct PoundsPerSquareInchToNewtonsPerSquareMeter : vtkm::worklet::WorkletMapFie
{
//// END-EXAMPLE WorkletOperator.cxx
// 1 psi = 6894.76 N/m^2
//// PAUSE-EXAMPLE
// The following line can create a warning when converting the literal
// to a float, even though it is clear that I want the casting. Rather
// then add the confusing code to handle all cases, just suppress the
// warning.
#ifdef VTKM_MSVC
#pragma warning(push)
#pragma warning(disable : 4305)
#endif
//// RESUME-EXAMPLE
nsm = T(6894.76) * psi;
//// PAUSE-EXAMPLE
#ifdef VTKM_MSVC
#pragma warning(pop)
#endif
//// RESUME-EXAMPLE
//// LABEL OperatorEnd
}
};
@@ -60,15 +79,112 @@ void DemoWorklet()
vtkm::cont::ArrayHandle<vtkm::FloatDefault> nsmArray;
//// LABEL Call
invoke(PoundsPerSquareInchToNewtonsPerSquareMeter{}, psiArray, nsmArray);
invoke(PoundsPerSquareInchToNewtonsPerSquareMeterWorklet{}, psiArray, nsmArray);
////
//// END-EXAMPLE WorkletInvoke.cxx
////
}
} // anonymous namespace
////
//// BEGIN-EXAMPLE SimpleField.cxx
////
namespace vtkm
{
namespace filter
{
class PoundsPerSquareInchToNewtonsPerSquareMeterFilter
: public vtkm::filter::FilterField<
PoundsPerSquareInchToNewtonsPerSquareMeterFilter>
{
public:
VTKM_CONT PoundsPerSquareInchToNewtonsPerSquareMeterFilter();
template<typename ArrayHandleType, typename Policy>
VTKM_CONT vtkm::cont::DataSet DoExecute(
const vtkm::cont::DataSet& inDataSet,
const ArrayHandleType& inField,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<Policy>);
};
}
} // namespace vtkm::filter
////
//// END-EXAMPLE SimpleField.cxx
////
////
//// BEGIN-EXAMPLE SimpleFieldConstructor.cxx
////
VTKM_CONT vtkm::filter::PoundsPerSquareInchToNewtonsPerSquareMeterFilter::
PoundsPerSquareInchToNewtonsPerSquareMeterFilter()
{
this->SetOutputFieldName("");
}
////
//// END-EXAMPLE SimpleFieldConstructor.cxx
////
////
//// BEGIN-EXAMPLE SimpleFieldDoExecute.cxx
////
template<typename ArrayHandleType, typename Policy>
VTKM_CONT vtkm::cont::DataSet
vtkm::filter::PoundsPerSquareInchToNewtonsPerSquareMeterFilter::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const ArrayHandleType& inField,
const vtkm::filter::FieldMetadata& fieldMetadata,
vtkm::filter::PolicyBase<Policy>)
{
//// LABEL CheckArray
VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
using ValueType = typename ArrayHandleType::ValueType;
//// LABEL CreateOutputArray
vtkm::cont::ArrayHandle<ValueType> outField;
//// LABEL Invoke
this->Invoke(
PoundsPerSquareInchToNewtonsPerSquareMeterWorklet{}, inField, outField);
//// LABEL OutputName
std::string outFieldName = this->GetOutputFieldName();
if (outFieldName == "")
{
outFieldName = fieldMetadata.GetName() + "_N/M^2";
}
//// LABEL CreateResult
return vtkm::filter::CreateResult(
inDataSet, outField, outFieldName, fieldMetadata);
}
////
//// END-EXAMPLE SimpleFieldDoExecute.cxx
////
namespace
{
void DemoFilter()
{
vtkm::cont::testing::MakeTestDataSet makeData;
vtkm::cont::DataSet inData = makeData.Make3DExplicitDataSet0();
vtkm::filter::PoundsPerSquareInchToNewtonsPerSquareMeterFilter convertFilter;
convertFilter.SetActiveField("pointvar");
vtkm::cont::DataSet outData = convertFilter.Execute(inData);
VTKM_TEST_ASSERT(outData.HasPointField("pointvar_N/m^2"));
}
void Run()
{
DemoWorklet();
DemoFilter();
}
} // anonymous namespace
Loading