BroadPhaseCollisionDetector::CellIndex BroadPhaseCollisionDetector::propagate_cell(const CellIndex& cell) { return CellIndex(static_cast<int>(floor(cell.i*0.5)), static_cast<int>(floor(cell.j*0.5)), static_cast<int>(floor(cell.k*0.5))); }
//#################### PRIVATE METHODS #################### BroadPhaseCollisionDetector::CellIndex BroadPhaseCollisionDetector::determine_cell(const Vector3d& p, double gridSize) { return CellIndex(static_cast<int>(floor(p.x / gridSize)), static_cast<int>(floor(p.y / gridSize)), static_cast<int>(floor(p.z / gridSize))); }
void vtSimpleLodGrid::AllocateCell(int a, int b) { int i = CellIndex(a,b); m_pCells[i] = new vtLOD; vtString name; name.Format("LOD cell %d %d", a, b); m_pCells[i]->setName(name); // The child of this LOD is only visible up to LODDistance away m_pCells[i]->setRange(0, 0.0f, m_fLODDistance); // determine LOD center FPoint3 lod_center; lod_center.x = m_origin.x + ((m_size.x / m_dim) * (a + 0.5f)); lod_center.y = m_origin.y + (m_size.y / 2.0f); lod_center.z = m_origin.z + ((m_size.z / m_dim) * (b + 0.5f)); if (m_pHeightField) m_pHeightField->FindAltitudeAtPoint(lod_center, lod_center.y); vtGroup *group = new vtGroup; group->setName("LOD group"); m_pCells[i]->SetCenter(lod_center); m_pCells[i]->addChild(group); addChild(m_pCells[i]); }
const std::vector<boost::shared_ptr<ribi::foam::Cell> > ribi::foam::Mesh::CreateEmptyCells( const Files& files) { std::vector<boost::shared_ptr<ribi::foam::Cell> > cells; const CellIndex n_cells = files.GetOwner()->CountNumberOfCells(); assert(n_cells == files.GetOwner()->CountNumberOfCells()); assert(n_cells > CellIndex(0)); for (CellIndex i=CellIndex(0); i!=n_cells; ++i) { const boost::shared_ptr<Cell> cell( new Cell ); cells.push_back(cell); } assert(!cells.empty()); return cells; }
osg::Group *vtSimpleLodGrid::GetCell(int a, int b) { int i = CellIndex(a, b); vtLOD *pCell = m_pCells[i]; if (!pCell) return NULL; return pCell; }
void vtSimpleLodGrid::SetDistance(float fLODDistance) { m_fLODDistance = fLODDistance; for (int a = 0; a < m_dim; a++) { for (int b = 0; b < m_dim; b++) { vtLOD *lod = m_pCells[CellIndex(a,b)]; if (lod) lod->setRange(0, 0.0f, m_fLODDistance); } } }
osg::Group *vtSimpleLodGrid::FindCellParent(const FPoint3 &point) { int a, b; DetermineCell(point, a, b); if (a < 0 || a >= m_dim || b < 0 || b >= m_dim) return NULL; int i = CellIndex(a, b); if (!m_pCells[i]) AllocateCell(a, b); return (osg::Group *) (m_pCells[i]->getChild(0)); }
std::set<BroadPhaseCollisionDetector::CellIndex> BroadPhaseCollisionDetector::determine_overlapped_cells(const Vector3d& mins, const Vector3d& maxs, double gridSize) { CellIndex minCell = determine_cell(mins, gridSize); CellIndex maxCell = determine_cell(maxs, gridSize); std::set<CellIndex> ret; for(int i=minCell.i; i<=maxCell.i; ++i) for(int j=minCell.j; j<=maxCell.j; ++j) for(int k=minCell.k; k<=maxCell.k; ++k) { ret.insert(CellIndex(i,j,k)); } return ret; }
void vtSimpleLodGrid::Setup(const FPoint3 &origin, const FPoint3 &size, int iDimension, float fLODDistance, vtHeightField3d *pHF) { m_origin = origin; m_size = size; m_dim = iDimension; m_fLODDistance = fLODDistance; m_step = m_size / (float)m_dim; // wrap with an array of simple LOD nodes m_pCells = (vtLOD **)malloc(m_dim * m_dim * sizeof(vtLOD *)); int a, b; for (a = 0; a < m_dim; a++) { for (b = 0; b < m_dim; b++) { m_pCells[CellIndex(a,b)] = NULL; } } m_pHeightField = pHF; }
void FIndirectLightingCache::InterpolateBlock( FScene* Scene, const FIndirectLightingCacheBlock& Block, TArray<float>& AccumulatedWeight, TArray<FSHVectorRGB2>& AccumulatedIncidentRadiance) { const FBoxCenterAndExtent BlockBoundingBox(Block.Min + Block.Size / 2, Block.Size / 2); const FVector HalfTexelWorldOffset = BlockBoundingBox.Extent / FVector(Block.TexelSize); if (GCacheLimitQuerySize && Block.TexelSize > 2) { for (int32 VolumeIndex = 0; VolumeIndex < Scene->PrecomputedLightVolumes.Num(); VolumeIndex++) { const FPrecomputedLightVolume* PrecomputedLightVolume = Scene->PrecomputedLightVolumes[VolumeIndex]; // Compute the target query size // We will try to split up the allocation into groups that are smaller than this before querying the octree // This prevents very large objects from finding all the samples in the level in their octree search const float WorldTargetSize = PrecomputedLightVolume->GetNodeLevelExtent(GCacheQueryNodeLevel) * 2; const FVector WorldCellSize = Block.Size / FVector(Block.TexelSize); // Number of cells to increment by for query blocks FIntVector NumStepCells; NumStepCells.X = FMath::Max(1, FMath::FloorToInt(WorldTargetSize / WorldCellSize.X)); NumStepCells.Y = FMath::Max(1, FMath::FloorToInt(WorldTargetSize / WorldCellSize.Y)); NumStepCells.Z = FMath::Max(1, FMath::FloorToInt(WorldTargetSize / WorldCellSize.Z)); FIntVector NumQueryStepCells(0, 0, 0); // World space size to increment by for query blocks const FVector WorldStepSize = FVector(NumStepCells) * WorldCellSize; FVector QueryWorldStepSize(0, 0, 0); check(NumStepCells.X > 0 && NumStepCells.Y > 0 && NumStepCells.Z > 0); // This will track the position in cells of the query block being built FIntVector CellIndex(0, 0, 0); // This will track the min world position of the query block being built FVector MinPosition = Block.Min; for (MinPosition.Z = Block.Min.Z, CellIndex.Z = 0; CellIndex.Z < Block.TexelSize; MinPosition.Z += WorldStepSize.Z, CellIndex.Z += NumStepCells.Z) { QueryWorldStepSize.Z = WorldStepSize.Z; NumQueryStepCells.Z = NumStepCells.Z; // If this is the last query block in this dimension, adjust both the world space and cell sizes to match if (CellIndex.Z + NumStepCells.Z > Block.TexelSize) { QueryWorldStepSize.Z = Block.Min.Z + Block.Size.Z - MinPosition.Z; NumQueryStepCells.Z = Block.TexelSize - CellIndex.Z; } for (MinPosition.Y = Block.Min.Y, CellIndex.Y = 0; CellIndex.Y < Block.TexelSize; MinPosition.Y += WorldStepSize.Y, CellIndex.Y += NumStepCells.Y) { QueryWorldStepSize.Y = WorldStepSize.Y; NumQueryStepCells.Y = NumStepCells.Y; if (CellIndex.Y + NumStepCells.Y > Block.TexelSize) { QueryWorldStepSize.Y = Block.Min.Y + Block.Size.Y - MinPosition.Y; NumQueryStepCells.Y = Block.TexelSize - CellIndex.Y; } for (MinPosition.X = Block.Min.X, CellIndex.X = 0; CellIndex.X < Block.TexelSize; MinPosition.X += WorldStepSize.X, CellIndex.X += NumStepCells.X) { QueryWorldStepSize.X = WorldStepSize.X; NumQueryStepCells.X = NumStepCells.X; if (CellIndex.X + NumStepCells.X > Block.TexelSize) { QueryWorldStepSize.X = Block.Min.X + Block.Size.X - MinPosition.X; NumQueryStepCells.X = Block.TexelSize - CellIndex.X; } FVector BoxExtent = QueryWorldStepSize / 2; // Use a 0 query extent in dimensions that only have one cell, these become point queries BoxExtent.X = NumQueryStepCells.X == 1 ? 0 : BoxExtent.X; BoxExtent.Y = NumQueryStepCells.Y == 1 ? 0 : BoxExtent.Y; BoxExtent.Z = NumQueryStepCells.Z == 1 ? 0 : BoxExtent.Z; // Build a bounding box for the query block const FBoxCenterAndExtent BoundingBox(MinPosition + BoxExtent + HalfTexelWorldOffset, BoxExtent); checkSlow(CellIndex.X < Block.TexelSize && CellIndex.Y < Block.TexelSize && CellIndex.Z < Block.TexelSize); checkSlow(CellIndex.X + NumQueryStepCells.X <= Block.TexelSize && CellIndex.Y + NumQueryStepCells.Y <= Block.TexelSize && CellIndex.Z + NumQueryStepCells.Z <= Block.TexelSize); // Interpolate from the SH volume lighting samples that Lightmass computed PrecomputedLightVolume->InterpolateIncidentRadianceBlock( BoundingBox, NumQueryStepCells, FIntVector(Block.TexelSize), CellIndex, AccumulatedWeight, AccumulatedIncidentRadiance); } } } } } else { for (int32 VolumeIndex = 0; VolumeIndex < Scene->PrecomputedLightVolumes.Num(); VolumeIndex++) { const FPrecomputedLightVolume* PrecomputedLightVolume = Scene->PrecomputedLightVolumes[VolumeIndex]; check(PrecomputedLightVolume); check(PrecomputedLightVolume->IsUsingHighQualityLightMap() == AllowHighQualityLightmaps(Scene->GetFeatureLevel())); // Interpolate from the SH volume lighting samples that Lightmass computed // Query using the bounds of all the samples in this block // There will be a performance cliff for large objects which end up intersecting with the entire octree PrecomputedLightVolume->InterpolateIncidentRadianceBlock( FBoxCenterAndExtent(BlockBoundingBox.Center + HalfTexelWorldOffset, BlockBoundingBox.Extent), FIntVector(Block.TexelSize), FIntVector(Block.TexelSize), FIntVector(0), AccumulatedWeight, AccumulatedIncidentRadiance); } } }
void vtkStructuredGridFacelistFilter::Execute() { int i, j; vtkStructuredGrid *input = GetInput(); vtkPolyData *output = GetOutput(); vtkCellData *inCellData = input->GetCellData(); vtkCellData *outCellData = output->GetCellData(); int dims[3]; input->GetDimensions(dims); int nX = dims[0]; int nY = dims[1]; int nZ = dims[2]; int numOutCells = 0; if (nX > 1) numOutCells += 2*(nY-1)*(nZ-1); else numOutCells += (nY-1)*(nZ-1); if (nY > 1) numOutCells += 2*(nX-1)*(nZ-1); else numOutCells += (nX-1)*(nZ-1); if (nZ > 1) numOutCells += 2*(nX-1)*(nY-1); else numOutCells += (nX-1)*(nY-1); // // Copy over the points and the point data. // output->SetPoints(input->GetPoints()); output->GetPointData()->PassData(input->GetPointData()); // // Have the cell data allocate memory. // outCellData->CopyAllocate(inCellData); vtkCellArray *polys = vtkCellArray::New(); vtkIdTypeArray *list = vtkIdTypeArray::New(); list->SetNumberOfValues(numOutCells*(4+1)); vtkIdType *nl = list->GetPointer(0); // // Left face // int cellId = 0; for (i = 0 ; i < nY-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(0, i, j, nX, nY, nZ); *nl++ = PointIndex(0, i, j+1, nX, nY, nZ); *nl++ = PointIndex(0, i+1, j+1, nX, nY, nZ); *nl++ = PointIndex(0, i+1, j, nX, nY, nZ); int cId = CellIndex(0, i, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Right face // if (nX > 1) { for (i = 0 ; i < nY-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(nX-1, i, j, nX, nY, nZ); *nl++ = PointIndex(nX-1, i+1, j, nX, nY, nZ); *nl++ = PointIndex(nX-1, i+1, j+1, nX, nY, nZ); *nl++ = PointIndex(nX-1, i, j+1, nX, nY, nZ); int cId = CellIndex(nX-2, i, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } // // Bottom face // for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, 0, j, nX, nY, nZ); *nl++ = PointIndex(i+1, 0, j, nX, nY, nZ); *nl++ = PointIndex(i+1, 0, j+1, nX, nY, nZ); *nl++ = PointIndex(i, 0, j+1, nX, nY, nZ); int cId = CellIndex(i, 0, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Top face // if (nY > 1) { for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nZ-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, nY-1, j, nX, nY, nZ); *nl++ = PointIndex(i, nY-1, j+1, nX, nY, nZ); *nl++ = PointIndex(i+1, nY-1, j+1, nX, nY, nZ); *nl++ = PointIndex(i+1, nY-1, j, nX, nY, nZ); int cId = CellIndex(i, nY-2, j, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } // // Back face // for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nY-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, j, 0, nX, nY, nZ); *nl++ = PointIndex(i, j+1, 0, nX, nY, nZ); *nl++ = PointIndex(i+1, j+1, 0, nX, nY, nZ); *nl++ = PointIndex(i+1, j, 0, nX, nY, nZ); int cId = CellIndex(i, j, 0, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } // // Front face // if (nZ > 1) { for (i = 0 ; i < nX-1 ; i++) { for (j = 0 ; j < nY-1 ; j++) { *nl++ = 4; *nl++ = PointIndex(i, j, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i+1, j, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i+1, j+1, nZ-1, nX, nY, nZ); *nl++ = PointIndex(i, j+1, nZ-1, nX, nY, nZ); int cId = CellIndex(i, j, nZ-2, nX, nY, nZ); outCellData->CopyData(inCellData, cId, cellId); cellId++; } } } polys->SetCells(numOutCells, list); list->Delete(); outCellData->Squeeze(); output->SetPolys(polys); polys->Delete(); }
NS_IMETHODIMP HTMLTableCellElement::GetCellIndex(int32_t* aCellIndex) { *aCellIndex = CellIndex(); return NS_OK; }