2015-06-09 15:02:17 +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 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_PointElevation_h
|
|
|
|
#define vtk_m_worklet_PointElevation_h
|
|
|
|
|
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
|
|
|
|
2015-08-17 18:47:46 +00:00
|
|
|
#include <vtkm/Math.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2015-06-09 15:02:17 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2015-06-09 15:02:17 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC T clamp(const T& val, const T& min, const T& max)
|
2015-06-09 15:02:17 +00:00
|
|
|
{
|
2015-08-17 18:47:46 +00:00
|
|
|
return vtkm::Min(max, vtkm::Max(min, val));
|
2015-06-09 15:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PointElevation : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
public:
|
2015-08-17 18:47:46 +00:00
|
|
|
typedef void ControlSignature(FieldIn<Vec3>, FieldOut<Scalar>);
|
|
|
|
typedef _2 ExecutionSignature(_1);
|
2015-06-09 15:02:17 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PointElevation()
|
|
|
|
: LowPoint(0.0, 0.0, 0.0)
|
|
|
|
, HighPoint(0.0, 0.0, 1.0)
|
|
|
|
, RangeLow(0.0)
|
|
|
|
, RangeHigh(1.0)
|
2015-06-09 15:02:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void SetLowPoint(const vtkm::Vec<vtkm::Float64, 3>& point) { this->LowPoint = point; }
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
void SetHighPoint(const vtkm::Vec<vtkm::Float64, 3>& point) { this->HighPoint = point; }
|
2015-06-09 15:02:17 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-06-09 15:02:17 +00:00
|
|
|
void SetRange(vtkm::Float64 low, vtkm::Float64 high)
|
|
|
|
{
|
|
|
|
this->RangeLow = low;
|
|
|
|
this->RangeHigh = high;
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Float64 operator()(const vtkm::Vec<vtkm::Float64, 3>& vec) const
|
2015-06-09 15:02:17 +00:00
|
|
|
{
|
|
|
|
vtkm::Vec<vtkm::Float64, 3> direction = this->HighPoint - this->LowPoint;
|
2015-08-17 18:47:46 +00:00
|
|
|
vtkm::Float64 lengthSqr = vtkm::dot(direction, direction);
|
2015-06-09 15:02:17 +00:00
|
|
|
vtkm::Float64 rangeLength = this->RangeHigh - this->RangeLow;
|
2015-08-17 18:47:46 +00:00
|
|
|
vtkm::Float64 s = vtkm::dot(vec - this->LowPoint, direction) / lengthSqr;
|
2015-06-09 15:02:17 +00:00
|
|
|
s = internal::clamp(s, 0.0, 1.0);
|
2015-08-17 18:47:46 +00:00
|
|
|
return this->RangeLow + (s * rangeLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC vtkm::Float64 operator()(const vtkm::Vec<T, 3>& vec) const
|
2015-08-17 18:47:46 +00:00
|
|
|
{
|
|
|
|
return (*this)(vtkm::make_Vec(static_cast<vtkm::Float64>(vec[0]),
|
|
|
|
static_cast<vtkm::Float64>(vec[1]),
|
|
|
|
static_cast<vtkm::Float64>(vec[2])));
|
2015-06-09 15:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::Vec<vtkm::Float64, 3> LowPoint, HighPoint;
|
|
|
|
vtkm::Float64 RangeLow, RangeHigh;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif // vtk_m_worklet_PointElevation_h
|