2017-03-29 16:11:09 +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.
|
|
|
|
//
|
|
|
|
// Copyright 2017 Sandia Corporation.
|
|
|
|
// Copyright 2017 UT-Battelle, LLC.
|
|
|
|
// Copyright 2017 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_exec_ImplicitFunction_h
|
|
|
|
#define vtk_m_exec_ImplicitFunction_h
|
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2017-03-29 16:11:09 +00:00
|
|
|
|
|
|
|
class VTKM_ALWAYS_EXPORT ImplicitFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImplicitFunction()
|
2017-05-18 14:29:41 +00:00
|
|
|
: Function(nullptr)
|
|
|
|
, ValueCaller(nullptr)
|
|
|
|
, GradientCaller(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2017-03-29 16:11:09 +00:00
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
|
|
|
{
|
|
|
|
return this->ValueCaller(this->Function, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
FloatDefault Value(const vtkm::Vec<FloatDefault, 3>& x) const
|
2017-03-29 16:11:09 +00:00
|
|
|
{
|
|
|
|
return this->ValueCaller(this->Function, x[0], x[1], x[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<FloatDefault, 3> Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const
|
2017-03-29 16:11:09 +00:00
|
|
|
{
|
|
|
|
return this->GradientCaller(this->Function, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3>& x) const
|
2017-03-29 16:11:09 +00:00
|
|
|
{
|
|
|
|
return this->GradientCaller(this->Function, x[0], x[1], x[2]);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
VTKM_EXEC void Bind(const T* function)
|
2017-03-29 16:11:09 +00:00
|
|
|
{
|
|
|
|
this->Function = function;
|
2017-05-18 14:29:41 +00:00
|
|
|
this->ValueCaller = [](const void* t, FloatDefault x, FloatDefault y, FloatDefault z) {
|
|
|
|
return static_cast<const T*>(t)->Value(x, y, z);
|
|
|
|
};
|
|
|
|
this->GradientCaller = [](const void* t, FloatDefault x, FloatDefault y, FloatDefault z) {
|
|
|
|
return static_cast<const T*>(t)->Gradient(x, y, z);
|
|
|
|
};
|
2017-03-29 16:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-05-18 14:29:41 +00:00
|
|
|
using ValueCallerSig = FloatDefault(const void*, FloatDefault, FloatDefault, FloatDefault);
|
2017-05-26 17:53:28 +00:00
|
|
|
using GradientCallerSig = vtkm::Vec<FloatDefault, 3>(const void*,
|
|
|
|
FloatDefault,
|
|
|
|
FloatDefault,
|
2017-05-18 14:29:41 +00:00
|
|
|
FloatDefault);
|
|
|
|
|
|
|
|
const void* Function;
|
|
|
|
ValueCallerSig* ValueCaller;
|
|
|
|
GradientCallerSig* GradientCaller;
|
2017-03-29 16:11:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A function object that evaluates the contained implicit function
|
|
|
|
class VTKM_ALWAYS_EXPORT ImplicitFunctionValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImplicitFunctionValue() = default;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
explicit ImplicitFunctionValue(const vtkm::exec::ImplicitFunction& func)
|
2017-03-29 16:11:09 +00:00
|
|
|
: Function(func)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2017-03-29 16:11:09 +00:00
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
FloatDefault operator()(const vtkm::Vec<FloatDefault, 3> x) const
|
|
|
|
{
|
|
|
|
return this->Function.Value(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
FloatDefault operator()(FloatDefault x, FloatDefault y, FloatDefault z) const
|
|
|
|
{
|
|
|
|
return this->Function.Value(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::exec::ImplicitFunction Function;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A function object that computes the gradient of the contained implicit
|
|
|
|
/// function and the specified point.
|
|
|
|
class VTKM_ALWAYS_EXPORT ImplicitFunctionGradient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImplicitFunctionGradient() = default;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
explicit ImplicitFunctionGradient(const vtkm::exec::ImplicitFunction& func)
|
2017-03-29 16:11:09 +00:00
|
|
|
: Function(func)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2017-03-29 16:11:09 +00:00
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
vtkm::Vec<FloatDefault, 3> operator()(const vtkm::Vec<FloatDefault, 3> x) const
|
|
|
|
{
|
|
|
|
return this->Function.Gradient(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
|
|
|
vtkm::Vec<FloatDefault, 3> operator()(FloatDefault x, FloatDefault y, FloatDefault z) const
|
|
|
|
{
|
|
|
|
return this->Function.Gradient(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::exec::ImplicitFunction Function;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // vtkm::exec
|
|
|
|
|
|
|
|
#endif // vtk_m_exec_ImplicitFunction_h
|