source: branches/1.3/gui/src/RpDxToVtk.c @ 3877

Last change on this file since 3877 was 3877, checked in by ldelgass, 11 years ago

Merge from trunk

File size: 23.3 KB
Line 
1
2/*
3 * ----------------------------------------------------------------------
4 *  RpDxToVtk -
5 *
6 * ======================================================================
7 *  AUTHOR:  Michael McLennan, Purdue University
8 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
9 *
10 *  See the file "license.terms" for information on usage and
11 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * ======================================================================
13 */
14#include <stdio.h>
15#include <string.h>
16#include <stdlib.h>
17#include <sys/types.h>
18#include <unistd.h>
19#include <ctype.h>
20#include <math.h>
21#include <limits.h>
22#include <float.h>
23#include "tcl.h"
24
25#define DO_WEDGES
26
27static INLINE char *
28SkipSpaces(char *string)
29{
30    while (isspace(*string)) {
31        string++;
32    }
33    return string;
34}
35
36static INLINE char *
37GetLine(char **stringPtr, const char *endPtr)
38{
39    char *line, *p;
40
41    line = SkipSpaces(*stringPtr);
42    for (p = line; p < endPtr; p++) {
43        if (*p == '\n') {
44            *stringPtr = p + 1;
45            return line;
46        }
47    }
48    *stringPtr = p;
49    return line;
50}
51
52static int
53GetUniformFieldValues(Tcl_Interp *interp, int nPoints, int *counts, char **stringPtr,
54                      const char *endPtr, Tcl_Obj *objPtr)
55{
56    int i;
57    const char *p;
58    char mesg[2000];
59    double *array, scale, vmin, vmax;
60    int iX, iY, iZ;
61
62    p = *stringPtr;
63    array = malloc(sizeof(double) * nPoints);
64    if (array == NULL) {
65        return TCL_ERROR;
66    }
67    vmin = DBL_MAX, vmax = -DBL_MAX;
68    iX = iY = iZ = 0;
69    for (i = 0; i < nPoints; i++) {
70        double value;
71        char *nextPtr;
72        int loc;
73
74        if (p >= endPtr) {
75            Tcl_AppendResult(interp, "unexpected EOF in reading points",
76                             (char *)NULL);
77            return TCL_ERROR;
78        }
79        value = strtod(p, &nextPtr);
80        if (nextPtr == p) {
81            Tcl_AppendResult(interp, "bad value found in reading points",
82                             (char *)NULL);
83            return TCL_ERROR;
84        }
85        p = nextPtr;
86        loc = iZ*counts[0]*counts[1] + iY*counts[0] + iX;
87        if (++iZ >= counts[2]) {
88            iZ = 0;
89            if (++iY >= counts[1]) {
90                iY = 0;
91                ++iX;
92            }
93        }
94        array[loc] = value;
95        if (value < vmin) {
96            vmin = value;
97        }
98        if (value > vmax) {
99            vmax = value;
100        }
101    }
102    scale = 1.0 / (vmax - vmin);
103    for (i = 0; i < nPoints; i++) {
104#ifdef notdef
105        sprintf(mesg, "%g\n", (array[i] - vmin) * scale);
106#endif
107        sprintf(mesg, "%g\n", array[i]);
108        Tcl_AppendToObj(objPtr, mesg, -1);
109    }
110    free(array);
111    *stringPtr = (char *)p;
112    return TCL_OK;
113}
114
115static int
116GetStructuredGridFieldValues(Tcl_Interp *interp, int nPoints, char **stringPtr,
117                             const char *endPtr, Tcl_Obj *objPtr)
118{
119    int i;
120    const char *p;
121    char mesg[2000];
122    double *array, scale, vmin, vmax;
123
124    p = *stringPtr;
125    array = malloc(sizeof(double) * nPoints);
126    if (array == NULL) {
127        return TCL_ERROR;
128    }
129    vmin = DBL_MAX, vmax = -DBL_MAX;
130    for (i = 0; i < nPoints; i++) {
131        double value;
132        char *nextPtr;
133
134        if (p >= endPtr) {
135            Tcl_AppendResult(interp, "unexpected EOF in reading points",
136                             (char *)NULL);
137            return TCL_ERROR;
138        }
139        value = strtod(p, &nextPtr);
140        if (nextPtr == p) {
141            Tcl_AppendResult(interp, "bad value found in reading points",
142                             (char *)NULL);
143            return TCL_ERROR;
144        }
145        p = nextPtr;
146        array[i] = value;
147        if (value < vmin) {
148            vmin = value;
149        }
150        if (value > vmax) {
151            vmax = value;
152        }
153    }
154    scale = 1.0 / (vmax - vmin);
155    for (i = 0; i < nPoints; i++) {
156#ifdef notdef
157        sprintf(mesg, "%g\n", (array[i] - vmin) * scale);
158#endif
159        sprintf(mesg, "%g\n", array[i]);
160        Tcl_AppendToObj(objPtr, mesg, -1);
161    }
162    free(array);
163    *stringPtr = (char *)p;
164    return TCL_OK;
165}
166
167static int
168GetCloudFieldValues(Tcl_Interp *interp, int nXYPoints, int nZPoints, char **stringPtr,
169                    const char *endPtr, Tcl_Obj *objPtr)
170{
171    int i;
172    const char *p;
173    char mesg[2000];
174    double *array, scale, vmin, vmax;
175    int iXY, iZ;
176    int nPoints;
177
178    nPoints = nXYPoints * nZPoints;
179
180    p = *stringPtr;
181    array = malloc(sizeof(double) * nPoints);
182    if (array == NULL) {
183        return TCL_ERROR;
184    }
185    vmin = DBL_MAX, vmax = -DBL_MAX;
186    iXY = iZ = 0;
187    for (i = 0; i < nPoints; i++) {
188        double value;
189        char *nextPtr;
190        int loc;
191
192        if (p >= endPtr) {
193            Tcl_AppendResult(interp, "unexpected EOF in reading points",
194                             (char *)NULL);
195            return TCL_ERROR;
196        }
197        value = strtod(p, &nextPtr);
198        if (nextPtr == p) {
199            Tcl_AppendResult(interp, "bad value found in reading points",
200                             (char *)NULL);
201            return TCL_ERROR;
202        }
203        p = nextPtr;
204        loc = nXYPoints * iZ + iXY;
205        if (++iZ >= nZPoints) {
206            iZ = 0;
207            ++iXY;
208        }
209        array[loc] = value;
210        if (value < vmin) {
211            vmin = value;
212        }
213        if (value > vmax) {
214            vmax = value;
215        }
216    }
217    scale = 1.0 / (vmax - vmin);
218    for (i = 0; i < nPoints; i++) {
219#ifdef notdef
220        sprintf(mesg, "%g\n", (array[i] - vmin) * scale);
221#endif
222        sprintf(mesg, "%g\n", array[i]);
223        Tcl_AppendToObj(objPtr, mesg, -1);
224    }
225    free(array);
226    *stringPtr = (char *)p;
227    return TCL_OK;
228}
229
230static int
231GetPoints(Tcl_Interp *interp, double *array, int nXYPoints,
232          char **stringPtr, const char *endPtr)
233{
234    int i;
235    const char *p;
236
237    p = *stringPtr;
238    if (array == NULL) {
239        return TCL_ERROR;
240    }
241    for (i = 0; i < nXYPoints; i++) {
242        double x, y;
243        char *nextPtr;
244
245        if (p >= endPtr) {
246            Tcl_AppendResult(interp, "unexpected EOF in reading points",
247                             (char *)NULL);
248            return TCL_ERROR;
249        }
250        x = strtod(p, &nextPtr);
251        if (nextPtr == p) {
252            Tcl_AppendResult(interp, "bad value found in reading points",
253                             (char *)NULL);
254            return TCL_ERROR;
255        }
256        p = nextPtr;
257        y = strtod(p, &nextPtr);
258        if (nextPtr == p) {
259            Tcl_AppendResult(interp, "bad value found in reading points",
260                             (char *)NULL);
261            return TCL_ERROR;
262        }
263        p = nextPtr;
264        /* z is unused */
265        strtod(p, &nextPtr);
266        if (nextPtr == p) {
267            Tcl_AppendResult(interp, "bad value found in reading points",
268                             (char *)NULL);
269            return TCL_ERROR;
270        }
271        p = nextPtr;
272
273        array[i*2  ] = x;
274        array[i*2+1] = y;
275    }
276
277    *stringPtr = (char *)p;
278    return TCL_OK;
279}
280
281static void
282Normalize(double v[3])
283{
284    double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
285    v[0] /= len;
286    v[1] /= len;
287    v[2] /= len;
288}
289
290static double
291Dot(double v1[3], double v2[3])
292{
293    return (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
294}
295
296static void
297Cross(double v1[3], double v2[3], double vout[3])
298{
299    vout[0] = v1[1]*v2[2] - v1[2]*v2[1];
300    vout[1] = v1[2]*v2[0] - v1[0]*v2[2];
301    vout[2] = v1[0]*v2[1] - v1[1]*v2[0];
302}
303
304/*
305 *  DxToVtk string
306 *
307 * In DX format:
308 *  rank 0 means scalars,
309 *  rank 1 means vectors,
310 *  rank 2 means matrices,
311 *  rank 3 means tensors
312 *
313 *  For rank 1, shape is a single number equal to the number of dimensions.
314 *  e.g. rank 1 shape 3 means a 3-component vector field
315 *
316 */
317
318static int
319DxToVtkCmd(ClientData clientData, Tcl_Interp *interp, int objc,
320           Tcl_Obj *const *objv)
321{
322    double *points;
323    Tcl_Obj *objPtr, *pointsObjPtr, *fieldObjPtr, *cellsObjPtr;
324    char *p, *pend;
325    char *string;
326    char mesg[2000];
327    double dv0[3], dv1[3], dv2[3];
328    double dx, dy, dz;
329    double origin[3];
330    int count[3];
331    int length, nAxes, nPoints, nXYPoints, nCells;
332    char *name;
333    int isUniform;
334    int isStructuredGrid;
335    int i, ix, iy, iz;
336
337    name = "component";
338    points = NULL;
339    nAxes = nPoints = nXYPoints = nCells = 0;
340    dx = dy = dz = 0.0; /* Suppress compiler warning. */
341    origin[0] = origin[1] = origin[2] = 0.0; /* May not have an origin line. */
342    dv0[0] = dv0[1] = dv0[2] = 0.0;
343    dv1[0] = dv1[1] = dv1[2] = 0.0;
344    dv2[0] = dv2[1] = dv2[2] = 0.0;
345    count[0] = count[1] = count[2] = 0; /* Suppress compiler warning. */
346    isUniform = 1; /* Default to expecting uniform grid */
347    isStructuredGrid = 0;
348
349    if (objc != 2) {
350        Tcl_AppendResult(interp, "wrong # arguments: should be \"",
351                         Tcl_GetString(objv[0]), " string\"", (char *)NULL);
352        return TCL_ERROR;
353    }
354    string = Tcl_GetStringFromObj(objv[1], &length);
355    if (strncmp("<ODX>", string, 5) == 0) {
356        string += 5;
357        length -= 5;
358    }
359    pointsObjPtr = Tcl_NewStringObj("", -1);
360    cellsObjPtr = Tcl_NewStringObj("", -1);
361    fieldObjPtr = Tcl_NewStringObj("", -1);
362    for (p = string, pend = p + length; p < pend; /*empty*/) {
363        char *line;
364        double ddx, ddy, ddz;
365
366        line = GetLine(&p, pend);
367        if (line >= pend) {
368            break;                        /* EOF */
369        }
370        if ((line[0] == '#') || (line[0] == '\n')) {
371            continue;                        /* Skip blank or comment lines. */
372        }
373        if (sscanf(line, "object %*d class gridpositions counts %d %d %d",
374                   count, count + 1, count + 2) == 3) {
375            isUniform = 1;
376            if ((count[0] < 0) || (count[1] < 0) || (count[2] < 0)) {
377                sprintf(mesg, "invalid grid size: x=%d, y=%d, z=%d",
378                        count[0], count[1], count[2]);
379                Tcl_AppendResult(interp, mesg, (char *)NULL);
380                return TCL_ERROR;
381            }
382#ifdef notdef
383            fprintf(stderr, "found gridpositions counts %d %d %d\n",
384                    count[0], count[1], count[2]);
385#endif
386        } else if (sscanf(line, "origin %lg %lg %lg", origin, origin + 1,
387                origin + 2) == 3) {
388            /* Found origin. */
389#ifdef notdef
390            fprintf(stderr, "found origin %g %g %g\n",
391                    origin[0], origin[1], origin[2]);
392#endif
393        } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
394            if (nAxes == 3) {
395                Tcl_AppendResult(interp, "too many delta statements",
396                        (char *)NULL);
397                return TCL_ERROR;
398            }
399            switch (nAxes) {
400            case 0:
401                dv0[0] = ddx;
402                dv0[1] = ddy;
403                dv0[2] = ddz;
404                break;
405            case 1:
406                dv1[0] = ddx;
407                dv1[1] = ddy;
408                dv1[2] = ddz;
409                break;
410            case 2:
411                dv2[0] = ddx;
412                dv2[1] = ddy;
413                dv2[2] = ddz;
414                break;
415            default:
416                break;
417            }
418
419            if (ddx != 0.0) {
420                if (ddy != 0.0 || ddz != 0.0) {
421                    /* Not axis aligned or skewed grid */
422                    isUniform = 0;
423                    isStructuredGrid = 1;
424                }
425                dx = ddx;
426            } else if (ddy != 0.0) {
427                if (ddx != 0.0 || ddz != 0.0) {
428                    /* Not axis aligned or skewed grid */
429                    isUniform = 0;
430                    isStructuredGrid = 1;
431                }
432                dy = ddy;
433            } else if (ddz != 0.0) {
434                if (ddx != 0.0 || ddy != 0.0) {
435                    /* Not axis aligned or skewed grid */
436                    isUniform = 0;
437                    isStructuredGrid = 1;
438                }
439                dz = ddz;
440            }
441            nAxes++;
442#ifdef notdef
443            fprintf(stderr, "found delta %g %g %g\n", ddx, ddy, ddx);
444#endif
445        } else if (sscanf(line, "object %*d class regulararray count %d",
446                          &count[2]) == 1) {
447            // Z grid
448        } else if (sscanf(line, "object %*d class array type %*s rank 1 shape 3"
449                          " items %d data follows", &nXYPoints) == 1) {
450            // This is a 2D point cloud in xy with a uniform zgrid
451            isUniform = 0;
452#ifdef notdef
453            fprintf(stderr, "found class array type shape 3 nPoints=%d\n",
454                    nPoints);
455#endif
456            if (nXYPoints < 0) {
457                sprintf(mesg, "bad # points %d", nXYPoints);
458                Tcl_AppendResult(interp, mesg, (char *)NULL);
459                return TCL_ERROR;
460            }
461            points = malloc(sizeof(double) * nXYPoints * 2);
462            if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) {
463                return TCL_ERROR;
464            }
465        } else if (sscanf(line, "object %*d class array type %*s rank 0"
466                          " %*s %d data follows", &nPoints) == 1) {
467#ifdef notdef
468            fprintf(stderr, "found class array type rank 0 nPoints=%d\n",
469                nPoints);
470#endif
471            if ((isUniform || isStructuredGrid) &&
472                nPoints != count[0]*count[1]*count[2]) {
473                sprintf(mesg, "inconsistent data: expected %d points"
474                        " but found %d points", count[0]*count[1]*count[2],
475                        nPoints);
476                Tcl_AppendResult(interp, mesg, (char *)NULL);
477                return TCL_ERROR;
478            } else if (!(isUniform || isStructuredGrid) &&
479                       nPoints != nXYPoints * count[2]) {
480                sprintf(mesg, "inconsistent data: expected %d points"
481                        " but found %d points", nXYPoints * count[2],
482                        nPoints);
483                Tcl_AppendResult(interp, mesg, (char *)NULL);
484                return TCL_ERROR;
485            }
486            if (isUniform) {
487                if (GetUniformFieldValues(interp, nPoints, count, &p, pend, fieldObjPtr)
488                    != TCL_OK) {
489                    return TCL_ERROR;
490                }
491            } else if (isStructuredGrid) {
492                if (GetStructuredGridFieldValues(interp, nPoints, &p, pend, fieldObjPtr)
493                    != TCL_OK) {
494                    return TCL_ERROR;
495                }
496            } else {
497                if (GetCloudFieldValues(interp, nXYPoints, count[2], &p, pend, fieldObjPtr)
498                    != TCL_OK) {
499                    return TCL_ERROR;
500                }
501            }
502#ifdef notdef
503        } else {
504            fprintf(stderr, "unknown line (%.80s)\n", line);
505#endif
506        }
507    }
508
509    if (isUniform) {
510        objPtr = Tcl_NewStringObj("# vtk DataFile Version 2.0\n", -1);
511        Tcl_AppendToObj(objPtr, "Converted from DX file\n", -1);
512        Tcl_AppendToObj(objPtr, "ASCII\n", -1);
513        Tcl_AppendToObj(objPtr, "DATASET STRUCTURED_POINTS\n", -1);
514        sprintf(mesg, "DIMENSIONS %d %d %d\n", count[0], count[1], count[2]);
515        Tcl_AppendToObj(objPtr, mesg, -1);
516        sprintf(mesg, "ORIGIN %g %g %g\n", origin[0], origin[1], origin[2]);
517        Tcl_AppendToObj(objPtr, mesg, -1);
518        sprintf(mesg, "SPACING %g %g %g\n", dx, dy, dz);
519        Tcl_AppendToObj(objPtr, mesg, -1);
520        sprintf(mesg, "POINT_DATA %d\n", nPoints);
521        Tcl_AppendToObj(objPtr, mesg, -1);
522        sprintf(mesg, "SCALARS %s double 1\n", name);
523        Tcl_AppendToObj(objPtr, mesg, -1);
524        sprintf(mesg, "LOOKUP_TABLE default\n");
525        Tcl_AppendToObj(objPtr, mesg, -1);
526        Tcl_AppendObjToObj(objPtr, fieldObjPtr);
527    } else if (isStructuredGrid) {
528#ifdef notdef
529        fprintf(stderr, "dv0 %g %g %g\n", dv0[0], dv0[1], dv0[2]);
530        fprintf(stderr, "dv1 %g %g %g\n", dv1[0], dv1[1], dv1[2]);
531        fprintf(stderr, "dv2 %g %g %g\n", dv2[0], dv2[1], dv2[2]);
532#endif
533        objPtr = Tcl_NewStringObj("# vtk DataFile Version 2.0\n", -1);
534        Tcl_AppendToObj(objPtr, "Converted from DX file\n", -1);
535        Tcl_AppendToObj(objPtr, "ASCII\n", -1);
536        Tcl_AppendToObj(objPtr, "DATASET STRUCTURED_GRID\n", -1);
537        sprintf(mesg, "DIMENSIONS %d %d %d\n", count[0], count[1], count[2]);
538        Tcl_AppendToObj(objPtr, mesg, -1);
539        for (iz = 0; iz < count[2]; iz++) {
540            for (iy = 0; iy < count[1]; iy++) {
541                for (ix = 0; ix < count[0]; ix++) {
542                    double x, y, z;
543                    x = origin[0] + dv2[0] * iz + dv1[0] * iy + dv0[0] * ix;
544                    y = origin[1] + dv2[1] * iz + dv1[1] * iy + dv0[1] * ix;
545                    z = origin[2] + dv2[2] * iz + dv1[2] * iy + dv0[2] * ix;
546                    sprintf(mesg, "%g %g %g\n", x, y, z);
547                    Tcl_AppendToObj(pointsObjPtr, mesg, -1);
548                }
549            }
550        }
551        sprintf(mesg, "POINTS %d double\n", nPoints);
552        Tcl_AppendToObj(objPtr, mesg, -1);
553        Tcl_AppendObjToObj(objPtr, pointsObjPtr);
554        sprintf(mesg, "POINT_DATA %d\n", nPoints);
555        Tcl_AppendToObj(objPtr, mesg, -1);
556        sprintf(mesg, "SCALARS %s double 1\n", name);
557        Tcl_AppendToObj(objPtr, mesg, -1);
558        sprintf(mesg, "LOOKUP_TABLE default\n");
559        Tcl_AppendToObj(objPtr, mesg, -1);
560        Tcl_AppendObjToObj(objPtr, fieldObjPtr);
561    } else {
562        /* Fill points.  Have to wait to do this since origin, delta can come after
563         * the point list in the file.
564         */
565        for (iz = 0; iz < count[2]; iz++) {
566            for (i = 0; i < nXYPoints; i++) {
567                sprintf(mesg, "%g %g %g\n", points[i*2], points[i*2+1], origin[2] + dz * iz);
568                Tcl_AppendToObj(pointsObjPtr, mesg, -1);
569            }
570        }
571
572        objPtr = Tcl_NewStringObj("# vtk DataFile Version 2.0\n", -1);
573        Tcl_AppendToObj(objPtr, "Converted from DX file\n", -1);
574        Tcl_AppendToObj(objPtr, "ASCII\n", -1);
575        Tcl_AppendToObj(objPtr, "DATASET UNSTRUCTURED_GRID\n", -1);
576        sprintf(mesg, "POINTS %d double\n", nPoints);
577        Tcl_AppendToObj(objPtr, mesg, -1);
578        Tcl_AppendObjToObj(objPtr, pointsObjPtr);
579#ifdef DO_WEDGES
580        {
581            double xmin, xmax, ymin, ymax;
582            xmin = xmax = points[0];
583            ymin = ymax = points[1];
584            for (i = 1; i < nXYPoints; i++) {
585                double x, y;
586                x = points[i*2];
587                y = points[i*2+1];
588                if (x < xmin) xmin = x;
589                if (x > xmax) xmax = x;
590                if (y < ymin) ymin = y;
591                if (y > ymax) ymax = y;
592            }
593
594            char fpts[128];
595            sprintf(fpts, "/tmp/tmppts%d", getpid());
596            char fcells[128];
597            sprintf(fcells, "/tmp/tmpcells%d", getpid());
598
599            FILE *ftmp = fopen(fpts, "w");
600            // save corners of bounding box first, to work around meshing
601            // problems in voronoi utility
602            int numBoundaryPoints = 4;
603
604            // Bump out the bounds by an epsilon to avoid problem when
605            // corner points are already nodes
606            double XEPS = (xmax - xmin) / 10.0f;
607            double YEPS = (ymax - ymin) / 10.0f;
608
609            fprintf(ftmp, "%g %g\n", xmin - XEPS, ymin - YEPS);
610            fprintf(ftmp, "%g %g\n", xmax + XEPS, ymin - YEPS);
611            fprintf(ftmp, "%g %g\n", xmax + XEPS, ymax + YEPS);
612            fprintf(ftmp, "%g %g\n", xmin - XEPS, ymax + YEPS);
613
614            for (i = 0; i < nXYPoints; i++) {
615                fprintf(ftmp, "%g %g\n", points[i*2], points[i*2+1]);
616            }
617            fclose(ftmp);
618#ifdef notdef
619            double normal[3];
620            normal[0] = normal[1] = 0.0;
621            if (dx >= 0) {
622                normal[2] = 1.0;
623            } else {
624                normal[2] = -1.0;
625            }
626#endif
627            char cmdstr[512];
628            sprintf(cmdstr, "voronoi -t < %s > %s", fpts, fcells);
629            if (system(cmdstr) == 0) {
630                int c0, c1, c2;
631                ftmp = fopen(fcells, "r");
632                while (!feof(ftmp)) {
633                    if (fscanf(ftmp, "%d %d %d", &c0, &c1, &c2) == 3) {
634                        c0 -= numBoundaryPoints;
635                        c1 -= numBoundaryPoints;
636                        c2 -= numBoundaryPoints;
637                        // skip boundary points we added
638                        if (c0 >= 0 && c1 >= 0 && c2 >= 0) {
639#ifdef notdef
640                            /* Winding of base triangle should point to
641                               outside of cell using right hand rule */
642                            double v1[3], v2[3], c[3];
643                            v1[0] = points[c1*2] - points[c0*2];
644                            v1[1] = points[c1*2+1] - points[c0*2+1];
645                            v1[2] = 0;
646                            v2[0] = points[c2*2] - points[c0*2];
647                            v2[1] = points[c2*2+1] - points[c0*2+1];
648                            v2[2] = 0;
649                            Cross(v1, v2, c);
650                            if (Dot(normal, c) > 0) {
651                                int tmp = c0;
652                                c0 = c2;
653                                c2 = tmp;
654                            }
655#endif
656                            for (iz = 0; iz < count[2] - 1; iz++) {
657                                int base = nXYPoints * iz;
658                                int top = base + nXYPoints;
659                                nCells++;
660                                sprintf(mesg, "%d %d %d %d %d %d %d\n", 6,
661                                        base + c0, base + c1, base + c2,
662                                        top + c0, top + c1, top + c2);
663                                Tcl_AppendToObj(cellsObjPtr, mesg, -1);
664                            }
665                        }
666                    } else {
667                        break;
668                    }
669                }
670                fclose(ftmp);
671             } else {
672                fprintf(stderr, "voronoi mesher failed");
673            }
674            unlink(fpts);
675            unlink(fcells);
676        }
677        free(points);
678        sprintf(mesg, "CELLS %d %d\n", nCells, 7*nCells);
679        Tcl_AppendToObj(objPtr, mesg, -1);
680        Tcl_AppendObjToObj(objPtr, cellsObjPtr);
681        sprintf(mesg, "CELL_TYPES %d\n", nCells);
682        Tcl_AppendToObj(objPtr, mesg, -1);
683        sprintf(mesg, "%d\n", 13);
684        for (i = 0; i < nCells; i++) {
685            Tcl_AppendToObj(objPtr, mesg, -1);
686        }
687#endif
688        sprintf(mesg, "POINT_DATA %d\n", nPoints);
689        Tcl_AppendToObj(objPtr, mesg, -1);
690        sprintf(mesg, "SCALARS %s double 1\n", name);
691        Tcl_AppendToObj(objPtr, mesg, -1);
692        sprintf(mesg, "LOOKUP_TABLE default\n");
693        Tcl_AppendToObj(objPtr, mesg, -1);
694        Tcl_AppendObjToObj(objPtr, fieldObjPtr);
695    }
696
697    Tcl_DecrRefCount(pointsObjPtr);
698    Tcl_DecrRefCount(cellsObjPtr);
699    Tcl_DecrRefCount(fieldObjPtr);
700    Tcl_SetObjResult(interp, objPtr);
701    return TCL_OK;
702}
703
704/*
705 * ------------------------------------------------------------------------
706 *  RpDxToVtk_Init --
707 *
708 *  Invoked when the Rappture GUI library is being initialized
709 *  to install the "DxToVtk" command into the interpreter.
710 *
711 *  Returns TCL_OK if successful, or TCL_ERROR (along with an error
712 *  message in the interp) if anything goes wrong.
713 * ------------------------------------------------------------------------
714 */
715int
716RpDxToVtk_Init(Tcl_Interp *interp)
717{
718    /* install the widget command */
719    Tcl_CreateObjCommand(interp, "Rappture::DxToVtk", DxToVtkCmd,
720        NULL, NULL);
721    return TCL_OK;
722}
Note: See TracBrowser for help on using the repository browser.