mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add implicit array for uniform grid point coordinates.
This commit is contained in:
parent
5cb4934279
commit
406e655910
@ -118,11 +118,13 @@ class ArrayHandleCounting
|
|||||||
> Superclass;
|
> Superclass;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
ArrayHandleCounting(CountingValueType startingValue, vtkm::Id length)
|
ArrayHandleCounting(CountingValueType startingValue, vtkm::Id length)
|
||||||
:Superclass(typename Superclass::PortalConstControl(startingValue, length))
|
:Superclass(typename Superclass::PortalConstControl(startingValue, length))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
ArrayHandleCounting():Superclass() {}
|
ArrayHandleCounting():Superclass() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
158
vtkm/cont/ArrayHandleUniformPointCoordinates.h
Normal file
158
vtkm/cont/ArrayHandleUniformPointCoordinates.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014. Los Alamos National Security
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// 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_ArrayHandleUniformPointCoordinates_h
|
||||||
|
#define vtk_m_cont_ArrayHandleUniformPointCoordinates_h
|
||||||
|
|
||||||
|
#include <vtkm/Extent.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/ArrayContainerControlImplicit.h>
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
||||||
|
|
||||||
|
namespace vtkm {
|
||||||
|
namespace cont {
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
/// \brief An implicit array port that computes point coordinates for a uniform
|
||||||
|
/// grid.
|
||||||
|
///
|
||||||
|
class ArrayPortalUniformPointCoordinates
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef vtkm::Vector3 ValueType;
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
ArrayPortalUniformPointCoordinates() : NumberOfValues(0) { }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
ArrayPortalUniformPointCoordinates(vtkm::Extent3 extent,
|
||||||
|
vtkm::Vector3 origin,
|
||||||
|
vtkm::Vector3 spacing)
|
||||||
|
: Extent(extent),
|
||||||
|
Dimensions(vtkm::ExtentPointDimensions(extent)),
|
||||||
|
NumberOfValues(vtkm::ExtentNumberOfPoints(extent)),
|
||||||
|
Origin(origin),
|
||||||
|
Spacing(spacing)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
ArrayPortalUniformPointCoordinates(
|
||||||
|
const ArrayPortalUniformPointCoordinates &src)
|
||||||
|
: Extent(src.Extent),
|
||||||
|
Dimensions(src.Dimensions),
|
||||||
|
NumberOfValues(src.NumberOfValues),
|
||||||
|
Origin(src.Origin),
|
||||||
|
Spacing(src.Spacing)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
ArrayPortalUniformPointCoordinates &
|
||||||
|
operator=(const ArrayPortalUniformPointCoordinates &src)
|
||||||
|
{
|
||||||
|
this->Extent = src.Extent;
|
||||||
|
this->Dimensions = src.Dimensions;
|
||||||
|
this->NumberOfValues = src.NumberOfValues;
|
||||||
|
this->Origin = src.Origin;
|
||||||
|
this->Spacing = src.Spacing;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
vtkm::Vector3 Get(vtkm::Id index) const {
|
||||||
|
return this->GetCoordinatesForTopologyIndex(
|
||||||
|
vtkm::ExtentPointFlatIndexToTopologyIndex(index, this->Extent));
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
vtkm::Id3 GetRange3() const { return this->Dimensions; }
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
vtkm::Vector3 Get(vtkm::Id3 index) const {
|
||||||
|
return this->GetCoordinatesForTopologyIndex(index + this->Extent.Min);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef vtkm::cont::internal::IteratorFromArrayPortal<
|
||||||
|
ArrayPortalUniformPointCoordinates> IteratorType;
|
||||||
|
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
|
IteratorType GetIteratorBegin() const {
|
||||||
|
return IteratorType(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
|
IteratorType GetIteratorEnd() const {
|
||||||
|
return IteratorType(*this, this->NumberOfValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
vtkm::Extent3 Extent;
|
||||||
|
vtkm::Id3 Dimensions;
|
||||||
|
vtkm::Id NumberOfValues;
|
||||||
|
vtkm::Vector3 Origin;
|
||||||
|
vtkm::Vector3 Spacing;
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT_EXPORT
|
||||||
|
vtkm::Vector3 GetCoordinatesForTopologyIndex(vtkm::Id3 ijk) const {
|
||||||
|
return vtkm::Vector3(this->Origin[0] + this->Spacing[0]*ijk[0],
|
||||||
|
this->Origin[1] + this->Spacing[1]*ijk[1],
|
||||||
|
this->Origin[2] + this->Spacing[2]*ijk[2]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/// ArrayHandleUniformPointCoordinates is a specialization of ArrayHandle. It
|
||||||
|
/// contains the information necessary to compute the point coordinates in a
|
||||||
|
/// uniform orthogonal grid (extent, origin, and spacing) and implicitly
|
||||||
|
/// computes these coordinates in its array portal.
|
||||||
|
///
|
||||||
|
class ArrayHandleUniformPointCoordinates
|
||||||
|
: public vtkm::cont::ArrayHandle<
|
||||||
|
vtkm::Vector3,
|
||||||
|
vtkm::cont::ArrayContainerControlTagImplicit<
|
||||||
|
internal::ArrayPortalUniformPointCoordinates> >
|
||||||
|
{
|
||||||
|
typedef vtkm::cont::ArrayHandle<
|
||||||
|
vtkm::Vector3,
|
||||||
|
vtkm::cont::ArrayContainerControlTagImplicit<
|
||||||
|
internal::ArrayPortalUniformPointCoordinates> > Superclass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
|
ArrayHandleUniformPointCoordinates() : Superclass() { }
|
||||||
|
|
||||||
|
VTKM_CONT_EXPORT
|
||||||
|
ArrayHandleUniformPointCoordinates(vtkm::Extent3 extent,
|
||||||
|
vtkm::Vector3 origin,
|
||||||
|
vtkm::Vector3 spacing)
|
||||||
|
: Superclass(
|
||||||
|
internal::ArrayPortalUniformPointCoordinates(extent, origin, spacing))
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
} // namespace vtkm::cont
|
||||||
|
|
||||||
|
#endif //vtk_+m_cont_ArrayHandleUniformPointCoordinates_h
|
@ -25,6 +25,8 @@ set(headers
|
|||||||
ArrayContainerControlBasic.h
|
ArrayContainerControlBasic.h
|
||||||
ArrayContainerControlImplicit.h
|
ArrayContainerControlImplicit.h
|
||||||
ArrayHandle.h
|
ArrayHandle.h
|
||||||
|
ArrayHandleCounting.h
|
||||||
|
ArrayHandleUniformPointCoordinates.h
|
||||||
ArrayPortal.h
|
ArrayPortal.h
|
||||||
Assert.h
|
Assert.h
|
||||||
DeviceAdapter.h
|
DeviceAdapter.h
|
||||||
|
@ -30,6 +30,7 @@ set(unit_tests
|
|||||||
UnitTestArrayContainerControlImplicit.cxx
|
UnitTestArrayContainerControlImplicit.cxx
|
||||||
UnitTestArrayHandle.cxx
|
UnitTestArrayHandle.cxx
|
||||||
UnitTestArrayHandleCounting.cxx
|
UnitTestArrayHandleCounting.cxx
|
||||||
|
UnitTestArrayHandleUniformPointCoordinates.cxx
|
||||||
UnitTestContTesting.cxx
|
UnitTestContTesting.cxx
|
||||||
UnitTestDeviceAdapterAlgorithmDependency.cxx
|
UnitTestDeviceAdapterAlgorithmDependency.cxx
|
||||||
UnitTestDeviceAdapterAlgorithmGeneral.cxx
|
UnitTestDeviceAdapterAlgorithmGeneral.cxx
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014. Los Alamos National Security
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// 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.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const vtkm::Id3 MIN_VALUES(-5, 8, 40);
|
||||||
|
const vtkm::Id3 MAX_VALUES(10, 25, 44);
|
||||||
|
const vtkm::Id3 POINT_DIMS(16, 18, 5);
|
||||||
|
const vtkm::Id NUM_POINTS = 1440;
|
||||||
|
|
||||||
|
const vtkm::Vector3 ORIGIN(30, -3, -14);
|
||||||
|
const vtkm::Vector3 SPACING(10, 1, 0.1);
|
||||||
|
const vtkm::Vector3 LOWER_LEFT(-20, 5, -10); // MIN_VALUES*SPACING + ORIGIN
|
||||||
|
|
||||||
|
void TestArrayHandleUniformPointCoordinates()
|
||||||
|
{
|
||||||
|
std::cout << "Creating ArrayHandleUniformPointCoordinates" << std::endl;
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleUniformPointCoordinates arrayHandle(
|
||||||
|
vtkm::Extent3(MIN_VALUES, MAX_VALUES), ORIGIN, SPACING);
|
||||||
|
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == NUM_POINTS,
|
||||||
|
"Array computed wrong number of points.");
|
||||||
|
|
||||||
|
std::cout << "Getting array portal." << std::endl;
|
||||||
|
vtkm::cont::internal::ArrayPortalUniformPointCoordinates portal =
|
||||||
|
arrayHandle.GetPortalConstControl();
|
||||||
|
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == NUM_POINTS,
|
||||||
|
"Portal has wrong number of points.");
|
||||||
|
VTKM_TEST_ASSERT(portal.GetRange3() == POINT_DIMS,
|
||||||
|
"Portal range is wrong.");
|
||||||
|
|
||||||
|
std::cout << "Checking computed values of portal." << std::endl;
|
||||||
|
vtkm::Vector3 expectedValue;
|
||||||
|
vtkm::Id flatIndex = 0;
|
||||||
|
vtkm::Id3 blockIndex;
|
||||||
|
expectedValue[2] = LOWER_LEFT[2];
|
||||||
|
for (blockIndex[2] = 0; blockIndex[2] < POINT_DIMS[2]; blockIndex[2]++)
|
||||||
|
{
|
||||||
|
expectedValue[1] = LOWER_LEFT[1];
|
||||||
|
for (blockIndex[1] = 0; blockIndex[1] < POINT_DIMS[1]; blockIndex[1]++)
|
||||||
|
{
|
||||||
|
expectedValue[0] = LOWER_LEFT[0];
|
||||||
|
for (blockIndex[0] = 0; blockIndex[0] < POINT_DIMS[0]; blockIndex[0]++)
|
||||||
|
{
|
||||||
|
VTKM_TEST_ASSERT(test_equal(expectedValue, portal.Get(flatIndex)),
|
||||||
|
"Got wrong value for flat index.");
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(test_equal(expectedValue, portal.Get(blockIndex)),
|
||||||
|
"Got wrong value for block index.");
|
||||||
|
|
||||||
|
flatIndex++;
|
||||||
|
expectedValue[0] += SPACING[0];
|
||||||
|
}
|
||||||
|
expectedValue[1] += SPACING[1];
|
||||||
|
}
|
||||||
|
expectedValue[2] += SPACING[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
int UnitTestArrayHandleUniformPointCoordinates(int, char *[])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(
|
||||||
|
TestArrayHandleUniformPointCoordinates);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user