BRL-CAD
tie.h
Go to the documentation of this file.
1 /* T I E . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file tie.h
21  *
22  *
23  */
24 
25 #ifndef RT_TIE_H
26 #define RT_TIE_H
27 
28 #include "common.h"
29 
30 #include "vmath.h"
31 
32 __BEGIN_DECLS
33 
34 #ifndef RT_EXPORT
35 # if defined(RT_DLL_EXPORTS) && defined(RT_DLL_IMPORTS)
36 # error "Only RT_DLL_EXPORTS or RT_DLL_IMPORTS can be defined, not both."
37 # elif defined(RT_DLL_EXPORTS)
38 # define RT_EXPORT COMPILER_DLLEXPORT
39 # elif defined(RT_DLL_IMPORTS)
40 # define RT_EXPORT COMPILER_DLLIMPORT
41 # else
42 # define RT_EXPORT
43 # endif
44 #endif
45 
46 /*
47  * define which precision to use, 0 is 'float' and 1 is 'double'.
48  * Horrible macros wrap functions and values to build a library
49  * capable of doing either without recompilation.
50  */
51 #ifndef TIE_PRECISION
52 # define TIE_PRECISION 1
53 #endif
54 
55 #define TIE_CHECK_DEGENERATE 1
56 
57 #define TIE_KDTREE_FAST 0x0
58 #define TIE_KDTREE_OPTIMAL 0x1
59 
60 /* Type to use for floating precision */
61 #if TIE_PRECISION == 0
62 typedef float TFLOAT;
63 # define TIE_VAL(x) CPP_GLUE(x, _single)
64 #elif TIE_PRECISION == 1
65 typedef double TFLOAT;
66 # define TIE_VAL(x) CPP_GLUE(x, _double)
67 #else
68 # error "Unknown precision"
69 #endif
70 
71 
72 /* TCOPY(type, source base, source offset, dest base, dest offset) */
73 #define TCOPY(_t, _fv, _fi, _tv, _ti) { \
74  *(_t *)&((uint8_t *)_tv)[_ti] = *(_t *)&((uint8_t *)_fv)[_fi]; }
75 
76 typedef struct TIE_3_s {
77  TFLOAT v[3]; /* 12-bytes or 24-bytes */
79 
80 struct tie_ray_s {
81  point_t pos; /* 24-bytes, Position */
82  vect_t dir; /* 24-bytes, Direction */
83  short depth; /* 2-bytes, Depth */
84  short kdtree_depth; /* 2-bytes */
85 };
86 
87 struct tie_id_s {
88  point_t pos; /* 24-bytes, Point */
89  vect_t norm; /* 24-bytes, Normal */
90  fastf_t dist; /* 8-bytes, Distance */
91  fastf_t alpha; /* 8-bytes, Barycentric Coordinate Alpha */
92  fastf_t beta; /* 8-bytes, Barycentric Coordinate Beta */
93 };
94 
95 struct tie_tri_s {
96  TIE_3 data[3]; /* 12*3=36-bytes or 24*3=72-bytes,
97  *
98  * Data[0] = Point,
99  * Data[1] = Normal,
100  * Data[2] = DotProduct, VectorU, VectorV
101  */
102  TFLOAT v[2]; /* 8-bytes or 16-bytes */
103  void *ptr; /* 4-bytes or 8-bytes */
104  uint32_t b; /* 4-bytes (way more than we need, but helps keep alignment) */
105 };
106 
107 struct tie_kdtree_s {
108  float axis; /* 4-bytes, intentionally float */
109  uint32_t b; /* 4-bytes, bit array to store data about the kdtree node */
110  void *data; /* 4-bytes or 8-bytes */
111 };
112 
113 
114 struct tie_s {
115  uint64_t rays_fired;
117  unsigned int max_depth; /* Maximum depth allowed for given geometry */
118  unsigned int tri_num;
119  unsigned int tri_num_alloc;
121  int stat; /* used for testing various statistics */
122  unsigned int kdmethod; /* Optimal or Fast */
126 };
127 
128 RT_EXPORT extern int tie_check_degenerate;
129 RT_EXPORT extern fastf_t TIE_PREC;
130 
131 #define TIE_INIT TIE_VAL(tie_init)
132 #define TIE_FREE TIE_VAL(tie_free)
133 #define TIE_PREP TIE_VAL(tie_prep)
134 #define TIE_WORK TIE_VAL(tie_work)
135 #define TIE_PUSH TIE_VAL(tie_push)
136 #define TIE_KDTREE_PREP TIE_VAL(tie_kdtree_prep)
137 #define TIE_KDTREE_FREE TIE_VAL(tie_kdtree_free)
138 
139 RT_EXPORT extern void TIE_INIT(struct tie_s *tie, unsigned int tri_num, unsigned int kdmethod);
140 RT_EXPORT extern void TIE_FREE(struct tie_s *tie);
141 RT_EXPORT extern void TIE_PREP(struct tie_s *tie);
142 RT_EXPORT extern void*TIE_WORK(struct tie_s *tie, struct tie_ray_s *ray, struct tie_id_s *id, void *(*hitfunc)(struct tie_ray_s*, struct tie_id_s*, struct tie_tri_s*, void *ptr), void *ptr);
143 RT_EXPORT extern void TIE_PUSH(struct tie_s *tie, TIE_3 **tlist, unsigned int tnum, void *plist, unsigned int pstride);
144 RT_EXPORT extern void TIE_KDTREE_FREE(struct tie_s *tie);
145 RT_EXPORT extern void TIE_KDTREE_PREP(struct tie_s *tie);
146 
147 __END_DECLS
148 
149 #endif /* RT_TIE_H */
150 
151 /*
152  * Local Variables:
153  * tab-width: 8
154  * mode: C
155  * indent-tabs-mode: t
156  * c-file-style: "stroustrup"
157  * End:
158  * ex: shiftwidth=4 tabstop=8
159  */
Header file for the BRL-CAD common definitions.
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition: vmath.h:349
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:334
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:355
Definition: tie.h:76
TFLOAT v[3]
Definition: tie.h:77
Definition: tie.h:87
fastf_t alpha
Definition: tie.h:91
vect_t norm
Definition: tie.h:89
fastf_t dist
Definition: tie.h:90
fastf_t beta
Definition: tie.h:92
point_t pos
Definition: tie.h:88
uint32_t b
Definition: tie.h:109
void * data
Definition: tie.h:110
float axis
Definition: tie.h:108
Definition: tie.h:80
short depth
Definition: tie.h:83
point_t pos
Definition: tie.h:81
vect_t dir
Definition: tie.h:82
short kdtree_depth
Definition: tie.h:84
Definition: tie.h:114
unsigned int kdmethod
Definition: tie.h:122
fastf_t radius
Definition: tie.h:125
point_t max
Definition: tie.h:123
unsigned int max_depth
Definition: tie.h:117
uint64_t rays_fired
Definition: tie.h:115
vect_t amin
Definition: tie.h:124
int stat
Definition: tie.h:121
vect_t amax
Definition: tie.h:124
struct tie_tri_s * tri_list
Definition: tie.h:120
struct tie_kdtree_s * kdtree
Definition: tie.h:116
vect_t mid
Definition: tie.h:124
unsigned int tri_num
Definition: tie.h:118
unsigned int tri_num_alloc
Definition: tie.h:119
point_t min
Definition: tie.h:123
Definition: tie.h:95
uint32_t b
Definition: tie.h:104
TIE_3 data[3]
Definition: tie.h:96
TFLOAT v[2]
Definition: tie.h:102
void * ptr
Definition: tie.h:103
int tie_check_degenerate
#define TIE_WORK
Definition: tie.h:134
#define TIE_KDTREE_PREP
Definition: tie.h:136
double TFLOAT
Definition: tie.h:65
#define TIE_FREE
Definition: tie.h:132
struct TIE_3_s TIE_3
fastf_t TIE_PREC
#define TIE_PUSH
Definition: tie.h:135
#define TIE_KDTREE_FREE
Definition: tie.h:137
#define TIE_INIT
Definition: tie.h:131
#define TIE_PREP
Definition: tie.h:133
fundamental vector, matrix, quaternion math macros