2019-01-07 01:18:23 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2019-01-07 01:18:23 +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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtkm_exec_celllocatorrectilineargrid_h
|
|
|
|
#define vtkm_exec_celllocatorrectilineargrid_h
|
|
|
|
|
|
|
|
#include <vtkm/Bounds.h>
|
|
|
|
#include <vtkm/TopologyElementTag.h>
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/VecFromPortalPermute.h>
|
|
|
|
|
2021-02-10 00:20:57 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
2019-01-07 01:18:23 +00:00
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/CellInside.h>
|
|
|
|
#include <vtkm/exec/CellLocator.h>
|
|
|
|
#include <vtkm/exec/ConnectivityStructured.h>
|
|
|
|
#include <vtkm/exec/ParametricCoordinates.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace exec
|
|
|
|
{
|
|
|
|
|
2021-02-10 00:20:57 +00:00
|
|
|
template <vtkm::IdComponent dimensions>
|
2019-06-17 12:44:33 +00:00
|
|
|
class VTKM_ALWAYS_EXPORT CellLocatorRectilinearGrid final : public vtkm::exec::CellLocator
|
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 AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
|
|
|
using RectilinearType =
|
|
|
|
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
2021-02-01 15:03:11 +00:00
|
|
|
using AxisPortalType = typename AxisHandle::ReadPortalType;
|
|
|
|
using RectilinearPortalType = typename RectilinearType::ReadPortalType;
|
2019-01-07 01:18:23 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
VTKM_CONT
|
|
|
|
CellLocatorRectilinearGrid(const vtkm::Id planeSize,
|
|
|
|
const vtkm::Id rowSize,
|
2019-07-11 17:45:30 +00:00
|
|
|
const vtkm::cont::CellSetStructured<dimensions>& cellSet,
|
2019-01-07 01:18:23 +00:00
|
|
|
const RectilinearType& coords,
|
2021-02-10 00:20:57 +00:00
|
|
|
vtkm::cont::DeviceAdapterId device,
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::cont::Token& token)
|
2019-01-07 01:18:23 +00:00
|
|
|
: PlaneSize(planeSize)
|
|
|
|
, RowSize(rowSize)
|
2021-02-10 00:20:57 +00:00
|
|
|
, CellSet(cellSet.PrepareForInput(device, VisitType(), IncidentType(), token))
|
|
|
|
, Coords(coords.PrepareForInput(device, token))
|
2019-04-01 14:00:35 +00:00
|
|
|
, PointDimensions(cellSet.GetPointDimensions())
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
2019-08-08 16:15:28 +00:00
|
|
|
this->AxisPortals[0] = this->Coords.GetFirstPortal();
|
2020-01-28 19:14:32 +00:00
|
|
|
this->MinPoint[0] = coords.ReadPortal().GetFirstPortal().Get(0);
|
|
|
|
this->MaxPoint[0] = coords.ReadPortal().GetFirstPortal().Get(this->PointDimensions[0] - 1);
|
2019-08-07 19:25:15 +00:00
|
|
|
|
2019-08-08 16:15:28 +00:00
|
|
|
this->AxisPortals[1] = this->Coords.GetSecondPortal();
|
2020-01-28 19:14:32 +00:00
|
|
|
this->MinPoint[1] = coords.ReadPortal().GetSecondPortal().Get(0);
|
|
|
|
this->MaxPoint[1] = coords.ReadPortal().GetSecondPortal().Get(this->PointDimensions[1] - 1);
|
2019-08-07 19:25:15 +00:00
|
|
|
if (dimensions == 3)
|
2019-08-02 15:40:54 +00:00
|
|
|
{
|
2019-08-08 16:15:28 +00:00
|
|
|
this->AxisPortals[2] = this->Coords.GetThirdPortal();
|
2020-01-28 19:14:32 +00:00
|
|
|
this->MinPoint[2] = coords.ReadPortal().GetThirdPortal().Get(0);
|
|
|
|
this->MaxPoint[2] = coords.ReadPortal().GetThirdPortal().Get(this->PointDimensions[2] - 1);
|
2019-08-02 15:40:54 +00:00
|
|
|
}
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 15:06:47 +00:00
|
|
|
VTKM_EXEC_CONT virtual ~CellLocatorRectilinearGrid() noexcept override
|
2019-04-26 14:10:21 +00:00
|
|
|
{
|
|
|
|
// This must not be defaulted, since defaulted virtual destructors are
|
|
|
|
// troublesome with CUDA __host__ __device__ markup.
|
|
|
|
}
|
|
|
|
|
2019-01-07 01:18:23 +00:00
|
|
|
VTKM_EXEC
|
2019-07-31 16:20:38 +00:00
|
|
|
inline bool IsInside(const vtkm::Vec3f& point) const
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
|
|
|
bool inside = true;
|
2019-04-01 14:00:35 +00:00
|
|
|
if (point[0] < this->MinPoint[0] || point[0] > this->MaxPoint[0])
|
2019-01-07 01:18:23 +00:00
|
|
|
inside = false;
|
2019-04-01 14:00:35 +00:00
|
|
|
if (point[1] < this->MinPoint[1] || point[1] > this->MaxPoint[1])
|
2019-01-07 01:18:23 +00:00
|
|
|
inside = false;
|
2019-08-08 16:41:23 +00:00
|
|
|
if (dimensions == 3)
|
|
|
|
{
|
|
|
|
if (point[2] < this->MinPoint[2] || point[2] > this->MaxPoint[2])
|
|
|
|
inside = false;
|
|
|
|
}
|
2019-01-07 01:18:23 +00:00
|
|
|
return inside;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::ErrorCode FindCell(const vtkm::Vec3f& point,
|
|
|
|
vtkm::Id& cellId,
|
|
|
|
vtkm::Vec3f& parametric) const override
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
2019-08-08 16:15:28 +00:00
|
|
|
if (!this->IsInside(point))
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
|
|
|
cellId = -1;
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::CellNotFound;
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
2019-04-01 14:00:35 +00:00
|
|
|
|
2019-01-07 01:18:23 +00:00
|
|
|
// Get the Cell Id from the point.
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Id3 logicalCell(0, 0, 0);
|
2019-08-06 16:52:10 +00:00
|
|
|
for (vtkm::Int32 dim = 0; dim < dimensions; ++dim)
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// When searching for points, we consider the max value of the cell
|
|
|
|
// to be apart of the next cell. If the point falls on the boundary of the
|
|
|
|
// data set, then it is technically inside a cell. This checks for that case
|
|
|
|
//
|
|
|
|
if (point[dim] == MaxPoint[dim])
|
|
|
|
{
|
2019-08-08 16:15:28 +00:00
|
|
|
logicalCell[dim] = this->PointDimensions[dim] - 2;
|
2020-04-23 20:14:28 +00:00
|
|
|
parametric[dim] = static_cast<vtkm::FloatDefault>(1);
|
2019-01-07 01:18:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-07 19:25:15 +00:00
|
|
|
vtkm::Id minIndex = 0;
|
2019-08-08 16:15:28 +00:00
|
|
|
vtkm::Id maxIndex = this->PointDimensions[dim] - 1;
|
2019-08-07 19:25:15 +00:00
|
|
|
vtkm::FloatDefault minVal;
|
|
|
|
vtkm::FloatDefault maxVal;
|
|
|
|
minVal = this->AxisPortals[dim].Get(minIndex);
|
|
|
|
maxVal = this->AxisPortals[dim].Get(maxIndex);
|
|
|
|
while (maxIndex > minIndex + 1)
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
2019-08-07 19:25:15 +00:00
|
|
|
vtkm::Id midIndex = (minIndex + maxIndex) / 2;
|
|
|
|
vtkm::FloatDefault midVal = this->AxisPortals[dim].Get(midIndex);
|
|
|
|
if (point[dim] <= midVal)
|
2019-01-07 01:18:23 +00:00
|
|
|
{
|
2019-08-07 19:25:15 +00:00
|
|
|
maxIndex = midIndex;
|
|
|
|
maxVal = midVal;
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-07 19:25:15 +00:00
|
|
|
minIndex = midIndex;
|
|
|
|
minVal = midVal;
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 19:25:15 +00:00
|
|
|
logicalCell[dim] = minIndex;
|
|
|
|
parametric[dim] = (point[dim] - minVal) / (maxVal - minVal);
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
|
|
|
// Get the actual cellId, from the logical cell index of the cell
|
2019-04-01 14:00:35 +00:00
|
|
|
cellId = logicalCell[2] * this->PlaneSize + logicalCell[1] * this->RowSize + logicalCell[0];
|
2020-03-12 23:38:27 +00:00
|
|
|
|
|
|
|
return vtkm::ErrorCode::Success;
|
2019-01-07 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vtkm::Id PlaneSize;
|
|
|
|
vtkm::Id RowSize;
|
|
|
|
|
|
|
|
CellSetPortal CellSet;
|
|
|
|
RectilinearPortalType Coords;
|
|
|
|
AxisPortalType AxisPortals[3];
|
2019-07-31 21:21:40 +00:00
|
|
|
vtkm::Vec<vtkm::Id, dimensions> PointDimensions;
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f MinPoint;
|
|
|
|
vtkm::Vec3f MaxPoint;
|
2019-01-07 01:18:23 +00:00
|
|
|
};
|
|
|
|
} //namespace exec
|
|
|
|
} //namespace vtkm
|
|
|
|
|
|
|
|
#endif //vtkm_exec_celllocatorrectilineargrid_h
|