10 #ifndef vtk_m_cont_internal_ReverseConnectivityBuilder_h
11 #define vtk_m_cont_internal_ReverseConnectivityBuilder_h
34 template <
typename AtomicHistogram,
typename ConnInPortal,
typename RConnToConnIdxCalc>
37 AtomicHistogram Histo;
39 RConnToConnIdxCalc IdxCalc;
42 BuildHistogram(
const AtomicHistogram& histo,
43 const ConnInPortal& conn,
44 const RConnToConnIdxCalc& idxCalc)
52 void operator()(
vtkm::Id rconnIdx)
const
55 const vtkm::Id connIdx = this->IdxCalc(rconnIdx);
56 const vtkm::Id ptId = this->Conn.Get(connIdx);
57 this->Histo.Add(ptId, 1);
61 template <
typename AtomicHistogram,
62 typename ConnInPortal,
63 typename ROffsetInPortal,
64 typename RConnOutPortal,
65 typename RConnToConnIdxCalc,
66 typename ConnIdxToCellIdxCalc>
69 AtomicHistogram Histo;
71 ROffsetInPortal ROffsets;
73 RConnToConnIdxCalc IdxCalc;
74 ConnIdxToCellIdxCalc CellIdCalc;
77 GenerateRConn(
const AtomicHistogram& histo,
78 const ConnInPortal& conn,
79 const ROffsetInPortal& rOffsets,
80 const RConnOutPortal& rconn,
81 const RConnToConnIdxCalc& idxCalc,
82 const ConnIdxToCellIdxCalc& cellIdCalc)
88 , CellIdCalc(cellIdCalc)
93 void operator()(
vtkm::Id inputIdx)
const
96 const vtkm::Id connIdx = this->IdxCalc(inputIdx);
97 const vtkm::Id ptId = this->Conn.Get(connIdx);
100 const vtkm::Id cellId = this->CellIdCalc(connIdx);
103 const vtkm::Id baseOffset = this->ROffsets.Get(ptId);
106 const vtkm::Id nextAvailable = this->Histo.Add(ptId, 1);
109 const vtkm::Id rconnIdx = baseOffset + nextAvailable;
110 this->RConn.Set(rconnIdx, cellId);
129 class ReverseConnectivityBuilder
133 template <
typename ConnArray,
135 typename ROffsetsArray,
136 typename RConnToConnIdxCalc,
137 typename ConnIdxToCellIdxCalc>
138 inline void Run(
const ConnArray& conn,
140 ROffsetsArray& rOffsets,
141 const RConnToConnIdxCalc& rConnToConnCalc,
142 const ConnIdxToCellIdxCalc& cellIdCalc,
148 auto connPortal = conn.PrepareForInput(device, connToken);
166 auto ac = atomicCounter.PrepareForExecution(device, token);
168 rcb::BuildHistogram<decltype(ac), decltype(connPortal), RConnToConnIdxCalc>;
169 BuildHisto histoGen{ ac, connPortal, rConnToConnCalc };
176 device, vtkm::cont::make_ArrayHandleCast<vtkm::Id>(rNumIndices), rOffsets);
199 auto ac = atomicCounter.PrepareForExecution(device, token);
200 auto rOffsetPortal = rOffsets.PrepareForInput(device, token);
201 auto rConnPortal = rConn.PrepareForOutput(rConnSize, device, token);
203 using GenRConnT = rcb::GenerateRConn<decltype(ac),
204 decltype(connPortal),
205 decltype(rOffsetPortal),
206 decltype(rConnPortal),
208 ConnIdxToCellIdxCalc>;
209 GenRConnT rConnGen{ ac, connPortal, rOffsetPortal, rConnPortal, rConnToConnCalc, cellIdCalc };
231 template <
typename OffsetsPortalType>
232 struct ConnIdxToCellIdCalc
234 OffsetsPortalType Offsets;
237 ConnIdxToCellIdCalc(
const OffsetsPortalType& offsets)
249 vtkm::Id length = this->Offsets.GetNumberOfValues();
255 vtkm::Id val = this->Offsets.Get(pos);
259 length -= halfway + 1;
267 upperBoundIdx = first;
270 return upperBoundIdx - 1;
275 struct ConnIdxToCellIdCalcSingleType
286 vtkm::Id operator()(
vtkm::Id inIdx)
const {
return inIdx / this->CellSize; }
289 template <
typename ConnTableT,
typename RConnTableT>
290 void ComputeRConnTable(RConnTableT& rConnTable,
291 const ConnTableT& connTable,
295 if (rConnTable.ElementsValid)
300 const auto& conn = connTable.Connectivity;
301 auto& rConn = rConnTable.Connectivity;
302 auto& rOffsets = rConnTable.Offsets;
303 const vtkm::Id rConnSize = conn.GetNumberOfValues();
307 const auto offInPortal = connTable.Offsets.PrepareForInput(device, token);
309 PassThrough idxCalc{};
310 ConnIdxToCellIdCalc<decltype(offInPortal)> cellIdCalc{ offInPortal };
312 vtkm::cont::internal::ReverseConnectivityBuilder builder;
313 builder.Run(conn, rConn, rOffsets, idxCalc, cellIdCalc, numberOfPoints, rConnSize, device);
318 rConnTable.ElementsValid =
true;
322 template <
typename RConnTableT,
typename ConnectivityStorageTag>
323 void ComputeRConnTable(RConnTableT& rConnTable,
324 const ConnectivityExplicitInternals<
326 ConnectivityStorageTag,
331 if (rConnTable.ElementsValid)
336 const auto& conn = connTable.Connectivity;
337 auto& rConn = rConnTable.Connectivity;
338 auto& rOffsets = rConnTable.Offsets;
339 const vtkm::Id rConnSize = conn.GetNumberOfValues();
342 if (connTable.Offsets.GetNumberOfValues() >= 2)
350 PassThrough idxCalc{};
351 ConnIdxToCellIdCalcSingleType cellIdCalc{ cellSize };
353 vtkm::cont::internal::ReverseConnectivityBuilder builder;
354 builder.Run(conn, rConn, rOffsets, idxCalc, cellIdCalc, numberOfPoints, rConnSize, device);
358 rConnTable.ElementsValid =
true;
365 #endif // ReverseConnectivityBuilder_h