Ignore:
Timestamp:
Nov 15, 2013, 6:32:03 PM (6 years ago)
Author:
ldelgass
Message:

Remove some more Rappture deps from nanovis

File:
1 edited

Legend:

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

    r4056 r4063  
    1717#include <poll.h>
    1818
     19#include <sstream>
     20
    1921#include <tcl.h>
    2022
    21 #include <RpOutcome.h>
     23#include <RpBuffer.h>
    2224
    2325#include <vrmath/Vector3f.h>
     
    3234#ifdef USE_VTK
    3335#include "VtkDataSetReader.h"
     36#else
     37#include "VtkReader.h"
    3438#endif
    35 #include "VtkReader.h"
    3639#include "FlowCmd.h"
    3740#include "FlowTypes.h"
     
    135138};
    136139
    137 static int
    138 FlowDataFileOp(ClientData clientData, Tcl_Interp *interp, int objc,
    139                Tcl_Obj *const *objv)
    140 {
    141     Rappture::Outcome result;
    142 
    143     const char *fileName;
    144     fileName = Tcl_GetString(objv[3]);
    145     TRACE("File: %s", fileName);
    146 
    147     int nComponents;
    148     if (Tcl_GetIntFromObj(interp, objv[4], &nComponents) != TCL_OK) {
    149         return TCL_ERROR;
    150     }
    151     if ((nComponents < 1) || (nComponents > 4)) {
    152         Tcl_AppendResult(interp, "bad # of components \"",
    153                          Tcl_GetString(objv[4]), "\"", (char *)NULL);
    154         return TCL_ERROR;
    155     }
    156     Rappture::Buffer buf;
    157     if (!buf.load(result, fileName)) {
    158         Tcl_AppendResult(interp, "can't load data from \"", fileName, "\": ",
    159                          result.remark(), (char *)NULL);
    160         return TCL_ERROR;
    161     }
    162 
    163     Unirect3d *dataPtr;
    164     dataPtr = new Unirect3d(nComponents);
    165     Flow *flow = (Flow *)clientData;
    166     size_t length = buf.size();
    167     char *bytes = (char *)buf.bytes();
    168     if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) {
    169         if (!dataPtr->importDx(result, nComponents, length-4, bytes+4)) {
    170             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    171             delete dataPtr;
    172             return TCL_ERROR;
    173         }
    174     } else if ((length > 10) && (strncmp(bytes, "unirect3d ", 10) == 0)) {
    175         if (dataPtr->parseBuffer(interp, buf) != TCL_OK) {
    176             delete dataPtr;
    177             return TCL_ERROR;
    178         }
    179     } else if ((length > 10) && (strncmp(bytes, "unirect2d ", 10) == 0)) {
    180         Unirect2d *u2dPtr;
    181         u2dPtr = new Unirect2d(nComponents);
    182         if (u2dPtr->parseBuffer(interp, buf) != TCL_OK) {
    183             delete u2dPtr;
    184             return TCL_ERROR;
    185         }
    186         dataPtr->convert(u2dPtr);
    187         delete u2dPtr;
    188     } else {
    189         TRACE("header is %.14s", buf.bytes());
    190         if (!dataPtr->importDx(result, nComponents, length, bytes)) {
    191             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
    192             delete dataPtr;
    193             return TCL_ERROR;
    194         }
    195     }
    196     if (dataPtr->nValues() == 0) {
    197         delete dataPtr;
    198         Tcl_AppendResult(interp, "no data found in \"", fileName, "\"",
    199                          (char *)NULL);
    200         return TCL_ERROR;
    201     }
    202     flow->data(dataPtr);
    203     Flow::updatePending = true;
    204     NanoVis::eventuallyRedraw();
    205     return TCL_OK;
    206 }
    207 
    208140/**
    209141 * $flow data follows nbytes nComponents
     
    213145                  Tcl_Obj *const *objv)
    214146{
    215     Rappture::Outcome result;
    216 
    217147    TRACE("Enter");
    218148
     
    253183    if ((length > 4) && (strncmp(bytes, "<DX>", 4) == 0)) {
    254184        unirect = new Unirect3d(nComponents);
    255         if (!unirect->importDx(result, nComponents, length - 4, bytes + 4)) {
    256             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
     185        if (!unirect->importDx(nComponents, length - 4, bytes + 4)) {
     186            Tcl_AppendResult(interp, "Failed to load DX file", (char *)NULL);
    257187            delete unirect;
    258188            return TCL_ERROR;
     
    260190    } else if ((length > 10) && (strncmp(bytes, "unirect3d ", 10) == 0)) {
    261191        unirect = new Unirect3d(nComponents);
    262         if (unirect->parseBuffer(interp, buf) != TCL_OK) {
     192        if (unirect->parseBuffer(interp, bytes, length) != TCL_OK) {
    263193            delete unirect;
    264194            return TCL_ERROR;
     
    268198        Unirect2d *u2dPtr;
    269199        u2dPtr = new Unirect2d(nComponents);
    270         if (u2dPtr->parseBuffer(interp, buf) != TCL_OK) {
     200        if (u2dPtr->parseBuffer(interp, bytes, length) != TCL_OK) {
    271201            delete unirect;
    272202            delete u2dPtr;
     
    277207    } else if ((length > 14) && (strncmp(bytes, "# vtk DataFile", 14) == 0)) {
    278208        TRACE("VTK loading...");
    279         std::stringstream fdata;
    280         fdata.write(bytes, length);
    281209        if (length <= 0) {
    282210            ERROR("data buffer is empty");
    283211            abort();
    284212        }
    285         Rappture::Outcome context;
    286213#ifdef USE_VTK
    287         volume = load_vtk_volume_stream(context, flow->name(), bytes, length);
     214        volume = load_vtk_volume_stream(flow->name(), bytes, length);
    288215#else
    289216        std::stringstream fdata;
    290         fdata.write(bytes, nBytes);
    291         volume = load_vtk_volume_stream(context, flow->name(), fdata);
     217        fdata.write(bytes, length);
     218        volume = load_vtk_volume_stream(flow->name(), fdata);
    292219#endif
    293220        if (volume == NULL) {
    294             Tcl_AppendResult(interp, context.remark(), (char*)NULL);
     221            Tcl_AppendResult(interp, "Failed to load VTK file", (char*)NULL);
    295222            return TCL_ERROR;
    296223        }
     
    298225        TRACE("header is %.14s", buf.bytes());
    299226        unirect = new Unirect3d(nComponents);
    300         if (!unirect->importDx(result, nComponents, length, bytes)) {
    301             Tcl_AppendResult(interp, result.remark(), (char *)NULL);
     227        if (!unirect->importDx(nComponents, length, bytes)) {
     228            Tcl_AppendResult(interp, "Failed to load DX file", (char *)NULL);
    302229            delete unirect;
    303230            return TCL_ERROR;
     
    350277
    351278static CmdSpec flowDataOps[] = {
    352     {"file",    2, FlowDataFileOp,    5, 5, "fileName nComponents",},
    353279    {"follows", 2, FlowDataFollowsOp, 5, 5, "size nComponents",},
    354280};
     
    11961122        return TCL_ERROR;
    11971123    }
    1198     Rappture::Buffer data;
     1124    char *data = NULL;
    11991125    size_t total = 0;
    12001126    for (;;) {
     
    12021128        char buffer[BUFSIZ];
    12031129       
    1204         numRead = fread(buffer, sizeof(unsigned char), BUFSIZ, f);
     1130        numRead = fread(buffer, sizeof(char), BUFSIZ, f);
    12051131        total += numRead;
    12061132        if (numRead == 0) {             // EOF
     
    12141140            return TCL_ERROR;
    12151141        }
    1216         if (!data.append(buffer, numRead)) {
     1142        data = (char *)realloc(data, total);
     1143        if (data == NULL) {
    12171144            ERROR("Can't append movie data to buffer %d bytes",
    12181145                  numRead);
     
    12211148            return TCL_ERROR;
    12221149        }
    1223     }
    1224     if (data.size() == 0) {
     1150        memcpy(data + (total - numRead), buffer, numRead);
     1151    }
     1152    if (total == 0) {
    12251153        ERROR("ffmpeg returned 0 bytes");
    12261154    }
    12271155    // Send zero length to client so it can deal with error
    12281156    sprintf(cmd,"nv>image -type movie -token \"%s\" -bytes %lu\n",
    1229             token, (unsigned long)data.size());
    1230     nv::sendDataToClient(cmd, data.bytes(), data.size());
     1157            token, total);
     1158    // Memory is freed by this call
     1159    nv::sendDataToClient(cmd, data, total);
    12311160    return TCL_OK;
    12321161}
Note: See TracChangeset for help on using the changeset viewer.