Changeset 3944 for trunk


Ignore:
Timestamp:
Sep 21, 2013, 5:48:43 PM (11 years ago)
Author:
ldelgass
Message:

Add support for converting DX with vectors to VTK

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/src/RpDxToVtk.c

    r3882 r3944  
    7373
    7474        if (p >= endPtr) {
    75             Tcl_AppendResult(interp, "unexpected EOF in reading points",
    76                              (char *)NULL);
     75            Tcl_AppendResult(interp, "unexpected EOF in reading field values",
     76                             (char *)NULL);
     77            free(array);
    7778            return TCL_ERROR;
    7879        }
    7980        value = strtod(p, &nextPtr);
    8081        if (nextPtr == p) {
    81             Tcl_AppendResult(interp, "bad value found in reading points",
    82                              (char *)NULL);
     82            Tcl_AppendResult(interp, "bad value found in reading field values",
     83                             (char *)NULL);
     84            free(array);
    8385            return TCL_ERROR;
    8486        }
     
    122124
    123125        if (p >= endPtr) {
    124             Tcl_AppendResult(interp, "unexpected EOF in reading points",
    125                              (char *)NULL);
     126            Tcl_AppendResult(interp, "unexpected EOF in reading field values",
     127                             (char *)NULL);
     128            free(array);
    126129            return TCL_ERROR;
    127130        }
    128131        value = strtod(p, &nextPtr);
    129132        if (nextPtr == p) {
    130             Tcl_AppendResult(interp, "bad value found in reading points",
    131                              (char *)NULL);
     133            Tcl_AppendResult(interp, "bad value found in reading field values",
     134                             (char *)NULL);
     135            free(array);
    132136            return TCL_ERROR;
    133137        }
     
    169173
    170174        if (p >= endPtr) {
    171             Tcl_AppendResult(interp, "unexpected EOF in reading points",
    172                              (char *)NULL);
     175            Tcl_AppendResult(interp, "unexpected EOF in reading field values",
     176                             (char *)NULL);
     177            free(array);
    173178            return TCL_ERROR;
    174179        }
    175180        value = strtod(p, &nextPtr);
    176181        if (nextPtr == p) {
    177             Tcl_AppendResult(interp, "bad value found in reading points",
    178                              (char *)NULL);
     182            Tcl_AppendResult(interp, "bad value found in reading field values",
     183                             (char *)NULL);
     184            free(array);
    179185            return TCL_ERROR;
    180186        }
     
    246252    return TCL_OK;
    247253}
     254
     255static int
     256GetUniformFieldVectors(Tcl_Interp *interp, int nPoints, int *counts,
     257                       char **stringPtr, const char *endPtr, Tcl_Obj *objPtr)
     258{
     259    int i;
     260    const char *p;
     261    char mesg[2000];
     262    double *array;
     263    int iX, iY, iZ;
     264
     265    p = *stringPtr;
     266    array = malloc(sizeof(double) * nPoints * 3);
     267    if (array == NULL) {
     268        return TCL_ERROR;
     269    }
     270    iX = iY = iZ = 0;
     271    for (i = 0; i < nPoints; i++) {
     272        double x, y, z;
     273        char *nextPtr;
     274        int loc;
     275
     276        if (p >= endPtr) {
     277            Tcl_AppendResult(interp, "unexpected EOF in reading vectors",
     278                             (char *)NULL);
     279            free(array);
     280            return TCL_ERROR;
     281        }
     282        x = strtod(p, &nextPtr);
     283        if (nextPtr == p) {
     284            Tcl_AppendResult(interp, "bad value found in reading vectors",
     285                             (char *)NULL);
     286            free(array);
     287            return TCL_ERROR;
     288        }
     289        p = nextPtr;
     290        y = strtod(p, &nextPtr);
     291        if (nextPtr == p) {
     292            Tcl_AppendResult(interp, "bad value found in reading vectors",
     293                             (char *)NULL);
     294            free(array);
     295            return TCL_ERROR;
     296        }
     297        p = nextPtr;
     298        z = strtod(p, &nextPtr);
     299        if (nextPtr == p) {
     300            Tcl_AppendResult(interp, "bad value found in reading vectors",
     301                             (char *)NULL);
     302            free(array);
     303            return TCL_ERROR;
     304        }
     305        p = nextPtr;
     306        loc = iZ*counts[0]*counts[1] + iY*counts[0] + iX;
     307        if (++iZ >= counts[2]) {
     308            iZ = 0;
     309            if (++iY >= counts[1]) {
     310                iY = 0;
     311                ++iX;
     312            }
     313        }
     314        array[loc*3  ] = x;
     315        array[loc*3+1] = y;
     316        array[loc*3+2] = z;
     317    }
     318    for (i = 0; i < nPoints; i++) {
     319        sprintf(mesg, "%g %g %g\n", array[i*3], array[i*3+1], array[i*3+2]);
     320        Tcl_AppendToObj(objPtr, mesg, -1);
     321    }
     322    free(array);
     323    *stringPtr = (char *)p;
     324    return TCL_OK;
     325}
     326
    248327#if defined(DO_WEDGES) && defined(CHECK_WINDINGS)
    249328static void
     
    301380    int isUniform;
    302381    int isStructuredGrid;
     382    int hasVectors;
    303383    int i, ix, iy, iz;
    304384
     
    312392    dv2[0] = dv2[1] = dv2[2] = 0.0;
    313393    count[0] = count[1] = count[2] = 0; /* Suppress compiler warning. */
    314     isUniform = 1; /* Default to expecting uniform grid */
     394    isUniform = 0;
    315395    isStructuredGrid = 0;
     396    hasVectors = 0;
    316397
    317398    if (objc != 2) {
     
    414495                          &count[2]) == 1) {
    415496            // Z grid
     497            isUniform = 0;
     498        } else if (sscanf(line, "object %*d class array type %*s shape 3 rank 1"
     499                          " items %d data follows", &nPoints) == 1) {
     500#ifdef notdef
     501                fprintf(stderr, "found class array type shape 3 nPoints=%d\n",
     502                        nPoints);
     503#endif
     504            if (isUniform) {
     505                hasVectors = 1;
     506                if (GetUniformFieldVectors(interp, nPoints, count, &p, pend, fieldObjPtr)
     507                    != TCL_OK) {
     508                    return TCL_ERROR;
     509                }
     510            } else {
     511                // This is a 2D point cloud in xy with a uniform zgrid
     512                isUniform = 0;
     513                nXYPoints = nPoints;
     514                if (nXYPoints < 0) {
     515                    sprintf(mesg, "bad # points %d", nXYPoints);
     516                    Tcl_AppendResult(interp, mesg, (char *)NULL);
     517                    return TCL_ERROR;
     518                }
     519                points = malloc(sizeof(double) * nXYPoints * 2);
     520                if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) {
     521                    return TCL_ERROR;
     522                }
     523            }
    416524        } else if (sscanf(line, "object %*d class array type %*s rank 1 shape 3"
    417                           " items %d data follows", &nXYPoints) == 1) {
    418             // This is a 2D point cloud in xy with a uniform zgrid
    419             isUniform = 0;
     525                          " items %d data follows", &nPoints) == 1) {
    420526#ifdef notdef
    421             fprintf(stderr, "found class array type shape 3 nPoints=%d\n",
    422                     nPoints);
    423 #endif
    424             if (nXYPoints < 0) {
    425                 sprintf(mesg, "bad # points %d", nXYPoints);
    426                 Tcl_AppendResult(interp, mesg, (char *)NULL);
    427                 return TCL_ERROR;
    428             }
    429             points = malloc(sizeof(double) * nXYPoints * 2);
    430             if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) {
    431                 return TCL_ERROR;
     527                fprintf(stderr, "found class array type shape 3 nPoints=%d\n",
     528                        nPoints);
     529#endif
     530            if (isUniform) {
     531                hasVectors = 1;
     532                if (GetUniformFieldVectors(interp, nPoints, count, &p, pend, fieldObjPtr)
     533                    != TCL_OK) {
     534                    return TCL_ERROR;
     535                }
     536            } else {
     537                // This is a 2D point cloud in xy with a uniform zgrid
     538                isUniform = 0;
     539                nXYPoints = nPoints;
     540                if (nXYPoints < 0) {
     541                    sprintf(mesg, "bad # points %d", nXYPoints);
     542                    Tcl_AppendResult(interp, mesg, (char *)NULL);
     543                    return TCL_ERROR;
     544                }
     545                points = malloc(sizeof(double) * nXYPoints * 2);
     546                if (GetPoints(interp, points, nXYPoints, &p, pend) != TCL_OK) {
     547                    return TCL_ERROR;
     548                }
    432549            }
    433550        } else if (sscanf(line, "object %*d class array type %*s rank 0"
     
    488605        sprintf(mesg, "POINT_DATA %d\n", nPoints);
    489606        Tcl_AppendToObj(objPtr, mesg, -1);
    490         sprintf(mesg, "SCALARS %s double 1\n", name);
    491         Tcl_AppendToObj(objPtr, mesg, -1);
    492         sprintf(mesg, "LOOKUP_TABLE default\n");
    493         Tcl_AppendToObj(objPtr, mesg, -1);
     607        if (hasVectors) {
     608            sprintf(mesg, "VECTORS %s double\n", name);
     609            Tcl_AppendToObj(objPtr, mesg, -1);
     610        } else {
     611            sprintf(mesg, "SCALARS %s double 1\n", name);
     612            Tcl_AppendToObj(objPtr, mesg, -1);
     613            sprintf(mesg, "LOOKUP_TABLE default\n");
     614            Tcl_AppendToObj(objPtr, mesg, -1);
     615        }
    494616        Tcl_AppendObjToObj(objPtr, fieldObjPtr);
    495617    } else if (isStructuredGrid) {
Note: See TracChangeset for help on using the changeset viewer.