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

SCM Repository

[diderot] Diff of /branches/lamont/src/include/Diderot/grid.h
ViewVC logotype

Diff of /branches/lamont/src/include/Diderot/grid.h

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

revision 2190, Sun Feb 24 03:43:58 2013 UTC revision 2191, Sun Feb 24 06:12:43 2013 UTC
# Line 24  Line 24 
24  #define YMIN 2  #define YMIN 2
25  #define YMAX 3  #define YMAX 3
26    
27  //StrandItem_t -> Strand Id linked list node  //GridItem_t
28  typedef struct strandItem{  typedef struct {
29      uint32_t strandId;             //the unique identification number for a strand      uint32_t strandId;             //the unique identification number for a strand
30      struct strandItem * next;      //the next strand item in the list      uint32_t next;      //the next strand item in the list
31      struct strandItem * prev;      //the previous strand item in the list  }GridItem_t;
32  }StrandItem_t;  
33    typedef struct {
34        uint32_t poolIdx;   //the index into the pool where the elements of this cell begin.
35    }GridCell_t;
36    
37    typedef struct {
38        uint32_t handle;    // the index into of the next free grid item in the pool;
39        uint32_t poolSize;  // the number of elements in the pool;
40        GridItem_t * pool;  // the pool of grid items.
41    }GridPool_t;
42    
43  //GridContext -> Information about the grid  //GridContext -> Information about the grid
44  typedef struct GridCtx2D {  typedef struct GridCtx2D {
# Line 37  Line 46 
46     uint32_t numberOfStrands;               // The nuber of strands in execution     uint32_t numberOfStrands;               // The nuber of strands in execution
47     Diderot_vec2_t * cellSize;             // The size of each cell in the grid     Diderot_vec2_t * cellSize;             // The size of each cell in the grid
48     Diderot_vec4_t  * window;              // The window dimensions (XMin,XMax,YMin,YMax)     Diderot_vec4_t  * window;              // The window dimensions (XMin,XMax,YMin,YMax)
49     StrandItem_t ** grid;                   // the number of strands in each grid cell.      GridPool_t gridPool;         // The pool of grid items for the grid.
50  } GridContext2D;      GridCell_t * grid;           // The uniform grid cells array.
51    }Grid2D_t;
52    
53  typedef struct GridCtx3D {  typedef struct GridCtx3D {
54      Diderot_vec3_t * gridSize;    // the size(s) of the spatial grid structure      Diderot_vec3_t * gridSize;    // the size(s) of the spatial grid structure
55      uint32_t numberOfStrands;      // The nuber of strands in execution      uint32_t numberOfStrands;      // The nuber of strands in execution
56      Diderot_vec3_t * cellSize;     // The size of each cell in the grid      Diderot_vec3_t * cellSize;     // The size of each cell in the grid
57      Diderot_vec6_t * window;       // The window dimensions (XMin,XMax,YMin,YMax,ZMin,ZMax)      Diderot_vec6_t * window;       // The window dimensions (XMin,XMax,YMin,YMax,ZMin,ZMax)
58      StrandItem_t ** grid;          // the number of strands in each grid cell.     GridPool_t gridPool;         // The pool of grid items for the grid.
59  } GridContext3D;     GridCell_t * grid;           // The uniform grid cells array.
60    }Grid3D_t;
   
61    
62    
63  STATIC_INLINE bool isWithinRadius2D( Diderot_vec2_t  particle,  Diderot_vec2_t neighbor, int radius) {  STATIC_INLINE bool isWithinRadius2D( Diderot_vec2_t  particle,  Diderot_vec2_t neighbor, int radius) {
# Line 60  Line 69 
69    
70  STATIC_INLINE Diderot_int_t clamp_int(Diderot_int_t x, Diderot_int_t a, Diderot_int_t b)  STATIC_INLINE Diderot_int_t clamp_int(Diderot_int_t x, Diderot_int_t a, Diderot_int_t b)
71  {  {
72      return x < a ? (a + 1) : (x > b ? (b + 1) : x);      return x < a ?  a : (x > b ? (b + 1) : (x + 1));
73  }  }
74  STATIC_INLINE Diderot_ivec2_t clampToGrid2D(GridContext2D * ctx, Diderot_ivec2_t cell) {  STATIC_INLINE Diderot_ivec2_t clampToGrid2D(Grid2D_t * ctx, Diderot_ivec2_t cell) {
75    
76      Diderot_iunion2_t u;      Diderot_iunion2_t u;
77      u.v = cell;      u.v = cell;
# Line 73  Line 82 
82      return vec2i(clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1),      return vec2i(clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1),
83                   clamp_int(u.i[1],0,(Diderot_int_t)v.r[1] -1));                   clamp_int(u.i[1],0,(Diderot_int_t)v.r[1] -1));
84  }  }
85  STATIC_INLINE Diderot_vec2_t worldToGrid2D(Diderot_vec2_t p, GridContext2D * ctx){  STATIC_INLINE Diderot_vec2_t worldToGrid2D(Diderot_vec2_t p, Grid2D_t * ctx){
86    
87      Diderot_union2_t pos;      Diderot_union2_t pos;
88      pos.v = p;      pos.v = p;
# Line 90  Line 99 
99      Diderot_real_t gridWidth = cellSize.r[0] * gridSize.r[0];      Diderot_real_t gridWidth = cellSize.r[0] * gridSize.r[0];
100      Diderot_real_t gridHeight = cellSize.r[1] * gridSize.r[1];      Diderot_real_t gridHeight = cellSize.r[1] * gridSize.r[1];
101    
102    
103      Diderot_real_t x = (pos.r[0] - winSize.r[XMIN]) * gridWidth / (winSize.r[XMAX] - winSize.r[XMIN]);      Diderot_real_t x = (pos.r[0] - winSize.r[XMIN]) * gridWidth / (winSize.r[XMAX] - winSize.r[XMIN]);
104      Diderot_real_t y = (pos.r[1] - winSize.r[YMAX]) * gridHeight / (winSize.r[YMAX] - winSize.r[YMIN]);      Diderot_real_t y = (pos.r[1] - winSize.r[YMAX]) * -gridHeight / (winSize.r[YMAX] - winSize.r[YMIN]);
105    
106    
107      return vec2(x,y);      return vec2(x,y);
108  }  }
109  STATIC_INLINE Diderot_ivec2_t worldToCell(Diderot_vec2_t p, GridContext2D * ctx){  STATIC_INLINE Diderot_ivec2_t worldToCell(Diderot_vec2_t p, Grid2D_t * ctx){
110    
111      Diderot_union2_t u;      Diderot_union2_t u;
112      u.v = worldToGrid2D(p,ctx);      u.v = worldToGrid2D(p,ctx);
# Line 105  Line 116 
116    
117     return clampToGrid2D(ctx,vec2rtoi(vec2(floor(u.r[0] /v.r[0]),floor(u.r[1]/v.r[1]))));     return clampToGrid2D(ctx,vec2rtoi(vec2(floor(u.r[0] /v.r[0]),floor(u.r[1]/v.r[1]))));
118  }  }
119  STATIC_INLINE uint32_t worldToGridIdx(Diderot_vec2_t p, GridContext2D * ctx){  STATIC_INLINE uint32_t worldToGridIdx2D(Diderot_vec2_t p, Grid2D_t * ctx){
120    
121      Diderot_ivec2_t cell = worldToCell(p,ctx);      Diderot_ivec2_t cell = worldToCell(p,ctx);
122    
# Line 115  Line 126 
126      Diderot_union2_t gridSize;      Diderot_union2_t gridSize;
127      gridSize.v = *(ctx->gridSize);      gridSize.v = *(ctx->gridSize);
128    
129     return UMAD(u.i[1],(Diderot_int_t)gridSize.r[1],u.i[0]);     return UMAD(u.i[1],((Diderot_int_t)gridSize.r[1] + 2),u.i[0]);
130  }  }
131  /* FIXME: Need to update the 3D functions to work once the 2D versions work */  /* FIXME: Need to update the 3D functions to work once the 2D versions work */
132  STATIC_INLINE Diderot_ivec3_t worldToGrid3D(Diderot_vec3_t p, GridContext3D * ctx){  STATIC_INLINE Diderot_ivec3_t worldToGrid3D(Diderot_vec3_t p, Grid3D_t * ctx){
133    
134      Diderot_union3_t u;      Diderot_union3_t u;
135      u.v = p;      u.v = p;
# Line 130  Line 141 
141                      floor(u.r[1]/v.r[1]),                      floor(u.r[1]/v.r[1]),
142                      floor(u.r[2] /v.r[2])));                      floor(u.r[2] /v.r[2])));
143  }  }
144  STATIC_INLINE  Diderot_ivec3_t  clampToGrid3D(GridContext3D * ctx,  Diderot_ivec3_t  cell) {  STATIC_INLINE  Diderot_ivec3_t  clampToGrid3D(Grid3D_t * ctx,  Diderot_ivec3_t  cell) {
145    
146      Diderot_iunion3_t u;      Diderot_iunion3_t u;
147      u.v = cell;      u.v = cell;

Legend:
Removed from v.2190  
changed lines
  Added in v.2191

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