mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Following what was done with ArrayRangeCompute, the GetRange and GetBounds methods are embedded into the vtkm_cont library for the most common type lists. Also, and probably more importantly, the device adapter is no longer one of the arguments for either of these methods. It is no longer needed as ArrayRangeCompute no longer needs it.
256 lines
7.7 KiB
C++
256 lines
7.7 KiB
C++
//============================================================================
|
|
// 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 2015 Sandia Corporation.
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
// Copyright 2015 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_CoordinateSystem_h
|
|
#define vtk_m_cont_CoordinateSystem_h
|
|
|
|
#include <vtkm/Bounds.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
|
#include <vtkm/cont/ArrayHandleCompositeVector.h>
|
|
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
|
|
#include <vtkm/cont/Field.h>
|
|
|
|
#ifndef VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG
|
|
#define VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG \
|
|
::vtkm::TypeListTagFieldVec3
|
|
#endif
|
|
|
|
#ifndef VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG
|
|
#define VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG \
|
|
::vtkm::cont::StorageListTagCoordinateSystemDefault
|
|
#endif
|
|
|
|
namespace vtkm {
|
|
namespace cont {
|
|
|
|
namespace detail {
|
|
|
|
typedef vtkm::cont::ArrayHandleCompositeVectorType<
|
|
vtkm::cont::ArrayHandle<vtkm::Float32>,
|
|
vtkm::cont::ArrayHandle<vtkm::Float32>,
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> >::type
|
|
ArrayHandleCompositeVectorFloat32_3Default;
|
|
|
|
typedef vtkm::cont::ArrayHandleCompositeVectorType<
|
|
vtkm::cont::ArrayHandle<vtkm::Float64>,
|
|
vtkm::cont::ArrayHandle<vtkm::Float64>,
|
|
vtkm::cont::ArrayHandle<vtkm::Float64> >::type
|
|
ArrayHandleCompositeVectorFloat64_3Default;
|
|
|
|
} // namespace detail
|
|
|
|
/// \brief Default storage list for CoordinateSystem arrays.
|
|
///
|
|
/// \c VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG is set to this value
|
|
/// by default (unless it is defined before including VTK-m headers.
|
|
///
|
|
struct StorageListTagCoordinateSystemDefault
|
|
: vtkm::ListTagBase<
|
|
vtkm::cont::StorageTagBasic,
|
|
vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag,
|
|
detail::ArrayHandleCompositeVectorFloat32_3Default::StorageTag,
|
|
detail::ArrayHandleCompositeVectorFloat64_3Default::StorageTag,
|
|
vtkm::cont::ArrayHandleCartesianProduct<
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
|
|
vtkm::cont::ArrayHandle<vtkm::FloatDefault> >::StorageTag >
|
|
{ };
|
|
|
|
typedef vtkm::cont::DynamicArrayHandleBase<
|
|
VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG,
|
|
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG>
|
|
DynamicArrayHandleCoordinateSystem;
|
|
|
|
class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field
|
|
{
|
|
typedef vtkm::cont::Field Superclass;
|
|
|
|
public:
|
|
VTKM_CONT
|
|
CoordinateSystem() : Superclass() { }
|
|
|
|
VTKM_CONT
|
|
CoordinateSystem(std::string name,
|
|
const vtkm::cont::DynamicArrayHandle &data)
|
|
: Superclass(name, ASSOC_POINTS, data) { }
|
|
|
|
template<typename T, typename Storage>
|
|
VTKM_CONT
|
|
CoordinateSystem(std::string name,
|
|
const ArrayHandle<T, Storage> &data)
|
|
: Superclass(name, ASSOC_POINTS, data) { }
|
|
|
|
template<typename T>
|
|
VTKM_CONT
|
|
CoordinateSystem(std::string name,
|
|
const std::vector<T> &data)
|
|
: Superclass(name, ASSOC_POINTS, data) { }
|
|
|
|
template<typename T>
|
|
VTKM_CONT
|
|
CoordinateSystem(std::string name,
|
|
const T *data,
|
|
vtkm::Id numberOfValues)
|
|
: Superclass(name, ASSOC_POINTS, data, numberOfValues) { }
|
|
|
|
/// This constructor of coordinate system sets up a regular grid of points.
|
|
///
|
|
VTKM_CONT
|
|
CoordinateSystem(std::string name,
|
|
vtkm::Id3 dimensions,
|
|
vtkm::Vec<vtkm::FloatDefault,3> origin
|
|
= vtkm::Vec<vtkm::FloatDefault,3>(0.0f, 0.0f, 0.0f),
|
|
vtkm::Vec<vtkm::FloatDefault,3> spacing
|
|
= vtkm::Vec<vtkm::FloatDefault,3>(1.0f, 1.0f, 1.0f))
|
|
: Superclass(name,
|
|
ASSOC_POINTS,
|
|
vtkm::cont::DynamicArrayHandle(
|
|
vtkm::cont::ArrayHandleUniformPointCoordinates(dimensions, origin, spacing)))
|
|
{ }
|
|
|
|
VTKM_CONT
|
|
CoordinateSystem &operator=(const vtkm::cont::CoordinateSystem &src) = default;
|
|
|
|
VTKM_CONT
|
|
vtkm::cont::DynamicArrayHandleCoordinateSystem GetData() const
|
|
{
|
|
return vtkm::cont::DynamicArrayHandleCoordinateSystem(
|
|
this->Superclass::GetData());
|
|
}
|
|
|
|
VTKM_CONT
|
|
vtkm::cont::DynamicArrayHandleCoordinateSystem GetData()
|
|
{
|
|
return vtkm::cont::DynamicArrayHandleCoordinateSystem(
|
|
this->Superclass::GetData());
|
|
}
|
|
|
|
VTKM_CONT
|
|
void GetRange(vtkm::Range *range) const;
|
|
|
|
template<typename TypeList>
|
|
VTKM_CONT
|
|
void GetRange(vtkm::Range *range, TypeList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
|
|
this->Superclass::GetRange(
|
|
range,
|
|
TypeList(),
|
|
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
|
|
}
|
|
|
|
template<typename TypeList, typename StorageList>
|
|
VTKM_CONT
|
|
void GetRange(vtkm::Range *range, TypeList, StorageList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
VTKM_IS_LIST_TAG(StorageList);
|
|
|
|
this->Superclass::GetRange(
|
|
range,
|
|
TypeList(),
|
|
StorageList());
|
|
}
|
|
|
|
VTKM_CONT
|
|
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange() const;
|
|
|
|
template<typename TypeList>
|
|
VTKM_CONT
|
|
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(TypeList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
|
|
return this->Superclass::GetRange(
|
|
TypeList(),
|
|
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
|
|
}
|
|
|
|
template<typename TypeList, typename StorageList>
|
|
VTKM_CONT
|
|
const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(TypeList,
|
|
StorageList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
VTKM_IS_LIST_TAG(StorageList);
|
|
|
|
return this->Superclass::GetRange(
|
|
TypeList(),
|
|
StorageList());
|
|
}
|
|
|
|
VTKM_CONT
|
|
vtkm::Bounds GetBounds() const;
|
|
|
|
template<typename TypeList>
|
|
VTKM_CONT
|
|
vtkm::Bounds GetBounds(TypeList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
|
|
return this->GetBounds(TypeList(),
|
|
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
|
|
}
|
|
|
|
template<typename TypeList, typename StorageList>
|
|
VTKM_CONT
|
|
vtkm::Bounds GetBounds(TypeList, StorageList) const
|
|
{
|
|
VTKM_IS_LIST_TAG(TypeList);
|
|
VTKM_IS_LIST_TAG(StorageList);
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Range> ranges =
|
|
this->GetRange(TypeList(), StorageList());
|
|
|
|
VTKM_ASSERT(ranges.GetNumberOfValues() == 3);
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Range>::PortalConstControl rangePortal =
|
|
ranges.GetPortalConstControl();
|
|
|
|
return vtkm::Bounds(rangePortal.Get(0),
|
|
rangePortal.Get(1),
|
|
rangePortal.Get(2));
|
|
}
|
|
|
|
virtual void PrintSummary(std::ostream &out) const;
|
|
};
|
|
|
|
template<typename Functor>
|
|
void CastAndCall(const vtkm::cont::CoordinateSystem& coords, const Functor &f)
|
|
{
|
|
coords.GetData().CastAndCall(f);
|
|
}
|
|
|
|
namespace internal {
|
|
|
|
template<>
|
|
struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
|
|
{
|
|
typedef vtkm::cont::internal::DynamicTransformTagCastAndCall DynamicTag;
|
|
};
|
|
|
|
} // namespace internal
|
|
} // namespace cont
|
|
} // namespace vtkm
|
|
|
|
|
|
#endif //vtk_m_cont_CoordinateSystem_h
|