9f624f0a36
Previously, coordinate systems in a DataSet simply pointed to field data specifying the coordinate information (although the ability to get that back out of the DataSet was missing). This makes sense since point coordinates are in fact just fields with a particular semantic meaning to them. However, there is an issue with this approach. It turns out that there are special representations that are very common for point coordinates and very uncommon for other types of fields. For example, a uniform (a.k.a. regular or image) grid has point coordinates that are easily derived from the point index, but such fields are quite uncommon elsewhere. Representing this kind of structure in the Field list of a DataSet is problematic. Either all fields have to check to see if they are this type, which will cause an explosion of unnecessary generated code, or you will have to actually write out the coordinates in memory, which is really wasteful but what was done previously. However, by storing fields representing coordinate systems in a separate batch, we can use these special types without the stated explosion.
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
//============================================================================
|
|
// 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>
|
|
|
|
#include <vtkm/Math.h>
|
|
|
|
namespace vtkm {
|
|
namespace worklet {
|
|
|
|
namespace internal {
|
|
|
|
template <typename T>
|
|
VTKM_EXEC_EXPORT
|
|
T clamp(const T& val, const T& min, const T& max)
|
|
{
|
|
return vtkm::Min(max, vtkm::Max(min, val));
|
|
}
|
|
|
|
}
|
|
|
|
class PointElevation : public vtkm::worklet::WorkletMapField
|
|
{
|
|
public:
|
|
typedef void ControlSignature(FieldIn<Vec3>, FieldOut<Scalar>);
|
|
typedef _2 ExecutionSignature(_1);
|
|
|
|
VTKM_CONT_EXPORT
|
|
PointElevation() : LowPoint(0.0, 0.0, 0.0), HighPoint(0.0, 0.0, 1.0),
|
|
RangeLow(0.0), RangeHigh(1.0) {}
|
|
|
|
VTKM_CONT_EXPORT
|
|
void SetLowPoint(const vtkm::Vec<vtkm::Float64, 3> &point)
|
|
{
|
|
this->LowPoint = point;
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
void SetHighPoint(const vtkm::Vec<vtkm::Float64, 3> &point)
|
|
{
|
|
this->HighPoint = point;
|
|
}
|
|
|
|
VTKM_CONT_EXPORT
|
|
void SetRange(vtkm::Float64 low, vtkm::Float64 high)
|
|
{
|
|
this->RangeLow = low;
|
|
this->RangeHigh = high;
|
|
}
|
|
|
|
VTKM_EXEC_EXPORT
|
|
vtkm::Float64 operator()(const vtkm::Vec<vtkm::Float64,3> &vec) const
|
|
{
|
|
vtkm::Vec<vtkm::Float64, 3> direction = this->HighPoint - this->LowPoint;
|
|
vtkm::Float64 lengthSqr = vtkm::dot(direction, direction);
|
|
vtkm::Float64 rangeLength = this->RangeHigh - this->RangeLow;
|
|
vtkm::Float64 s = vtkm::dot(vec - this->LowPoint, direction) / lengthSqr;
|
|
s = internal::clamp(s, 0.0, 1.0);
|
|
return this->RangeLow + (s * rangeLength);
|
|
}
|
|
|
|
template <typename T>
|
|
VTKM_EXEC_EXPORT
|
|
vtkm::Float64 operator()(const vtkm::Vec<T,3> &vec) const
|
|
{
|
|
return (*this)(vtkm::make_Vec(static_cast<vtkm::Float64>(vec[0]),
|
|
static_cast<vtkm::Float64>(vec[1]),
|
|
static_cast<vtkm::Float64>(vec[2])));
|
|
}
|
|
|
|
private:
|
|
vtkm::Vec<vtkm::Float64, 3> LowPoint, HighPoint;
|
|
vtkm::Float64 RangeLow, RangeHigh;
|
|
};
|
|
|
|
}
|
|
} // namespace vtkm::worklet
|
|
|
|
#endif // vtk_m_worklet_PointElevation_h
|