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

SCM Repository

[diderot] View of /branches/lamont/src/lib/common/grid.c
ViewVC logotype

View of /branches/lamont/src/lib/common/grid.c

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: 3053 byte(s)
Commiting 3D grid work
/*! \file dyn-seq.c
 *
 * \author Lamont Samuels
 *
 * An implementation of the uniform grid. 
 */

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

#include "Diderot/diderot.h"

Diderot_vec2_t worldToGrid2D(Diderot_vec2_t p, Grid2D_t * ctx)
{

    Diderot_union2_t pos; 
    pos.v = p; 

    Diderot_union2_t cellSize; 
    cellSize.v = *(ctx->cellSize); 

    Diderot_union4_t winSize; 
    winSize.v = *(ctx->window); 

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

    Diderot_real_t gridWidth = cellSize.r[0] * gridSize.r[0]; 
    Diderot_real_t gridHeight = cellSize.r[1] * gridSize.r[1]; 


    Diderot_real_t x = (pos.r[0] - winSize.r[XMIN]) * gridWidth / (winSize.r[XMAX] - winSize.r[XMIN]); 
    Diderot_real_t y = (pos.r[1] - winSize.r[YMAX]) * -gridHeight / (winSize.r[YMAX] - winSize.r[YMIN]); 

    return vec2(x,y); 
}

Diderot_ivec2_t worldToCell(Diderot_vec2_t p, Grid2D_t * ctx)
{

    Diderot_union2_t u; 
    u.v = worldToGrid2D(p,ctx);

    Diderot_union2_t v; 
    v.v = *(ctx->cellSize); 

   return clampToGrid2D(ctx,vec2rtoi(vec2(floor(u.r[0] /v.r[0]),floor(u.r[1]/v.r[1]))));
}

uint32_t worldToGridIdx2D(Diderot_vec2_t p, Grid2D_t * ctx)
{

    Diderot_ivec2_t cell = worldToCell(p,ctx);

    Diderot_iunion2_t u;
    u.v = cell;

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

   return UMAD(u.i[1],((Diderot_int_t)gridSize.r[0] + 2),u.i[0]);
}

Diderot_vec3_t worldToGrid3D(Diderot_vec3_t p, Grid3D_t * ctx)
{

    Diderot_union3_t pos; 
    pos.v = p; 

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

    Diderot_union6_t winSize; 
    winSize.v = *(ctx->window); 

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

    Diderot_real_t gridWidth = cellSize.r[0] * gridSize.r[0]; 
    Diderot_real_t gridHeight = cellSize.r[1] * gridSize.r[1]; 
    Diderot_real_t gridDepth = cellSize.r[2] * gridSize.r[2]; 

    Diderot_real_t x = (pos.r[0] - winSize.r[XMIN]) * gridWidth / (winSize.r[XMAX] - winSize.r[XMIN]); 
    Diderot_real_t y = (pos.r[1] - winSize.r[YMAX]) * -gridHeight / (winSize.r[YMAX] - winSize.r[YMIN]); 
    Diderot_real_t z = (pos.r[2] - winSize.r[ZMIN]) * gridDepth / (winSize.r[ZMAX] - winSize.r[ZMIN]);  

    return vec3(x,y,z); 
}
Diderot_ivec3_t worldToCell3D(Diderot_vec3_t p, Grid3D_t * ctx)
{

    Diderot_union3_t u; 
    u.v = worldToGrid3D(p,ctx);

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

   return clampToGrid3D(ctx,vec3rtoi(vec3(floor(u.r[0] /v.r[0]),
                                          floor(u.r[1]/v.r[1]), 
                                          floor(u.r[2]/v.r[2]))));
}
uint32_t worldToGridIdx3D(Diderot_vec3_t p, Grid3D_t * ctx)
{

    Diderot_ivec3_t cell = worldToCell3D(p,ctx);

    Diderot_iunion3_t u;
    u.v = cell;

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

    return UMAD(UMAD(u.i[1],((Diderot_int_t)gridSize.r[0] + 2),u.i[0]),((Diderot_int_t)gridSize.r[1] + 2),u.i[2]);
}

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