Merge topic 'add_pointaverage_filter'

854e298b CellAverage filter now verifies the field is a point field.
b85cb2dd Add a PointAverage Filter.
daa75d74 Add a PointAverage worklet which is the twin to CellAverage.
839d8e83 CellAverage first control parameter is now the cellset.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland <kmorel@sandia.gov>
Merge-request: !636
This commit is contained in:
Robert Maynard 2016-12-15 12:18:57 -05:00 committed by Kitware Robot
commit 3c9b8f1793
14 changed files with 499 additions and 152 deletions

@ -146,8 +146,8 @@ private:
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<
vtkm::worklet::CellAverage,DeviceAdapterTag> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
cellset,
dispatcher.Invoke(cellset,
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[3] = { 20.1333f, 30.1667f, 40.2333f };

@ -125,8 +125,8 @@ void TestDataSet_Explicit()
//run a basic for-each topology algorithm on this
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
subset,
dispatcher.Invoke(subset,
dataSet.GetField("pointvar"),
result);
//iterate same cell 4 times
@ -173,8 +173,8 @@ void TestDataSet_Structured2D()
//run a basic for-each topology algorithm on this
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
subset,
dispatcher.Invoke(subset,
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[4] = { 40.1f, 40.1f, 40.1f, 40.1f };
@ -218,8 +218,8 @@ void TestDataSet_Structured3D()
//run a basic for-each topology algorithm on this
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
subset,
dispatcher.Invoke(subset,
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[4] = { 70.2125f, 70.2125f, 70.2125f, 70.2125f };

@ -32,6 +32,7 @@ set(headers
Gradient.h
Histogram.h
MarchingCubes.h
PointAverage.h
PointElevation.h
PolicyBase.h
PolicyDefault.h
@ -54,6 +55,7 @@ set(header_template_sources
Gradient.hxx
Histogram.hxx
MarchingCubes.hxx
PointAverage.hxx
PointElevation.hxx
Threshold.hxx
VertexClustering.hxx

@ -48,6 +48,11 @@ vtkm::filter::ResultField CellAverage::DoExecute(
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter&)
{
if(!fieldMetadata.IsPointField())
{
return vtkm::filter::ResultField();
}
vtkm::cont::DynamicCellSet cellSet =
input.GetCellSet(this->GetActiveCellSetIndex());
@ -60,7 +65,7 @@ vtkm::filter::ResultField CellAverage::DoExecute(
//todo: we need to use the policy to determine the valid conversions
//that the dispatcher should do, including the result from GetCellSet
dispatcher.Invoke(inField, cellSet, outArray);
dispatcher.Invoke(cellSet, inField, outArray);
std::string outputName = this->GetOutputFieldName();
if (outputName == "")

@ -0,0 +1,55 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_PointAverage_h
#define vtk_m_filter_PointAverage_h
#include <vtkm/filter/FilterCell.h>
#include <vtkm/worklet/PointAverage.h>
namespace vtkm {
namespace filter {
class PointAverage : public vtkm::filter::FilterCell<PointAverage>
{
public:
VTKM_CONT
PointAverage();
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
vtkm::filter::ResultField DoExecute(const vtkm::cont::DataSet &input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
vtkm::worklet::PointAverage Worklet;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/PointAverage.hxx>
#endif // vtk_m_filter_PointAverage_h

@ -0,0 +1,85 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm {
namespace filter {
//-----------------------------------------------------------------------------
inline VTKM_CONT
PointAverage::PointAverage():
vtkm::filter::FilterCell<PointAverage>(),
Worklet()
{
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
vtkm::filter::ResultField PointAverage::DoExecute(
const vtkm::cont::DataSet &input,
const vtkm::cont::ArrayHandle<T, StorageType> &inField,
const vtkm::filter::FieldMetadata &fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter&)
{
if(!fieldMetadata.IsCellField())
{
return vtkm::filter::ResultField();
}
vtkm::cont::DynamicCellSet cellSet =
input.GetCellSet(this->GetActiveCellSetIndex());
//todo: we need to ask the policy what storage type we should be using
//If the input is implicit, we should know what to fall back to
vtkm::cont::ArrayHandle<T> outArray;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::PointAverage,
DeviceAdapter > dispatcher(this->Worklet);
//todo: we need to use the policy to determine the valid conversions
//that the dispatcher should do, including the result from GetCellSet
dispatcher.Invoke(cellSet, inField, outArray);
std::string outputName = this->GetOutputFieldName();
if (outputName.empty())
{
// Default name is name of input.
outputName = fieldMetadata.GetName();
}
return vtkm::filter::ResultField(input,
outArray,
outputName,
vtkm::cont::Field::ASSOC_POINTS,
cellSet.GetName());
}
}
} // namespace vtkm::filter

@ -27,6 +27,7 @@ set(unit_tests
UnitTestGradient.cxx
UnitTestHistogramFilter.cxx
UnitTestMarchingCubesFilter.cxx
UnitTestPointAverageFilter.cxx
UnitTestPointElevationFilter.cxx
UnitTestThresholdFilter.cxx
UnitTestVertexClusteringFilter.cxx

@ -0,0 +1,179 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/filter/PointAverage.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
namespace {
void TestPointAverageUniform3D()
{
std::cout << "Testing PointAverage Filter on 3D structured data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
vtkm::filter::ResultField result;
vtkm::filter::PointAverage pointAverage;
pointAverage.SetOutputFieldName("avgvals");
result = pointAverage.Execute( dataSet, dataSet.GetField("cellvar"));
VTKM_TEST_ASSERT(result.GetField().GetName() == "avgvals",
"Field was given the wrong name.");
VTKM_TEST_ASSERT(result.GetField().GetAssociation() ==
vtkm::cont::Field::ASSOC_POINTS,
"Field was given the wrong association.");
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
bool valid = result.FieldAs(resultArrayHandle);
if(valid)
{
vtkm::Float32 expected[18] = { 100.1f, 100.15f, 100.2f, 100.1f, 100.15f, 100.2f,
100.2f, 100.25f, 100.3f, 100.2f, 100.25f, 100.3f,
100.3f, 100.35f, 100.4f, 100.3f, 100.35f, 100.4f
};
for (vtkm::Id i = 0; i < 18; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for PointAverage worklet on 3D regular data");
}
}
}
void TestPointAverageRegular3D()
{
std::cout << "Testing PointAverage Filter on 2D strucutred data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DRectilinearDataSet0();
vtkm::filter::ResultField result;
vtkm::filter::PointAverage pointAverage;
result = pointAverage.Execute( dataSet, dataSet.GetField("cellvar"));
// If no name is given, should have the same name as the input.
VTKM_TEST_ASSERT(result.GetField().GetName() == "cellvar",
"Field was given the wrong name.");
VTKM_TEST_ASSERT(result.GetField().GetAssociation() ==
vtkm::cont::Field::ASSOC_POINTS,
"Field was given the wrong association.");
vtkm::cont::Field resultField = result.GetField();
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
resultField.GetData().CopyTo(resultArrayHandle);
if(result.IsValid())
{
vtkm::Float32 expected[18] = { 0.f, 0.5f, 1.f, 0.f, 0.5f, 1.f,
1.f, 1.5f, 2.f, 1.f, 1.5f, 2.f,
2.f, 2.5f, 3.f, 2.f, 2.5f, 3.f
};
for (vtkm::Id i = 0; i < 18; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for PointAverage worklet on 3D regular data");
}
}
}
void TestPointAverageExplicit1()
{
std::cout << "Testing PointAverage Filter on Explicit data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet1();
vtkm::filter::ResultField result;
vtkm::filter::PointAverage pointAverage;
result = pointAverage.Execute( dataSet, dataSet.GetField("cellvar"));
// If no name is given, should have the same name as the input.
VTKM_TEST_ASSERT(result.GetField().GetName() == "cellvar",
"Field was given the wrong name.");
VTKM_TEST_ASSERT(result.GetField().GetAssociation() ==
vtkm::cont::Field::ASSOC_POINTS,
"Field was given the wrong association.");
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
const bool valid = result.FieldAs(resultArrayHandle);
if(valid)
{
vtkm::Float32 expected[5] = { 100.1f, 100.15f, 100.15f, 100.2f, 100.2f };
for (int i = 0; i < 5; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for PointAverage worklet on 3D regular data");
}
}
}
void TestPointAverageExplicit2()
{
std::cout << "Testing PointAverage Filter on Explicit data" << std::endl;
vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet4();
vtkm::filter::ResultField result;
vtkm::filter::PointAverage pointAverage;
result = pointAverage.Execute( dataSet, dataSet.GetField("cellvar"));
// If no name is given, should have the same name as the input.
VTKM_TEST_ASSERT(result.GetField().GetName() == "cellvar",
"Field was given the wrong name.");
VTKM_TEST_ASSERT(result.GetField().GetAssociation() ==
vtkm::cont::Field::ASSOC_POINTS,
"Field was given the wrong association.");
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
const bool valid = result.FieldAs(resultArrayHandle);
if(valid)
{
vtkm::Float32 expected[12] = { 100.1f, 105.05f, 105.05f, 100.1f,
100.1f, 105.05f, 105.05f, 100.1f,
110.0f, 110.0f, 110.0f, 110.0f
};
for (int i = 0; i < 12; ++i)
{
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.GetPortalConstControl().Get(i),
expected[i]), "Wrong result for PointAverage worklet on 3D regular data");
}
}
}
void TestPointAverage()
{
TestPointAverageUniform3D();
TestPointAverageRegular3D();
TestPointAverageExplicit1();
TestPointAverageExplicit2();
}
}
int UnitTestPointAverageFilter(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestPointAverage);
}

@ -37,6 +37,7 @@ set(headers
MarchingCubes.h
MarchingCubesDataTables.h
PointElevation.h
PointAverage.h
RemoveUnusedPoints.h
ScatterCounting.h
ScatterIdentity.h

@ -28,21 +28,21 @@
namespace vtkm {
namespace worklet {
//simple functor that returns the average point value.
//simple functor that returns the average point value as a cell field
class CellAverage :
public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(FieldInPoint<> inPoints,
CellSetIn cellset,
typedef void ControlSignature(CellSetIn cellset,
FieldInPoint<> inPoints,
FieldOutCell<> outCells);
typedef void ExecutionSignature(_1, PointCount, _3);
typedef _2 InputDomain;
typedef void ExecutionSignature(PointCount, _2, _3);
typedef _1 InputDomain;
template<typename PointValueVecType, typename OutType>
VTKM_EXEC
void operator()(const PointValueVecType &pointValues,
const vtkm::IdComponent &numPoints,
void operator()(const vtkm::IdComponent &numPoints,
const PointValueVecType &pointValues,
OutType &average) const
{
using PointValueType = typename PointValueVecType::ComponentType;
@ -55,8 +55,8 @@ public:
vtkm::IdComponent,
vtkm::VecTraits<OutType>::NUM_COMPONENTS>;
this->DoAverage(pointValues,
numPoints,
this->DoAverage(numPoints,
pointValues,
average,
PointVecSize(),
OutVecSize());
@ -65,8 +65,8 @@ public:
private:
template<typename PointValueVecType, typename OutType>
VTKM_EXEC
void DoAverage(const PointValueVecType &pointValues,
const vtkm::IdComponent &numPoints,
void DoAverage(const vtkm::IdComponent &numPoints,
const PointValueVecType &pointValues,
OutType &average,
std::integral_constant<vtkm::IdComponent,1>,
std::integral_constant<vtkm::IdComponent,1>) const
@ -84,8 +84,8 @@ private:
typename OutType,
vtkm::IdComponent VecSize>
VTKM_EXEC
void DoAverage(const PointValueVecType &pointValues,
const vtkm::IdComponent &numPoints,
void DoAverage(const vtkm::IdComponent &numPoints,
const PointValueVecType &pointValues,
OutType &average,
std::integral_constant<vtkm::IdComponent,VecSize>,
std::integral_constant<vtkm::IdComponent,VecSize>) const
@ -105,8 +105,8 @@ private:
vtkm::IdComponent InVecSize,
vtkm::IdComponent OutVecSize>
VTKM_EXEC
void DoAverage(const PointValueVecType &vtkmNotUsed(pointValues),
const vtkm::IdComponent &vtkmNotUsed(numPoints),
void DoAverage(const vtkm::IdComponent &vtkmNotUsed(numPoints),
const PointValueVecType &vtkmNotUsed(pointValues),
OutType &vtkmNotUsed(average),
std::integral_constant<vtkm::IdComponent,InVecSize>,
std::integral_constant<vtkm::IdComponent,OutVecSize>) const

123
vtkm/worklet/PointAverage.h Normal file

@ -0,0 +1,123 @@
//============================================================================
// 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_worklet_PointAverage_h
#define vtk_m_worklet_PointAverage_h
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/VecTraits.h>
namespace vtkm {
namespace worklet {
//simple functor that returns the average point value of a given
//cell based field.
class PointAverage :
public vtkm::worklet::WorkletMapCellToPoint
{
public:
typedef void ControlSignature(CellSetIn cellset,
FieldInCell<> inCellField,
FieldOutPoint<> outPointField);
typedef void ExecutionSignature(CellCount, _2, _3);
typedef _1 InputDomain;
template<typename CellValueVecType, typename OutType>
VTKM_EXEC
void operator()(const vtkm::IdComponent &numCells,
const CellValueVecType &cellValues,
OutType &average) const
{
using CellValueType = typename CellValueVecType::ComponentType;
using InVecSize =
std::integral_constant<
vtkm::IdComponent,
vtkm::VecTraits<CellValueType>::NUM_COMPONENTS>;
using OutVecSize =
std::integral_constant<
vtkm::IdComponent,
vtkm::VecTraits<OutType>::NUM_COMPONENTS>;
this->DoAverage(numCells,
cellValues,
average,
InVecSize(),
OutVecSize());
}
private:
template<typename CellValueVecType, typename OutType>
VTKM_EXEC
void DoAverage(const vtkm::IdComponent &numCells,
const CellValueVecType &cellValues,
OutType &average,
std::integral_constant<vtkm::IdComponent,1>,
std::integral_constant<vtkm::IdComponent,1>) const
{
OutType sum = static_cast<OutType>(cellValues[0]);
for (vtkm::IdComponent cellIndex = 1; cellIndex < numCells; ++cellIndex)
{
sum = sum + static_cast<OutType>(cellValues[cellIndex]);
}
average = sum / static_cast<OutType>(numCells);
}
template<typename CellValueVecType,
typename OutType,
vtkm::IdComponent VecSize>
VTKM_EXEC
void DoAverage(const vtkm::IdComponent &numCells,
const CellValueVecType &cellValues,
OutType &average,
std::integral_constant<vtkm::IdComponent,VecSize>,
std::integral_constant<vtkm::IdComponent,VecSize>) const
{
using OutComponentType = typename vtkm::VecTraits<OutType>::ComponentType;
OutType sum = OutType(cellValues[0]);
for (vtkm::IdComponent cellIndex = 1; cellIndex < numCells; ++cellIndex)
{
sum = sum + OutType(cellValues[cellIndex]);
}
average = sum / OutType(static_cast<OutComponentType>(numCells));
}
template<typename CellValueVecType,
typename OutType,
vtkm::IdComponent InVecSize,
vtkm::IdComponent OutVecSize>
VTKM_EXEC
void DoAverage(const vtkm::IdComponent &vtkmNotUsed(numCells),
const CellValueVecType &vtkmNotUsed(cellValues),
OutType &vtkmNotUsed(average),
std::integral_constant<vtkm::IdComponent,InVecSize>,
std::integral_constant<vtkm::IdComponent,OutVecSize>) const
{
this->RaiseError(
"PointAverage called with mismatched Vec sizes for PointAverage.");
}
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_PointAverage_h

@ -36,8 +36,8 @@ void TestCellAverageUniform3D()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
dataSet.GetCellSet(),
dispatcher.Invoke(dataSet.GetCellSet(),
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[4] = { 60.1875f, 70.2125f, 120.3375f, 130.3625f };
@ -59,8 +59,8 @@ void TestCellAverageUniform2D()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
dataSet.GetCellSet(),
dispatcher.Invoke(dataSet.GetCellSet(),
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[2] = { 30.1f, 40.1f };
@ -83,8 +83,8 @@ void TestCellAverageExplicit()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage> dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
dataSet.GetCellSet(),
dispatcher.Invoke(dataSet.GetCellSet(),
dataSet.GetField("pointvar"),
result);
vtkm::Float32 expected[2] = { 20.1333f, 35.2f };

@ -21,6 +21,9 @@
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/CellAverage.h>
#include <vtkm/worklet/PointAverage.h>
#include <vtkm/Math.h>
#include <vtkm/cont/DataSet.h>
@ -66,62 +69,6 @@ public:
}
};
class AveragePointToCellValue : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(FieldInPoint<Scalar> inPoints,
CellSetIn topology,
FieldOutCell<Scalar> outCells);
typedef void ExecutionSignature(_1, _3, PointCount);
typedef _2 InputDomain;
VTKM_CONT
AveragePointToCellValue() { }
template<typename PointVecType, typename OutType>
VTKM_EXEC
void operator()(const PointVecType &pointValues,
OutType &avgVal,
const vtkm::IdComponent &numPoints) const
{
//simple functor that returns the average pointValue.
avgVal = static_cast<OutType>(pointValues[0]);
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
{
avgVal += static_cast<OutType>(pointValues[pointIndex]);
}
avgVal = avgVal / static_cast<OutType>(numPoints);
}
};
class AverageCellToPointValue : public vtkm::worklet::WorkletMapCellToPoint
{
public:
typedef void ControlSignature(FieldInCell<Scalar> inCells,
CellSetIn topology,
FieldOut<Scalar> outPoints);
typedef void ExecutionSignature(_1, _3, CellCount);
typedef _2 InputDomain;
VTKM_CONT
AverageCellToPointValue() { }
template<typename CellVecType, typename OutType>
VTKM_EXEC
void operator()(const CellVecType &cellValues,
OutType &avgVal,
const vtkm::IdComponent &numCellIDs) const
{
//simple functor that returns the average cell Value.
avgVal = static_cast<OutType>(cellValues[0]);
for (vtkm::IdComponent cellIndex = 1; cellIndex < numCellIDs; ++cellIndex)
{
avgVal += static_cast<OutType>(cellValues[cellIndex]);
}
avgVal = avgVal / static_cast<OutType>(numCellIDs);
}
};
}
namespace {
@ -176,9 +123,9 @@ TestAvgPointToCell()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology< ::test_explicit::AveragePointToCellValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
dataSet.GetCellSet(),
vtkm::worklet::DispatcherMapTopology< vtkm::worklet::CellAverage > dispatcher;
dispatcher.Invoke(dataSet.GetCellSet(),
dataSet.GetField("pointvar"),
result);
//make sure we got the right answer.
@ -199,9 +146,9 @@ TestAvgCellToPoint()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology< ::test_explicit::AverageCellToPointValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("cellvar"),
dataSet.GetCellSet(),
vtkm::worklet::DispatcherMapTopology< vtkm::worklet::PointAverage > dispatcher;
dispatcher.Invoke(dataSet.GetCellSet(),
dataSet.GetField("cellvar"),
result);
//make sure we got the right answer.

@ -21,6 +21,9 @@
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/worklet/CellAverage.h>
#include <vtkm/worklet/PointAverage.h>
#include <vtkm/Math.h>
#include <vtkm/cont/DataSet.h>
@ -66,62 +69,6 @@ public:
}
};
class AveragePointToCellValue : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(FieldInPoint<Scalar> inPoints,
CellSetIn topology,
FieldOutCell<Scalar> outCells);
typedef void ExecutionSignature(_1, _3, PointCount);
typedef _2 InputDomain;
VTKM_CONT
AveragePointToCellValue() { }
template<typename PointVecType, typename OutType>
VTKM_EXEC
void operator()(const PointVecType &pointValues,
OutType &avgVal,
const vtkm::IdComponent &numPoints) const
{
//simple functor that returns the average pointValue.
avgVal = static_cast<OutType>(pointValues[0]);
for (vtkm::IdComponent pointIndex = 1; pointIndex < numPoints; ++pointIndex)
{
avgVal += static_cast<OutType>(pointValues[pointIndex]);
}
avgVal = avgVal / static_cast<OutType>(numPoints);
}
};
class AverageCellToPointValue : public vtkm::worklet::WorkletMapCellToPoint
{
public:
typedef void ControlSignature(FieldInCell<Scalar> inCells,
CellSetIn topology,
FieldOut<Scalar> outPoints);
typedef void ExecutionSignature(_1, _3, CellCount);
typedef _2 InputDomain;
VTKM_CONT
AverageCellToPointValue() { }
template<typename CellVecType, typename OutType>
VTKM_EXEC
void operator()(const CellVecType &cellValues,
OutType &avgVal,
const vtkm::IdComponent &numCellIDs) const
{
//simple functor that returns the average cell Value.
avgVal = static_cast<OutType>(cellValues[0]);
for (vtkm::IdComponent cellIndex = 1; cellIndex < numCellIDs; ++cellIndex)
{
avgVal += static_cast<OutType>(cellValues[cellIndex]);
}
avgVal = avgVal / static_cast<OutType>(numCellIDs);
}
};
struct CheckStructuredUniformPointCoords
: public vtkm::worklet::WorkletMapPointToCell
{
@ -208,14 +155,15 @@ TestAvgPointToCell()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology< ::test_uniform::AveragePointToCellValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("pointvar"),
vtkm::worklet::DispatcherMapTopology< vtkm::worklet::CellAverage > dispatcher;
dispatcher.Invoke(
// We know that the cell set is a structured 2D grid and
// The worklet does not work with general types because
// of the way we get cell indices. We need to make that
// part more flexible.
dataSet.GetCellSet(0).ResetCellSetList(
vtkm::cont::CellSetListTagStructured2D()),
dataSet.GetField("pointvar"),
result);
//make sure we got the right answer.
@ -235,14 +183,15 @@ TestAvgCellToPoint()
vtkm::cont::ArrayHandle<vtkm::Float32> result;
vtkm::worklet::DispatcherMapTopology< ::test_uniform::AverageCellToPointValue > dispatcher;
dispatcher.Invoke(dataSet.GetField("cellvar"),
vtkm::worklet::DispatcherMapTopology< vtkm::worklet::PointAverage > dispatcher;
dispatcher.Invoke(
// We know that the cell set is a structured 2D grid and
// The worklet does not work with general types because
// of the way we get cell indices. We need to make that
// part more flexible.
dataSet.GetCellSet(0).ResetCellSetList(
vtkm::cont::CellSetListTagStructured2D()),
dataSet.GetField("cellvar"),
result);
//make sure we got the right answer.