Changeset 2213 for trunk/packages


Ignore:
Timestamp:
Apr 20, 2011, 1:20:02 PM (14 years ago)
Author:
ldelgass
Message:

vtkvis - rename camera orient command to camera set, new camera orient command
takes a quaternion to orient the scene.

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

Legend:

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

    r2200 r2213  
    16351635}
    16361636
    1637 void Renderer::setCameraOrientation(double position[3],
    1638                                     double focalPoint[3],
    1639                                     double viewUp[3])
     1637void Renderer::setSceneOrientation(double quat[4])
     1638{
     1639    vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera();
     1640    vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkPerspectiveTransform>::New();
     1641    double mat3[3][3];
     1642    vtkMath::QuaternionToMatrix3x3(quat, mat3);
     1643    vtkSmartPointer<vtkMatrix4x4> mat4 = vtkSmartPointer<vtkMatrix4x4>::New();
     1644    for (int r = 0; r < 3; r++) {
     1645        memcpy(mat4[r], mat3[r], sizeof(double)*3);
     1646    }
     1647    trans->Translate(+_cameraFocalPoint[0], +_cameraFocalPoint[1], +_cameraFocalPoint[2]);
     1648    trans->Concatenate(mat4);
     1649    trans->Translate(-_cameraFocalPoint[0], -_cameraFocalPoint[1], -_cameraFocalPoint[2]);
     1650    camera->SetPosition(0, 0, 1);
     1651    camera->SetFocalPoint(0, 0, 0);
     1652    camera->SetViewUp(0, 1, 0);
     1653    camera->ApplyTransform(trans);
     1654    storeCameraOrientation();
     1655    if (_cameraPan[0] != 0.0 || _cameraPan[1] != 0.0) {
     1656        panCamera(_cameraPan[0], _cameraPan[1], true);
     1657    }
     1658    _needsRedraw = true;
     1659}
     1660
     1661void Renderer::setCameraOrientationAndPosition(double position[3],
     1662                                               double focalPoint[3],
     1663                                               double viewUp[3])
    16401664{
    16411665    memcpy(_cameraPos, position, sizeof(double)*3);
     
    16471671}
    16481672
    1649 void Renderer::getCameraOrientation(double position[3],
    1650                                     double focalPoint[3],
    1651                                     double viewUp[3])
     1673void Renderer::getCameraOrientationAndPosition(double position[3],
     1674                                               double focalPoint[3],
     1675                                               double viewUp[3])
    16521676{
    16531677    memcpy(position, _cameraPos, sizeof(double)*3);
  • trunk/packages/vizservers/vtkvis/RpVtkRenderer.h

    r2200 r2213  
    110110    void rotateCamera(double yaw, double pitch, double roll);
    111111
    112     void setCameraOrientation(double position[3],
    113                               double focalPoint[3],
    114                               double viewUp[3]);
    115 
    116     void getCameraOrientation(double position[3],
    117                               double focalPoint[3],
    118                               double viewUp[3]);
     112    void setSceneOrientation(double quat[4]);
     113
     114    void setCameraOrientationAndPosition(double position[3],
     115                                         double focalPoint[3],
     116                                         double viewUp[3]);
     117
     118    void getCameraOrientationAndPosition(double position[3],
     119                                         double focalPoint[3],
     120                                         double viewUp[3]);
    119121
    120122    void panCamera(double x, double y, bool absolute = true);
  • trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp

    r2200 r2213  
    219219    double viewUp[3];
    220220
    221     g_renderer->getCameraOrientation(pos, focalPt, viewUp);
     221    g_renderer->getCameraOrientationAndPosition(pos, focalPt, viewUp);
    222222
    223223    char buf[256];
     
    242242                    Tcl_Obj *const *objv)
    243243{
     244    double quat[4];
     245
     246    if (Tcl_GetDoubleFromObj(interp, objv[2], &quat[0]) != TCL_OK ||
     247        Tcl_GetDoubleFromObj(interp, objv[3], &quat[1]) != TCL_OK ||
     248        Tcl_GetDoubleFromObj(interp, objv[4], &quat[2]) != TCL_OK ||
     249        Tcl_GetDoubleFromObj(interp, objv[5], &quat[3]) != TCL_OK) {
     250        return TCL_ERROR;
     251    }
     252
     253    g_renderer->setCameraOrientation(pos, focalPt, viewUp);
     254    return TCL_OK;
     255}
     256
     257static int
     258CameraOrthoOp(ClientData clientData, Tcl_Interp *interp, int objc,
     259              Tcl_Obj *const *objv)
     260{
     261    double x, y, width, height;
     262
     263    if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
     264        Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK ||
     265        Tcl_GetDoubleFromObj(interp, objv[4], &width) != TCL_OK ||
     266        Tcl_GetDoubleFromObj(interp, objv[5], &height) != TCL_OK) {
     267        return TCL_ERROR;
     268    }
     269
     270    g_renderer->setCameraZoomRegion(x, y, width, height);
     271    return TCL_OK;
     272}
     273
     274static int
     275CameraPanOp(ClientData clientData, Tcl_Interp *interp, int objc,
     276            Tcl_Obj *const *objv)
     277{
     278    double x, y;
     279
     280    if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
     281        Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) {
     282        return TCL_ERROR;
     283    }
     284
     285    g_renderer->panCamera(x, y);
     286    return TCL_OK;
     287}
     288
     289static int
     290CameraResetOp(ClientData clientData, Tcl_Interp *interp, int objc,
     291              Tcl_Obj *const *objv)
     292{
     293    if (objc == 3) {
     294        const char *string = Tcl_GetString(objv[2]);
     295        char c = string[0];
     296        if ((c != 'a') || (strcmp(string, "all") != 0)) {
     297            Tcl_AppendResult(interp, "bad camera reset option \"", string,
     298                         "\": should be all", (char*)NULL);
     299            return TCL_ERROR;
     300        }
     301        g_renderer->resetCamera(true);
     302    } else {
     303        g_renderer->resetCamera(false);
     304    }
     305    return TCL_OK;
     306}
     307
     308static int
     309CameraRotateOp(ClientData clientData, Tcl_Interp *interp, int objc,
     310               Tcl_Obj *const *objv)
     311{
     312    double yaw, pitch, roll;
     313
     314    if (Tcl_GetDoubleFromObj(interp, objv[2], &yaw) != TCL_OK ||
     315        Tcl_GetDoubleFromObj(interp, objv[3], &pitch) != TCL_OK ||
     316        Tcl_GetDoubleFromObj(interp, objv[4], &roll) != TCL_OK) {
     317        return TCL_ERROR;
     318    }
     319
     320    g_renderer->rotateCamera(yaw, pitch, roll);
     321    return TCL_OK;
     322}
     323
     324static int
     325CameraSetOp(ClientData clientData, Tcl_Interp *interp, int objc,
     326            Tcl_Obj *const *objv)
     327{
    244328    double pos[3];
    245329    double focalPt[3];
     
    258342    }
    259343
    260     g_renderer->setCameraOrientation(pos, focalPt, viewUp);
    261     return TCL_OK;
    262 }
    263 
    264 static int
    265 CameraOrthoOp(ClientData clientData, Tcl_Interp *interp, int objc,
    266               Tcl_Obj *const *objv)
    267 {
    268     double x, y, width, height;
    269 
    270     if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
    271         Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK ||
    272         Tcl_GetDoubleFromObj(interp, objv[4], &width) != TCL_OK ||
    273         Tcl_GetDoubleFromObj(interp, objv[5], &height) != TCL_OK) {
    274         return TCL_ERROR;
    275     }
    276 
    277     g_renderer->setCameraZoomRegion(x, y, width, height);
    278     return TCL_OK;
    279 }
    280 
    281 static int
    282 CameraPanOp(ClientData clientData, Tcl_Interp *interp, int objc,
    283             Tcl_Obj *const *objv)
    284 {
    285     double x, y;
    286 
    287     if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
    288         Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) {
    289         return TCL_ERROR;
    290     }
    291 
    292     g_renderer->panCamera(x, y);
    293     return TCL_OK;
    294 }
    295 
    296 static int
    297 CameraResetOp(ClientData clientData, Tcl_Interp *interp, int objc,
    298               Tcl_Obj *const *objv)
    299 {
    300     if (objc == 3) {
    301         const char *string = Tcl_GetString(objv[2]);
    302         char c = string[0];
    303         if ((c != 'a') || (strcmp(string, "all") != 0)) {
    304             Tcl_AppendResult(interp, "bad camera reset option \"", string,
    305                          "\": should be all", (char*)NULL);
    306             return TCL_ERROR;
    307         }
    308         g_renderer->resetCamera(true);
    309     } else {
    310         g_renderer->resetCamera(false);
    311     }
    312     return TCL_OK;
    313 }
    314 
    315 static int
    316 CameraRotateOp(ClientData clientData, Tcl_Interp *interp, int objc,
    317                Tcl_Obj *const *objv)
    318 {
    319     double yaw, pitch, roll;
    320 
    321     if (Tcl_GetDoubleFromObj(interp, objv[2], &yaw) != TCL_OK ||
    322         Tcl_GetDoubleFromObj(interp, objv[3], &pitch) != TCL_OK ||
    323         Tcl_GetDoubleFromObj(interp, objv[4], &roll) != TCL_OK) {
    324         return TCL_ERROR;
    325     }
    326 
    327     g_renderer->rotateCamera(yaw, pitch, roll);
     344    g_renderer->setCameraOrientationAndPosition(pos, focalPt, viewUp);
    328345    return TCL_OK;
    329346}
     
    346363    {"get", 1, CameraGetOrientationOp, 2, 2, ""},
    347364    {"mode", 1, CameraModeOp, 3, 3, "mode"},
    348     {"orient", 3, CameraOrientationOp, 11, 11, "posX posY posZ focalPtX focalPtY focalPtZ viewUpX viewUpY viewUpZ"},
     365    {"orient", 3, CameraOrientationOp, 6, 6, "qx qy qz qw"},
    349366    {"ortho", 1, CameraOrthoOp, 6, 6, "x y width height"},
    350367    {"pan", 1, CameraPanOp, 4, 4, "panX panY"},
    351368    {"reset", 2, CameraResetOp, 2, 3, "?all?"},
    352369    {"rotate", 2, CameraRotateOp, 5, 5, "angle angle angle"},
     370    {"set", 1, CameraSetOp, 11, 11, "posX posY posZ focalPtX focalPtY focalPtZ viewUpX viewUpY viewUpZ"},
    353371    {"zoom", 1, CameraZoomOp, 3, 3, "zoomAmount"}
    354372};
  • trunk/packages/vizservers/vtkvis/protocol.txt

    r2200 r2213  
    2121camera mode <mode>
    2222       <mode> = persp|ortho|image
    23 camera orient <posX> <posY> <posZ> <focalPtX> <focalPtY> <focalPtZ> <viewUpX> <viewUpY> <viewUpZ>
    24        Set camera orientation using camera position, focal point and view up
    25        vector
     23camera orient <quatX> <quatY> <quatZ> <quatW>
     24       Set scene orientation using a quaternion
    2625camera ortho <x> <y> <width> <height>
    2726       Supply world coordinate bounds of plot area for image camera mode
     
    3332camera rotate <yaw> <pitch> <roll>
    3433       Specify relative rotation in Euler angles (FIXME)
     34camera set <posX> <posY> <posZ> <focalPtX> <focalPtY> <focalPtZ> <viewUpX> <viewUpY> <viewUpZ>
     35       Set camera orientation using camera position, focal point and view up
     36       vector
    3537camera zoom <z>
    3638       Specify zoom ratio
Note: See TracChangeset for help on using the changeset viewer.