1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10
11
12 #define _HP_FAST_MACROS 1
13 #include <starbase.c.h>
14 #include "hwDeclarations.h"
15 #include "hwTmesh.h"
16 #include "hwPortSB.h"
17 #include "hwXfield.h"
18 #include "hwCacheUtilSB.h"
19 #include "hwMemory.h"
20
21 #include "hwDebug.h"
22
23 #ifdef DEBUG
24 #define PrintBounds() \
25 { \
26 int i; \
27 float outx, outy, outz; \
28 float minx, maxx, miny, maxy, minz, maxz; \
29 \
30 minx = miny = minz = +MAXFLOAT; \
31 maxx = maxy = maxz = -MAXFLOAT; \
32 \
33 if (is_2d) \
34 { \
35 minz = maxz = 0; \
36 fprintf (stderr, "\n2-dimensional positions"); \
37 for (i=0; i<xf->npositions; i++) \
38 { \
39 if (pnts2d[i].x < minx) minx = pnts2d[i].x; \
40 if (pnts2d[i].y < miny) miny = pnts2d[i].y; \
41 \
42 if (pnts2d[i].x > maxx) maxx = pnts2d[i].x; \
43 if (pnts2d[i].y > maxy) maxy = pnts2d[i].y; \
44 } \
45 } \
46 else \
47 for (i=0; i<xf->npositions; i++) \
48 { \
49 if (points[i].x < minx) minx = points[i].x; \
50 if (points[i].y < miny) miny = points[i].y; \
51 if (points[i].z < minz) minz = points[i].z; \
52 \
53 if (points[i].x > maxx) maxx = points[i].x; \
54 if (points[i].y > maxy) maxy = points[i].y; \
55 if (points[i].z > maxz) maxz = points[i].z; \
56 } \
57 \
58 transform_point(FILDES, MC_TO_VDC, minx, miny, minz, &outx, &outy, &outz);\
59 fprintf(stderr, "\nmin MC->VDC %9f %9f %9f -> %9f %9f %9f", \
60 minx, miny, minz, outx, outy, outz); \
61 \
62 transform_point(FILDES, MC_TO_VDC, maxx, maxy, maxz, &outx, &outy, &outz);\
63 fprintf(stderr, "\nmax MC->VDC %9f %9f %9f -> %9f %9f %9f", \
64 maxx, maxy, maxz, outx, outy, outz); \
65 }
66 #else
67 #define PrintBounds() {}
68 #endif
69
70
71
72 int
_dxfPolylineDraw(tdmPortHandleP portHandle,xfieldT * xf,int buttonUp)73 _dxfPolylineDraw (tdmPortHandleP portHandle, xfieldT *xf, int buttonUp)
74 {
75 register Point *points;
76 register RGBColor *fcolors, *color_map;
77 register float *clist = NULL;
78 register int i, k, vsize, dV, *polylines, *edges;
79 int num_coords, mod, prev_point, start, cOffs, vertex_flags;
80 int type, rank, shape, is_2d;
81 struct p2d {float x, y;} *pnts2d;
82 enum approxE approx;
83 int nshapes, maxsize;
84
85 DEFPORT(portHandle);
86
87 ENTRY(("_dxfPolylineDraw(0x%x, 0x%x, %d)", portHandle, xf, buttonUp));
88
89 PRINT(("%d invalid connections",
90 xf->invCntns? DXGetInvalidCount(xf->invCntns): 0));
91
92 /*
93 * Extract required data from the xfield.
94 */
95
96 if (is_2d = IS_2D (xf->positions_array, type, rank, shape))
97 pnts2d = (struct p2d *) DXGetArrayData(xf->positions_array);
98 else
99 points = (Point *) DXGetArrayData(xf->positions_array);
100
101 PrintBounds();
102
103 color_map = (RGBColor *) DXGetArrayData(xf->cmap_array);
104
105 polylines = xf->polylines;
106 edges = xf->edges;
107 nshapes = xf->npolylines;
108
109 if (DXGetArrayClass(xf->fcolors_array) == CLASS_CONSTANTARRAY)
110 fcolors = (Pointer) DXGetArrayEntry(xf->fcolors, 0, NULL);
111 else
112 fcolors = (Pointer) DXGetArrayData(xf->fcolors_array);
113
114 if (buttonUp)
115 {
116 mod = xf->attributes.buttonUp.density;
117 approx = xf->attributes.buttonUp.approx;
118 }
119 else
120 {
121 mod = xf->attributes.buttonDown.density;
122 approx = xf->attributes.buttonDown.approx;
123 }
124
125 vertex_flags = 0;
126 hidden_surface (FILDES, TRUE, FALSE);
127
128 switch (approx)
129 {
130 case approx_dots:
131 case approx_none:
132 case approx_lines:
133 default:
134 if (xf->colorsDep == dep_field)
135 {
136 num_coords = 0;
137 vsize = 3;
138 SET_COLOR(line_color, 0);
139 }
140 else
141 {
142 num_coords = 3;
143 vsize = 6;
144 cOffs = 3;
145 vertex_flags = VERTEX_COLOR;
146 }
147
148 /*
149 * determine length of longest polyline
150 */
151 maxsize = 0;
152 for (k = 0; k < nshapes; k += mod)
153 {
154 int start = polylines[k];
155 int end = (k == nshapes-1) ? xf->nedges : polylines[k+1];
156 int knt = end - start;
157
158 if (xf->invCntns && !DXIsElementValid (xf->invCntns, k))
159 continue;
160
161 if (knt > maxsize) maxsize = knt;
162 }
163
164 clist = (float *)tdmAllocate(maxsize*vsize*sizeof(float));
165 if (!clist) DXErrorGoto(ERROR_INTERNAL, "#13000");
166
167
168 for (k = 0; k < nshapes; k += mod)
169 {
170 int start = polylines[k];
171 int end = (k == nshapes-1) ? xf->nedges : polylines[k+1];
172 int e, knt = end - start;
173
174 /* skip invalid connections */
175 if (xf->invCntns && !DXIsElementValid (xf->invCntns, k))
176 continue;
177
178 /* copy vertex coordinates into clist */
179 if (is_2d)
180 for (i = start, dV = 0; i < end; i++, dV += vsize)
181 {
182 *(struct p2d *)(clist+dV) = pnts2d[edges[i]];
183 ((Point *)(clist+dV))->z = 0;
184 }
185 else
186 for (i = start, dV = 0; i < end; i++, dV += vsize)
187 *(Point *)(clist+dV) = points[edges[i]];
188
189 if (xf->colorsDep == dep_positions)
190 {
191 if (color_map)
192 for (i = start, dV = cOffs; i < end; i++, dV += vsize)
193 *(RGBColor *)(clist+dV) =
194 color_map[((char *)fcolors)[edges[i]]];
195 else
196 for (i = start, dV = cOffs; i < end; i++, dV += vsize)
197 *(RGBColor *)(clist+dV) = fcolors[edges[i]];
198 }
199 else if (xf->colorsDep == dep_polylines)
200 {
201 if (color_map)
202 for (i = start, dV = cOffs; i < end; i++, dV += vsize)
203 *(RGBColor *)(clist+dV) =
204 color_map[((char *)fcolors)[k]];
205 else
206 for (i = start, dV = cOffs; i < end; i++, dV += vsize)
207 *(RGBColor *)(clist+dV) = fcolors[k];
208 }
209
210 polyline_with_data3d(FILDES, clist, knt,
211 num_coords, vertex_flags, NULL);
212 }
213 break;
214 }
215
216 if (clist) tdmFree(clist);
217 hidden_surface (FILDES, FALSE, FALSE);
218 EXIT(("OK"));
219 return OK;
220
221 error:
222 if (clist) tdmFree(clist);
223 hidden_surface (FILDES, FALSE, FALSE);
224 EXIT(("ERROR"));
225 return ERROR;
226 }
227