BRL-CAD
spm.h
Go to the documentation of this file.
1/* S P M . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1986-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/** @addtogroup bn_sphmap
21 *
22 * @brief Sphere data structure and function declarations. Provides
23 * spherical data structures for texture mapping.
24 *
25 */
26/** @{ */
27/** @file spm.h */
28
29#ifndef BN_SPM_H
30#define BN_SPM_H
31
32#include "common.h"
33#include "bn/defines.h"
34
35typedef struct {
36 uint32_t magic;
37 int ny; /**< @brief Number of "y" bins */
38 int *nx; /**< @brief Number of "x" bins per "y" bin */
39 int elsize; /**< @brief Size of each bin element */
40 unsigned char **xbin; /**< @brief staring addresses of "x" bins */
41 unsigned char *_data; /**< @brief For freeing purposes, start of data */
43
44#define BN_SPM_MAP_NULL (bn_spm_map_t *)0
45#define BN_CK_SPM_MAP(_p) BU_CKMAG(_p, BN_SPM_MAGIC, "bn_spm_map_t")
46
47__BEGIN_DECLS
48
49/**
50 *@brief
51 * Return a sphere map structure initialized for N points around the
52 * equator.
53 *
54 * Malloc the storage and fill in the pointers. This code leaves a
55 * ring of "triangular" pixels at the poles. An alternative would be
56 * to have the pole region map to a single pixel.
57 *
58 * Returns BN_SPM_NULL on error.
59 */
60BN_EXPORT extern bn_spm_map_t *bn_spm_init(int N, int elsize);
61
62/**
63 *@brief
64 * Free the storage associated with a sphere structure.
65 */
66BN_EXPORT extern void bn_spm_free(bn_spm_map_t *mp);
67
68/**
69 *@brief
70 * Read the value of the pixel at the given normalized (u, v)
71 * coordinates. It does NOT check the sanity of the coords.
72 *
73 *@n 0.0 <= u < 1.0 Left to Right
74 *@n 0.0 <= v < 1.0 Bottom to Top
75 */
76BN_EXPORT extern void bn_spm_read(register bn_spm_map_t *mapp, register unsigned char *valp, double u, double v);
77
78/**
79 *@brief
80 * Write the value of the pixel at the given normalized (u, v)
81 * coordinates. It does NOT check the sanity of the coords.
82 *
83 *@n 0.0 <= u < 1.0 Left to Right
84 *@n 0.0 <= v < 1.0 Bottom to Top
85 */
86BN_EXPORT extern void bn_spm_write(register bn_spm_map_t *mapp, register unsigned char *valp, double u, double v);
87
88/**
89 *@brief
90 * Return a pointer to the storage element indexed by (u, v)
91 * coordinates. It does NOT check the sanity of the coords.
92 *
93 *@n 0.0 <= u < 1.0 Left to Right
94 *@n 0.0 <= v < 1.0 Bottom to Top
95 */
96BN_EXPORT extern char *bn_spm_get(register bn_spm_map_t *mapp, double u, double v);
97
98/**
99 *@brief
100 * Read a saved sphere map from a file ("-" for stdin) into the given
101 * map structure. This does not check for conformity of size, etc.
102 *
103 * @return -1 on error, else 0.
104 */
105BN_EXPORT extern int bn_spm_load(bn_spm_map_t *mapp, char *filename);
106
107/**
108 *@brief
109 * Write a loaded sphere map to the given file ("-" for stdout).
110 * Returns -1 on error, else 0.
111 */
112BN_EXPORT extern int bn_spm_save(bn_spm_map_t *mapp, char *filename);
113
114/**
115 *@brief
116 * Load an 'nx' by 'ny' pix file and filter it into the
117 * given sphere structure.
118 *
119 * @return -1 on error, else 0.
120 */
121BN_EXPORT extern int bn_spm_pix_load(bn_spm_map_t *mapp, char *filename, int nx, int ny);
122
123/**
124 *@brief
125 * Save a sphere structure as an 'nx' by 'ny' pix file.
126 * @return -1 on error, else 0.
127 */
128BN_EXPORT extern int bn_spm_pix_save(bn_spm_map_t *mapp, char *filename, int nx, int ny);
129
130/**
131 *@brief
132 * Display a sphere structure on stderr. Used for debugging.
133 */
134BN_EXPORT extern void bn_spm_dump(bn_spm_map_t *mp, int verbose);
135
136__END_DECLS
137
138#endif /* BN_SPM_H */
139
140/** @} */
141/*
142 * Local Variables:
143 * mode: C
144 * tab-width: 8
145 * indent-tabs-mode: t
146 * c-file-style: "stroustrup"
147 * End:
148 * ex: shiftwidth=4 tabstop=8
149 */
Header file for the BRL-CAD common definitions.
int bn_spm_load(bn_spm_map_t *mapp, char *filename)
Read a saved sphere map from a file ("-" for stdin) into the given map structure. This does not check...
bn_spm_map_t * bn_spm_init(int N, int elsize)
Return a sphere map structure initialized for N points around the equator.
void bn_spm_write(register bn_spm_map_t *mapp, register unsigned char *valp, double u, double v)
Write the value of the pixel at the given normalized (u, v) coordinates. It does NOT check the sanity...
int bn_spm_pix_load(bn_spm_map_t *mapp, char *filename, int nx, int ny)
Load an 'nx' by 'ny' pix file and filter it into the given sphere structure.
int bn_spm_save(bn_spm_map_t *mapp, char *filename)
Write a loaded sphere map to the given file ("-" for stdout). Returns -1 on error,...
char * bn_spm_get(register bn_spm_map_t *mapp, double u, double v)
Return a pointer to the storage element indexed by (u, v) coordinates. It does NOT check the sanity o...
void bn_spm_free(bn_spm_map_t *mp)
Free the storage associated with a sphere structure.
void bn_spm_read(register bn_spm_map_t *mapp, register unsigned char *valp, double u, double v)
Read the value of the pixel at the given normalized (u, v) coordinates. It does NOT check the sanity ...
int bn_spm_pix_save(bn_spm_map_t *mapp, char *filename, int nx, int ny)
Save a sphere structure as an 'nx' by 'ny' pix file.
void bn_spm_dump(bn_spm_map_t *mp, int verbose)
Display a sphere structure on stderr. Used for debugging.
uint32_t magic
Definition: spm.h:36
int ny
Number of "y" bins.
Definition: spm.h:37
unsigned char * _data
For freeing purposes, start of data.
Definition: spm.h:41
unsigned char ** xbin
staring addresses of "x" bins
Definition: spm.h:40
int elsize
Size of each bin element.
Definition: spm.h:39
int * nx
Number of "x" bins per "y" bin.
Definition: spm.h:38