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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 2416 - (download) (as text) (annotate)
Mon Aug 19 12:57:45 2013 UTC (7 years, 1 month ago) by lamonts
File size: 2469 byte(s)
Adding KDTree code for c-tagert and parallel c-target
/*! \file grid.h
 * \author Lamont Samuels
 * This is includes the structure of and functions for the KDTree. 

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

#ifndef _KDTREE_H_
#define _KDTREE_H_

#  include "Diderot/types.h"

#define MAX_KD_DIM 3 
#define POOL_INCR_SIZE 100

typedef struct KDNode {
    uint32_t        strandId;			// the unique identification number for a strand  
    struct KDNode   *left, *right;       // the left and right hand sides of the node  
} KDNode_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; 
    KDNode_t *pool;   	               // the pool of grid nodes. 
} KDPool_t;

//KDTree_t -> Information about the tree 
typedef struct{
    uint32_t	 *numOfStrands;        // The nuber of strands in execution
    uint32_t  dim;				        // the dimension of the tree 
    KDPool_t  treePool;               	// The pool of KDNodes for the grid. 
    KDNode_t  *root;                  // The root of the tree. 

STATIC_INLINE bool isWithinRadius1D( Diderot_real_t  particle,  Diderot_real_t neighbor, Diderot_real_t radius, uint32_t dim)
    Diderot_real_t squared_r = radius * radius; 
	Diderot_real_t squared_dist = (particle-neighbor) * (particle-neighbor); 

 	return squared_dist <= squared_r; 
STATIC_INLINE bool isWithinRadius2D( Diderot_vec2_t  particle,  Diderot_vec2_t neighbor, Diderot_real_t radius) { 

    Diderot_real_t squared_r = radius * radius; 

	Diderot_union2_t uv = __extension__ (Diderot_union2_t)(((particle-neighbor) * (particle-neighbor)));
    Diderot_real_t squared_dist = uv.r[0] + uv.r[1];

	return squared_dist <= squared_r; 
STATIC_INLINE bool isWithinRadius3D(Diderot_vec3_t  particle,  Diderot_vec3_t neighbor, Diderot_real_t radius) { 

    Diderot_real_t squared_r = radius * radius; 

	Diderot_union3_t uv = __extension__ (Diderot_union3_t)((particle-neighbor) * (particle-neighbor));
    Diderot_real_t squared_dist = uv.r[0] + uv.r[1] + uv.r[2]; 

	return squared_dist <= squared_r; 

void Diderot_KDTree_Alloc(KDTree_t ** tree,  uint32_t * numOfStrands, uint32_t dim); 
KDNode_t * Diderot_KDTree_GrabNode( KDTree_t * tree); 
void Diderot_KDTree_PoolClear( KDTree_t * tree); 

#endif /* _KDTREE_H_ */ 

ViewVC Help
Powered by ViewVC 1.0.0