30 #define BUFFER_SIZE 1000000 35 #define LINTERP(d,a,b) (a + d * (b - a)) 36 #define TINTERP(d,v) ((v[0]*(1.-d[0])*(1.-d[1])*(1.-d[2])) +\ 37 (v[1]*d[0]*(1.-d[1])*(1.-d[2])) + \ 38 (v[2]*d[0]*d[1]*(1.-d[2])) + \ 39 (v[3]*(1.-d[0])*d[1]*(1.-d[2])) + \ 40 (v[4]*(1.-d[0])*(1.-d[1])*d[2]) + \ 41 (v[5]*d[0]*(1.-d[1])*d[2]) + \ 42 (v[6]*d[0]*d[1]*d[2]) + \ 43 (v[7]*(1.-d[0])*d[1]*d[2])) 46 #define FOR_0_TO_N(n, cmd) { int FOR_VAR; for (FOR_VAR = 0; FOR_VAR < n; FOR_VAR++) {cmd;} } 51 #define WRITE(c) gvl_write_char(dbuff->ndx_new++, &(dbuff->new), c) 52 #define READ() gvl_read_char(dbuff->ndx_old++, dbuff->old) 53 #define SKIP(n) dbuff->ndx_old = dbuff->ndx_old + n 58 #define IS_IN_DATA(att) ((isosurf->data_desc >> att) & 1) 59 #define SET_IN_DATA(att) isosurf->data_desc = (isosurf->data_desc | (1 << att)) 89 if (dbuff->num_zero == 0) {
93 else if (dbuff->num_zero == 254) {
94 WRITE(dbuff->num_zero + 1);
102 if (dbuff->num_zero == 0) {
103 WRITE((ndx / 256) + 1);
107 WRITE(dbuff->num_zero);
109 WRITE((ndx / 256) + 1);
124 if (dbuff->num_zero != 0) {
137 ndx = (ndx - 1) * 256 + ndx2;
173 (
int)(z *
ResZ), &d);
228 for (p = 0; p < 8; ++p) {
230 (isosurf, desc, x + ((p ^ (p >> 1)) & 1), y + ((p >> 1) & 1),
231 z + ((p >> 2) & 1), &v[p]) == 0) {
252 for (p = 0; p < 8; ++p) {
253 i = x + ((p ^ (p >> 1)) & 1);
254 j = y + ((p >> 1) & 1);
255 k = z + ((p >> 2) & 1);
261 grad[p][0] = v[2] - v[1];
264 if (i == (
Cols - 1)) {
267 grad[p][0] = v[1] - v[0];
272 grad[p][0] = (v[2] - v[0]) / 2;
280 grad[p][1] = v[2] - v[1];
283 if (j == (
Rows - 1)) {
286 grad[p][1] = v[1] - v[0];
291 grad[p][1] = (v[2] - v[0]) / 2;
299 grad[p][2] = v[2] - v[1];
305 grad[p][2] = v[1] - v[0];
310 grad[p][2] = (v[2] - v[0]) / 2;
329 float d, d3[3], d_sum[3], n[3], n_sum[3], tv;
350 for (i = 0; i < 8; i++) {
351 if (val[ATT_TOPO][i] > 0)
421 v1 = edge_vert[crnt][0];
422 v2 = edge_vert[crnt][1];
428 d_sum[edge_vert_pos[crnt][0]] += d;
429 d_sum[edge_vert_pos[crnt][1]] += edge_vert_pos[crnt][2];
430 d_sum[edge_vert_pos[crnt][3]] += edge_vert_pos[crnt][4];
446 d3[0] = ((float)c) / 255.0;
448 d3[1] = ((float)c) / 255.0;
450 d3[2] = ((float)c) / 255.0;
454 v1 = edge_vert[crnt][0];
455 v2 = edge_vert[crnt][1];
458 d = ((float)c) / 255.0;
506 c = (min !=
max) ? 255 - (tv - min) / (max -
min) * 255 : 0;
533 c = (min !=
max) ? (tv - min) / (max -
min) * 255 : 0;
560 c = (min !=
max) ? (tv - min) / (max -
min) * 255 : 0;
593 int *need_update, need_update_global;
599 need_update_global = 0;
608 dbuff[i].ndx_old = 0;
609 dbuff[i].ndx_new = 0;
610 dbuff[i].num_zero = 0;
636 need_update_global = 1;
641 if (need_update[i]) {
643 dbuff[i].old = isosurf->
data;
648 if (need_update_global) {
660 for (z = 0; z <
Depths - 1; z++) {
661 for (y = 0; y <
Rows - 1; y++) {
662 for (x = 0; x <
Cols - 1; x++) {
665 if (need_update[i]) {
682 if (need_update[i]) {
683 if (dbuff[i].num_zero != 0)
687 if (dbuff[i].old == isosurf->
data)
691 isosurf->
data = dbuff[i].new;
742 sizeof(
char) * ((pos / BUFFER_SIZE) +
749 "gvl_write_char(): reallocate memory for pos : %d to : %lu B",
750 pos,
sizeof(
char) * ((pos / BUFFER_SIZE) + 1) * BUFFER_SIZE);
781 unsigned char *p = *data;
785 p = (
unsigned char *)
G_realloc(p,
sizeof(
unsigned char) * pos);
790 G_debug(3,
"gvl_align_data(): reallocate memory finally to : %d B", pos);
805 #define DISTANCE_2(x1, y1, x2, y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) 807 #define SLICE_MODE_INTERP_NO 0 808 #define SLICE_MODE_INTERP_YES 1 825 if (x < 0 || y < 0 || z < 0 || (x > gvl->
cols - 1) || (y > gvl->
rows - 1)
859 int cols, rows, c,
r;
860 int i, j, k, pos, color;
861 int *p_x, *p_y, *p_z;
862 float *p_ex, *p_ey, *p_ez;
864 float x, y, z, ei, ej, ek, stepx, stepy, stepz;
865 float f_cols, f_rows, distxy, distz, modxy, modx, mody, modz;
870 slice = gvl->
slice[ndx_slc];
873 if (slice->
dir ==
X) {
884 else if (slice->
dir ==
Y) {
909 distz = fabsf(slice->
z2 - slice->
z1);
912 if (distxy == 0. || distz == 0.) {
924 (slice->
y2 - slice->
y1) / distxy * mody, 0., 0.);
927 f_cols = distxy / modxy;
928 cols = f_cols > (int)f_cols ? (
int)f_cols + 1 : (int)f_cols;
930 f_rows = distz / modz;
931 rows = f_rows > (int)f_rows ? (
int)f_rows + 1 : (int)f_rows;
938 stepx = (slice->
x2 - slice->
x1) / f_cols;
939 stepy = (slice->
y2 - slice->
y1) / f_cols;
940 stepz = (slice->
z2 - slice->
z1) / f_rows;
946 for (c = 0; c < cols + 1; c++) {
960 for (r = 0; r < rows + 1; r++) {
980 value = v[0] * (1. - *p_ex) * (1. - *p_ey) * (1. - *p_ez)
981 + v[1] * (*p_ex) * (1. - *p_ey) * (1. - *p_ez)
982 + v[2] * (1. - *p_ex) * (*p_ey) * (1. - *p_ez)
983 + v[3] * (*p_ex) * (*p_ey) * (1. - *p_ez)
984 + v[4] * (1. - *p_ex) * (1. - *p_ey) * (*p_ez)
985 + v[5] * (*p_ex) * (1. - *p_ey) * (*p_ez)
986 + v[6] * (1. - *p_ex) * (*p_ey) * (*p_ez)
987 + v[7] * (*p_ex) * (*p_ey) * (*p_ez);
1004 if (r + 1 > f_rows) {
1005 z += stepz * (f_rows - (float)r);
1013 if (c + 1 > f_cols) {
1014 x += stepx * (f_cols - (float)c);
1015 y += stepy * (f_cols - (float)c);
1058 for (i = 0; i < gvol->
n_slices; i++) {
void gvl_file_get_min_max(geovol_file *, double *, double *)
Get minimum and maximum value in volume file.
#define BUFFER_SIZE
memory buffer for writing
int iso_r_cndx(data_buffer *dbuff)
Read cube index.
#define IS_IN_DATA(att)
check and set data descriptor
int Gvl_unload_colors_data(void *)
Unload color table.
int gvl_file_get_value(geovol_file *, int, int, int, void *)
Get value for volume file at x, y, z.
int gvl_file_is_null_value(geovol_file *, void *)
Check for null value.
void G_free(void *)
Free allocated memory.
geovol_isosurf * isosurf[MAX_ISOSURFS]
#define FOR_0_TO_N(n, cmd)
int mc33_process_cube(int c_ndx, float *v)
ADD.
int gvl_isosurf_calc(geovol *gvol)
Fill data structure with computed isosurfaces polygons.
int GS_v3norm(float *)
Change v1 so that it is a unit vector (2D)
int Gvl_load_colors_data(void **, const char *)
Load color table.
void iso_get_range(geovol_isosurf *isosurf, int desc, double *min, double *max)
Get volume file values range.
int gvl_file_get_data_type(geovol_file *)
Get data type for given handle.
void gvl_write_char(int pos, unsigned char **data, unsigned char c)
ADD.
geovol_isosurf_att att[MAX_ATTS]
unsigned char gvl_read_char(int pos, const unsigned char *data)
Read char.
char * gvl_file_get_name(int)
Get file name for given handle.
geovol_slice * slice[MAX_SLICES]
void iso_calc_cube(geovol_isosurf *isosurf, int x, int y, int z, data_buffer *dbuff)
Process cube.
int Gvl_get_color_for_value(void *, float *)
Get color for value.
void iso_w_cndx(int ndx, data_buffer *dbuff)
Write cube index.
#define SLICE_MODE_INTERP_YES
#define WRITE(c)
writing and reading isosurface data
int iso_get_cube_value(geovol_isosurf *isosurf, int desc, int x, int y, int z, float *v)
Get value from data input.
void gvl_align_data(int pos, unsigned char **data)
Append data to buffer.
int iso_get_cube_values(geovol_isosurf *isosurf, int desc, int x, int y, int z, float *v)
Read values for cube.
geovol_file * gvl_file_get_volfile(int)
Get geovol_file structure for given handle.
float slice_get_value(geovol *gvl, int x, int y, int z)
Get volume value.
#define DISTANCE_2(x1, y1, x2, y2)
int gvl_file_end_read(geovol_file *)
End read - free buffer memory.
int gvl_file_set_mode(geovol_file *, IFLAG)
Set read mode.
void iso_get_cube_grads(geovol_isosurf *isosurf, int x, int y, int z, float(*grad)[3])
Calculate cube grads.
int slice_calc(geovol *gvl, int ndx_slc, void *colors)
Calculate slices.
int gvl_slices_calc(geovol *gvol)
Calculate slices for given volume set.
CELL_ENTRY cell_table[256]
int G_debug(int, const char *,...) __attribute__((format(printf
int gvl_file_start_read(geovol_file *)
Start read - allocate memory buffer a read first data into buffer.