VTK-m  2.2
CellSetExplicit.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_CellSetExplicit_h
11 #define vtk_m_cont_CellSetExplicit_h
12 
13 #include <vtkm/CellShape.h>
20 #include <vtkm/cont/CellSet.h>
24 
26 
27 namespace vtkm
28 {
29 namespace cont
30 {
31 
32 namespace detail
33 {
34 
35 template <typename CellSetType, typename VisitTopology, typename IncidentTopology>
36 struct CellSetExplicitConnectivityChooser
37 {
38  using ConnectivityType = vtkm::cont::internal::ConnectivityExplicitInternals<>;
39 };
40 
41 // The connectivity generally used for the visit-points-with-cells connectivity.
42 // This type of connectivity does not have variable shape types, and since it is
43 // never really provided externally we can use the defaults for the other arrays.
44 using DefaultVisitPointsWithCellsConnectivityExplicit =
45  vtkm::cont::internal::ConnectivityExplicitInternals<
47 
48 VTKM_CONT_EXPORT void BuildReverseConnectivity(
49  const vtkm::cont::UnknownArrayHandle& connections,
50  const vtkm::cont::UnknownArrayHandle& offsets,
51  vtkm::Id numberOfPoints,
52  vtkm::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit& visitPointsWithCells,
54 
55 } // namespace detail
56 
57 #ifndef VTKM_DEFAULT_SHAPES_STORAGE_TAG
58 #define VTKM_DEFAULT_SHAPES_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
59 #endif
60 
61 #ifndef VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
62 #define VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
63 #endif
64 
65 #ifndef VTKM_DEFAULT_OFFSETS_STORAGE_TAG
66 #define VTKM_DEFAULT_OFFSETS_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
67 #endif
68 
73 template <typename ShapesStorageTag = VTKM_DEFAULT_SHAPES_STORAGE_TAG,
74  typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG,
75  typename OffsetsStorageTag = VTKM_DEFAULT_OFFSETS_STORAGE_TAG>
76 class VTKM_ALWAYS_EXPORT CellSetExplicit : public CellSet
77 {
79 
80  template <typename VisitTopology, typename IncidentTopology>
82  {
83  private:
84  using Chooser = typename detail::
85  CellSetExplicitConnectivityChooser<Thisclass, VisitTopology, IncidentTopology>;
86 
87  public:
88  using ConnectivityType = typename Chooser::ConnectivityType;
89  using ShapesArrayType = typename ConnectivityType::ShapesArrayType;
90  using ConnectivityArrayType = typename ConnectivityType::ConnectivityArrayType;
91  using OffsetsArrayType = typename ConnectivityType::OffsetsArrayType;
92 
94 
95  using ExecConnectivityType =
96  vtkm::exec::ConnectivityExplicit<typename ShapesArrayType::ReadPortalType,
97  typename ConnectivityArrayType::ReadPortalType,
98  typename OffsetsArrayType::ReadPortalType>;
99  };
100 
101  using ConnTypes =
103  using RConnTypes =
105 
108 
109 public:
111 
112  using ShapesArrayType = typename CellPointIdsType::ShapesArrayType;
113  using ConnectivityArrayType = typename CellPointIdsType::ConnectivityArrayType;
114  using OffsetsArrayType = typename CellPointIdsType::OffsetsArrayType;
116 
118  VTKM_CONT CellSetExplicit(const Thisclass& src);
119  VTKM_CONT CellSetExplicit(Thisclass&& src) noexcept;
120 
121  VTKM_CONT Thisclass& operator=(const Thisclass& src);
122  VTKM_CONT Thisclass& operator=(Thisclass&& src) noexcept;
123 
124  VTKM_CONT ~CellSetExplicit() override;
125 
126  VTKM_CONT vtkm::Id GetNumberOfCells() const override;
127  VTKM_CONT vtkm::Id GetNumberOfPoints() const override;
128  VTKM_CONT vtkm::Id GetNumberOfFaces() const override;
129  VTKM_CONT vtkm::Id GetNumberOfEdges() const override;
130  VTKM_CONT void PrintSummary(std::ostream& out) const override;
131 
132  VTKM_CONT void ReleaseResourcesExecution() override;
133 
134  VTKM_CONT std::shared_ptr<CellSet> NewInstance() const override;
135  VTKM_CONT void DeepCopy(const CellSet* src) override;
136 
137  VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const;
138  VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const;
139 
140  VTKM_CONT vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellid) const override;
141  VTKM_CONT void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override;
142 
147  ShapesReadPortal() const;
148 
149  VTKM_CONT vtkm::UInt8 GetCellShape(vtkm::Id cellid) const override;
150 
153  template <vtkm::IdComponent NumIndices>
154  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, NumIndices>& ids) const;
155 
157  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const;
158 
163  VTKM_CONT void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen);
164 
168  template <typename IdVecType>
169  VTKM_CONT void AddCell(vtkm::UInt8 cellType, vtkm::IdComponent numVertices, const IdVecType& ids);
170 
172  VTKM_CONT void CompleteAddingCells(vtkm::Id numPoints);
173 
178  VTKM_CONT
179  void Fill(vtkm::Id numPoints,
183 
184  template <typename VisitTopology, typename IncidentTopology>
185  using ExecConnectivityType =
187 
202  template <typename VisitTopology, typename IncidentTopology>
205  VisitTopology visitTopology,
206  IncidentTopology incidentTopology,
207  vtkm::cont::Token& token) const;
208 
215  template <typename VisitTopology, typename IncidentTopology>
217  GetShapesArray(VisitTopology, IncidentTopology) const;
218 
226  template <typename VisitTopology, typename IncidentTopology>
227  VTKM_CONT const typename ConnectivityChooser<VisitTopology,
228  IncidentTopology>::ConnectivityArrayType&
229  GetConnectivityArray(VisitTopology, IncidentTopology) const;
230 
238  template <typename VisitTopology, typename IncidentTopology>
240  GetOffsetsArray(VisitTopology, IncidentTopology) const;
241 
242  template <typename VisitTopology, typename IncidentTopology>
244  GetNumIndicesArray(VisitTopology, IncidentTopology) const;
245 
249  template <typename VisitTopology, typename IncidentTopology>
250  VTKM_CONT bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
251  {
252  return this->HasConnectivityImpl(visit, incident);
253  }
254 
255  // Can be used to reset a connectivity table, mostly useful for benchmarking.
256  template <typename VisitTopology, typename IncidentTopology>
257  VTKM_CONT void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
258  {
259  this->ResetConnectivityImpl(visit, incident);
260  }
261 
262 protected:
266  {
267  VTKM_ASSERT(this->Data->CellPointIds.ElementsValid);
268  // no-op
269  }
270 
274  {
275  detail::BuildReverseConnectivity(this->Data->CellPointIds.Connectivity,
276  this->Data->CellPointIds.Offsets,
277  this->Data->NumberOfPoints,
278  this->Data->PointCellIds,
279  device);
280  }
281 
284  {
285  return this->Data->CellPointIds.ElementsValid;
286  }
287 
290  {
291  return this->Data->PointCellIds.ElementsValid;
292  }
293 
295  {
296  // Reset entire cell set
297  this->Data->CellPointIds = CellPointIdsType{};
298  this->Data->PointCellIds = PointCellIdsType{};
299  this->Data->ConnectivityAdded = -1;
300  this->Data->NumberOfCellsAdded = -1;
301  this->Data->NumberOfPoints = 0;
302  }
303 
305  {
306  this->Data->PointCellIds = PointCellIdsType{};
307  }
308 
309  // Store internals in a shared pointer so shallow copies stay consistent.
310  // See #2268.
311  struct Internals
312  {
315 
316  // These are used in the AddCell and related methods to incrementally add
317  // cells. They need to be protected as subclasses of CellSetExplicit
318  // need to set these values when implementing Fill()
322 
323  VTKM_CONT
325  : ConnectivityAdded(-1)
326  , NumberOfCellsAdded(-1)
327  , NumberOfPoints(0)
328  {
329  }
330  };
331 
332  std::shared_ptr<Internals> Data;
333 
334 private:
335  VTKM_CONT
338  {
339  return this->Data->CellPointIds;
340  }
341 
342  VTKM_CONT
345  {
346  return this->Data->CellPointIds;
347  }
348 
349  VTKM_CONT
352  {
353  return this->Data->PointCellIds;
354  }
355 
356  VTKM_CONT
359  {
360  return this->Data->PointCellIds;
361  }
362 };
363 
364 namespace detail
365 {
366 
367 template <typename Storage1, typename Storage2, typename Storage3>
368 struct CellSetExplicitConnectivityChooser<vtkm::cont::CellSetExplicit<Storage1, Storage2, Storage3>,
371 {
372  using ConnectivityType =
373  vtkm::cont::internal::ConnectivityExplicitInternals<Storage1, Storage2, Storage3>;
374 };
375 
376 template <typename CellSetType>
377 struct CellSetExplicitConnectivityChooser<CellSetType,
378  vtkm::TopologyElementTagPoint,
380 {
381  //only specify the shape type as it will be constant as everything
382  //is a vertex. otherwise use the defaults.
383  using ConnectivityType = vtkm::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit;
384 };
385 
386 } // namespace detail
387 
390 #ifndef vtk_m_cont_CellSetExplicit_cxx
391 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<>; // default
392 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<
395  typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag>; // CellSetSingleType base
396 #endif
397 }
399 } // namespace vtkm::cont
400 
401 //=============================================================================
402 // Specializations of serialization related classes
404 namespace vtkm
405 {
406 namespace cont
407 {
408 
409 template <typename SST, typename CST, typename OST>
410 struct SerializableTypeString<vtkm::cont::CellSetExplicit<SST, CST, OST>>
411 {
412  static VTKM_CONT const std::string& Get()
413  {
414  static std::string name = "CS_Explicit<" +
415  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::UInt8, SST>>::Get() + "_ST," +
416  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, CST>>::Get() + "_ST," +
417  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, OST>>::Get() + "_ST>";
418 
419  return name;
420  }
421 };
422 }
423 } // vtkm::cont
424 
425 namespace mangled_diy_namespace
426 {
427 
428 template <typename SST, typename CST, typename OST>
429 struct Serialization<vtkm::cont::CellSetExplicit<SST, CST, OST>>
430 {
431 private:
433 
434 public:
435  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
436  {
437  vtkmdiy::save(bb, cs.GetNumberOfPoints());
438  vtkmdiy::save(
439  bb, cs.GetShapesArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
440  vtkmdiy::save(
441  bb, cs.GetConnectivityArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
442  vtkmdiy::save(
443  bb, cs.GetOffsetsArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
444  }
445 
446  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
447  {
448  vtkm::Id numberOfPoints = 0;
449  vtkmdiy::load(bb, numberOfPoints);
451  vtkmdiy::load(bb, shapes);
453  vtkmdiy::load(bb, connectivity);
455  vtkmdiy::load(bb, offsets);
456 
457  cs = Type{};
458  cs.Fill(numberOfPoints, shapes, connectivity, offsets);
459  }
460 };
461 
462 } // diy
464 
465 #ifndef vtk_m_cont_CellSetExplicit_hxx
466 #include <vtkm/cont/CellSetExplicit.hxx>
467 #endif //vtk_m_cont_CellSetExplicit_hxx
468 
469 #endif //vtk_m_cont_CellSetExplicit_h
vtkm::cont::CellSetExplicit::GetConnectivity
const PointCellIdsType & GetConnectivity(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:350
vtkm::cont::CellSetExplicit::GetConnectivity
const CellPointIdsType & GetConnectivity(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:336
vtkm::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:34
VTKM_DEFAULT_OFFSETS_STORAGE_TAG
#define VTKM_DEFAULT_OFFSETS_STORAGE_TAG
Definition: CellSetExplicit.h:66
vtkm::cont::CellSetExplicit::Internals::NumberOfPoints
vtkm::Id NumberOfPoints
Definition: CellSetExplicit.h:321
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::cont::CellSetExplicit::ConnectivityChooser
Definition: CellSetExplicit.h:81
vtkm::cont::CellSetExplicit::ShapesArrayType
typename CellPointIdsType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:112
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
ArrayHandleCast.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::CellSetExplicit::Internals::CellPointIds
CellPointIdsType CellPointIds
Definition: CellSetExplicit.h:313
vtkm::cont::CellSetExplicit::SchedulingRangeType
vtkm::Id SchedulingRangeType
Definition: CellSetExplicit.h:110
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::cont::CellSetExplicit::ConnectivityArrayType
typename CellPointIdsType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:113
vtkm::cont::CellSetExplicit::GetConnectivity
const CellPointIdsType & GetConnectivity(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint)
Definition: CellSetExplicit.h:343
vtkm::cont::ArrayHandleConstant::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleConstant.h:75
vtkm::cont::CellSetExplicit::ResetConnectivity
void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
Definition: CellSetExplicit.h:257
vtkm::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(vtkm::cont::DeviceAdapterId, vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:263
vtkm::cont::CellSetExplicit::ConnectivityChooser::ConnectivityType
typename Chooser::ConnectivityType ConnectivityType
Definition: CellSetExplicit.h:88
vtkm::cont::CellSetExplicit::CellPointIdsType
typename ConnTypes::ConnectivityType CellPointIdsType
Definition: CellSetExplicit.h:106
vtkm::cont::CellSetExplicit::GetConnectivity
const PointCellIdsType & GetConnectivity(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell)
Definition: CellSetExplicit.h:357
ArrayHandleConstant.h
CellShape.h
vtkm::cont::ArrayHandle::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
The type of portal used when accessing data in a read-only mode.
Definition: ArrayHandle.h:312
mangled_diy_namespace
Definition: Particle.h:351
vtkm::cont::CellSetExplicit::ConnectivityChooser::ShapesArrayType
typename ConnectivityType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:89
ConnectivityExplicit.h
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::cont::CellSetExplicit::ExecConnectivityType
typename ConnectivityChooser< VisitTopology, IncidentTopology >::ExecConnectivityType ExecConnectivityType
Definition: CellSetExplicit.h:186
vtkm::cont::CellSetExplicit::ConnectivityChooser::ConnectivityArrayType
typename ConnectivityType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:90
vtkm::cont::CellSetExplicit::HasConnectivityImpl
bool HasConnectivityImpl(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:288
UnknownArrayHandle.h
vtkm::cont::CellSetExplicit::NumIndicesArrayType
typename ConnTypes::NumIndicesArrayType NumIndicesArrayType
Definition: CellSetExplicit.h:115
vtkm::cont::CellSetExplicit::Internals::NumberOfCellsAdded
vtkm::Id NumberOfCellsAdded
Definition: CellSetExplicit.h:320
vtkm::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(vtkm::cont::DeviceAdapterId device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:271
vtkm::cont::CellSetExplicit::OffsetsArrayType
typename CellPointIdsType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:114
VTKM_CONT_EXPORT
#define VTKM_CONT_EXPORT
Definition: vtkm_cont_export.h:44
vtkm_cont_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::exec::ConnectivityExplicit
A class holding information about topology connections.
Definition: ConnectivityExplicit.h:29
CellSet.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::CellSet
Defines the topological structure of the data in a DataSet.
Definition: CellSet.h:28
vtkm::cont::CellSetExplicit::Data
std::shared_ptr< Internals > Data
Definition: CellSetExplicit.h:332
VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
#define VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
Definition: CellSetExplicit.h:62
vtkm::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
vtkm::cont::CellSetExplicit::ResetConnectivityImpl
void ResetConnectivityImpl(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell)
Definition: CellSetExplicit.h:304
ArrayGetValues.h
vtkm::cont::CellSetExplicit::HasConnectivity
bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
Returns whether the CellSetExplicit has information for the given visit and incident topology element...
Definition: CellSetExplicit.h:250
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
VTKM_CONT_TEMPLATE_EXPORT
#define VTKM_CONT_TEMPLATE_EXPORT
Definition: vtkm_cont_export.h:62
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::cont::CellSetExplicit::Internals::PointCellIds
PointCellIdsType PointCellIds
Definition: CellSetExplicit.h:314
vtkm::cont::CellSetExplicit::Internals::Internals
Internals()
Definition: CellSetExplicit.h:324
vtkm::cont::CellSetExplicit::Internals::ConnectivityAdded
vtkm::Id ConnectivityAdded
Definition: CellSetExplicit.h:319
ConnectivityExplicitInternals.h
vtkm::cont::CellSetExplicit::ConnectivityChooser::OffsetsArrayType
typename ConnectivityType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:91
vtkm::cont::CellSetExplicit
Defines an irregular collection of cells.
Definition: CastAndCall.h:36
VTKM_DEFAULT_SHAPES_STORAGE_TAG
#define VTKM_DEFAULT_SHAPES_STORAGE_TAG
Definition: CellSetExplicit.h:58
vtkm::cont::CellSetExplicit::PointCellIdsType
typename RConnTypes::ConnectivityType PointCellIdsType
Definition: CellSetExplicit.h:107
vtkm::cont::ArrayHandleOffsetsToNumComponents
An ArrayHandle that converts an array of offsets to an array of Vec sizes.
Definition: ArrayHandleOffsetsToNumComponents.h:135
ArrayHandleCounting.h
vtkm::cont::CellSetExplicit::HasConnectivityImpl
bool HasConnectivityImpl(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:282
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
vtkm::cont::CellSetExplicit::Internals
Definition: CellSetExplicit.h:311
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
vtkm::cont::CellSetExplicit::ResetConnectivityImpl
void ResetConnectivityImpl(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint)
Definition: CellSetExplicit.h:294
vtkm::cont::CellSetExplicit::ConnectivityChooser::Chooser
typename detail::CellSetExplicitConnectivityChooser< Thisclass, VisitTopology, IncidentTopology > Chooser
Definition: CellSetExplicit.h:85
vtkm::cont::ArrayHandleCounting::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleCounting.h:136
ArrayHandleOffsetsToNumComponents.h
TopologyElementTag.h