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 2161, Wed Feb 20 04:32:27 2013 UTC revision 2162, Thu Feb 21 04:59:17 2013 UTC
# Line 2  Line 2 
2   *   *
3   * \author Lamont Samuels   * \author Lamont Samuels
4   *   *
5   * This is the interface for building and running a uniform grid on the CPU.   * This is includes the structure of the uniform grid on the CPU and functions for calculating cell indicies for strand positions.
6   */   */
7    
8  /*  /*
# Line 19  Line 19 
19    
20  #define UMAD(a, b, c)  ( (a) * (b) + (c) )  #define UMAD(a, b, c)  ( (a) * (b) + (c) )
21    
22    #define XMIN 0
23    #define XMAX 1
24    #define YMIN 2
25    #define YMAX 3
26    
27  //StrandItem_t -> Strand Id linked list node  //StrandItem_t -> Strand Id linked list node
28  typedef struct strandItem{  typedef struct strandItem{
29      uint32_t strandId;             //the unique identification number for a strand      uint32_t strandId;             //the unique identification number for a strand
# Line 28  Line 33 
33    
34  //GridContext -> Information about the grid  //GridContext -> Information about the grid
35  typedef struct GridCtx2D {  typedef struct GridCtx2D {
36     uint32_t gridSize[2];              // the size(s) of the spatial grid structure     Diderot_vec2_t * gridSize;            // the size(s) of the spatial grid structure
37     uint32_t numberOfStrands;             // The nuber of strands in execution     uint32_t numberOfStrands;             // The nuber of strands in execution
38     uint32_t cellSize[2];             // The size of each cell in the grid     Diderot_vec2_t * cellSize;             // The size of each cell in the grid
39       Diderot_vec4_t  * window;              // The window dimensions (XMin,XMax,YMin,YMax)
40     StrandItem_t ** grid;                 // the number of strands in each grid cell.     StrandItem_t ** grid;                 // the number of strands in each grid cell.
41  } GridContext2D;  } GridContext2D;
42    
43  typedef struct GridCtx3D {  typedef struct GridCtx3D {
44      uint32_t gridSize[3];              // the size(s) of the spatial grid structure      Diderot_vec3_t * gridSize;    // the size(s) of the spatial grid structure
45      uint32_t numberOfStrands;             // The nuber of strands in execution      uint32_t numberOfStrands;             // The nuber of strands in execution
46      uint32_t cellSize[3];             // The size of each cell in the grid      Diderot_vec3_t * cellSize;     // The size of each cell in the grid
47        Diderot_vec6_t * window;       // The window dimensions (XMin,XMax,YMin,YMax,ZMin,ZMax)
48      StrandItem_t ** grid;                 // the number of strands in each grid cell.      StrandItem_t ** grid;                 // the number of strands in each grid cell.
49  } GridContext3D;  } GridContext3D;
50    
51    
52    
53    
54  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) {
55      return dist2(particle,neighbor) <= radius;      return dist2(particle,neighbor) <= radius;
56  }  }
# Line 52  Line 60 
60    
61  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)
62  {  {
63      return x < a ? a : (x > b ? b : x);      return x < a ? (a + 1) : (x > b ? (b + 1) : x);
64  }  }
65    STATIC_INLINE Diderot_ivec2_t clampToGrid2D(GridContext2D * ctx, Diderot_ivec2_t cell) {
66    
67  STATIC_INLINE void worldToGrid2D(Diderot_vec2_t p, GridContext2D * ctx,int * cell){      Diderot_iunion2_t u;
68      uint32_t gridPos[2];      u.v = cell;
69      Diderot_union2_t u;  
70      u.v = p;      Diderot_union2_t v;
71        v.v = *(ctx->gridSize);
72    
73      cell[0] = (int)floor(u.r[0] /ctx->cellSize[0]);      return vec2i(clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1),
74      cell[1] = (int)floor(u.r[1]/ctx->cellSize[1]);                   clamp_int(u.i[1],0,(Diderot_int_t)v.r[1] -1));
75  }  }
76    STATIC_INLINE Diderot_vec2_t worldToGrid2D(Diderot_vec2_t p, GridContext2D * ctx){
77    
78  STATIC_INLINE void worldToGrid3D(Diderot_vec3_t p, GridContext3D * ctx,int * cell){      Diderot_union2_t pos;
79      uint32_t gridPos[2];      pos.v = p;
80      Diderot_union3_t u;  
81      u.v = p;      Diderot_union2_t cellSize;
82        cellSize.v = *(ctx->cellSize);
83    
84        Diderot_union4_t winSize;
85        winSize.v = *(ctx->window);
86    
87        Diderot_union2_t gridSize;
88        gridSize.v = *(ctx->gridSize);
89    
90        Diderot_real_t gridWidth = cellSize.r[0] * gridSize.r[0];
91        Diderot_real_t gridHeight = cellSize.r[1] * gridSize.r[1];
92    
93        Diderot_real_t x = (pos.r[0] - winSize.r[XMIN]) * gridWidth / (winSize.r[XMAX] - winSize.r[XMIN]);
94        Diderot_real_t y = (pos.r[1] - winSize.r[YMAX]) * gridHeight / (winSize.r[YMAX] - winSize.r[YMIN]);
95    
96      cell[0] = (int)floor(u.r[0] /ctx->cellSize[0]);      return vec2(x,y);
     cell[1] = (int)floor(u.r[1]/ctx->cellSize[1]);  
     cell[2] = (int)floor(u.r[2] /ctx->cellSize[2]);  
97  }  }
98    STATIC_INLINE Diderot_ivec2_t worldToCell(Diderot_vec2_t p, GridContext2D * ctx){
99    
100  STATIC_INLINE void clampToGrid2D(GridContext2D * ctx, int * cell) {      Diderot_union2_t u;
101        u.v = worldToGrid2D(p,ctx);
102    
103        Diderot_union2_t v;
104        v.v = *(ctx->cellSize);
105    
106      cell[0] = clamp_int(cell[0],0,ctx->gridSize[0] -1);     return clampToGrid2D(ctx,vec2rtoi(vec2(floor(u.r[0] /v.r[0]),floor(u.r[1]/v.r[1]))));
     cell[1] = clamp_int(cell[1],0,ctx->gridSize[1] -1);  
107  }  }
108    STATIC_INLINE uint32_t worldToGridIdx(Diderot_vec2_t p, GridContext2D * ctx){
109    
110        Diderot_ivec2_t cell = worldToCell(p,ctx);
111    
112        Diderot_iunion2_t u;
113        u.v = cell;
114    
115        Diderot_union2_t gridSize;
116        gridSize.v = *(ctx->gridSize);
117    
118       return UMAD(u.i[1],(Diderot_int_t)gridSize.r[1],u.i[0]);
119    }
120    /* FIXME: Need to update the 3D functions to work once the 2D versions work */
121    STATIC_INLINE Diderot_ivec3_t worldToGrid3D(Diderot_vec3_t p, GridContext3D * ctx){
122    
123        Diderot_union3_t u;
124        u.v = p;
125    
126        Diderot_union3_t v;
127        v.v = *(ctx->cellSize);
128    
129  STATIC_INLINE void clampToGrid3D(GridContext3D * ctx, int * cell) {      return vec3rtoi(vec3(floor(u.r[0] /v.r[0]),
130                        floor(u.r[1]/v.r[1]),
131                        floor(u.r[2] /v.r[2])));
132    }
133    STATIC_INLINE  Diderot_ivec3_t  clampToGrid3D(GridContext3D * ctx,  Diderot_ivec3_t  cell) {
134    
135        Diderot_iunion3_t u;
136        u.v = cell;
137    
138        Diderot_union3_t v;
139        v.v = *(ctx->gridSize);
140    
141        Diderot_int_t x = clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1);
142        Diderot_int_t y = clamp_int(u.i[1],0,(Diderot_int_t)v.r[1] -1);
143        Diderot_int_t z = clamp_int(u.i[2],0,(Diderot_int_t)v.r[2] -1);
144    
145        return __extension__ (Diderot_ivec3_t){
146                x,
147                y,
148                z,
149                0
150            };
151    
     cell[0] = clamp_int(cell[0],0,ctx->gridSize[0] -1);  
     cell[1] = clamp_int(cell[1],0,ctx->gridSize[1] -1);  
     cell[2] = clamp_int(cell[2],0,ctx->gridSize[2] -1);  
152  }  }
153    
154  #endif /* _GRID_H_ */  #endif /* _GRID_H_ */

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