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 2848 - (download) (as text) (annotate)
Mon Dec 15 04:50:29 2014 UTC (4 years, 10 months ago) by lamonts
File size: 2316 byte(s)
Fixed a few bugs in the parallel kd-tree example
/*! \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_

#ifndef _DIDEROT_TYPES_H_
#  include "Diderot/types.h"
#endif
#ifndef _DIDEROT_INLINE_VEC2_H_
#  include "Diderot/inline-vec2.h"
#endif
#ifndef _DIDEROT_INLINE_VEC3_H_
#  include "Diderot/inline-vec3.h"
#endif

#define MAX_KD_DIM 3 
#define POOL_INCR_SIZE 100
//#define SPATIAL_SEQ_THERSHOLD 2048

//KDNode_t
typedef struct struct_kdnode KDNode_t;
struct struct_kdnode {
    uint32_t	 strandId;		// the unique identification number for a strand
    struct struct_kdnode 	*left; 
    struct struct_kdnode     *right;	// the left and right hand sides of the node  
     /* Tree Building Info */ 
    uint32_t len;              // the len of the array 
    uint32_t axis;             // the axis of the node 
    uint32_t start;            // the starting parameter   
};

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. 
} KDTree_t; 

STATIC_INLINE bool isWithinRadius1D (Diderot_real_t particle, Diderot_real_t neighbor, Diderot_real_t radius)
{
    return ABS(particle - neighbor) <= radius; 
}

STATIC_INLINE bool isWithinRadius2D (Diderot_vec2_t particle, Diderot_vec2_t neighbor, Diderot_real_t radius)
{ 
    return lengthSq2(particle - neighbor) <= (radius * radius); 
}

STATIC_INLINE bool isWithinRadius3D (Diderot_vec3_t particle, Diderot_vec3_t neighbor, Diderot_real_t radius)
{
    return lengthSq3(particle - neighbor) <= (radius * radius); 
}

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_ */ 

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