Ignore:
Timestamp:
Mar 12, 2012 1:13:51 AM (12 years ago)
Author:
ldelgass
Message:

tabs -> spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/Unirect.cpp

    r2831 r2843  
    1818{
    1919    while (isspace(*string)) {
    20         string++;
     20        string++;
    2121    }
    2222    return string;
     
    3030    line = skipspaces(*stringPtr);
    3131    for (p = line; p < endPtr; p++) {
    32         if (*p == '\n') {
    33             *p++ = '\0';
    34             *stringPtr = p;
    35             return line;
    36         }
     32        if (*p == '\n') {
     33            *p++ = '\0';
     34            *stringPtr = p;
     35            return line;
     36        }
    3737    }
    3838    *stringPtr = p;
     
    4848    int objc;
    4949    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
    50         return TCL_ERROR;
     50        return TCL_ERROR;
    5151    }
    5252    int result;
     
    5454    Tcl_DecrRefCount(objPtr);
    5555    if ((result != TCL_OK) || (!isInitialized())) {
    56         return TCL_ERROR;
     56        return TCL_ERROR;
    5757    }
    5858    return TCL_OK;
     
    6767    int objc;
    6868    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
    69         return TCL_ERROR;
     69        return TCL_ERROR;
    7070    }
    7171    int result;
     
    7373    Tcl_DecrRefCount(objPtr);
    7474    if ((result != TCL_OK) || (!isInitialized())) {
    75         return TCL_ERROR;
     75        return TCL_ERROR;
    7676    }
    7777    return TCL_OK;
     
    8080int
    8181Rappture::Unirect3d::LoadData(Tcl_Interp *interp, int objc,
    82                               Tcl_Obj *const *objv)
     82                              Tcl_Obj *const *objv)
    8383{
    8484    int num[3], nValues;
     
    174174
    175175            if (Tcl_ListObjGetElements(interp, objv[i+1], &nValues, &vobj)
    176                 != TCL_OK) {
     176                != TCL_OK) {
    177177                return TCL_ERROR;
    178178            }
     
    182182                if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) {
    183183                    return TCL_ERROR;
    184                 }
    185             }
     184                }
     185            }
    186186        } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
    187187            _vUnits = strdup(Tcl_GetString(objv[i+1]));
    188188        } else if ((c == 'c') && (strcmp(string, "components") == 0)) {
    189             int n;
    190 
    191             if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
    192                 return TCL_ERROR;
    193             }
    194             if (n <= 0) {
     189            int n;
     190
     191            if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
     192                return TCL_ERROR;
     193            }
     194            if (n <= 0) {
    195195                Tcl_AppendResult(interp, "bad extents value: must be > 0",
    196196                                 (char *)NULL);
    197197                return TCL_ERROR;
    198198            }
    199             _nComponents = n;
     199            _nComponents = n;
    200200        } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) {
    201             Tcl_Obj **axes;
    202             int n;
    203 
    204             if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &axes)
    205                 != TCL_OK) {
    206                 return TCL_ERROR;
    207             }
    208             if (n != 3) {
    209                 return TCL_ERROR;
    210             }
    211             if ((GetAxisFromObj(interp, axes[0], &axis1) != TCL_OK) ||
    212                 (GetAxisFromObj(interp, axes[1], &axis2) != TCL_OK) ||
    213                 (GetAxisFromObj(interp, axes[2], &axis3) != TCL_OK)) {
    214                 return TCL_ERROR;
    215             }
     201            Tcl_Obj **axes;
     202            int n;
     203
     204            if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &axes)
     205                != TCL_OK) {
     206                return TCL_ERROR;
     207            }
     208            if (n != 3) {
     209                return TCL_ERROR;
     210            }
     211            if ((GetAxisFromObj(interp, axes[0], &axis1) != TCL_OK) ||
     212                (GetAxisFromObj(interp, axes[1], &axis2) != TCL_OK) ||
     213                (GetAxisFromObj(interp, axes[2], &axis3) != TCL_OK)) {
     214                return TCL_ERROR;
     215            }
    216216        } else {
    217217            Tcl_AppendResult(interp, "unknown key \"", string,
     
    225225    }
    226226    if ((size_t)nValues != (num[0] * num[1] * num[2] * _nComponents)) {
    227         TRACE("num[0]=%d num[1]=%d num[2]=%d ncomponents=%d nValues=%d\n",
    228                num[0], num[1], num[2], _nComponents, nValues);
     227        TRACE("num[0]=%d num[1]=%d num[2]=%d ncomponents=%d nValues=%d\n",
     228               num[0], num[1], num[2], _nComponents, nValues);
    229229        Tcl_AppendResult(interp,
    230                 "wrong # of values: must be xnum*ynum*znum*extents",
    231                         (char *)NULL);
     230                "wrong # of values: must be xnum*ynum*znum*extents",
     231                        (char *)NULL);
    232232       return TCL_ERROR;
    233233    }
     
    235235#ifdef notdef
    236236    if ((axis1 != 0) || (axis2 != 1) || (axis3 != 2)) {
    237         // Reorder the data into x, y, z where x varies fastest and so on.
    238         int z;
    239         float *data, *dp;
    240 
    241         dp = data = new float[nValues];
    242         for (z = 0; z < num[0]; z++) {
    243             int y;
    244 
    245             for (y = 0; y < num[1]; y++) {
    246                 int x;
    247 
    248                 for (x = 0; x < num[2]; x++) {
    249                     int i;
    250                    
    251                     /* Compute the index from the data's described ordering. */
    252                     i = ((z*num[axis2]*num[axis3]) + (y*num[axis3]) + x) * 3;
    253                     for(size_t v = 0; v < _nComponents; v++) {
    254                         dp[v] = values[i+v];
    255                     }
    256                     dp += _nComponents;
    257                 }
    258             }
    259         }
    260         delete [] values;
    261         values = data;
     237        // Reorder the data into x, y, z where x varies fastest and so on.
     238        int z;
     239        float *data, *dp;
     240
     241        dp = data = new float[nValues];
     242        for (z = 0; z < num[0]; z++) {
     243            int y;
     244
     245            for (y = 0; y < num[1]; y++) {
     246                int x;
     247
     248                for (x = 0; x < num[2]; x++) {
     249                    int i;
     250                   
     251                    /* Compute the index from the data's described ordering. */
     252                    i = ((z*num[axis2]*num[axis3]) + (y*num[axis3]) + x) * 3;
     253                    for(size_t v = 0; v < _nComponents; v++) {
     254                        dp[v] = values[i+v];
     255                    }
     256                    dp += _nComponents;
     257                }
     258            }
     259        }
     260        delete [] values;
     261        values = data;
    262262    }
    263263#endif
    264264    _nValues = nValues;
    265265    if (units[3] != NULL) {
    266         if (_vUnits != NULL) {
    267             free(_vUnits);
    268         }
    269         _vUnits = strdup(units[3]);
     266        if (_vUnits != NULL) {
     267            free(_vUnits);
     268        }
     269        _vUnits = strdup(units[3]);
    270270    }
    271271    _xMin = min[axis3];
     
    273273    _xNum = num[axis3];
    274274    if (units[axis3] != NULL) {
    275         if (_xUnits != NULL) {
    276             free(_xUnits);
    277         }
    278         _xUnits = strdup(units[axis3]);
     275        if (_xUnits != NULL) {
     276            free(_xUnits);
     277        }
     278        _xUnits = strdup(units[axis3]);
    279279    }
    280280    _yMin = min[axis2];
     
    282282    _yNum = num[axis2];
    283283    if (units[axis2] != NULL) {
    284         if (_yUnits != NULL) {
    285             free(_yUnits);
    286         }
    287         _yUnits = strdup(units[axis2]);
     284        if (_yUnits != NULL) {
     285            free(_yUnits);
     286        }
     287        _yUnits = strdup(units[axis2]);
    288288    }
    289289    _zMin = min[axis1];
     
    291291    _zNum = num[axis1];
    292292    if (units[axis1] != NULL) {
    293         if (_zUnits != NULL) {
    294             free(_zUnits);
    295         }
    296         _zUnits = strdup(units[axis1]);
     293        if (_zUnits != NULL) {
     294            free(_zUnits);
     295        }
     296        _zUnits = strdup(units[axis1]);
    297297    }
    298298    _initialized = true;
    299299#ifdef notdef
    300300    {
    301         FILE *f;
    302         f = fopen("/tmp/unirect3d.txt", "w");
    303         fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum);
    304         fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum);
    305         fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum);
    306         fprintf(f, "components %d values {\n",  _nComponents);
    307         for (size_t i = 0; i < _nValues; i+= 3) {
    308             fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]);
    309         }
    310         fprintf(f, "}\n");
    311         fclose(f);
     301        FILE *f;
     302        f = fopen("/tmp/unirect3d.txt", "w");
     303        fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum);
     304        fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum);
     305        fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum);
     306        fprintf(f, "components %d values {\n",  _nComponents);
     307        for (size_t i = 0; i < _nValues; i+= 3) {
     308            fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]);
     309        }
     310        fprintf(f, "}\n");
     311        fclose(f);
    312312    }
    313313#endif
     
    318318int
    319319Rappture::Unirect2d::LoadData(Tcl_Interp *interp, int objc,
    320                               Tcl_Obj *const *objv)
     320                              Tcl_Obj *const *objv)
    321321{
    322322    if ((objc & 0x01) == 0) {
     
    328328
    329329    int axis[2];
    330     axis[0] = 1;                        /* X-axis */
     330    axis[0] = 1;                         /* X-axis */
    331331    axis[1] = 0;                        /* Y-axis */
    332332
     
    334334    _xMin = _yMin = _xMax = _yMax = 0.0f;
    335335    if (_xUnits != NULL) {
    336         free(_xUnits);
     336        free(_xUnits);
    337337    }
    338338    if (_yUnits != NULL) {
    339         free(_yUnits);
     339        free(_yUnits);
    340340    }
    341341    if (_vUnits != NULL) {
    342         free(_vUnits);
     342        free(_vUnits);
    343343    }
    344344    _xUnits = _yUnits = _vUnits = NULL;
     
    361361            }
    362362        } else if ((c == 'x') && (strcmp(string, "xnum") == 0)) {
    363             int n;
     363            int n;
    364364            if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
    365365                return TCL_ERROR;
     
    370370                return TCL_ERROR;
    371371            }
    372             _xNum = n;
     372            _xNum = n;
    373373        } else if ((c == 'x') && (strcmp(string, "xunits") == 0)) {
    374374            _xUnits = strdup(Tcl_GetString(objv[i+1]));
     
    382382            }
    383383        } else if ((c == 'y') && (strcmp(string, "ynum") == 0)) {
    384             int n;
     384            int n;
    385385            if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
    386386                return TCL_ERROR;
     
    391391                return TCL_ERROR;
    392392            }
    393             _yNum = n;
     393            _yNum = n;
    394394        } else if ((c == 'y') && (strcmp(string, "yunits") == 0)) {
    395395            _yUnits = strdup(Tcl_GetString(objv[i+1]));
    396396        } else if ((c == 'v') && (strcmp(string, "values") == 0)) {
    397397            Tcl_Obj **vobj;
    398             int n;
    399 
    400             Tcl_IncrRefCount(objv[i+1]);
     398            int n;
     399
     400            Tcl_IncrRefCount(objv[i+1]);
    401401            if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &vobj) != TCL_OK){
    402402                return TCL_ERROR;
    403403            }
    404             if (n <= 0) {
     404            if (n <= 0) {
    405405                Tcl_AppendResult(interp, "empty values list : must be > 0",
    406406                                 (char *)NULL);
    407407                return TCL_ERROR;
    408             }
    409             _nValues = n;
     408            }
     409            _nValues = n;
    410410            _values = (float *)realloc(_values, sizeof(float) * _nValues);
    411411            size_t j;
     
    413413                if (GetFloatFromObj(interp, vobj[j], _values + j)!=TCL_OK) {
    414414                    return TCL_ERROR;
    415                 }
    416             }
    417             Tcl_DecrRefCount(objv[i+1]);
     415                }
     416            }
     417            Tcl_DecrRefCount(objv[i+1]);
    418418        } else if ((c == 'u') && (strcmp(string, "units") == 0)) {
    419419            _vUnits = strdup(Tcl_GetString(objv[i+1]));
    420420        } else if ((c == 'c') && (strcmp(string, "components") == 0)) {
    421             int n;
    422 
    423             if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
    424                 return TCL_ERROR;
    425             }
    426             if (n <= 0) {
     421            int n;
     422
     423            if (Tcl_GetIntFromObj(interp, objv[i+1], &n) != TCL_OK) {
     424                return TCL_ERROR;
     425            }
     426            if (n <= 0) {
    427427                Tcl_AppendResult(interp, "bad extents value: must be > 0",
    428428                                 (char *)NULL);
    429429                return TCL_ERROR;
    430430            }
    431             _nComponents = n;
     431            _nComponents = n;
    432432        } else if ((c == 'a') && (strcmp(string, "axisorder") == 0)) {
    433             Tcl_Obj **order;
    434             int n;
    435 
    436             if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &order)
    437                 != TCL_OK) {
    438                 return TCL_ERROR;
    439             }
    440             if (n != 2) {
    441                 Tcl_AppendResult(interp,
    442                         "wrong # of axes defined for ordering the data",
    443                         (char *)NULL);
    444                 return TCL_ERROR;
    445             }
    446             if ((GetAxisFromObj(interp, order[0], axis) != TCL_OK) ||
    447                 (GetAxisFromObj(interp, order[1], axis+1) != TCL_OK)) {
    448                 return TCL_ERROR;
    449             }
     433            Tcl_Obj **order;
     434            int n;
     435
     436            if (Tcl_ListObjGetElements(interp, objv[i+1], &n, &order)
     437                != TCL_OK) {
     438                return TCL_ERROR;
     439            }
     440            if (n != 2) {
     441                Tcl_AppendResult(interp,
     442                        "wrong # of axes defined for ordering the data",
     443                        (char *)NULL);
     444                return TCL_ERROR;
     445            }
     446            if ((GetAxisFromObj(interp, order[0], axis) != TCL_OK) ||
     447                (GetAxisFromObj(interp, order[1], axis+1) != TCL_OK)) {
     448                return TCL_ERROR;
     449            }
    450450        } else {
    451451            Tcl_AppendResult(interp, "unknown key \"", string,
     
    460460    if (_nValues != (_xNum * _yNum * _nComponents)) {
    461461        Tcl_AppendResult(interp,
    462                 "wrong number of values: must be xnum*ynum*components",
    463                         (char *)NULL);
     462                "wrong number of values: must be xnum*ynum*components",
     463                        (char *)NULL);
    464464        return TCL_ERROR;
    465465    }
    466466   
    467467    if ((axis[0] != 1) || (axis[1] != 0)) {
    468         TRACE("reordering data\n");
    469         /* Reorder the data into x, y where x varies fastest and so on. */
    470         size_t y;
    471         float *dp;
    472 
    473         dp = _values = (float *)realloc(_values, sizeof(float) * _nValues);
    474         for (y = 0; y < _yNum; y++) {
    475             size_t x;
    476 
    477             for (x = 0; x < _xNum; x++) {
    478                 size_t i, v;
    479                    
    480                 /* Compute the index from the data's described ordering. */
    481                 i = (y + (_yNum * x)) * _nComponents;
    482                 for(v = 0; v < _nComponents; v++) {
    483                     dp[v] = _values[i+v];
    484                 }
    485                 dp += _nComponents;
    486             }
    487         }
     468        TRACE("reordering data\n");
     469        /* Reorder the data into x, y where x varies fastest and so on. */
     470        size_t y;
     471        float *dp;
     472
     473        dp = _values = (float *)realloc(_values, sizeof(float) * _nValues);
     474        for (y = 0; y < _yNum; y++) {
     475            size_t x;
     476
     477            for (x = 0; x < _xNum; x++) {
     478                size_t i, v;
     479                   
     480                /* Compute the index from the data's described ordering. */
     481                i = (y + (_yNum * x)) * _nComponents;
     482                for(v = 0; v < _nComponents; v++) {
     483                    dp[v] = _values[i+v];
     484                }
     485                dp += _nComponents;
     486            }
     487        }
    488488    }
    489489    _initialized = true;
     
    494494bool
    495495Rappture::Unirect3d::ImportDx(Rappture::Outcome &result, size_t nComponents,
    496                               size_t length, char *string)
     496                              size_t length, char *string)
    497497{
    498498    int nx, ny, nz, npts;
     
    504504    nx = ny = nz = npts = 0;            /* Suppress compiler warning. */
    505505    for (p = string, pend = p + length; p < pend; /*empty*/) {
    506         char *line;
    507 
    508         line = getline(&p, pend);
     506        char *line;
     507
     508        line = getline(&p, pend);
    509509        if (line == pend) {
    510             break;                      /* EOF */
    511         }
     510            break;                        /* EOF */
     511        }
    512512        if ((line[0] == '#') || (line == '\0')) {
    513             continue;                   /* Skip blank or comment lines. */
    514         }
    515         if (sscanf(line, "object %*d class gridpositions counts %d %d %d",
    516                    &nx, &ny, &nz) == 3) {
    517             if ((nx < 0) || (ny < 0) || (nz < 0)) {
    518                 result.addError("invalid grid size: x=%d, y=%d, z=%d",
    519                         nx, ny, nz);
    520                 return false;
    521             }
    522         } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) {
    523             /* Found origin. */
    524         } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
    525             /* Found one of the delta lines. */
    526             if (ddx != 0.0) {
    527                 dx = ddx;
    528             } else if (ddy != 0.0) {
    529                 dy = ddy;
    530             } else if (ddz != 0.0) {
    531                 dz = ddz;
    532             }
    533         } else if (sscanf(line, "object %*d class array type %*s shape 3"
    534                 " rank 1 items %d data follows", &npts) == 1) {
    535             if (npts < 0) {
    536                 result.addError("bad # points %d", npts);
    537                 return false;
    538             }   
    539             printf("#points=%d\n", npts);
    540             if (npts != nx*ny*nz) {
    541                 result.addError("inconsistent data: expected %d points"
    542                                 " but found %d points", nx*ny*nz, npts);
    543                 return false;
    544             }
    545             break;
    546         } else if (sscanf(line, "object %*d class array type %*s rank 0"
    547                 " times %d data follows", &npts) == 1) {
    548             if (npts != nx*ny*nz) {
    549                 result.addError("inconsistent data: expected %d points"
    550                                 " but found %d points", nx*ny*nz, npts);
    551                 return false;
    552             }
    553             break;
    554         }
     513            continue;                        /* Skip blank or comment lines. */
     514        }
     515        if (sscanf(line, "object %*d class gridpositions counts %d %d %d",
     516                   &nx, &ny, &nz) == 3) {
     517            if ((nx < 0) || (ny < 0) || (nz < 0)) {
     518                result.addError("invalid grid size: x=%d, y=%d, z=%d",
     519                        nx, ny, nz);
     520                return false;
     521            }
     522        } else if (sscanf(line, "origin %lg %lg %lg", &x0, &y0, &z0) == 3) {
     523            /* Found origin. */
     524        } else if (sscanf(line, "delta %lg %lg %lg", &ddx, &ddy, &ddz) == 3) {
     525            /* Found one of the delta lines. */
     526            if (ddx != 0.0) {
     527                dx = ddx;
     528            } else if (ddy != 0.0) {
     529                dy = ddy;
     530            } else if (ddz != 0.0) {
     531                dz = ddz;
     532            }
     533        } else if (sscanf(line, "object %*d class array type %*s shape 3"
     534                " rank 1 items %d data follows", &npts) == 1) {
     535            if (npts < 0) {
     536                result.addError("bad # points %d", npts);
     537                return false;
     538            }
     539            TRACE("#points=%d\n", npts);
     540            if (npts != nx*ny*nz) {
     541                result.addError("inconsistent data: expected %d points"
     542                                " but found %d points", nx*ny*nz, npts);
     543                return false;
     544            }
     545            break;
     546        } else if (sscanf(line, "object %*d class array type %*s rank 0"
     547                " times %d data follows", &npts) == 1) {
     548            if (npts != nx*ny*nz) {
     549                result.addError("inconsistent data: expected %d points"
     550                                " but found %d points", nx*ny*nz, npts);
     551                return false;
     552            }
     553            break;
     554        }
    555555    }
    556556    if (npts != nx*ny*nz) {
    557         result.addError("inconsistent data: expected %d points"
    558                         " but found %d points", nx*ny*nz, npts);
    559         return false;
     557        result.addError("inconsistent data: expected %d points"
     558                        " but found %d points", nx*ny*nz, npts);
     559        return false;
    560560    }
    561561
     
    573573    _nValues = 0;
    574574    for (size_t ix = 0; ix < _xNum; ix++) {
    575         for (size_t iy = 0; iy < _yNum; iy++) {
    576             for (size_t iz = 0; iz < _zNum; iz++) {
    577                 char *line;
    578                 if ((p == pend) || (_nValues > (size_t)npts)) {
    579                     break;
    580                 }
    581                 line = getline(&p, pend);
    582                 if ((line[0] == '#') || (line[0] == '\0')) {
    583                     continue;           /* Skip blank or comment lines. */
    584                 }
    585                 double vx, vy, vz;
    586                 if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
    587                     int nindex = (iz*nx*ny + iy*nx + ix) * 3;
    588                     if (vx < _xValueMin) {
    589                         _xValueMin = vx;
    590                     } else if (vx > _xValueMax) {
    591                         _xValueMax = vx;
    592                     }
    593                     if (vy < _yValueMin) {
    594                         _yValueMin = vy;
    595                     } else if (vy > _yValueMax) {
    596                         _yValueMax = vy;
    597                     }
    598                     if (vz < _zValueMin) {
    599                         _zValueMin = vz;
    600                     } else if (vz > _zValueMax) {
    601                         _zValueMax = vz;
    602                     }
    603                     _values[nindex] = vx;
    604                     _values[nindex+1] = vy;
    605                     _values[nindex+2] = vz;
    606                     _nValues++;
    607                 }
    608             }
    609         }
     575        for (size_t iy = 0; iy < _yNum; iy++) {
     576            for (size_t iz = 0; iz < _zNum; iz++) {
     577                char *line;
     578                if ((p == pend) || (_nValues > (size_t)npts)) {
     579                    break;
     580                }
     581                line = getline(&p, pend);
     582                if ((line[0] == '#') || (line[0] == '\0')) {
     583                    continue;                /* Skip blank or comment lines. */
     584                }
     585                double vx, vy, vz;
     586                if (sscanf(line, "%lg %lg %lg", &vx, &vy, &vz) == 3) {
     587                    int nindex = (iz*nx*ny + iy*nx + ix) * 3;
     588                    if (vx < _xValueMin) {
     589                        _xValueMin = vx;
     590                    } else if (vx > _xValueMax) {
     591                        _xValueMax = vx;
     592                    }
     593                    if (vy < _yValueMin) {
     594                        _yValueMin = vy;
     595                    } else if (vy > _yValueMax) {
     596                        _yValueMax = vy;
     597                    }
     598                    if (vz < _zValueMin) {
     599                        _zValueMin = vz;
     600                    } else if (vz > _zValueMax) {
     601                        _zValueMax = vz;
     602                    }
     603                    _values[nindex] = vx;
     604                    _values[nindex+1] = vy;
     605                    _values[nindex+2] = vz;
     606                    _nValues++;
     607                }
     608            }
     609        }
    610610    }
    611611    /* Make sure that we read all of the expected points. */
    612612    if (_nValues != (size_t)npts) {
    613         result.addError("inconsistent data: expected %d points"
    614                         " but found %d points", npts, _nValues);
    615         free(_values);
    616         _values = NULL;
    617         return false;
     613        result.addError("inconsistent data: expected %d points"
     614                        " but found %d points", npts, _nValues);
     615        free(_values);
     616        _values = NULL;
     617        return false;
    618618    }
    619619    _nValues *= _nComponents;
     
    621621#ifdef notdef
    622622    {
    623         FILE *f;
    624         f = fopen("/tmp/dx.txt", "w");
    625         fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum);
    626         fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum);
    627         fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum);
    628         fprintf(f, "components %d values {\n",  _nComponents);
    629         for (size_t i = 0; i < _nValues; i+= 3) {
    630             fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]);
    631         }
    632         fprintf(f, "}\n");
    633         fclose(f);
     623        FILE *f;
     624        f = fopen("/tmp/dx.txt", "w");
     625        fprintf(f, "unirect3d xmin %g xmax %g xnum %d ", _xMin, _xMax, _xNum);
     626        fprintf(f, "ymin %g ymax %g ynum %d ", _yMin, _yMax, _yNum);
     627        fprintf(f, "zmin %g zmax %g znum %d ", _zMin, _zMax, _zNum);
     628        fprintf(f, "components %d values {\n",  _nComponents);
     629        for (size_t i = 0; i < _nValues; i+= 3) {
     630            fprintf(f, "%g %g %g\n", _values[i], _values[i+1], _values[i+2]);
     631        }
     632        fprintf(f, "}\n");
     633        fclose(f);
    634634    }
    635635#endif
     
    650650    size_t i, j;
    651651    for (i = 0, j = 0; i < _nValues; i += _nComponents, j++) {
    652         double vx, vy, vz;
    653 
    654         vx = _values[i];
    655         vy = _values[i+1];
    656         vz = _values[i+2];
    657        
    658         xfield.define(j, vx);
    659         yfield.define(j, vy);
    660         zfield.define(j, vz);
     652        double vx, vy, vz;
     653
     654        vx = _values[i];
     655        vy = _values[i+1];
     656        vz = _values[i+2];
     657       
     658        xfield.define(j, vx);
     659        yfield.define(j, vy);
     660        zfield.define(j, vz);
    661661    }
    662662    // Figure out a good mesh spacing
     
    690690    float *destPtr = _values;
    691691    for (size_t i = 0; i < _zNum; i++) {
    692         double z;
    693 
    694         z = _zMin + (i * dmin);
    695         for (size_t j = 0; j < _yNum; j++) {
    696             double y;
    697                
    698             y = _yMin + (j * dmin);
    699             for (size_t k = 0; k < _xNum; k++) {
    700                 double x;
    701 
    702                 x = _xMin + (k * dmin);
    703                 destPtr[0] = xfield.value(x, y, z);
    704                 destPtr[1] = yfield.value(x, y, z);
    705                 destPtr[2] = zfield.value(x, y, z);
    706             }
    707         }
     692        double z;
     693
     694        z = _zMin + (i * dmin);
     695        for (size_t j = 0; j < _yNum; j++) {
     696            double y;
     697               
     698            y = _yMin + (j * dmin);
     699            for (size_t k = 0; k < _xNum; k++) {
     700                double x;
     701
     702                x = _xMin + (k * dmin);
     703                destPtr[0] = xfield.value(x, y, z);
     704                destPtr[1] = yfield.value(x, y, z);
     705                destPtr[2] = zfield.value(x, y, z);
     706            }
     707        }
    708708    }
    709709    _nValues = _xNum * _yNum * _zNum * _nComponents;
     
    720720    size_t i;
    721721    for (i = 0; i < _nValues; i += _nComponents) {
    722         double vx, vy, vz, vm;
    723 
    724         vx = _values[i];
    725         vy = _values[i+1];
    726         vz = _values[i+2];
    727                    
    728         vm = sqrt(vx*vx + vy*vy + vz*vz);
    729         if (vm > _magMax) {
    730             _magMax = vm;
    731         }
    732         if (vm < _magMin) {
    733             _magMin = vm;
    734         }
     722        double vx, vy, vz, vm;
     723
     724        vx = _values[i];
     725        vy = _values[i+1];
     726        vz = _values[i+2];
     727                   
     728        vm = sqrt(vx*vx + vy*vy + vz*vz);
     729        if (vm > _magMax) {
     730            _magMax = vm;
     731        }
     732        if (vm < _magMin) {
     733            _magMin = vm;
     734        }
    735735    }
    736736}
     
    756756    case 1:
    757757    case 3:
    758         _values = (float *)realloc(_values, sizeof(float) * dataPtr->nValues());
    759         if (_values == NULL) {
    760             return false;
    761         }
    762         memcpy(_values, dataPtr->values(), dataPtr->nValues());
    763         _nValues = dataPtr->nValues();
    764         _nComponents = dataPtr->nComponents();
    765         break;
     758        _values = (float *)realloc(_values, sizeof(float) * dataPtr->nValues());
     759        if (_values == NULL) {
     760            return false;
     761        }
     762        memcpy(_values, dataPtr->values(), dataPtr->nValues());
     763        _nValues = dataPtr->nValues();
     764        _nComponents = dataPtr->nComponents();
     765        break;
    766766    case 2:
    767         float *values;
    768         _nValues = 3 * _xNum * _yNum * _zNum;
    769         _values = (float *)realloc(_values, sizeof(float) * _nValues);
    770         if (_values == NULL) {
    771             return false;
    772         }
    773         values = dataPtr->values();
    774         size_t i, j;
    775         for(j = i = 0; i < dataPtr->nValues(); i += 2, j+= 3) {
    776             _values[j] = values[i];
    777             _values[j+1] = values[i+1];
    778             _values[j+2] = 0.0f;
    779         }           
    780         _nComponents = 3;
    781         break;
     767        float *values;
     768        _nValues = 3 * _xNum * _yNum * _zNum;
     769        _values = (float *)realloc(_values, sizeof(float) * _nValues);
     770        if (_values == NULL) {
     771            return false;
     772        }
     773        values = dataPtr->values();
     774        size_t i, j;
     775        for (j = i = 0; i < dataPtr->nValues(); i += 2, j+= 3) {
     776            _values[j] = values[i];
     777            _values[j+1] = values[i+1];
     778            _values[j+2] = 0.0f;
     779        }
     780        _nComponents = 3;
     781        break;
    782782    }
    783783    return true;
Note: See TracChangeset for help on using the changeset viewer.