Changeset 2575 for trunk/packages


Ignore:
Timestamp:
Sep 23, 2011, 6:54:41 PM (13 years ago)
Author:
ldelgass
Message:

cutplane now controls 3 axis aligned cutplanes. Add some comments to new
classes.

Location:
trunk/packages/vizservers/vtkvis
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/ReadBuffer.cpp

    r2573 r2575  
    1717using namespace Rappture::VtkVis;
    1818
    19 ReadBuffer::ReadBuffer(int f, size_t bufferSize) :
     19/**
     20 * \param[in] fd File descriptor to read
     21 * \param[in] bufferSize Block size to use in internal buffer
     22 */
     23ReadBuffer::ReadBuffer(int fd, size_t bufferSize) :
    2024    _bufferSize(bufferSize),
    21     _fd(f),
     25    _fd(fd),
    2226    _lastStatus(OK)
    2327{
     
    3337
    3438/**
    35  * Checks if a new line is currently in the buffer.  It returns
    36  * the index of the character past the new line.
     39 * \brief Checks if a new line is currently in the buffer.
     40 *
     41 * \return the index of the character past the new line.
    3742 */
    3843size_t
     
    4954
    5055/** 
    51  * Fills the buffer with available data.  Any existing data in the buffer
    52  * is moved to the front of the buffer, then the channel is read to fill
    53  * the rest of the buffer.
     56 * \brief Fills the buffer with available data.
     57 *
     58 * Any existing data in the buffer is moved to the front of the buffer,
     59 * then the channel is read to fill the rest of the buffer.
    5460 *
    5561 * \return If an error occur when reading the channel, then ERROR is
     
    98104
    99105/**
    100  * Read the requested number of bytes from the buffer.  Fails if
    101  * the requested number of bytes are not immediately available.
    102  * Never should be short.
     106 * \brief Read the requested number of bytes from the buffer.
     107
     108 * Fails if the requested number of bytes are not immediately
     109 * available. Never should be short.
    103110 */
    104111ReadBuffer::BufferStatus
     
    135142
    136143/**
    137  * Returns the next available line (terminated by a newline).
     144 * \brief Returns the next available line (terminated by a newline)
     145 *
    138146 * If insufficient data is in the buffer, then the channel is
    139147 * read for more data.  If reading the channel results in a
    140  * short read, CONTINUE is returned and *numBytesPtr is set to
    141  * 0.
     148 * short read, CONTINUE is returned and *numBytesPtr is set to 0.
    142149 */
    143150ReadBuffer::BufferStatus
  • trunk/packages/vizservers/vtkvis/ReadBuffer.h

    r2573 r2575  
    1414namespace VtkVis {
    1515
     16/**
     17 * \brief Buffered input for reading socket
     18 */
    1619class ReadBuffer
    1720{
     
    2427    };
    2528
    26     ReadBuffer(int f, size_t bufferSize);
     29    ReadBuffer(int fd, size_t bufferSize);
    2730
    2831    virtual ~ReadBuffer();
     
    3235    BufferStatus followingData(unsigned char *out, size_t numBytes);
    3336
     37    /**
     38     * \brief Check if buffer contains data ending in a newline
     39     *
     40     * \return bool indicating if getLine can be called without blocking
     41     */
    3442    bool isLineAvailable()
    3543    {
     
    3745    }
    3846
     47    /**
     48     * \brief Get the file descriptor this object reads from
     49     */
    3950    int file()
    4051    {
     
    4253    }
    4354
     55    /**
     56     * \brief Get the status of the last read
     57     */
    4458    BufferStatus status()
    4559    {
  • trunk/packages/vizservers/vtkvis/ResponseQueue.h

    r2573 r2575  
    1717namespace VtkVis {
    1818
     19/**
     20 * \brief Holds data for a response to be sent to client
     21 */
    1922class Response
    2023{
     
    4750    }
    4851
     52    /// Get the ResponseType
    4953    ResponseType type()
    5054    {
     
    5256    }
    5357
     58    /// Get the Response data
    5459    unsigned char *message()
    5560    {
     
    5762    }
    5863
     64    /// Get the number of bytes in the Response data
    5965    size_t length()
    6066    {
     
    6268    }
    6369
     70    /// Set the message/data making up the Response
     71    /**
     72     * If the AllocationType is DYNAMIC, the message data will be free()d
     73     * by the destructor.  If the AllocationType is VOLATILE, a copy of
     74     * the message data will be made.
     75     *
     76     * \param[in] mesg The Response data, can be a command and/or binary data
     77     * \param[in] length The number of bytes in mesg
     78     * \param[in] type Specify how the memory was allocated for mesg
     79     */
    6480    void setMessage(unsigned char *mesg, size_t length, AllocationType type)
    6581    {
     
    86102};
    87103
     104/**
     105 * \brief Queue to hold pending Responses to be sent to the client
     106 *
     107 * A semaphore and mutex are used to control access to the
     108 * queue by a reader and writer thread
     109 */
    88110class ResponseQueue
    89111{
     
    93115    virtual ~ResponseQueue();
    94116
     117    /// A place to store a data pointer.  Not used internally.
     118    /* XXX: This probably doesn't belong here */
    95119    void *clientData()
    96120    {
     
    98122    }
    99123
     124    /// Add a response to the end of the queue
    100125    void enqueue(Response *response);
    101126
     127    /// Remove a response from the front of the queue
    102128    Response *dequeue();
    103129
  • trunk/packages/vizservers/vtkvis/RpCutplane.cpp

    r2514 r2575  
    3434    VtkGraphicsObject(),
    3535    _colorMode(COLOR_BY_SCALAR),
    36     _colorMap(NULL),
    37     _sliceAxis(Z_AXIS)
     36    _colorMap(NULL)
    3837{
    3938}
     
    7978}
    8079
     80/**
     81 * \brief Create and initialize a VTK Prop to render the object
     82 */
     83void Cutplane::initProp()
     84{
     85    if (_prop == NULL) {
     86        _prop = vtkSmartPointer<vtkAssembly>::New();
     87
     88        for (int i = 0; i < 3; i++) {
     89            _actor[i] = vtkSmartPointer<vtkActor>::New();
     90            //_actor[i]->VisibilityOff();
     91            vtkProperty *property = _actor[i]->GetProperty();
     92            property->SetColor(_color[0], _color[1], _color[2]);
     93            property->SetEdgeColor(_edgeColor[0], _edgeColor[1], _edgeColor[2]);
     94            property->SetLineWidth(_edgeWidth);
     95            property->SetPointSize(_pointSize);
     96            property->EdgeVisibilityOff();
     97            property->SetOpacity(_opacity);
     98            property->SetAmbient(.2);
     99            if (!_lighting)
     100                property->LightingOff();
     101            if (_faceCulling && _opacity == 1.0) {
     102                setCulling(property, true);
     103            }
     104            getAssembly()->AddPart(_actor[i]);
     105        }
     106    }
     107}
     108
    81109void Cutplane::update()
    82110{
     
    86114    vtkDataSet *ds = _dataSet->getVtkDataSet();
    87115
     116    double bounds[6];
     117    _dataSet->getBounds(bounds);
    88118    // Mapper, actor to render color-mapped data set
    89     if (_mapper == NULL) {
    90         _mapper = vtkSmartPointer<vtkDataSetMapper>::New();
    91         // Map scalars through lookup table regardless of type
    92         _mapper->SetColorModeToMapScalars();
    93         //_mapper->InterpolateScalarsBeforeMappingOn();
    94     }
     119    for (int i = 0; i < 3; i++) {
     120        if (_mapper[i] == NULL) {
     121            _mapper[i] = vtkSmartPointer<vtkDataSetMapper>::New();
     122            // Map scalars through lookup table regardless of type
     123            _mapper[i]->SetColorModeToMapScalars();
     124            //_mapper->InterpolateScalarsBeforeMappingOn();
     125        }
     126        _cutPlane[i] = vtkSmartPointer<vtkPlane>::New();
     127        switch (i) {
     128        case 0:
     129            _cutPlane[i]->SetNormal(1, 0, 0);
     130            _cutPlane[i]->SetOrigin(bounds[0] + (bounds[1]-bounds[0])/2.,
     131                                    0,
     132                                    0);
     133            break;
     134        case 1:
     135            _cutPlane[i]->SetNormal(0, 1, 0);
     136            _cutPlane[i]->SetOrigin(0,
     137                                    bounds[2] + (bounds[3]-bounds[2])/2.,
     138                                    0);
     139            break;
     140        case 2:
     141        default:
     142            _cutPlane[i]->SetNormal(0, 0, 1);
     143            _cutPlane[i]->SetOrigin(0,
     144                                    0,
     145                                    bounds[4] + (bounds[5]-bounds[4])/2.);
     146            break;
     147        }
     148        _cutter[i] = vtkSmartPointer<vtkCutter>::New();
     149        _cutter[i]->SetCutFunction(_cutPlane[i]);
     150    }
     151
     152    initProp();
    95153
    96154    vtkPolyData *pd = vtkPolyData::SafeDownCast(ds);
    97     if (pd) {
    98         // DataSet is a vtkPolyData
    99         if (pd->GetNumberOfLines() == 0 &&
    100             pd->GetNumberOfPolys() == 0 &&
    101             pd->GetNumberOfStrips() == 0) {
    102             // DataSet is a point cloud
    103             DataSet::PrincipalPlane plane;
    104             double offset;
    105             if (_dataSet->is2D(&plane, &offset)) {
    106                 // DataSet is a 2D point cloud
     155    if (pd &&
     156        pd->GetNumberOfLines() == 0 &&
     157        pd->GetNumberOfPolys() == 0 &&
     158        pd->GetNumberOfStrips() == 0) {
     159        // DataSet is a point cloud
     160        DataSet::PrincipalPlane plane;
     161        double offset;
     162        if (_dataSet->is2D(&plane, &offset)) {
     163            // DataSet is a 2D point cloud
    107164#ifdef MESH_POINT_CLOUDS
    108                 vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
    109                 if (plane == DataSet::PLANE_ZY) {
    110                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    111                     trans->RotateWXYZ(90, 0, 1, 0);
    112                     if (offset != 0.0) {
    113                         trans->Translate(-offset, 0, 0);
    114                     }
    115                     mesher->SetTransform(trans);
    116                     _sliceAxis = X_AXIS;
    117                 } else if (plane == DataSet::PLANE_XZ) {
    118                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    119                     trans->RotateWXYZ(-90, 1, 0, 0);
    120                     if (offset != 0.0) {
    121                         trans->Translate(0, -offset, 0);
    122                     }
    123                     mesher->SetTransform(trans);
    124                     _sliceAxis = Y_AXIS;
    125                 } else if (offset != 0.0) {
    126                     // XY with Z offset
    127                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    128                     trans->Translate(0, 0, -offset);
    129                     mesher->SetTransform(trans);
     165            vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
     166            if (plane == DataSet::PLANE_ZY) {
     167                vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     168                trans->RotateWXYZ(90, 0, 1, 0);
     169                if (offset != 0.0) {
     170                    trans->Translate(-offset, 0, 0);
    130171                }
    131                 mesher->SetInput(pd);
    132                 _mapper->SetInputConnection(mesher->GetOutputPort());
     172                mesher->SetTransform(trans);
     173                _actor[1]->VisibilityOff();
     174                _actor[2]->VisibilityOff();
     175            } else if (plane == DataSet::PLANE_XZ) {
     176                vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     177                trans->RotateWXYZ(-90, 1, 0, 0);
     178                if (offset != 0.0) {
     179                    trans->Translate(0, -offset, 0);
     180                }
     181                mesher->SetTransform(trans);
     182                _actor[0]->VisibilityOff();
     183                _actor[2]->VisibilityOff();
     184            } else if (offset != 0.0) {
     185                // XY with Z offset
     186                vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     187                trans->Translate(0, 0, -offset);
     188                mesher->SetTransform(trans);
     189                _actor[0]->VisibilityOff();
     190                _actor[1]->VisibilityOff();
     191            }
     192            mesher->SetInput(pd);
     193            for (int i = 0; i < 3; i++) {
     194                _mapper[i]->SetInputConnection(mesher->GetOutputPort());
     195            }
    133196#else
    134                 vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
    135                 splatter->SetInput(pd);
    136                 int dims[3];
    137                 splatter->GetSampleDimensions(dims);
    138                 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
     197            vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
     198            splatter->SetInput(pd);
     199            int dims[3];
     200            splatter->GetSampleDimensions(dims);
     201            TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
     202            if (plane == DataSet::PLANE_ZY) {
     203                dims[0] = 3;
     204            } else if (plane == DataSet::PLANE_XZ) {
     205                dims[1] = 3;
     206            } else {
    139207                dims[2] = 3;
    140                 splatter->SetSampleDimensions(dims);
    141                 double bounds[6];
    142                 splatter->Update();
    143                 splatter->GetModelBounds(bounds);
    144                 TRACE("Model bounds: %g %g %g %g %g %g",
    145                       bounds[0], bounds[1],
    146                       bounds[2], bounds[3],
    147                       bounds[4], bounds[5]);
    148                 vtkSmartPointer<vtkExtractVOI> slicer = vtkSmartPointer<vtkExtractVOI>::New();
    149                 slicer->SetInputConnection(splatter->GetOutputPort());
    150                 slicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, 1, 1);
    151                 slicer->SetSampleRate(1, 1, 1);
     208            }
     209            splatter->SetSampleDimensions(dims);
     210            for (int i = 0; i < 3; i++) {
     211                _cutter[i]->SetInputConnection(splatter->GetOutputPort());
    152212                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    153213                gf->UseStripsOn();
    154                 gf->SetInputConnection(slicer->GetOutputPort());
    155                 _mapper->SetInputConnection(gf->GetOutputPort());
     214                gf->SetInputConnection(_cutter[i]->GetOutputPort());
     215                _mapper[i]->SetInputConnection(gf->GetOutputPort());
     216            }
    156217#endif
    157             } else {
     218        } else {
    158219#ifdef MESH_POINT_CLOUDS
    159                 // Data Set is a 3D point cloud
    160                 // Result of Delaunay3D mesher is unstructured grid
    161                 vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
    162                 mesher->SetInput(pd);
    163                 // Run the mesher
    164                 mesher->Update();
    165                 // Get bounds of resulting grid
    166                 double bounds[6];
    167                 mesher->GetOutput()->GetBounds(bounds);
    168                 // Sample a plane within the grid bounding box
    169                 vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
    170                 cutter->SetInputConnection(mesher->GetOutputPort());
    171                 if (_cutPlane == NULL) {
    172                     _cutPlane = vtkSmartPointer<vtkPlane>::New();
    173                 }
    174                 _cutPlane->SetNormal(0, 0, 1);
    175                 _cutPlane->SetOrigin(0,
    176                                      0,
    177                                      bounds[4] + (bounds[5]-bounds[4])/2.);
    178                 cutter->SetCutFunction(_cutPlane);
     220            // Data Set is a 3D point cloud
     221            // Result of Delaunay3D mesher is unstructured grid
     222            vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
     223            mesher->SetInput(pd);
     224            // Sample a plane within the grid bounding box
     225            for (int i = 0; i < 3; i++) {
     226                _cutter[i]->SetInputConnection(mesher->GetOutputPort());
    179227                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    180228                gf->UseStripsOn();
    181                 gf->SetInputConnection(cutter->GetOutputPort());
     229                gf->SetInputConnection(_cutter[i]->GetOutputPort());
     230                _mapper[i]->SetInputConnection(gf->GetOutputPort());
     231            }
    182232#else
    183                 if (_pointSplatter == NULL)
    184                     _pointSplatter = vtkSmartPointer<vtkGaussianSplatter>::New();
    185                 _pointSplatter->SetInput(pd);
    186                 int dims[3];
    187                 _pointSplatter->GetSampleDimensions(dims);
    188                 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
    189                 dims[2] = 3;
    190                 _pointSplatter->SetSampleDimensions(dims);
    191                 double bounds[6];
    192                 _pointSplatter->Update();
    193                 _pointSplatter->GetModelBounds(bounds);
    194                 TRACE("Model bounds: %g %g %g %g %g %g",
    195                       bounds[0], bounds[1],
    196                       bounds[2], bounds[3],
    197                       bounds[4], bounds[5]);
    198                 if (_volumeSlicer == NULL)
    199                     _volumeSlicer = vtkSmartPointer<vtkExtractVOI>::New();
    200                 _volumeSlicer->SetInputConnection(_pointSplatter->GetOutputPort());
    201                 _volumeSlicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, 1, 1);
    202                 _volumeSlicer->SetSampleRate(1, 1, 1);
     233            vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
     234            splatter->SetInput(pd);
     235            int dims[3];
     236            splatter->GetSampleDimensions(dims);
     237            TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
     238            for (int i = 0; i < 3; i++) {
     239                _cutter[i]->SetInputConnection(splatter->GetOutputPort());
    203240                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    204241                gf->UseStripsOn();
    205                 gf->SetInputConnection(_volumeSlicer->GetOutputPort());
     242                gf->SetInputConnection(_cutter[i]->GetOutputPort());
     243                _mapper[i]->SetInputConnection(gf->GetOutputPort());
     244            }
    206245#endif
    207                 _mapper->SetInputConnection(gf->GetOutputPort());
    208              }
    209         } else {
    210             // DataSet is a vtkPolyData with lines and/or polygons
    211             _mapper->SetInput(ds);
    212246        }
    213247    } else {
    214         // DataSet is NOT a vtkPolyData
    215         // Can be: image/volume/uniform grid, structured grid, unstructured grid, rectilinear grid
    216         vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    217         gf->UseStripsOn();
    218         vtkImageData *imageData = vtkImageData::SafeDownCast(ds);
    219         if (!_dataSet->is2D() && imageData != NULL) {
    220             // 3D image/volume/uniform grid
    221             if (_volumeSlicer == NULL)
    222                 _volumeSlicer = vtkSmartPointer<vtkExtractVOI>::New();
    223             int dims[3];
    224             imageData->GetDimensions(dims);
    225             TRACE("Image data dimensions: %d %d %d", dims[0], dims[1], dims[2]);
    226             _volumeSlicer->SetInput(ds);
    227             _volumeSlicer->SetVOI(0, dims[0]-1, 0, dims[1]-1, (dims[2]-1)/2, (dims[2]-1)/2);
    228             _volumeSlicer->SetSampleRate(1, 1, 1);
    229             gf->SetInputConnection(_volumeSlicer->GetOutputPort());
    230         } else if (!_dataSet->is2D() && imageData == NULL) {
    231             // 3D structured grid, unstructured grid, or rectilinear grid
    232             double bounds[6];
    233             ds->GetBounds(bounds);
     248        // DataSet can be: image/volume/uniform grid, structured grid, unstructured grid, rectilinear grid, or
     249        // PolyData with cells other than points
     250        DataSet::PrincipalPlane plane;
     251        double offset;
     252        if (!_dataSet->is2D(&plane, &offset)) {
    234253            // Sample a plane within the grid bounding box
    235             vtkSmartPointer<vtkCutter> cutter = vtkSmartPointer<vtkCutter>::New();
    236             cutter->SetInput(ds);
    237             if (_cutPlane == NULL) {
    238                 _cutPlane = vtkSmartPointer<vtkPlane>::New();
    239             }
    240             _cutPlane->SetNormal(0, 0, 1);
    241             _cutPlane->SetOrigin(0,
    242                                  0,
    243                                  bounds[4] + (bounds[5]-bounds[4])/2.);
    244             cutter->SetCutFunction(_cutPlane);
    245             gf->SetInputConnection(cutter->GetOutputPort());
     254            for (int i = 0; i < 3; i++) {
     255                _cutter[i]->SetInput(ds);
     256                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     257                gf->UseStripsOn();
     258                gf->SetInputConnection(_cutter[i]->GetOutputPort());
     259                _mapper[i]->SetInputConnection(gf->GetOutputPort());
     260            }
    246261        } else {
    247262            // 2D data
    248             gf->SetInput(ds);
    249         }
    250         _mapper->SetInputConnection(gf->GetOutputPort());
     263            if (plane == DataSet::PLANE_ZY) {
     264                _actor[1]->VisibilityOff();
     265                _actor[2]->VisibilityOff();
     266            } else if (plane == DataSet::PLANE_XZ) {
     267                _actor[0]->VisibilityOff();
     268                _actor[2]->VisibilityOff();
     269            } else if (offset != 0.0) {
     270                // XY with Z offset
     271                _actor[0]->VisibilityOff();
     272                _actor[1]->VisibilityOff();
     273            }
     274            for (int i = 0; i < 3; i++) {
     275                vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     276                gf->UseStripsOn();
     277                gf->SetInput(ds);
     278                _mapper[i]->SetInputConnection(gf->GetOutputPort());
     279            }
     280        }
    251281    }
    252282
     
    255285    }
    256286
    257     initProp();
    258     getActor()->SetMapper(_mapper);
    259     _mapper->Update();
     287    for (int i = 0; i < 3; i++) {
     288        if (_mapper[i] != NULL) {
     289            _actor[i]->SetMapper(_mapper[i]);
     290            _mapper[i]->Update();
     291        }
     292    }
    260293}
    261294
     
    274307    }
    275308
    276     if (_volumeSlicer == NULL &&
    277         _cutPlane == NULL) {
     309    if ((axis == X_AXIS &&_cutPlane[0] == NULL) ||
     310        (axis == Y_AXIS &&_cutPlane[1] == NULL) ||
     311        (axis == Z_AXIS &&_cutPlane[2] == NULL)) {
    278312        WARN("Called before update() or DataSet is not a volume");
    279313        return;
    280314    }
    281315
    282     _sliceAxis = axis;
    283 
    284     if (_cutPlane != NULL) {
    285         double bounds[6];
    286         _dataSet->getBounds(bounds);
    287         switch (axis) {
    288         case X_AXIS:
    289             _cutPlane->SetNormal(1, 0, 0);
    290             _cutPlane->SetOrigin(bounds[0] + (bounds[1]-bounds[0]) * ratio,
    291                                  0,
    292                                  0);
    293             break;
    294         case Y_AXIS:
    295             _cutPlane->SetNormal(0, 1, 0);
    296             _cutPlane->SetOrigin(0,
    297                                  bounds[2] + (bounds[3]-bounds[2]) * ratio,
    298                                  0);
    299             break;
    300         case Z_AXIS:
    301             _cutPlane->SetNormal(0, 0, 1);
    302             _cutPlane->SetOrigin(0,
    303                                  0,
    304                                  bounds[4] + (bounds[5]-bounds[4]) * ratio);
    305             break;
    306         default:
    307             ERROR("Invalid Axis");
    308             return;
    309         }
    310     } else {
    311         int dims[3];
    312         if (_pointSplatter != NULL) {
    313             _pointSplatter->GetSampleDimensions(dims);
    314         } else {
    315             vtkImageData *imageData = vtkImageData::SafeDownCast(_dataSet->getVtkDataSet());
    316             if (imageData == NULL) {
    317                 ERROR("Not a volume data set");
    318                 return;
    319             }
    320             imageData->GetDimensions(dims);
    321         }
    322         int voi[6];
    323 
    324         switch (axis) {
    325         case X_AXIS:
    326             voi[0] = voi[1] = (int)((dims[0]-1) * ratio);
    327             voi[2] = 0;
    328             voi[3] = dims[1]-1;
    329             voi[4] = 0;
    330             voi[5] = dims[2]-1;
    331             break;
    332         case Y_AXIS:
    333             voi[0] = 0;
    334             voi[1] = dims[0]-1;
    335             voi[2] = voi[3] = (int)((dims[1]-1) * ratio);
    336             voi[4] = 0;
    337             voi[5] = dims[2]-1;
    338             break;
    339         case Z_AXIS:
    340             voi[0] = 0;
    341             voi[1] = dims[0]-1;
    342             voi[2] = 0;
    343             voi[3] = dims[1]-1;
    344             voi[4] = voi[5] = (int)((dims[2]-1) * ratio);
    345             break;
    346         default:
    347             ERROR("Invalid Axis");
    348             return;
    349         }
    350 
    351         _volumeSlicer->SetVOI(voi);
    352     }
    353 
    354     if (_mapper != NULL)
    355         _mapper->Update();
     316    double bounds[6];
     317    _dataSet->getBounds(bounds);
     318    switch (axis) {
     319    case X_AXIS:
     320        _cutPlane[0]->SetOrigin(bounds[0] + (bounds[1]-bounds[0]) * ratio,
     321                                0,
     322                                0);
     323        if (_mapper[0] != NULL)
     324            _mapper[0]->Update();
     325        break;
     326    case Y_AXIS:
     327        _cutPlane[1]->SetOrigin(0,
     328                                bounds[2] + (bounds[3]-bounds[2]) * ratio,
     329                                0);
     330        if (_mapper[1] != NULL)
     331            _mapper[1]->Update();
     332        break;
     333    case Z_AXIS:
     334        _cutPlane[2]->SetOrigin(0,
     335                                0,
     336                                bounds[4] + (bounds[5]-bounds[4]) * ratio);
     337        if (_mapper[2] != NULL)
     338            _mapper[2]->Update();
     339        break;
     340    default:
     341        ERROR("Invalid Axis");
     342        return;
     343    }
    356344}
    357345
     
    385373{
    386374    _colorMode = mode;
    387     if (_dataSet == NULL || _mapper == NULL)
     375    if (_dataSet == NULL ||
     376        _mapper[0] == NULL ||
     377        _mapper[1] == NULL ||
     378        _mapper[2] == NULL)
    388379        return;
    389380
     
    392383    switch (mode) {
    393384    case COLOR_BY_SCALAR: {
    394         _mapper->ScalarVisibilityOn();
    395         _mapper->SetScalarModeToDefault();
     385        for (int i = 0; i < 3; i++) {
     386            _mapper[i]->ScalarVisibilityOn();
     387            _mapper[i]->SetScalarModeToDefault();
     388        }
    396389        if (_lut != NULL) {
    397390            _lut->SetRange(_dataRange);
     
    400393        break;
    401394    case COLOR_BY_VECTOR_MAGNITUDE: {
    402         _mapper->ScalarVisibilityOn();
     395        for (int i = 0; i < 3; i++) {
     396            _mapper[i]->ScalarVisibilityOn();
     397        }
    403398        if (ds->GetPointData() != NULL &&
    404399            ds->GetPointData()->GetVectors() != NULL) {
    405             _mapper->SetScalarModeToUsePointFieldData();
    406             _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     400            for (int i = 0; i < 3; i++) {
     401                _mapper[i]->SetScalarModeToUsePointFieldData();
     402                _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     403            }
    407404        } else if (ds->GetCellData() != NULL &&
    408405                   ds->GetCellData()->GetVectors() != NULL) {
    409             _mapper->SetScalarModeToUseCellFieldData();
    410             _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     406            for (int i = 0; i < 3; i++) {
     407                _mapper[i]->SetScalarModeToUseCellFieldData();
     408                _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     409            }
    411410        }
    412411        if (_lut != NULL) {
     
    417416        break;
    418417    case COLOR_BY_VECTOR_X:
    419         _mapper->ScalarVisibilityOn();
     418        for (int i = 0; i < 3; i++) {
     419            _mapper[i]->ScalarVisibilityOn();
     420        }
    420421        if (ds->GetPointData() != NULL &&
    421422            ds->GetPointData()->GetVectors() != NULL) {
    422             _mapper->SetScalarModeToUsePointFieldData();
    423             _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     423            for (int i = 0; i < 3; i++) {
     424                _mapper[i]->SetScalarModeToUsePointFieldData();
     425                _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     426            }
    424427        } else if (ds->GetCellData() != NULL &&
    425428                   ds->GetCellData()->GetVectors() != NULL) {
    426             _mapper->SetScalarModeToUseCellFieldData();
    427             _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     429            for (int i = 0; i < 3; i++) {
     430                _mapper[i]->SetScalarModeToUseCellFieldData();
     431                _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     432            }
    428433        }
    429434        if (_lut != NULL) {
     
    434439        break;
    435440    case COLOR_BY_VECTOR_Y:
    436         _mapper->ScalarVisibilityOn();
     441        for (int i = 0; i < 3; i++) {
     442            _mapper[i]->ScalarVisibilityOn();
     443        }
    437444        if (ds->GetPointData() != NULL &&
    438445            ds->GetPointData()->GetVectors() != NULL) {
    439             _mapper->SetScalarModeToUsePointFieldData();
    440             _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     446            for (int i = 0; i < 3; i++) {
     447                _mapper[i]->SetScalarModeToUsePointFieldData();
     448                _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     449            }
    441450        } else if (ds->GetCellData() != NULL &&
    442451                   ds->GetCellData()->GetVectors() != NULL) {
    443             _mapper->SetScalarModeToUseCellFieldData();
    444             _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     452            for (int i = 0; i < 3; i++) {
     453                _mapper[i]->SetScalarModeToUseCellFieldData();
     454                _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     455            }
    445456        }
    446457        if (_lut != NULL) {
     
    451462        break;
    452463    case COLOR_BY_VECTOR_Z:
    453         _mapper->ScalarVisibilityOn();
     464        for (int i = 0; i < 3; i++) {
     465            _mapper[i]->ScalarVisibilityOn();
     466        }
    454467        if (ds->GetPointData() != NULL &&
    455468            ds->GetPointData()->GetVectors() != NULL) {
    456             _mapper->SetScalarModeToUsePointFieldData();
    457             _mapper->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     469            for (int i = 0; i < 3; i++) {
     470                _mapper[i]->SetScalarModeToUsePointFieldData();
     471                _mapper[i]->SelectColorArray(ds->GetPointData()->GetVectors()->GetName());
     472            }
    458473        } else if (ds->GetCellData() != NULL &&
    459474                   ds->GetCellData()->GetVectors() != NULL) {
    460             _mapper->SetScalarModeToUseCellFieldData();
    461             _mapper->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     475            for (int i = 0; i < 3; i++) {
     476                _mapper[i]->SetScalarModeToUseCellFieldData();
     477                _mapper[i]->SelectColorArray(ds->GetCellData()->GetVectors()->GetName());
     478            }
    462479        }
    463480        if (_lut != NULL) {
     
    468485        break;
    469486    default:
    470         _mapper->ScalarVisibilityOff();
     487        for (int i = 0; i < 3; i++) {
     488            _mapper[i]->ScalarVisibilityOff();
     489        }
    471490        break;
    472491    }
     
    493512    if (_lut == NULL) {
    494513        _lut = vtkSmartPointer<vtkLookupTable>::New();
    495         if (_mapper != NULL) {
    496             _mapper->UseLookupTableScalarRangeOn();
    497             _mapper->SetLookupTable(_lut);
     514        for (int i = 0; i < 3; i++) {
     515            if (_mapper[i] != NULL) {
     516                _mapper[i]->UseLookupTableScalarRangeOn();
     517                _mapper[i]->SetLookupTable(_lut);
     518            }
    498519        }
    499520    }
     
    530551
    531552/**
     553 * \brief Set visibility of cutplane on specified axis
     554 */
     555void Cutplane::setSliceVisibility(Axis axis, bool state)
     556{
     557    switch (axis) {
     558    case X_AXIS:
     559        if (_actor[0] != NULL)
     560            _actor[0]->SetVisibility((state ? 1 : 0));
     561        break;
     562    case Y_AXIS:
     563        if (_actor[1] != NULL)
     564            _actor[1]->SetVisibility((state ? 1 : 0));
     565        break;
     566    case Z_AXIS:
     567    default:
     568        if (_actor[2] != NULL)
     569            _actor[2]->SetVisibility((state ? 1 : 0));
     570        break;
     571    }
     572}
     573
     574/**
    532575 * \brief Set a group of world coordinate planes to clip rendering
    533576 *
     
    536579void Cutplane::setClippingPlanes(vtkPlaneCollection *planes)
    537580{
    538     if (_mapper != NULL) {
    539         _mapper->SetClippingPlanes(planes);
    540     }
    541 }
     581    for (int i = 0; i < 3; i++) {
     582        if (_mapper[i] != NULL) {
     583            _mapper[i]->SetClippingPlanes(planes);
     584        }
     585    }
     586}
  • trunk/packages/vizservers/vtkvis/RpCutplane.h

    r2514 r2575  
    1414#include <vtkActor.h>
    1515#include <vtkPlaneCollection.h>
    16 #include <vtkGaussianSplatter.h>
    17 #include <vtkExtractVOI.h>
     16#include <vtkCutter.h>
    1817#include <vtkPlane.h>
    1918
     
    6261    void selectVolumeSlice(Axis axis, double ratio);
    6362
     63    void setSliceVisibility(Axis axis, bool state);
     64
    6465    void setColorMode(ColorMode mode);
    6566
     
    8283
    8384private:
     85    virtual void initProp();
    8486    virtual void update();
    8587
    8688    ColorMode _colorMode;
    8789    ColorMap *_colorMap;
    88     Axis _sliceAxis;
    8990    double _vectorMagnitudeRange[2];
    9091    double _vectorComponentRange[3][2];
    9192
    9293    vtkSmartPointer<vtkLookupTable> _lut;
    93     vtkSmartPointer<vtkDataSetMapper> _mapper;
    94     vtkSmartPointer<vtkGaussianSplatter> _pointSplatter;
    95     vtkSmartPointer<vtkExtractVOI> _volumeSlicer;
    96     vtkSmartPointer<vtkPlane> _cutPlane;
     94    vtkSmartPointer<vtkActor> _actor[3];
     95    vtkSmartPointer<vtkDataSetMapper> _mapper[3];
     96    vtkSmartPointer<vtkCutter> _cutter[3];
     97    vtkSmartPointer<vtkPlane> _cutPlane[3];
    9798};
    9899
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp

    r2533 r2575  
    27762776    } while (doAll && ++itr != _dataSets.end());
    27772777
     2778    initCamera();
    27782779    _needsRedraw = true;
    27792780    return true;
     
    29592960    do {
    29602961        itr->second->selectVolumeSlice(axis, ratio);
     2962     } while (doAll && ++itr != _cutplanes.end());
     2963
     2964    _renderer->ResetCameraClippingRange();
     2965    _needsRedraw = true;
     2966}
     2967
     2968/**
     2969 * \brief Set the visibility of slices in one of the three axes
     2970 */
     2971void Renderer::setCutplaneSliceVisibility(const DataSetId& id, Cutplane::Axis axis, bool state)
     2972{
     2973    CutplaneHashmap::iterator itr;
     2974
     2975    bool doAll = false;
     2976
     2977    if (id.compare("all") == 0) {
     2978        itr = _cutplanes.begin();
     2979        doAll = true;
     2980    } else {
     2981        itr = _cutplanes.find(id);
     2982    }
     2983
     2984    if (itr == _cutplanes.end()) {
     2985        ERROR("Cutplane not found: %s", id.c_str());
     2986        return;
     2987    }
     2988
     2989    do {
     2990        itr->second->setSliceVisibility(axis, state);
    29612991     } while (doAll && ++itr != _cutplanes.end());
    29622992
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2514 r2575  
    376376
    377377    void setCutplaneVolumeSlice(const DataSetId& id, Cutplane::Axis axis, double ratio);
     378
     379    void setCutplaneSliceVisibility(const DataSetId& id, Cutplane::Axis axis, bool state);
    378380
    379381    void setCutplaneColorMap(const DataSetId& id, const ColorMapId& colorMapId);
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2573 r2575  
    15121512
    15131513static int
    1514 CutplaneVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1515                   Tcl_Obj *const *objv)
     1514CutplaneSliceVisibilityOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1515                          Tcl_Obj *const *objv)
    15161516{
    15171517    bool state;
    1518     if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
    1519         return TCL_ERROR;
    1520     }
    1521     if (objc == 4) {
    1522         const char *name = Tcl_GetString(objv[3]);
    1523         g_renderer->setCutplaneVisibility(name, state);
    1524     } else {
    1525         g_renderer->setCutplaneVisibility("all", state);
    1526     }
    1527     return TCL_OK;
    1528 }
    1529 
    1530 static int
    1531 CutplaneVolumeSliceOp(ClientData clientData, Tcl_Interp *interp, int objc,
    1532                       Tcl_Obj *const *objv)
    1533 {
    1534     double ratio;
    1535     if (Tcl_GetDoubleFromObj(interp, objv[3], &ratio) != TCL_OK) {
     1518    if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) {
    15361519        return TCL_ERROR;
    15371520    }
     
    15471530    } else {
    15481531        Tcl_AppendResult(interp, "bad axis option \"", string,
     1532                         "\": should be axisName bool", (char*)NULL);
     1533        return TCL_ERROR;
     1534    }
     1535    if (objc == 5) {
     1536        const char *name = Tcl_GetString(objv[4]);
     1537        g_renderer->setCutplaneSliceVisibility(name, axis, state);
     1538    } else {
     1539        g_renderer->setCutplaneSliceVisibility("all", axis, state);
     1540    }
     1541    return TCL_OK;
     1542}
     1543
     1544static int
     1545CutplaneVisibleOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1546                  Tcl_Obj *const *objv)
     1547{
     1548    bool state;
     1549    if (GetBooleanFromObj(interp, objv[2], &state) != TCL_OK) {
     1550        return TCL_ERROR;
     1551    }
     1552    if (objc == 4) {
     1553        const char *name = Tcl_GetString(objv[3]);
     1554        g_renderer->setCutplaneVisibility(name, state);
     1555    } else {
     1556        g_renderer->setCutplaneVisibility("all", state);
     1557    }
     1558    return TCL_OK;
     1559}
     1560
     1561static int
     1562CutplaneVolumeSliceOp(ClientData clientData, Tcl_Interp *interp, int objc,
     1563                      Tcl_Obj *const *objv)
     1564{
     1565    double ratio;
     1566    if (Tcl_GetDoubleFromObj(interp, objv[3], &ratio) != TCL_OK) {
     1567        return TCL_ERROR;
     1568    }
     1569    const char *string = Tcl_GetString(objv[2]);
     1570    char c = string[0];
     1571    Cutplane::Axis axis;
     1572    if ((c == 'x') && (strcmp(string, "x") == 0)) {
     1573        axis = Cutplane::X_AXIS;
     1574    } else if ((c == 'y') && (strcmp(string, "y") == 0)) {
     1575        axis = Cutplane::Y_AXIS;
     1576    } else if ((c == 'z') && (strcmp(string, "z") == 0)) {
     1577        axis = Cutplane::Z_AXIS;
     1578    } else {
     1579        Tcl_AppendResult(interp, "bad axis option \"", string,
    15491580                         "\": should be axisName ratio", (char*)NULL);
    15501581        return TCL_ERROR;
     
    15771608
    15781609static Rappture::CmdSpec cutplaneOps[] = {
    1579     {"add",          1, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"},
     1610    {"add",          2, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"},
     1611    {"axis",         2, CutplaneSliceVisibilityOp, 4, 5, "axis bool ?dataSetName?"},
    15801612    {"colormap",     7, CutplaneColorMapOp, 3, 4, "colorMapName ?dataSetName?"},
    15811613    {"colormode",    7, CutplaneColorModeOp, 3, 4, "mode ?dataSetNme?"},
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r2514 r2575  
    145145
    146146cutplane add <?dataSetName?>
     147cutplane axis <axis> <bool> <?dataSetName?>
     148         Toggle visibility of the 3 principal axis cutplanes
    147149cutplane colormap <colorMapName> <?dataSetName?>
    148150cutplane colormode <scalar|vmag|vx|vy|vz> <?datasetName?>
Note: See TracChangeset for help on using the changeset viewer.