VTK-m  1.5
CoordinateSystem.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_CoordinateSystem_h
11 #define vtk_m_cont_CoordinateSystem_h
12 
13 #include <vtkm/Bounds.h>
14 #include <vtkm/Deprecated.h>
15 
17 #include <vtkm/cont/CastAndCall.h>
18 #include <vtkm/cont/Field.h>
19 
20 #ifndef VTKM_NO_DEPRECATED_VIRTUAL
22 #endif
23 
24 namespace vtkm
25 {
26 namespace cont
27 {
28 
29 #ifndef VTKM_NO_DEPRECATED_VIRTUAL
30 namespace detail
31 {
32 
33 // CoordinateSystem::GetData used to return an ArrayHandleVirtualCoordinates.
34 // That behavior is deprecated, and CoordianteSystem::GetData now returns a
35 // VariantArrayHandle similar (although slightly different than) its superclass.
36 // This wrapper class supports the old deprecated behavior until it is no longer
37 // supported. Once the behavior is removed (probably when
38 // ArrayHandleVirtualCoordinates is removed), then this class should be removed.
39 class VTKM_ALWAYS_EXPORT CoordDataDepWrapper
40  : public vtkm::cont::VariantArrayHandleBase<vtkm::TypeListFieldVec3>
41 {
43 
45  VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates ToArray() const;
47 
48 public:
49  using Superclass::Superclass;
50 
51  // Make the return also behave as ArrayHandleVirtualCoordiantes
53 
54  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
55  operator vtkm::cont::ArrayHandleVirtualCoordinates() const
56  {
57  return this->ToArray();
58  }
59 
60  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
61  operator vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagVirtual>() const
62  {
63  return this->ToArray();
64  }
65 
66  using ValueType VTKM_DEPRECATED(1.6,
67  "CoordinateSystem::GetData() now returns a VariantArrayHandle.") =
69 
70  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
71  ArrayHandleVirtualCoordinates::ReadPortalType ReadPortal() const
72  {
73  return this->ToArray().ReadPortal();
74  }
75 
76  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
77  ArrayHandleVirtualCoordinates::WritePortalType WritePortal() const
78  {
79  return this->ToArray().WritePortal();
80  }
81 
82  template <typename Device>
83  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
84  typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::PortalConst
85  PrepareForInput(Device device, vtkm::cont::Token& token) const
86  {
87  return this->ToArray().PrepareForInput(device, token);
88  }
89 
90  template <typename Device>
91  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
92  typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::Portal
93  PrepareForInPlace(Device device, vtkm::cont::Token& token) const
94  {
95  return this->ToArray().PrepareForInPlace(device, token);
96  }
97 
98  template <typename Device>
99  VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
100  typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::Portal
101  PrepareForOutput(vtkm::Id numberOfValues, Device device, vtkm::cont::Token& token) const
102  {
103  return this->ToArray().PrepareForOutput(numberOfValues, device, token);
104  }
105 
107 };
108 
109 } // namespace detail
110 
113  1.6,
114  "CoordinateSystem::GetData() now returns a "
115  "VariantArrayHandle.") inline void printSummary_ArrayHandle(const detail::CoordDataDepWrapper&
116  array,
117  std::ostream& out,
118  bool full = false)
119 {
120  vtkm::cont::ArrayHandleVirtualCoordinates coordArray = array;
121  vtkm::cont::printSummary_ArrayHandle(coordArray, out, full);
122 }
124 #endif //VTKM_NO_DEPRECATED_VIRTUAL
125 
126 class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field
127 {
130 
131 public:
132  VTKM_CONT
134 
135  VTKM_CONT CoordinateSystem(std::string name, const vtkm::cont::VariantArrayHandleCommon& data);
136 
137  template <typename T, typename Storage>
138  VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle<T, Storage>& data)
139  : Superclass(name, Association::POINTS, data)
140  {
141  }
142 
145  VTKM_CONT
146  CoordinateSystem(std::string name,
147  vtkm::Id3 dimensions,
148  vtkm::Vec3f origin = vtkm::Vec3f(0.0f, 0.0f, 0.0f),
149  vtkm::Vec3f spacing = vtkm::Vec3f(1.0f, 1.0f, 1.0f));
150 
151  VTKM_CONT
152  vtkm::Id GetNumberOfPoints() const { return this->GetNumberOfValues(); }
153 
154 #ifndef VTKM_NO_DEPRECATED_VIRTUAL
155  VTKM_CONT detail::CoordDataDepWrapper GetData() const;
156 #else
158 #endif
159 
160 private:
161 #ifdef VTKM_USE_DOUBLE_PRECISION
162  using FloatNonDefault = vtkm::Float32;
163 #else
165 #endif
167 
169  {
170  template <typename S>
171  using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle<vtkm::Vec3f, S>;
172 
173  template <typename S>
175  };
176 
178  {
179  template <typename S>
180  using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle<Vec3f_nd, S>;
181 
182  template <typename S>
183  using Transform =
185  };
186 
193 
194 public:
195  using MultiplexerArrayType = //
198 
205  VTKM_CONT MultiplexerArrayType GetDataAsMultiplexer() const;
206 
207  VTKM_CONT
208  void GetRange(vtkm::Range* range) const
209  {
210  this->Superclass::GetRange(range, CoordinatesTypeList());
211  }
212 
213  VTKM_CONT
215  {
217  this->GetRange(&range[0]);
218  return range;
219  }
220 
221  VTKM_CONT
223  {
224  return this->Superclass::GetRange(CoordinatesTypeList());
225  }
226 
227  VTKM_CONT
229  {
230  vtkm::Range ranges[3];
231  this->GetRange(ranges);
232  return vtkm::Bounds(ranges[0], ranges[1], ranges[2]);
233  }
234 
235  virtual void PrintSummary(std::ostream& out) const override;
236 
240  {
241  this->Superclass::ReleaseResourcesExecution();
242  this->GetData().ReleaseResourcesExecution();
243  }
244 };
245 
246 template <typename Functor, typename... Args>
247 void CastAndCall(const vtkm::cont::CoordinateSystem& coords, Functor&& f, Args&&... args)
248 {
249  CastAndCall(coords.GetData(), std::forward<Functor>(f), std::forward<Args>(args)...);
250 }
251 
252 template <typename T>
254  const std::vector<T>& data,
256 {
258 }
259 
260 template <typename T>
262  const T* data,
263  vtkm::Id numberOfValues,
265 {
266  return vtkm::cont::CoordinateSystem(name,
267  vtkm::cont::make_ArrayHandle(data, numberOfValues, copy));
268 }
269 
270 namespace internal
271 {
272 
273 template <>
274 struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
275 {
276  using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
277 };
278 
279 #ifndef VTKM_NO_DEPRECATED_VIRTUAL
280 template <>
281 struct DynamicTransformTraits<vtkm::cont::detail::CoordDataDepWrapper>
282 {
283  using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
284 };
285 #endif //VTKM_NO_DEPRECATED_VIRTUAL
286 
287 
288 } // namespace internal
289 } // namespace cont
290 } // namespace vtkm
291 
292 //=============================================================================
293 // Specializations of serialization related classes
295 namespace mangled_diy_namespace
296 {
297 
298 #ifndef VTKM_NO_DEPRECATED_VIRTUAL
299 template <>
300 struct Serialization<vtkm::cont::detail::CoordDataDepWrapper>
301  : public Serialization<
302  vtkm::cont::VariantArrayHandleBase<vtkm::List<vtkm::Vec3f_32, vtkm::Vec3f_64>>>
303 {
304 };
305 #endif //VTKM_NO_DEPRECATED_VIRTUAL
306 
307 template <>
308 struct Serialization<vtkm::cont::CoordinateSystem>
309 {
310  using CoordinatesTypeList = vtkm::List<vtkm::Vec3f_32, vtkm::Vec3f_64>;
311 
312  static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::CoordinateSystem& cs)
313  {
314  vtkmdiy::save(bb, cs.GetName());
315  vtkmdiy::save(
317  }
318 
319  static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::CoordinateSystem& cs)
320  {
321  std::string name;
322  vtkmdiy::load(bb, name);
324  vtkmdiy::load(bb, data);
325  cs = vtkm::cont::CoordinateSystem(name, data);
326  }
327 };
328 
329 } // diy
331 
332 #endif //vtk_m_cont_CoordinateSystem_h
vtkm::cont::make_CoordinateSystem
vtkm::cont::CoordinateSystem make_CoordinateSystem(std::string name, const std::vector< T > &data, vtkm::CopyFlag copy=vtkm::CopyFlag::Off)
Definition: CoordinateSystem.h:253
vtkm::cont::CoordinateSystem::ArraysFloatNonDefault
vtkm::ListTransform< vtkm::ListRemoveIf< VTKM_DEFAULT_STORAGE_LIST, StorageToArrayNonDefault::IsInvalid >, StorageToArrayNonDefault::Transform > ArraysFloatNonDefault
Definition: CoordinateSystem.h:192
vtkm::cont::make_ArrayHandle
VTKM_CONT vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:196
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:281
vtkm::cont::VariantArrayHandleCommon
VariantArrayHandle superclass holding common operations.
Definition: VariantArrayHandle.h:107
vtkm::cont::VTKM_DEPRECATED
struct VTKM_DEPRECATED(1.6, "Use vtkm::ColorSpace.") ColorSpace
Definition: cont/ColorTable.h:36
vtkm
Groups connected points that have the same field value.
Definition: Algorithms.h:23
vtkm::cont::CoordinateSystem::GetRangeAsArrayHandle
VTKM_CONT vtkm::cont::ArrayHandle< vtkm::Range > GetRangeAsArrayHandle() const
Definition: CoordinateSystem.h:222
ArrayHandleCast.h
vtkm::cont::CoordinateSystem::ArraysFloatDefault
vtkm::ListTransform< vtkm::ListRemoveIf< VTKM_DEFAULT_STORAGE_LIST, StorageToArrayDefault::IsInvalid >, StorageToArrayDefault::Transform > ArraysFloatDefault
Definition: CoordinateSystem.h:189
vtkm::cont::CoordinateSystem::GetRange
VTKM_CONT vtkm::Vec< vtkm::Range, 3 > GetRange() const
Definition: CoordinateSystem.h:214
vtkm::cont::printSummary_ArrayHandle
VTKM_NEVER_EXPORT VTKM_CONT void printSummary_ArrayHandle(const vtkm::cont::ArrayHandle< T, StorageT > &array, std::ostream &out, bool full=false)
Definition: ArrayHandle.h:1496
vtkm::cont::Field::Association
Association
Definition: cont/Field.h:50
vtkm::cont::VariantArrayHandleBase
Holds an array handle without having to specify template parameters.
Definition: ArrayCopy.h:162
ArrayHandleVirtualCoordinates.h
mangled_diy_namespace
Definition: Particle.h:279
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:189
vtkm::exec::arg::load
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
VTKM_DEPRECATED_SUPPRESS_END
#define VTKM_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:123
vtkm::cont::CoordinateSystem::ReleaseResourcesExecution
VTKM_CONT void ReleaseResourcesExecution() override
Releases any resources being used in the execution environment (that are not being shared by the cont...
Definition: CoordinateSystem.h:239
vtkm::cont::CoordinateSystem::StorageToArrayNonDefault
Definition: CoordinateSystem.h:177
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:126
vtkm::cont::CoordinateSystem::FloatNonDefault
vtkm::Float64 FloatNonDefault
Definition: CoordinateSystem.h:164
vtkm::cont::CoordinateSystem::GetNumberOfPoints
VTKM_CONT vtkm::Id GetNumberOfPoints() const
Definition: CoordinateSystem.h:152
vtkm::cont::CoordinateSystem::MultiplexerArrayType
vtkm::cont::ArrayHandleMultiplexerFromList< vtkm::ListAppend< ArraysFloatDefault, ArraysFloatNonDefault > > MultiplexerArrayType
Definition: CoordinateSystem.h:197
vtkm::cont::CoordinateSystem::StorageToArrayNonDefault::IsInvalid
vtkm::cont::internal::IsInvalidArrayHandle< Vec3f_nd, S > IsInvalid
Definition: CoordinateSystem.h:180
Bounds.h
vtkm::cont::CoordinateSystem::StorageToArrayDefault
Definition: CoordinateSystem.h:168
CastAndCall.h
vtkm::ListAppend
brigand::append< internal::AsList< Lists >... > ListAppend
Concatinates a set of lists into a single list.
Definition: List.h:399
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: cont/Field.h:47
vtkm::cont::CoordinateSystem::GetBounds
VTKM_CONT vtkm::Bounds GetBounds() const
Definition: CoordinateSystem.h:228
vtkm::cont::CoordinateSystem::GetData
VTKM_CONT detail::CoordDataDepWrapper GetData() const
vtkm::ListRemoveIf
brigand::remove_if< internal::AsList< List >, brigand::bind< Predicate, brigand::_1 > > ListRemoveIf
Takes an existing List and a predicate template that is applied to each type in the List.
Definition: List.h:502
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:50
vtkm::cont::ArrayHandleMultiplexerFromList
vtkm::ListApply< List, ArrayHandleMultiplexer > ArrayHandleMultiplexerFromList
Converts avtkm::List to an ArrayHandleMultiplexer
Definition: ArrayHandleMultiplexer.h:585
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
VTKM_DEPRECATED_SUPPRESS_BEGIN
#define VTKM_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:122
vtkm::Vec3f
vtkm::Vec< vtkm::FloatDefault, 3 > Vec3f
Vec3f corresponds to a 3-dimensional vector of floating point values.
Definition: Types.h:976
vtkm::Vec< vtkm::Id, 3 >
vtkm::CopyFlag::Off
@ Off
vtkm::cont::CoordinateSystem::CoordinateSystem
VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle< T, Storage > &data)
Definition: CoordinateSystem.h:138
vtkm::cont::ArrayHandleCast
Cast the values of an array to the specified type, on demand.
Definition: ArrayHandleCast.h:156
vtkm::cont::Field::GetName
const VTKM_CONT std::string & GetName() const
Definition: cont/Field.h:80
Deprecated.h
vtkm::Float32
float Float32
Definition: Types.h:154
Field.h
vtkm::List
Definition: List.h:21
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::CopyFlag
CopyFlag
Definition: Flags.h:16
vtkm::cont::CastAndCall
VTKM_DEPRECATED_SUPPRESS_BEGIN class VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6, "Virtual ArrayHandles are being phased out.") ArrayHandleVirtualCoordinates final void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates &coords, Functor &&f, Args &&... args)
ArrayHandleVirtualCoordinates is a specialization of ArrayHandle.
Definition: ArrayHandleVirtualCoordinates.h:52
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:85
vtkm::ListTransform
typename detail::ListTransformImpl< internal::AsList< List >, Transform >::type ListTransform
Constructs a list containing all types in a source list applied to a transform template.
Definition: List.h:486
vtkm::cont::CoordinateSystem::GetRange
VTKM_CONT void GetRange(vtkm::Range *range) const
Definition: CoordinateSystem.h:208
vtkm::cont::CoordinateSystem::StorageToArrayDefault::IsInvalid
vtkm::cont::internal::IsInvalidArrayHandle< vtkm::Vec3f, S > IsInvalid
Definition: CoordinateSystem.h:171
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:30