10 #ifndef vtk_m_cont_ArrayHandleXGCCoordinates_h
11 #define vtk_m_cont_ArrayHandleXGCCoordinates_h
26 template <
typename PortalType>
33 ArrayPortalXGCCoordinates()
35 , NumberOfPointsPerPlane(0)
37 , NumberOfPlanesOwned(0)
39 , UseCylindrical(false){};
43 ArrayPortalXGCCoordinates(
const PortalType& p,
47 bool cylindrical =
false)
49 , NumberOfPlanes(numOfPlanes)
50 , NumberOfPlanesOwned(numOfPlanesOwned)
51 , PlaneStartId(planeStartId)
52 , UseCylindrical(cylindrical)
54 this->NumberOfPointsPerPlane = this->Portal.GetNumberOfValues() / 2;
61 return (this->NumberOfPointsPerPlane *
static_cast<vtkm::Id>(NumberOfPlanesOwned));
68 const vtkm::Id realIdx = ((index * 2) % this->Portal.GetNumberOfValues()) / 2;
69 const vtkm::Id whichPlane = (index * 2) / this->Portal.GetNumberOfValues() + this->PlaneStartId;
77 using CompType =
typename ValueType::ComponentType;
79 const vtkm::Id realIdx = (index[0] * 2);
80 const vtkm::Id whichPlane = index[1];
81 const auto phi =
static_cast<CompType
>(whichPlane * (vtkm::TwoPi() / this->NumberOfPlanes));
83 auto r = this->Portal.Get(realIdx);
84 auto z = this->Portal.Get(realIdx + 1);
85 if (this->UseCylindrical)
87 return ValueType(r, phi, z);
99 using CompType =
typename ValueType::ComponentType;
102 for (
int j = 0; j < 2; ++j)
105 static_cast<CompType
>(index.Planes[j] * (vtkm::TwoPi() / this->NumberOfPlanes));
106 for (
int i = 0; i < 3; ++i)
108 const vtkm::Id realIdx = index.PointIds[j][i] * 2;
109 auto r = this->Portal.Get(realIdx);
110 auto z = this->Portal.Get(realIdx + 1);
111 result[3 * j + i] = this->UseCylindrical
112 ? ValueType(r, phi, z)
143 struct XGCCoordinatesMetaData
148 bool UseCylindrical =
false;
150 XGCCoordinatesMetaData() =
default;
152 XGCCoordinatesMetaData(
vtkm::Id numberOfPlanes,
156 : NumberOfPlanes(numberOfPlanes)
157 , NumberOfPlanesOwned(numberOfPlanesOwned)
158 , PlaneStartId(planeStartId)
159 , UseCylindrical(useCylindrical)
167 template <
typename T>
168 class XGCCoordinatesStorageImpl
170 using SourceStorage = Storage<T, StorageTagBasic>;
171 using MetaData = XGCCoordinatesMetaData;
173 static MetaData& GetMetaData(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
175 return buffers[0].GetMetaData<MetaData>();
179 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> SourceBuffers(
180 const std::vector<vtkm::cont::internal::Buffer>& buffers)
182 return std::vector<vtkm::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
186 using ReadPortalType =
187 vtkm::internal::ArrayPortalXGCCoordinates<typename SourceStorage::ReadPortalType>;
190 const std::vector<vtkm::cont::internal::Buffer>& buffers)
192 return GetNumberOfValuesPerPlane(buffers) * GetNumberOfPlanesOwned(buffers);
196 const std::vector<vtkm::cont::internal::Buffer>& buffers)
198 return SourceStorage::GetNumberOfValues(SourceBuffers(buffers)) / 2;
202 const std::vector<vtkm::cont::internal::Buffer>& buffers)
204 return GetMetaData(buffers).NumberOfPlanes;
208 const std::vector<vtkm::cont::internal::Buffer>& buffers)
210 return GetMetaData(buffers).NumberOfPlanesOwned;
214 const std::vector<vtkm::cont::internal::Buffer>& buffers)
216 return GetMetaData(buffers).PlaneStartId;
219 VTKM_CONT static bool GetUseCylindrical(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
221 return GetMetaData(buffers).UseCylindrical;
224 VTKM_CONT static ReadPortalType CreateReadPortal(
225 const std::vector<vtkm::cont::internal::Buffer>& buffers,
229 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
230 GetNumberOfPlanes(buffers),
231 GetNumberOfPlanesOwned(buffers),
232 GetPlaneStartId(buffers),
233 GetUseCylindrical(buffers));
236 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
243 return vtkm::cont::internal::CreateBuffers(
244 MetaData(numberOfPlanes, numberOfPlanesOwned, planeStartId, useCylindrical), array);
247 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
253 const std::vector<vtkm::cont::internal::Buffer>& buffers)
263 :
public detail::XGCCoordinatesStorageImpl<vtkm::Float32>
272 :
public detail::XGCCoordinatesStorageImpl<vtkm::Float64>
281 template <
typename T>
295 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
316 return StorageType::GetNumberOfPlanes(this->GetBuffers());
321 return StorageType::GetNumberOfPlanesOwned(this->GetBuffers());
326 return StorageType::GetPlaneStartId(this->GetBuffers());
331 return StorageType::GetUseCylindrical(this->GetBuffers());
336 return StorageType::GetNumberOfValuesPerPlane(this->GetBuffers());
341 return StorageType::GetArrayHandle(this->GetBuffers());
345 template <
typename T>
353 if (numberOfPlanes == -1)
355 numberOfPlanes = numberOfPlanesOwned;
358 arrHandle, numberOfPlanes, numberOfPlanesOwned, planeStartId, cylindrical);
361 template <
typename T>
371 if (numberOfPlanes == -1)
373 numberOfPlanes = numberOfPlanesOwned;
383 template <
typename T>
385 const std::vector<T>& array,
394 if (numberOfPlanes == -1)
396 numberOfPlanes = numberOfPlanesOwned;
398 return make_ArrayHandleXGCCoordinates<T>(&array.front(),
399 static_cast<vtkm::Id>(array.size()),
424 template <
typename T>
425 struct SerializableTypeString<
vtkm::cont::ArrayHandleXGCCoordinates<T>>
434 template <
typename T>
435 struct SerializableTypeString<
436 vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, vtkm::cont::StorageTagXGCCoordinates>>
437 : SerializableTypeString<vtkm::cont::ArrayHandleXGCCoordinates<T>>
446 template <
typename T>
447 struct Serialization<
vtkm::cont::ArrayHandleXGCCoordinates<T>>
454 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
457 vtkmdiy::save(bb, ah.GetNumberOfPlanes());
458 vtkmdiy::save(bb, ah.GetNumberOfPlanesOwned());
459 vtkmdiy::save(bb, ah.GetPlaneStartId());
460 vtkmdiy::save(bb, ah.GetUseCylindrical());
461 vtkmdiy::save(bb, ah.GetArray());
479 array, numberOfPlanes, numberOfPlanesOwned, planeStartId, isCylindrical);
483 template <
typename T>
484 struct Serialization<
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, vtkm::cont::StorageTagXGCCoordinates>>
485 : Serialization<vtkm::cont::ArrayHandleXGCCoordinates<T>>