Changeset 2550 for branches/blt4


Ignore:
Timestamp:
Sep 21, 2011, 2:33:59 PM (13 years ago)
Author:
gah
Message:

updates from trunk

Location:
branches/blt4/packages/vizservers/vtkvis
Files:
2 added
26 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/packages/vizservers/vtkvis/CmdProc.cpp

    r2542 r2550  
    1010
    1111#include "CmdProc.h"
    12 
    13 using namespace Rappture;
    1412
    1513/**
     
    2422 */
    2523static int
    26 BinaryOpSearch(CmdSpec *specs,
     24BinaryOpSearch(Rappture::CmdSpec *specs,
    2725               int nSpecs,
    2826               char *string)       /* Name of minor operation to search for */
     
    3735    length = strlen(string);
    3836    while (low <= high) {
    39         CmdSpec *specPtr;
     37        Rappture::CmdSpec *specPtr;
    4038        int compare;
    4139        int median;
     
    7876 */
    7977static int
    80 LinearOpSearch(CmdSpec *specs,
     78LinearOpSearch(Rappture::CmdSpec *specs,
    8179               int nSpecs,
    8280               char *string)       /* Name of minor operation to search for */
    8381{
    84     CmdSpec *specPtr;
     82    Rappture::CmdSpec *specPtr;
    8583    char c;
    8684    size_t length;
     
    122120 */
    123121Tcl_ObjCmdProc *
    124 Rappture::GetOpFromObj(Tcl_Interp *interp,      /* Interpreter to report errors to */
    125                        int nSpecs,              /* Number of specifications in array */
    126                        CmdSpec *specs,          /* Op specification array */
    127                        int operPos,             /* Position of operation in argument
    128                                                  * list. */
    129                        int objc,                /* Number of arguments in the argument
    130                                                  * vector.  This includes any prefixed
    131                                                  * arguments */
    132                        Tcl_Obj *const *objv,    /* Argument vector */
     122Rappture::GetOpFromObj(Tcl_Interp *interp,              /* Interpreter to report errors to */
     123                       int nSpecs,                      /* Number of specifications in array */
     124                       Rappture::CmdSpec *specs,        /* Op specification array */
     125                       int operPos,                     /* Position of operation in argument
     126                                                         * list. */
     127                       int objc,                        /* Number of arguments in the argument
     128                                                         * vector.  This includes any prefixed
     129                                                         * arguments */
     130                       Tcl_Obj *const *objv,            /* Argument vector */
    133131                       int flags)
    134132{
  • branches/blt4/packages/vizservers/vtkvis/CmdProc.h

    r2542 r2550  
    1919 * for a function pointer associated with the operation name.
    2020 */
    21 struct CmdSpec {
     21typedef struct {
    2222    const char *name;           /**< Name of operation */
    2323    int minChars;               /**< Minimum # characters to disambiguate */
     
    2626    int maxArgs;                /**< Maximum # args required */
    2727    const char *usage;          /**< Usage message */
    28 };
     28} CmdSpec;
    2929
    30 enum CmdSpecIndex {
     30typedef enum {
    3131    CMDSPEC_ARG0,               /**< Op is the first argument. */
    3232    CMDSPEC_ARG1,               /**< Op is the second argument. */
     
    3434    CMDSPEC_ARG3,               /**< Op is the fourth argument. */
    3535    CMDSPEC_ARG4                /**< Op is the fifth argument. */
    36 };
     36} CmdSpecIndex;
    3737
    3838#define CMDSPEC_LINEAR_SEARCH   1
  • branches/blt4/packages/vizservers/vtkvis/Makefile.in

    r2542 r2550  
    4747DEBUG                   = #yes
    4848TRACE                   = #yes
    49 USE_CUSTOM_AXES         = yes
    50 USE_GPU_RAYCASTING      = yes
    51 USE_OFFSCREEN_RENDERING = yes
    52 USE_THREADS             = yes
     49USE_CUSTOM_AXES         = yes
     50USE_GPU_RAYCASTING      = yes
     51USE_OFFSCREEN_RENDERING = yes
    5352
    5453#vtk uses deprecated strstream header (instead of sstream)
     
    7170DEFINES         += -DUSE_GPU_RAYCAST_MAPPER
    7271endif
    73 ifdef USE_THREADS
    74 DEFINES         += -DUSE_THREADS
    75 endif
    7672CXX_SWITCHES    = $(CXXFLAGS) $(EXTRA_CFLAGS) $(DEFINES) $(INCLUDES)
    7773
     
    8278                RpContour2D.cpp \
    8379                RpContour3D.cpp \
     80                RpCutplane.cpp \
    8481                RpGlyphs.cpp \
    8582                RpHeightMap.cpp \
     
    9996ifdef USE_CUSTOM_AXES
    10097SERVER_SRCS+=vtkRpCubeAxesActor2D.cpp
    101 endif
    102 ifdef USE_THREADS
    103 SERVER_SRCS+=ResponseQueue.cpp
    10498endif
    10599
     
    136130CmdProc.o: CmdProc.h
    137131ColorMap.o: ColorMap.h RpMolecule.h Trace.h
    138 PPMWriter.o: PPMWriter.h ResponseQueue.h Trace.h
    139 ResponseQueue.o: ResponseQueue.h Trace.h
     132PPMWriter.o: PPMWriter.h Trace.h
    140133RpContour2D.o: RpContour2D.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    141134RpContour3D.o: RpContour3D.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
     135RpCutplane.o: RpCutplane.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    142136RpGlyphs.o: RpGlyphs.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    143137RpHeightMap.o: RpHeightMap.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
     
    149143RpVolume.o: RpVolume.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
    150144RpVtkDataSet.o: RpVtkDataSet.h Trace.h
    151 RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h
    152 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h ResponseQueue.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h
    153 RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h ResponseQueue.h Trace.h PPMWriter.h TGAWriter.h
     145RpVtkRenderer.o: RpVtkRenderer.h vtkRpCubeAxesActor2D.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h
     146RpVtkRendererCmd.o: RpVtkRenderer.h vtkRpCubeAxesActor2D.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h
     147RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h vtkRpCubeAxesActor2D.h Trace.h PPMWriter.h TGAWriter.h
    154148Trace.o: Trace.h
    155 TGAWriter.o: TGAWriter.h ResponseQueue.h Trace.h
     149TGAWriter.o: TGAWriter.h Trace.h
    156150vtkRpCubeAxesActor2D.o: vtkRpCubeAxesActor2D.h
  • branches/blt4/packages/vizservers/vtkvis/PPMWriter.cpp

    r2542 r2550  
    1212#include <sys/uio.h>
    1313
     14#include "PPMWriter.h"
    1415#include "Trace.h"
    15 #include "PPMWriter.h"
    16 #ifdef USE_THREADS
    17 #include "ResponseQueue.h"
    18 #endif
    1916
    2017using namespace Rappture::VtkVis;
    21 
    22 #ifdef USE_THREADS
    23 
    24 /**
    25  * \brief Writes image data as PPM binary data to the client.
    26  *
    27  * The PPM binary format is very simple.
    28  *
    29  *     P6 w h 255\n
    30  *     3-byte RGB pixel data.
    31  *
    32  * The client (using the TkImg library) will do less work to unpack this
    33  * format, as opposed to BMP or PNG.
    34  *
    35  * Note that currently the image data has bottom to top scanlines.  This
    36  * routine could be made even simpler (faster) if the image data had top
    37  * to bottom scanlines.
    38  *
    39  * \param[in] queue Pointer to ResponseQueue to write to
    40  * \param[in] cmdName Command name to send (byte length will be appended)
    41  * \param[in] data Image data
    42  * \param[in] width Width of image in pixels
    43  * \param[in] height Height of image in pixels
    44  */
    45 void
    46 Rappture::VtkVis::queuePPM(ResponseQueue *queue, const char *cmdName,
    47                            const unsigned char *data, int width, int height)
    48 {
    49 #define PPM_MAXVAL 255
    50     char header[200];
    51 
    52     TRACE("Entering (%dx%d)\n", width, height);
    53     // Generate the PPM binary file header
    54     snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height,
    55              PPM_MAXVAL);
    56 
    57     size_t headerLength = strlen(header);
    58     size_t dataLength = width * height * 3;
    59 
    60     char command[200];
    61     snprintf(command, sizeof(command), "%s %lu\n", cmdName,
    62              (unsigned long)headerLength + dataLength);
    63 
    64     size_t cmdLength;
    65     cmdLength = strlen(command);
    66 
    67     size_t length;
    68     unsigned char *mesg;
    69 
    70     length = headerLength + dataLength + cmdLength;
    71     mesg = (unsigned char *)malloc(length);
    72     if (mesg == NULL) {
    73         ERROR("can't allocate %ld bytes for the image message", length);
    74         return;
    75     }
    76     memcpy(mesg, command, cmdLength);
    77     memcpy(mesg + cmdLength, header, headerLength);
    78 
    79     size_t bytesPerRow = width * 3;
    80     unsigned char *destRowPtr = mesg + length - bytesPerRow;
    81     int y;
    82     unsigned char *srcRowPtr = const_cast<unsigned char *>(data);
    83     for (y = 0; y < height; y++) {
    84         memcpy(destRowPtr, srcRowPtr, bytesPerRow);
    85         srcRowPtr += bytesPerRow;
    86         destRowPtr -= bytesPerRow;
    87     }
    88 
    89     Response *response;
    90     if (strncmp(cmdName, "nv>legend", 9) == 0) {
    91         response = new Response(Response::LEGEND);
    92     } else {
    93         response = new Response(Response::IMAGE);
    94     }
    95     response->setMessage(mesg, length, Response::DYNAMIC);
    96     queue->enqueue(response);
    97     TRACE("Leaving (%dx%d)\n", width, height);
    98 }
    99 #else
    10018
    10119/**
     
    12139 */
    12240void
    123 Rappture::VtkVis::writePPM(int fd, const char *cmdName,
    124                            const unsigned char *data, int width, int height)
     41Rappture::VtkVis::writePPM(int fd, const char *cmdName, const unsigned char *data,
     42                           int width, int height)
    12543{
    12644#define PPM_MAXVAL 255
     
    12947    TRACE("Entering (%dx%d)\n", width, height);
    13048    // Generate the PPM binary file header
    131     snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height,
    132              PPM_MAXVAL);
     49    snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height, PPM_MAXVAL);
    13350
    13451    size_t headerLength = strlen(header);
     
    16279    }
    16380    if (writev(fd, iov, nRecs) < 0) {
    164         ERROR("write failed: %s\n", strerror(errno));
     81        ERROR("write failed: %s\n", strerror(errno));
    16582    }
    16683    free(iov);
     
    16885    TRACE("Leaving (%dx%d)\n", width, height);
    16986}
    170 
    171 #endif /*USE_THREADS*/
  • branches/blt4/packages/vizservers/vtkvis/PPMWriter.h

    r2542 r2550  
    99#define __RAPPTURE_VTKVIS_PPMWRITER_H__
    1010
    11 #ifdef USE_THREADS
    12 #include "ResponseQueue.h"
    13 #endif
    14 
    1511namespace Rappture {
    1612namespace VtkVis {
    17 #ifdef USE_THREADS
     13
    1814extern
    19 void queuePPM(ResponseQueue *queue, const char *cmdName,
    20               const unsigned char *data, int width, int height);
    21 #else
    22 extern
    23 void writePPM(int fd, const char *cmdName,
    24               const unsigned char *data, int width, int height);
    25 #endif
     15void writePPM(int fd, const char *cmdName, const unsigned char *data, int width, int height);
     16
    2617}
    2718}
     19
    2820#endif
  • branches/blt4/packages/vizservers/vtkvis/RpContour3D.cpp

    r2542 r2550  
    172172        _contourMapper->SetResolveCoincidentTopologyToPolygonOffset();
    173173        _contourMapper->SetInputConnection(_contourFilter->GetOutputPort());
     174        _contourMapper->SetColorModeToMapScalars();
    174175        getActor()->SetMapper(_contourMapper);
    175176    }
  • branches/blt4/packages/vizservers/vtkvis/RpGlyphs.h

    r2542 r2550  
    1414#include <vtkProp.h>
    1515#include <vtkActor.h>
    16 #ifdef HAVE_GLYPH3D_MAPPER
     16#include <vtkVersion.h>
     17#if ((VTK_MAJOR_VERSION > 5) || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 8))
     18#define HAVE_GLYPH3D_MAPPER
    1719#include <vtkGlyph3DMapper.h>
    1820#else
  • branches/blt4/packages/vizservers/vtkvis/RpHeightMap.cpp

    r2542 r2550  
    9191                _dataRange[1] = scalarRange[1];
    9292            } else {
    93                 dataSet->getScalarRange(_dataRange);
     93                _dataSet->getScalarRange(_dataRange);
    9494            }
    9595
  • branches/blt4/packages/vizservers/vtkvis/RpHeightMap.h

    r2542 r2550  
    7373    void setHeightScale(double scale);
    7474
     75    double getHeightScale()
     76    {
     77        return _warpScale;
     78    }
     79
    7580    void setNumContours(int numContours);
    7681
  • branches/blt4/packages/vizservers/vtkvis/RpLIC.cpp

    r2542 r2550  
    2424#include "RpLIC.h"
    2525#include "Trace.h"
    26 #include "RpVtkRenderServer.h"
    2726
    2827using namespace Rappture::VtkVis;
  • branches/blt4/packages/vizservers/vtkvis/RpPseudoColor.cpp

    r2542 r2550  
    1010#include <vtkDataSet.h>
    1111#include <vtkPointData.h>
     12#include <vtkCellData.h>
    1213#include <vtkDataSetMapper.h>
    1314#include <vtkUnstructuredGrid.h>
     
    235236    case COLOR_BY_VECTOR_MAGNITUDE: {
    236237        _dsMapper->ScalarVisibilityOn();
    237         _dsMapper->SetScalarModeToUsePointFieldData();
    238238        if (ds->GetPointData() != NULL &&
    239239            ds->GetPointData()->GetVectors() != NULL) {
     240            _dsMapper->SetScalarModeToUsePointFieldData();
    240241            _dsMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     242        } else if (ds->GetCellData() != NULL &&
     243                   ds->GetCellData()->GetVectors() != NULL) {
     244            _dsMapper->SetScalarModeToUseCellFieldData();
     245            _dsMapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
    241246        }
    242247        if (_lut != NULL) {
     
    248253    case COLOR_BY_VECTOR_X:
    249254        _dsMapper->ScalarVisibilityOn();
    250         _dsMapper->SetScalarModeToUsePointFieldData();
    251255        if (ds->GetPointData() != NULL &&
    252256            ds->GetPointData()->GetVectors() != NULL) {
     257            _dsMapper->SetScalarModeToUsePointFieldData();
    253258            _dsMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     259        } else if (ds->GetCellData() != NULL &&
     260                   ds->GetCellData()->GetVectors() != NULL) {
     261            _dsMapper->SetScalarModeToUseCellFieldData();
     262            _dsMapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
    254263        }
    255264        if (_lut != NULL) {
     
    261270    case COLOR_BY_VECTOR_Y:
    262271        _dsMapper->ScalarVisibilityOn();
    263         _dsMapper->SetScalarModeToUsePointFieldData();
    264272        if (ds->GetPointData() != NULL &&
    265273            ds->GetPointData()->GetVectors() != NULL) {
     274            _dsMapper->SetScalarModeToUsePointFieldData();
    266275            _dsMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     276        } else if (ds->GetCellData() != NULL &&
     277                   ds->GetCellData()->GetVectors() != NULL) {
     278            _dsMapper->SetScalarModeToUseCellFieldData();
     279            _dsMapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
    267280        }
    268281        if (_lut != NULL) {
     
    274287    case COLOR_BY_VECTOR_Z:
    275288        _dsMapper->ScalarVisibilityOn();
    276         _dsMapper->SetScalarModeToUsePointFieldData();
    277289        if (ds->GetPointData() != NULL &&
    278290            ds->GetPointData()->GetVectors() != NULL) {
     291            _dsMapper->SetScalarModeToUsePointFieldData();
    279292            _dsMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     293        } else if (ds->GetCellData() != NULL &&
     294                   ds->GetCellData()->GetVectors() != NULL) {
     295            _dsMapper->SetScalarModeToUseCellFieldData();
     296            _dsMapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
    280297        }
    281298        if (_lut != NULL) {
  • branches/blt4/packages/vizservers/vtkvis/RpStreamlines.cpp

    r2542 r2550  
    2121#include <vtkCellData.h>
    2222#include <vtkCellDataToPointData.h>
     23#include <vtkPolygon.h>
    2324#include <vtkPolyData.h>
    2425#include <vtkTubeFilter.h>
     
    2627#include <vtkTransform.h>
    2728#include <vtkTransformPolyDataFilter.h>
     29#include <vtkVertexGlyphFilter.h>
    2830
    2931#include "RpStreamlines.h"
     
    123125        _seedActor = vtkSmartPointer<vtkActor>::New();
    124126        _seedActor->GetProperty()->SetColor(_seedColor[0], _seedColor[1], _seedColor[2]);
     127        _seedActor->GetProperty()->SetEdgeColor(_seedColor[0], _seedColor[1], _seedColor[2]);
    125128        _seedActor->GetProperty()->SetLineWidth(1);
    126129        _seedActor->GetProperty()->SetPointSize(2);
     
    172175 */
    173176void Streamlines::getRandomPointInTriangle(double pt[3],
     177                                           const double v0[3],
    174178                                           const double v1[3],
    175                                            const double v2[3],
    176                                            const double v3[3])
     179                                           const double v2[3])
    177180{
    178181    // Choose random barycentric coordinates
     
    189192    // Convert to cartesian coords
    190193    for (int i = 0; i < 3; i++) {
    191         pt[i] = v1[i] * bary[0] + v2[i] * bary[1] + v3[i] * bary[2];
     194        pt[i] = v0[i] * bary[0] + v1[i] * bary[1] + v2[i] * bary[2];
     195    }
     196}
     197
     198void Streamlines::getRandomPointInTetrahedron(double pt[3],
     199                                              const double v0[3],
     200                                              const double v1[3],
     201                                              const double v2[3],
     202                                              const double v3[3])
     203{
     204    // Choose random barycentric coordinates
     205    double bary[4];
     206    bary[0] = getRandomNum(0, 1);
     207    bary[1] = getRandomNum(0, 1);
     208    bary[2] = getRandomNum(0, 1);
     209    if (bary[0] + bary[1] > 1.0) {
     210        bary[0] = 1.0 - bary[0];
     211        bary[1] = 1.0 - bary[1];
     212    }
     213    if (bary[1] + bary[2] > 1.0) {
     214        double tmp = bary[2];
     215        bary[2] = 1.0 - bary[0] - bary[1];
     216        bary[1] = 1.0 - tmp;
     217    } else if (bary[0] + bary[1] + bary[2] > 1.0) {
     218        double tmp = bary[2];
     219        bary[2] = bary[0] + bary[1] + bary[2] - 1.0;
     220        bary[0] = 1.0 - bary[1] - tmp;
     221    }
     222    bary[3] = 1.0 - bary[0] - bary[1] - bary[2];
     223    TRACE("bary %g %g %g %g", bary[0], bary[1], bary[2], bary[3]);
     224    // Convert to cartesian coords
     225    for (int i = 0; i < 3; i++) {
     226#if 0
     227        pt[i] = (v0[i] - v3[i]) * bary[0] +
     228                (v1[i] - v3[i]) * bary[1] +
     229                (v2[i] - v3[i]) * bary[2] + v3[i];
     230#else
     231        pt[i] = v0[i] * bary[0] + v1[i] * bary[1] +
     232                v2[i] * bary[2] + v3[i] * bary[3];
     233#endif
    192234    }
    193235}
     
    209251 * \brief Get a random point within a vtkDataSet's mesh
    210252 *
    211  * Note: This currently doesn't give a uniform distribution of
    212  * points in space and can generate points outside the mesh
     253 * Note: This currently doesn't always give a uniform distribution
     254 * of points in space and can generate points outside the mesh for
     255 * unusual cell types
    213256 */
    214257void Streamlines::getRandomCellPt(double pt[3], vtkDataSet *ds)
     
    218261    // all cells are equal area/volume)
    219262    int cell = rand() % numCells;
    220     double bounds[6];
    221     ds->GetCellBounds(cell, bounds);
    222     // Note: point is inside AABB of cell, but may be outside the cell
    223     getRandomPoint(pt, bounds);
     263    int type = ds->GetCellType(cell);
     264    switch (type) {
     265    case VTK_VERTEX: {
     266        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     267        ds->GetCellPoints(cell, ptIds);
     268        assert(ptIds->GetNumberOfIds() == 1);
     269        ds->GetPoint(ptIds->GetId(0), pt);
     270    }
     271        break;
     272    case VTK_POLY_VERTEX: {
     273        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     274        ds->GetCellPoints(cell, ptIds);
     275        assert(ptIds->GetNumberOfIds() >= 1);
     276        int id = rand() % ptIds->GetNumberOfIds();
     277        ds->GetPoint(ptIds->GetId(id), pt);
     278    }
     279        break;
     280    case VTK_LINE: {
     281        double v[2][3];
     282        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     283        ds->GetCellPoints(cell, ptIds);
     284        assert(ptIds->GetNumberOfIds() == 2);
     285        for (int i = 0; i < 2; i++) {
     286            ds->GetPoint(ptIds->GetId(i), v[i]);
     287        }
     288        getRandomPointOnLineSegment(pt, v[0], v[1]);
     289    }
     290        break;
     291    case VTK_POLY_LINE: {
     292        double v[2][3];
     293        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     294        ds->GetCellPoints(cell, ptIds);
     295        assert(ptIds->GetNumberOfIds() >= 2);
     296        int id = rand() % (ptIds->GetNumberOfIds()-1);
     297        for (int i = 0; i < 2; i++) {
     298            ds->GetPoint(ptIds->GetId(id+i), v[i]);
     299        }
     300        getRandomPointOnLineSegment(pt, v[0], v[1]);
     301    }
     302        break;
     303    case VTK_TRIANGLE: {
     304        double v[3][3];
     305        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     306        ds->GetCellPoints(cell, ptIds);
     307        assert(ptIds->GetNumberOfIds() == 3);
     308        for (int i = 0; i < 3; i++) {
     309            ds->GetPoint(ptIds->GetId(i), v[i]);
     310        }
     311        getRandomPointInTriangle(pt, v[0], v[1], v[2]);
     312    }
     313        break;
     314    case VTK_TRIANGLE_STRIP: {
     315        double v[3][3];
     316        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     317        ds->GetCellPoints(cell, ptIds);
     318        assert(ptIds->GetNumberOfIds() >= 3);
     319        int id = rand() % (ptIds->GetNumberOfIds()-2);
     320        for (int i = 0; i < 3; i++) {
     321            ds->GetPoint(ptIds->GetId(id+i), v[i]);
     322        }
     323        getRandomPointInTriangle(pt, v[0], v[1], v[2]);
     324    }
     325        break;
     326    case VTK_POLYGON: {
     327        vtkPolygon *poly = vtkPolygon::SafeDownCast(ds->GetCell(cell));
     328        assert (poly != NULL);
     329        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     330        poly->Triangulate(ptIds);
     331        assert(ptIds->GetNumberOfIds() >= 3 && ptIds->GetNumberOfIds() % 3 == 0);
     332        int tri = rand() % (ptIds->GetNumberOfIds()/3);
     333        double v[3][3];
     334        for (int i = 0; i < 3; i++) {
     335            ds->GetPoint(ptIds->GetId(i + tri * 3), v[i]);
     336        }
     337        getRandomPointInTriangle(pt, v[0], v[1], v[2]);
     338    }
     339        break;
     340    case VTK_QUAD: {
     341        double v[4][3];
     342        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     343        ds->GetCellPoints(cell, ptIds);
     344        assert(ptIds->GetNumberOfIds() == 4);
     345        for (int i = 0; i < 4; i++) {
     346            ds->GetPoint(ptIds->GetId(i), v[i]);
     347        }
     348        int tri = rand() & 0x1;
     349        if (tri) {
     350            getRandomPointInTriangle(pt, v[0], v[1], v[2]);
     351        } else {
     352            getRandomPointInTriangle(pt, v[0], v[2], v[3]);
     353        }
     354    }
     355        break;
     356    case VTK_TETRA: {
     357        double v[4][3];
     358        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     359        ds->GetCellPoints(cell, ptIds);
     360        assert(ptIds->GetNumberOfIds() == 4);
     361        for (int i = 0; i < 4; i++) {
     362            ds->GetPoint(ptIds->GetId(i), v[i]);
     363        }
     364        getRandomPointInTetrahedron(pt, v[0], v[1], v[2], v[3]);
     365    }
     366        break;
     367    case VTK_WEDGE: {
     368        double v[6][3];
     369        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     370        ds->GetCellPoints(cell, ptIds);
     371        assert(ptIds->GetNumberOfIds() == 6);
     372        for (int i = 0; i < 6; i++) {
     373            ds->GetPoint(ptIds->GetId(i), v[i]);
     374        }
     375        double vv[3][3];
     376        getRandomPointOnLineSegment(vv[0], v[0], v[3]);
     377        getRandomPointOnLineSegment(vv[1], v[1], v[4]);
     378        getRandomPointOnLineSegment(vv[2], v[2], v[5]);
     379        getRandomPointInTriangle(pt, vv[0], vv[1], vv[2]);
     380    }
     381        break;
     382    case VTK_PYRAMID: {
     383        double v[5][3];
     384        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     385        ds->GetCellPoints(cell, ptIds);
     386        assert(ptIds->GetNumberOfIds() == 5);
     387        for (int i = 0; i < 5; i++) {
     388            ds->GetPoint(ptIds->GetId(i), v[i]);
     389        }
     390        int tetra = rand() & 0x1;
     391        if (tetra) {
     392            getRandomPointInTetrahedron(pt, v[0], v[1], v[2], v[4]);
     393        } else {
     394            getRandomPointInTetrahedron(pt, v[0], v[2], v[3], v[4]);
     395        }
     396    }
     397        break;
     398    case VTK_PIXEL:
     399    case VTK_VOXEL: {
     400        double bounds[6];
     401        ds->GetCellBounds(cell, bounds);
     402        getRandomPoint(pt, bounds);
     403    }
     404        break;
     405    default: {
     406        vtkSmartPointer<vtkIdList> ptIds = vtkSmartPointer<vtkIdList>::New();
     407        vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();
     408        ds->GetCell(cell)->Triangulate(0, ptIds, pts);
     409        if (ptIds->GetNumberOfIds() % 4 == 0) {
     410            int tetra = rand() % (ptIds->GetNumberOfIds()/4);
     411            double v[4][3];
     412            for (int i = 0; i < 4; i++) {
     413                ds->GetPoint(ptIds->GetId(i + tetra * 4), v[i]);
     414            }
     415            getRandomPointInTetrahedron(pt, v[0], v[1], v[2], v[4]);
     416        } else {
     417            assert(ptIds->GetNumberOfIds() % 3 == 0);
     418            int tri = rand() % (ptIds->GetNumberOfIds()/3);
     419            double v[3][3];
     420            for (int i = 0; i < 3; i++) {
     421                ds->GetPoint(ptIds->GetId(i + tri * 3), v[i]);
     422            }
     423            getRandomPointInTriangle(pt, v[0], v[1], v[2]);
     424        }
     425    }
     426    }
    224427}
    225428
     
    237440    double bounds[6];
    238441    _dataSet->getBounds(bounds);
     442    double xLen = bounds[1] - bounds[0];
     443    double yLen = bounds[3] - bounds[2];
     444    double zLen = bounds[5] - bounds[4];
    239445    double maxBound = 0.0;
    240     if (bounds[1] - bounds[0] > maxBound) {
    241         maxBound = bounds[1] - bounds[0];
    242     }
    243     if (bounds[3] - bounds[2] > maxBound) {
    244         maxBound = bounds[3] - bounds[2];
    245     }
    246     if (bounds[5] - bounds[4] > maxBound) {
    247         maxBound = bounds[5] - bounds[4];
     446    if (xLen > maxBound) {
     447        maxBound = xLen;
     448    }
     449    if (yLen > maxBound) {
     450        maxBound = yLen;
     451    }
     452    if (zLen > maxBound) {
     453        maxBound = zLen;
    248454    }
    249455
     
    276482
    277483    _streamTracer->SetInput(ds);
    278     _streamTracer->SetMaximumPropagation(maxBound);
     484    _streamTracer->SetMaximumPropagation(xLen + yLen + zLen);
     485    _streamTracer->SetIntegratorTypeToRungeKutta45();
     486
     487    TRACE("Setting streamlines max length to %g",
     488          _streamTracer->GetMaximumPropagation());
    279489
    280490    if (_pdMapper == NULL) {
     
    286496        _seedMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    287497        _seedMapper->SetResolveCoincidentTopologyToPolygonOffset();
     498        _seedMapper->ScalarVisibilityOff();
    288499    }
    289500
    290501    // Set up seed source object
    291     setSeedToRandomPoints(200);
     502    setSeedToFilledMesh(200);
    292503
    293504    switch (_lineType) {
     
    343554
    344555/**
    345  * \brief Use randomly distributed seed points
     556 * \brief Use points of the DataSet associated with this
     557 * Streamlines as seeds
     558 */
     559void Streamlines::setSeedToMeshPoints()
     560{
     561    setSeedToMeshPoints(_dataSet->getVtkDataSet());
     562}
     563
     564/**
     565 * \brief Use seed points randomly distributed within the cells
     566 * of the DataSet associated with this Streamlines
    346567 *
    347568 * Note: The current implementation doesn't give a uniform
     
    351572 * \param[in] numPoints Number of random seed points to generate
    352573 */
    353 void Streamlines::setSeedToRandomPoints(int numPoints)
     574void Streamlines::setSeedToFilledMesh(int numPoints)
     575{
     576    setSeedToFilledMesh(_dataSet->getVtkDataSet(), numPoints);
     577}
     578
     579/**
     580 * \brief Use points of a supplied vtkDataSet as seeds
     581 *
     582 * \param[in] seed vtkDataSet with points to use as seeds
     583 */
     584void Streamlines::setSeedToMeshPoints(vtkDataSet *seed)
     585{
     586    if (_streamTracer != NULL) {
     587        TRACE("Seed points: %d", seed->GetNumberOfPoints());
     588        vtkSmartPointer<vtkDataSet> oldSeed;
     589        if (_streamTracer->GetSource() != NULL) {
     590            oldSeed = _streamTracer->GetSource();
     591        }
     592
     593        _streamTracer->SetSource(seed);
     594        if (oldSeed != NULL) {
     595            oldSeed->SetPipelineInformation(NULL);
     596        }
     597
     598        if (vtkPolyData::SafeDownCast(seed) != NULL) {
     599            _seedMapper->SetInput(vtkPolyData::SafeDownCast(seed));
     600        } else {
     601            vtkSmartPointer<vtkVertexGlyphFilter> vertFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
     602            vertFilter->SetInput(seed);
     603            _seedMapper->SetInputConnection(vertFilter->GetOutputPort());
     604        }
     605    }
     606}
     607
     608/**
     609 * \brief Use seed points randomly distributed within the cells
     610 * of a supplied vtkDataSet
     611 *
     612 * Note: The current implementation doesn't give a uniform
     613 * distribution of points, and points outside the mesh bounds
     614 * may be generated
     615 *
     616 * \param[in] ds vtkDataSet containing cells
     617 * \param[in] numPoints Number of random seed points to generate
     618 */
     619void Streamlines::setSeedToFilledMesh(vtkDataSet *ds, int numPoints)
    354620{
    355621    if (_streamTracer != NULL) {
     
    359625        vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
    360626
     627        if (ds->GetNumberOfCells() < 1) {
     628            ERROR("No cells in mesh");
     629        }
     630
    361631        for (int i = 0; i < numPoints; i++) {
    362632            double pt[3];
    363             getRandomCellPt(pt, _dataSet->getVtkDataSet());
    364             TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
     633            getRandomCellPt(pt, ds);
     634            //TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
    365635            pts->InsertNextPoint(pt);
    366636            cells->InsertNextCell(1);
     
    415685                pt[ii] = start[ii] + dir[ii] * ((double)i / (numPoints-1));
    416686            }
    417             TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
     687            //TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
    418688            pts->InsertNextPoint(pt);
    419689            polyline->GetPointIds()->SetId(i, i);
     
    507777                pt[i] = center[i] + r * (px[i] * cos(angle) + py[i] * sin(angle));
    508778            }
    509             TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
     779            //TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
    510780            pts->InsertNextPoint(pt);
    511781            cells->InsertNextCell(1);
     
    662932                                                    py[i] * sin(theta));
    663933            }
    664             TRACE("Vert %d: %g %g %g", j, verts[j][0], verts[j][1], verts[j][2]);
     934            //TRACE("Vert %d: %g %g %g", j, verts[j][0], verts[j][1], verts[j][2]);
    665935        }
    666936
     
    671941                double pt[3];
    672942                getRandomPointInTriangle(pt, verts[0], verts[1], verts[2]);
    673                 TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
     943                //TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
    674944                pts->InsertNextPoint(pt);
    675945                cells->InsertNextCell(1);
     
    682952                double pt[3];
    683953                getRandomPointInTriangle(pt, center, verts[tri], verts[(tri+1) % numSides]);
    684                 TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
     954                //TRACE("Seed pt: %g %g %g", pt[0], pt[1], pt[2]);
    685955                pts->InsertNextPoint(pt);
    686956                cells->InsertNextCell(1);
     
    708978
    709979/**
    710  * \brief Set maximum length of stream lines in world coordinates
     980 * \brief Set the integration method used
     981 */
     982void Streamlines::setIntegrator(IntegratorType integrator)
     983{
     984    if (_streamTracer != NULL) {
     985        switch (integrator) {
     986        case RUNGE_KUTTA2:
     987            _streamTracer->SetIntegratorTypeToRungeKutta2();
     988            break;
     989        case RUNGE_KUTTA4:
     990            _streamTracer->SetIntegratorTypeToRungeKutta4();
     991            break;
     992        case RUNGE_KUTTA45:
     993            _streamTracer->SetIntegratorTypeToRungeKutta45();
     994            break;
     995        default:
     996            ;
     997        }
     998    }
     999}
     1000
     1001/**
     1002 * \brief Set the direction of integration
     1003 */
     1004void Streamlines::setIntegrationDirection(IntegrationDirection dir)
     1005{
     1006    if (_streamTracer != NULL) {
     1007        switch (dir) {
     1008        case FORWARD:
     1009            _streamTracer->SetIntegrationDirectionToForward();
     1010            break;
     1011        case BACKWARD:
     1012            _streamTracer->SetIntegrationDirectionToBackward();
     1013            break;
     1014        case BOTH:
     1015            _streamTracer->SetIntegrationDirectionToBoth();
     1016            break;
     1017        default:
     1018            ;
     1019        }
     1020    }
     1021}
     1022
     1023/**
     1024 * \brief Set the step size units.  Length units are world
     1025 * coordinates, and cell units means steps are from cell to
     1026 * cell.  Default is cell units.
     1027 *
     1028 * Note: calling this function will not convert existing
     1029 * initial, minimum or maximum step value settings to the
     1030 * new units, so this function should be called before
     1031 * setting step values.
     1032 */
     1033void Streamlines::setIntegrationStepUnit(StepUnit unit)
     1034{
     1035    if (_streamTracer != NULL) {
     1036        switch (unit) {
     1037        case LENGTH_UNIT:
     1038            _streamTracer->SetIntegrationStepUnit(vtkStreamTracer::LENGTH_UNIT);
     1039            break;
     1040        case CELL_LENGTH_UNIT:
     1041            _streamTracer->SetIntegrationStepUnit(vtkStreamTracer::CELL_LENGTH_UNIT);
     1042            break;
     1043        default:
     1044            ;
     1045        }
     1046    }
     1047}
     1048
     1049/**
     1050 * \brief Set initial step size for adaptive step integrator in
     1051 * step units (see setIntegrationStepUnit).  For non-adaptive
     1052 * integrators, this is the fixed step size.
     1053 */
     1054void Streamlines::setInitialIntegrationStep(double step)
     1055{
     1056    if (_streamTracer != NULL) {
     1057        _streamTracer->SetInitialIntegrationStep(step);
     1058    }
     1059}
     1060
     1061/**
     1062 * \brief Set minimum step for adaptive step integrator in
     1063 * step units (see setIntegrationStepUnit)
     1064 */
     1065void Streamlines::setMinimumIntegrationStep(double step)
     1066{
     1067    if (_streamTracer != NULL) {
     1068        _streamTracer->SetMinimumIntegrationStep(step);
     1069    }
     1070}
     1071
     1072/**
     1073 * \brief Set maximum step for adaptive step integrator in
     1074 * step units (see setIntegrationStepUnit)
     1075 */
     1076void Streamlines::setMaximumIntegrationStep(double step)
     1077{
     1078    if (_streamTracer != NULL) {
     1079        _streamTracer->SetMaximumIntegrationStep(step);
     1080    }
     1081}
     1082
     1083/**
     1084 * \brief Set maximum error tolerance
     1085 */
     1086void Streamlines::setMaximumError(double error)
     1087{
     1088    if (_streamTracer != NULL) {
     1089        _streamTracer->SetMaximumError(error);
     1090    }
     1091}
     1092
     1093/**
     1094 * \brief Set maximum length of stream lines in world
     1095 * coordinates
    7111096 */
    7121097void Streamlines::setMaxPropagation(double length)
     
    7141099    if (_streamTracer != NULL) {
    7151100        _streamTracer->SetMaximumPropagation(length);
     1101    }
     1102}
     1103
     1104/**
     1105 * \brief Set maximum number of integration steps
     1106 */
     1107void Streamlines::setMaxNumberOfSteps(int steps)
     1108{
     1109    if (_streamTracer != NULL) {
     1110        _streamTracer->SetMaximumNumberOfSteps(steps);
     1111    }
     1112}
     1113
     1114/**
     1115 * \brief Set the minimum speed before integration stops
     1116 */
     1117void Streamlines::setTerminalSpeed(double speed)
     1118{
     1119    if (_streamTracer != NULL) {
     1120        _streamTracer->SetTerminalSpeed(speed);
    7161121    }
    7171122}
     
    8201225        return;
    8211226
    822     vtkDataSet *ds = _dataSet->getVtkDataSet();
    823 
    8241227    switch (mode) {
    8251228    case COLOR_BY_SCALAR: {
     
    8341237        _pdMapper->ScalarVisibilityOn();
    8351238        _pdMapper->SetScalarModeToUsePointFieldData();
    836         if (ds->GetPointData() != NULL &&
    837             ds->GetPointData()->GetVectors() != NULL) {
    838             _pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    839         }
     1239        _pdMapper->SelectColorArray(_dataSet->getActiveVectorsName());
    8401240        if (_lut != NULL) {
    8411241            _lut->SetRange(_vectorMagnitudeRange);
     
    8471247        _pdMapper->ScalarVisibilityOn();
    8481248        _pdMapper->SetScalarModeToUsePointFieldData();
    849         if (ds->GetPointData() != NULL &&
    850             ds->GetPointData()->GetVectors() != NULL) {
    851             _pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    852         }
     1249        _pdMapper->SelectColorArray(_dataSet->getActiveVectorsName());
    8531250        if (_lut != NULL) {
    8541251            _lut->SetRange(_vectorComponentRange[0]);
     
    8601257        _pdMapper->ScalarVisibilityOn();
    8611258        _pdMapper->SetScalarModeToUsePointFieldData();
    862         if (ds->GetPointData() != NULL &&
    863             ds->GetPointData()->GetVectors() != NULL) {
    864             _pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    865         }
     1259        _pdMapper->SelectColorArray(_dataSet->getActiveVectorsName());
    8661260        if (_lut != NULL) {
    8671261            _lut->SetRange(_vectorComponentRange[1]);
     
    8731267        _pdMapper->ScalarVisibilityOn();
    8741268        _pdMapper->SetScalarModeToUsePointFieldData();
    875         if (ds->GetPointData() != NULL &&
    876             ds->GetPointData()->GetVectors() != NULL) {
    877             _pdMapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
    878         }
     1269        _pdMapper->SelectColorArray(_dataSet->getActiveVectorsName());
    8791270        if (_lut != NULL) {
    8801271            _lut->SetRange(_vectorComponentRange[2]);
     
    10581449    _seedColor[1] = color[1];
    10591450    _seedColor[2] = color[2];
    1060     if (_seedActor != NULL)
     1451    if (_seedActor != NULL) {
    10611452        _seedActor->GetProperty()->SetColor(_seedColor[0], _seedColor[1], _seedColor[2]);
     1453        _seedActor->GetProperty()->SetEdgeColor(_seedColor[0], _seedColor[1], _seedColor[2]);
     1454    }
    10621455}
    10631456
  • branches/blt4/packages/vizservers/vtkvis/RpStreamlines.h

    r2542 r2550  
    4444        COLOR_CONSTANT
    4545    };
     46    enum StepUnit {
     47        LENGTH_UNIT,
     48        CELL_LENGTH_UNIT
     49    };
     50    enum IntegratorType {
     51        RUNGE_KUTTA2,
     52        RUNGE_KUTTA4,
     53        RUNGE_KUTTA45
     54    };
     55    enum IntegrationDirection {
     56        FORWARD,
     57        BACKWARD,
     58        BOTH
     59    };
    4660
    4761    Streamlines();
     
    7791    virtual void setClippingPlanes(vtkPlaneCollection *planes);
    7892
    79     void setSeedToRandomPoints(int numPoints);
     93    void setSeedToMeshPoints();
     94
     95    void setSeedToFilledMesh(int numPoints);
     96
     97    void setSeedToMeshPoints(vtkDataSet *ds);
     98
     99    void setSeedToFilledMesh(vtkDataSet *ds, int numPoints);
    80100
    81101    void setSeedToRake(double start[3], double end[3], int numPoints);
     
    92112                                int numSides, int numPoints);
    93113
     114    void setIntegrator(IntegratorType integrator);
     115
     116    void setIntegrationDirection(IntegrationDirection dir);
     117
     118    void setIntegrationStepUnit(StepUnit unit);
     119
     120    void setInitialIntegrationStep(double step);
     121
     122    void setMinimumIntegrationStep(double step);
     123
     124    void setMaximumIntegrationStep(double step);
     125
     126    void setMaximumError(double error);
     127
    94128    void setMaxPropagation(double length);
     129
     130    void setMaxNumberOfSteps(int steps);
     131
     132    void setTerminalSpeed(double speed);
    95133
    96134    void setLineTypeToLines();
     
    130168    static void getRandomPoint(double pt[3], const double bounds[6]);
    131169    static void getRandomPointInTriangle(double pt[3],
     170                                         const double v0[3],
    132171                                         const double v1[3],
    133                                          const double v2[3],
    134                                          const double v3[3]);
     172                                         const double v2[3]);
    135173    static void getRandomPointOnLineSegment(double pt[3],
    136174                                            const double endpt[3],
    137175                                            const double endpt2[3]);
     176    static void getRandomPointInTetrahedron(double pt[3],
     177                                            const double v0[3],
     178                                            const double v1[3],
     179                                            const double v2[3],
     180                                            const double v3[3]);
    138181    static void getRandomCellPt(double pt[3], vtkDataSet *ds);
    139182
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRenderServer.cpp

    r2542 r2550  
    1 
    21/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    32/*
     
    109#include <cstring>
    1110#include <cstdlib>
    12 #include <cerrno>
     11#include <string>
     12#include <sstream>
    1313#include <unistd.h>
    1414#include <signal.h>
     
    1717#include <sys/time.h>
    1818#endif
    19 
    20 #include <string>
    21 #include <sstream>
    2219
    2320#include "Trace.h"
     
    2724#include "PPMWriter.h"
    2825#include "TGAWriter.h"
    29 #ifdef USE_THREADS
    30 #include <pthread.h>
    31 #include "ResponseQueue.h"
    32 #endif
    3326
    3427using namespace Rappture::VtkVis;
     
    4538     (((t2).tv_sec - (t1).tv_sec))*1.0e+3f + (float)((t2).tv_usec - (t1).tv_usec)/1.0e+3f)
    4639
    47 #ifdef USE_THREADS
    4840static void
    49 queueFrame(ResponseQueue *queue, vtkUnsignedCharArray *imgData)
     41writeFrame(int fd, vtkUnsignedCharArray *imgData)
    5042{
    5143#ifdef DEBUG
     
    7365                 TARGA_BYTES_PER_PIXEL,
    7466                 true);
    75 #endif  /*RENDER_TARGA*/
     67#endif
    7668
    7769#else
     
    9082
    9183#ifdef RENDER_TARGA
    92         queueTGA(queue, oss.str().c_str(),
     84        writeTGA(fd, oss.str().c_str(),
    9385                 imgData->GetPointer(0),
    9486                 g_renderer->getWindowWidth(),
     
    9688                 TARGA_BYTES_PER_PIXEL);
    9789#else
    98         queuePPM(queue, oss.str().c_str(),
     90        writePPM(fd, oss.str().c_str(),
    9991                 imgData->GetPointer(0),
    10092                 g_renderer->getWindowWidth(),
    10193                 g_renderer->getWindowHeight());
    102 #endif  /*RENDER_TARGA*/
    103     } else {
    104 #ifdef RENDER_TARGA
    105         queueTGA(queue, "nv>image -type image -bytes",
    106                  imgData->GetPointer(0),
    107                  g_renderer->getWindowWidth(),
    108                  g_renderer->getWindowHeight(),
    109                  TARGA_BYTES_PER_PIXEL);
    110 #else
    111         queuePPM(queue, "nv>image -type image -bytes",
    112                  imgData->GetPointer(0),
    113                  g_renderer->getWindowWidth(),
    114                  g_renderer->getWindowHeight());
    115 #endif  /*RENDER_TARGA*/
    116     }
    117 #endif  /*DEBUG*/
    118 }
    119 
    120 #else
    121 
    122 static void
    123 writeFrame(int fd, vtkUnsignedCharArray *imgData)
    124 {
    125 #ifdef DEBUG
    126     if (g_renderer->getCameraMode() == Renderer::IMAGE) {
    127         double xywh[4];
    128         g_renderer->getScreenWorldCoords(xywh);
    129         TRACE("Image bbox: %g %g %g %g",
    130               xywh[0],
    131               (xywh[1] + xywh[3]),
    132               (xywh[0] + xywh[2]),
    133               xywh[1]);
    134     }
    135 
    136 #ifdef RENDER_TARGA
    137     writeTGAFile("/tmp/frame.tga",
    138                  imgData->GetPointer(0),
    139                  g_renderer->getWindowWidth(),
    140                  g_renderer->getWindowHeight(),
    141                  TARGA_BYTES_PER_PIXEL);
    142 #else
    143     writeTGAFile("/tmp/frame.tga",
    144                  imgData->GetPointer(0),
    145                  g_renderer->getWindowWidth(),
    146                  g_renderer->getWindowHeight(),
    147                  TARGA_BYTES_PER_PIXEL,
    148                  true);
    149 #endif  /*RENDER_TARGA*/
    150 
    151 #else
    152     if (g_renderer->getCameraMode() == Renderer::IMAGE) {
    153         double xywh[4];
    154         g_renderer->getCameraZoomRegion(xywh);
    155         std::ostringstream oss;
    156         oss.precision(12);
    157         // Send upper left and lower right corners as bbox
    158         oss << "nv>image -type image -bbox {"
    159             << std::scientific
    160             << xywh[0] << " "
    161             << xywh[1] << " "
    162             << xywh[2] << " "
    163             << xywh[3] << "} -bytes";
    164 
    165 #ifdef RENDER_TARGA
    166         writeTGA(fd, oss.str().c_str(),
    167                  imgData->GetPointer(0),
    168                  g_renderer->getWindowWidth(),
    169                  g_renderer->getWindowHeight(),
    170                  TARGA_BYTES_PER_PIXEL);
    171 #else
    172         writePPM(fd, oss.str().c_str(),
    173                  imgData->GetPointer(0),
    174                  g_renderer->getWindowWidth(),
    175                  g_renderer->getWindowHeight());
    176 #endif  /*RENDER_TARGA*/
     94#endif
    17795    } else {
    17896#ifdef RENDER_TARGA
     
    187105                 g_renderer->getWindowWidth(),
    188106                 g_renderer->getWindowHeight());
    189 #endif  /*RENDER_TARGA*/
    190     }
    191 #endif  /*DEBUG*/
    192 }
    193 #endif /*USE_THREADS*/
     107#endif
     108    }
     109#endif
     110}
    194111
    195112static void
     
    236153}
    237154
    238 #ifdef USE_THREADS
    239 static void *
    240 readerThread(void *clientData)
    241 {
    242     ResponseQueue *queue = (ResponseQueue *)clientData;
    243     Tcl_Interp *interp;
    244 
    245     TRACE("starting reader thread");
    246     interp = (Tcl_Interp *)queue->clientData();
    247     vtkSmartPointer<vtkUnsignedCharArray> imgData =
    248         vtkSmartPointer<vtkUnsignedCharArray>::New();
    249     for (;;) {
    250         int ret;
    251 
    252         ret = processCommands(interp, g_fIn, g_fOut);
    253         if (ret < 0)
    254             break;
    255         if (g_renderer->render()) {
    256             TRACE("Rendering new frame");
    257             g_renderer->getRenderedFrame(imgData);
    258             queueFrame(queue, imgData);
    259         } else {
    260             TRACE("No render required");
    261         }
    262         if (feof(g_fIn))
    263             break;
    264     }   
    265     return NULL;
    266 }
    267 
    268 static void *
    269 writerThread(void *clientData)
    270 {
    271     ResponseQueue *queue = (ResponseQueue *)clientData;
    272 
    273     TRACE("starting writer thread");
    274     for (;;) {
    275         Response *response;
    276 
    277         response = queue->dequeue();
    278         if (fwrite(response->message(), sizeof(char), response->length(),
    279                    g_fOut) != response->length()) {
    280             ERROR("short write while trying to write %ld bytes",
    281                   response->length());
    282         }
    283         fflush(g_fOut);
    284         delete response;
    285         if (feof(g_fOut))
    286             break;
    287     }   
    288     return NULL;
    289 }
    290 
    291 #endif  /*USE_THREADS*/
    292 
    293155int
    294156main(int argc, char *argv[])
     
    297159    signal(SIGPIPE, SIG_IGN);
    298160    initService();
    299     initLog();
     161    InitLog();
    300162
    301163    TRACE("Starting VTKVis Server");
     
    314176
    315177    g_renderer = new Renderer();
    316 
    317     Tcl_Interp *interp = Tcl_CreateInterp();
    318 
    319 #ifdef USE_THREADS
    320     ResponseQueue queue((void *)interp);
    321     initTcl(interp, (ClientData)&queue);
    322 
    323     pthread_t readerThreadId, writerThreadId;
    324     if (pthread_create(&readerThreadId, NULL, &readerThread, &queue) < 0) {
    325         ERROR("can't create reader thread: %s", strerror(errno));
    326     }
    327     if (pthread_create(&writerThreadId, NULL, &writerThread, &queue) < 0) {
    328         ERROR("can't create writer thread: %s", strerror(errno));
    329     }
    330     if (pthread_join(readerThreadId, NULL) < 0) {
    331         ERROR("can't join reader thread: %s", strerror(errno));
    332     }
    333     if (pthread_join(writerThreadId, NULL) < 0) {
    334         ERROR("can't join writer thread: %s", strerror(errno));
    335     }
    336 #else
    337     initTcl(interp, (ClientData)NULL);
    338     int ret = 0;
    339 
    340178    vtkSmartPointer<vtkUnsignedCharArray> imgData =
    341179        vtkSmartPointer<vtkUnsignedCharArray>::New();
     180
     181    Tcl_Interp *interp = initTcl();
     182
     183    int ret = 0;
     184
    342185    while (1) {
    343186        ret = processCommands(interp, g_fIn, g_fOut);
     
    356199            break;
    357200    }
    358 #endif
    359     INFO("exiting vtkvis");
     201
    360202    exitTcl(interp);
    361203    interp = NULL;
     
    366208    TRACE("Exiting VTKVis Server");
    367209
    368     closeLog();
     210    CloseLog();
    369211    exitService();
    370212
    371     return 0;
    372 }
    373 
     213    return ret;
     214}
     215
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRenderServer.h

    r2120 r2550  
    99#define __RAPPTURE_VTKVIS_RENDERSERVER_H__
    1010
    11 #include "RpVtkRenderer.h"
    12 
    1311namespace Rappture {
    1412namespace VtkVis {
     13
     14class Renderer;
    1515
    1616extern int g_fdIn;
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2542 r2550  
    4040#include <vtkTextProperty.h>
    4141#include <vtkOpenGLRenderWindow.h>
     42#include <vtkVersion.h>
    4243
    4344#include "RpVtkRenderer.h"
     
    158159    }
    159160    _contour3Ds.clear();
     161    TRACE("Deleting Cutplanes");
     162    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     163             itr != _cutplanes.end(); ++itr) {
     164        delete itr->second;
     165    }
     166    _cutplanes.clear();
    160167    TRACE("Deleting Glyphs");
    161168    for (GlyphsHashmap::iterator itr = _glyphs.begin();
     
    314321
    315322/**
     323 * \brief Remove the Cutplane for the specified DataSet
     324 *
     325 * The underlying Cutplane is deleted, freeing its memory
     326 */
     327void Renderer::deleteCutplane(const DataSetId& id)
     328{
     329    CutplaneHashmap::iterator itr;
     330
     331    bool doAll = false;
     332
     333    if (id.compare("all") == 0) {
     334        itr = _cutplanes.begin();
     335        doAll = true;
     336    } else {
     337        itr = _cutplanes.find(id);
     338    }
     339    if (itr == _cutplanes.end()) {
     340        ERROR("Cutplane not found: %s", id.c_str());
     341        return;
     342    }
     343
     344    TRACE("Deleting Cutplanes for %s", id.c_str());
     345
     346    do {
     347        Cutplane *cutplane = itr->second;
     348        if (cutplane->getProp())
     349            _renderer->RemoveViewProp(cutplane->getProp());
     350        delete cutplane;
     351
     352        itr = _cutplanes.erase(itr);
     353    } while (doAll && itr != _cutplanes.end());
     354
     355    _renderer->ResetCameraClippingRange();
     356    _needsRedraw = true;
     357}
     358
     359/**
    316360 * \brief Remove the Glyphs for the specified DataSet
    317361 *
     
    637681        deleteContour2D(itr->second->getName());
    638682        deleteContour3D(itr->second->getName());
     683        deleteCutplane(itr->second->getName());
    639684        deleteGlyphs(itr->second->getName());
    640685        deleteHeightMap(itr->second->getName());
     
    825870            double newBounds[6];
    826871            collectBounds(newBounds, false);
     872#if ((VTK_MAJOR_VERSION > 5) || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 8))
     873            _cubeAxesActor->SetXAxisRange(newBounds[0], newBounds[1]);
     874            _cubeAxesActor->SetYAxisRange(newBounds[2], newBounds[3]);
     875            _cubeAxesActor->SetZAxisRange(newBounds[4], newBounds[5]);
     876#endif
    827877            _cubeAxesActor->SetBounds(newBounds);
    828878            TRACE("Bounds (computed): %g %g %g %g %g %g",
     
    834884                  newBounds[5]);
    835885        } else {
     886#if ((VTK_MAJOR_VERSION > 5) || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 8))
     887            _cubeAxesActor->SetXAxisRange(bounds[0], bounds[1]);
     888            _cubeAxesActor->SetYAxisRange(bounds[2], bounds[3]);
     889            _cubeAxesActor->SetZAxisRange(bounds[4], bounds[5]);
     890#endif
    836891            _cubeAxesActor->SetBounds(bounds);
    837892            TRACE("Bounds (supplied): %g %g %g %g %g %g",
     
    858913    // Don't offset labels at origin
    859914    _cubeAxesActor->SetCornerOffset(0);
    860     _cubeAxesActor->SetFlyModeToClosestTriad();
     915    _cubeAxesActor->SetFlyModeToStaticTriad();
    861916
    862917#ifdef USE_CUSTOM_AXES
     
    12131268        }
    12141269    }
     1270    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     1271         itr != _cutplanes.end(); ++itr) {
     1272        if (itr->second->getColorMap() == cmap) {
     1273            itr->second->updateColorMap();
     1274            _needsRedraw = true;
     1275        }
     1276    }
    12151277    for (GlyphsHashmap::iterator itr = _glyphs.begin();
    12161278         itr != _glyphs.end(); ++itr) {
     
    12711333    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
    12721334         itr != _contour3Ds.end(); ++itr) {
     1335        if (itr->second->getColorMap() == cmap)
     1336            return true;
     1337    }
     1338    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     1339         itr != _cutplanes.end(); ++itr) {
    12731340        if (itr->second->getColorMap() == cmap)
    12741341            return true;
     
    21972264    } while (doAll && ++itr != _dataSets.end());
    21982265
    2199     if (_cameraMode == IMAGE)
    2200         setCameraMode(PERSPECTIVE);
    22012266    initCamera();
    22022267    _needsRedraw = true;
     
    26722737
    26732738/**
     2739 * \brief Create a new Cutplane and associate it with the named DataSet
     2740 */
     2741bool Renderer::addCutplane(const DataSetId& id)
     2742{
     2743    DataSetHashmap::iterator itr;
     2744
     2745    bool doAll = false;
     2746
     2747    if (id.compare("all") == 0) {
     2748        itr = _dataSets.begin();
     2749    } else {
     2750        itr = _dataSets.find(id);
     2751    }
     2752    if (itr == _dataSets.end()) {
     2753        ERROR("Unknown dataset %s", id.c_str());
     2754        return false;
     2755    }
     2756
     2757    do {
     2758        DataSet *ds = itr->second;
     2759        const DataSetId& dsID = ds->getName();
     2760
     2761        if (getCutplane(dsID)) {
     2762            WARN("Replacing existing Cutplane %s", dsID.c_str());
     2763            deleteCutplane(dsID);
     2764        }
     2765
     2766        Cutplane *cutplane = new Cutplane();
     2767        _cutplanes[dsID] = cutplane;
     2768
     2769        cutplane->setDataSet(ds,
     2770                             _useCumulativeRange,
     2771                             _cumulativeScalarRange,
     2772                             _cumulativeVectorMagnitudeRange,
     2773                             _cumulativeVectorComponentRange);
     2774
     2775        _renderer->AddViewProp(cutplane->getProp());
     2776    } while (doAll && ++itr != _dataSets.end());
     2777
     2778    _needsRedraw = true;
     2779    return true;
     2780}
     2781
     2782/**
     2783 * \brief Get the Cutplane associated with a named DataSet
     2784 */
     2785Cutplane *Renderer::getCutplane(const DataSetId& id)
     2786{
     2787    CutplaneHashmap::iterator itr = _cutplanes.find(id);
     2788
     2789    if (itr == _cutplanes.end()) {
     2790#ifdef DEBUG
     2791        TRACE("Cutplane not found: %s", id.c_str());
     2792#endif
     2793        return NULL;
     2794    } else
     2795        return itr->second;
     2796}
     2797
     2798/**
     2799 * \brief Set an additional transform on the prop
     2800 */
     2801void Renderer::setCutplaneTransform(const DataSetId& id, vtkMatrix4x4 *trans)
     2802{
     2803    CutplaneHashmap::iterator itr;
     2804
     2805    bool doAll = false;
     2806
     2807    if (id.compare("all") == 0) {
     2808        itr = _cutplanes.begin();
     2809        doAll = true;
     2810    } else {
     2811        itr = _cutplanes.find(id);
     2812    }
     2813    if (itr == _cutplanes.end()) {
     2814        ERROR("Cutplane not found: %s", id.c_str());
     2815        return;
     2816    }
     2817
     2818    do {
     2819        itr->second->setTransform(trans);
     2820    } while (doAll && ++itr != _cutplanes.end());
     2821
     2822    resetAxes();
     2823    _needsRedraw = true;
     2824}
     2825
     2826/**
     2827 * \brief Set the prop orientation with a quaternion
     2828 */
     2829void Renderer::setCutplaneOrientation(const DataSetId& id, double quat[4])
     2830{
     2831    CutplaneHashmap::iterator itr;
     2832
     2833    bool doAll = false;
     2834
     2835    if (id.compare("all") == 0) {
     2836        itr = _cutplanes.begin();
     2837        doAll = true;
     2838    } else {
     2839        itr = _cutplanes.find(id);
     2840    }
     2841    if (itr == _cutplanes.end()) {
     2842        ERROR("Cutplane not found: %s", id.c_str());
     2843        return;
     2844    }
     2845
     2846    do {
     2847        itr->second->setOrientation(quat);
     2848    } while (doAll && ++itr != _cutplanes.end());
     2849
     2850    resetAxes();
     2851    _needsRedraw = true;
     2852}
     2853
     2854/**
     2855 * \brief Set the prop orientation with a rotation about an axis
     2856 */
     2857void Renderer::setCutplaneOrientation(const DataSetId& id, double angle, double axis[3])
     2858{
     2859    CutplaneHashmap::iterator itr;
     2860
     2861    bool doAll = false;
     2862
     2863    if (id.compare("all") == 0) {
     2864        itr = _cutplanes.begin();
     2865        doAll = true;
     2866    } else {
     2867        itr = _cutplanes.find(id);
     2868    }
     2869    if (itr == _cutplanes.end()) {
     2870        ERROR("Cutplane not found: %s", id.c_str());
     2871        return;
     2872    }
     2873
     2874    do {
     2875        itr->second->setOrientation(angle, axis);
     2876    } while (doAll && ++itr != _cutplanes.end());
     2877
     2878    resetAxes();
     2879    _needsRedraw = true;
     2880}
     2881
     2882/**
     2883 * \brief Set the prop position in world coords
     2884 */
     2885void Renderer::setCutplanePosition(const DataSetId& id, double pos[3])
     2886{
     2887    CutplaneHashmap::iterator itr;
     2888
     2889    bool doAll = false;
     2890
     2891    if (id.compare("all") == 0) {
     2892        itr = _cutplanes.begin();
     2893        doAll = true;
     2894    } else {
     2895        itr = _cutplanes.find(id);
     2896    }
     2897    if (itr == _cutplanes.end()) {
     2898        ERROR("Cutplane not found: %s", id.c_str());
     2899        return;
     2900    }
     2901
     2902    do {
     2903        itr->second->setPosition(pos);
     2904    } while (doAll && ++itr != _cutplanes.end());
     2905
     2906    resetAxes();
     2907    _needsRedraw = true;
     2908}
     2909
     2910/**
     2911 * \brief Set the prop scaling
     2912 */
     2913void Renderer::setCutplaneScale(const DataSetId& id, double scale[3])
     2914{
     2915    CutplaneHashmap::iterator itr;
     2916
     2917    bool doAll = false;
     2918
     2919    if (id.compare("all") == 0) {
     2920        itr = _cutplanes.begin();
     2921        doAll = true;
     2922    } else {
     2923        itr = _cutplanes.find(id);
     2924    }
     2925    if (itr == _cutplanes.end()) {
     2926        ERROR("Cutplane not found: %s", id.c_str());
     2927        return;
     2928    }
     2929
     2930    do {
     2931        itr->second->setScale(scale);
     2932    } while (doAll && ++itr != _cutplanes.end());
     2933
     2934    resetAxes();
     2935    _needsRedraw = true;
     2936}
     2937
     2938/**
     2939 * \brief Set the volume slice used for mapping volumetric data
     2940 */
     2941void Renderer::setCutplaneVolumeSlice(const DataSetId& id, Cutplane::Axis axis, double ratio)
     2942{
     2943    CutplaneHashmap::iterator itr;
     2944
     2945    bool doAll = false;
     2946
     2947    if (id.compare("all") == 0) {
     2948        itr = _cutplanes.begin();
     2949        doAll = true;
     2950    } else {
     2951        itr = _cutplanes.find(id);
     2952    }
     2953
     2954    if (itr == _cutplanes.end()) {
     2955        ERROR("Cutplane not found: %s", id.c_str());
     2956        return;
     2957    }
     2958
     2959    do {
     2960        itr->second->selectVolumeSlice(axis, ratio);
     2961     } while (doAll && ++itr != _cutplanes.end());
     2962
     2963    _renderer->ResetCameraClippingRange();
     2964    _needsRedraw = true;
     2965}
     2966
     2967/**
     2968 * \brief Associate an existing named color map with a Cutplane for the given DataSet
     2969 */
     2970void Renderer::setCutplaneColorMap(const DataSetId& id, const ColorMapId& colorMapId)
     2971{
     2972    CutplaneHashmap::iterator itr;
     2973
     2974    bool doAll = false;
     2975
     2976    if (id.compare("all") == 0) {
     2977        itr = _cutplanes.begin();
     2978        doAll = true;
     2979    } else {
     2980        itr = _cutplanes.find(id);
     2981    }
     2982
     2983    if (itr == _cutplanes.end()) {
     2984        ERROR("Cutplane not found: %s", id.c_str());
     2985        return;
     2986    }
     2987
     2988    ColorMap *cmap = getColorMap(colorMapId);
     2989    if (cmap == NULL) {
     2990        ERROR("Unknown colormap: %s", colorMapId.c_str());
     2991        return;
     2992    }
     2993
     2994    do {
     2995        TRACE("Set Cutplane color map: %s for dataset %s", colorMapId.c_str(),
     2996              itr->second->getDataSet()->getName().c_str());
     2997
     2998        itr->second->setColorMap(cmap);
     2999    } while (doAll && ++itr != _cutplanes.end());
     3000
     3001    _needsRedraw = true;
     3002}
     3003
     3004/**
     3005 * \brief Set the color mode for the specified DataSet
     3006 */
     3007void Renderer::setCutplaneColorMode(const DataSetId& id, Cutplane::ColorMode mode)
     3008{
     3009    CutplaneHashmap::iterator itr;
     3010
     3011    bool doAll = false;
     3012
     3013    if (id.compare("all") == 0) {
     3014        itr = _cutplanes.begin();
     3015        doAll = true;
     3016    } else {
     3017        itr = _cutplanes.find(id);
     3018    }
     3019    if (itr == _cutplanes.end()) {
     3020        ERROR("Cutplane not found: %s", id.c_str());
     3021        return;
     3022    }
     3023
     3024    do {
     3025        itr->second->setColorMode(mode);
     3026    } while (doAll && ++itr != _cutplanes.end());
     3027
     3028    _needsRedraw = true;
     3029}
     3030
     3031/**
     3032 * \brief Set opacity of height map for the given DataSet
     3033 */
     3034void Renderer::setCutplaneOpacity(const DataSetId& id, double opacity)
     3035{
     3036    CutplaneHashmap::iterator itr;
     3037
     3038    bool doAll = false;
     3039
     3040    if (id.compare("all") == 0) {
     3041        itr = _cutplanes.begin();
     3042        doAll = true;
     3043    } else {
     3044        itr = _cutplanes.find(id);
     3045    }
     3046    if (itr == _cutplanes.end()) {
     3047        ERROR("Cutplane not found: %s", id.c_str());
     3048        return;
     3049    }
     3050
     3051    do {
     3052        itr->second->setOpacity(opacity);
     3053    } while (doAll && ++itr != _cutplanes.end());
     3054
     3055    _needsRedraw = true;
     3056}
     3057
     3058/**
     3059 * \brief Turn on/off rendering height map for the given DataSet
     3060 */
     3061void Renderer::setCutplaneVisibility(const DataSetId& id, bool state)
     3062{
     3063    CutplaneHashmap::iterator itr;
     3064
     3065    bool doAll = false;
     3066
     3067    if (id.compare("all") == 0) {
     3068        itr = _cutplanes.begin();
     3069        doAll = true;
     3070    } else {
     3071        itr = _cutplanes.find(id);
     3072    }
     3073    if (itr == _cutplanes.end()) {
     3074        ERROR("Cutplane not found: %s", id.c_str());
     3075        return;
     3076    }
     3077
     3078    do {
     3079        itr->second->setVisibility(state);
     3080    } while (doAll && ++itr != _cutplanes.end());
     3081
     3082    _needsRedraw = true;
     3083}
     3084
     3085/**
     3086 * \brief Set wireframe rendering for the specified DataSet
     3087 */
     3088void Renderer::setCutplaneWireframe(const DataSetId& id, bool state)
     3089{
     3090    CutplaneHashmap::iterator itr;
     3091
     3092    bool doAll = false;
     3093
     3094    if (id.compare("all") == 0) {
     3095        itr = _cutplanes.begin();
     3096        doAll = true;
     3097    } else {
     3098        itr = _cutplanes.find(id);
     3099    }
     3100    if (itr == _cutplanes.end()) {
     3101        ERROR("Cutplane not found: %s", id.c_str());
     3102        return;
     3103    }
     3104
     3105    do {
     3106        itr->second->setWireframe(state);
     3107    } while (doAll && ++itr != _cutplanes.end());
     3108
     3109    _needsRedraw = true;
     3110}
     3111
     3112/**
     3113 * \brief Turn on/off rendering height map mesh edges for the given DataSet
     3114 */
     3115void Renderer::setCutplaneEdgeVisibility(const DataSetId& id, bool state)
     3116{
     3117    CutplaneHashmap::iterator itr;
     3118
     3119    bool doAll = false;
     3120
     3121    if (id.compare("all") == 0) {
     3122        itr = _cutplanes.begin();
     3123        doAll = true;
     3124    } else {
     3125        itr = _cutplanes.find(id);
     3126    }
     3127    if (itr == _cutplanes.end()) {
     3128        ERROR("Cutplane not found: %s", id.c_str());
     3129        return;
     3130    }
     3131
     3132    do {
     3133        itr->second->setEdgeVisibility(state);
     3134    } while (doAll && ++itr != _cutplanes.end());
     3135
     3136    _needsRedraw = true;
     3137}
     3138
     3139/**
     3140 * \brief Set the RGB height map mesh edge color for the specified DataSet
     3141 */
     3142void Renderer::setCutplaneEdgeColor(const DataSetId& id, float color[3])
     3143{
     3144    CutplaneHashmap::iterator itr;
     3145
     3146    bool doAll = false;
     3147
     3148    if (id.compare("all") == 0) {
     3149        itr = _cutplanes.begin();
     3150        doAll = true;
     3151    } else {
     3152        itr = _cutplanes.find(id);
     3153    }
     3154    if (itr == _cutplanes.end()) {
     3155        ERROR("Cutplane not found: %s", id.c_str());
     3156        return;
     3157    }
     3158
     3159    do {
     3160        itr->second->setEdgeColor(color);
     3161    } while (doAll && ++itr != _cutplanes.end());
     3162
     3163    _needsRedraw = true;
     3164}
     3165
     3166/**
     3167 * \brief Set the height map mesh edge width for the specified DataSet (may be a no-op)
     3168 *
     3169 * If the OpenGL implementation/hardware does not support wide lines,
     3170 * this function may not have an effect.
     3171 */
     3172void Renderer::setCutplaneEdgeWidth(const DataSetId& id, float edgeWidth)
     3173{
     3174    CutplaneHashmap::iterator itr;
     3175
     3176    bool doAll = false;
     3177
     3178    if (id.compare("all") == 0) {
     3179        itr = _cutplanes.begin();
     3180        doAll = true;
     3181    } else {
     3182        itr = _cutplanes.find(id);
     3183    }
     3184    if (itr == _cutplanes.end()) {
     3185        ERROR("Cutplane not found: %s", id.c_str());
     3186        return;
     3187    }
     3188
     3189    do {
     3190        itr->second->setEdgeWidth(edgeWidth);
     3191    } while (doAll && ++itr != _cutplanes.end());
     3192
     3193    _needsRedraw = true;
     3194}
     3195
     3196/**
     3197 * \brief Turn height map lighting on/off for the specified DataSet
     3198 */
     3199void Renderer::setCutplaneLighting(const DataSetId& id, bool state)
     3200{
     3201    CutplaneHashmap::iterator itr;
     3202
     3203    bool doAll = false;
     3204
     3205    if (id.compare("all") == 0) {
     3206        itr = _cutplanes.begin();
     3207        doAll = true;
     3208    } else {
     3209        itr = _cutplanes.find(id);
     3210    }
     3211    if (itr == _cutplanes.end()) {
     3212        ERROR("Cutplane not found: %s", id.c_str());
     3213        return;
     3214    }
     3215
     3216    do {
     3217        itr->second->setLighting(state);
     3218    } while (doAll && ++itr != _cutplanes.end());
     3219    _needsRedraw = true;
     3220}
     3221
     3222/**
    26743223 * \brief Create a new Glyphs and associate it with the named DataSet
    26753224 */
     
    27173266    } while (doAll && ++itr != _dataSets.end());
    27183267
    2719     if (_cameraMode == IMAGE)
    2720         setCameraMode(PERSPECTIVE);
    27213268    initCamera();
    27223269
     
    33223869    } while (doAll && ++itr != _dataSets.end());
    33233870
    3324     if (_cameraMode == IMAGE)
    3325         setCameraMode(PERSPECTIVE);
    33263871    initCamera();
    33273872
     
    33763921    } while (doAll && ++itr != _dataSets.end());
    33773922
    3378     if (_cameraMode == IMAGE)
    3379         setCameraMode(PERSPECTIVE);
    33803923    initCamera();
    33813924
     
    35614104    }
    35624105
     4106    bool initCam = false;
    35634107    do {
    35644108        itr->second->selectVolumeSlice(axis, ratio);
     4109        if (itr->second->getHeightScale() > 0.0)
     4110            initCam = true;
    35654111     } while (doAll && ++itr != _heightMaps.end());
    35664112
    3567     initCamera();
     4113    if (initCam)
     4114        initCamera();
     4115    else
     4116        _renderer->ResetCameraClippingRange();
    35684117    _needsRedraw = true;
    35694118}
     
    40324581    } while (doAll && ++itr != _dataSets.end());
    40334582
    4034     if (_cameraMode == IMAGE)
    4035         setCameraMode(PERSPECTIVE);
    40364583    initCamera();
    40374584    _needsRedraw = true;
     
    42204767     } while (doAll && ++itr != _lics.end());
    42214768
    4222     initCamera();
     4769    _renderer->ResetCameraClippingRange();
    42234770    _needsRedraw = true;
    42244771}
     
    44625009    } while (doAll && ++itr != _dataSets.end());
    44635010
    4464     if (_cameraMode == IMAGE)
    4465         setCameraMode(PERSPECTIVE);
    44665011    initCamera();
    44675012    _needsRedraw = true;
     
    49715516    } while (doAll && ++itr != _dataSets.end());
    49725517
    4973     if (_cameraMode == IMAGE)
    4974         setCameraMode(PERSPECTIVE);
    49755518    initCamera();
    49765519    _needsRedraw = true;
     
    60736616
    60746617/**
     6618 * \brief Set the streamlines seed to points of the streamlines DataSet
     6619 */
     6620void Renderer::setStreamlinesSeedToMeshPoints(const DataSetId& id)
     6621{
     6622    StreamlinesHashmap::iterator itr;
     6623
     6624    bool doAll = false;
     6625
     6626    if (id.compare("all") == 0) {
     6627        itr = _streamlines.begin();
     6628        doAll = true;
     6629    } else {
     6630        itr = _streamlines.find(id);
     6631    }
     6632    if (itr == _streamlines.end()) {
     6633        ERROR("Streamlines not found: %s", id.c_str());
     6634        return;
     6635    }
     6636
     6637    do {
     6638        itr->second->setSeedToMeshPoints();
     6639    } while (doAll && ++itr != _streamlines.end());
     6640
     6641    _needsRedraw = true;
     6642}
     6643
     6644/**
     6645 * \brief Set the streamlines seed to points distributed randomly inside
     6646 * cells of the streamlines DataSet
     6647 */
     6648void Renderer::setStreamlinesSeedToFilledMesh(const DataSetId& id, int numPoints)
     6649{
     6650    StreamlinesHashmap::iterator itr;
     6651
     6652    bool doAll = false;
     6653
     6654    if (id.compare("all") == 0) {
     6655        itr = _streamlines.begin();
     6656        doAll = true;
     6657    } else {
     6658        itr = _streamlines.find(id);
     6659    }
     6660    if (itr == _streamlines.end()) {
     6661        ERROR("Streamlines not found: %s", id.c_str());
     6662        return;
     6663    }
     6664
     6665    do {
     6666        itr->second->setSeedToFilledMesh(numPoints);
     6667    } while (doAll && ++itr != _streamlines.end());
     6668
     6669    _needsRedraw = true;
     6670}
     6671
     6672/**
     6673 * \brief Set the streamlines seed to points of a DataSet
     6674 *
     6675 * \param[in] id DataSet identifier
     6676 * \param[in] data Bytes of VTK DataSet file
     6677 * \param[in] nbytes Length of data array
     6678 *
     6679 * \return boolean indicating success or failure
     6680 */
     6681bool Renderer::setStreamlinesSeedToMeshPoints(const DataSetId& id,
     6682                                              char *data, size_t nbytes)
     6683{
     6684    vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New();
     6685    vtkSmartPointer<vtkCharArray> dataSetString = vtkSmartPointer<vtkCharArray>::New();
     6686
     6687    dataSetString->SetArray(data, nbytes, 1);
     6688    reader->SetInputArray(dataSetString);
     6689    reader->ReadFromInputStringOn();
     6690    reader->Update();
     6691
     6692    vtkSmartPointer<vtkDataSet> dataSet = reader->GetOutput();
     6693    if (dataSet == NULL) {
     6694        return false;
     6695    }
     6696    dataSet->SetPipelineInformation(NULL);
     6697
     6698    StreamlinesHashmap::iterator itr;
     6699
     6700    bool doAll = false;
     6701
     6702    if (id.compare("all") == 0) {
     6703        itr = _streamlines.begin();
     6704        doAll = true;
     6705    } else {
     6706        itr = _streamlines.find(id);
     6707    }
     6708    if (itr == _streamlines.end()) {
     6709        ERROR("Streamlines not found: %s", id.c_str());
     6710        return false;
     6711    }
     6712
     6713    do {
     6714        itr->second->setSeedToMeshPoints(dataSet);
     6715    } while (doAll && ++itr != _streamlines.end());
     6716
     6717    _needsRedraw = true;
     6718    return true;
     6719}
     6720
     6721/**
    60756722 * \brief Set the streamlines seed to points distributed randomly inside
    60766723 * cells of DataSet
    6077  */
    6078 void Renderer::setStreamlinesSeedToRandomPoints(const DataSetId& id, int numPoints)
    6079 {
     6724 *
     6725 * \param[in] id DataSet identifier
     6726 * \param[in] data Bytes of VTK DataSet file
     6727 * \param[in] nbytes Length of data array
     6728 * \param[in] numPoints Number of random seed points to generate
     6729 *
     6730 * \return boolean indicating success or failure
     6731 */
     6732bool Renderer::setStreamlinesSeedToFilledMesh(const DataSetId& id,
     6733                                              char *data, size_t nbytes,
     6734                                              int numPoints)
     6735{
     6736    vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New();
     6737    vtkSmartPointer<vtkCharArray> dataSetString = vtkSmartPointer<vtkCharArray>::New();
     6738
     6739    dataSetString->SetArray(data, nbytes, 1);
     6740    reader->SetInputArray(dataSetString);
     6741    reader->ReadFromInputStringOn();
     6742    reader->Update();
     6743
     6744    vtkSmartPointer<vtkDataSet> dataSet = reader->GetOutput();
     6745    if (dataSet == NULL) {
     6746        return false;
     6747    }
     6748    dataSet->SetPipelineInformation(NULL);
     6749
    60806750    StreamlinesHashmap::iterator itr;
    60816751
     
    60906760    if (itr == _streamlines.end()) {
    60916761        ERROR("Streamlines not found: %s", id.c_str());
    6092         return;
    6093     }
    6094 
    6095     do {
    6096         itr->second->setSeedToRandomPoints(numPoints);
     6762        return false;
     6763    }
     6764
     6765    do {
     6766        itr->second->setSeedToFilledMesh(dataSet, numPoints);
    60976767    } while (doAll && ++itr != _streamlines.end());
    60986768
    60996769    _needsRedraw = true;
     6770    return true;
    61006771}
    61016772
     
    66817352    } while (doAll && ++itr != _dataSets.end());
    66827353
    6683     if (_cameraMode == IMAGE)
    6684         setCameraMode(PERSPECTIVE);
    66857354    initCamera();
    66867355    _needsRedraw = true;
     
    74168085            _cameraOrientation[3] = 0.0;
    74178086        }
    7418         setViewAngle(_windowHeight);
     8087        //setViewAngle(_windowHeight);
    74198088        double bounds[6];
    74208089        collectBounds(bounds, false);
     
    79528621            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
    79538622    }
     8623    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     8624             itr != _cutplanes.end(); ++itr) {
     8625        if ((!onlyVisible || itr->second->getVisibility()) &&
     8626            itr->second->getProp() != NULL)
     8627            mergeBounds(bounds, bounds, itr->second->getProp()->GetBounds());
     8628    }
    79548629    for (GlyphsHashmap::iterator itr = _glyphs.begin();
    79558630             itr != _glyphs.end(); ++itr) {
     
    80488723    for (Contour3DHashmap::iterator itr = _contour3Ds.begin();
    80498724         itr != _contour3Ds.end(); ++itr) {
     8725        itr->second->updateRanges(_useCumulativeRange,
     8726                                  _cumulativeScalarRange,
     8727                                  _cumulativeVectorMagnitudeRange,
     8728                                  _cumulativeVectorComponentRange);
     8729    }
     8730    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     8731         itr != _cutplanes.end(); ++itr) {
    80508732        itr->second->updateRanges(_useCumulativeRange,
    80518733                                  _cumulativeScalarRange,
     
    83839065    if (id.compare("all") == 0 || getContour3D(id) != NULL)
    83849066        setContour3DOpacity(id, opacity);
     9067    if (id.compare("all") == 0 || getCutplane(id) != NULL)
     9068        setCutplaneOpacity(id, opacity);
    83859069    if (id.compare("all") == 0 || getGlyphs(id) != NULL)
    83869070        setGlyphsOpacity(id, opacity);
     
    84319115    if (id.compare("all") == 0 || getContour3D(id) != NULL)
    84329116        setContour3DVisibility(id, state);
     9117   if (id.compare("all") == 0 || getCutplane(id) != NULL)
     9118        setCutplaneVisibility(id, state);
    84339119    if (id.compare("all") == 0 || getGlyphs(id) != NULL)
    84349120        setGlyphsVisibility(id, state);
     
    85379223            }
    85389224        } else {
    8539             if (ratio > 0.0) {
     9225            if (ratio < 1.0) {
    85409226                if (_userClipPlanes[1] == NULL) {
    85419227                    _userClipPlanes[1] = vtkSmartPointer<vtkPlane>::New();
     
    85609246            }
    85619247        } else {
    8562             if (ratio > 0.0) {
     9248            if (ratio < 1.0) {
    85639249                if (_userClipPlanes[3] == NULL) {
    85649250                    _userClipPlanes[3] = vtkSmartPointer<vtkPlane>::New();
     
    85839269            }
    85849270        } else {
    8585             if (ratio > 0.0) {
     9271            if (ratio < 1.0) {
    85869272                if (_userClipPlanes[5] == NULL) {
    85879273                    _userClipPlanes[5] = vtkSmartPointer<vtkPlane>::New();
     
    86399325        itr->second->setClippingPlanes(_activeClipPlanes);
    86409326    }
     9327    for (CutplaneHashmap::iterator itr = _cutplanes.begin();
     9328         itr != _cutplanes.end(); ++itr) {
     9329        itr->second->setClippingPlanes(_activeClipPlanes);
     9330    }
    86419331    for (GlyphsHashmap::iterator itr = _glyphs.begin();
    86429332         itr != _glyphs.end(); ++itr) {
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2542 r2550  
    2929#include "RpContour2D.h"
    3030#include "RpContour3D.h"
     31#include "RpCutplane.h"
    3132#include "RpGlyphs.h"
    3233#include "RpHeightMap.h"
     
    101102    typedef std::tr1::unordered_map<DataSetId, Contour2D *> Contour2DHashmap;
    102103    typedef std::tr1::unordered_map<DataSetId, Contour3D *> Contour3DHashmap;
     104    typedef std::tr1::unordered_map<DataSetId, Cutplane *> CutplaneHashmap;
    103105    typedef std::tr1::unordered_map<DataSetId, Glyphs *> GlyphsHashmap;
    104106    typedef std::tr1::unordered_map<DataSetId, HeightMap *> HeightMapHashmap;
     
    164166    void setViewAngle(int height);
    165167
     168    vtkCamera *getVtkCamera()
     169    {
     170        if (_renderer != NULL)
     171            return _renderer->GetActiveCamera();
     172        else
     173            return NULL;
     174    }
     175
    166176    void setCameraMode(CameraMode mode);
    167177
     
    333343    void setContour3DColorMap(const DataSetId& id, const ColorMapId& colorMapId);
    334344
     345    // Cutplanes
     346
     347    bool addCutplane(const DataSetId& id);
     348   
     349    void deleteCutplane(const DataSetId& id);
     350
     351    Cutplane *getCutplane(const DataSetId& id);
     352
     353    void setCutplaneTransform(const DataSetId& id, vtkMatrix4x4 *trans);
     354
     355    void setCutplaneOrientation(const DataSetId& id, double quat[4]);
     356
     357    void setCutplaneOrientation(const DataSetId& id, double angle, double axis[3]);
     358
     359    void setCutplanePosition(const DataSetId& id, double pos[3]);
     360
     361    void setCutplaneScale(const DataSetId& id, double scale[3]);
     362
     363    void setCutplaneEdgeVisibility(const DataSetId& id, bool state);
     364
     365    void setCutplaneEdgeColor(const DataSetId& id, float color[3]);
     366
     367    void setCutplaneEdgeWidth(const DataSetId& id, float edgeWidth);
     368
     369    void setCutplaneLighting(const DataSetId& id, bool state);
     370
     371    void setCutplaneOpacity(const DataSetId& id, double opacity);
     372
     373    void setCutplaneVisibility(const DataSetId& id, bool state);
     374
     375    void setCutplaneWireframe(const DataSetId& id, bool state);
     376
     377    void setCutplaneVolumeSlice(const DataSetId& id, Cutplane::Axis axis, double ratio);
     378
     379    void setCutplaneColorMap(const DataSetId& id, const ColorMapId& colorMapId);
     380
     381    void setCutplaneColorMode(const DataSetId& id, Cutplane::ColorMode mode);
     382
    335383    // Glyphs
    336384
     
    611659    void setStreamlinesVisibility(const DataSetId& id, bool state);
    612660
    613     void setStreamlinesSeedToRandomPoints(const DataSetId& id, int numPoints);
     661    void setStreamlinesSeedToMeshPoints(const DataSetId& id);
     662
     663    void setStreamlinesSeedToFilledMesh(const DataSetId& id, int numPoints);
     664
     665    bool setStreamlinesSeedToMeshPoints(const DataSetId& id,
     666                                        char *data, size_t nbytes);
     667
     668    bool setStreamlinesSeedToFilledMesh(const DataSetId& id,
     669                                        char *data, size_t nbytes,
     670                                        int numPoints);
    614671
    615672    void setStreamlinesSeedToRake(const DataSetId& id,
     
    745802    Contour2DHashmap _contour2Ds;
    746803    Contour3DHashmap _contour3Ds;
     804    CutplaneHashmap _cutplanes;
    747805    GlyphsHashmap _glyphs;
    748806    HeightMapHashmap _heightMaps;
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2542 r2550  
    2121#include "RpVtkRendererCmd.h"
    2222#include "RpVtkRenderServer.h"
     23#include "RpVtkRenderer.h"
    2324#include "PPMWriter.h"
    2425#include "TGAWriter.h"
    25 #ifdef USE_THREADS
    26 #include "ResponseQueue.h"
    27 #endif
    2826
    2927using namespace Rappture::VtkVis;
    30 
    31 static int lastCmdStatus;
    32 
    33 #ifdef USE_THREADS
    34 static void
    35 QueueResponse(ClientData clientData, const void *bytes, size_t len,
    36               Response::AllocationType allocType)
    37 {
    38     ResponseQueue *queue = (ResponseQueue *)clientData;
    39 
    40     Response *response;
    41 
    42     response = new Response(Response::DATA);
    43     response->setMessage((unsigned char *)bytes, len, allocType);
    44     queue->enqueue(response);
    45 }
    46 #else
    4728
    4829static ssize_t
     
    6243}
    6344
    64 #endif  /*USE_THREADS*/
     45static size_t
     46SocketRead(void *bytes, size_t len)
     47{
     48#ifdef notdef
     49    size_t ofs = 0;
     50    ssize_t bytesRead = 0;
     51    while ((bytesRead = read(g_fdIn, bytes + ofs, len - ofs)) > 0) {
     52        ofs += bytesRead;
     53        if (ofs == len)
     54            break;
     55    }
     56    TRACE("bytesRead: %lu", ofs);
     57    return ofs;
     58#else
     59    size_t bytesRead = fread(bytes, 1, len, g_fIn);
     60    TRACE("bytesRead: %lu", bytesRead);
     61    return bytesRead;
     62#endif
     63}
    6564
    6665static int
     
    6968    int result;
    7069
    71     TRACE("command: '%s'", Tcl_DStringValue(dsPtr));
    72     lastCmdStatus = TCL_OK;
    73     result = Tcl_EvalEx(interp, Tcl_DStringValue(dsPtr),
    74                         Tcl_DStringLength(dsPtr),
    75                         TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL);
     70    result = Tcl_Eval(interp, Tcl_DStringValue(dsPtr));
    7671    Tcl_DStringSetLength(dsPtr, 0);
    77     if (lastCmdStatus == TCL_BREAK) {
    78         return TCL_BREAK;
    79     }
    80     lastCmdStatus = result;
     72
    8173    return result;
    8274}
     
    203195{
    204196    const char *title = Tcl_GetString(objv[3]);
     197    if (strlen(title) > 30) {
     198        Tcl_AppendResult(interp, "axis name \"", title,
     199                         "\" is too long", (char*)NULL);
     200        return TCL_ERROR;
     201    }
    205202    const char *string = Tcl_GetString(objv[2]);
    206203    char c = string[0];
     
    270267{
    271268    const char *units = Tcl_GetString(objv[3]);
     269    if (strlen(units) > 10) {
     270        Tcl_AppendResult(interp, "axis units name \"", units,
     271                         "\" is too long", (char*)NULL);
     272        return TCL_ERROR;
     273    }
    272274    const char *string = Tcl_GetString(objv[2]);
    273275    char c = string[0];
     
    277279        g_renderer->setAxisUnits(Renderer::Y_AXIS, units);
    278280    } else if ((c == 'z') && (strcmp(string, "z") == 0)) {
     281        g_renderer->setAxisUnits(Renderer::Z_AXIS, units);
     282    } else if ((c == 'a') && (strcmp(string, "all") == 0)) {
     283        g_renderer->setAxisUnits(Renderer::X_AXIS, units);
     284        g_renderer->setAxisUnits(Renderer::Y_AXIS, units);
    279285        g_renderer->setAxisUnits(Renderer::Z_AXIS, units);
    280286    } else {
     
    374380             pos[0], pos[1], pos[2], focalPt[0], focalPt[1], focalPt[2], viewUp[0], viewUp[1], viewUp[2]);
    375381
    376 #ifdef USE_THREADS
    377     QueueResponse(clientData, buf, strlen(buf), Response::VOLATILE);
    378 #else
    379382    ssize_t bytesWritten = SocketWrite(buf, strlen(buf));
     383
    380384    if (bytesWritten < 0) {
    381385        return TCL_ERROR;
    382386    }
    383 #endif
    384387    return TCL_OK;
    385388}
     
    12661269
    12671270static int
     1271CutplaneAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1272              Tcl_Obj *const *objv)
     1273{
     1274    if (objc == 3) {
     1275        const char *name = Tcl_GetString(objv[2]);
     1276        if (!g_renderer->addCutplane(name)) {
     1277            Tcl_AppendResult(interp, "Failed to create cutplane", (char*)NULL);
     1278            return TCL_ERROR;
     1279        }
     1280    } else {
     1281        if (!g_renderer->addCutplane("all")) {
     1282            Tcl_AppendResult(interp, "Failed to create cutplane for one or more data sets", (char*)NULL);
     1283            return TCL_ERROR;
     1284        }
     1285    }
     1286    return TCL_OK;
     1287}
     1288
     1289static int
     1290CutplaneColorMapOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1291                   Tcl_Obj *const *objv)
     1292{
     1293    const char *colorMapName = Tcl_GetString(objv[2]);
     1294    if (objc == 4) {
     1295        const char *dataSetName = Tcl_GetString(objv[3]);
     1296        g_renderer->setCutplaneColorMap(dataSetName, colorMapName);
     1297    } else {
     1298        g_renderer->setCutplaneColorMap("all", colorMapName);
     1299    }
     1300    return TCL_OK;
     1301}
     1302
     1303static int
     1304CutplaneColorModeOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1305                    Tcl_Obj *const *objv)
     1306{
     1307    Cutplane::ColorMode mode;
     1308    const char *str = Tcl_GetString(objv[2]);
     1309    if (str[0] == 's' && strcmp(str, "scalar") == 0) {
     1310        mode = Cutplane::COLOR_BY_SCALAR;
     1311    } else if (str[0] == 'v' && strcmp(str, "vmag") == 0) {
     1312        mode = Cutplane::COLOR_BY_VECTOR_MAGNITUDE;
     1313    } else if (str[0] == 'v' && strcmp(str, "vx") == 0) {
     1314        mode = Cutplane::COLOR_BY_VECTOR_X;
     1315    } else if (str[0] == 'v' && strcmp(str, "vy") == 0) {
     1316        mode = Cutplane::COLOR_BY_VECTOR_Y;
     1317    } else if (str[0] == 'v' && strcmp(str, "vz") == 0) {
     1318        mode = Cutplane::COLOR_BY_VECTOR_Z;
     1319    } else {
     1320        Tcl_AppendResult(interp, "bad color mode option \"", str,
     1321                         "\": should be one of: 'scalar', 'vmag', 'vx', 'vy', 'vz'", (char*)NULL);
     1322        return TCL_ERROR;
     1323    }
     1324    if (objc == 4) {
     1325        const char *name = Tcl_GetString(objv[3]);
     1326        g_renderer->setCutplaneColorMode(name, mode);
     1327    } else {
     1328        g_renderer->setCutplaneColorMode("all", mode);
     1329    }
     1330    return TCL_OK;
     1331}
     1332
     1333static int
     1334CutplaneDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1335                 Tcl_Obj *const *objv)
     1336{
     1337    if (objc == 3) {
     1338        const char *name = Tcl_GetString(objv[2]);
     1339        g_renderer->deleteCutplane(name);
     1340    } else {
     1341        g_renderer->deleteCutplane("all");
     1342    }
     1343    return TCL_OK;
     1344}
     1345
     1346static int
     1347CutplaneEdgeVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1348                         Tcl_Obj *const *objv)
     1349{
     1350    bool state;
     1351    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1352        return TCL_ERROR;
     1353    }
     1354    if (objc == 4) {
     1355        const char *name = Tcl_GetString(objv[3]);
     1356        g_renderer->setCutplaneEdgeVisibility(name, state);
     1357    } else {
     1358        g_renderer->setCutplaneEdgeVisibility("all", state);
     1359    }
     1360    return TCL_OK;
     1361}
     1362
     1363static int
     1364CutplaneLightingOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1365                   Tcl_Obj *const *objv)
     1366{
     1367    bool state;
     1368    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1369        return TCL_ERROR;
     1370    }
     1371    if (objc == 4) {
     1372        const char *name = Tcl_GetString(objv[3]);
     1373        g_renderer->setCutplaneLighting(name, state);
     1374    } else {
     1375        g_renderer->setCutplaneLighting("all", state);
     1376    }
     1377    return TCL_OK;
     1378}
     1379
     1380static int
     1381CutplaneLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1382                    Tcl_Obj *const *objv)
     1383{
     1384    float color[3];
     1385    if (GetFloatFromObj(interp, objv[2], &color[0]) != TCL_OK ||
     1386        GetFloatFromObj(interp, objv[3], &color[1]) != TCL_OK ||
     1387        GetFloatFromObj(interp, objv[4], &color[2]) != TCL_OK) {
     1388        return TCL_ERROR;
     1389    }
     1390    if (objc == 6) {
     1391        const char *name = Tcl_GetString(objv[5]);
     1392        g_renderer->setCutplaneEdgeColor(name, color);
     1393    } else {
     1394        g_renderer->setCutplaneEdgeColor("all", color);
     1395    }
     1396    return TCL_OK;
     1397}
     1398
     1399static int
     1400CutplaneLineWidthOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1401                    Tcl_Obj *const *objv)
     1402{
     1403    float width;
     1404    if (GetFloatFromObj(interp, objv[2], &width) != TCL_OK) {
     1405        return TCL_ERROR;
     1406    }
     1407    if (objc == 4) {
     1408        const char *name = Tcl_GetString(objv[3]);
     1409        g_renderer->setCutplaneEdgeWidth(name, width);
     1410    } else {
     1411        g_renderer->setCutplaneEdgeWidth("all", width);
     1412    }
     1413    return TCL_OK;
     1414}
     1415
     1416static int
     1417CutplaneOpacityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1418                  Tcl_Obj *const *objv)
     1419{
     1420    double opacity;
     1421    if (Tcl_GetDoubleFromObj(interp, objv[2], &opacity) != TCL_OK) {
     1422        return TCL_ERROR;
     1423    }
     1424    if (objc == 4) {
     1425        const char *name = Tcl_GetString(objv[3]);
     1426        g_renderer->setCutplaneOpacity(name, opacity);
     1427    } else {
     1428        g_renderer->setCutplaneOpacity("all", opacity);
     1429    }
     1430    return TCL_OK;
     1431}
     1432
     1433static int
     1434CutplaneOrientOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1435                 Tcl_Obj *const *objv)
     1436{
     1437    double quat[4];
     1438    if (Tcl_GetDoubleFromObj(interp, objv[2], &quat[0]) != TCL_OK ||
     1439        Tcl_GetDoubleFromObj(interp, objv[3], &quat[1]) != TCL_OK ||
     1440        Tcl_GetDoubleFromObj(interp, objv[4], &quat[2]) != TCL_OK ||
     1441        Tcl_GetDoubleFromObj(interp, objv[5], &quat[3]) != TCL_OK) {
     1442        return TCL_ERROR;
     1443    }
     1444    if (objc == 7) {
     1445        const char *name = Tcl_GetString(objv[6]);
     1446        g_renderer->setCutplaneOrientation(name, quat);
     1447    } else {
     1448        g_renderer->setCutplaneOrientation("all", quat);
     1449    }
     1450    return TCL_OK;
     1451}
     1452
     1453static int
     1454CutplanePositionOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1455                   Tcl_Obj *const *objv)
     1456{
     1457    double pos[3];
     1458    if (Tcl_GetDoubleFromObj(interp, objv[2], &pos[0]) != TCL_OK ||
     1459        Tcl_GetDoubleFromObj(interp, objv[3], &pos[1]) != TCL_OK ||
     1460        Tcl_GetDoubleFromObj(interp, objv[4], &pos[2]) != TCL_OK) {
     1461        return TCL_ERROR;
     1462    }
     1463    if (objc == 6) {
     1464        const char *name = Tcl_GetString(objv[5]);
     1465        g_renderer->setCutplanePosition(name, pos);
     1466    } else {
     1467        g_renderer->setCutplanePosition("all", pos);
     1468    }
     1469    return TCL_OK;
     1470}
     1471
     1472static int
     1473CutplaneScaleOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1474                Tcl_Obj *const *objv)
     1475{
     1476    double scale[3];
     1477    if (Tcl_GetDoubleFromObj(interp, objv[2], &scale[0]) != TCL_OK ||
     1478        Tcl_GetDoubleFromObj(interp, objv[3], &scale[1]) != TCL_OK ||
     1479        Tcl_GetDoubleFromObj(interp, objv[4], &scale[2]) != TCL_OK) {
     1480        return TCL_ERROR;
     1481    }
     1482    if (objc == 6) {
     1483        const char *name = Tcl_GetString(objv[5]);
     1484        g_renderer->setCutplaneScale(name, scale);
     1485    } else {
     1486        g_renderer->setCutplaneScale("all", scale);
     1487    }
     1488    return TCL_OK;
     1489}
     1490
     1491static int
     1492CutplaneVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1493                  Tcl_Obj *const *objv)
     1494{
     1495    bool state;
     1496    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1497        return TCL_ERROR;
     1498    }
     1499    if (objc == 4) {
     1500        const char *name = Tcl_GetString(objv[3]);
     1501        g_renderer->setCutplaneVisibility(name, state);
     1502    } else {
     1503        g_renderer->setCutplaneVisibility("all", state);
     1504    }
     1505    return TCL_OK;
     1506}
     1507
     1508static int
     1509CutplaneVolumeSliceOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1510                      Tcl_Obj *const *objv)
     1511{
     1512    double ratio;
     1513    if (Tcl_GetDoubleFromObj(interp, objv[3], &ratio) != TCL_OK) {
     1514        return TCL_ERROR;
     1515    }
     1516    const char *string = Tcl_GetString(objv[2]);
     1517    char c = string[0];
     1518    Cutplane::Axis axis;
     1519    if ((c == 'x') && (strcmp(string, "x") == 0)) {
     1520        axis = Cutplane::X_AXIS;
     1521    } else if ((c == 'y') && (strcmp(string, "y") == 0)) {
     1522        axis = Cutplane::Y_AXIS;
     1523    } else if ((c == 'z') && (strcmp(string, "z") == 0)) {
     1524        axis = Cutplane::Z_AXIS;
     1525    } else {
     1526        Tcl_AppendResult(interp, "bad axis option \"", string,
     1527                         "\": should be axisName ratio", (char*)NULL);
     1528        return TCL_ERROR;
     1529    }
     1530    if (objc == 5) {
     1531        const char *name = Tcl_GetString(objv[4]);
     1532        g_renderer->setCutplaneVolumeSlice(name, axis, ratio);
     1533    } else {
     1534        g_renderer->setCutplaneVolumeSlice("all", axis, ratio);
     1535    }
     1536    return TCL_OK;
     1537}
     1538
     1539static int
     1540CutplaneWireframeOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1541                    Tcl_Obj *const *objv)
     1542{
     1543    bool state;
     1544    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1545        return TCL_ERROR;
     1546    }
     1547    if (objc == 4) {
     1548        const char *name = Tcl_GetString(objv[3]);
     1549        g_renderer->setCutplaneWireframe(name, state);
     1550    } else {
     1551        g_renderer->setCutplaneWireframe("all", state);
     1552    }
     1553    return TCL_OK;
     1554}
     1555
     1556static Rappture::CmdSpec cutplaneOps[] = {
     1557    {"add",          1, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"},
     1558    {"colormap",     7, CutplaneColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
     1559    {"colormode",    7, CutplaneColorModeOp, 3, 4, "mode ?dataSetNme?"},
     1560    {"delete",       1, CutplaneDeleteOp, 2, 3, "?dataSetName?"},
     1561    {"edges",        1, CutplaneEdgeVisibilityOp, 3, 4, "bool ?dataSetName?"},
     1562    {"lighting",     3, CutplaneLightingOp, 3, 4, "bool ?dataSetName?"},
     1563    {"linecolor",    5, CutplaneLineColorOp, 5, 6, "r g b ?dataSetName?"},
     1564    {"linewidth",    5, CutplaneLineWidthOp, 3, 4, "width ?dataSetName?"},
     1565    {"opacity",      2, CutplaneOpacityOp, 3, 4, "value ?dataSetName?"},
     1566    {"orient",       2, CutplaneOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"},
     1567    {"pos",          1, CutplanePositionOp, 5, 6, "x y z ?dataSetName?"},
     1568    {"scale",        2, CutplaneScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     1569    {"slice",        2, CutplaneVolumeSliceOp, 4, 5, "axis ratio ?dataSetName?"},
     1570    {"visible",      1, CutplaneVisibleOp, 3, 4, "bool ?dataSetName?"},
     1571    {"wireframe",    1, CutplaneWireframeOp, 3, 4, "bool ?dataSetName?"}
     1572};
     1573static int nCutplaneOps = NumCmdSpecs(cutplaneOps);
     1574
     1575static int
     1576CutplaneCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     1577             Tcl_Obj *const *objv)
     1578{
     1579    Tcl_ObjCmdProc *proc;
     1580
     1581    proc = Rappture::GetOpFromObj(interp, nCutplaneOps, cutplaneOps,
     1582                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
     1583    if (proc == NULL) {
     1584        return TCL_ERROR;
     1585    }
     1586    return (*proc) (clientData, interp, objc, objv);
     1587}
     1588
     1589static int
    12681590DataSetActiveScalarsOp(ClientData clientData, Tcl_Interp *interp, int objc,
    12691591                       Tcl_Obj *const *objv)
     
    13341656    }
    13351657    char *data = (char *)malloc(nbytes);
    1336     size_t bytesRead = fread(data, 1, nbytes, g_fIn);
    1337     TRACE("bytesRead: %d", bytesRead);
    1338     if (bytesRead < (size_t)nbytes) {
     1658    size_t bytesRead = SocketRead(data, nbytes);
     1659    if (bytesRead < 0) {
    13391660        free(data);
    13401661        return TCL_ERROR;
     
    13771698
    13781699    char buf[256];
    1379     int length;
    1380 
    1381     length = snprintf(buf, sizeof(buf), "nv>dataset scalar pixel %d %d %g %s\n",
    1382         x, y, value, name);
    1383 
    1384 #ifdef USE_THREADS
    1385     QueueResponse(clientData, buf, length, Response::VOLATILE);
    1386 #else
    1387     ssize_t bytesWritten = SocketWrite(buf, length);
     1700    snprintf(buf, sizeof(buf), "nv>dataset scalar pixel %d %d %g %s\n", x, y, value, name);
     1701
     1702    ssize_t bytesWritten = SocketWrite(buf, strlen(buf));
    13881703
    13891704    if (bytesWritten < 0) {
    13901705        return TCL_ERROR;
    13911706    }
    1392 #endif
    13931707    return TCL_OK;
    13941708}
     
    14121726
    14131727    char buf[256];
    1414     int length;
    1415 
    1416     length = snprintf(buf, sizeof(buf),
    1417         "nv>dataset scalar world %g %g %g %g %s\n", x, y, z, value, name);
    1418 
    1419 #ifdef USE_THREADS
    1420     QueueResponse(clientData, buf, length, Response::VOLATILE);
    1421 #else
    1422     ssize_t bytesWritten = SocketWrite(buf, length);
     1728    snprintf(buf, sizeof(buf), "nv>dataset scalar world %g %g %g %g %s\n", x, y, z, value, name);
     1729
     1730    ssize_t bytesWritten = SocketWrite(buf, strlen(buf));
     1731
    14231732    if (bytesWritten < 0) {
    14241733        return TCL_ERROR;
    14251734    }
    1426 #endif
    14271735    return TCL_OK;
    14281736}
     
    14651773
    14661774    char buf[256];
    1467     int length;
    1468     length = snprintf(buf, sizeof(buf),
    1469         "nv>dataset vector pixel %d %d %g %g %g %s\n", x, y, value[0],
    1470         value[1], value[2], name);
    1471 
    1472 #ifdef USE_THREADS
    1473     QueueResponse(clientData, buf, length, Response::VOLATILE);
    1474 #else
    1475     ssize_t bytesWritten = SocketWrite(buf, length);
     1775    snprintf(buf, sizeof(buf), "nv>dataset vector pixel %d %d %g %g %g %s\n", x, y,
     1776             value[0], value[1], value[2], name);
     1777
     1778    ssize_t bytesWritten = SocketWrite(buf, strlen(buf));
    14761779
    14771780    if (bytesWritten < 0) {
    14781781        return TCL_ERROR;
    14791782    }
    1480 #endif /*USE_THREADS*/
    14811783    return TCL_OK;
    14821784}
     
    15001802
    15011803    char buf[256];
    1502     int length;
    1503     length = snprintf(buf, sizeof(buf),
    1504         "nv>dataset vector world %g %g %g %g %g %g %s\n", x, y, z,
    1505         value[0], value[1], value[2], name);
    1506 #ifdef USE_THREADS
    1507     QueueResponse(clientData, buf, length, Response::VOLATILE);
    1508 #else
    1509     ssize_t bytesWritten = SocketWrite(buf, length);
     1804    snprintf(buf, sizeof(buf), "nv>dataset vector world %g %g %g %g %g %g %s\n", x, y, z,
     1805             value[0], value[1], value[2], name);
     1806
     1807    ssize_t bytesWritten = SocketWrite(buf, strlen(buf));
    15101808
    15111809    if (bytesWritten < 0) {
    15121810        return TCL_ERROR;
    15131811    }
    1514 #endif /*USE_THREADS*/
    15151812    return TCL_OK;
    15161813}
     
    15751872    oss << "}\n";
    15761873    len += 2;
    1577 #ifdef USE_THREADS
    1578     QueueResponse(clientData, oss.str().c_str(), len, Response::VOLATILE);
    1579 #else
    1580     ssize_t bytesWritten = SocketWrite(oss.str().c_str(), len);
     1874
     1875    size_t bytesWritten = SocketWrite(oss.str().c_str(), len);
    15811876
    15821877    if (bytesWritten < 0) {
    15831878        return TCL_ERROR;
    15841879    }
    1585 #endif /*USE_THREADS*/
    15861880    return TCL_OK;
    15871881}
     
    25892883static Rappture::CmdSpec heightmapOps[] = {
    25902884    {"add",          1, HeightMapAddOp, 5, 6, "oper value ?dataSetName?"},
    2591     {"colormap",     2, HeightMapColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
    2592     {"contourlist",  2, HeightMapContourListOp, 3, 4, "contourList ?dataSetName?"},
     2885    {"colormap",     3, HeightMapColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
     2886    {"contourlist",  3, HeightMapContourListOp, 3, 4, "contourList ?dataSetName?"},
    25932887    {"delete",       1, HeightMapDeleteOp, 2, 3, "?dataSetName?"},
    25942888    {"edges",        1, HeightMapEdgeVisibilityOp, 3, 4, "bool ?dataSetName?"},
     
    26042898    {"orient",       2, HeightMapOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"},
    26052899    {"pos",          1, HeightMapPositionOp, 5, 6, "x y z ?dataSetName?"},
    2606     {"scale",        1, HeightMapScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     2900    {"scale",        2, HeightMapScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     2901    {"slice",        2, HeightMapVolumeSliceOp, 4, 5, "axis ratio ?dataSetName?"},
    26072902    {"surface",      2, HeightMapContourSurfaceVisibleOp, 3, 4, "bool ?dataSetName?"},
    2608     {"visible",      2, HeightMapVisibleOp, 3, 4, "bool ?dataSetName?"},
    2609     {"volumeslice",  2, HeightMapVolumeSliceOp, 4, 5, "axis ratio ?dataSetName?"},
     2903    {"visible",      1, HeightMapVisibleOp, 3, 4, "bool ?dataSetName?"},
    26102904    {"wireframe",    1, HeightMapWireframeOp, 3, 4, "bool ?dataSetName?"}
    26112905};
     
    26242918    }
    26252919    return (*proc) (clientData, interp, objc, objv);
    2626 }
    2627 
    2628 static int
    2629 ImageFlushCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    2630              Tcl_Obj *const *objv)
    2631 {
    2632     lastCmdStatus = TCL_BREAK;
    2633     return TCL_OK;
    26342920}
    26352921
     
    26952981
    26962982#ifdef DEBUG
    2697 # ifdef RENDER_TARGA
    26982983    writeTGAFile("/tmp/legend.tga", imgData->GetPointer(0), width, height,
    26992984                 TARGA_BYTES_PER_PIXEL);
    2700 # else
    2701     writeTGAFile("/tmp/legend.tga", imgData->GetPointer(0), width, height,
    2702                  TARGA_BYTES_PER_PIXEL, true);
    2703 # endif
    27042985#else
    27052986    char cmd[256];
    27062987    snprintf(cmd, sizeof(cmd), "nv>legend {%s} {%s} %g %g",
    27072988             colorMapName, title.c_str(), range[0], range[1]);
    2708 
    2709 # ifdef USE_THREADS
    2710 #  ifdef RENDER_TARGA
    2711     ResponseQueue *queue = (ResponseQueue *)clientData;
    2712     queueTGA(queue, cmd, imgData->GetPointer(0), width, height,
    2713              TARGA_BYTES_PER_PIXEL);
    2714 #  else
    2715     ResponseQueue *queue = (ResponseQueue *)clientData;
    2716     queuePPM(queue, cmd, imgData->GetPointer(0), width, height);
    2717 #  endif
    2718 # else
    2719 #  ifdef RENDER_TARGA
     2989#ifdef RENDER_TARGA
    27202990    writeTGA(g_fdOut, cmd, imgData->GetPointer(0), width, height,
    2721              TARGA_BYTES_PER_PIXEL);
    2722 #  else
     2991                 TARGA_BYTES_PER_PIXEL);
     2992#else
    27232993    writePPM(g_fdOut, cmd, imgData->GetPointer(0), width, height);
    2724 #  endif
    2725 # endif // USE_THREADS
    2726 #endif // DEBUG
     2994#endif
     2995#endif
     2996
    27272997    return TCL_OK;
    27282998}
     
    29783248    {"orient",      2, LICOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"},
    29793249    {"pos",         1, LICPositionOp, 5, 6, "x y z ?dataSetName?"},
    2980     {"scale",       1, LICScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
    2981     {"visible",     2, LICVisibleOp, 3, 4, "bool ?dataSetName?"},
    2982     {"volumeslice", 2, LICVolumeSliceOp, 4, 5, "axis ratio ?dataSetName?"}
     3250    {"scale",       2, LICScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     3251    {"slice",       2, LICVolumeSliceOp, 4, 5, "axis ratio ?dataSetName?"},
     3252    {"visible",     1, LICVisibleOp, 3, 4, "bool ?dataSetName?"}
    29833253};
    29843254static int nLICOps = NumCmdSpecs(licOps);
     
    43864656
    43874657static int
     4658StreamlinesSeedFilledMeshOp(ClientData clientData, Tcl_Interp *interp,
     4659                            int objc, Tcl_Obj *const *objv)
     4660{
     4661    int numPoints = 0;
     4662    if (Tcl_GetIntFromObj(interp, objv[3], &numPoints) != TCL_OK ||
     4663        numPoints < 1) {
     4664        return TCL_ERROR;
     4665    }
     4666    const char *string = Tcl_GetString(objv[4]);
     4667    char c = string[0];
     4668    if ((c != 'd') || (strcmp(string, "data") != 0)) {
     4669        Tcl_AppendResult(interp, "bad streamlines seed fmesh option \"",
     4670                         string, "\": should be data", (char*)NULL);
     4671        return TCL_ERROR;
     4672    }
     4673    string = Tcl_GetString(objv[5]);
     4674    c = string[0];
     4675    if ((c != 'f') || (strcmp(string, "follows") != 0)) {
     4676        Tcl_AppendResult(interp, "bad streamlines seed fmesh option \"",
     4677                         string, "\": should be follows", (char*)NULL);
     4678        return TCL_ERROR;
     4679    }
     4680    int nbytes = 0;
     4681    if (Tcl_GetIntFromObj(interp, objv[6], &nbytes) != TCL_OK ||
     4682        nbytes < 0) {
     4683        return TCL_ERROR;
     4684    }
     4685    char *data = (char *)malloc(nbytes);
     4686    size_t bytesRead = SocketRead(data, nbytes);
     4687    if (bytesRead < 0) {
     4688        free(data);
     4689        return TCL_ERROR;
     4690    }
     4691    if (objc == 8) {
     4692        const char *name = Tcl_GetString(objv[7]);
     4693        if (!g_renderer->setStreamlinesSeedToFilledMesh(name, data, nbytes,
     4694                                                        numPoints)) {
     4695            free(data);
     4696            Tcl_AppendResult(interp, "Couldn't read mesh data or streamlines not found", (char*)NULL);
     4697            return TCL_ERROR;
     4698        }
     4699    } else {
     4700        if (!g_renderer->setStreamlinesSeedToFilledMesh("all", data, nbytes,
     4701                                                        numPoints)) {
     4702            free(data);
     4703            Tcl_AppendResult(interp, "Couldn't read mesh data or streamlines not found", (char*)NULL);
     4704            return TCL_ERROR;
     4705        }
     4706    }
     4707    free(data);
     4708    return TCL_OK;
     4709}
     4710
     4711static int
     4712StreamlinesSeedMeshPointsOp(ClientData clientData, Tcl_Interp *interp,
     4713                            int objc, Tcl_Obj *const *objv)
     4714{
     4715    const char *string = Tcl_GetString(objv[3]);
     4716    char c = string[0];
     4717    if ((c != 'd') || (strcmp(string, "data") != 0)) {
     4718        Tcl_AppendResult(interp, "bad streamlines seed fmesh option \"",
     4719                         string, "\": should be data", (char*)NULL);
     4720        return TCL_ERROR;
     4721    }
     4722    string = Tcl_GetString(objv[4]);
     4723    c = string[0];
     4724    if ((c != 'f') || (strcmp(string, "follows") != 0)) {
     4725        Tcl_AppendResult(interp, "bad streamlines seed fmesh option \"",
     4726                         string, "\": should be follows", (char*)NULL);
     4727        return TCL_ERROR;
     4728    }
     4729    int nbytes = 0;
     4730    if (Tcl_GetIntFromObj(interp, objv[5], &nbytes) != TCL_OK ||
     4731        nbytes < 0) {
     4732        return TCL_ERROR;
     4733    }
     4734    char *data = (char *)malloc(nbytes);
     4735    size_t bytesRead = SocketRead(data, nbytes);
     4736    if (bytesRead < 0) {
     4737        free(data);
     4738        return TCL_ERROR;
     4739    }
     4740    if (objc == 7) {
     4741        const char *name = Tcl_GetString(objv[6]);
     4742        if (!g_renderer->setStreamlinesSeedToMeshPoints(name, data, nbytes)) {
     4743            free(data);
     4744            Tcl_AppendResult(interp, "Couldn't read mesh data or streamlines not found", (char*)NULL);
     4745            return TCL_ERROR;
     4746        }
     4747    } else {
     4748        if (!g_renderer->setStreamlinesSeedToMeshPoints("all", data, nbytes)) {
     4749            free(data);
     4750            Tcl_AppendResult(interp, "Couldn't read mesh data or streamlines not found", (char*)NULL);
     4751            return TCL_ERROR;
     4752        }
     4753    }
     4754    free(data);
     4755    return TCL_OK;
     4756}
     4757
     4758static int
     4759StreamlinesSeedPointsOp(ClientData clientData, Tcl_Interp *interp, int objc,
     4760                        Tcl_Obj *const *objv)
     4761{
     4762    if (objc == 4) {
     4763        const char *name = Tcl_GetString(objv[3]);
     4764        g_renderer->setStreamlinesSeedToMeshPoints(name);
     4765    } else {
     4766        g_renderer->setStreamlinesSeedToMeshPoints("all");
     4767    }
     4768    return TCL_OK;
     4769}
     4770
     4771static int
    43884772StreamlinesSeedPolygonOp(ClientData clientData, Tcl_Interp *interp, int objc,
    43894773                         Tcl_Obj *const *objv)
     
    44984882    if (objc == 5) {
    44994883        const char *name = Tcl_GetString(objv[4]);
    4500         g_renderer->setStreamlinesSeedToRandomPoints(name, numPoints);
    4501     } else {
    4502         g_renderer->setStreamlinesSeedToRandomPoints("all", numPoints);
     4884        g_renderer->setStreamlinesSeedToFilledMesh(name, numPoints);
     4885    } else {
     4886        g_renderer->setStreamlinesSeedToFilledMesh("all", numPoints);
    45034887    }
    45044888    return TCL_OK;
     
    45254909    {"color",   1, StreamlinesSeedColorOp, 6, 7, "r g b ?dataSetName?"},
    45264910    {"disk",    1, StreamlinesSeedDiskOp, 12, 13, "centerX centerY centerZ normalX normalY normalZ radius innerRadius numPoints ?dataSetName?"},
    4527     {"fpoly",   1, StreamlinesSeedFilledPolygonOp, 13, 14, "centerX centerY centerZ normalX normalY normalZ angle radius numSides numPoints ?dataSetName?"},
    4528     {"polygon", 1, StreamlinesSeedPolygonOp, 12, 13, "centerX centerY centerZ normalX normalY normalZ angle radius numSides ?dataSetName?"},
     4911    {"fmesh",   2, StreamlinesSeedFilledMeshOp, 7, 8, "numPoints data follows nbytes ?dataSetName?"},
     4912    {"fpoly",   2, StreamlinesSeedFilledPolygonOp, 13, 14, "centerX centerY centerZ normalX normalY normalZ angle radius numSides numPoints ?dataSetName?"},
     4913    {"mesh",    1, StreamlinesSeedMeshPointsOp, 6, 7, "data follows nbytes ?dataSetName?"},
     4914    {"points",  3, StreamlinesSeedPointsOp, 3, 4, "?dataSetName?"},
     4915    {"polygon", 3, StreamlinesSeedPolygonOp, 12, 13, "centerX centerY centerZ normalX normalY normalZ angle radius numSides ?dataSetName?"},
    45294916    {"rake",    3, StreamlinesSeedRakeOp, 10, 11, "startX startY startZ endX endY endZ numPoints ?dataSetName?"},
    45304917    {"random",  3, StreamlinesSeedRandomOp, 4, 5, "numPoints ?dataSetName?"},
     
    45864973
    45874974static Rappture::CmdSpec streamlinesOps[] = {
    4588     {"add",       1, StreamlinesAddOp,       2, 3, "?dataSetName?"},
    4589     {"ccolor",    1, StreamlinesColorOp,     5, 6, "r g b ?dataSetName?"},
    4590     {"colormap",  7, StreamlinesColorMapOp,  3, 4, "colorMapName ?dataSetName?"},
     4975    {"add",       1, StreamlinesAddOp, 2, 3, "?dataSetName?"},
     4976    {"ccolor",    1, StreamlinesColorOp, 5, 6, "r g b ?dataSetName?"},
     4977    {"colormap",  7, StreamlinesColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
    45914978    {"colormode", 7, StreamlinesColorModeOp, 3, 4, "mode ?dataSetNme?"},
    4592     {"delete",    1, StreamlinesDeleteOp,    2, 3, "?dataSetName?"},
     4979    {"delete",    1, StreamlinesDeleteOp, 2, 3, "?dataSetName?"},
    45934980    {"edges",     1, StreamlinesEdgeVisibilityOp, 3, 4, "bool ?dataSetName?"},
    4594     {"length",    2, StreamlinesLengthOp,    3, 4, "length ?dataSetName?"},
    4595     {"lighting",  3, StreamlinesLightingOp,  3, 4, "bool ?dataSetName?"},
     4981    {"length",    2, StreamlinesLengthOp, 3, 4, "length ?dataSetName?"},
     4982    {"lighting",  3, StreamlinesLightingOp, 3, 4, "bool ?dataSetName?"},
    45964983    {"linecolor", 5, StreamlinesLineColorOp, 5, 6, "r g b ?dataSetName?"},
    4597     {"lines",     5, StreamlinesLinesOp,     2, 3, "?dataSetName?"},
     4984    {"lines",     5, StreamlinesLinesOp, 2, 3, "?dataSetName?"},
    45984985    {"linewidth", 5, StreamlinesLineWidthOp, 3, 4, "width ?dataSetName?"},
    4599     {"opacity",   2, StreamlinesOpacityOp,   3, 4, "val ?dataSetName?"},
    4600     {"orient",    2, StreamlinesOrientOp,    6, 7, "qw qx qy qz ?dataSetName?"},
    4601     {"pos",       1, StreamlinesPositionOp,  5, 6, "x y z ?dataSetName?"},
    4602     {"ribbons",   1, StreamlinesRibbonsOp,   4, 5, "width angle ?dataSetName?"},
    4603     {"scale",     2, StreamlinesScaleOp,     5, 6, "sx sy sz ?dataSetName?"},
    4604     {"seed",      2, StreamlinesSeedOp,  4, 14, "op params... ?dataSetName?"},
     4986    {"opacity",   2, StreamlinesOpacityOp, 3, 4, "val ?dataSetName?"},
     4987    {"orient",    2, StreamlinesOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"},
     4988    {"pos",       1, StreamlinesPositionOp, 5, 6, "x y z ?dataSetName?"},
     4989    {"ribbons",   1, StreamlinesRibbonsOp, 4, 5, "width angle ?dataSetName?"},
     4990    {"scale",     2, StreamlinesScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     4991    {"seed",      2, StreamlinesSeedOp, 3, 14, "op params... ?dataSetName?"},
    46054992    {"tubes",     1, StreamlinesTubesOp, 4, 5, "numSides radius ?dataSetName?"},
    46064993    {"visible",   1, StreamlinesVisibleOp, 3, 4, "bool ?dataSetName?"}
     
    48165203
    48175204static Rappture::CmdSpec volumeShadingOps[] = {
    4818     {"ambient",  1, VolumeShadingAmbientOp,  4, 5, "coeff ?dataSetName?"},
    4819     {"diffuse",  1, VolumeShadingDiffuseOp,  4, 5, "coeff ?dataSetName?"},
     5205    {"ambient",  1, VolumeShadingAmbientOp, 4, 5, "coeff ?dataSetName?"},
     5206    {"diffuse",  1, VolumeShadingDiffuseOp, 4, 5, "coeff ?dataSetName?"},
    48205207    {"specular", 1, VolumeShadingSpecularOp, 5, 6, "coeff power ?dataSetName?"}
    48215208};
     
    48545241
    48555242static Rappture::CmdSpec volumeOps[] = {
    4856     {"add",      1, VolumeAddOp,      2, 3, "?dataSetName?"},
     5243    {"add",      1, VolumeAddOp, 2, 3, "?dataSetName?"},
    48575244    {"colormap", 1, VolumeColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
    4858     {"delete",   1, VolumeDeleteOp,   2, 3, "?dataSetName?"},
     5245    {"delete",   1, VolumeDeleteOp, 2, 3, "?dataSetName?"},
    48595246    {"lighting", 1, VolumeLightingOp, 3, 4, "bool ?dataSetName?"},
    4860     {"opacity",  2, VolumeOpacityOp,  3, 4, "val ?dataSetName?"},
    4861     {"orient",   2, VolumeOrientOp,   6, 7, "qw qx qy qz ?dataSetName?"},
     5247    {"opacity",  2, VolumeOpacityOp, 3, 4, "val ?dataSetName?"},
     5248    {"orient",   2, VolumeOrientOp, 6, 7, "qw qx qy qz ?dataSetName?"},
    48625249    {"pos",      1, VolumePositionOp, 5, 6, "x y z ?dataSetName?"},
    4863     {"scale",    2, VolumeScaleOp,    5, 6, "sx sy sz ?dataSetName?"},
    4864     {"shading",  2, VolumeShadingOp,  4, 6, "oper val ?dataSetName?"},
    4865     {"visible",  1, VolumeVisibleOp,  3, 4, "bool ?dataSetName?"}
     5250    {"scale",    2, VolumeScaleOp, 5, 6, "sx sy sz ?dataSetName?"},
     5251    {"shading",  2, VolumeShadingOp, 4, 6, "oper val ?dataSetName?"},
     5252    {"visible",  1, VolumeVisibleOp, 3, 4, "bool ?dataSetName?"}
    48665253};
    48675254static int nVolumeOps = NumCmdSpecs(volumeOps);
     
    48835270/**
    48845271 * \brief Execute commands from client in Tcl interpreter
    4885  *
    4886  * In this threaded model, the select call is for event compression.  We
    4887  * want to execute render server commands as long as they keep coming. 
    4888  * This lets us execute a stream of many commands but render once.  This
    4889  * benefits camera movements, screen resizing, and opacity changes
    4890  * (using a slider on the client).  The down side is you don't render
    4891  * until there's a lull in the command stream.  If the client needs an
    4892  * image, it can issue an "imgflush" command.  That breaks us out of the
    4893  * read loop.
    48945272 */
    48955273int
    48965274Rappture::VtkVis::processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout)
    48975275{
     5276    Tcl_DString cmdbuffer;
     5277    Tcl_DStringInit(&cmdbuffer);
     5278
     5279    int fdIn = fileno(fin);
     5280    int fdOut = fileno(fout);
     5281    int flags = fcntl(fdIn, F_GETFL, 0);
     5282    fcntl(fdIn, F_SETFL, flags & ~O_NONBLOCK);
     5283
    48985284    int status = TCL_OK;
    4899 
    4900 #define BUFFERSIZE   ((1<<16)-1)
    4901     char buffer[BUFFERSIZE+1];
    4902 
    4903     Tcl_DString command;
    4904     Tcl_DStringInit(&command);
    4905 
    4906     fd_set readFds;
    4907     struct timeval tv, *tvPtr;
    4908 
    4909     FD_ZERO(&readFds);
    4910     FD_SET(fileno(fin), &readFds);
    4911     tvPtr = NULL;                       /* Initially there is no timeout. */
    4912     while (select(1, &readFds, NULL, NULL, tvPtr) > 0) {
    4913         if (fgets(buffer, BUFFERSIZE, fin) == NULL) {
    4914             /* Terminate the server if we can't
    4915              * communicate with the client
    4916              * anymore. */
    4917             if (feof(fin)) {
    4918                 INFO("Exiting server on EOF from client");
    4919                 exit(0);
    4920             } else {
    4921                 ERROR("Exiting server, failed to read from client: %s",
    4922                       strerror(errno));
    4923                 exit(1);
     5285    int nCommands = 0;
     5286    bool isComplete = false;
     5287    while ((!feof(fin)) && (status == TCL_OK)) {
     5288        while (!feof(fin)) {
     5289            int c = fgetc(fin);
     5290            if (c <= 0) {
     5291                if (errno == EWOULDBLOCK) {
     5292                    break;
     5293                }
     5294                if (feof(fin))
     5295                    return 1;
     5296                else
     5297                    return c;
    49245298            }
    4925         }
    4926         buffer[BUFFERSIZE] = '\0';
    4927         Tcl_DStringAppend(&command, buffer, -1);
    4928         if (Tcl_CommandComplete(Tcl_DStringValue(&command))) {
    4929             status = ExecuteCommand(interp, &command);
    4930             if (status == TCL_BREAK) {
    4931                 return 1;               /* This was caused by a "imgflush"
    4932                                          * command. Break out of the read loop
    4933                                          * and allow a new image to be
    4934                                          * rendered. */
     5299            char ch = (char)c;
     5300            Tcl_DStringAppend(&cmdbuffer, &ch, 1);
     5301            if (ch == '\n') {
     5302                isComplete = Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer));
     5303                if (isComplete) {
     5304                    break;
     5305                }
    49355306            }
    49365307        }
    4937         tv.tv_sec = tv.tv_usec = 0L;
    4938         FD_SET(fileno(fin), &readFds);
    4939         tvPtr = &tv;
    4940     }
     5308        // no command? then we're done for now
     5309        if (Tcl_DStringLength(&cmdbuffer) == 0) {
     5310            break;
     5311        }
     5312        if (isComplete) {
     5313            // back to original flags during command evaluation...
     5314            fcntl(fdIn, F_SETFL, flags & ~O_NONBLOCK);
     5315            TRACE("command: '%s'", Tcl_DStringValue(&cmdbuffer));
     5316            status = ExecuteCommand(interp, &cmdbuffer);
     5317            // non-blocking for next read -- we might not get anything
     5318            fcntl(fdIn, F_SETFL, flags | O_NONBLOCK);
     5319            isComplete = false;
     5320            nCommands++;
     5321        }
     5322    }
     5323    fcntl(fdIn, F_SETFL, flags);
    49415324
    49425325    if (status != TCL_OK) {
     
    49465329        string = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
    49475330        TRACE("ERROR errorInfo=(%s)", string);
    4948         INFO("%s: status=%d ERROR errorInfo=(%s)", Tcl_DStringValue(&command),
    4949              status, string);
     5331
    49505332        nBytes = strlen(string);
    49515333        struct iovec iov[3];
     
    49565338        iov[2].iov_base = (char *)"\n";
    49575339        iov[2].iov_len = strlen((char *)iov[2].iov_base);
    4958         int fdOut = fileno(fout);
    49595340        if (writev(fdOut, iov, 3) < 0) {
    49605341            ERROR("write failed: %s", strerror(errno));
     
    49715352 * \return The initialized Tcl interpreter
    49725353 */
    4973 void
    4974 Rappture::VtkVis::initTcl(Tcl_Interp *interp, ClientData clientData)
    4975 {
     5354Tcl_Interp *
     5355Rappture::VtkVis::initTcl()
     5356{
     5357    Tcl_Interp *interp;
     5358    interp = Tcl_CreateInterp();
     5359
    49765360    Tcl_MakeSafe(interp);
    4977     Tcl_CreateObjCommand(interp, "axis",        AxisCmd,        clientData, NULL);
    4978     Tcl_CreateObjCommand(interp, "camera",      CameraCmd,      clientData, NULL);
    4979     Tcl_CreateObjCommand(interp, "colormap",    ColorMapCmd,    clientData, NULL);
    4980     Tcl_CreateObjCommand(interp, "contour2d",   Contour2DCmd,   clientData, NULL);
    4981     Tcl_CreateObjCommand(interp, "contour3d",   Contour3DCmd,   clientData, NULL);
    4982     Tcl_CreateObjCommand(interp, "dataset",     DataSetCmd,     clientData, NULL);
    4983     Tcl_CreateObjCommand(interp, "glyphs",      GlyphsCmd,      clientData, NULL);
    4984     Tcl_CreateObjCommand(interp, "heightmap",   HeightMapCmd,   clientData, NULL);
    4985     Tcl_CreateObjCommand(interp, "imgflush",    ImageFlushCmd,  clientData, NULL);
    4986     Tcl_CreateObjCommand(interp, "legend",      LegendCmd,      clientData, NULL);
    4987     Tcl_CreateObjCommand(interp, "lic",         LICCmd,         clientData, NULL);
    4988     Tcl_CreateObjCommand(interp, "molecule",    MoleculeCmd,    clientData, NULL);
    4989     Tcl_CreateObjCommand(interp, "polydata",    PolyDataCmd,    clientData, NULL);
    4990     Tcl_CreateObjCommand(interp, "pseudocolor", PseudoColorCmd, clientData, NULL);
    4991     Tcl_CreateObjCommand(interp, "renderer",    RendererCmd,    clientData, NULL);
    4992     Tcl_CreateObjCommand(interp, "screen",      ScreenCmd,      clientData, NULL);
    4993     Tcl_CreateObjCommand(interp, "streamlines", StreamlinesCmd, clientData, NULL);
    4994     Tcl_CreateObjCommand(interp, "volume",      VolumeCmd,      clientData, NULL);
     5361
     5362    Tcl_CreateObjCommand(interp, "axis",        AxisCmd,        NULL, NULL);
     5363    Tcl_CreateObjCommand(interp, "camera",      CameraCmd,      NULL, NULL);
     5364    Tcl_CreateObjCommand(interp, "colormap",    ColorMapCmd,    NULL, NULL);
     5365    Tcl_CreateObjCommand(interp, "contour2d",   Contour2DCmd,   NULL, NULL);
     5366    Tcl_CreateObjCommand(interp, "contour3d",   Contour3DCmd,   NULL, NULL);
     5367    Tcl_CreateObjCommand(interp, "cutplane",    CutplaneCmd,    NULL, NULL);
     5368    Tcl_CreateObjCommand(interp, "dataset",     DataSetCmd,     NULL, NULL);
     5369    Tcl_CreateObjCommand(interp, "glyphs",      GlyphsCmd,      NULL, NULL);
     5370    Tcl_CreateObjCommand(interp, "heightmap",   HeightMapCmd,   NULL, NULL);
     5371    Tcl_CreateObjCommand(interp, "legend",      LegendCmd,      NULL, NULL);
     5372    Tcl_CreateObjCommand(interp, "lic",         LICCmd,         NULL, NULL);
     5373    Tcl_CreateObjCommand(interp, "molecule",    MoleculeCmd,    NULL, NULL);
     5374    Tcl_CreateObjCommand(interp, "polydata",    PolyDataCmd,    NULL, NULL);
     5375    Tcl_CreateObjCommand(interp, "pseudocolor", PseudoColorCmd, NULL, NULL);
     5376    Tcl_CreateObjCommand(interp, "renderer",    RendererCmd,    NULL, NULL);
     5377    Tcl_CreateObjCommand(interp, "screen",      ScreenCmd,      NULL, NULL);
     5378    Tcl_CreateObjCommand(interp, "streamlines", StreamlinesCmd, NULL, NULL);
     5379    Tcl_CreateObjCommand(interp, "volume",      VolumeCmd,      NULL, NULL);
     5380    return interp;
    49955381}
    49965382
    49975383/**
    49985384 * \brief Delete Tcl commands and interpreter
     5385 *
    49995386 */
    50005387void Rappture::VtkVis::exitTcl(Tcl_Interp *interp)
     
    50065393    Tcl_DeleteCommand(interp, "contour2d");
    50075394    Tcl_DeleteCommand(interp, "contour3d");
     5395    Tcl_DeleteCommand(interp, "cutplane");
    50085396    Tcl_DeleteCommand(interp, "dataset");
    50095397    Tcl_DeleteCommand(interp, "glyphs");
    50105398    Tcl_DeleteCommand(interp, "heightmap");
    5011     Tcl_DeleteCommand(interp, "imgflush");
    50125399    Tcl_DeleteCommand(interp, "legend");
    50135400    Tcl_DeleteCommand(interp, "lic");
  • branches/blt4/packages/vizservers/vtkvis/RpVtkRendererCmd.h

    r2542 r2550  
    1616
    1717extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout);
    18 extern void initTcl(Tcl_Interp *interp, ClientData clientData);
     18extern Tcl_Interp *initTcl();
    1919extern void exitTcl(Tcl_Interp *interp);
    2020
  • branches/blt4/packages/vizservers/vtkvis/TGAWriter.cpp

    r2542 r2550  
    1717#include "TGAWriter.h"
    1818#include "Trace.h"
    19 #ifdef USE_THREADS
    20 #include "ResponseQueue.h"
    21 #endif
    22 
    23 #ifdef USE_THREADS
    24 
    25 /**
    26  * \brief Writes image command + data to supplied file descriptor.
    27  *
    28  * The image data must be supplied in BGR(A) order with bottom to
    29  * top scanline ordering.
    30  *
    31  * \param[in] queue Pointer to ResponseQueue to write to
    32  * \param[in] cmdName Command name to send (byte length will be appended)
    33  * \param[in] data Image data
    34  * \param[in] width Width of image in pixels
    35  * \param[in] height Height of image in pixels
    36  * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha
    37  */
    38 void
    39 Rappture::VtkVis::queueTGA(ResponseQueue *queue, const char *cmdName,
    40                            const unsigned char *data,
    41                            int width, int height,
    42                            int bytesPerPixel)
    43 {
    44     TRACE("(%dx%d)\n", width, height);
    45 
    46     size_t headerLength = 18;
    47 
    48     char header[headerLength];
    49     memset(header, 0, headerLength);
    50     header[2] = (char)2;  // image type (2 = uncompressed true-color)
    51     header[12] = (char)width;
    52     header[13] = (char)(width >> 8);
    53     header[14] = (char)height;
    54     header[15] = (char)(height >> 8);
    55     header[16] = (char)(bytesPerPixel*8); // bits per pixel
    56 
    57     size_t dataLength = width * height * bytesPerPixel;
    58     size_t cmdLength;
    59 
    60     char command[200];
    61     cmdLength = snprintf(command, sizeof(command), "%s %lu\n", cmdName,
    62                          (unsigned long)headerLength + dataLength);
    63 
    64     size_t length;
    65     unsigned char *mesg = NULL;
    66 
    67     length = headerLength + dataLength + cmdLength;
    68     mesg = (unsigned char *)malloc(length);
    69     if (mesg == NULL) {
    70         ERROR("can't allocate %ld bytes for the image message", length);
    71         return;
    72     }
    73     memcpy(mesg, command, cmdLength);
    74     memcpy(mesg + cmdLength, header, headerLength);
    75     memcpy(mesg + cmdLength + headerLength,
    76            const_cast<unsigned char *>(data), dataLength);
    77 
    78     Response *response = NULL;
    79     if (strncmp(cmdName, "nv>legend", 9) == 0) {
    80         response = new Response(Response::LEGEND);
    81     } else {
    82         response = new Response(Response::IMAGE);
    83     }
    84     response->setMessage(mesg, length, Response::DYNAMIC);
    85     queue->enqueue(response);
    86     TRACE("Leaving (%dx%d)\n", width, height);
    87 }
    88 #else
    8919
    9020/**
     
    14979    TRACE("Leaving (%dx%d)\n", width, height);
    15080}
    151 #endif  /*USE_THREADS*/
    15281
    15382/**
  • branches/blt4/packages/vizservers/vtkvis/TGAWriter.h

    r2542 r2550  
    99#define __RAPPTURE_VTKVIS_TGAWRITER_H__
    1010
    11 #ifdef USE_THREADS
    12 #include "ResponseQueue.h"
    13 #endif
    14 
    1511namespace Rappture {
    1612namespace VtkVis {
    17 #ifdef USE_THREADS
     13
    1814extern
    19 void queueTGA(ResponseQueue *queue, const char *cmdName,
    20               const unsigned char *data, int width, int height,
    21               int bytesPerPixel);
    22 #else
     15void writeTGA(int fd, const char *cmdName, const unsigned char *data,
     16              int width, int height, int bytesPerPixel);
     17
    2318extern
    24 void writeTGA(int fd, const char *cmdName,
    25               const unsigned char *data, int width, int height,
    26               int bytesPerPixel);
    27 #endif
    28 extern
    29 void writeTGAFile(const char *filename,
    30                   const unsigned char *data, int width, int height,
    31                   int bytesPerPixel, bool srcIsRGB = false);
     19void writeTGAFile(const char *filename, const unsigned char *data,
     20                  int width, int height, int bytesPerPixel,
     21                  bool srcIsRGB = false);
     22
    3223}
    3324}
  • branches/blt4/packages/vizservers/vtkvis/Trace.cpp

    r2542 r2550  
    33 * Copyright (C) 2011, Purdue Research Foundation
    44 *
    5  * Author: ?
     5 * Author: George A. Howlett <gah@purdue.edu>
    66 */
    77
     
    2121 */
    2222void
    23 Rappture::VtkVis::initLog()
     23Rappture::VtkVis::InitLog()
    2424{
    2525    openlog("vtkvis", LOG_CONS | LOG_PERROR | LOG_PID,  LOG_USER);
     
    3030 */
    3131void
    32 Rappture::VtkVis::closeLog()
     32Rappture::VtkVis::CloseLog()
    3333{
    3434    closelog();
     
    3939 */
    4040void
    41 Rappture::VtkVis::logMessage(int priority, const char *funcname,
     41Rappture::VtkVis::LogMessage(int priority, const char *funcname,
    4242                             const char *path, int lineNum, const char* fmt, ...)
    4343{
  • branches/blt4/packages/vizservers/vtkvis/Trace.h

    r2542 r2550  
    33 * Copyright (C) 2011, Purdue Research Foundation
    44 *
    5  * Author: ?
     5 * Author: George A. Howlett <gah@purdue.edu>
    66 */
    77
     
    1414namespace VtkVis {
    1515
    16 extern void initLog();
     16extern void InitLog();
    1717
    18 extern void closeLog();
     18extern void CloseLog();
    1919
    20 extern void logMessage(int priority, const char *funcname, const char *fileName,
    21                        int lineNum, const char* format, ...);
     20extern void LogMessage(int priority, const char *funcname, const char *fileName, int lineNum,
     21                       const char* format, ...);
    2222
    23 #define ERROR(...)      Rappture::VtkVis::logMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     23#define ERROR(...)      LogMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    2424#ifdef WANT_TRACE
    25 #define TRACE(...)      Rappture::VtkVis::logMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     25#define TRACE(...)      LogMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    2626#else
    2727#define TRACE(...)
    28 #endif  /*WANT_TRACE*/
    29 #define WARN(...)       Rappture::VtkVis::logMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    30 #define INFO(...)       Rappture::VtkVis::logMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     28#endif
     29#define WARN(...)       LogMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     30#define INFO(...)       LogMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    3131
    3232}
  • branches/blt4/packages/vizservers/vtkvis/protocol.txt

    r2542 r2550  
    144144contour3d wireframe <bool> <?datasetName?>
    145145
    146 glyphs add <?dataSetName?>
     146cutplane add <?dataSetName?>
     147cutplane colormap <colorMapName> <?dataSetName?>
     148cutplane colormode <scalar|vmag|vx|vy|vz> <?datasetName?>
     149         Set the field used to color the object.  'scalar' uses
     150         the active scalar field.  'vmag' uses the magnitude of the current
     151         vector field, and 'vx','vy','vz' use the corresponding component of
     152         the active vector field.
     153cutplane delete <?dataSetName?>
     154cutplane edges <bool> <?dataSetName?>
     155cutplane lighting <bool> <?dataSetName?>
     156cutplane linecolor <r> <g> <b> <?dataSetName?>
     157cutplane linewidth <width> <?dataSetName?>
     158cutplane opacity <value> <?dataSetName?>
     159cutplane orient <qw> <qx> <qy> <qz> <?dataSetName?>
     160cutplane pos <x> <y> <z> <?dataSetName?>
     161cutplane scale <sx> <sy> <sz> <?dataSetName?>
     162cutplane slice axis ratio <?dataSetName?>
     163         For 3D data, select a slice along a principle axis of the volume. The
     164         ratio is [0,1]
     165cutplane visible <bool> <?dataSetName?>
     166cutplane wireframe <bool> <?datasetName?>
     167
     168glyphs add <shape> <?dataSetName?>
     169       See 'glyphs shape' for list of shapes
    147170glyphs ccolor r g b <?datasetName?>
    148171glyphs colormap <colorMapName> <?dataSetName?>
     
    193216heightmap pos <x> <y> <z> <?dataSetName?>
    194217heightmap scale <sx> <sy> <sz> <?dataSetName?>
     218heightmap slice axis ratio <?dataSetName?>
     219          For 3D data, select a slice along a principle axis of the volume. The
     220          ratio is [0,1]
    195221heightmap surface <bool> <?dataSetName?>
    196222          Toggle rendering of colormapped surface (mountain plot or cutplane)
    197223heightmap visible <bool> <?dataSetName?>
    198 heightmap volumeslice axis ratio <?dataSetName?>
    199           For 3D data, select a slice along a principle axis of the volume. The
    200           ratio is [0,1]
    201224heightmap wireframe <bool> <?datasetName?>
    202225
     
    212235lic pos <x> <y> <z> <?dataSetName?>
    213236lic scale <sx> <sy> <sz> <?dataSetName?>
     237lic slice <axis> <ratio> <?datasetName?>
     238    For 3D data, select a slice along a principle axis of the volume. The
     239    ratio is [0,1]
    214240lic visible <bool> <?datasetName?>
    215 lic volumeslice <axis> <ratio> <?datasetName?>
    216241
    217242molecule add <?datasetName?>
     
    305330            Create a disk seed area with optional hole, filled with randomly
    306331            placed points
     332streamlines seed fmesh <numPoints> data follows <nbytes> <?datasetName?>
     333            Fill a mesh supplied as a VTK data file with randomly placed points
    307334streamlines seed fpoly <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <angle> <radius> <numSides> <numPoints> <?dataSetName?>
    308335            Create a regular n-sided polygonal seed area filled with randomly
    309336            placed points
     337streamlines seed mesh data follows <nbytes> <?datasetName?>
     338            Use points of a mesh supplied as a VTK data file
     339streamlines seed points <?datasetName?>
     340            Use points of the streamlines' dataset mesh
    310341streamlines seed polygon <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <angle> <radius> <numSides> <?dataSetName?>
    311342            Create seed points from vertices of a regular n-sided polygon
    312343streamlines seed rake <startX> <startY> <startZ> <endX> <endY> <endZ> <numPoints> <?datasetName?>
    313344streamlines seed random <numPoints> <?datasetName?>
     345            Fill the streamlines' dataset mesh with randomly placed points
    314346streamlines seed visible <bool> <?datasetName?>
    315347streamlines tubes <numSides> <radius> <?datasetName?>
  • branches/blt4/packages/vizservers/vtkvis/vtkRpCubeAxesActor2D.cpp

    r2542 r2550  
    439439  // can be changed). Therefore, we can not just assign pointers otherwise
    440440  // each individual axis text prop would point to the same text prop.
    441 #ifdef notdef
     441#if 1
    442442  if (this->AxisLabelTextProperty &&
    443443      this->AxisLabelTextProperty->GetMTime() > this->BuildTime)
     
    10781078}
    10791079
    1080 //----------------------------------------------------------------------------
    1081 
    1082 // Disable warnings about qualifiers on return types.
    1083 #if defined(_COMPILER_VERSION)
    1084 # pragma set woff 3303
    1085 #endif
    1086 #if defined(__INTEL_COMPILER)
    1087 # pragma warning (disable:858)
    1088 #endif
    1089 
    1090 #ifndef VTK_LEGACY_REMOVE
    1091 # ifdef VTK_WORKAROUND_WINDOWS_MANGLE
    1092 #  undef SetProp
    1093 #  undef GetProp
    1094 void vtkRpCubeAxesActor2D::SetPropA(vtkProp* prop)
    1095 {
    1096   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::SetProp, "VTK 5.0",
    1097                            vtkRpCubeAxesActor2D::SetViewProp);
    1098   this->SetViewProp(prop);
    1099 }
    1100 void vtkRpCubeAxesActor2D::SetPropW(vtkProp* prop)
    1101 {
    1102   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::SetProp, "VTK 5.0",
    1103                            vtkRpCubeAxesActor2D::SetViewProp);
    1104   this->SetViewProp(prop);
    1105 }
    1106 vtkProp* vtkRpCubeAxesActor2D::GetPropA()
    1107 {
    1108   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::GetProp, "VTK 5.0",
    1109                            vtkRpCubeAxesActor2D::GetViewProp);
    1110   return this->GetViewProp();
    1111 }
    1112 vtkProp* vtkRpCubeAxesActor2D::GetPropW()
    1113 {
    1114   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::GetProp, "VTK 5.0",
    1115                            vtkRpCubeAxesActor2D::GetViewProp);
    1116   return this->GetViewProp();
    1117 }
    1118 # endif
    1119 void vtkRpCubeAxesActor2D::SetProp(vtkProp* prop)
    1120 {
    1121   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::SetProp, "VTK 5.0",
    1122                            vtkRpCubeAxesActor2D::SetViewProp);
    1123   this->SetViewProp(prop);
    1124 }
    1125 vtkProp* vtkRpCubeAxesActor2D::GetProp()
    1126 {
    1127   VTK_LEGACY_REPLACED_BODY(vtkRpCubeAxesActor2D::GetProp, "VTK 5.0",
    1128                            vtkRpCubeAxesActor2D::GetViewProp);
    1129   return this->GetViewProp();
    1130 }
    1131 #endif
  • branches/blt4/packages/vizservers/vtkvis/vtkRpCubeAxesActor2D.h

    r2322 r2550  
    253253  void ShallowCopy(vtkRpCubeAxesActor2D *actor);
    254254
    255 // Disable warnings about qualifiers on return types.
    256 #if defined(_COMPILER_VERSION)
    257 # pragma set woff 3303
    258 #endif
    259 #if defined(__INTEL_COMPILER)
    260 # pragma warning (push)
    261 # pragma warning (disable:858)
    262 #endif
    263 
    264 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
    265 # define SetPropA SetProp
    266 # define SetPropW SetProp
    267 # define GetPropA GetProp
    268 # define GetPropW GetProp
    269 #endif
    270 
    271   // Description:
    272   // @deprecated Replaced by vtkRpCubeAxesActor2D::SetViewProp() as of VTK 5.0.
    273   VTK_LEGACY(virtual void SetProp(vtkProp* prop));
    274 
    275   // Description:
    276   // @deprecated Replaced by vtkRpCubeAxesActor2D::GetViewProp() as of VTK 5.0.
    277   VTK_LEGACY(virtual vtkProp* GetProp());
    278 
    279 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
    280 # undef SetPropW
    281 # undef SetPropA
    282 # undef GetPropW
    283 # undef GetPropA
    284   //BTX
    285   VTK_LEGACY(virtual void SetPropA(vtkProp* prop));
    286   VTK_LEGACY(virtual void SetPropW(vtkProp* prop));
    287   VTK_LEGACY(virtual vtkProp* GetPropA());
    288   VTK_LEGACY(virtual vtkProp* GetPropW());
    289   //ETX
    290 #endif
    291 
    292 // Reset disabled warning about qualifiers on return types.
    293 #if defined(__INTEL_COMPILER)
    294 # pragma warning (pop)
    295 #endif
    296 #if defined(_COMPILER_VERSION)
    297 # pragma reset woff 3303
    298 #endif
    299 
    300255protected:
    301256  vtkRpCubeAxesActor2D();
Note: See TracChangeset for help on using the changeset viewer.