22 #include <grass/gis.h>
23 #include <grass/ogsf.h>
28 #define READ() gvl_read_char(pos[i]++, gvl->isosurf[i]->data)
40 G_debug(5,
"gvld_vol(): id=%d", gvl->gvol_id);
71 G_debug(5,
"gvld_wire_vol(): id=%d", gvl->gvol_id);
95 int cols, rows, depths;
98 float xres, yres, zres;
101 int j, p, num, c_ndx, crnt_ev;
104 int n_i = gvl->n_isosurfs;
106 int *check_color, *check_transp, *check_material, *check_emis, *check_shin;
107 float *kem, *ksh, pkem, pksh;
108 unsigned int *ktrans, *curcolor;
112 int *pos, *nz, *e_dl, tmp_pos, edge_pos[13];
114 GLdouble modelMatrix[16], projMatrix[16];
118 geovol_isosurf *isosurf;
122 check_color = G_malloc(n_i *
sizeof(
int));
123 check_transp = G_malloc(n_i *
sizeof(
int));
124 check_material = G_malloc(n_i *
sizeof(
int));
125 check_emis = G_malloc(n_i *
sizeof(
int));
126 check_shin = G_malloc(n_i *
sizeof(
int));
128 kem = G_malloc(n_i *
sizeof(
float));
129 ksh = G_malloc(n_i *
sizeof(
float));
131 ktrans = G_malloc(n_i *
sizeof(
unsigned int));
132 curcolor = G_malloc(n_i *
sizeof(
unsigned int));
134 pos = G_malloc(n_i *
sizeof(
int));
135 nz = G_malloc(n_i *
sizeof(
int));
136 e_dl = G_malloc(n_i *
sizeof(
int));
139 for (i = 0; i < gvl->n_isosurfs; i++) {
140 G_debug(5,
" start : gvl: %s isosurf : %d\n",
151 cols = gvl->cols / gvl->isosurf_x_mod;
152 rows = gvl->rows / gvl->isosurf_y_mod;
153 depths = gvl->depths / gvl->isosurf_z_mod;
170 window[0] += (int)(yres * 2);
171 window[1] -= (int)(yres * 2);
172 window[2] -= (int)(xres * 2);
173 window[3] += (int)(xres * 2);
184 for (i = 0; i < gvl->n_isosurfs; i++) {
185 isosurf = gvl->isosurf[i];
192 ktrans[i] = (255U << 24);
193 if (CONST_ATT == isosurf->att[ATT_TRANSP].att_src &&
194 isosurf->att[ATT_TRANSP].constant != 0.0) {
195 ktrans[i] = (255 - (int)isosurf->att[ATT_TRANSP].constant) << 24;
197 else if (MAP_ATT == isosurf->att[ATT_TRANSP].att_src) {
205 if (CONST_ATT == isosurf->att[ATT_EMIT].att_src) {
206 kem[i] = isosurf->att[ATT_EMIT].constant / 255.;
208 else if (MAP_ATT == isosurf->att[ATT_EMIT].att_src) {
216 if (CONST_ATT == isosurf->att[ATT_SHINE].att_src) {
217 ksh[i] = isosurf->att[ATT_SHINE].constant / 255.;
219 else if (MAP_ATT == isosurf->att[ATT_SHINE].att_src) {
227 if (CONST_ATT == isosurf->att[ATT_COLOR].att_src) {
228 curcolor[i] = (int)isosurf->att[ATT_COLOR].constant;
230 else if (MAP_ATT == isosurf->att[ATT_COLOR].att_src) {
237 (check_shin[i] || check_emis[i] || (kem[i] && check_color[i]));
246 for (z = 0; z < depths - 1; z++) {
250 for (i = 0; i < gvl->n_isosurfs; i++) {
251 G_debug(5,
" break : isosurf : %d datalength : %d B\n", i,
263 for (y = 0; y < rows - 1; y++) {
264 yc = ((rows - 1) * yres) - (y * yres);
266 for (
x = 0;
x < cols - 1;
x++) {
269 for (i = 0; i < gvl->n_isosurfs; i++) {
283 c_ndx = (c_ndx - 1) * 256 +
READ();
297 pos[i] + j * e_dl[i];
301 if (check_transp[i] || (ktrans[i] >> 24) < 255) {
318 for (j = 0; j < 3; j++) {
321 pos[i] = edge_pos[crnt_ev];
325 pt[
X] = xc + (
READ() / 255. * xres);
326 pt[
Y] = yc + (-(
READ() / 255. * yres));
327 pt[Z] = zc + (
READ() / 255. * zres);
330 pt[edge_vert_pos[crnt_ev][0]] =
READ() / 255.;
331 pt[edge_vert_pos[crnt_ev][1]] =
332 edge_vert_pos[crnt_ev][2];
333 pt[edge_vert_pos[crnt_ev][3]] =
334 edge_vert_pos[crnt_ev][4];
336 pt[
X] = xc + (pt[
X] * xres);
337 pt[
Y] = yc + (-(pt[
Y] * yres));
338 pt[Z] = zc + (pt[Z] * zres);
341 n[
X] = (
READ() / 127. - 1.) / xres;
342 n[
Y] = (-(
READ() / 127. - 1.)) / yres;
343 n[Z] = (
READ() / 127. - 1.) / zres;
345 if (gvl->isosurf[i]->inout_mode) {
351 if (check_color[i]) {
355 curcolor[i] = (
r & 0xff) | ((
g & 0xff) << 8) |
360 ktrans[i] =
READ() << 24;
364 ksh[i] = ((float)
READ()) / 255.;
367 kem[i] = ((float)
READ()) / 255.;
369 if (pksh != ksh[i] || pkem != kem[i] ||
370 (kem[i] && check_color[i])) {
392 for (i = 0; i < gvl->n_isosurfs; i++) {
393 G_debug(5,
" end : isosurf : %d datalength : %d B\n", i, pos[i]);
433 #define DISTANCE_2(x1, y1, x2, y2) \
434 sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
448 GLdouble modelMatrix[16], projMatrix[16];
468 for (i = 0; i < gvl->n_slices; i++) {
472 if (gvl->slice[i]->transp == 0)
476 for (i = 0; i < gvl->n_slices; i++) {
480 if (gvl->slice[i]->transp > 0)
504 int color, offset, transp;
506 float x, nextx, y, nexty, z, stepx, stepy, stepz;
507 int cols, rows, c,
r;
508 float f_cols, f_rows, distxy, distz, modx, mody, modz, modxy;
510 double resx, resy, resz;
513 slice = gvl->slice[ndx];
516 distxy =
DISTANCE_2(slice->x2, slice->y2, slice->x1, slice->y1);
517 distz = fabsf(slice->z2 - slice->z1);
520 if (distxy == 0. || distz == 0.) {
525 if (slice->dir ==
X) {
526 modx = gvl->slice_y_mod;
527 mody = gvl->slice_z_mod;
528 modz = gvl->slice_x_mod;
536 else if (slice->dir ==
Y) {
537 modx = gvl->slice_x_mod;
538 mody = gvl->slice_z_mod;
539 modz = gvl->slice_y_mod;
548 modx = gvl->slice_x_mod;
549 mody = gvl->slice_y_mod;
550 modz = gvl->slice_z_mod;
560 modxy =
DISTANCE_2((slice->x2 - slice->x1) / distxy * modx,
561 (slice->y2 - slice->y1) / distxy * mody, 0., 0.);
564 f_cols = distxy / modxy;
565 cols = f_cols > (int)f_cols ? (
int)f_cols + 1 : (int)f_cols;
567 f_rows = distz / modz;
568 rows = f_rows > (int)f_rows ? (
int)f_rows + 1 : (int)f_rows;
571 stepx = (slice->x2 - slice->x1) / f_cols;
572 stepy = (slice->y2 - slice->y1) / f_cols;
573 stepz = (slice->z2 - slice->z1) / f_rows;
581 nextx =
x + stepx * f_cols;
582 nexty = y + stepy * f_cols;
590 if (slice->transp > 0) {
591 transp = (255 - slice->transp) << 24;
598 for (c = 0; c < cols; c++) {
607 for (
r = 0;
r < rows + 1;
r++) {
609 offset = (c + 1) * (rows + 1) * 3 +
r * 3;
612 color = (slice->data[offset] & 0xff) |
613 ((slice->data[offset + 1] & 0xff) << 8) |
614 ((slice->data[offset + 2] & 0xff) << 16);
617 pt[ptX] = nextx * resx;
618 pt[ptY] = nexty * resy;
621 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
625 offset = c * (rows + 1) * 3 +
r * 3;
628 color = (slice->data[offset] & 0xff) |
629 ((slice->data[offset + 1] & 0xff) << 8) |
630 ((slice->data[offset + 2] & 0xff) << 16);
637 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
640 if (
r + 1 > f_rows) {
641 z += stepz * (f_rows - (float)
r);
651 if (c + 2 > f_cols) {
653 nextx += stepx * (f_cols - (float)(c + 1));
655 nexty += stepy * (f_cols - (float)(c + 1));
683 double resx, resy, resz;
687 G_debug(5,
"gvld_wire_slices");
704 for (i = 0; i < gvl->n_slices; i++) {
705 slice = gvl->slice[i];
708 if (slice->dir ==
X) {
716 else if (slice->dir ==
Y) {
736 pt[ptX] = slice->x1 * resx;
737 pt[ptY] = slice->y1 * resy;
738 pt[ptZ] = slice->z1 * resz;
740 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
743 pt[ptX] = slice->x1 * resx;
744 pt[ptY] = slice->y1 * resy;
745 pt[ptZ] = slice->z2 * resz;
747 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
750 pt[ptX] = slice->x2 * resx;
751 pt[ptY] = slice->y2 * resy;
752 pt[ptZ] = slice->z2 * resz;
754 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
757 pt[ptX] = slice->x2 * resx;
758 pt[ptY] = slice->y2 * resy;
759 pt[ptZ] = slice->z1 * resz;
761 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
764 pt[ptX] = slice->x1 * resx;
765 pt[ptY] = slice->y1 * resy;
766 pt[ptZ] = slice->z1 * resz;
768 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
791 G_debug(5,
"gvld_wind3_box(): id=%d", gvl->gvol_id);
815 pt[
X] = (gvl->cols - 1) * gvl->xres;
819 pt[
X] = (gvl->cols - 1) * gvl->xres;
820 pt[
Y] = (gvl->rows - 1) * gvl->yres;
824 pt[
Y] = (gvl->rows - 1) * gvl->yres;
837 pt[Z] = (gvl->depths - 1) * gvl->zres;
839 pt[
X] = (gvl->cols - 1) * gvl->xres;
841 pt[Z] = (gvl->depths - 1) * gvl->zres;
843 pt[
X] = (gvl->cols - 1) * gvl->xres;
844 pt[
Y] = (gvl->rows - 1) * gvl->yres;
845 pt[Z] = (gvl->depths - 1) * gvl->zres;
848 pt[
Y] = (gvl->rows - 1) * gvl->yres;
849 pt[Z] = (gvl->depths - 1) * gvl->zres;
853 pt[Z] = (gvl->depths - 1) * gvl->zres;
865 pt[Z] = (gvl->depths - 1) * gvl->zres;
870 pt[
X] = (gvl->cols - 1) * gvl->xres;
874 pt[
X] = (gvl->cols - 1) * gvl->xres;
876 pt[Z] = (gvl->depths - 1) * gvl->zres;
882 pt[
Y] = (gvl->rows - 1) * gvl->yres;
886 pt[
Y] = (gvl->rows - 1) * gvl->yres;
887 pt[Z] = (gvl->depths - 1) * gvl->zres;
892 pt[
X] = (gvl->cols - 1) * gvl->xres;
893 pt[
Y] = (gvl->rows - 1) * gvl->yres;
896 pt[
X] = (gvl->cols - 1) * gvl->xres;
897 pt[
Y] = (gvl->rows - 1) * gvl->yres;
898 pt[Z] = (gvl->depths - 1) * gvl->zres;
void G_free(void *buf)
Free allocated memory.
CELL_ENTRY cell_table[256]
int G_debug(int level, const char *msg,...)
Print debugging message.
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale.
void gsd_endtmesh(void)
ADD.
void gsd_pushmatrix(void)
Push the current matrix stack.
void gsd_zwritemask(unsigned long n)
Write out z-mask.
void gsd_vert_func(float *pt)
ADD.
void gsd_litvert_func(float *norm, unsigned long col, float *pt)
Set the current normal vector & specify vertex.
void gsd_colormode(int cm)
Set color mode.
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_blend(int yesno)
Specify pixel arithmetic.
void gsd_popmatrix(void)
Pop the current matrix stack.
void gsd_endline(void)
End line.
void gsd_bgnline(void)
Begin line.
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
void gsd_bgntmesh(void)
ADD.
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
void gsd_color_func(unsigned int col)
Set current color.
void gsd_shademodel(int shade)
Set shaded model.
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
void gsd_linewidth(short n)
Set width of rasterized lines.
void gsd_set_material(int set_shin, int set_emis, float sh, float em, int emcolor)
Set material.
void gsd_do_scale(int doexag)
Set current scale.
int GS_check_cancel(void)
Check for cancel.
int gvl_slices_calc(geovol *gvol)
Calculate slices for given volume set.
int gvl_isosurf_calc(geovol *gvol)
Fill data structure with computed isosurfaces polygons.
char * gvl_file_get_name(int id)
Get file name for given handle.
#define DISTANCE_2(x1, y1, x2, y2)
int gvld_isosurf(geovol *gvl)
Draw volume isosurfaces.
int gvld_slice(geovol *gvl, int ndx)
Draw slice.
int gvld_wire_slices(geovol *gvl)
Draw wire slices.
int gvld_wire_isosurf(geovol *gvl)
Draw volume isosurface in draw mode.
int gvld_wind3_box(geovol *gvl)
Draw volume bounding box.
int gvld_slices(geovol *gvl)
Draw slices.
int gvld_wire_vol(geovol *gvl)
Draw volume in wire mode (bounding box)
int gvld_vol(geovol *gvl)
Draw volume set (slices and isosurfaces)