- Timestamp:
- Aug 13, 2011 2:44:22 PM (13 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp
r2349 r2351 65 65 _cameraPan[0] = 0; 66 66 _cameraPan[1] = 0; 67 _cameraOrientation[0] = 1.0; 68 _cameraOrientation[1] = 0.0; 69 _cameraOrientation[2] = 0.0; 70 _cameraOrientation[3] = 0.0; 67 71 _cumulativeDataRange[0] = 0.0; 68 72 _cumulativeDataRange[1] = 1.0; … … 125 129 initAxes(); 126 130 initCamera(); 127 storeCameraOrientation();128 131 addColorMap("default", ColorMap::getDefault()); 129 132 addColorMap("volumeDefault", ColorMap::getVolumeDefault()); … … 6556 6559 } 6557 6560 6561 inline 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 6578 inline 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 6586 inline 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 6600 inline double *quatReciprocal(double quat[4]) 6601 { 6602 return quatReciprocal(quat, quat); 6603 } 6604 6605 inline void copyQuat(double quat[4], double result[4]) 6606 { 6607 memcpy(result, quat, sizeof(double)*4); 6608 } 6609 6558 6610 /** 6559 6611 * \brief Set the orientation of the camera from a quaternion … … 6571 6623 6572 6624 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); 6574 6638 #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); 6579 6651 #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 6624 6658 _renderer->ResetCameraClippingRange(); 6625 6659 printCameraInfo(camera); … … 6638 6672 double viewUp[3]) 6639 6673 { 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 camera6644 restoreCameraOrientation();6674 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 6675 camera->SetPosition(position); 6676 camera->SetFocalPoint(focalPoint); 6677 camera->SetViewUp(viewUp); 6678 _renderer->ResetCameraClippingRange(); 6645 6679 _needsRedraw = true; 6646 6680 } … … 6657 6691 double viewUp[3]) 6658 6692 { 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 to6666 * be able to later restore the saved orientation and position6667 */6668 void Renderer::storeCameraOrientation()6669 {6670 6693 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); 6686 6697 } 6687 6698 … … 6701 6712 camera->SetFocalPoint(0, 0, 0); 6702 6713 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; 6706 6718 } 6707 6719 setViewAngle(_windowHeight); … … 6738 6750 camera->Roll(roll); // Roll about camera view axis 6739 6751 _renderer->ResetCameraClippingRange(); 6740 storeCameraOrientation();6741 6752 //computeScreenWorldCoords(); 6742 6753 _needsRedraw = true; … … 6750 6761 * etc. 6751 6762 * 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) 6754 6767 * \param[in] absolute Control if pan amount is relative to current or absolute 6755 6768 */ … … 6832 6845 6833 6846 _renderer->ResetCameraClippingRange(); 6834 storeCameraOrientation();6835 6847 //computeScreenWorldCoords(); 6836 6848 } … … 6877 6889 camera->Zoom(z); // Change ortho parallel scale (Dolly has no effect in ortho) 6878 6890 _renderer->ResetCameraClippingRange(); 6879 storeCameraOrientation();6880 6891 } else { 6881 6892 camera->Dolly(z); // Move camera forward/back 6882 6893 _renderer->ResetCameraClippingRange(); 6883 storeCameraOrientation();6884 6894 //computeScreenWorldCoords(); 6885 6895 } -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.h
r2349 r2351 650 650 void computeScreenWorldCoords(); 651 651 652 void storeCameraOrientation();653 void restoreCameraOrientation();654 652 void initCamera(); 655 653 void initAxes(); … … 662 660 double _imgWorldDims[2]; 663 661 double _screenWorldCoords[4]; 664 double _cameraPos[3]; 665 double _cameraFocalPoint[3]; 666 double _cameraUp[3]; 662 double _cameraOrientation[4]; 667 663 double _cameraZoomRatio; 668 664 double _cameraPan[2]; -
trunk/packages/vizservers/vtkvis/protocol.txt
r2349 r2351 42 42 43 43 camera get 44 Request current camera orientation44 Request current camera parameters 45 45 camera mode <mode> 46 46 <mode> = persp|ortho|image … … 51 51 Data is assumed to lie in XY plane (z = 0) 52 52 camera 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 54 57 camera reset <?all?> 55 58 Option all resets orientation/rotation as well as pan/zoom/clip range … … 57 60 Specify relative rotation in Euler angles 58 61 camera 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 61 63 camera 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. 63 66 64 67 colormap add <colorMapName> <colorMap> <opacityMap> … … 251 254 streamlines seed color <r> <g> <b> <?datasetName?> 252 255 streamlines 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 254 258 streamlines 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 256 261 streamlines seed polygon <centerX> <centerY> <centerZ> <normalX> <normalY> <normalZ> <angle> <radius> <numSides> <?dataSetName?> 257 262 Create seed points from vertices of a regular n-sided polygon
Note: See TracChangeset
for help on using the changeset viewer.