2019-03-29 17:28:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2019-03-29 17:28:27 +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/CellLocatorGeneral.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
|
|
|
#include <vtkm/cont/CellLocatorRectilinearGrid.h>
|
2020-09-21 21:35:30 +00:00
|
|
|
#include <vtkm/cont/CellLocatorTwoLevel.h>
|
2019-03-29 17:28:27 +00:00
|
|
|
#include <vtkm/cont/CellLocatorUniformGrid.h>
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2020-09-22 15:32:01 +00:00
|
|
|
template <typename LocatorImplType, typename LocatorVariantType>
|
|
|
|
void BuildForType(vtkm::cont::CellLocatorGeneral& locator, LocatorVariantType& locatorVariant)
|
|
|
|
{
|
|
|
|
constexpr vtkm::IdComponent LOCATOR_INDEX =
|
|
|
|
LocatorVariantType::template GetIndexOf<LocatorImplType>();
|
|
|
|
if (locatorVariant.GetIndex() != LOCATOR_INDEX)
|
|
|
|
{
|
|
|
|
locatorVariant = LocatorImplType{};
|
|
|
|
}
|
|
|
|
LocatorImplType& locatorImpl = locatorVariant.template Get<LOCATOR_INDEX>();
|
|
|
|
locatorImpl.SetCellSet(locator.GetCellSet());
|
|
|
|
locatorImpl.SetCoordinates(locator.GetCoordinates());
|
|
|
|
locatorImpl.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
|
|
|
VTKM_CONT void CellLocatorGeneral::Build()
|
2019-03-29 17:28:27 +00:00
|
|
|
{
|
|
|
|
using StructuredCellSet = vtkm::cont::CellSetStructured<3>;
|
|
|
|
using UniformCoordinates = vtkm::cont::ArrayHandleUniformPointCoordinates;
|
|
|
|
using RectilinearCoordinates =
|
|
|
|
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>;
|
|
|
|
|
2022-01-04 22:38:18 +00:00
|
|
|
vtkm::cont::UnknownCellSet cellSet = this->GetCellSet();
|
2020-09-22 15:32:01 +00:00
|
|
|
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
|
|
|
|
|
2019-03-29 17:28:27 +00:00
|
|
|
if (cellSet.IsType<StructuredCellSet>() && coords.GetData().IsType<UniformCoordinates>())
|
|
|
|
{
|
2020-09-22 15:32:01 +00:00
|
|
|
BuildForType<vtkm::cont::CellLocatorUniformGrid>(*this, this->LocatorImpl);
|
2019-03-29 17:28:27 +00:00
|
|
|
}
|
|
|
|
else if (cellSet.IsType<StructuredCellSet>() && coords.GetData().IsType<RectilinearCoordinates>())
|
|
|
|
{
|
2020-09-22 15:32:01 +00:00
|
|
|
BuildForType<vtkm::cont::CellLocatorRectilinearGrid>(*this, this->LocatorImpl);
|
2019-03-29 17:28:27 +00:00
|
|
|
}
|
2020-09-22 15:32:01 +00:00
|
|
|
else
|
2019-03-29 17:28:27 +00:00
|
|
|
{
|
2020-09-22 15:32:01 +00:00
|
|
|
BuildForType<vtkm::cont::CellLocatorTwoLevel>(*this, this->LocatorImpl);
|
2019-03-29 17:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 15:32:01 +00:00
|
|
|
struct CellLocatorGeneral::PrepareFunctor
|
2019-03-29 17:28:27 +00:00
|
|
|
{
|
2020-09-22 15:32:01 +00:00
|
|
|
template <typename LocatorType>
|
|
|
|
ExecObjType operator()(LocatorType&& locator,
|
|
|
|
vtkm::cont::DeviceAdapterId device,
|
|
|
|
vtkm::cont::Token& token) const
|
2019-03-29 17:28:27 +00:00
|
|
|
{
|
2020-09-22 15:32:01 +00:00
|
|
|
return locator.PrepareForExecution(device, token);
|
2019-03-29 17:28:27 +00:00
|
|
|
}
|
2020-09-22 15:32:01 +00:00
|
|
|
};
|
2019-03-29 17:28:27 +00:00
|
|
|
|
2020-09-22 15:32:01 +00:00
|
|
|
CellLocatorGeneral::ExecObjType CellLocatorGeneral::PrepareForExecution(
|
|
|
|
vtkm::cont::DeviceAdapterId device,
|
|
|
|
vtkm::cont::Token& token) const
|
2019-03-29 17:28:27 +00:00
|
|
|
{
|
2020-11-11 22:29:48 +00:00
|
|
|
this->Update();
|
2020-09-22 15:32:01 +00:00
|
|
|
return this->LocatorImpl.CastAndCall(PrepareFunctor{}, device, token);
|
2019-03-29 17:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} // vtkm::cont
|