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;
99 int j, p, num, c_ndx, crnt_ev;
102 int n_i = gvl->n_isosurfs;
104 int *check_color, *check_transp, *check_material, *check_emis,
106 float *kem, *ksh, pkem, pksh;
107 unsigned int *ktrans, *curcolor;
110 int *pos, *nz, *e_dl, tmp_pos, edge_pos[12];
112 GLdouble modelMatrix[16], projMatrix[16];
116 geovol_isosurf *isosurf;
120 check_color = G_malloc(n_i *
sizeof(
int));
121 check_transp = G_malloc(n_i *
sizeof(
int));
122 check_material = G_malloc(n_i *
sizeof(
int));
123 check_emis = G_malloc(n_i *
sizeof(
int));
124 check_shin = G_malloc(n_i *
sizeof(
int));
126 kem = G_malloc(n_i *
sizeof(
float));
127 ksh = G_malloc(n_i *
sizeof(
float));
129 ktrans = G_malloc(n_i *
sizeof(
unsigned int));
130 curcolor = G_malloc(n_i *
sizeof(
unsigned int));
132 pos = G_malloc(n_i *
sizeof(
int));
133 nz = G_malloc(n_i *
sizeof(
int));
134 e_dl = G_malloc(n_i *
sizeof(
int));
137 for (i = 0; i < gvl->n_isosurfs; i++) {
138 G_debug(5,
" start : gvl: %s isosurf : %d\n",
149 cols = gvl->cols / gvl->isosurf_x_mod;
150 rows = gvl->rows / gvl->isosurf_y_mod;
151 depths = gvl->depths / gvl->isosurf_z_mod;
168 window[0] += (int)(yres * 2);
169 window[1] -= (int)(yres * 2);
170 window[2] -= (int)(xres * 2);
171 window[3] += (int)(xres * 2);
182 for (i = 0; i < gvl->n_isosurfs; i++) {
183 isosurf = gvl->isosurf[i];
190 ktrans[i] = (255 << 24);
191 if (CONST_ATT == isosurf->att[ATT_TRANSP].att_src &&
192 isosurf->att[ATT_TRANSP].constant != 0.0) {
193 ktrans[i] = (255 - (int)isosurf->att[ATT_TRANSP].constant) << 24;
195 else if (MAP_ATT == isosurf->att[ATT_TRANSP].att_src) {
203 if (CONST_ATT == isosurf->att[ATT_EMIT].att_src) {
204 kem[i] = isosurf->att[ATT_EMIT].constant / 255.;
206 else if (MAP_ATT == isosurf->att[ATT_EMIT].att_src) {
214 if (CONST_ATT == isosurf->att[ATT_SHINE].att_src) {
215 ksh[i] = isosurf->att[ATT_SHINE].constant / 255.;
217 else if (MAP_ATT == isosurf->att[ATT_SHINE].att_src) {
225 if (CONST_ATT == isosurf->att[ATT_COLOR].att_src) {
226 curcolor[i] = (int)isosurf->att[ATT_COLOR].constant;
228 else if (MAP_ATT == isosurf->att[ATT_COLOR].att_src) {
234 check_material[i] = (check_shin[i] || check_emis[i] ||
235 (kem[i] && check_color[i]));
244 for (z = 0; z < depths - 1; z++) {
248 for (i = 0; i < gvl->n_isosurfs; i++) {
249 G_debug(5,
" break : isosurf : %d datalength : %d B\n",
261 for (y = 0; y < rows - 1; y++) {
262 yc = ((rows - 1) * yres) - (y * yres);
264 for (x = 0; x < cols - 1; x++) {
267 for (i = 0; i < gvl->n_isosurfs; i++) {
281 c_ndx = (c_ndx - 1) * 256 +
READ();
295 pos[i] + j * e_dl[i];
299 if (check_transp[i] || (ktrans[i] >> 24) < 255) {
316 for (j = 0; j < 3; j++) {
319 pos[i] = edge_pos[crnt_ev];
323 pt[
X] = xc + (
READ() / 255. * xres);
324 pt[
Y] = yc + (-(
READ() / 255. * yres));
325 pt[Z] = zc + (
READ() / 255. * zres);
328 pt[edge_vert_pos[crnt_ev][0]] =
READ() / 255.;
329 pt[edge_vert_pos[crnt_ev][1]] =
330 edge_vert_pos[crnt_ev][2];
331 pt[edge_vert_pos[crnt_ev][3]] =
332 edge_vert_pos[crnt_ev][4];
334 pt[
X] = xc + (pt[
X] * xres);
335 pt[
Y] = yc + (-(pt[
Y] * yres));
336 pt[Z] = zc + (pt[Z] * zres);
339 n[
X] = (
READ() / 127. - 1.) / xres;
340 n[
Y] = (-(
READ() / 127. - 1.)) / yres;
341 n[Z] = (
READ() / 127. - 1.) / zres;
343 if (gvl->isosurf[i]->inout_mode) {
351 (
READ() & 0xff) | ((
READ() & 0xff) << 8) |
352 ((
READ() & 0xff) << 16);
355 ktrans[i] =
READ() << 24;;
358 ksh[i] = ((float)
READ()) / 255.;
361 kem[i] = ((float)
READ()) / 255.;
363 if (pksh != ksh[i] || pkem != kem[i] ||
364 (kem[i] && check_color[i])) {
390 for (i = 0; i < gvl->n_isosurfs; i++) {
391 G_debug(5,
" end : isosurf : %d datalength : %d B\n", i, pos[i]);
419 #define DISTANCE_2(x1, y1, x2, y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
433 GLdouble modelMatrix[16], projMatrix[16];
453 for (i = 0; i < gvl->n_slices; i++) {
457 if (gvl->slice[i]->transp == 0)
461 for (i = 0; i < gvl->n_slices; i++) {
465 if (gvl->slice[i]->transp > 0)
489 int color, offset, transp;
491 float x, nextx, y, nexty, z, stepx, stepy, stepz;
492 int cols, rows, c,
r;
493 float f_cols, f_rows, distxy, distz, modx, mody, modz, modxy;
494 int ptX, ptY, ptZ, resx, resy, resz;
497 slice = gvl->slice[ndx];
500 distxy =
DISTANCE_2(slice->x2, slice->y2, slice->x1, slice->y1);
501 distz = fabsf(slice->z2 - slice->z1);
504 if (distxy == 0. || distz == 0.) {
509 if (slice->dir ==
X) {
510 modx = gvl->slice_y_mod;
511 mody = gvl->slice_z_mod;
512 modz = gvl->slice_x_mod;
520 else if (slice->dir ==
Y) {
521 modx = gvl->slice_x_mod;
522 mody = gvl->slice_z_mod;
523 modz = gvl->slice_y_mod;
532 modx = gvl->slice_x_mod;
533 mody = gvl->slice_y_mod;
534 modz = gvl->slice_z_mod;
545 DISTANCE_2((slice->x2 - slice->x1) / distxy * modx,
546 (slice->y2 - slice->y1) / distxy * mody, 0., 0.);
549 f_cols = distxy / modxy;
550 cols = f_cols > (int)f_cols ? (
int)f_cols + 1 : (int)f_cols;
552 f_rows = distz / modz;
553 rows = f_rows > (int)f_rows ? (
int)f_rows + 1 : (int)f_rows;
556 stepx = (slice->x2 - slice->x1) / f_cols;
557 stepy = (slice->y2 - slice->y1) / f_cols;
558 stepz = (slice->z2 - slice->z1) / f_rows;
566 nextx = x + stepx * f_cols;
567 nexty = y + stepy * f_cols;
575 if (slice->transp > 0) {
576 transp = (255 - slice->transp) << 24;
583 for (c = 0; c <
cols; c++) {
592 for (r = 0; r < rows + 1; r++) {
594 offset = (c + 1) * (rows + 1) * 3 + r * 3;
597 color = (slice->data[offset] & 0xff) |
598 ((slice->data[offset + 1] & 0xff) << 8) |
599 ((slice->data[offset + 2] & 0xff) << 16);
602 pt[ptX] = nextx * resx;
603 pt[ptY] = nexty * resy;
606 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
610 offset = c * (rows + 1) * 3 + r * 3;
613 color = (slice->data[offset] & 0xff) |
614 ((slice->data[offset + 1] & 0xff) << 8) |
615 ((slice->data[offset + 2] & 0xff) << 16);
622 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
625 if (r + 1 > f_rows) {
626 z += stepz * (f_rows - (float)r);
636 if (c + 2 > f_cols) {
638 nextx += stepx * (f_cols - (float)(c + 1));
640 nexty += stepy * (f_cols - (float)(c + 1));
667 int ptX, ptY, ptZ, resx, resy, resz;
671 G_debug(5,
"gvld_wire_slices");
688 for (i = 0; i < gvl->n_slices; i++) {
689 slice = gvl->slice[i];
692 if (slice->dir ==
X) {
700 else if (slice->dir ==
Y) {
720 pt[ptX] = slice->x1 * resx;
721 pt[ptY] = slice->y1 * resy;
722 pt[ptZ] = slice->z1 * resz;;
723 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
726 pt[ptX] = slice->x1 * resx;
727 pt[ptY] = slice->y1 * resy;
728 pt[ptZ] = slice->z2 * resz;;
729 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
732 pt[ptX] = slice->x2 * resx;
733 pt[ptY] = slice->y2 * resy;
734 pt[ptZ] = slice->z2 * resz;;
735 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
738 pt[ptX] = slice->x2 * resx;
739 pt[ptY] = slice->y2 * resy;
740 pt[ptZ] = slice->z1 * resz;;
741 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
744 pt[ptX] = slice->x1 * resx;
745 pt[ptY] = slice->y1 * resy;
746 pt[ptZ] = slice->z1 * resz;;
747 pt[
Y] = (gvl->rows - 1) * gvl->yres - pt[
Y];
770 G_debug(5,
"gvld_wind3_box(): id=%d", gvl->gvol_id);
794 pt[
X] = (gvl->cols - 1) * gvl->xres;
798 pt[
X] = (gvl->cols - 1) * gvl->xres;
799 pt[
Y] = (gvl->rows - 1) * gvl->yres;
803 pt[
Y] = (gvl->rows - 1) * gvl->yres;
816 pt[Z] = (gvl->depths - 1) * gvl->zres;
818 pt[
X] = (gvl->cols - 1) * gvl->xres;
820 pt[Z] = (gvl->depths - 1) * gvl->zres;
822 pt[
X] = (gvl->cols - 1) * gvl->xres;
823 pt[
Y] = (gvl->rows - 1) * gvl->yres;
824 pt[Z] = (gvl->depths - 1) * gvl->zres;
827 pt[
Y] = (gvl->rows - 1) * gvl->yres;
828 pt[Z] = (gvl->depths - 1) * gvl->zres;
832 pt[Z] = (gvl->depths - 1) * gvl->zres;
844 pt[Z] = (gvl->depths - 1) * gvl->zres;
849 pt[
X] = (gvl->cols - 1) * gvl->xres;
853 pt[
X] = (gvl->cols - 1) * gvl->xres;
855 pt[Z] = (gvl->depths - 1) * gvl->zres;
861 pt[
Y] = (gvl->rows - 1) * gvl->yres;
865 pt[
Y] = (gvl->rows - 1) * gvl->yres;
866 pt[Z] = (gvl->depths - 1) * gvl->zres;
871 pt[
X] = (gvl->cols - 1) * gvl->xres;
872 pt[
Y] = (gvl->rows - 1) * gvl->yres;
875 pt[
X] = (gvl->cols - 1) * gvl->xres;
876 pt[
Y] = (gvl->rows - 1) * gvl->yres;
877 pt[Z] = (gvl->depths - 1) * gvl->zres;