Changeset 2351 for trunk


Ignore:
Timestamp:
Aug 13, 2011 2:44:22 PM (13 years ago)
Author:
ldelgass
Message:

Use same code path for setting relative/absolute camera orientation, as with
pan/zoom, compute a relative setting from the previous and current absolute
settings. This fixes interaction between pan/zoom/rotate when using absolute
settings from client. Rotation now always occurs about the focal point. With
the current client implementation, the camera settings after a loss of
connection may not be correct, since the decomposition into orientation, pan,
and zoom will not necessarily reproduce the same camera matrix. To fix this,
the client will probably need to keep track of the concatented camera matrix in order to properly restore the camera settings after a reconnect.

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

Legend:

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

    r2349 r2351  
    6565    _cameraPan[0] = 0;
    6666    _cameraPan[1] = 0;
     67    _cameraOrientation[0] = 1.0;
     68    _cameraOrientation[1] = 0.0;
     69    _cameraOrientation[2] = 0.0;
     70    _cameraOrientation[3] = 0.0;
    6771    _cumulativeDataRange[0] = 0.0;
    6872    _cumulativeDataRange[1] = 1.0;
     
    125129    initAxes();
    126130    initCamera();
    127     storeCameraOrientation();
    128131    addColorMap("default", ColorMap::getDefault());
    129132    addColorMap("volumeDefault", ColorMap::getVolumeDefault());
     
    65566559}
    65576560
     6561inline double *quatMult(double q1[4], double q2[4], double result[4])
     6562{
     6563    double q1w = q1[0];
     6564    double q1x = q1[1];
     6565    double q1y = q1[2];
     6566    double q1z = q1[3];
     6567    double q2w = q2[0];
     6568    double q2x = q2[1];
     6569    double q2y = q2[2];
     6570    double q2z = q2[3];
     6571    result[0] = (q1w*q2w) - (q1x*q2x) - (q1y*q2y) - (q1z*q2z);
     6572    result[1] = (q1w*q2x) + (q1x*q2w) + (q1y*q2z) - (q1z*q2y);
     6573    result[2] = (q1w*q2y) + (q1y*q2w) + (q1z*q2x) - (q1x*q2z);
     6574    result[3] = (q1w*q2z) + (q1z*q2w) + (q1x*q2y) - (q1y*q2x);
     6575    return result;
     6576}
     6577
     6578inline double *quatConjugate(double quat[4], double result[4])
     6579{
     6580    result[1] = -quat[1];
     6581    result[2] = -quat[2];
     6582    result[3] = -quat[3];
     6583    return result;
     6584}
     6585
     6586inline double *quatReciprocal(double quat[4], double result[4])
     6587{
     6588    double denom =
     6589        quat[0]*quat[0] +
     6590        quat[1]*quat[1] +
     6591        quat[2]*quat[2] +
     6592        quat[3]*quat[3];
     6593    quatConjugate(quat, result);
     6594    for (int i = 0; i < 4; i++) {
     6595        result[i] /= denom;
     6596    }
     6597    return result;
     6598}
     6599
     6600inline double *quatReciprocal(double quat[4])
     6601{
     6602    return quatReciprocal(quat, quat);
     6603}
     6604
     6605inline void copyQuat(double quat[4], double result[4])
     6606{
     6607    memcpy(result, quat, sizeof(double)*4);
     6608}
     6609
    65586610/**
    65596611 * \brief Set the orientation of the camera from a quaternion
     
    65716623
    65726624    if (absolute) {
    6573         quaternionToMatrix4x4(quat, *mat4);
     6625        double abs[4];
     6626        // Save absolute rotation
     6627        copyQuat(quat, abs);
     6628        // Compute relative rotation
     6629        quatMult(quatReciprocal(_cameraOrientation), quat, quat);
     6630        // Store absolute rotation
     6631        copyQuat(abs, _cameraOrientation);
     6632    } else {
     6633        // Compute new absolute rotation
     6634        quatMult(_cameraOrientation, quat, _cameraOrientation);
     6635    }
     6636
     6637    quaternionToTransposeMatrix4x4(quat, *mat4);
    65746638#ifdef DEBUG
    6575         TRACE("Arcball camera matrix:\n %g %g %g\n %g %g %g\n %g %g %g",
    6576               (*mat4)[0][0], (*mat4)[0][1], (*mat4)[0][2],
    6577               (*mat4)[1][0], (*mat4)[1][1], (*mat4)[1][2],
    6578               (*mat4)[2][0], (*mat4)[2][1], (*mat4)[2][2]);
     6639    TRACE("Arcball camera matrix:\n %g %g %g\n %g %g %g\n %g %g %g",
     6640          (*mat4)[0][0], (*mat4)[0][1], (*mat4)[0][2],
     6641          (*mat4)[1][0], (*mat4)[1][1], (*mat4)[1][2],
     6642          (*mat4)[2][0], (*mat4)[2][1], (*mat4)[2][2]);
     6643    vtkSmartPointer<vtkMatrix4x4> mat2 = vtkSmartPointer<vtkMatrix4x4>::New();
     6644    mat2->DeepCopy(camera->GetViewTransformMatrix());
     6645    TRACE("camera matrix:\n %g %g %g %g\n %g %g %g %g\n %g %g %g %g\n %g %g %g %g",
     6646          (*mat2)[0][0], (*mat2)[0][1], (*mat2)[0][2], (*mat2)[0][3],
     6647          (*mat2)[1][0], (*mat2)[1][1], (*mat2)[1][2], (*mat2)[1][3],
     6648          (*mat2)[2][0], (*mat2)[2][1], (*mat2)[2][2], (*mat2)[2][3],
     6649          (*mat2)[3][0], (*mat2)[3][1], (*mat2)[3][2], (*mat2)[3][3]);
     6650    printCameraInfo(camera);
    65796651#endif
    6580         camera->SetPosition(0, 0, 1);
    6581         camera->SetFocalPoint(0, 0, 0);
    6582         camera->SetViewUp(0, 1, 0);
    6583         double bounds[6];
    6584         collectBounds(bounds, false);
    6585         _renderer->ResetCamera(bounds);
    6586         camera->GetFocalPoint(_cameraFocalPoint);
    6587         trans->Translate(+_cameraFocalPoint[0], +_cameraFocalPoint[1], +_cameraFocalPoint[2]);
    6588         trans->Concatenate(mat4);
    6589         trans->Translate(-_cameraFocalPoint[0], -_cameraFocalPoint[1], -_cameraFocalPoint[2]);
    6590         camera->ApplyTransform(trans);
    6591     } else {
    6592         quaternionToTransposeMatrix4x4(quat, *mat4);
    6593 #ifdef DEBUG
    6594         vtkSmartPointer<vtkMatrix4x4> mat2 = vtkSmartPointer<vtkMatrix4x4>::New();
    6595         mat2->DeepCopy(camera->GetViewTransformMatrix());
    6596         TRACE("camera matrix:\n %g %g %g %g\n %g %g %g %g\n %g %g %g %g\n %g %g %g %g",
    6597               (*mat2)[0][0], (*mat2)[0][1], (*mat2)[0][2], (*mat2)[0][3],
    6598               (*mat2)[1][0], (*mat2)[1][1], (*mat2)[1][2], (*mat2)[1][3],
    6599               (*mat2)[2][0], (*mat2)[2][1], (*mat2)[2][2], (*mat2)[2][3],
    6600               (*mat2)[3][0], (*mat2)[3][1], (*mat2)[3][2], (*mat2)[3][3]);
    6601         printCameraInfo(camera);
    6602 #endif
    6603         trans->Translate(0, 0, -camera->GetDistance());
    6604         trans->Concatenate(mat4);
    6605         trans->Translate(0, 0, camera->GetDistance());
    6606         trans->Concatenate(camera->GetViewTransformMatrix());
    6607         setCameraFromMatrix(camera, *trans->GetMatrix());
    6608     }
    6609     storeCameraOrientation();
    6610     if (absolute) {
    6611         if (_cameraZoomRatio != 1.0) {
    6612             double z = _cameraZoomRatio;
    6613             _cameraZoomRatio = 1.0;
    6614             zoomCamera(z, true);
    6615         }
    6616         if (_cameraPan[0] != 0.0 || _cameraPan[1] != 0.0) {
    6617             double panx = _cameraPan[0];
    6618             double pany = -_cameraPan[1];
    6619             _cameraPan[0] = 0;
    6620             _cameraPan[1] = 0;
    6621             panCamera(panx, pany, true);
    6622         }
    6623     }
     6652    trans->Translate(0, 0, -camera->GetDistance());
     6653    trans->Concatenate(mat4);
     6654    trans->Translate(0, 0, camera->GetDistance());
     6655    trans->Concatenate(camera->GetViewTransformMatrix());
     6656    setCameraFromMatrix(camera, *trans->GetMatrix());
     6657
    66246658    _renderer->ResetCameraClippingRange();
    66256659    printCameraInfo(camera);
     
    66386672                                               double viewUp[3])
    66396673{
    6640     memcpy(_cameraPos, position, sizeof(double)*3);
    6641     memcpy(_cameraFocalPoint, focalPoint, sizeof(double)*3);
    6642     memcpy(_cameraUp, viewUp, sizeof(double)*3);
    6643     // Apply the new parameters to the VTK camera
    6644     restoreCameraOrientation();
     6674    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
     6675    camera->SetPosition(position);
     6676    camera->SetFocalPoint(focalPoint);
     6677    camera->SetViewUp(viewUp);
     6678    _renderer->ResetCameraClippingRange();
    66456679    _needsRedraw = true;
    66466680}
     
    66576691                                               double viewUp[3])
    66586692{
    6659     memcpy(position, _cameraPos, sizeof(double)*3);
    6660     memcpy(focalPoint, _cameraFocalPoint, sizeof(double)*3);
    6661     memcpy(viewUp, _cameraUp, sizeof(double)*3);
    6662 }
    6663 
    6664 /**
    6665  * \brief Saves the current camera orientation and position in order to
    6666  * be able to later restore the saved orientation and position
    6667  */
    6668 void Renderer::storeCameraOrientation()
    6669 {
    66706693    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
    6671     camera->GetPosition(_cameraPos);
    6672     camera->GetFocalPoint(_cameraFocalPoint);
    6673     camera->GetViewUp(_cameraUp);
    6674 }
    6675 
    6676 /**
    6677  * \brief Use the stored orientation and position to set the camera's
    6678  * current state
    6679  */
    6680 void Renderer::restoreCameraOrientation()
    6681 {
    6682     vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
    6683     camera->SetPosition(_cameraPos);
    6684     camera->SetFocalPoint(_cameraFocalPoint);
    6685     camera->SetViewUp(_cameraUp);
     6694    camera->GetPosition(position);
     6695    camera->GetFocalPoint(focalPoint);
     6696    camera->GetViewUp(viewUp);
    66866697}
    66876698
     
    67016712            camera->SetFocalPoint(0, 0, 0);
    67026713            camera->SetViewUp(0, 1, 0);
    6703             storeCameraOrientation();
    6704         } else {
    6705             restoreCameraOrientation();
     6714            _cameraOrientation[0] = 1.0;
     6715            _cameraOrientation[1] = 0.0;
     6716            _cameraOrientation[2] = 0.0;
     6717            _cameraOrientation[3] = 0.0;
    67066718        }
    67076719        setViewAngle(_windowHeight);
     
    67386750    camera->Roll(roll); // Roll about camera view axis
    67396751    _renderer->ResetCameraClippingRange();
    6740     storeCameraOrientation();
    67416752    //computeScreenWorldCoords();
    67426753    _needsRedraw = true;
     
    67506761 * etc.
    67516762 *
    6752  * \param[in] x Viewport coordinate horizontal panning
    6753  * \param[in] y Viewport coordinate vertical panning (with origin at top)
     6763 * \param[in] x Viewport coordinate horizontal panning (positive number pans
     6764 * camera left, object right)
     6765 * \param[in] y Viewport coordinate vertical panning (positive number pans
     6766 * camera up, object down)
    67546767 * \param[in] absolute Control if pan amount is relative to current or absolute
    67556768 */
     
    68326845
    68336846        _renderer->ResetCameraClippingRange();
    6834         storeCameraOrientation();
    68356847        //computeScreenWorldCoords();
    68366848    }
     
    68776889        camera->Zoom(z); // Change ortho parallel scale (Dolly has no effect in ortho)
    68786890        _renderer->ResetCameraClippingRange();
    6879         storeCameraOrientation();
    68806891    } else {
    68816892        camera->Dolly(z); // Move camera forward/back
    68826893        _renderer->ResetCameraClippingRange();
    6883         storeCameraOrientation();
    68846894        //computeScreenWorldCoords();
    68856895    }
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2349 r2351  
    650650    void computeScreenWorldCoords();
    651651
    652     void storeCameraOrientation();
    653     void restoreCameraOrientation();
    654652    void initCamera();
    655653    void initAxes();
     
    662660    double _imgWorldDims[2];
    663661    double _screenWorldCoords[4];
    664     double _cameraPos[3];
    665     double _cameraFocalPoint[3];
    666     double _cameraUp[3];
     662    double _cameraOrientation[4];
    667663    double _cameraZoomRatio;
    668664    double _cameraPan[2];
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r2349 r2351  
    4242
    4343camera get
    44        Request current camera orientation
     44       Request current camera parameters
    4545camera mode <mode>
    4646       <mode> = persp|ortho|image
     
    5151       Data is assumed to lie in XY plane (z = 0)
    5252camera pan <x> <y>
    53        <x,y> world coordinates
     53       <x,y> viewport coordinates (window center at 0,0).  Positive x pan
     54       means pan object to right (camera to left).  Positive y pan means
     55       pan object down (camera up).  For example a pan of 0.5, 0.5 would
     56       move the object center to the lower right corner of the window
    5457camera reset <?all?>
    5558       Option all resets orientation/rotation as well as pan/zoom/clip range
     
    5760       Specify relative rotation in Euler angles
    5861camera set <posX> <posY> <posZ> <focalPtX> <focalPtY> <focalPtZ> <viewUpX> <viewUpY> <viewUpZ>
    59        Set camera orientation using camera position, focal point and view up
    60        vector
     62       Set camera parameters: camera position, focal point and view up vector
    6163camera zoom <z>
    62        Specify zoom ratio
     64       Specify zoom ratio.  z > 1 is a zoom in, z < 1 is zoom out. z = 1
     65       resets to default.
    6366
    6467colormap add <colorMapName> <colorMap> <opacityMap>
     
    251254streamlines seed color <r> <g> <b> <?datasetName?>
    252255streamlines seed disk <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <radius> <innerRadius> <numPoints> <?dataSetName?>
    253             Create a disk seed area with optional hole, filled with randomly placed points
     256            Create a disk seed area with optional hole, filled with randomly
     257            placed points
    254258streamlines seed fpoly <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <angle> <radius> <numSides> <numPoints> <?dataSetName?>
    255             Create a regular n-sided polygonal seed area filled with randomly placed points
     259            Create a regular n-sided polygonal seed area filled with randomly
     260            placed points
    256261streamlines seed polygon <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <angle> <radius> <numSides> <?dataSetName?>
    257262            Create seed points from vertices of a regular n-sided polygon
Note: See TracChangeset for help on using the changeset viewer.