CoordinateSystem.h 8.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
//============================================================================
//  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

23 24
#include <vtkm/Bounds.h>

25
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
26
#include <vtkm/cont/ArrayHandleCompositeVector.h>
27
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
28
#include <vtkm/cont/Field.h>
29

30 31 32 33 34 35 36 37 38 39
#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

40 41 42
namespace vtkm {
namespace cont {

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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

59 60 61 62 63 64 65 66
/// \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::ListTagJoin<
        VTKM_DEFAULT_STORAGE_LIST_TAG,
67
    vtkm::ListTagBase<vtkm::cont::ArrayHandleUniformPointCoordinates::StorageTag,
68 69 70 71 72 73
                      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 > >
74 75 76 77 78 79 80
{ };

typedef vtkm::cont::DynamicArrayHandleBase<
    VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG,
    VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG>
  DynamicArrayHandleCoordinateSystem;

81
class CoordinateSystem : public vtkm::cont::Field
82
{
83 84
  typedef vtkm::cont::Field Superclass;

85
public:
86 87 88
  VTKM_CONT_EXPORT
  CoordinateSystem(std::string name,
                   const vtkm::cont::DynamicArrayHandle &data)
89
    : Superclass(name, ASSOC_POINTS, data) {  }
90

91
  template<typename T, typename Storage>
92
  VTKM_CONT_EXPORT
93 94
  CoordinateSystem(std::string name,
                   const ArrayHandle<T, Storage> &data)
95
    : Superclass(name, ASSOC_POINTS, data) {  }
96

97
  template<typename T>
98
  VTKM_CONT_EXPORT
99 100
  CoordinateSystem(std::string name,
                   const std::vector<T> &data)
101
    : Superclass(name, ASSOC_POINTS, data) {  }
102

103
  template<typename T>
104
  VTKM_CONT_EXPORT
105 106 107
  CoordinateSystem(std::string name,
                   const T *data,
                   vtkm::Id numberOfValues)
108
    : Superclass(name, ASSOC_POINTS, data, numberOfValues) {  }
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

  /// This constructor of coordinate system sets up a regular grid of points.
  ///
  VTKM_CONT_EXPORT
  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_EXPORT
  vtkm::cont::DynamicArrayHandleCoordinateSystem GetData() const
  {
    return vtkm::cont::DynamicArrayHandleCoordinateSystem(
          this->Superclass::GetData());
  }

  VTKM_CONT_EXPORT
  vtkm::cont::DynamicArrayHandleCoordinateSystem GetData()
  {
    return vtkm::cont::DynamicArrayHandleCoordinateSystem(
          this->Superclass::GetData());
  }

139
  template<typename DeviceAdapterTag>
140
  VTKM_CONT_EXPORT
141
  void GetRange(vtkm::Range *range, DeviceAdapterTag) const
142
  {
143 144
    this->Superclass::GetRange(
          range,
145
          DeviceAdapterTag(),
146
          VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(),
147 148 149 150 151
          VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }

  template<typename DeviceAdapterTag, typename TypeList>
  VTKM_CONT_EXPORT
152
  void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList) const
153
  {
154 155
    this->Superclass::GetRange(
          range,
156
          DeviceAdapterTag(),
157 158 159 160
          TypeList(),
          VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }

161 162
  template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
  VTKM_CONT_EXPORT
163
  void GetRange(vtkm::Range *range, DeviceAdapterTag, TypeList, StorageList) const
164
  {
165 166
    this->Superclass::GetRange(
          range,
167 168 169 170 171
          DeviceAdapterTag(),
          TypeList(),
          StorageList());
  }

172 173
  template<typename DeviceAdapterTag>
  VTKM_CONT_EXPORT
174
  const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag) const
175
  {
176
    return this->Superclass::GetRange(
177 178 179 180 181
          DeviceAdapterTag(),
          VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(),
          VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }

182
  template<typename DeviceAdapterTag, typename TypeList>
183
  VTKM_CONT_EXPORT
184 185
  const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag,
                                                       TypeList) const
186
  {
187
    return this->Superclass::GetRange(
188
          DeviceAdapterTag(),
189
          TypeList(),
190 191
          VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }
192

193 194
  template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
  VTKM_CONT_EXPORT
195 196 197
  const vtkm::cont::ArrayHandle<vtkm::Range>& GetRange(DeviceAdapterTag,
                                                       TypeList,
                                                       StorageList) const
198
  {
199
    return this->Superclass::GetRange(
200 201 202 203 204
          DeviceAdapterTag(),
          TypeList(),
          StorageList());
  }

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  template<typename DeviceAdapterTag>
  VTKM_CONT_EXPORT
  vtkm::Bounds GetBounds(DeviceAdapterTag) const
  {
    VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);

    return this->GetBounds(DeviceAdapterTag(),
                           VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(),
                           VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }

  template<typename DeviceAdapterTag, typename TypeList>
  VTKM_CONT_EXPORT
  vtkm::Bounds GetBounds(DeviceAdapterTag, TypeList) const
  {
    VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
    VTKM_IS_LIST_TAG(TypeList);

    return this->GetBounds(DeviceAdapterTag(),
                           TypeList(),
                           VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
  }

  template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
  VTKM_CONT_EXPORT
  vtkm::Bounds GetBounds(DeviceAdapterTag, TypeList, StorageList) const
  {
    VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
    VTKM_IS_LIST_TAG(TypeList);
    VTKM_IS_LIST_TAG(StorageList);

    vtkm::cont::ArrayHandle<vtkm::Range> ranges =
        this->GetRange(DeviceAdapterTag(), 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));
  }
248 249


250
  VTKM_CONT_EXPORT
251
  virtual void PrintSummary(std::ostream &out) const
252
  {
253
    out << "    Coordinate System ";
254
    this->Superclass::PrintSummary(out);
255
  }
256 257 258 259 260 261
};

} // namespace cont
} // namespace vtkm


262
#endif //vtk_m_cont_CoordinateSystem_h
263 264