VTK-m  2.0
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 
25 #include <vtkm/cont/vtkm_cont_export.h>
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 
69 template <typename ShapesStorageTag = VTKM_DEFAULT_SHAPES_STORAGE_TAG,
70  typename ConnectivityStorageTag = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG,
71  typename OffsetsStorageTag = VTKM_DEFAULT_OFFSETS_STORAGE_TAG>
72 class VTKM_ALWAYS_EXPORT CellSetExplicit : public CellSet
73 {
75 
76  template <typename VisitTopology, typename IncidentTopology>
78  {
79  private:
80  using Chooser = typename detail::
81  CellSetExplicitConnectivityChooser<Thisclass, VisitTopology, IncidentTopology>;
82 
83  public:
84  using ConnectivityType = typename Chooser::ConnectivityType;
85  using ShapesArrayType = typename ConnectivityType::ShapesArrayType;
86  using ConnectivityArrayType = typename ConnectivityType::ConnectivityArrayType;
87  using OffsetsArrayType = typename ConnectivityType::OffsetsArrayType;
88 
90 
91  using ExecConnectivityType =
92  vtkm::exec::ConnectivityExplicit<typename ShapesArrayType::ReadPortalType,
93  typename ConnectivityArrayType::ReadPortalType,
94  typename OffsetsArrayType::ReadPortalType>;
95  };
96 
97  using ConnTypes =
99  using RConnTypes =
101 
104 
105 public:
107 
108  using ShapesArrayType = typename CellPointIdsType::ShapesArrayType;
109  using ConnectivityArrayType = typename CellPointIdsType::ConnectivityArrayType;
110  using OffsetsArrayType = typename CellPointIdsType::OffsetsArrayType;
112 
114  VTKM_CONT CellSetExplicit(const Thisclass& src);
115  VTKM_CONT CellSetExplicit(Thisclass&& src) noexcept;
116 
117  VTKM_CONT Thisclass& operator=(const Thisclass& src);
118  VTKM_CONT Thisclass& operator=(Thisclass&& src) noexcept;
119 
120  VTKM_CONT virtual ~CellSetExplicit() override;
121 
122  VTKM_CONT vtkm::Id GetNumberOfCells() const override;
123  VTKM_CONT vtkm::Id GetNumberOfPoints() const override;
124  VTKM_CONT vtkm::Id GetNumberOfFaces() const override;
125  VTKM_CONT vtkm::Id GetNumberOfEdges() const override;
126  VTKM_CONT void PrintSummary(std::ostream& out) const override;
127 
128  VTKM_CONT void ReleaseResourcesExecution() override;
129 
130  VTKM_CONT std::shared_ptr<CellSet> NewInstance() const override;
131  VTKM_CONT void DeepCopy(const CellSet* src) override;
132 
133  VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagCell) const;
134  VTKM_CONT vtkm::Id GetSchedulingRange(vtkm::TopologyElementTagPoint) const;
135 
136  VTKM_CONT vtkm::IdComponent GetNumberOfPointsInCell(vtkm::Id cellid) const override;
137  VTKM_CONT void GetCellPointIds(vtkm::Id id, vtkm::Id* ptids) const override;
138 
140  ShapesReadPortal() const;
141 
142  VTKM_CONT vtkm::UInt8 GetCellShape(vtkm::Id cellid) const override;
143 
144  template <vtkm::IdComponent NumIndices>
145  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, NumIndices>& ids) const;
146 
147  VTKM_CONT void GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const;
148 
150  VTKM_CONT void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen);
151 
152  template <typename IdVecType>
153  VTKM_CONT void AddCell(vtkm::UInt8 cellType, vtkm::IdComponent numVertices, const IdVecType& ids);
154 
155  VTKM_CONT void CompleteAddingCells(vtkm::Id numPoints);
156 
160  VTKM_CONT
161  void Fill(vtkm::Id numPoints,
165 
166  template <typename VisitTopology, typename IncidentTopology>
167  using ExecConnectivityType =
169 
170  template <typename VisitTopology, typename IncidentTopology>
173  VisitTopology,
174  IncidentTopology,
175  vtkm::cont::Token&) const;
176 
177  template <typename VisitTopology, typename IncidentTopology>
179  GetShapesArray(VisitTopology, IncidentTopology) const;
180 
181  template <typename VisitTopology, typename IncidentTopology>
182  VTKM_CONT const typename ConnectivityChooser<VisitTopology,
183  IncidentTopology>::ConnectivityArrayType&
184  GetConnectivityArray(VisitTopology, IncidentTopology) const;
185 
186  template <typename VisitTopology, typename IncidentTopology>
188  GetOffsetsArray(VisitTopology, IncidentTopology) const;
189 
190  template <typename VisitTopology, typename IncidentTopology>
192  GetNumIndicesArray(VisitTopology, IncidentTopology) const;
193 
194  template <typename VisitTopology, typename IncidentTopology>
195  VTKM_CONT bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
196  {
197  return this->HasConnectivityImpl(visit, incident);
198  }
199 
200  // Can be used to reset a connectivity table, mostly useful for benchmarking.
201  template <typename VisitTopology, typename IncidentTopology>
202  VTKM_CONT void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
203  {
204  this->ResetConnectivityImpl(visit, incident);
205  }
206 
207 protected:
211  {
212  VTKM_ASSERT(this->Data->CellPointIds.ElementsValid);
213  // no-op
214  }
215 
219  {
220  detail::BuildReverseConnectivity(this->Data->CellPointIds.Connectivity,
221  this->Data->CellPointIds.Offsets,
222  this->Data->NumberOfPoints,
223  this->Data->PointCellIds,
224  device);
225  }
226 
229  {
230  return this->Data->CellPointIds.ElementsValid;
231  }
232 
235  {
236  return this->Data->PointCellIds.ElementsValid;
237  }
238 
240  {
241  // Reset entire cell set
242  this->Data->CellPointIds = CellPointIdsType{};
243  this->Data->PointCellIds = PointCellIdsType{};
244  this->Data->ConnectivityAdded = -1;
245  this->Data->NumberOfCellsAdded = -1;
246  this->Data->NumberOfPoints = 0;
247  }
248 
250  {
251  this->Data->PointCellIds = PointCellIdsType{};
252  }
253 
254  // Store internals in a shared pointer so shallow copies stay consistent.
255  // See #2268.
256  struct Internals
257  {
260 
261  // These are used in the AddCell and related methods to incrementally add
262  // cells. They need to be protected as subclasses of CellSetExplicit
263  // need to set these values when implementing Fill()
267 
268  VTKM_CONT
270  : ConnectivityAdded(-1)
271  , NumberOfCellsAdded(-1)
272  , NumberOfPoints(0)
273  {
274  }
275  };
276 
277  std::shared_ptr<Internals> Data;
278 
279 private:
280  VTKM_CONT
283  {
284  return this->Data->CellPointIds;
285  }
286 
287  VTKM_CONT
290  {
291  return this->Data->CellPointIds;
292  }
293 
294  VTKM_CONT
297  {
298  return this->Data->PointCellIds;
299  }
300 
301  VTKM_CONT
304  {
305  return this->Data->PointCellIds;
306  }
307 };
308 
309 namespace detail
310 {
311 
312 template <typename Storage1, typename Storage2, typename Storage3>
313 struct CellSetExplicitConnectivityChooser<vtkm::cont::CellSetExplicit<Storage1, Storage2, Storage3>,
316 {
317  using ConnectivityType =
318  vtkm::cont::internal::ConnectivityExplicitInternals<Storage1, Storage2, Storage3>;
319 };
320 
321 template <typename CellSetType>
322 struct CellSetExplicitConnectivityChooser<CellSetType,
323  vtkm::TopologyElementTagPoint,
325 {
326  //only specify the shape type as it will be constant as everything
327  //is a vertex. otherwise use the defaults.
328  using ConnectivityType = vtkm::cont::detail::DefaultVisitPointsWithCellsConnectivityExplicit;
329 };
330 
331 } // namespace detail
332 
335 #ifndef vtk_m_cont_CellSetExplicit_cxx
336 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<>; // default
337 extern template class VTKM_CONT_TEMPLATE_EXPORT CellSetExplicit<
340  typename vtkm::cont::ArrayHandleCounting<vtkm::Id>::StorageTag>; // CellSetSingleType base
341 #endif
342 }
344 } // namespace vtkm::cont
345 
346 //=============================================================================
347 // Specializations of serialization related classes
349 namespace vtkm
350 {
351 namespace cont
352 {
353 
354 template <typename SST, typename CST, typename OST>
355 struct SerializableTypeString<vtkm::cont::CellSetExplicit<SST, CST, OST>>
356 {
357  static VTKM_CONT const std::string& Get()
358  {
359  static std::string name = "CS_Explicit<" +
360  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::UInt8, SST>>::Get() + "_ST," +
361  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, CST>>::Get() + "_ST," +
362  SerializableTypeString<vtkm::cont::ArrayHandle<vtkm::Id, OST>>::Get() + "_ST>";
363 
364  return name;
365  }
366 };
367 }
368 } // vtkm::cont
369 
370 namespace mangled_diy_namespace
371 {
372 
373 template <typename SST, typename CST, typename OST>
374 struct Serialization<vtkm::cont::CellSetExplicit<SST, CST, OST>>
375 {
376 private:
378 
379 public:
380  static VTKM_CONT void save(BinaryBuffer& bb, const Type& cs)
381  {
382  vtkmdiy::save(bb, cs.GetNumberOfPoints());
383  vtkmdiy::save(
384  bb, cs.GetShapesArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
385  vtkmdiy::save(
386  bb, cs.GetConnectivityArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
387  vtkmdiy::save(
388  bb, cs.GetOffsetsArray(vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagPoint{}));
389  }
390 
391  static VTKM_CONT void load(BinaryBuffer& bb, Type& cs)
392  {
393  vtkm::Id numberOfPoints = 0;
394  vtkmdiy::load(bb, numberOfPoints);
396  vtkmdiy::load(bb, shapes);
398  vtkmdiy::load(bb, connectivity);
400  vtkmdiy::load(bb, offsets);
401 
402  cs = Type{};
403  cs.Fill(numberOfPoints, shapes, connectivity, offsets);
404  }
405 };
406 
407 } // diy
409 
410 #ifndef vtk_m_cont_CellSetExplicit_hxx
411 #include <vtkm/cont/CellSetExplicit.hxx>
412 #endif //vtk_m_cont_CellSetExplicit_hxx
413 
414 #endif //vtk_m_cont_CellSetExplicit_h
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::GetConnectivity
const VTKM_CONT PointCellIdsType & GetConnectivity(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell)
Definition: CellSetExplicit.h:302
vtkm::cont::CellSetExplicit::Internals::NumberOfPoints
vtkm::Id NumberOfPoints
Definition: CellSetExplicit.h:266
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::cont::CellSetExplicit::ConnectivityChooser
Definition: CellSetExplicit.h:77
vtkm::cont::CellSetExplicit::ShapesArrayType
typename CellPointIdsType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:108
vtkm::cont::CellSetExplicit::GetConnectivity
const VTKM_CONT PointCellIdsType & GetConnectivity(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:295
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ArrayHandleCast.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::cont::CellSetExplicit::HasConnectivityImpl
VTKM_CONT bool HasConnectivityImpl(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:227
vtkm::Get
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto Get(const vtkm::Tuple< Ts... > &tuple) -> decltype(tuple.template Get< Index >())
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:83
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::CellSetExplicit::Internals::CellPointIds
CellPointIdsType CellPointIds
Definition: CellSetExplicit.h:258
vtkm::cont::CellSetExplicit::SchedulingRangeType
vtkm::Id SchedulingRangeType
Definition: CellSetExplicit.h:106
vtkm::cont::CellSetExplicit::GetConnectivity
const VTKM_CONT CellPointIdsType & GetConnectivity(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint)
Definition: CellSetExplicit.h:288
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
vtkm::cont::CellSetExplicit::ConnectivityArrayType
typename CellPointIdsType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:109
vtkm::cont::CellSetExplicit::BuildConnectivity
VTKM_CONT void BuildConnectivity(vtkm::cont::DeviceAdapterId device, vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:216
vtkm::cont::CellSetExplicit::ConnectivityChooser::ConnectivityType
typename Chooser::ConnectivityType ConnectivityType
Definition: CellSetExplicit.h:84
vtkm::cont::CellSetExplicit::CellPointIdsType
typename ConnTypes::ConnectivityType CellPointIdsType
Definition: CellSetExplicit.h:102
vtkm::cont::CellSetExplicit::Internals::Internals
VTKM_CONT Internals()
Definition: CellSetExplicit.h:269
ArrayHandleConstant.h
CellShape.h
vtkm::cont::ArrayHandle::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::cont::CellSetExplicit::BuildConnectivity
VTKM_CONT void BuildConnectivity(vtkm::cont::DeviceAdapterId, vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:208
mangled_diy_namespace
Definition: Particle.h:331
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::CellSetExplicit::ConnectivityChooser::ShapesArrayType
typename ConnectivityType::ShapesArrayType ShapesArrayType
Definition: CellSetExplicit.h:85
vtkm::exec::arg::load
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm::cont::StorageTagConstant
Definition: ArrayHandleConstant.h:20
vtkm::cont::CellSetExplicit::ResetConnectivityImpl
VTKM_CONT void ResetConnectivityImpl(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell)
Definition: CellSetExplicit.h:249
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:168
vtkm::cont::CellSetExplicit::HasConnectivity
VTKM_CONT bool HasConnectivity(VisitTopology visit, IncidentTopology incident) const
Definition: CellSetExplicit.h:195
vtkm::cont::StorageTagCounting
Definition: ArrayHandleCounting.h:23
vtkm::cont::CellSetExplicit::ConnectivityChooser::ConnectivityArrayType
typename ConnectivityType::ConnectivityArrayType ConnectivityArrayType
Definition: CellSetExplicit.h:86
UnknownArrayHandle.h
vtkm::cont::CellSetExplicit::NumIndicesArrayType
typename ConnTypes::NumIndicesArrayType NumIndicesArrayType
Definition: CellSetExplicit.h:111
vtkm::cont::CellSetExplicit::Internals::NumberOfCellsAdded
vtkm::Id NumberOfCellsAdded
Definition: CellSetExplicit.h:265
vtkm::cont::CellSetExplicit::OffsetsArrayType
typename CellPointIdsType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:110
vtkm::cont::CellSetExplicit::ResetConnectivity
VTKM_CONT void ResetConnectivity(VisitTopology visit, IncidentTopology incident)
Definition: CellSetExplicit.h:202
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::exec::ConnectivityExplicit
Definition: ConnectivityExplicit.h:24
CellSet.h
vtkm::cont::CellSet
Definition: CellSet.h:24
vtkm::cont::CellSetExplicit::Data
std::shared_ptr< Internals > Data
Definition: CellSetExplicit.h:277
VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
#define VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
Definition: CellSetExplicit.h:62
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::cont::CellSetExplicit::ResetConnectivityImpl
VTKM_CONT void ResetConnectivityImpl(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint)
Definition: CellSetExplicit.h:239
ArrayGetValues.h
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::cont::CellSetExplicit::Internals::PointCellIds
PointCellIdsType PointCellIds
Definition: CellSetExplicit.h:259
vtkm::cont::CellSetExplicit::Internals::ConnectivityAdded
vtkm::Id ConnectivityAdded
Definition: CellSetExplicit.h:264
ConnectivityExplicitInternals.h
vtkm::cont::CellSetExplicit::ConnectivityChooser::OffsetsArrayType
typename ConnectivityType::OffsetsArrayType OffsetsArrayType
Definition: CellSetExplicit.h:87
vtkm::cont::CellSetExplicit
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:103
vtkm::cont::ArrayHandleOffsetsToNumComponents
An ArrayHandle that converts an array of offsets to an array of Vec sizes.
Definition: ArrayHandleOffsetsToNumComponents.h:129
ArrayHandleCounting.h
vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagConstant >::StorageTag
vtkm::cont::StorageTagConstant StorageTag
Definition: ArrayHandle.h:291
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
vtkm::cont::CellSetExplicit::Internals
Definition: CellSetExplicit.h:256
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
vtkm::cont::CellSetExplicit::ConnectivityChooser::Chooser
typename detail::CellSetExplicitConnectivityChooser< Thisclass, VisitTopology, IncidentTopology > Chooser
Definition: CellSetExplicit.h:81
vtkm::cont::CellSetExplicit::HasConnectivityImpl
VTKM_CONT bool HasConnectivityImpl(vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell) const
Definition: CellSetExplicit.h:233
vtkm::cont::CellSetExplicit::GetConnectivity
const VTKM_CONT CellPointIdsType & GetConnectivity(vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint) const
Definition: CellSetExplicit.h:281
ArrayHandleOffsetsToNumComponents.h
TopologyElementTag.h