Changeset 2200 for trunk/packages/vizservers/vtkvis
- Timestamp:
- Apr 12, 2011, 2:20:21 PM (14 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/RpVtkRenderer.cpp
r2194 r2200 76 76 _renderer = vtkSmartPointer<vtkRenderer>::New(); 77 77 _renderer->LightFollowCameraOn(); 78 storeCameraOrientation();79 78 _cameraMode = PERSPECTIVE; 80 79 initAxes(); 81 80 initCamera(); 81 storeCameraOrientation(); 82 82 _renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); 83 83 _renderWindow->DoubleBufferOff(); … … 1635 1635 } 1636 1636 1637 void Renderer::setCameraOrientation(double position[3], 1638 double focalPoint[3], 1639 double viewUp[3]) 1640 { 1641 memcpy(_cameraPos, position, sizeof(double)*3); 1642 memcpy(_cameraFocalPoint, focalPoint, sizeof(double)*3); 1643 memcpy(_cameraUp, viewUp, sizeof(double)*3); 1644 // Apply the new parameters to the VTK camera 1645 restoreCameraOrientation(); 1646 _needsRedraw = true; 1647 } 1648 1649 void Renderer::getCameraOrientation(double position[3], 1650 double focalPoint[3], 1651 double viewUp[3]) 1652 { 1653 memcpy(position, _cameraPos, sizeof(double)*3); 1654 memcpy(focalPoint, _cameraFocalPoint, sizeof(double)*3); 1655 memcpy(viewUp, _cameraUp, sizeof(double)*3); 1656 } 1657 1637 1658 void Renderer::storeCameraOrientation() 1638 1659 { … … 1677 1698 _cameraPan[0] = 0; 1678 1699 _cameraPan[1] = 0; 1700 1679 1701 _needsRedraw = true; 1680 1702 } … … 1704 1726 * \brief Perform a 2D translation of the camera 1705 1727 * 1706 * \param[in] x [0,1] Viewport coordinate horizontal panning 1707 * \param[in] y [0,1] Viewport coordinate vertical panning (with origin at top) 1728 * x,y pan amount are specified as signed absolute pan amount in viewport 1729 * units -- i.e. 0 is no pan, .5 is half the viewport, 2 is twice the viewport, 1730 * etc. 1731 * 1732 * \param[in] x Viewport coordinate horizontal panning 1733 * \param[in] y Viewport coordinate vertical panning (with origin at top) 1708 1734 * \param[in] absolute Control if pan amount is relative to current or absolute 1709 1735 */ 1710 1736 void Renderer::panCamera(double x, double y, bool absolute) 1711 1737 { 1712 // Reverse x rather than y, since we are panning the camera, and client1713 // expects to be panning/moving the object1714 x = -x * _screenWorldCoords[2];1715 y = y * _screenWorldCoords[3];1716 1717 if (absolute) {1718 double panAbs[2];1719 panAbs[0] = x;1720 panAbs[1] = y;1721 x -= _cameraPan[0];1722 y -= _cameraPan[1];1723 _cameraPan[0] = panAbs[0];1724 _cameraPan[1] = panAbs[1];1725 } else {1726 _cameraPan[0] += x;1727 _cameraPan[1] += y;1728 }1729 1738 if (_cameraMode == IMAGE) { 1739 // Reverse x rather than y, since we are panning the camera, and client 1740 // expects to be panning/moving the object 1741 x = -x * _screenWorldCoords[2]; 1742 y = y * _screenWorldCoords[3]; 1743 1744 if (absolute) { 1745 double panAbs[2]; 1746 panAbs[0] = x; 1747 panAbs[1] = y; 1748 x -= _cameraPan[0]; 1749 y -= _cameraPan[1]; 1750 _cameraPan[0] = panAbs[0]; 1751 _cameraPan[1] = panAbs[1]; 1752 } else { 1753 _cameraPan[0] += x; 1754 _cameraPan[1] += y; 1755 } 1756 1730 1757 _imgWorldOrigin[0] += x; 1731 1758 _imgWorldOrigin[1] += y; … … 1733 1760 _imgWorldDims[0], _imgWorldDims[1]); 1734 1761 } else { 1762 y = -y; 1763 if (absolute) { 1764 double panAbs[2]; 1765 panAbs[0] = x; 1766 panAbs[1] = y; 1767 x -= _cameraPan[0]; 1768 y -= _cameraPan[1]; 1769 _cameraPan[0] = panAbs[0]; 1770 _cameraPan[1] = panAbs[1]; 1771 } else { 1772 _cameraPan[0] += x; 1773 _cameraPan[1] += y; 1774 } 1775 1735 1776 vtkSmartPointer<vtkCamera> camera = _renderer->GetActiveCamera(); 1736 vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); 1737 trans->Translate(x, y, 0); 1738 camera->ApplyTransform(trans); 1777 double viewFocus[4], focalDepth, viewPoint[3]; 1778 double newPickPoint[4], oldPickPoint[4], motionVector[3]; 1779 1780 camera->GetFocalPoint(viewFocus); 1781 computeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2], 1782 viewFocus); 1783 focalDepth = viewFocus[2]; 1784 1785 computeDisplayToWorld(( x * 2. + 1.) * _windowWidth / 2.0, 1786 ( y * 2. + 1.) * _windowHeight / 2.0, 1787 focalDepth, 1788 newPickPoint); 1789 1790 computeDisplayToWorld(_windowWidth / 2.0, 1791 _windowHeight / 2.0, 1792 focalDepth, 1793 oldPickPoint); 1794 1795 // Camera motion is reversed 1796 motionVector[0] = oldPickPoint[0] - newPickPoint[0]; 1797 motionVector[1] = oldPickPoint[1] - newPickPoint[1]; 1798 motionVector[2] = oldPickPoint[2] - newPickPoint[2]; 1799 1800 camera->GetFocalPoint(viewFocus); 1801 camera->GetPosition(viewPoint); 1802 camera->SetFocalPoint(motionVector[0] + viewFocus[0], 1803 motionVector[1] + viewFocus[1], 1804 motionVector[2] + viewFocus[2]); 1805 1806 camera->SetPosition(motionVector[0] + viewPoint[0], 1807 motionVector[1] + viewPoint[1], 1808 motionVector[2] + viewPoint[2]); 1809 1739 1810 _renderer->ResetCameraClippingRange(); 1740 1811 storeCameraOrientation(); … … 1799 1870 int imgHeightPx = _windowHeight - pxOffsetY - outerGutter; 1800 1871 int imgWidthPx = _windowWidth - pxOffsetX - outerGutter; 1872 1873 double imgAspect = width / height; 1874 double winAspect = (double)_windowWidth / _windowHeight; 1875 1801 1876 double pxToWorld; 1802 if (height > width) 1877 1878 if (imgAspect >= winAspect) { 1879 pxToWorld = width / imgWidthPx; 1880 } else { 1803 1881 pxToWorld = height / imgHeightPx; 1804 else1805 pxToWorld = width / imgWidthPx; 1882 } 1883 1806 1884 double offsetX = pxOffsetX * pxToWorld; 1807 1885 double offsetY = pxOffsetY * pxToWorld; … … 1853 1931 } 1854 1932 1933 void Renderer::computeDisplayToWorld(double x, double y, double z, double worldPt[4]) 1934 { 1935 _renderer->SetDisplayPoint(x, y, z); 1936 _renderer->DisplayToWorld(); 1937 _renderer->GetWorldPoint(worldPt); 1938 if (worldPt[3]) { 1939 worldPt[0] /= worldPt[3]; 1940 worldPt[1] /= worldPt[3]; 1941 worldPt[2] /= worldPt[3]; 1942 worldPt[3] = 1.0; 1943 } 1944 } 1945 1946 void Renderer::computeWorldToDisplay(double x, double y, double z, double displayPt[3]) 1947 { 1948 _renderer->SetWorldPoint(x, y, z, 1.0); 1949 _renderer->WorldToDisplay(); 1950 _renderer->GetDisplayPoint(displayPt); 1951 } 1952 1855 1953 void Renderer::computeScreenWorldCoords() 1856 1954 { … … 1858 1956 double x0 = -1; 1859 1957 double y0 = -1; 1860 double z0 = 0;1958 double z0 = -1; 1861 1959 double x1 = 1; 1862 1960 double y1 = 1; 1863 double z1 = 0;1961 double z1 = -1; 1864 1962 1865 1963 vtkMatrix4x4 *mat = vtkMatrix4x4::New(); … … 2100 2198 void Renderer::printCameraInfo(vtkCamera *camera) 2101 2199 { 2102 TRACE("Parallel Scale: %g, Cam pos: %g %g %g, Clipping range: %g %g",2200 TRACE("Parallel Scale: %g, Cam pos: %g %g %g, focal pt: %g %g %g, view up: %g %g %g, Clipping range: %g %g", 2103 2201 camera->GetParallelScale(), 2104 2202 camera->GetPosition()[0], 2105 2203 camera->GetPosition()[1], 2106 2204 camera->GetPosition()[2], 2205 camera->GetFocalPoint()[0], 2206 camera->GetFocalPoint()[1], 2207 camera->GetFocalPoint()[2], 2208 camera->GetViewUp()[0], 2209 camera->GetViewUp()[1], 2210 camera->GetViewUp()[2], 2107 2211 camera->GetClippingRange()[0], 2108 2212 camera->GetClippingRange()[1]); -
trunk/packages/vizservers/vtkvis/RpVtkRenderer.h
r2194 r2200 110 110 void rotateCamera(double yaw, double pitch, double roll); 111 111 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]); 119 112 120 void panCamera(double x, double y, bool absolute = true); 113 121 … … 239 247 240 248 void updateRanges(bool useCumulative); 249 250 void computeDisplayToWorld(double x, double y, double z, double worldPt[4]); 251 252 void computeWorldToDisplay(double x, double y, double z, double displayPt[3]); 241 253 242 254 void computeScreenWorldCoords(); -
trunk/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp
r2194 r2200 212 212 213 213 static int 214 CameraGetOrientationOp(ClientData clientData, Tcl_Interp *interp, int objc, 215 Tcl_Obj *const *objv) 216 { 217 double pos[3]; 218 double focalPt[3]; 219 double viewUp[3]; 220 221 g_renderer->getCameraOrientation(pos, focalPt, viewUp); 222 223 char buf[256]; 224 snprintf(buf, sizeof(buf), "nv>camera orient %.12e %.12e %.12e %.12e %.12e %.12e %.12e %.12e %.12e", 225 pos[0], pos[1], pos[2], focalPt[0], focalPt[1], focalPt[2], viewUp[0], viewUp[1], viewUp[2]); 226 ssize_t bytesWritten; 227 size_t len = strlen(buf); 228 size_t ofs = 0; 229 while ((bytesWritten = write(g_fdOut, buf + ofs, len - ofs)) > 0) { 230 ofs += bytesWritten; 231 if (ofs == len) 232 break; 233 } 234 if (bytesWritten < 0) { 235 return TCL_ERROR; 236 } 237 return TCL_OK; 238 } 239 240 static int 241 CameraOrientationOp(ClientData clientData, Tcl_Interp *interp, int objc, 242 Tcl_Obj *const *objv) 243 { 244 double pos[3]; 245 double focalPt[3]; 246 double viewUp[3]; 247 248 if (Tcl_GetDoubleFromObj(interp, objv[2], &pos[0]) != TCL_OK || 249 Tcl_GetDoubleFromObj(interp, objv[3], &pos[1]) != TCL_OK || 250 Tcl_GetDoubleFromObj(interp, objv[4], &pos[2]) != TCL_OK || 251 Tcl_GetDoubleFromObj(interp, objv[5], &focalPt[0]) != TCL_OK || 252 Tcl_GetDoubleFromObj(interp, objv[6], &focalPt[1]) != TCL_OK || 253 Tcl_GetDoubleFromObj(interp, objv[7], &focalPt[2]) != TCL_OK || 254 Tcl_GetDoubleFromObj(interp, objv[8], &viewUp[0]) != TCL_OK || 255 Tcl_GetDoubleFromObj(interp, objv[9], &viewUp[1]) != TCL_OK || 256 Tcl_GetDoubleFromObj(interp, objv[10], &viewUp[2]) != TCL_OK) { 257 return TCL_ERROR; 258 } 259 260 g_renderer->setCameraOrientation(pos, focalPt, viewUp); 261 return TCL_OK; 262 } 263 264 static int 214 265 CameraOrthoOp(ClientData clientData, Tcl_Interp *interp, int objc, 215 266 Tcl_Obj *const *objv) 216 267 { 217 floatx, y, width, height;218 219 if ( GetFloatFromObj(interp, objv[2], &x) != TCL_OK ||220 GetFloatFromObj(interp, objv[3], &y) != TCL_OK ||221 GetFloatFromObj(interp, objv[4], &width) != TCL_OK ||222 GetFloatFromObj(interp, objv[5], &height) != TCL_OK) {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) { 223 274 return TCL_ERROR; 224 275 } … … 232 283 Tcl_Obj *const *objv) 233 284 { 234 floatx, y;235 236 if ( GetFloatFromObj(interp, objv[2], &x) != TCL_OK ||237 GetFloatFromObj(interp, objv[3], &y) != TCL_OK) {285 double x, y; 286 287 if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK || 288 Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) { 238 289 return TCL_ERROR; 239 290 } … … 266 317 Tcl_Obj *const *objv) 267 318 { 268 floatyaw, pitch, roll;269 270 if ( GetFloatFromObj(interp, objv[2], &yaw) != TCL_OK ||271 GetFloatFromObj(interp, objv[3], &pitch) != TCL_OK ||272 GetFloatFromObj(interp, objv[4], &roll) != TCL_OK) {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) { 273 324 return TCL_ERROR; 274 325 } … … 282 333 Tcl_Obj *const *objv) 283 334 { 284 floatz;285 286 if ( GetFloatFromObj(interp, objv[2], &z) != TCL_OK) {335 double z; 336 337 if (Tcl_GetDoubleFromObj(interp, objv[2], &z) != TCL_OK) { 287 338 return TCL_ERROR; 288 339 } … … 293 344 294 345 static Rappture::CmdSpec cameraOps[] = { 346 {"get", 1, CameraGetOrientationOp, 2, 2, ""}, 295 347 {"mode", 1, CameraModeOp, 3, 3, "mode"}, 348 {"orient", 3, CameraOrientationOp, 11, 11, "posX posY posZ focalPtX focalPtY focalPtZ viewUpX viewUpY viewUpZ"}, 296 349 {"ortho", 1, CameraOrthoOp, 6, 6, "x y width height"}, 297 350 {"pan", 1, CameraPanOp, 4, 4, "panX panY"}, -
trunk/packages/vizservers/vtkvis/protocol.txt
r2194 r2200 17 17 <axis> = x|y|z|all 18 18 19 camera get 20 Request current camera orientation 19 21 camera mode <mode> 20 22 <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 21 26 camera ortho <x> <y> <width> <height> 22 27 Supply world coordinate bounds of plot area for image camera mode … … 89 94 Replies: 90 95 96 nv>camera orient <posX> <posY> <posZ> <focalPtX> <focalPtY> <focalPtZ> <viewUpX> <viewUpY> <viewUpZ> 97 Reply to "camera get" 91 98 nv>image -type image -bytes <nbytes> 92 99 <binary RGB data>
Note: See TracChangeset
for help on using the changeset viewer.