18#ifndef AGX_CREATE_CELL_H
19#define AGX_CREATE_CELL_H
35 template <
typename Gr
idTierDataT,
typename CellDataT,
typename CellT,
typename CellIdT,
typename CellPosT,
typename Gr
idCellTableT,
size_t NumNeighbors>
43 GridTierDataT& gridTier,
46 const CellIdT *NeighborTable,
48 Physics::HierarchicalGrid::SolveBodyManager* solveBodyManager,
49 const agx::UInt& contactZoneAccumulationLevel
53 template <
typename CellDataT,
typename CellIdT>
58 Index parentCellIndex,
60 Physics::HierarchicalGrid::SolveBodyManager* solveBodyManager,
61 const agx::UInt& contactZoneAccumulationLevel
66 template <
typename Gr
idTierDataT,
typename CellDataT,
typename CellT,
typename CellIdT,
typename CellPosT,
typename Gr
idCellTableT,
size_t NumNeighbors>
72 GridTierDataT& gridTier,
75 const CellIdT *NeighborTable,
77 Physics::HierarchicalGrid::SolveBodyManager* solveBodyManager,
78 const agx::UInt& contactZoneAccumulationLevel
87 template <
typename Gr
idTierDataT,
typename CellDataT,
typename CellT,
typename CellIdT,
typename CellPosT,
typename Gr
idCellTableT,
size_t NumNeighbors>
94 GridTierDataT& gridTier,
97 const CellIdT *NeighborTable,
100 const agx::UInt& contactZoneAccumulationLevel
111 GridCellTableT& parentTierTable = *gridTier.cellTable[ parentTier ];
112 parentCellIndex = parentTierTable.find( parentId );
117 size_t oldNumTiers = gridTier.cellTable.size();
121 GridTierDataT, CellDataT, CellT, CellIdT, CellPosT, GridCellTableT, NumNeighbors
124 deadCells, emptyZones, parentTier, parentId, gridTier, cell,
125 rootCells, NeighborTable, hasNewTiers, solveBodyManager,
126 contactZoneAccumulationLevel
130 tier =
agx::UInt8(tier + (gridTier.numElements() - oldNumTiers));
138 if (!deadCells.
empty())
140 cellIndex = deadCells.
back();
146 cell.numChildren[cellIndex] = 0;
147 cell.invDepth[cellIndex] = 0;
151 cellIndex = cell.createInstance();
156 cell.tier[ cellIndex ] = tier;
157 cell.id[ cellIndex ] = cellId;
160 GridCellTableT& cellTable = *gridTier.cellTable[ tier ];
162 cellTable.insert(cellId, cellIndex);
168 connectToParentCell<CellDataT, CellIdT>(cellIndex, cellId, parentCellIndex, cell, solveBodyManager, contactZoneAccumulationLevel);
180 solveBodyManager->
registerCell(cell.instance[cellIndex]);
182 if (!rootCells[rootIndex])
185 rootCells[rootIndex] =
root;
188 UInt32 *neighborList = &cell.neighbors[CellDataT::neighborsArraySize * cellIndex];
190 for (
size_t i = 0; i < NumNeighbors; ++i)
193 for (
size_t i = 0; i < rootCells.
size(); ++i)
198 UInt32 otherIndex = rootCells[i].calculateIndex();
200 CellIdT offset = cell.id[otherIndex] - cellId;
204 neighborList[localNeighborIndex] = otherIndex;
206 UInt32 *reverseList = &cell.neighbors[CellDataT::neighborsArraySize * otherIndex];
207 reverseList[ NumNeighbors-1-localNeighborIndex ] = cellIndex;
214 for (
size_t i = 0; i < rootCells.
size(); ++i)
220 GridTierDataT, CellDataT, CellT, CellIdT, CellPosT, GridCellTableT, NumNeighbors
223 gridTier.size[0] *
Real(2),
232 contactZoneAccumulationLevel
242 template <
typename CellDataT,
typename CellIdT>
246 const CellIdT cellId,
247 Index parentCellIndex,
250 const agx::UInt& contactZoneAccumulationLevel
256 cell.parent[ cellIndex ] = (
UInt32)parentCellIndex;
257 UInt32 *childList = &cell.children[CellDataT::childrenArraySize * parentCellIndex];
260 const UInt numChildren = cell.numChildren[ parentCellIndex ];
261 UInt compactedIndex = 0;
262 for (; compactedIndex < numChildren; ++compactedIndex)
264 if (childIndex < childList[ compactedIndex ])
268 for (
UInt n = numChildren; n > compactedIndex; --n)
269 childList[n] = childList[n-1];
271 childList[compactedIndex] = (
UInt32)cellIndex;
273 cell.numChildren[ parentCellIndex ]++;
274 agxAssert(cell.numChildren[parentCellIndex] <= CellDataT::childrenArraySize);
277 if (numChildren == 0)
279 UInt8 invDepth = cell.invDepth[cellIndex];
281 while (parentCellIndex !=
InvalidIndex && cell.invDepth[parentCellIndex] <= invDepth)
284 cell.invDepth[parentCellIndex] = ++invDepth;
286 if ( (invDepth >= contactZoneAccumulationLevel || cell.tier[parentCellIndex] <= contactZoneAccumulationLevel) && !cell.solveBodyOffsets[parentCellIndex])
287 solveBodyManager->
registerCell(cell.instance[parentCellIndex]);
289 parentCellIndex = cell.parent[parentCellIndex];
295 template <
typename Gr
idTierDataT,
typename CellDataT,
typename CellT,
typename CellIdT,
typename CellPosT,
typename Gr
idCellTableT,
size_t NumNeighbors>
302 const CellIdT cellId,
303 GridTierDataT& gridTier,
306 const CellIdT *NeighborTable,
309 const agx::UInt& contactZoneAccumulationLevel
315 GridCellTableT& parentTierTable = *gridTier.cellTable[ parentTier ];
316 UInt32 parentCellIndex = parentTierTable.find( parentId );
323 GridTierDataT, CellDataT, CellT, CellIdT, CellPosT, GridCellTableT, NumNeighbors
326 deadCells, emptyZones, parentTier, parentId, gridTier, cell,
327 rootCells, NeighborTable, hasNewTiers, solveBodyManager,
328 contactZoneAccumulationLevel
333 connectToParentCell<CellDataT, CellIdT>(cellIndex, cellId, parentCellIndex, cell, solveBodyManager, contactZoneAccumulationLevel);
335 return parentCellIndex;
agx::IndexRange32 & range()
Type-specific Array used for fast access into the data held by a Buffer.
Accessor to a entity instance stored in a EntityStorage, to allow SOA (structure of arrays) data to b...
static EntityPtr createWithIndex(EntityStorage *storage, agx::Index index)
Pointer to a entity instance of type Physics.HierarchicalGrid.Cell.
void registerCell(CellPtr cell)
AGXPHYSICS_EXPORT bool isNeighborOffset(const Vec3i &offset)
AGXPHYSICS_EXPORT Index calculateNeighborIndex(const Vec3i &offset)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
UInt32 createCell(agxData::Array< agx::UInt32 > &deadCells, agxData::Array< Physics::HierarchicalGrid::ContactZonePtr > &emptyZones, UInt8 tier, const CellIdT cellId, GridTierDataT &gridTier, CellDataT &cell, agxData::Array< CellT > &rootCells, const CellIdT *NeighborTable, agx::Bool &hasNewTiers, Physics::HierarchicalGrid::SolveBodyManager *solveBodyManager, const agx::UInt &contactZoneAccumulationLevel)
Create and connect a cell.
UInt32 connectToParentCell(agxData::Array< agx::UInt32 > &deadCells, agxData::Array< Physics::HierarchicalGrid::ContactZonePtr > &emptyZones, Index cellIndex, UInt8 tier, const CellIdT cellId, GridTierDataT &gridTier, CellDataT &cell, agxData::Array< CellT > &rootCells, const CellIdT *NeighborTable, agx::Bool &hasNewTiers, Physics::HierarchicalGrid::SolveBodyManager *solveBodyManager, const agx::UInt &contactZoneAccumulationLevel)
UInt calculateRootCellIndex(const Vec3i &cellId)
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
UInt calculateCellChildIndex(const Vec3i &cellId)
size_t createMissingTiers(Real minCellSize, agxData::Array< agx::UInt32 > &deadCells, agxData::Array< Physics::HierarchicalGrid::ContactZonePtr > &emptyZones, GridTierDataT &gridTier, CellDataT &cell, agxData::Array< CellT > &rootCells, const CellIdT *NeighborTable, agx::Bool &hasNewTiers, Physics::HierarchicalGrid::SolveBodyManager *solveBodyManager, const agx::UInt &contactZoneAccumulationLevel)
AGXCORE_EXPORT Component * root()
Vec3i calculateParentCellId(const Vec3i &cellId)