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

SCM Repository

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

Diff of /branches/lamont/src/compiler/c-target/fragments/grid2D.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2161, Wed Feb 20 04:32:27 2013 UTC revision 2162, Thu Feb 21 04:59:17 2013 UTC
# Line 1  Line 1 
1  void constructGrid2D (@STRANDTY@ ** strands, GridContext * ctx)  void constructGrid2D (@STRANDTY@ ** strands, GridContext * ctx)
2  {  {
3      int size = ctx->gridSize[0] * ctx->gridSize[1];      union2i_t gridSize;
4        gridSize.v = *(ctx->gridSize);
5    
6    
7        int size = (gridSize.[0] + 1) * (gridSize.[1] + 1);
8    
9      ctx->grid = (StrandItem_t **)malloc(sizeof(StrandItem_t *) * size);      ctx->grid = (StrandItem_t **)malloc(sizeof(StrandItem_t *) * size);
10    
# Line 10  Line 14 
14    
15      for(int id = 0; id < ctx->numberOfStrands; id++)      for(int id = 0; id < ctx->numberOfStrands; id++)
16      {      {
17          int cell[2];          uint32_t gridIdx = findGridIdx(strands[id]->pos,ctx);
   
         worldToGrid2D(strands[id]->pos,ctx,cell);  
   
         clampToGrid2D(ctx,cell);  
   
         uint32_t gridIdx = UMAD(cell[1],ctx->gridSize[1],cell[0]);  
18    
19          StrandItem_t * newCell = (StrandItem_t *)malloc(sizeof(StrandItem_t));          StrandItem_t * newCell = (StrandItem_t *)malloc(sizeof(StrandItem_t));
20    
# Line 33  Line 31 
31  }  }
32  void updateGrid2D (@STRANDTY@ ** selfIn, @STRANDTY@ ** selfOut, GridContext * ctx)  void updateGrid2D (@STRANDTY@ ** selfIn, @STRANDTY@ ** selfOut, GridContext * ctx)
33  {  {
     int size = ctx->gridSize[0] * ctx->gridSize[1];  
   
34      for(int id = 0; id < ctx->numberOfStrands; id++)      for(int id = 0; id < ctx->numberOfStrands; id++)
35      {      {
36          int cell[2];         uint32_t newGridIdx = findGridIdx(selfOut[id]->pos,ctx);
37    
38          worldToGrid2D(selfOut[id]->pos,ctx,cell);         uint32_t oldGridIdx = findGridIdx(selfIn[id]->pos,ctx);
   
         clampToGrid2D(ctx,cell);  
   
         uint32_t newGridIdx = UMAD(cell[1],ctx->gridSize[1],cell[0]);  
   
         worldToGrid2D(selfIn[id]->pos,ctx,cell);  
   
         clampToGrid2D(ctx,cell);  
   
         uint32_t oldGridIdx = UMAD(cell[1],ctx->gridSize[1],cell[0]);  
39    
40          if(newGridIdx != oldGridIdx){          if(newGridIdx != oldGridIdx){
41                StrandItem_t * curr = ctx->grid[oldGridIdx];                StrandItem_t * curr = ctx->grid[oldGridIdx];
# Line 85  Line 71 
71    
72      Diderot_vec2_t strandPosition = qStrand->pos;      Diderot_vec2_t strandPosition = qStrand->pos;
73    
74      worldToGrid2D(strandPosition,ctx,gridPos);      union2i_t gridSize;
75        gridSize.v = *(ctx->gridSize);
76    
77        union2i_t cellSize;
78        cellSize.v = *(ctx->cellSize);
79    
80        union2i_t gridPos;
81        gridPos.v = findGridCell(strandPosition, ctx);
82    
83      int xBounds[2] = {clamp_int(gridPos[0] - ceil(radius/(float)ctx->cellSize[0]),      union2i_t xBounds;
84        xBounds.v = vec2i(clamp_int(gridPos.r[0] - ceil(radius/(float)cellSize.r[0]),
85                                  0,                                  0,
86                                  ctx->gridSize[0]-1),                                  gridSize.r[0]- 1),
87                        clamp_int(gridPos[0] + ceil(radius/(float)ctx->cellSize[0]),                        clamp_int(gridPos.r[0] + ceil(radius/(float)cellSize.r[0]),
88                                  0,                                  0,
89                                  ctx->gridSize[0]-1)};                                  gridSize.r[0]-1));
90    
91    
92      int yBounds[2] =  {clamp_int(gridPos[1] - ceil(radius/(float)ctx->cellSize[1]),      union2i_t yBounds;
93        yBounds.v = vec2i(clamp_int(gridPos.r[1] - ceil(radius/(float)cellSize.r[1]),
94                                   0,                                   0,
95                                   ctx->gridSize[1]-1),                                  gridSize.r[1]-1),
96                         clamp_int(gridPos[1] + ceil(radius/(float)ctx->cellSize[1]),                        clamp_int(gridPos.r[1] + ceil(radius/(float)cellSize.r[1]),
97                                   0,                                   0,
98                                   ctx->gridSize[1]-1)};                                   gridSize.r[1]-1)};
99    
100      StrandItem_t * results = 0;      StrandItem_t * results = 0;
101      int neighborCount = 0,idx=0;      int neighborCount = 0,idx=0;
102    
103     for(int x = xBounds[0]; x <= xBounds[1]; x++){     for(int x = xBounds.r[0]; x <= xBounds.r[1]; x++){
104          for(int y = yBounds[0]; y <= yBounds[1]; y++) {          for(int y = yBounds.r[0]; y <= yBounds.r[1]; y++) {
105                   int neighborCellIndx = UMAD(y,ctx->gridSize[1],x);                   int neighborCellIndx = UMAD(y,gridSize.r[1],x);
106                   StrandItem_t * neighborCellStrands = ctx->grid[neighborCellIndx];                   StrandItem_t * neighborCellStrands = ctx->grid[neighborCellIndx];
107                  while(neighborCellStrands != 0) {                  while(neighborCellStrands != 0) {
108                        if(isWithinRadius2D(strandPosition,strands[neighborCellStrands->strandId]->pos,radius)){                        if(isWithinRadius2D(strandPosition,strands[neighborCellStrands->strandId]->pos,radius)){

Legend:
Removed from v.2161  
changed lines
  Added in v.2162

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