Changeset 1515 for trunk/packages


Ignore:
Timestamp:
Jun 13, 2009, 1:02:51 PM (15 years ago)
Author:
gah
Message:
 
Location:
trunk/packages/vizservers/nanovis
Files:
10 edited

Legend:

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

    r1510 r1515  
    44#include <stddef.h>
    55#include <limits.h>
     6#include <poll.h>
    67#include <tcl.h>
    78#include "Switch.h"
     
    13511352}
    13521353
     1354/*
     1355 *---------------------------------------------------------------------------
     1356 *
     1357 * VideoFormatSwitchProc --
     1358 *
     1359 *      Convert a Tcl_Obj representing the video format into its
     1360 *      integer id.
     1361 *
     1362 * Results:
     1363 *      The return value is a standard Tcl result.
     1364 *
     1365 *---------------------------------------------------------------------------
     1366 */
     1367/*ARGSUSED*/
     1368static int
     1369VideoFormatSwitchProc(
     1370    ClientData clientData,      /* Not used. */
     1371    Tcl_Interp *interp,         /* Interpreter to send results back to */
     1372    const char *switchName,     /* Not used. */
     1373    Tcl_Obj *objPtr,            /* String representation */
     1374    char *record,               /* Structure record */
     1375    int offset,                 /* Not used. */
     1376    int flags)                  /* Not used. */
     1377{
     1378    Rappture::AVTranslate::VideoFormats *formatPtr =
     1379        (Rappture::AVTranslate::VideoFormats *)(record + offset);
     1380    const char *string;
     1381    char c;
     1382
     1383    string = Tcl_GetString(objPtr);
     1384    c = string[0];
     1385    if ((c == 'm') && (strcmp(string, "mpeg") == 0)) {
     1386        *formatPtr =  Rappture::AVTranslate::MPEG1;
     1387    } else if ((c == 't') && (strcmp(string, "theora") == 0)) {
     1388        *formatPtr = Rappture::AVTranslate::THEORA;
     1389    } else if ((c == 'm') && (strcmp(string, "mov") == 0)) {
     1390        *formatPtr = Rappture::AVTranslate::QUICKTIME;
     1391    } else {
     1392        Tcl_AppendResult(interp, "bad video format \"", string,
     1393                     "\": should be mpeg, theora, or mov", (char*)NULL);
     1394    }
     1395    return TCL_ERROR;
     1396}
     1397
    13531398static int
    13541399FlowConfigureOp(ClientData clientData, Tcl_Interp *interp, int objc,
     
    18741919}
    18751920
     1921struct FlowVideoValues {
     1922    float frameRate;                    /* Frame rate */
     1923    int bitRate;                        /* Video bitrate */
     1924    int width, height;                  /* Dimensions of video frame. */
     1925    int nFrames;
     1926    Rappture::AVTranslate::VideoFormats format;
     1927};
     1928
     1929static Rappture::SwitchParseProc VideoFormatSwitchProc;
     1930static Rappture::SwitchCustom videoFormatSwitch = {
     1931    VideoFormatSwitchProc, NULL, 0,
     1932};
     1933
     1934Rappture::SwitchSpec FlowCmd::videoSwitches[] = {
     1935    {Rappture::SWITCH_FLOAT, "-bitrate", "value",
     1936        offsetof(FlowVideoValues, bitRate), 0},
     1937    {Rappture::SWITCH_CUSTOM, "-format", "string",
     1938        offsetof(FlowVideoValues, format), 0, 0, &videoFormatSwitch},
     1939    {Rappture::SWITCH_FLOAT, "-framerate", "value",
     1940        offsetof(FlowVideoValues, frameRate), 0},
     1941    {Rappture::SWITCH_INT, "-height", "integer",
     1942        offsetof(FlowVideoValues, height), 0},
     1943    {Rappture::SWITCH_INT, "-numframes", "count",
     1944        offsetof(FlowVideoValues, nFrames), 0},
     1945    {Rappture::SWITCH_INT, "-width", "integer",
     1946        offsetof(FlowVideoValues, width), 0},
     1947    {Rappture::SWITCH_END}
     1948};
     1949
    18761950static int
    18771951FlowVideoOp(ClientData clientData, Tcl_Interp *interp, int objc,
    18781952            Tcl_Obj *const *objv)
    18791953{
    1880     int width, height;          // Resolution of video.
    1881     int numFrames;              // Total number of frames.
    1882     float frameRate;            // Frame rate of the video.
    1883     float bitRate;              // Bit rate of the vide.
    1884 
    1885     if ((Tcl_GetIntFromObj(interp, objv[2], &width) != TCL_OK) ||
    1886         (Tcl_GetIntFromObj(interp, objv[3], &height) != TCL_OK) ||
    1887         (Tcl_GetIntFromObj(interp, objv[4], &numFrames) != TCL_OK) ||
    1888         (GetFloatFromObj(interp, objv[5], &frameRate) != TCL_OK) ||
    1889         (GetFloatFromObj(interp, objv[6], &bitRate) != TCL_OK)) {
    1890         return TCL_ERROR;
    1891     }
    1892     if ((width<0) || (width>SHRT_MAX) || (height<0) || (height>SHRT_MAX)) {
     1954    struct pollfd pollResults;
     1955    int timeout;
     1956
     1957    pollResults.fd = fileno(NanoVis::stdin);
     1958    pollResults.events = POLLIN;
     1959
     1960#define PENDING_TIMEOUT         10  /* milliseconds. */
     1961    timeout = PENDING_TIMEOUT;
     1962
     1963    FlowVideoValues values;
     1964    const char *token;
     1965
     1966    token = Tcl_GetString(objv[2]);
     1967    values.frameRate = 25.0f;           // Default frame rate 25 fps
     1968    values.bitRate = 6.0e+6f;           // Default video bit rate.
     1969    values.width = NanoVis::win_width;
     1970    values.height = NanoVis::win_height;
     1971    values.nFrames = 100;
     1972    values.format = Rappture::AVTranslate::MPEG1;
     1973    if (Rappture::ParseSwitches(interp, FlowCmd::videoSwitches,
     1974        objc - 2, objv + 2, &values, SWITCH_DEFAULTS) < 0) {
     1975        return TCL_ERROR;
     1976    }
     1977    if ((values.width < 0) || (values.width > SHRT_MAX) ||
     1978        (values.height < 0) || (values.height > SHRT_MAX)) {
    18931979        Tcl_AppendResult(interp, "bad dimensions for video", (char *)NULL);
    18941980        return TCL_ERROR;
    18951981    }
    1896     if ((frameRate < 0.0f) || (frameRate > 30.0f)) {
    1897         Tcl_AppendResult(interp, "bad frame rate \"", Tcl_GetString(objv[5]),
    1898                          "\"", (char *)NULL);
    1899         return TCL_ERROR;
    1900     }
    1901     if ((bitRate < 0.0f) || (frameRate > 30.0f)) {
    1902         Tcl_AppendResult(interp, "bad bit rate \"", Tcl_GetString(objv[6]),
    1903                          "\"", (char *)NULL);
     1982    if ((values.frameRate < 0.0f) || (values.frameRate > 30.0f)) {
     1983        Tcl_AppendResult(interp, "bad frame rate.", (char *)NULL);
     1984        return TCL_ERROR;
     1985    }
     1986    if (values.bitRate < 0.0f) {
     1987        Tcl_AppendResult(interp, "bad bit rate.", (char *)NULL);
    19041988        return TCL_ERROR;
    19051989    }
    19061990    if (NanoVis::licRenderer == NULL) {
    19071991        Tcl_AppendResult(interp, "no lic renderer.", (char *)NULL);
    1908         return TCL_ERROR;
    1909     }
    1910     if (NanoVis::flowVisRenderer == NULL) {
    1911         Tcl_AppendResult(interp, "no flow renderer.", (char *)NULL);
    19121992        return TCL_ERROR;
    19131993    }
     
    19171997    oldHeight = NanoVis::win_height;
    19181998
    1919     char fileName[200];
    1920     sprintf(fileName,"/tmp/flow%d.mpeg", getpid());
    1921 
    19221999    Trace("FLOW started\n");
    19232000
    19242001    Rappture::Outcome context;
    19252002
    1926     Rappture::AVTranslate movie(width, height, bitRate, frameRate);
    1927     if (!movie.init(context, fileName)) {
    1928         Tcl_AppendResult(interp, "can't initialized movie \"", fileName,
    1929                          "\": ", context.remark(), (char *)NULL);
    1930         return TCL_ERROR;
    1931     }
    1932     if ((width != oldWidth) || (height != oldHeight)) {
     2003    Rappture::AVTranslate movie(values.width, values.height, values.bitRate,
     2004        values.frameRate);
     2005    char tmpFileName[200];
     2006    sprintf(tmpFileName,"/tmp/flow%d.mpeg", getpid());
     2007    if (!movie.init(context, tmpFileName)) {
     2008        Tcl_AppendResult(interp, "can't initialized movie \"", tmpFileName,
     2009                "\": ", context.remark(), (char *)NULL);
     2010        return TCL_ERROR;
     2011    }
     2012    if ((values.width != oldWidth) || (values.height != oldHeight)) {
    19332013        // Resize to the requested size.
    1934         NanoVis::resize_offscreen_buffer(width, height);
     2014        NanoVis::resize_offscreen_buffer(values.width, values.height);
    19352015    }
    19362016    // Now compute the line padding for the offscreen buffer.
    19372017    int pad = 0;
    1938     if ((3*NanoVis::win_width) % 4 > 0) {
    1939         pad = 4 - ((3*NanoVis::win_width) % 4);
     2018    if (( 3 * values.width) % 4 > 0) {
     2019        pad = 4 - ((3* values.width) % 4);
    19402020    }
    19412021    NanoVis::ResetFlows();
    1942     for (int i = 0; i < numFrames; i++) {
    1943         // Generate the latest frame and send it back to the client
     2022    bool canceled = false;
     2023    for (int i = 0; i < values.nFrames; i++) {
     2024        if (poll(&pollResults, 1, 0 /* No Timeout */) > 0) {
     2025            /* If there's another command on stdin, that means the client is
     2026             * trying to cancel this operation. */
     2027            canceled = true;
     2028            break;
     2029        }
    19442030        NanoVis::licRenderer->convolve();
    19452031        NanoVis::AdvectFlows();
     
    19472033        NanoVis::offscreen_buffer_capture();  //enable offscreen render
    19482034        NanoVis::display();
    1949 
    19502035        NanoVis::read_screen();
    19512036        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    1952 
    1953         // This is done before bmp_write_to_file because bmp_write_to_file
    1954         // turns rgb data to bgr
    19552037        movie.append(context, NanoVis::screen_buffer, pad);
    1956         // NanoVis::bmp_write_to_file(frame_count, fileName);
    1957     }
    1958 
     2038    }
    19592039    movie.done(context);
    19602040    Trace("FLOW end\n");
    1961 
    1962     // FIXME: find a way to get the data from the movie object as a void*
    1963     Rappture::Buffer data;
    1964     if (!data.load(context, fileName)) {
    1965         Tcl_AppendResult(interp, "can't load data from temporary movie file \"",
    1966                 fileName, "\": ", context.remark(), (char *)NULL);
    1967         return TCL_ERROR;
    1968     }
    1969 
    1970     // Build the command string for the client.
    1971     char command[200];
    1972     sprintf(command,"nv>image -bytes %lu -type movie -token \"%s\"\n",
    1973             (unsigned long)data.size(), Tcl_GetString(objv[7]));
    1974     NanoVis::sendDataToClient(command, data.bytes(), data.size());
    1975 
    1976     if ((width != oldWidth) || (height != oldHeight)) {
     2041    if (!canceled) {
     2042        Rappture::Buffer data;
     2043        // FIXME: find a way to get the data from the movie object as a void*
     2044        if (!data.load(context, tmpFileName)) {
     2045            Tcl_AppendResult(interp, "can't load data from temporary file \"",
     2046                tmpFileName, "\": ", context.remark(), (char *)NULL);
     2047            return TCL_ERROR;
     2048        }
     2049
     2050        // Build the command string for the client.
     2051        char command[200];
     2052        sprintf(command,"nv>image -bytes %lu -type movie -token \"%s\"\n",
     2053                (unsigned long)data.size(), Tcl_GetString(objv[7]));
     2054        NanoVis::sendDataToClient(command, data.bytes(), data.size());
     2055    }
     2056    if ((values.width != oldWidth) || (values.height != oldHeight)) {
    19772057        // Restore to the old size.
    19782058        NanoVis::resize_offscreen_buffer(oldWidth, oldHeight);
     
    19802060    NanoVis::ResetFlows();
    19812061    NanoVis::licRenderer->make_patterns();
    1982     if (unlink(fileName) != 0) {
     2062    if (unlink(tmpFileName) != 0) {
    19832063        Tcl_AppendResult(interp, "can't unlink temporary movie file \"",
    1984                 fileName, "\": ", Tcl_PosixError(interp), (char *)NULL);
     2064                tmpFileName, "\": ", Tcl_PosixError(interp), (char *)NULL);
    19852065        return TCL_ERROR;
    19862066    }
  • trunk/packages/vizservers/nanovis/FlowCmd.h

    r1510 r1515  
    187187    void RenderBoxes(void);
    188188public:
     189    static Rappture::SwitchSpec videoSwitches[];
    189190    enum SliceAxis { AXIS_X, AXIS_Y, AXIS_Z };
    190191    FlowCmd(Tcl_Interp *interp, const char *name, Tcl_HashEntry *hPtr);
  • trunk/packages/vizservers/nanovis/Lic.cpp

    r1510 r1515  
    2323
    2424Lic::Lic(int _size, int _width, int _height, float _offset,
    25                 CGcontext _context, GLuint _vector_field,
     25                CGcontext _context, GLuint _vectorField,
    2626                float scalex, float scaley, float scalez):
    2727        Renderable(Vector3(0.,0.,0.)),
     
    9696  m_plane_normal_param_render_vel = cgGetNamedParameter(m_render_vel_fprog,
    9797        "plane_normal");
    98   cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vector_field);
     98  cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vectorField);
    9999
    100100  get_slice();
  • trunk/packages/vizservers/nanovis/Lic.h

    r1510 r1515  
    6161  GLuint fbo, vel_fbo, slice_vector_tex;  //for projecting 3d vector to 2d vector on a plane
    6262
    63   Volume* vector_field;
     63  Volume* _vectorField;
    6464
    6565public:
     
    6767                  //the inherited Vector3 location is its center
    6868  Lic(int _size, int _width, int _height, float _offset,
    69           CGcontext _context, GLuint _vector_field,
     69          CGcontext _context, GLuint _vectorField,
    7070          float scalex, float scaley, float scalez);
    7171  ~Lic();
  • trunk/packages/vizservers/nanovis/NvLIC.cpp

    r1510 r1515  
    4141    max(1.0f),
    4242    m_g_context(_context),
    43     vectorFieldID(0),
     43    _vectorFieldId(0),
    4444    _activate(false)
    4545{
     
    248248
    249249    glEnable(GL_TEXTURE_3D);
    250     glBindTexture(GL_TEXTURE_3D, vectorFieldID);
     250    glBindTexture(GL_TEXTURE_3D, _vectorFieldId);
    251251    cgGLBindProgram(m_render_vel_fprog);
    252252
    253     cgGLSetTextureParameter(m_vel_tex_param_render_vel, vectorFieldID);
     253    cgGLSetTextureParameter(m_vel_tex_param_render_vel, _vectorFieldId);
    254254    cgGLEnableTextureParameter(m_vel_tex_param_render_vel);
    255255    cgGLSetParameter4f(m_plane_normal_param_render_vel, 1., 1., 0., 0);
     
    310310NvLIC::convolve()
    311311{
    312     if (vectorFieldID == 0) {
     312    if (_vectorFieldId == 0) {
    313313        return;
    314314    }
     
    419419NvLIC::display()
    420420{
    421     if (vectorFieldID == 0) {
     421    if (_vectorFieldId == 0) {
    422422        return;
    423423    }
     
    506506{
    507507    Trace("NvLIC: vector field is assigned [%d]\n", texID);
    508     vectorFieldID = texID;
     508    _vectorFieldId = texID;
    509509    origin = ori;
    510510    scale = Vector3(scaleX, scaleY, scaleZ);
  • trunk/packages/vizservers/nanovis/NvLIC.h

    r1510 r1515  
    3838
    3939private:
    40     unsigned int disListID;
     40    GLuint disListID;
    4141
    4242    int width, height;
     
    7171    GLuint fbo, vel_fbo, slice_vector_tex;  // For projecting 3d vector to 2d
    7272                                            // vector on a plane.
    73     GLuint vectorFieldID;
     73    GLuint _vectorFieldId;
    7474
    75     Volume* vector_field;
     75    Volume* _vectorField;
    7676    /**
    7777     * flag for rendering
     
    8282    Vector3 normal; //the normal vector of the NvLIC plane,
    8383    //the inherited Vector3 location is its center
    84     NvLIC(int _size, int _width, int _height, int axis, const Vector3& _offset, CGcontext _context);
     84    NvLIC(int _size, int _width, int _height, int axis,
     85          const Vector3& _offset, CGcontext _context);
    8586    ~NvLIC();
    8687
  • trunk/packages/vizservers/nanovis/NvVectorField.cpp

    r1431 r1515  
    44
    55NvVectorField::NvVectorField() :
    6     _vectorFieldID(0),
     6    _vectorFieldId(0),
    77    _activated(true),
    88    _scaleX(1),
     
    3636    _scaleZ = scaleZ;
    3737    _max = max;
    38     _vectorFieldID = volPtr->id;
     38    _vectorFieldId = volPtr->id;
    3939    _physicalMin = volPtr->getPhysicalBBoxMin();
    4040    printf("_pysicalMin %f %f %f\n", _physicalMin.x, _physicalMin.y, _physicalMin.z);
     
    107107    }
    108108       
    109     renderer->setVectorField(_vectorFieldID, _origin, _scaleX, _scaleY, _scaleZ, _max);
     109    renderer->setVectorField(_vectorFieldId, _origin, _scaleX, _scaleY, _scaleZ, _max);
    110110    if (renderer) {
    111111        renderer->initialize();
  • trunk/packages/vizservers/nanovis/NvVectorField.h

    r1431 r1515  
    2222
    2323class NvVectorField {
    24     unsigned int _vectorFieldID;
     24    GLuint _vectorFieldId;
    2525    Volume* _volPtr;
    2626    std::map<std::string, NvParticleRenderer*> _particleRendererMap;
  • trunk/packages/vizservers/nanovis/RpAVTranslate.h

    r1351 r1515  
    3333class AVTranslate {
    3434public:
     35    enum VideoFormats { MPEG1, MPEG4, THEORA, QUICKTIME };
    3536    AVTranslate(size_t width, size_t height);
    3637
  • trunk/packages/vizservers/nanovis/nanovis.h

    r1510 r1515  
     1
    12/*
    23 * ----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.