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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (download) (as text) (annotate)
Tue Mar 19 20:17:15 2013 UTC (6 years, 10 months ago) by lamonts
File size: 3744 byte(s)
Commiting 3D grid work
/*! \file grid.h
 *
 * \author Lamont Samuels
 *
 * This is includes the structure of the uniform grid on the CPU and functions for calculating cell indicies for strand positions.
 */

/*
 * COPYRIGHT (c) 2013 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#ifndef _GRID_H_
#define _GRID_H_

#ifndef _DIDEROT_TYPES_H_
#  include "Diderot/types.h"
#endif

#define UMAD(a, b, c)  ( (a) * (b) + (c) )

#define XMIN 0 
#define XMAX 1 
#define YMIN 2
#define YMAX 3 
#define ZMAX 4
#define ZMIN 5 

//GridItem_t
typedef struct {
    uint32_t strandId;  // the unique identification number for a strand  
    uint32_t next;      // the next strand item in the list 
} GridItem_t;

typedef struct {
    uint32_t poolIdx;   // the index into the pool where the elements of this cell begin. 
} GridCell_t;   

typedef struct { 
    uint32_t handle;    // the index into of the next free grid item in the pool; 
    uint32_t poolSize;  // the number of elements in the pool; 
    GridItem_t *pool;   // the pool of grid items. 
} GridPool_t;

//GridContext -> Information about the grid 
typedef struct GridCtx2D{
    Diderot_vec2_t      *gridSize;              // the size(s) of the spatial grid structure
    uint32_t            numberOfStrands;        // The nuber of strands in execution
    Diderot_vec2_t      *cellSize;              // The size of each cell in the grid
    Diderot_vec4_t      *window;                // The window dimensions (XMin,XMax,YMin,YMax)
    GridPool_t          gridPool;               // The pool of grid items for the grid. 
    GridCell_t          *grid;                  // The uniform grid cells array. 
} Grid2D_t; 

typedef struct GridCtx3D{
    Diderot_vec3_t *  gridSize;   // the size(s) of the spatial grid structure
    uint32_t numberOfStrands;    // The nuber of strands in execution
    Diderot_vec3_t * cellSize;   // The size of each cell in the grid
    Diderot_vec6_t * window;     // The window dimensions (XMin,XMax,YMin,YMax,ZMin,ZMax)
    GridPool_t gridPool;         // The pool of grid items for the grid.  
    GridCell_t * grid;           // The uniform grid cells array.   
} Grid3D_t;


STATIC_INLINE bool isWithinRadius2D( Diderot_vec2_t  particle,  Diderot_vec2_t neighbor, float radius)
{
    return dist2(particle,neighbor) <= radius;
}
STATIC_INLINE bool isWithinRadius3D( Diderot_vec3_t  particle,  Diderot_vec3_t neighbor, float radius)
{
    return dist3(particle,neighbor) <= radius;
}

STATIC_INLINE Diderot_int_t clamp_int(Diderot_int_t x, Diderot_int_t a, Diderot_int_t b)
{
    return x < a ?  a : (x > b ? (b + 1) : (x + 1));
}
STATIC_INLINE Diderot_ivec2_t clampToGrid2D(Grid2D_t * ctx, Diderot_ivec2_t cell)
{

    Diderot_iunion2_t u;
    u.v = cell;
    
    Diderot_union2_t v;
    v.v = *(ctx->gridSize);   

    return vec2i(clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1),
                 clamp_int(u.i[1],0,(Diderot_int_t)v.r[1]- 1));
}

STATIC_INLINE Diderot_ivec3_t clampToGrid3D(Grid3D_t * ctx, Diderot_ivec3_t cell)
{

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

    return vec3i(clamp_int(u.i[0],0,(Diderot_int_t)v.r[0] -1),
                 clamp_int(u.i[1],0,(Diderot_int_t)v.r[1]- 1), 
                 clamp_int(u.i[2],0,(Diderot_int_t)v.r[2]- 1));
}

Diderot_vec2_t worldToGrid2D (Diderot_vec2_t p, Grid2D_t *ctx); 
Diderot_ivec2_t worldToCell (Diderot_vec2_t p, Grid2D_t *ctx); 
uint32_t worldToGridIdx2D (Diderot_vec2_t p, Grid2D_t *ctx);

Diderot_ivec3_t worldToCell3D(Diderot_vec3_t p, Grid3D_t * ctx);
Diderot_vec3_t worldToGrid3D(Diderot_vec3_t p, Grid3D_t * ctx); 
uint32_t worldToGridIdx3D(Diderot_vec3_t p, Grid3D_t * ctx); 

#endif /* _GRID_H_ */ 

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