2019-03-20 23:38:50 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2019-03-20 23:38:50 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/Algorithm.h>
|
2019-03-28 12:27:37 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
2019-03-20 23:38:50 +00:00
|
|
|
#include <vtkm/cont/CellLocatorUniformGrid.h>
|
2019-03-28 12:27:37 +00:00
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
2019-03-20 23:38:50 +00:00
|
|
|
|
2019-03-28 12:27:37 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2019-03-20 23:38:50 +00:00
|
|
|
|
2019-03-28 12:27:37 +00:00
|
|
|
using UniformType = vtkm::cont::ArrayHandleUniformPointCoordinates;
|
2019-08-06 16:52:10 +00:00
|
|
|
using Structured2DType = vtkm::cont::CellSetStructured<2>;
|
|
|
|
using Structured3DType = vtkm::cont::CellSetStructured<3>;
|
2019-03-20 23:38:50 +00:00
|
|
|
|
2019-03-28 12:27:37 +00:00
|
|
|
void CellLocatorUniformGrid::Build()
|
2019-03-20 23:38:50 +00:00
|
|
|
{
|
|
|
|
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
|
|
|
|
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
|
|
|
|
|
|
|
|
if (!coords.GetData().IsType<UniformType>())
|
2019-08-08 16:15:28 +00:00
|
|
|
throw vtkm::cont::ErrorBadType("Coordinates are not uniform type.");
|
2019-03-20 23:38:50 +00:00
|
|
|
|
2019-08-06 16:52:10 +00:00
|
|
|
if (cellSet.IsSameType(Structured2DType()))
|
|
|
|
{
|
|
|
|
this->Is3D = false;
|
2019-08-07 16:30:01 +00:00
|
|
|
Structured2DType structuredCellSet = cellSet.Cast<Structured2DType>();
|
|
|
|
vtkm::Id2 pointDims = structuredCellSet.GetSchedulingRange(vtkm::TopologyElementTagPoint());
|
|
|
|
this->PointDims = vtkm::Id3(pointDims[0], pointDims[1], 1);
|
2019-08-06 16:52:10 +00:00
|
|
|
}
|
2019-08-06 17:10:21 +00:00
|
|
|
else if (cellSet.IsSameType(Structured3DType()))
|
2019-08-06 16:52:10 +00:00
|
|
|
{
|
|
|
|
this->Is3D = true;
|
2019-08-07 16:30:01 +00:00
|
|
|
Structured3DType structuredCellSet = cellSet.Cast<Structured3DType>();
|
|
|
|
this->PointDims = structuredCellSet.GetSchedulingRange(vtkm::TopologyElementTagPoint());
|
2019-08-06 16:52:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-08 16:15:28 +00:00
|
|
|
throw vtkm::cont::ErrorBadType("Cells are not 2D or 3D structured type.");
|
2019-08-06 16:52:10 +00:00
|
|
|
}
|
2019-08-07 16:30:01 +00:00
|
|
|
|
2021-01-25 17:36:56 +00:00
|
|
|
UniformType uniformCoords = coords.GetData().AsArrayHandle<UniformType>();
|
2020-05-12 19:43:40 +00:00
|
|
|
auto coordsPortal = uniformCoords.ReadPortal();
|
|
|
|
this->Origin = coordsPortal.GetOrigin();
|
2019-08-07 16:30:01 +00:00
|
|
|
|
2020-05-12 19:43:40 +00:00
|
|
|
vtkm::Vec3f spacing = coordsPortal.GetSpacing();
|
2019-08-08 16:15:28 +00:00
|
|
|
vtkm::Vec3f unitLength;
|
|
|
|
unitLength[0] = static_cast<vtkm::FloatDefault>(this->PointDims[0] - 1);
|
|
|
|
unitLength[1] = static_cast<vtkm::FloatDefault>(this->PointDims[1] - 1);
|
|
|
|
unitLength[2] = static_cast<vtkm::FloatDefault>(this->PointDims[2] - 1);
|
2019-08-07 16:30:01 +00:00
|
|
|
|
2019-08-08 16:15:28 +00:00
|
|
|
this->MaxPoint = this->Origin + spacing * unitLength;
|
2019-08-07 16:30:01 +00:00
|
|
|
this->InvSpacing[0] = 1.f / spacing[0];
|
|
|
|
this->InvSpacing[1] = 1.f / spacing[1];
|
|
|
|
this->InvSpacing[2] = 1.f / spacing[2];
|
|
|
|
|
2019-08-08 16:15:28 +00:00
|
|
|
this->CellDims[0] = this->PointDims[0] - 1;
|
|
|
|
this->CellDims[1] = this->PointDims[1] - 1;
|
|
|
|
this->CellDims[2] = this->PointDims[2] - 1;
|
2019-03-20 23:38:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 15:32:01 +00:00
|
|
|
vtkm::exec::CellLocatorUniformGrid CellLocatorUniformGrid::PrepareForExecution(
|
|
|
|
vtkm::cont::DeviceAdapterId vtkmNotUsed(device),
|
|
|
|
vtkm::cont::Token& vtkmNotUsed(token)) const
|
2019-03-20 23:38:50 +00:00
|
|
|
{
|
2020-11-11 22:29:48 +00:00
|
|
|
this->Update();
|
2020-09-22 15:32:01 +00:00
|
|
|
return vtkm::exec::CellLocatorUniformGrid(
|
|
|
|
this->CellDims, this->Origin, this->InvSpacing, this->MaxPoint);
|
2019-03-28 12:27:37 +00:00
|
|
|
}
|
2019-04-01 20:25:51 +00:00
|
|
|
|
|
|
|
} //namespace cont
|
|
|
|
} //namespace vtkm
|