2018-08-30 02:46:49 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-08-30 02:46:49 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2018-08-30 02:25:01 +00:00
|
|
|
#ifndef vtkm_exec_celllocatoruniformgrid_h
|
|
|
|
#define vtkm_exec_celllocatoruniformgrid_h
|
|
|
|
|
|
|
|
#include <vtkm/Bounds.h>
|
|
|
|
#include <vtkm/TopologyElementTag.h>
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/VecFromPortalPermute.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/CellInside.h>
|
|
|
|
#include <vtkm/exec/CellLocator.h>
|
|
|
|
#include <vtkm/exec/ParametricCoordinates.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace exec
|
|
|
|
{
|
|
|
|
|
2019-08-06 16:52:10 +00:00
|
|
|
template <typename DeviceAdapter, vtkm::IdComponent dimensions>
|
2019-06-17 12:44:33 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT CellLocatorUniformGrid final : public vtkm::exec::CellLocator
|
2018-08-30 02:25:01 +00:00
|
|
|
{
|
2019-01-07 01:18:23 +00:00
|
|
|
private:
|
2019-07-30 16:53:51 +00:00
|
|
|
using VisitType = vtkm::TopologyElementTagCell;
|
|
|
|
using IncidentType = vtkm::TopologyElementTagPoint;
|
2019-08-07 20:06:34 +00:00
|
|
|
using CellSetPortal = vtkm::exec::ConnectivityStructured<VisitType, IncidentType, dimensions>;
|
2019-01-07 01:18:23 +00:00
|
|
|
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
|
|
|
|
DeviceAdapter>::PortalConst;
|
|
|
|
|
2018-08-30 02:25:01 +00:00
|
|
|
public:
|
|
|
|
VTKM_CONT
|
2019-08-07 16:30:01 +00:00
|
|
|
CellLocatorUniformGrid(const vtkm::Id3 cellDims,
|
|
|
|
const vtkm::Id3 pointDims,
|
2019-08-08 16:15:28 +00:00
|
|
|
const vtkm::Vec3f origin,
|
|
|
|
const vtkm::Vec3f invSpacing,
|
|
|
|
const vtkm::Vec3f maxPoint,
|
2018-08-30 02:25:01 +00:00
|
|
|
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
|
|
|
|
DeviceAdapter)
|
2019-08-07 16:30:01 +00:00
|
|
|
: CellDims(cellDims)
|
|
|
|
, PointDims(pointDims)
|
|
|
|
, Origin(origin)
|
|
|
|
, InvSpacing(invSpacing)
|
|
|
|
, MaxPoint(maxPoint)
|
2019-02-01 13:43:54 +00:00
|
|
|
, Coords(coords.PrepareForInput(DeviceAdapter()))
|
2018-08-30 02:25:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:10:21 +00:00
|
|
|
VTKM_EXEC_CONT virtual ~CellLocatorUniformGrid() noexcept
|
|
|
|
{
|
|
|
|
// This must not be defaulted, since defaulted virtual destructors are
|
|
|
|
// troublesome with CUDA __host__ __device__ markup.
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:15:28 +00:00
|
|
|
VTKM_EXEC inline bool IsInside(const vtkm::Vec3f& point) const
|
2019-08-07 16:30:01 +00:00
|
|
|
{
|
|
|
|
bool inside = true;
|
|
|
|
if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
|
|
|
|
inside = false;
|
|
|
|
if (point[1] < this->Origin[1] || point[1] > this->MaxPoint[1])
|
|
|
|
inside = false;
|
|
|
|
if (point[2] < this->Origin[2] || point[2] > this->MaxPoint[2])
|
|
|
|
inside = false;
|
|
|
|
return inside;
|
|
|
|
}
|
|
|
|
|
2018-08-30 02:25:01 +00:00
|
|
|
VTKM_EXEC
|
2019-07-31 16:20:38 +00:00
|
|
|
void FindCell(const vtkm::Vec3f& point,
|
2018-08-30 02:25:01 +00:00
|
|
|
vtkm::Id& cellId,
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f& parametric,
|
2018-08-30 02:25:01 +00:00
|
|
|
const vtkm::exec::FunctorBase& worklet) const override
|
|
|
|
{
|
2019-08-07 16:30:01 +00:00
|
|
|
(void)worklet; //suppress unused warning
|
2019-08-08 16:15:28 +00:00
|
|
|
if (!this->IsInside(point))
|
2018-08-30 02:25:01 +00:00
|
|
|
{
|
|
|
|
cellId = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Get the Cell Id from the point.
|
2019-08-06 16:52:10 +00:00
|
|
|
vtkm::Id3 logicalCell(0, 0, 0);
|
2019-08-07 16:30:01 +00:00
|
|
|
|
2019-08-08 16:15:28 +00:00
|
|
|
vtkm::Vec3f temp;
|
|
|
|
temp = point - this->Origin;
|
|
|
|
temp = temp * this->InvSpacing;
|
2019-08-07 16:30:01 +00:00
|
|
|
|
|
|
|
//make sure that if we border the upper edge, we sample the correct cell
|
|
|
|
logicalCell = temp;
|
|
|
|
if (logicalCell[0] == this->CellDims[0])
|
2019-08-06 16:52:10 +00:00
|
|
|
{
|
2019-08-07 16:30:01 +00:00
|
|
|
logicalCell[0]--;
|
2019-08-06 16:52:10 +00:00
|
|
|
}
|
2019-08-07 16:30:01 +00:00
|
|
|
if (logicalCell[1] == this->CellDims[1])
|
|
|
|
{
|
|
|
|
logicalCell[1]--;
|
|
|
|
}
|
|
|
|
if (logicalCell[2] == this->CellDims[2])
|
|
|
|
{
|
|
|
|
logicalCell[2]--;
|
|
|
|
}
|
|
|
|
if (dimensions == 2)
|
|
|
|
logicalCell[2] = 0;
|
|
|
|
cellId =
|
|
|
|
(logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
|
|
|
|
parametric = temp - logicalCell;
|
2018-08-30 02:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Id3 CellDims;
|
2019-08-07 16:30:01 +00:00
|
|
|
vtkm::Id3 PointDims;
|
2019-08-08 16:15:28 +00:00
|
|
|
vtkm::Vec3f Origin;
|
|
|
|
vtkm::Vec3f InvSpacing;
|
|
|
|
vtkm::Vec3f MaxPoint;
|
2018-08-30 02:25:01 +00:00
|
|
|
CoordsPortal Coords;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //vtkm_exec_celllocatoruniformgrid_h
|