Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/lamont/src/compiler/c-target/fragments/grid3D.in
ViewVC logotype

View of /branches/lamont/src/compiler/c-target/fragments/grid3D.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (download) (annotate)
Tue Mar 19 20:17:15 2013 UTC (6 years, 10 months ago) by lamonts
File size: 4858 byte(s)
Commiting 3D grid work
//! \brief allocate memory for the grid context 
//! \param gridSize the dimensions of the grid 
//! \param numberOfStrands the number of strands 
//! \param cellSize the size of the cells 
//! \param window the viewing window (i.e. [XMIN,XMAX,YMIN,YMAX]) 
//! \return the address of the grid context 
GridContext * Diderot_GridAllocGrid3D (
    Diderot_vec3_t *gridSize, 
    uint32_t numberOfStrands, 
    Diderot_vec3_t *cellSize,    
    Diderot_vec6_t  *window) 
{
    GridContext *newGridContext = CheckedAlloc (sizeof(GridContext));

    newGridContext->gridSize = gridSize; 
    newGridContext->numberOfStrands = numberOfStrands; 
    newGridContext->cellSize = cellSize; 
    newGridContext->window = window; 

    Diderot_union3_t v;
    v.v = *(gridSize);   

    newGridContext->grid = CheckedAlloc(sizeof(GridCell_t)*((Diderot_int_t)v.r[0] + 2)  
                                                          *((Diderot_int_t)v.r[1] + 2) 
                                                          *((Diderot_int_t)v.r[2] + 2)); 
    newGridContext->gridPool.poolSize = numberOfStrands; 
    newGridContext->gridPool.handle = 0; 
    newGridContext->gridPool.pool = CheckedAlloc(sizeof(GridItem_t)*numberOfStrands); 
    
    return newGridContext; 
}
void Diderot_GridAdd3D(Diderot_vec3_t pos, uint32_t id, GridContext * ctx) 
{ 
   uint32_t gridIdx = worldToGridIdx3D(pos,ctx);
   uint32_t newPoolIdx = 0; 

   GridItem_t * newItem = newGridItem(ctx,&newPoolIdx);
   newItem->strandId = id; 

   if(ctx->grid[gridIdx].poolIdx != -1) 
       newItem->next = ctx->grid[gridIdx].poolIdx; 
   else 
       newItem->next = -1; 

   ctx->grid[gridIdx].poolIdx = newPoolIdx; 
}
void Diderot_GridBuild3D(@STRANDTY@ ** strands, GridContext * ctx) 
{ 
    Diderot_GridClear(ctx); 

    for(int id = 0; id < ctx->numberOfStrands; id++) {
        Diderot_GridAdd3D(strands[id]->pos,strands[id]->strandId,ctx);
    }  
}
/************* Query Functions *******************/
Diderot_DynSeq_t *spherical_query3D (
    @STRANDTY@ **strands,
    @STRANDTY@ *qStrand,
    GridContext *ctx,
    QueryPool_t *queryPool,
    Diderot_real_t radius) 
{    
    Diderot_vec3_t strandPosition = qStrand->pos;

    Diderot_union3_t gridSize; 
    gridSize.v = *(ctx->gridSize); 

    Diderot_union3_t cellSize; 
    cellSize.v = *(ctx->cellSize); 
 
    Diderot_iunion3_t gridPos; 
    gridPos.v = worldToCell3D(strandPosition, ctx); 
    
    Diderot_iunion2_t xBounds; 
    xBounds.v = vec2i(clamp_int((gridPos.i[0] - ceil(radius/(float)cellSize.r[0])) - 1,
                                0,
                                gridSize.r[0]),
                      clamp_int((gridPos.i[0] + ceil(radius/(float)cellSize.r[0])) - 1,
                                0,
                                gridSize.r[0]));

    Diderot_iunion2_t  yBounds;  
    yBounds.v = vec2i(clamp_int((gridPos.i[1] - ceil(radius/(float)cellSize.r[1])) - 1,
                                0,
                                gridSize.r[1]),
                      clamp_int((gridPos.i[1] + ceil(radius/(float)cellSize.r[1])) - 1,
                                 0,
                                 gridSize.r[1]));


    Diderot_iunion2_t  zBounds;  
    zBounds.v = vec2i(clamp_int((gridPos.i[2] - ceil(radius/(float)cellSize.r[2])) - 1,
                                0,
                                gridSize.r[2]),
                      clamp_int((gridPos.i[2] + ceil(radius/(float)cellSize.r[2])) - 1,
                                 0,
                                 gridSize.r[2]));


    int neighborCount = 0;  

    Diderot_QueryClearPool(queryPool);

    for (int x = xBounds.i[0]; x <= xBounds.i[1]; x++){
        for (int y = yBounds.i[0]; y <= yBounds.i[1]; y++) {
            for (int z = zBounds.i[0]; z <= zBounds.i[1]; z++) {
                int neighborCellIndx = UMAD(UMAD(y,gridSize.r[0] + 2,x),gridSize.r[1],z);
                GridItem_t *neighborCellStrands = Diderot_GridFindCellStart(neighborCellIndx,ctx);
                while (neighborCellStrands != 0) {
                    if (isWithinRadius3D(strandPosition,strands[neighborCellStrands->strandId]->pos, radius)) {
                        if (neighborCellStrands->strandId != qStrand->strandId) {
                            Diderot_QueryAddToPool(strands[neighborCellStrands->strandId], queryPool); 
                            neighborCount++; 
                        }
                    }
                    if(neighborCellStrands->next == -1) 
                        break; 
                    else 
                        neighborCellStrands = Diderot_GridFindItemInCell(neighborCellStrands->next, ctx);
                }
            }
        }
    }   
    Diderot_DynSeq_t * seq = Diderot_DynSeqAlloc(sizeof(@STRANDTY@ *), neighborCount);
    seq->data = queryPool->pool;
 
    return seq;
} 

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0