00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef lint
00040 static const char librt_htbl_RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/htbl.c,v 14.10 2006/09/16 02:04:25 lbutler Exp $ (ARL)";
00041 #endif
00042
00043 #include "common.h"
00044
00045
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include "machine.h"
00049 #include "bu.h"
00050 #include "vmath.h"
00051 #include "raytrace.h"
00052
00053
00054
00055
00056 void
00057 rt_htbl_init(struct rt_htbl *b, int len, const char *str)
00058
00059
00060
00061 {
00062 if (bu_debug & BU_DEBUG_PTBL)
00063 bu_log("rt_htbl_init(%8x, len=%d, %s)\n", b, len, str);
00064 BU_LIST_INIT(&b->l);
00065 b->l.magic = RT_HTBL_MAGIC;
00066 if( len <= 0 ) len = 64;
00067 b->blen = len;
00068 b->hits = (struct hit *)bu_calloc(b->blen, sizeof(struct hit), str);
00069 b->end = 0;
00070 }
00071
00072
00073
00074
00075
00076
00077 void
00078 rt_htbl_reset(struct rt_htbl *b)
00079 {
00080 RT_CK_HTBL(b);
00081 b->end = 0;
00082 if (bu_debug & BU_DEBUG_PTBL)
00083 bu_log("rt_htbl_reset(%8x)\n", b);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 void
00093 rt_htbl_free(struct rt_htbl *b)
00094 {
00095 RT_CK_HTBL(b);
00096
00097 bu_free((genptr_t)b->hits, "rt_htbl.hits[]");
00098 bzero((char *)b, sizeof(struct rt_htbl));
00099
00100 if (bu_debug & BU_DEBUG_PTBL)
00101 bu_log("rt_htbl_free(%8x)\n", b);
00102 }
00103
00104
00105
00106
00107
00108
00109 struct hit *
00110 rt_htbl_get(struct rt_htbl *b)
00111 {
00112 RT_CK_HTBL(b);
00113
00114 if( b->end >= b->blen ) {
00115
00116 b->hits = (struct hit *)bu_realloc( (char *)b->hits,
00117 sizeof(struct hit) * (b->blen *= 4),
00118 "rt_htbl.hits[]" );
00119 }
00120
00121
00122 return &b->hits[b->end++];
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133