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>&)
196 const std::vector<vtkm::cont::internal::Buffer>& buffers)
198 return GetNumberOfValuesPerPlane(buffers) * GetNumberOfPlanesOwned(buffers);
202 const std::vector<vtkm::cont::internal::Buffer>& buffers)
204 return SourceStorage::GetNumberOfValues(SourceBuffers(buffers)) / 2;
208 const std::vector<vtkm::cont::internal::Buffer>& buffers)
210 return GetMetaData(buffers).NumberOfPlanes;
214 const std::vector<vtkm::cont::internal::Buffer>& buffers)
216 return GetMetaData(buffers).NumberOfPlanesOwned;
220 const std::vector<vtkm::cont::internal::Buffer>& buffers)
222 return GetMetaData(buffers).PlaneStartId;
225 VTKM_CONT static bool GetUseCylindrical(
const std::vector<vtkm::cont::internal::Buffer>& buffers)
227 return GetMetaData(buffers).UseCylindrical;
230 VTKM_CONT static ReadPortalType CreateReadPortal(
231 const std::vector<vtkm::cont::internal::Buffer>& buffers,
235 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
236 GetNumberOfPlanes(buffers),
237 GetNumberOfPlanesOwned(buffers),
238 GetPlaneStartId(buffers),
239 GetUseCylindrical(buffers));
242 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers(
249 return vtkm::cont::internal::CreateBuffers(
250 MetaData(numberOfPlanes, numberOfPlanesOwned, planeStartId, useCylindrical), array);
253 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
259 const std::vector<vtkm::cont::internal::Buffer>& buffers)
269 :
public detail::XGCCoordinatesStorageImpl<vtkm::Float32>
278 :
public detail::XGCCoordinatesStorageImpl<vtkm::Float64>
287 template <
typename T>
318 return StorageType::GetNumberOfPlanes(this->GetBuffers());
323 return StorageType::GetNumberOfPlanesOwned(this->GetBuffers());
328 return StorageType::GetPlaneStartId(this->GetBuffers());
333 return StorageType::GetUseCylindrical(this->GetBuffers());
338 return StorageType::GetNumberOfValuesPerPlane(this->GetBuffers());
343 return StorageType::GetArrayHandle(this->GetBuffers());
347 template <
typename T>
355 if (numberOfPlanes == -1)
357 numberOfPlanes = numberOfPlanesOwned;
360 arrHandle, numberOfPlanes, numberOfPlanesOwned, planeStartId, cylindrical);
363 template <
typename T>
373 if (numberOfPlanes == -1)
375 numberOfPlanes = numberOfPlanesOwned;
385 template <
typename T>
387 const std::vector<T>& array,
396 if (numberOfPlanes == -1)
398 numberOfPlanes = numberOfPlanesOwned;
400 return make_ArrayHandleXGCCoordinates<T>(&array.front(),
401 static_cast<vtkm::Id>(array.size()),
426 template <
typename T>
427 struct SerializableTypeString<
vtkm::cont::ArrayHandleXGCCoordinates<T>>
436 template <
typename T>
437 struct SerializableTypeString<
438 vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, vtkm::cont::StorageTagXGCCoordinates>>
439 : SerializableTypeString<vtkm::cont::ArrayHandleXGCCoordinates<T>>
448 template <
typename T>
449 struct Serialization<
vtkm::cont::ArrayHandleXGCCoordinates<T>>
456 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
459 vtkmdiy::save(bb, ah.GetNumberOfPlanes());
460 vtkmdiy::save(bb, ah.GetNumberOfPlanesOwned());
461 vtkmdiy::save(bb, ah.GetPlaneStartId());
462 vtkmdiy::save(bb, ah.GetUseCylindrical());
463 vtkmdiy::save(bb, ah.GetArray());
481 array, numberOfPlanes, numberOfPlanesOwned, planeStartId, isCylindrical);
485 template <
typename T>
486 struct Serialization<
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, vtkm::cont::StorageTagXGCCoordinates>>
487 : Serialization<vtkm::cont::ArrayHandleXGCCoordinates<T>>