21 #include <grass/gis.h>
22 #include <grass/gstypes.h>
27 #define READ() gvl_read_char(pos[i]++, gvl->isosurf[i]->data)
39 G_debug(5,
"gvld_vol(): id=%d", gvl->gvol_id);
70 G_debug(5,
"gvld_vol(): id=%d", gvl->gvol_id);
94 int cols, rows, depths;
97 float xres, yres, zres;
100 int j, p,
num, c_ndx, crnt_ev;
103 int n_i = gvl->n_isosurfs;
105 int *check_color, *check_transp, *check_material, *check_emis,
107 float *kem, *ksh, pkem, pksh;
108 unsigned int *ktrans, *curcolor;
111 int *
pos, *nz, *e_dl, tmp_pos, edge_pos[13];
113 GLdouble modelMatrix[16], projMatrix[16];
117 geovol_isosurf *isosurf;
121 check_color = G_malloc(n_i *
sizeof(
int));
122 check_transp = G_malloc(n_i *
sizeof(
int));
123 check_material = G_malloc(n_i *
sizeof(
int));
124 check_emis = G_malloc(n_i *
sizeof(
int));
125 check_shin = G_malloc(n_i *
sizeof(
int));
127 kem = G_malloc(n_i *
sizeof(
float));
128 ksh = G_malloc(n_i *
sizeof(
float));
130 ktrans = G_malloc(n_i *
sizeof(
unsigned int));
131 curcolor = G_malloc(n_i *
sizeof(
unsigned int));
133 pos = G_malloc(n_i *
sizeof(
int));
134 nz = G_malloc(n_i *
sizeof(
int));
135 e_dl = G_malloc(n_i *
sizeof(
int));
138 for (i = 0; i < gvl->n_isosurfs; i++) {
139 G_debug(5,
" start : gvl: %s isosurf : %d\n",
150 cols = gvl->cols / gvl->isosurf_x_mod;
151 rows = gvl->rows / gvl->isosurf_y_mod;
152 depths = gvl->depths / gvl->isosurf_z_mod;
169 window[0] += (int)(yres * 2);
170 window[1] -= (int)(yres * 2);
171 window[2] -= (int)(xres * 2);
172 window[3] += (int)(xres * 2);
183 for (i = 0; i < gvl->n_isosurfs; i++) {
184 isosurf = gvl->isosurf[i];
191 ktrans[i] = (255 << 24);
192 if (CONST_ATT == isosurf->att[ATT_TRANSP].att_src &&
193 isosurf->att[ATT_TRANSP].constant != 0.0) {
194 ktrans[i] = (255 - (int)isosurf->att[ATT_TRANSP].constant) << 24;
196 else if (MAP_ATT == isosurf->att[ATT_TRANSP].att_src) {
204 if (CONST_ATT == isosurf->att[ATT_EMIT].att_src) {
205 kem[i] = isosurf->att[ATT_EMIT].constant / 255.;
207 else if (MAP_ATT == isosurf->att[ATT_EMIT].att_src) {
215 if (CONST_ATT == isosurf->att[ATT_SHINE].att_src) {
216 ksh[i] = isosurf->att[ATT_SHINE].constant / 255.;
218 else if (MAP_ATT == isosurf->att[ATT_SHINE].att_src) {
226 if (CONST_ATT == isosurf->att[ATT_COLOR].att_src) {
227 curcolor[i] = (int)isosurf->att[ATT_COLOR].constant;
229 else if (MAP_ATT == isosurf->att[ATT_COLOR].att_src) {
235 check_material[i] = (check_shin[i] || check_emis[i] ||
236 (kem[i] && check_color[i]));
245 for (z = 0; z < depths - 1; z++) {
249 for (i = 0; i < gvl->n_isosurfs; i++) {
250 G_debug(5,
" break : isosurf : %d datalength : %d B\n",
262 for (y = 0; y < rows - 1; y++) {
263 yc = ((rows - 1) * yres) - (y * yres);
265 for (x = 0; x < cols - 1; x++) {
268 for (i = 0; i < gvl->n_isosurfs; i++) {
282 c_ndx = (c_ndx - 1) * 256 +
READ();
296 pos[i] + j * e_dl[i];
300 if (check_transp[i] || (ktrans[i] >> 24) < 255) {
317 for (j = 0; j < 3; j++) {
320 pos[i] = edge_pos[crnt_ev];
324 pt[
X] = xc + (
READ() / 255. * xres);
325 pt[
Y] = yc + (-(
READ() / 255. * yres));
326 pt[Z] = zc + (
READ() / 255. * zres);
329 pt[edge_vert_pos[crnt_ev][0]] =
READ() / 255.;
330 pt[edge_vert_pos[crnt_ev][1]] =
331 edge_vert_pos[crnt_ev][2];
332 pt[edge_vert_pos[crnt_ev][3]] =
333 edge_vert_pos[crnt_ev][4];
335 pt[
X] = xc + (pt[
X] * xres);
336 pt[
Y] = yc + (-(pt[
Y] * yres));
337 pt[Z] = zc + (pt[Z] * zres);
340 n[
X] = (
READ() / 127. - 1.) / xres;
341 n[
Y] = (-(
READ() / 127. - 1.)) / yres;
342 n[Z] = (
READ() / 127. - 1.) / zres;
344 if (gvl->isosurf[i]->inout_mode) {
350 if (check_color[i]) {
355 (r & 0xff) | ((g & 0xff) << 8) |
360 ktrans[i] =
READ() << 24;;
363 ksh[i] = ((float)
READ()) / 255.;
366 kem[i] = ((float)
READ()) / 255.;
368 if (pksh != ksh[i] || pkem != kem[i] ||
369 (kem[i] && check_color[i])) {
395 for (i = 0; i < gvl->n_isosurfs; i++) {
396 G_debug(5,
" end : isosurf : %d datalength : %d B\n", i, pos[i]);
424 #define DISTANCE_2(x1, y1, x2, y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
438 GLdouble modelMatrix[16], projMatrix[16];
458 for (i = 0; i < gvl->n_slices; i++) {
462 if (gvl->slice[i]->transp == 0)
466 for (i = 0; i < gvl->n_slices; i++) {
470 if (gvl->slice[i]->transp > 0)
494 int color, offset, transp;
496 float x, nextx,
y, nexty, z, stepx, stepy, stepz;
497 int cols, rows, c,
r;
498 float f_cols, f_rows, distxy, distz, modx, mody, modz, modxy;
500 double resx, resy, resz;
503 slice = gvl->slice[ndx];
506 distxy =
DISTANCE_2(slice->x2, slice->y2, slice->x1, slice->y1);
507 distz = fabsf(slice->z2 - slice->z1);
510 if (distxy == 0. || distz == 0.) {
515 if (slice->dir ==
X) {
516 modx = gvl->slice_y_mod;
517 mody = gvl->slice_z_mod;
518 modz = gvl->slice_x_mod;
526 else if (slice->dir ==
Y) {
527 modx = gvl->slice_x_mod;
528 mody = gvl->slice_z_mod;
529 modz = gvl->slice_y_mod;
538 modx = gvl->slice_x_mod;
539 mody = gvl->slice_y_mod;
540 modz = gvl->slice_z_mod;
551 DISTANCE_2((slice->x2 - slice->x1) / distxy * modx,
552 (slice->y2 - slice->y1) / distxy * mody, 0., 0.);
555 f_cols = distxy / modxy;
556 cols = f_cols > (
int)f_cols ? (
int)f_cols + 1 : (
int)f_cols;
558 f_rows = distz / modz;
559 rows = f_rows > (
int)f_rows ? (
int)f_rows + 1 : (
int)f_rows;
562 stepx = (slice->x2 - slice->x1) / f_cols;
563 stepy = (slice->y2 - slice->y1) / f_cols;
564 stepz = (slice->z2 - slice->z1) / f_rows;
572 nextx = x + stepx * f_cols;
573 nexty = y + stepy * f_cols;
581 if (slice->transp > 0) {
582 transp = (255 - slice->transp) << 24;
589 for (c = 0; c <
cols; c++) {
598 for (r = 0; r < rows + 1; r++) {
600 offset = (c + 1) * (rows + 1) * 3 + r * 3;
603 color = (slice->data[offset] & 0xff) |
604 ((slice->data[offset + 1] & 0xff) << 8) |
605 ((slice->data[offset + 2] & 0xff) << 16);
608 pt[ptX] = nextx * resx;
609 pt[ptY] = nexty * resy;
612 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
616 offset = c * (rows + 1) * 3 + r * 3;
619 color = (slice->data[offset] & 0xff) |
620 ((slice->data[offset + 1] & 0xff) << 8) |
621 ((slice->data[offset + 2] & 0xff) << 16);
628 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
631 if (r + 1 > f_rows) {
632 z += stepz * (f_rows - (float)r);
642 if (c + 2 > f_cols) {
644 nextx += stepx * (f_cols - (float)(c + 1));
646 nexty += stepy * (f_cols - (float)(c + 1));
674 double resx, resy, resz;
678 G_debug(5,
"gvld_wire_slices");
695 for (i = 0; i < gvl->n_slices; i++) {
696 slice = gvl->slice[i];
699 if (slice->dir ==
X) {
707 else if (slice->dir ==
Y) {
727 pt[ptX] = slice->x1 * resx;
728 pt[ptY] = slice->y1 * resy;
729 pt[ptZ] = slice->z1 * resz;;
730 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
733 pt[ptX] = slice->x1 * resx;
734 pt[ptY] = slice->y1 * resy;
735 pt[ptZ] = slice->z2 * resz;;
736 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
739 pt[ptX] = slice->x2 * resx;
740 pt[ptY] = slice->y2 * resy;
741 pt[ptZ] = slice->z2 * resz;;
742 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
745 pt[ptX] = slice->x2 * resx;
746 pt[ptY] = slice->y2 * resy;
747 pt[ptZ] = slice->z1 * resz;;
748 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
751 pt[ptX] = slice->x1 * resx;
752 pt[ptY] = slice->y1 * resy;
753 pt[ptZ] = slice->z1 * resz;;
754 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
777 G_debug(5,
"gvld_wind3_box(): id=%d", gvl->gvol_id);
801 pt[
X] = (gvl->cols - 1) * gvl->xres;
805 pt[
X] = (gvl->cols - 1) * gvl->xres;
806 pt[
Y] = (gvl->rows - 1) * gvl->yres;
810 pt[
Y] = (gvl->rows - 1) * gvl->yres;
823 pt[Z] = (gvl->depths - 1) * gvl->zres;
825 pt[
X] = (gvl->cols - 1) * gvl->xres;
827 pt[Z] = (gvl->depths - 1) * gvl->zres;
829 pt[
X] = (gvl->cols - 1) * gvl->xres;
830 pt[
Y] = (gvl->rows - 1) * gvl->yres;
831 pt[Z] = (gvl->depths - 1) * gvl->zres;
834 pt[
Y] = (gvl->rows - 1) * gvl->yres;
835 pt[Z] = (gvl->depths - 1) * gvl->zres;
839 pt[Z] = (gvl->depths - 1) * gvl->zres;
851 pt[Z] = (gvl->depths - 1) * gvl->zres;
856 pt[
X] = (gvl->cols - 1) * gvl->xres;
860 pt[
X] = (gvl->cols - 1) * gvl->xres;
862 pt[Z] = (gvl->depths - 1) * gvl->zres;
868 pt[
Y] = (gvl->rows - 1) * gvl->yres;
872 pt[
Y] = (gvl->rows - 1) * gvl->yres;
873 pt[Z] = (gvl->depths - 1) * gvl->zres;
878 pt[
X] = (gvl->cols - 1) * gvl->xres;
879 pt[
Y] = (gvl->rows - 1) * gvl->yres;
882 pt[
X] = (gvl->cols - 1) * gvl->xres;
883 pt[
Y] = (gvl->rows - 1) * gvl->yres;
884 pt[Z] = (gvl->depths - 1) * gvl->zres;
void gsd_zwritemask(unsigned long n)
Write out z-mask.
#define DISTANCE_2(x1, y1, x2, y2)
void gsd_bgntmesh(void)
ADD.
void gsd_do_scale(int doexag)
Set current scale.
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_set_material(int set_shin, int set_emis, float sh, float em, int emcolor)
Set material.
void gsd_colormode(int cm)
Set color mode.
int GS_check_cancel(void)
Check for cancel.
char * gvl_file_get_name(int id)
Get file name for given handle.
void gsd_color_func(unsigned int col)
Set current color.
void gsd_endtmesh(void)
ADD.
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
int gvld_isosurf(geovol *gvl)
Draw volume isosurfaces.
void gsd_litvert_func(float *norm, unsigned long col, float *pt)
Set the current normal vector & specify vertex.
void gsd_shademodel(int bool)
Set shaded model.
int gvl_isosurf_calc(geovol *gvol)
Fill data structure with computed isosurfaces polygons.
int gvld_slice(geovol *gvl, int ndx)
Draw slice.
void gsd_pushmatrix(void)
Push the current matrix stack.
void gsd_endline(void)
End line.
int gvld_wire_slices(geovol *gvl)
Draw wire slices.
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
int gvld_wire_vol(geovol *gvl)
Draw volume in wire mode (bounding box)
void gsd_blend(int yesno)
Specify pixel arithmetic.
void gsd_vert_func(float *pt)
ADD.
CELL_ENTRY cell_table[256]
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
int gvld_slices(geovol *gvl)
Draw slices.
int G_debug(int level, const char *msg,...)
Print debugging message.
int gvld_wind3_box(geovol *gvl)
Draw volume bounding box.
void gsd_linewidth(short n)
Set width of rasterized lines.
int gvld_vol(geovol *gvl)
Draw volume set (slices and isosurfaces)
void gsd_popmatrix(void)
Pop the current matrix stack.
void gsd_bgnline(void)
Begin line.
int gvl_slices_calc(geovol *gvol)
Calculate slices for given volume set.
int gvld_wire_isosurf(geovol *gvl)
Draw volume isosurface in draw mode.
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale.