BRL-CAD
uv.h
Go to the documentation of this file.
1/* U V . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2019-2023 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 uv.h
21 *
22 * This file is API pertaining to uv parameterization on objects.
23 *
24 */
25
26
27#ifndef RT_UV_H
28#define RT_UV_H
29
30
31#include "common.h"
32
33#include "bu/vls.h"
34#include "bu/mapped_file.h"
35#include "vmath.h"
36#include "rt/geom.h"
37#include "rt/functab.h"
38
39
40__BEGIN_DECLS
41
42
43/*
44 * // Setup:
45 *
46 * RT_APPLICATION_INIT();
47 * rt_dirbuild();
48 * rt_gettree();
49 * rt_prep();
50 * rt_texture_load(); // load texture image(s)
51 *
52 * // Shoot:
53 *
54 * rt_shootray();
55 *
56 * // Lookup:
57 *
58 * RT_HIT_UV(); // get UV-coordinate
59 * rt_texture_lookup(); // get corresponding data
60 *
61 */
62
63
64/**
65 * This is a ray tracing texture image context. Basically, it's a
66 * handle to an image stored in a file or in a database object with
67 * additional parameters specific to a given ray tracing use such as
68 * scaling and mirroring.
69 *
70 * TODO: replace txt_specific in liboptical
71 */
72struct rt_texture {
73 struct bu_vls tx_name; /* name of object or file (depending on tx_datasrc flag) */
74 int tx_w; /* Width of texture in pixels */
75 int tx_n; /* Number of scanlines */
76 int tx_trans_valid; /* boolean: is tx_transp valid ? */
77 int tx_transp[3]; /* RGB for transparency */
78 fastf_t tx_scale[2]; /* replication factors in U, V */
79 int tx_mirror; /* flag: repetitions are mirrored */
80#define TXT_SRC_FILE 'f'
81#define TXT_SRC_OBJECT 'o'
82#define TXT_SRC_AUTO 0
83 char tx_datasrc; /* which type of datasource */
84
85 /* internal state */
86 struct rt_binunif_internal *tx_binunifp; /* db internal object when TXT_SRC_OBJECT */
87 struct bu_mapped_file *tx_mp; /* mapped file when TXT_SRC_FILE */
88};
89
90
91/**
92 * initialize an rt_texture to zero
93 */
94#define RT_TEXTURE_INIT_ZERO {{0,0,0}, BU_VLS_INIT_ZERO, 0, 0, 0, {0.0, 0.0}, 0, 0, NULL, NULL}
95
96
97/**
98 * loads a texture from either a file or database object.
99 *
100 * TODO: replace txt_load_datasource in liboptical
101 */
102RT_EXPORT int
103rt_texture_load(struct rt_texture *tp, const char *name, struct db_i *dbip);
104
105
106/**
107 * As rt_shootray() only calculates hit points and returns a list of
108 * partitions, applications must request that the corresponding UV
109 * coordinate be computed via: RT_HIT_UV(NULL, hitp, stp, rayp, 0);
110 *
111 * These calculations are deferred to user code to avoid needless
112 * computation in other ray situations.
113 */
114#define RT_HIT_UV(_ap, _stp, _hitp, _uvp) { \
115 RT_CK_HIT(_hitp); \
116 RT_CK_SOLTAB(_stp); \
117 RT_CK_FUNCTAB((_stp)->st_meth); \
118 if ((_stp)->st_meth->ft_uv) { \
119 (_stp)->st_meth->ft_uv(ap, _stp, _hitp, uvp); \
120 } \
121 }
122
123
124/* TODO: move from liboptical */
125struct uvcoord;
126
127
128/**
129 * Given a uv coordinate (0.0 <= u, v <= 1.0) and a texture, return a
130 * pointer to the corresponding texture data (as a fastf_t[3]).
131 *
132 * TODO: replace txt_render in liboptical
133 */
134RT_EXPORT int
135rt_texture_lookup(fastf_t *data, const struct rt_texture *tp, const struct uvcoord *uvp);
136
137
138__END_DECLS
139
140
141#endif
142
143
144/*
145 * Local Variables:
146 * tab-width: 8
147 * mode: C
148 * indent-tabs-mode: t
149 * c-file-style: "stroustrup"
150 * End:
151 * ex: shiftwidth=4 tabstop=8
152 */
Header file for the BRL-CAD common definitions.
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330
Definition: vls.h:53
Definition: uv.h:72
int tx_transp[3]
Definition: uv.h:77
int tx_mirror
Definition: uv.h:79
struct bu_mapped_file * tx_mp
Definition: uv.h:87
int tx_w
Definition: uv.h:74
struct bu_vls tx_name
Definition: uv.h:73
fastf_t tx_scale[2]
Definition: uv.h:78
int tx_trans_valid
Definition: uv.h:76
char tx_datasrc
Definition: uv.h:83
int tx_n
Definition: uv.h:75
struct rt_binunif_internal * tx_binunifp
Definition: uv.h:86
Definition: hit.h:152
int rt_texture_load(struct rt_texture *tp, const char *name, struct db_i *dbip)
int rt_texture_lookup(fastf_t *data, const struct rt_texture *tp, const struct uvcoord *uvp)
fundamental vector, matrix, quaternion math macros