Merge topic 'add_scalar_cell_gradient'
7a52fa39 Add in Cell Gradient for scalar fields. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !607
This commit is contained in:
commit
523ac98754
@ -30,6 +30,7 @@ set(headers
|
||||
ExternalFaces.h
|
||||
FieldHistogram.h
|
||||
FieldStatistics.h
|
||||
Gradient.h
|
||||
KernelSplatter.h
|
||||
Magnitude.h
|
||||
MarchingCubes.h
|
||||
|
108
vtkm/worklet/Gradient.h
Normal file
108
vtkm/worklet/Gradient.h
Normal file
@ -0,0 +1,108 @@
|
||||
//============================================================================
|
||||
// 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_Gradient_h
|
||||
#define vtk_m_worklet_Gradient_h
|
||||
|
||||
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||
#include <vtkm/exec/internal/VecFromPortalPermute.h>
|
||||
#include <vtkm/exec/CellDerivative.h>
|
||||
#include <vtkm/exec/ParametricCoordinates.h>
|
||||
#include <vtkm/CellTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
#include <vtkm/worklet/WorkletMapTopology.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace worklet {
|
||||
|
||||
struct GradientOutTypes
|
||||
: vtkm::ListTagBase<
|
||||
vtkm::Vec<vtkm::Float32,3>,
|
||||
vtkm::Vec<vtkm::Float64,3>
|
||||
>
|
||||
{ };
|
||||
struct CellGradient : vtkm::worklet::WorkletMapPointToCell
|
||||
{
|
||||
typedef void ControlSignature(CellSetIn,
|
||||
FieldInPoint<Vec3> pointCoordinates,
|
||||
FieldInPoint<Scalar> inputField,
|
||||
FieldOutCell<GradientOutTypes> outputField);
|
||||
|
||||
typedef void ExecutionSignature(CellShape, PointCount, _2, _3, _4);
|
||||
typedef _1 InputDomain;
|
||||
|
||||
template <typename CellTagType, typename PointCoordVecType,
|
||||
typename FieldInVecType, typename FieldOutType>
|
||||
VTKM_EXEC_EXPORT void operator()(CellTagType shape,
|
||||
vtkm::IdComponent pointCount, const PointCoordVecType& pointCoordinates,
|
||||
const FieldInVecType& inputField, FieldOutType& outputField) const
|
||||
{
|
||||
//To confirm that we have the proper input and output types we need
|
||||
//to verify that input type matches the output vtkm::Vec<T> 'T' type.
|
||||
//For example:
|
||||
// input is float => output is vtkm::Vec<float>
|
||||
// input is vtkm::Vec<float> => output is vtkm::Vec< vtkm::Vec< float > >
|
||||
|
||||
//Grab the dimension tag for the input
|
||||
using InValueType = typename FieldInVecType::ComponentType;
|
||||
using InDimensionTag = typename TypeTraits<InValueType>::DimensionalityTag;
|
||||
|
||||
//grad the dimension tag for the output component type
|
||||
using OutValueType = typename VecTraits<typename FieldOutType::ComponentType>::ComponentType;
|
||||
using OutDimensionTag = typename TypeTraits<OutValueType>::DimensionalityTag;
|
||||
|
||||
//Verify that input and output dimension tags match
|
||||
using Matches = typename std::is_same<InDimensionTag, OutDimensionTag>::type;
|
||||
|
||||
this->Compute(shape, pointCount, pointCoordinates, inputField, outputField,
|
||||
Matches());
|
||||
}
|
||||
|
||||
template <typename CellShapeTag, typename PointCoordVecType,
|
||||
typename FieldInVecType, typename FieldOutType>
|
||||
VTKM_EXEC_EXPORT void Compute(CellShapeTag shape,
|
||||
vtkm::IdComponent pointCount, const PointCoordVecType& wCoords,
|
||||
const FieldInVecType& field, FieldOutType& outputField,
|
||||
std::true_type) const
|
||||
{
|
||||
vtkm::Vec<vtkm::FloatDefault, 3> center =
|
||||
vtkm::exec::ParametricCoordinatesCenter(pointCount, shape, *this);
|
||||
outputField = vtkm::exec::CellDerivative(field, wCoords, center, shape, *this);
|
||||
}
|
||||
|
||||
template <typename CellShapeTag,
|
||||
typename PointCoordVecType,
|
||||
typename FieldInVecType,
|
||||
typename FieldOutType>
|
||||
VTKM_EXEC_EXPORT void Compute(CellShapeTag,
|
||||
vtkm::IdComponent,
|
||||
const PointCoordVecType&,
|
||||
const FieldInVecType&,
|
||||
FieldOutType&,
|
||||
std::false_type) const
|
||||
{
|
||||
//this is invalid
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::worklet
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@
|
||||
|
||||
set(unit_tests
|
||||
UnitTestCellAverage.cxx
|
||||
UnitTestCellGradient.cxx
|
||||
UnitTestClipping.cxx
|
||||
UnitTestExternalFaces.cxx
|
||||
UnitTestFieldHistogram.cxx
|
||||
|
120
vtkm/worklet/testing/UnitTestCellGradient.cxx
Normal file
120
vtkm/worklet/testing/UnitTestCellGradient.cxx
Normal file
@ -0,0 +1,120 @@
|
||||
//============================================================================
|
||||
// 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/worklet/Gradient.h>
|
||||
#include <vtkm/worklet/DispatcherMapTopology.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
void TestCellGradientUniform2D()
|
||||
{
|
||||
std::cout << "Testing CellGradient Worklet on 2D structured data" << std::endl;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
||||
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
|
||||
|
||||
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float32,3> > result;
|
||||
|
||||
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellGradient> dispatcher;
|
||||
dispatcher.Invoke(dataSet.GetCellSet(),
|
||||
dataSet.GetCoordinateSystem(),
|
||||
dataSet.GetField("pointvar"),
|
||||
result);
|
||||
|
||||
vtkm::Vec<vtkm::Float32,3> expected[2] = { {10,30,0}, {10,30,0} };
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
||||
"Wrong result for CellGradient worklet on 2D uniform data");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestCellGradientUniform3D()
|
||||
{
|
||||
std::cout << "Testing CellGradient Worklet on 3D strucutred data" << std::endl;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
||||
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
|
||||
|
||||
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float64,3> > result;
|
||||
|
||||
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellGradient> dispatcher;
|
||||
dispatcher.Invoke(dataSet.GetCellSet(),
|
||||
dataSet.GetCoordinateSystem(),
|
||||
dataSet.GetField("pointvar"),
|
||||
result);
|
||||
|
||||
vtkm::Vec<vtkm::Float64,3> expected[4] = { {10.025,30.075,60.125},
|
||||
{10.025,30.075,60.125},
|
||||
{10.025,30.075,60.175},
|
||||
{10.025,30.075,60.175},
|
||||
};
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
||||
"Wrong result for CellGradient worklet on 3D uniform data");
|
||||
}
|
||||
}
|
||||
|
||||
void TestCellGradientExplicit()
|
||||
{
|
||||
std::cout << "Testing CellGradient Worklet on Explicit data" << std::endl;
|
||||
|
||||
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
||||
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
|
||||
|
||||
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float32,3> > result;
|
||||
|
||||
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellGradient> dispatcher;
|
||||
dispatcher.Invoke(dataSet.GetCellSet(),
|
||||
dataSet.GetCoordinateSystem(),
|
||||
dataSet.GetField("pointvar"),
|
||||
result);
|
||||
|
||||
vtkm::Vec<vtkm::Float32,3> expected[2] = { {10.f,10.1f,0.0f}, {10.f,10.1f,-0.0f} };
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
VTKM_TEST_ASSERT(
|
||||
test_equal(result.GetPortalConstControl().Get(i), expected[i]),
|
||||
"Wrong result for CellGradient worklet on 3D explicit data");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestCellGradient()
|
||||
{
|
||||
TestCellGradientUniform2D();
|
||||
TestCellGradientUniform3D();
|
||||
TestCellGradientExplicit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int UnitTestCellGradient(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestCellGradient);
|
||||
}
|
Loading…
Reference in New Issue
Block a user