VTK-m  2.1
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 
144  ShapesReadPortal() const;
145 
146  VTKM_CONT vtkm::UInt8 GetCellShape(vtkm::Id cellid) const override;
147 
148  template <vtkm::IdComponent NumIndices>
149  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, NumIndices>& ids) const;
150 
151  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const;
152 
157  VTKM_CONT void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen);
158 
162  template <typename IdVecType>
163  VTKM_CONT void AddCell(vtkm::UInt8 cellType, vtkm::IdComponent numVertices, const IdVecType& ids);
164 
166  VTKM_CONT void CompleteAddingCells(vtkm::Id numPoints);
167 
172  VTKM_CONT
173  void Fill(vtkm::Id numPoints,
177 
178  template <typename VisitTopology, typename IncidentTopology>
179  using ExecConnectivityType =
181 
182  template <typename VisitTopology, typename IncidentTopology>
185  VisitTopology,
186  IncidentTopology,
187  vtkm::cont::Token&) const;
188 
189  template <typename VisitTopology, typename IncidentTopology>
191  GetShapesArray(VisitTopology, IncidentTopology) const;
192 
193  template <typename VisitTopology, typename IncidentTopology>
194  VTKM_CONT const typename ConnectivityChooser<VisitTopology,
195  IncidentTopology>::ConnectivityArrayType&
196  GetConnectivityArray(VisitTopology, IncidentTopology) const;
197 
198  template <typename VisitTopology, typename IncidentTopology>
200  GetOffsetsArray(VisitTopology, IncidentTopology) const;
201 
202  template <typename VisitTopology, typename IncidentTopology>
204  GetNumIndicesArray(VisitTopology, IncidentTopology) const;
205 
206  template <typename VisitTopology, typename IncidentTopology>
207  VTKM_CONT bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
208  {
209  return this->HasConnectivityImpl(visit, incident);
210  }
211 
212  // Can be used to reset a connectivity table, mostly useful for benchmarking.
213  template <typename VisitTopology, typename IncidentTopology>
214  VTKM_CONT void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
215  {
216  this->ResetConnectivityImpl(visit, incident);
217  }
218 
219 protected:
223  {
224  VTKM_ASSERT(this->Data->CellPointIds.ElementsValid);
225  // no-op
226  }
227 
231  {
232  detail::BuildReverseConnectivity(this->Data->CellPointIds.Connectivity,
233  this->Data->CellPointIds.Offsets,
234  this->Data->NumberOfPoints,
235  this->Data->PointCellIds,
236  device);
237  }
238 
241  {
242  return this->Data->CellPointIds.ElementsValid;
243  }
244 
247  {
248  return this->Data->PointCellIds.ElementsValid;
249  }
250 
252  {
253  // Reset entire cell set
254  this->Data->CellPointIds = CellPointIdsType{};
255  this->Data->PointCellIds = PointCellIdsType{};
256  this->Data->ConnectivityAdded = -1;
257  this->Data->NumberOfCellsAdded = -1;
258  this->Data->NumberOfPoints = 0;
259  }
260 
262  {
263  this->Data->PointCellIds = PointCellIdsType{};
264  }
265 
266  // Store internals in a shared pointer so shallow copies stay consistent.
267  // See #2268.
268  struct Internals
269  {
272 
273  // These are used in the AddCell and related methods to incrementally add
274  // cells. They need to be protected as subclasses of CellSetExplicit
275  // need to set these values when implementing Fill()
279 
280  VTKM_CONT
282  : ConnectivityAdded(-1)
283  , NumberOfCellsAdded(-1)
284  , NumberOfPoints(0)
285  {
286  }
287  };
288 
289  std::shared_ptr<Internals> Data;
290 
291 private:
292  VTKM_CONT
295  {
296  return this->Data->CellPointIds;
297  }
298 
299  VTKM_CONT
302  {
303  return this->Data->CellPointIds;
304  }
305 
306  VTKM_CONT
309  {
310  return this->Data->PointCellIds;
311  }
312 
313  VTKM_CONT
316  {
317  return this->Data->PointCellIds;
318  }
319 };
320 
321 namespace detail
322 {
323 
324 template <typename Storage1, typename Storage2, typename Storage3>
325 struct CellSetExplicitConnectivityChooser<vtkm::cont::CellSetExplicit<Storage1, Storage2, Storage3>,
328 {
329  using ConnectivityType =
330  vtkm::cont::internal::ConnectivityExplicitInternals<Storage1, Storage2, Storage3>;
331 };
332 
333 template <typename CellSetType>
334 struct CellSetExplicitConnectivityChooser<CellSetType,
335  vtkm::TopologyElementTagPoint,
337 {
338  //only specify the shape type as it will be constant as everything
339  //is a vertex. otherwise use the defaults.
340  using ConnectivityType = vtkm::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit;
341 };
342 
343 } // namespace detail
344 
347 #ifndef vtk_m_cont_CellSetExplicit_cxx
348 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<>; // default
349 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<
352  typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag>; // CellSetSingleType base
353 #endif
354 }
356 } // namespace vtkm::cont
357 
358 //=============================================================================
359 // Specializations of serialization related classes
361 namespace vtkm
362 {
363 namespace cont
364 {
365 
366 template <typename SST, typename CST, typename OST>
367 struct SerializableTypeString<vtkm::cont::CellSetExplicit<SST, CST, OST>>
368 {
369  static VTKM_CONT const std::string& Get()
370  {
371  static std::string name = "CS_Explicit<" +
372  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::UInt8, SST>>::Get() + "_ST," +
373  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, CST>>::Get() + "_ST," +
374  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, OST>>::Get() + "_ST>";
375 
376  return name;
377  }
378 };
379 }
380 } // vtkm::cont
381 
382 namespace mangled_diy_namespace
383 {
384 
385 template <typename SST, typename CST, typename OST>
386 struct Serialization<vtkm::cont::CellSetExplicit<SST, CST, OST>>
387 {
388 private:
390 
391 public:
392  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
393  {
394  vtkmdiy::save(bb, cs.GetNumberOfPoints());
395  vtkmdiy::save(
396  bb, cs.GetShapesArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
397  vtkmdiy::save(
398  bb, cs.GetConnectivityArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
399  vtkmdiy::save(
400  bb, cs.GetOffsetsArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
401  }
402 
403  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
404  {
405  vtkm::Id numberOfPoints = 0;
406  vtkmdiy::load(bb, numberOfPoints);
408  vtkmdiy::load(bb, shapes);
410  vtkmdiy::load(bb, connectivity);
412  vtkmdiy::load(bb, offsets);
413 
414  cs = Type{};
415  cs.Fill(numberOfPoints, shapes, connectivity, offsets);
416  }
417 };
418 
419 } // diy
421 
422 #ifndef vtk_m_cont_CellSetExplicit_hxx
423 #include <vtkm/cont/CellSetExplicit.hxx>
424 #endif //vtk_m_cont_CellSetExplicit_hxx
425 
426 #endif //vtk_m_cont_CellSetExplicit_h
vtkm::cont::CellSetExplicit::GetConnectivity
const PointCellIdsType & GetConnectivity(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:307
vtkm::cont::CellSetExplicit::GetConnectivity
const CellPointIdsType & GetConnectivity(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:293
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:278
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:270
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:300
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:214
vtkm::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(vtkm::cont::DeviceAdapterId, vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:220
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:314
ArrayHandleConstant.h
CellShape.h
vtkm::cont::ArrayHandle::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:311
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:180
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:245
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:277
vtkm::cont::CellSetExplicit::BuildConnectivity
void BuildConnectivity(vtkm::cont::DeviceAdapterId device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:228
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
Definition: ConnectivityExplicit.h:24
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:289
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:261
ArrayGetValues.h
vtkm::cont::CellSetExplicit::HasConnectivity
bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
Definition: CellSetExplicit.h:207
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:271
vtkm::cont::CellSetExplicit::Internals::Internals
Internals()
Definition: CellSetExplicit.h:281
vtkm::cont::CellSetExplicit::Internals::ConnectivityAdded
vtkm::Id ConnectivityAdded
Definition: CellSetExplicit.h:276
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:239
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
vtkm::cont::CellSetExplicit::Internals
Definition: CellSetExplicit.h:268
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
vtkm::cont::CellSetExplicit::ResetConnectivityImpl
void ResetConnectivityImpl(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint)
Definition: CellSetExplicit.h:251
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:127
ArrayHandleOffsetsToNumComponents.h
TopologyElementTag.h