rasdaman complete source
cube_render.h
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
23 
43 #ifndef _CUBE_RENDER_H
44 #define _CUBE_RENDER_H
45 
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51  /* Externally visible structs and definitions */
52 
53 #define CUBE_BSIZE_CHAR 1
54 #define CUBE_BSIZE_SHORT 2
55 #define CUBE_BSIZE_RGB 3
56 #define CUBE_BSIZE_LONG 4
57 
58 
59  /* FP type to use */
60  typedef float real_t;
61 
62 
63  typedef struct vertex
64  {
65  long x, y, z;
66  } vertex;
67 
68  typedef struct vertex_fp
69  {
70  real_t x, y, z;
71  } vertex_fp;
72 
73  typedef struct vertex_p
74  {
75  long x, y;
76  } vertex_p;
77 
78  typedef struct rotation_desc
79  {
80  double sin;
81  double cos;
82  } rotation_desc;
83 
84 
85 
86  typedef struct graph_env
87  {
88  int clipl, clipr, clipd, clipu, clipz;
89  int midx, midy, lineadd, zpro;
90  unsigned long bbox_colour;
91  void *dest;
92  } graph_env;
93 
94 
95  typedef struct tex_desc
96  {
97  int dimx, dimy, dimz;
98  int widthx, widthy, widthz;
99  int baseSize;
100  void *data;
101  int floatType;
102  double minVal; /* Only needed for float types */
103  double maxVal;
104  } tex_desc;
105 
106 
107  /* generalized tex_desc */
108  typedef struct mdd_desc
109  {
110  int numDims;
111  int *widths;
112  int *dims;
113  int baseSize;
114  void *data;
115  int floatType;
116  double minVal;
117  double maxVal;
118  } mdd_desc;
119 
120 
121  typedef struct bounding_box
122  {
123  int minx, miny, maxx, maxy;
124  } bounding_box;
125 
126  typedef struct face
127  {
128  int vertices;
129  unsigned int flags;
130  vertex_fp *first;
131  vertex_p *first_p;
132  bounding_box bBox;
133  } face;
134 
135 
136  /* Methods for normal vector approximation when summing up neighbouring voxels */
137 #define RENDER_NORM_KERNEL_VOID 0
138 #define RENDER_NORM_KERNEL_HOMO 1
139 #define RENDER_NORM_KERNEL_LINEAR 2
140 #define RENDER_NORM_KERNEL_GAUSS 3
141 
142  typedef unsigned short zbuffer_t;
143 
144  typedef struct mesh_desc
145  {
146  void *srcData;
147  int width, height;
148  real_t scaleGrid, scaleHeight;
149  real_t oldGrid, oldHeight;
150  unsigned int colour;
151  real_t miny, maxy;
152  vertex_fp *vert;
153  vertex_fp *norm;
154  zbuffer_t *zbuffer;
155  unsigned int zbuffSize;
156  } mesh_desc;
157 
158  typedef struct light_desc
159  {
160  vertex_fp lights;
161  double ambient;
162  double gain;
163  double cosine;
164  double scintCos;
165  } light_desc;
166 
167  typedef struct voxel_desc
168  {
169  double pixelThresholdLow;
170  double pixelThresholdHigh;
171  double weightThreshold;
172  int weightQuantisation;
173  int useRgbBrightness;
174  int kernSize;
175  int kernType;
176  void *voxColour;
177  light_desc light;
178  } voxel_desc;
179 
180  typedef struct render_desc
181  {
182  face *faces;
183  vertex_fp left_g, right_g;
184  vertex_fp left_t, right_t;
185  long left_p, right_p;
186  vertex_fp *texbase;
187  vertex_fp org, tmax;
188  int found, do_lines;
189  tex_desc *texDesc;
190  graph_env *graphEnv;
191  } render_desc;
192 
193 
194 
195  /*
196  * These calls aren't needed for rendering. They let you build a clipped cube
197  * which can be referenced via the render descriptor (also used internally) and
198  * free the resources after you're finished with them.
199  */
200  extern void RenderCubeClipCube(const vertex_fp geomData[4], render_desc *renderDesc, int removeHidden);
201  extern render_desc *RenderCubeBuild(const vertex_fp geomData[4], const graph_env *graphEnv);
202  extern void RenderCubeFreeDesc(render_desc *renderDesc);
203  extern int RenderCubeGetPosition(int x_p, int y_p, vertex_fp *pos, render_desc *renderDesc);
204  extern void RenderCubeDetermineRotation(const vertex_fp *base, rotation_desc *rd);
205 
206 
207 
208  /*
209  * The actual renderers.
210  * Exit status is 0 for OK, otherwise an error occurred. */
211 
212  /* For backwards compatibility, equals RenderCubeSurf */
213  extern int RenderCube(const vertex_fp geomData[4], const graph_env *graphEnv, const tex_desc *texDesc);
214 
215  /* Renders the textured surfaces of the cube only */
216  extern int RenderCubeSurf(const vertex_fp geomData[4], const graph_env *graphEnv, const tex_desc *texDesc);
217 
218  /* Renders the cube using a volume-oriented method. */
219  extern int RenderCubeVoxel(const vertex_fp geomData[4], const graph_env *graphEnv, const tex_desc *texDesc, voxel_desc *voxDesc);
220 
221  /* Line API: only texDesc and graphEnv of renderDesc have to be initialized */
222  /* Renders a line in unprocessed 3D coordinates */
223  extern void Render3DLine(const vertex_fp *from, const vertex_fp *to, const render_desc *renderDesc, long colour);
224  /* Renders a line in already projected, z-clipped coordinates */
225  extern void RenderLineSegment(const vertex_p *from, const vertex_p *to, const render_desc *renderDesc, long colour);
226 
227  /* Renders a polygon using shading */
228  extern int RenderShadedPolygon(int numVert, const vertex_fp *vertices, const vertex_fp *normals, unsigned int colour, const graph_env *graphEnv, const light_desc *lightDesc, const vertex_fp *real_norm, zbuffer_t *zbuffer);
229 
230  /* Renders a 2D height field */
231  extern int RenderHeightField(mesh_desc *meshDesc, const vertex_fp *rotTrans, const graph_env *graphEnv, const mdd_desc *mddDesc, const light_desc *lightDesc);
232 
233  extern void RenderHeightFreeMesh(mesh_desc *meshDesc);
234 
235  extern int RenderHeightGetDomain(const mdd_desc *mddDesc, int *dimx, int *dimz, int *stepx, int *stepz);
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif