mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'code_sprint_locator_fixes'
9b56d41fe Fixing Rectilinear Grid Cell Locator 10e9d47dc Removing std::out print statement from test 34c7b57d8 Merge branch 'code_sprint_locator_fixes' of gitlab.kitware.com:ayenpure/vtk-m into code_sprint_locator_fixes 62ee1a2c8 Updates to the Cell Locators 7eb0de5b7 Merge branch 'code_sprint_locator_fixes' of gitlab.kitware.com:ayenpure/vtk-m into code_sprint_locator_fixes 866b0798d Resolving type warnings c062f2e26 Merge branch 'master' of https://gitlab.kitware.com/vtk/vtk-m into code_sprint_locator_fixes 797c83891 Adding default constructor and removing wrong comment ... Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Kenneth Moreland <kmorel@sandia.gov> Merge-request: !1395
This commit is contained in:
commit
afd0409189
@ -55,7 +55,9 @@ set(headers
|
||||
BoundsGlobalCompute.h
|
||||
CellLocator.h
|
||||
CellLocatorHelper.h
|
||||
CellLocatorRectilinearGrid.h
|
||||
CellLocatorTwoLevelUniformGrid.h
|
||||
CellLocatorUniformGrid.h
|
||||
CellSet.h
|
||||
CellSetExplicit.h
|
||||
CellSetListTag.h
|
||||
|
@ -35,8 +35,6 @@ namespace cont
|
||||
|
||||
class CellLocator : public vtkm::cont::ExecutionObjectBase
|
||||
{
|
||||
private:
|
||||
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
|
||||
|
||||
public:
|
||||
CellLocator()
|
||||
@ -73,6 +71,8 @@ public:
|
||||
return PrepareForExecutionImpl(device).PrepareForExecution(device);
|
||||
}
|
||||
|
||||
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>;
|
||||
|
||||
protected:
|
||||
void SetDirty() { Dirty = true; }
|
||||
|
||||
|
109
vtkm/cont/CellLocatorRectilinearGrid.h
Normal file
109
vtkm/cont/CellLocatorRectilinearGrid.h
Normal file
@ -0,0 +1,109 @@
|
||||
//============================================================================
|
||||
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2018 UT-Battelle, LLC.
|
||||
// Copyright 2018 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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 vtkm_cont_celllocatorrectilineargrid_h
|
||||
#define vtkm_cont_celllocatorrectilineargrid_h
|
||||
|
||||
#include <vtkm/cont/CellLocator.h>
|
||||
#include <vtkm/cont/CellSetStructured.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/ErrorBadDevice.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorRectilinearGrid.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class CellLocatorRectilinearGrid : public vtkm::cont::CellLocator
|
||||
{
|
||||
public:
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
|
||||
VTKM_CONT
|
||||
CellLocatorRectilinearGrid() = default;
|
||||
|
||||
VTKM_CONT
|
||||
void Build() override
|
||||
{
|
||||
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
|
||||
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
|
||||
|
||||
if (!coords.GetData().IsType<RectilinearType>())
|
||||
throw vtkm::cont::ErrorInternal("Coordinates are not rectilinear.");
|
||||
if (!cellSet.IsSameType(StructuredType()))
|
||||
throw vtkm::cont::ErrorInternal("Cells are not 3D structured.");
|
||||
|
||||
vtkm::Vec<vtkm::Id, 3> celldims =
|
||||
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
|
||||
this->PlaneSize = celldims[0] * celldims[1];
|
||||
this->RowSize = celldims[0];
|
||||
}
|
||||
|
||||
struct PrepareForExecutionFunctor
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter,
|
||||
const vtkm::cont::CellLocatorRectilinearGrid& contLocator,
|
||||
HandleType& execLocator) const
|
||||
{
|
||||
using ExecutionType = vtkm::exec::CellLocatorRectilinearGrid<DeviceAdapter>;
|
||||
ExecutionType* execObject =
|
||||
new ExecutionType(contLocator.PlaneSize,
|
||||
contLocator.RowSize,
|
||||
contLocator.GetCellSet().template Cast<StructuredType>(),
|
||||
contLocator.GetCoordinates().GetData().template Cast<RectilinearType>(),
|
||||
DeviceAdapter());
|
||||
execLocator.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
deviceId, PrepareForExecutionFunctor(), *this, this->ExecHandle);
|
||||
if (!success)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("CellLocatorRectilinearGrid", deviceId);
|
||||
}
|
||||
return this->ExecHandle;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Id PlaneSize;
|
||||
vtkm::Id RowSize;
|
||||
|
||||
mutable HandleType ExecHandle;
|
||||
};
|
||||
|
||||
} //namespace cont
|
||||
|
||||
} //namespace vtkm
|
||||
|
||||
#endif //vtkm_cont_celllocatorrectilineargrid_h
|
115
vtkm/cont/CellLocatorUniformGrid.h
Normal file
115
vtkm/cont/CellLocatorUniformGrid.h
Normal file
@ -0,0 +1,115 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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 vtkm_cont_celllocatoruniformgrid_h
|
||||
#define vtkm_cont_celllocatoruniformgrid_h
|
||||
|
||||
#include <vtkm/cont/CellLocator.h>
|
||||
#include <vtkm/cont/CellSetStructured.h>
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/ErrorBadDevice.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorUniformGrid.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class CellLocatorUniformGrid : public vtkm::cont::CellLocator
|
||||
{
|
||||
public:
|
||||
VTKM_CONT
|
||||
CellLocatorUniformGrid() = default;
|
||||
|
||||
VTKM_CONT
|
||||
void Build() override
|
||||
{
|
||||
vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
|
||||
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
|
||||
|
||||
if (!coords.GetData().IsType<UniformType>())
|
||||
throw vtkm::cont::ErrorBadType("Coordinate system is not uniform type");
|
||||
if (!cellSet.IsSameType(StructuredType()))
|
||||
throw vtkm::cont::ErrorBadType("Cell set is not 3D structured type");
|
||||
|
||||
Bounds = coords.GetBounds();
|
||||
vtkm::Vec<vtkm::Id, 3> celldims =
|
||||
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
|
||||
|
||||
RangeTransform[0] = static_cast<vtkm::FloatDefault>(celldims[0]) /
|
||||
static_cast<vtkm::FloatDefault>(Bounds.X.Length());
|
||||
RangeTransform[1] = static_cast<vtkm::FloatDefault>(celldims[1]) /
|
||||
static_cast<vtkm::FloatDefault>(Bounds.Y.Length());
|
||||
RangeTransform[2] = static_cast<vtkm::FloatDefault>(celldims[2]) /
|
||||
static_cast<vtkm::FloatDefault>(Bounds.Z.Length());
|
||||
|
||||
PlaneSize = celldims[0] * celldims[1];
|
||||
RowSize = celldims[0];
|
||||
}
|
||||
|
||||
struct PrepareForExecutionFunctor
|
||||
{
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT bool operator()(DeviceAdapter,
|
||||
const vtkm::cont::CellLocatorUniformGrid& contLocator,
|
||||
HandleType& execLocator) const
|
||||
{
|
||||
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter>;
|
||||
ExecutionType* execObject =
|
||||
new ExecutionType(contLocator.Bounds,
|
||||
contLocator.RangeTransform,
|
||||
contLocator.PlaneSize,
|
||||
contLocator.RowSize,
|
||||
contLocator.GetCellSet().template Cast<StructuredType>(),
|
||||
contLocator.GetCoordinates().GetData(),
|
||||
DeviceAdapter());
|
||||
execLocator.Reset(execObject);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImpl(
|
||||
const vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success = vtkm::cont::TryExecuteOnDevice(
|
||||
deviceId, PrepareForExecutionFunctor(), *this, this->ExecHandle);
|
||||
if (!success)
|
||||
{
|
||||
throwFailedRuntimeDeviceTransfer("CellLocatorUniformGrid", deviceId);
|
||||
}
|
||||
return this->ExecHandle;
|
||||
}
|
||||
|
||||
private:
|
||||
using UniformType = vtkm::cont::ArrayHandleUniformPointCoordinates;
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Vec<vtkm::FloatDefault, 3> RangeTransform;
|
||||
vtkm::Id PlaneSize;
|
||||
vtkm::Id RowSize;
|
||||
mutable HandleType ExecHandle;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtkm_cont_celllocatoruniformgrid_h
|
@ -38,11 +38,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
vtkm::cont::CoordinateSystem GetCoords() const { return coordinates; }
|
||||
vtkm::cont::CoordinateSystem GetCoordinates() const { return Coords; }
|
||||
|
||||
void SetCoords(const vtkm::cont::CoordinateSystem& coords)
|
||||
void SetCoordinates(const vtkm::cont::CoordinateSystem& coords)
|
||||
{
|
||||
coordinates = coords;
|
||||
Coords = coords;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@ -58,15 +58,15 @@ public:
|
||||
template <typename DeviceAdapter>
|
||||
VTKM_CONT const vtkm::exec::PointLocator* PrepareForExecution(DeviceAdapter device) const
|
||||
{
|
||||
return PrepareForExecutionImp(device).PrepareForExecution(device);
|
||||
return PrepareForExecutionImpl(device).PrepareForExecution(device);
|
||||
}
|
||||
|
||||
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator>;
|
||||
VTKM_CONT virtual const HandleType PrepareForExecutionImp(
|
||||
VTKM_CONT virtual const HandleType PrepareForExecutionImpl(
|
||||
vtkm::cont::DeviceAdapterId deviceId) const = 0;
|
||||
|
||||
private:
|
||||
vtkm::cont::CoordinateSystem coordinates;
|
||||
vtkm::cont::CoordinateSystem Coords;
|
||||
|
||||
bool dirty;
|
||||
};
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
void Build() override
|
||||
{
|
||||
// Save training data points.
|
||||
vtkm::cont::ArrayCopy(this->GetCoords().GetData(), this->coords);
|
||||
vtkm::cont::ArrayCopy(this->GetCoordinates().GetData(), this->coords);
|
||||
|
||||
// generate unique id for each input point
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> pointCounting(0, 1, this->coords.GetNumberOfValues());
|
||||
@ -125,7 +125,7 @@ public:
|
||||
};
|
||||
|
||||
VTKM_CONT
|
||||
const HandleType PrepareForExecutionImp(vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
const HandleType PrepareForExecutionImpl(vtkm::cont::DeviceAdapterId deviceId) const override
|
||||
{
|
||||
const bool success =
|
||||
vtkm::cont::TryExecuteOnDevice(deviceId, PrepareForExecutionFunctor(), *this, ExecHandle);
|
||||
|
@ -22,7 +22,9 @@ set(unit_tests
|
||||
UnitTestCudaArrayHandle.cu
|
||||
UnitTestCudaArrayHandleFancy.cu
|
||||
UnitTestCudaArrayHandleVirtualCoordinates.cu
|
||||
UnitTestCudaCellLocatorRectilinearGrid.cu
|
||||
UnitTestCudaCellLocatorTwoLevelUniformGrid.cu
|
||||
UnitTestCudaCellLocatorUniformGrid.cu
|
||||
UnitTestCudaComputeRange.cu
|
||||
UnitTestCudaColorTable.cu
|
||||
UnitTestCudaDataSetExplicit.cu
|
||||
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestCudaCellLocatorRectilinearGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagCuda>());
|
||||
}
|
34
vtkm/cont/cuda/testing/UnitTestCudaCellLocatorUniformGrid.cu
Normal file
34
vtkm/cont/cuda/testing/UnitTestCudaCellLocatorUniformGrid.cu
Normal file
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestCudaCellLocatorUniformGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagCuda{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagCuda>());
|
||||
}
|
@ -22,7 +22,9 @@ set(unit_tests
|
||||
UnitTestOpenMPArrayHandle.cxx
|
||||
UnitTestOpenMPArrayHandleFancy.cxx
|
||||
UnitTestOpenMPArrayHandleVirtualCoordinates.cxx
|
||||
UnitTestOpenMPCellLocatorRectilinearGrid.cxx
|
||||
UnitTestOpenMPCellLocatorTwoLevelUniformGrid.cxx
|
||||
UnitTestOpenMPCellLocatorUniformGrid.cxx
|
||||
UnitTestOpenMPColorTable.cxx
|
||||
UnitTestOpenMPComputeRange.cxx
|
||||
UnitTestOpenMPDataSetExplicit.cxx
|
||||
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestOpenMPCellLocatorRectilinearGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagSerial>());
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestOpenMPCellLocatorUniformGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagSerial>());
|
||||
}
|
@ -22,7 +22,9 @@ set(unit_tests
|
||||
UnitTestSerialArrayHandle.cxx
|
||||
UnitTestSerialArrayHandleFancy.cxx
|
||||
UnitTestSerialArrayHandleVirtualCoordinates.cxx
|
||||
UnitTestSerialCellLocatorRectilinearGrid.cxx
|
||||
UnitTestSerialCellLocatorTwoLevelUniformGrid.cxx
|
||||
UnitTestSerialCellLocatorUniformGrid.cxx
|
||||
UnitTestSerialComputeRange.cxx
|
||||
UnitTestSerialColorTable.cxx
|
||||
UnitTestSerialDataSetExplicit.cxx
|
||||
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestSerialCellLocatorRectilinearGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagSerial>());
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestSerialCellLocatorUniformGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagSerial{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagSerial>());
|
||||
}
|
@ -22,7 +22,9 @@ set(unit_tests
|
||||
UnitTestTBBArrayHandle.cxx
|
||||
UnitTestTBBArrayHandleFancy.cxx
|
||||
UnitTestTBBArrayHandleVirtualCoordinates.cxx
|
||||
UnitTestTBBCellLocatorRectilinearGrid.cxx
|
||||
UnitTestTBBCellLocatorTwoLevelUniformGrid.cxx
|
||||
UnitTestTBBCellLocatorUniformGrid.cxx
|
||||
UnitTestTBBColorTable.cxx
|
||||
UnitTestTBBComputeRange.cxx
|
||||
UnitTestTBBDataSetExplicit.cxx
|
||||
|
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h>
|
||||
|
||||
int UnitTestTBBCellLocatorRectilinearGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorRectilinearGrid<vtkm::cont::DeviceAdapterTagTBB>());
|
||||
}
|
34
vtkm/cont/tbb/testing/UnitTestTBBCellLocatorUniformGrid.cxx
Normal file
34
vtkm/cont/tbb/testing/UnitTestTBBCellLocatorUniformGrid.cxx
Normal file
@ -0,0 +1,34 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
// Make sure that the tested code is using the device adapter specified. This
|
||||
// is important in the long run so we don't, for example, use the CUDA device
|
||||
// for a part of an operation where the TBB device was specified.
|
||||
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_ERROR
|
||||
|
||||
#include <vtkm/cont/testing/TestingCellLocatorUniformGrid.h>
|
||||
|
||||
int UnitTestTBBCellLocatorUniformGrid(int, char* [])
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
tracker.ForceDevice(vtkm::cont::DeviceAdapterTagTBB{});
|
||||
return vtkm::cont::testing::Testing::Run(
|
||||
TestingCellLocatorUniformGrid<vtkm::cont::DeviceAdapterTagTBB>());
|
||||
}
|
@ -24,7 +24,9 @@ set(headers
|
||||
Testing.h
|
||||
TestingArrayHandles.h
|
||||
TestingArrayHandleVirtualCoordinates.h
|
||||
TestingCellLocatorRectilinearGrid.h
|
||||
TestingCellLocatorTwoLevelUniformGrid.h
|
||||
TestingCellLocatorUniformGrid.h
|
||||
TestingColorTable.h
|
||||
TestingComputeRange.h
|
||||
TestingDeviceAdapter.h
|
||||
|
206
vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h
Normal file
206
vtkm/cont/testing/TestingCellLocatorRectilinearGrid.h
Normal file
@ -0,0 +1,206 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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_cont_testing_TestingCellLocatorRectilinearGrid_h
|
||||
#define vtk_m_cont_testing_TestingCellLocatorRectilinearGrid_h
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <vtkm/cont/CellLocatorRectilinearGrid.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderRectilinear.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorRectilinearGrid.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class LocatorWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using AxisPortalType = typename AxisHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
using RectilinearPortalType =
|
||||
typename RectilinearType::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
||||
|
||||
LocatorWorklet(vtkm::Bounds& bounds, vtkm::Vec<vtkm::Id, 3>& dims, const RectilinearType& coords)
|
||||
: Bounds(bounds)
|
||||
, Dims(dims)
|
||||
{
|
||||
RectilinearPortalType coordsPortal = coords.PrepareForInput(DeviceAdapter());
|
||||
xAxis = coordsPortal.GetFirstPortal();
|
||||
yAxis = coordsPortal.GetSecondPortal();
|
||||
zAxis = coordsPortal.GetThirdPortal();
|
||||
}
|
||||
|
||||
using ControlSignature = void(FieldIn<> pointIn,
|
||||
ExecObject locator,
|
||||
FieldOut<> cellId,
|
||||
FieldOut<> parametric,
|
||||
FieldOut<> match);
|
||||
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
||||
|
||||
template <typename PointType>
|
||||
VTKM_EXEC vtkm::Id CalculateCellId(const PointType& point) const
|
||||
{
|
||||
if (!Bounds.Contains(point))
|
||||
return -1;
|
||||
vtkm::Vec<vtkm::Id, 3> logical(-1, -1, -1);
|
||||
// Linear search in the coordinates.
|
||||
vtkm::Id index;
|
||||
/*Get floor X location*/
|
||||
for (index = 0; index < this->Dims[0] - 1; index++)
|
||||
if (xAxis.Get(index) <= point[0] && point[0] < xAxis.Get(index + 1))
|
||||
{
|
||||
logical[0] = index;
|
||||
break;
|
||||
}
|
||||
/*Get floor Y location*/
|
||||
for (index = 0; index < this->Dims[1] - 1; index++)
|
||||
if (yAxis.Get(index) <= point[1] && point[1] < yAxis.Get(index + 1))
|
||||
{
|
||||
logical[1] = index;
|
||||
break;
|
||||
}
|
||||
/*Get floor Z location*/
|
||||
for (index = 0; index < this->Dims[2] - 1; index++)
|
||||
if (zAxis.Get(index) <= point[2] && point[2] < zAxis.Get(index + 1))
|
||||
{
|
||||
logical[2] = index;
|
||||
break;
|
||||
}
|
||||
if (logical[0] == -1 || logical[1] == -1 || logical[2] == -1)
|
||||
return -1;
|
||||
return logical[2] * (Dims[0] - 1) * (Dims[1] - 1) + logical[1] * (Dims[0] - 1) + logical[0];
|
||||
}
|
||||
|
||||
template <typename PointType, typename LocatorType>
|
||||
VTKM_EXEC void operator()(const PointType& pointIn,
|
||||
const LocatorType& locator,
|
||||
vtkm::Id& cellId,
|
||||
PointType& parametric,
|
||||
bool& match) const
|
||||
{
|
||||
vtkm::Id calculated = CalculateCellId(pointIn);
|
||||
locator->FindCell(pointIn, cellId, parametric, (*this));
|
||||
match = (calculated == cellId);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Vec<vtkm::Id, 3> Dims;
|
||||
AxisPortalType xAxis;
|
||||
AxisPortalType yAxis;
|
||||
AxisPortalType zAxis;
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingCellLocatorRectilinearGrid
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
|
||||
void TestTest() const
|
||||
{
|
||||
vtkm::cont::DataSetBuilderRectilinear dsb;
|
||||
std::vector<vtkm::Float32> X(4), Y(3), Z(5);
|
||||
X[0] = 0.0f;
|
||||
X[1] = 1.0f;
|
||||
X[2] = 3.0f;
|
||||
X[3] = 4.0f;
|
||||
Y[0] = 0.0f;
|
||||
Y[1] = 1.0f;
|
||||
Y[2] = 2.0f;
|
||||
Z[0] = 0.0f;
|
||||
Z[1] = 1.0f;
|
||||
Z[2] = 3.0f;
|
||||
Z[3] = 5.0f;
|
||||
Z[4] = 6.0f;
|
||||
vtkm::cont::DataSet dataset = dsb.Create(X, Y, Z);
|
||||
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
|
||||
vtkm::cont::CoordinateSystem coords = dataset.GetCoordinateSystem();
|
||||
vtkm::cont::DynamicCellSet cellSet = dataset.GetCellSet();
|
||||
vtkm::Bounds bounds = coords.GetBounds();
|
||||
std::cout << "X bounds : " << bounds.X.Min << " to " << bounds.X.Max << std::endl;
|
||||
std::cout << "Y bounds : " << bounds.Y.Min << " to " << bounds.Y.Max << std::endl;
|
||||
std::cout << "Z bounds : " << bounds.Z.Min << " to " << bounds.Z.Max << std::endl;
|
||||
vtkm::Vec<vtkm::Id, 3> dims =
|
||||
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
|
||||
std::cout << "Dimensions of dataset : " << dims << std::endl;
|
||||
|
||||
// Generate some sample points.
|
||||
using PointType = vtkm::Vec<vtkm::FloatDefault, 3>;
|
||||
std::vector<PointType> pointsVec;
|
||||
std::default_random_engine dre;
|
||||
std::uniform_real_distribution<vtkm::Float32> xCoords(0.0f, 4.0f);
|
||||
std::uniform_real_distribution<vtkm::Float32> yCoords(0.0f, 2.0f);
|
||||
std::uniform_real_distribution<vtkm::Float32> zCoords(0.0f, 6.0f);
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(xCoords(dre), yCoords(dre), zCoords(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<PointType> points = vtkm::cont::make_ArrayHandle(pointsVec);
|
||||
|
||||
// Initialize locator
|
||||
vtkm::cont::CellLocatorRectilinearGrid locator;
|
||||
locator.SetCoordinates(coords);
|
||||
locator.SetCellSet(cellSet);
|
||||
locator.Update();
|
||||
|
||||
// Query the points using the locator.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
|
||||
vtkm::cont::ArrayHandle<PointType> parametric;
|
||||
vtkm::cont::ArrayHandle<bool> match;
|
||||
LocatorWorklet<DeviceAdapter> worklet(
|
||||
bounds, dims, coords.GetData().template Cast<RectilinearType>());
|
||||
|
||||
vtkm::worklet::DispatcherMapField<LocatorWorklet<DeviceAdapter>> dispatcher(worklet);
|
||||
dispatcher.SetDevice(DeviceAdapter());
|
||||
dispatcher.Invoke(points, locator, cellIds, parametric, match);
|
||||
|
||||
auto matchPortal = match.GetPortalConstControl();
|
||||
for (vtkm::Id index = 0; index < match.GetNumberOfValues(); index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(matchPortal.Get(index), "Points do not match");
|
||||
}
|
||||
std::cout << "Test finished successfully." << std::endl;
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
|
||||
this->TestTest();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
156
vtkm/cont/testing/TestingCellLocatorUniformGrid.h
Normal file
156
vtkm/cont/testing/TestingCellLocatorUniformGrid.h
Normal file
@ -0,0 +1,156 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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_cont_testing_TestingCellLocatorUniformGrid_h
|
||||
#define vtk_m_cont_testing_TestingCellLocatorUniformGrid_h
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <vtkm/cont/CellLocatorUniformGrid.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#include <vtkm/exec/CellLocatorUniformGrid.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
|
||||
class LocatorWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
LocatorWorklet(vtkm::Bounds& bounds_, vtkm::Vec<vtkm::Id, 3>& dims_)
|
||||
: bounds(bounds_)
|
||||
, dims(dims_)
|
||||
{
|
||||
}
|
||||
|
||||
using ControlSignature = void(FieldIn<> pointIn,
|
||||
ExecObject locator,
|
||||
FieldOut<> cellId,
|
||||
FieldOut<> parametric,
|
||||
FieldOut<> match);
|
||||
|
||||
using ExecutionSignature = void(_1, _2, _3, _4, _5);
|
||||
|
||||
template <typename PointType>
|
||||
VTKM_EXEC vtkm::Id CalculateCellId(const PointType& point) const
|
||||
{
|
||||
if (!bounds.Contains(point))
|
||||
return -1;
|
||||
vtkm::Vec<vtkm::Id, 3> logical;
|
||||
logical[0] = static_cast<vtkm::Id>(
|
||||
vtkm::Floor((point[0] / bounds.X.Length()) * static_cast<vtkm::FloatDefault>(dims[0] - 1)));
|
||||
logical[1] = static_cast<vtkm::Id>(
|
||||
vtkm::Floor((point[1] / bounds.Y.Length()) * static_cast<vtkm::FloatDefault>(dims[1] - 1)));
|
||||
logical[2] = static_cast<vtkm::Id>(
|
||||
vtkm::Floor((point[2] / bounds.Z.Length()) * static_cast<vtkm::FloatDefault>(dims[2] - 1)));
|
||||
return logical[2] * (dims[0] - 1) * (dims[1] - 1) + logical[1] * (dims[0] - 1) + logical[0];
|
||||
}
|
||||
|
||||
template <typename PointType, typename LocatorType>
|
||||
VTKM_EXEC void operator()(const PointType& pointIn,
|
||||
const LocatorType& locator,
|
||||
vtkm::Id& cellId,
|
||||
PointType& parametric,
|
||||
bool& match) const
|
||||
{
|
||||
vtkm::Id calculated = CalculateCellId(pointIn);
|
||||
locator->FindCell(pointIn, cellId, parametric, (*this));
|
||||
match = (calculated == cellId);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds bounds;
|
||||
vtkm::Vec<vtkm::Id, 3> dims;
|
||||
};
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class TestingCellLocatorUniformGrid
|
||||
{
|
||||
public:
|
||||
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||
|
||||
void TestTest() const
|
||||
{
|
||||
vtkm::cont::DataSet dataset = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1();
|
||||
vtkm::cont::CoordinateSystem coords = dataset.GetCoordinateSystem();
|
||||
vtkm::cont::DynamicCellSet cellSet = dataset.GetCellSet();
|
||||
|
||||
vtkm::Bounds bounds = coords.GetBounds();
|
||||
std::cout << "X bounds : " << bounds.X.Min << " to " << bounds.X.Max << std::endl;
|
||||
std::cout << "Y bounds : " << bounds.Y.Min << " to " << bounds.Y.Max << std::endl;
|
||||
std::cout << "Z bounds : " << bounds.Z.Min << " to " << bounds.Z.Max << std::endl;
|
||||
|
||||
using StructuredType = vtkm::cont::CellSetStructured<3>;
|
||||
vtkm::Vec<vtkm::Id, 3> dims =
|
||||
cellSet.Cast<StructuredType>().GetSchedulingRange(vtkm::TopologyElementTagPoint());
|
||||
std::cout << "Dimensions of dataset : " << dims << std::endl;
|
||||
|
||||
vtkm::cont::CellLocatorUniformGrid locator;
|
||||
locator.SetCoordinates(coords);
|
||||
locator.SetCellSet(cellSet);
|
||||
|
||||
locator.Update();
|
||||
|
||||
// Generate some sample points.
|
||||
using PointType = vtkm::Vec<vtkm::FloatDefault, 3>;
|
||||
std::vector<PointType> pointsVec;
|
||||
std::default_random_engine dre;
|
||||
std::uniform_real_distribution<vtkm::Float32> inBounds(0.0f, 4.0f);
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(inBounds(dre), inBounds(dre), inBounds(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
std::uniform_real_distribution<vtkm::Float32> outBounds(4.0f, 5.0f);
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
PointType point = vtkm::make_Vec(outBounds(dre), outBounds(dre), outBounds(dre));
|
||||
pointsVec.push_back(point);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle<PointType> points = vtkm::cont::make_ArrayHandle(pointsVec);
|
||||
// Query the points using the locators.
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
|
||||
vtkm::cont::ArrayHandle<PointType> parametric;
|
||||
vtkm::cont::ArrayHandle<bool> match;
|
||||
LocatorWorklet worklet(bounds, dims);
|
||||
vtkm::worklet::DispatcherMapField<LocatorWorklet> dispatcher(worklet);
|
||||
dispatcher.SetDevice(DeviceAdapter());
|
||||
dispatcher.Invoke(points, locator, cellIds, parametric, match);
|
||||
|
||||
auto matchPortal = match.GetPortalConstControl();
|
||||
for (vtkm::Id index = 0; index < match.GetNumberOfValues(); index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(matchPortal.Get(index), "Points do not match");
|
||||
}
|
||||
std::cout << "Test finished successfully." << std::endl;
|
||||
}
|
||||
|
||||
void operator()() const
|
||||
{
|
||||
vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
|
||||
this->TestTest();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -129,8 +129,8 @@ public:
|
||||
// { 0.0f, 0.0f, 0.0f }, { 10.0f, 10.0f, 10.0f }, { 5, 5, 5 });
|
||||
vtkm::cont::PointLocatorUniformGrid locator(
|
||||
{ 0.0f, 0.0f, 0.0f }, { 10.0f, 10.0f, 10.0f }, { 5, 5, 5 });
|
||||
locator.SetCoords(coord);
|
||||
locator.Build();
|
||||
locator.SetCoordinates(coord);
|
||||
locator.Update();
|
||||
|
||||
///// randomly generate testing points/////
|
||||
std::vector<vtkm::Vec<vtkm::Float32, 3>> qcVec;
|
||||
|
@ -28,6 +28,8 @@ set(headers
|
||||
CellInside.h
|
||||
CellInterpolate.h
|
||||
CellLocator.h
|
||||
CellLocatorUniformGrid.h
|
||||
CellLocatorRectilinearGrid.h
|
||||
CellMeasure.h
|
||||
ColorTable.h
|
||||
ConnectivityExplicit.h
|
||||
|
187
vtkm/exec/CellLocatorRectilinearGrid.h
Normal file
187
vtkm/exec/CellLocatorRectilinearGrid.h
Normal file
@ -0,0 +1,187 @@
|
||||
//============================================================================
|
||||
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2018 UT-Battelle, LLC.
|
||||
// Copyright 2018 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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 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>
|
||||
|
||||
#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
|
||||
{
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class CellLocatorRectilinearGrid : public vtkm::exec::CellLocator
|
||||
{
|
||||
private:
|
||||
using FromType = vtkm::TopologyElementTagPoint;
|
||||
using ToType = vtkm::TopologyElementTagCell;
|
||||
using CellSetPortal = vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
|
||||
vtkm::TopologyElementTagCell,
|
||||
3>;
|
||||
using AxisHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault>;
|
||||
using RectilinearType =
|
||||
vtkm::cont::ArrayHandleCartesianProduct<AxisHandle, AxisHandle, AxisHandle>;
|
||||
using AxisPortalType = typename AxisHandle::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
||||
using RectilinearPortalType =
|
||||
typename RectilinearType::template ExecutionTypes<DeviceAdapter>::PortalConst;
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
CellLocatorRectilinearGrid(const vtkm::Id planeSize,
|
||||
const vtkm::Id rowSize,
|
||||
const vtkm::cont::CellSetStructured<3>& cellSet,
|
||||
const RectilinearType& coords,
|
||||
DeviceAdapter)
|
||||
: PlaneSize(planeSize)
|
||||
, RowSize(rowSize)
|
||||
{
|
||||
CellSet = cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType());
|
||||
Coords = coords.PrepareForInput(DeviceAdapter());
|
||||
|
||||
PointDimensions = CellSet.GetPointDimensions();
|
||||
|
||||
AxisPortals[0] = Coords.GetFirstPortal();
|
||||
AxisPortals[1] = Coords.GetSecondPortal();
|
||||
AxisPortals[2] = Coords.GetThirdPortal();
|
||||
|
||||
MinPoint[0] =
|
||||
static_cast<vtkm::Float32>(coords.GetPortalConstControl().GetFirstPortal().Get(0));
|
||||
MinPoint[1] =
|
||||
static_cast<vtkm::Float32>(coords.GetPortalConstControl().GetSecondPortal().Get(0));
|
||||
MinPoint[2] =
|
||||
static_cast<vtkm::Float32>(coords.GetPortalConstControl().GetThirdPortal().Get(0));
|
||||
|
||||
MaxPoint[0] = static_cast<vtkm::Float32>(
|
||||
coords.GetPortalConstControl().GetFirstPortal().Get(PointDimensions[0] - 1));
|
||||
MaxPoint[1] = static_cast<vtkm::Float32>(
|
||||
coords.GetPortalConstControl().GetSecondPortal().Get(PointDimensions[1] - 1));
|
||||
MaxPoint[2] = static_cast<vtkm::Float32>(
|
||||
coords.GetPortalConstControl().GetThirdPortal().Get(PointDimensions[2] - 1));
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
inline bool IsInside(const vtkm::Vec<vtkm::Float32, 3>& point) const
|
||||
{
|
||||
bool inside = true;
|
||||
if (point[0] < MinPoint[0] || point[0] > MaxPoint[0])
|
||||
inside = false;
|
||||
if (point[1] < MinPoint[1] || point[1] > MaxPoint[1])
|
||||
inside = false;
|
||||
if (point[2] < MinPoint[2] || point[2] > MaxPoint[2])
|
||||
inside = false;
|
||||
return inside;
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void FindCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
|
||||
vtkm::Id& cellId,
|
||||
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
|
||||
const vtkm::exec::FunctorBase& worklet) const override
|
||||
{
|
||||
if (!IsInside(point))
|
||||
{
|
||||
cellId = -1;
|
||||
return;
|
||||
}
|
||||
// Get the Cell Id from the point.
|
||||
vtkm::Vec<vtkm::Id, 3> logicalCell(0, 0, 0);
|
||||
for (vtkm::Int32 dim = 0; dim < 3; ++dim)
|
||||
{
|
||||
//
|
||||
// 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])
|
||||
{
|
||||
logicalCell[dim] = PointDimensions[dim] - 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
vtkm::Float32 minVal = static_cast<vtkm::Float32>(AxisPortals[dim].Get(logicalCell[dim]));
|
||||
const vtkm::Id searchDir = (point[dim] - minVal >= 0.f) ? 1 : -1;
|
||||
vtkm::Float32 maxVal = static_cast<vtkm::Float32>(AxisPortals[dim].Get(logicalCell[dim] + 1));
|
||||
|
||||
while (!found)
|
||||
{
|
||||
if (point[dim] >= minVal && point[dim] < maxVal)
|
||||
{
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
logicalCell[dim] += searchDir;
|
||||
vtkm::Id nextCellId = searchDir == 1 ? logicalCell[dim] + 1 : logicalCell[dim];
|
||||
vtkm::Float32 next = static_cast<vtkm::Float32>(AxisPortals[dim].Get(nextCellId));
|
||||
if (searchDir == 1)
|
||||
{
|
||||
minVal = maxVal;
|
||||
maxVal = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxVal = minVal;
|
||||
minVal = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the actual cellId, from the logical cell index of the cell
|
||||
cellId = logicalCell[2] * PlaneSize + logicalCell[1] * RowSize + logicalCell[0];
|
||||
|
||||
bool success = false;
|
||||
using IndicesType = typename CellSetPortal::IndicesType;
|
||||
IndicesType cellPointIndices = CellSet.GetIndices(cellId);
|
||||
vtkm::VecFromPortalPermute<IndicesType, RectilinearPortalType> cellPoints(&cellPointIndices,
|
||||
Coords);
|
||||
auto cellShape = CellSet.GetCellShape(cellId);
|
||||
// Get Parametric Coordinates from the cell, for the point.
|
||||
parametric = vtkm::exec::WorldCoordinatesToParametricCoordinates(
|
||||
cellPoints, point, cellShape, success, worklet);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Id PlaneSize;
|
||||
vtkm::Id RowSize;
|
||||
|
||||
CellSetPortal CellSet;
|
||||
RectilinearPortalType Coords;
|
||||
AxisPortalType AxisPortals[3];
|
||||
vtkm::Id3 PointDimensions;
|
||||
vtkm::Vec<vtkm::Float32, 3> MinPoint;
|
||||
vtkm::Vec<vtkm::Float32, 3> MaxPoint;
|
||||
};
|
||||
} //namespace exec
|
||||
} //namespace vtkm
|
||||
|
||||
#endif //vtkm_exec_celllocatorrectilineargrid_h
|
113
vtkm/exec/CellLocatorUniformGrid.h
Normal file
113
vtkm/exec/CellLocatorUniformGrid.h
Normal file
@ -0,0 +1,113 @@
|
||||
//============================================================================
|
||||
// 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 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2019 UT-Battelle, LLC.
|
||||
// Copyright 2019 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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 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
|
||||
{
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class CellLocatorUniformGrid : public vtkm::exec::CellLocator
|
||||
{
|
||||
private:
|
||||
using FromType = vtkm::TopologyElementTagPoint;
|
||||
using ToType = vtkm::TopologyElementTagCell;
|
||||
using CellSetPortal = vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
|
||||
vtkm::TopologyElementTagCell,
|
||||
3>;
|
||||
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
|
||||
DeviceAdapter>::PortalConst;
|
||||
|
||||
public:
|
||||
VTKM_CONT
|
||||
CellLocatorUniformGrid(const vtkm::Bounds& bounds,
|
||||
const vtkm::Vec<vtkm::FloatDefault, 3> rangeTransform,
|
||||
const vtkm::Id planeSize,
|
||||
const vtkm::Id rowSize,
|
||||
const vtkm::cont::CellSetStructured<3>& cellSet,
|
||||
const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
|
||||
DeviceAdapter)
|
||||
: Bounds(bounds)
|
||||
, RangeTransform(rangeTransform)
|
||||
, PlaneSize(planeSize)
|
||||
, RowSize(rowSize)
|
||||
{
|
||||
CellSet = cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType());
|
||||
Coords = coords.PrepareForInput(DeviceAdapter());
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void FindCell(const vtkm::Vec<vtkm::FloatDefault, 3>& point,
|
||||
vtkm::Id& cellId,
|
||||
vtkm::Vec<vtkm::FloatDefault, 3>& parametric,
|
||||
const vtkm::exec::FunctorBase& worklet) const override
|
||||
{
|
||||
if (!Bounds.Contains(point))
|
||||
{
|
||||
cellId = -1;
|
||||
return;
|
||||
}
|
||||
// Get the Cell Id from the point.
|
||||
vtkm::Vec<vtkm::Id, 3> logicalCell;
|
||||
logicalCell[0] =
|
||||
static_cast<vtkm::Id>(vtkm::Floor((point[0] - Bounds.X.Min) * RangeTransform[0]));
|
||||
logicalCell[1] =
|
||||
static_cast<vtkm::Id>(vtkm::Floor((point[1] - Bounds.Y.Min) * RangeTransform[1]));
|
||||
logicalCell[2] =
|
||||
static_cast<vtkm::Id>(vtkm::Floor((point[2] - Bounds.Z.Min) * RangeTransform[2]));
|
||||
// Get the actual cellId, from the logical cell index of the cell
|
||||
cellId = logicalCell[2] * PlaneSize + logicalCell[1] * RowSize + logicalCell[0];
|
||||
|
||||
bool success = false;
|
||||
using IndicesType = typename CellSetPortal::IndicesType;
|
||||
IndicesType cellPointIndices = CellSet.GetIndices(cellId);
|
||||
vtkm::VecFromPortalPermute<IndicesType, CoordsPortal> cellPoints(&cellPointIndices, Coords);
|
||||
auto cellShape = CellSet.GetCellShape(cellId);
|
||||
// Get Parametric Coordinates from the cell, for the point.
|
||||
parametric = vtkm::exec::WorldCoordinatesToParametricCoordinates(
|
||||
cellPoints, point, cellShape, success, worklet);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Bounds Bounds;
|
||||
vtkm::Vec<vtkm::FloatDefault, 3> RangeTransform;
|
||||
vtkm::Id PlaneSize;
|
||||
vtkm::Id RowSize;
|
||||
CellSetPortal CellSet;
|
||||
CoordsPortal Coords;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif //vtkm_exec_celllocatoruniformgrid_h
|
Loading…
Reference in New Issue
Block a user