- Timestamp:
- Oct 27, 2013, 12:18:57 AM (11 years ago)
- Location:
- trunk/packages/vizservers/geovis
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/geovis/Makefile.in
r4013 r4014 42 42 -losgDB \ 43 43 -losgViewer \ 44 -losgGA \ 44 45 -losg \ 45 46 -lOpenThreads 46 47 47 OSGEARTH_LIB_DIR = 48 OSGEARTH_LIB_DIR = 48 49 OSGEARTH_INC_SPEC = 49 50 OSGEARTH_LIB_SPEC = \ -
trunk/packages/vizservers/geovis/RenderServer.cpp
r4009 r4014 507 507 } 508 508 509 double x, y, z; 510 if (g_renderer->getMousePoint(&x, &y, &z)) { 511 // send coords to client 512 size_t length; 513 char mesg[256]; 514 515 length = snprintf(mesg, sizeof(mesg), 516 "nv>dataset coords %g %g %g\n", x, y, z); 517 518 queueResponse(mesg, length, Response::VOLATILE); 519 } 520 509 521 if (g_inBufPtr->status() == ReadBuffer::ENDFILE) 510 522 break; -
trunk/packages/vizservers/geovis/Renderer.cpp
r4013 r4014 24 24 #include <osgEarth/ModelLayer> 25 25 #include <osgEarthUtil/EarthManipulator> 26 #include <osgEarthUtil/MouseCoordsTool> 26 27 27 28 #include "Renderer.h" … … 53 54 _manipulator = new osgEarth::Util::EarthManipulator; 54 55 _viewer->setCameraManipulator(_manipulator); 56 _coordsCallback = new MouseCoordsCallback(); 55 57 _viewer->getCamera()->setNearFarRatio(0.00002); 56 58 _viewer->getCamera()->setSmallFeatureCullingPixelSize(-1.0f); 57 59 _viewer->setUpViewInWindow(0, 0, _windowWidth, _windowHeight); 58 60 _viewer->realize(); 61 if (_viewer->getEventQueue()->getUseFixedMouseInputRange()) { 62 osgGA::GUIEventAdapter* ea = _viewer->getEventQueue()->getCurrentEventState(); 63 TRACE("Mouse range: %g %g %g %g", ea->getXmin(), ea->getXmax(), ea->getYmin(), ea->getYmax()); 64 } else { 65 osgGA::GUIEventAdapter* ea = _viewer->getEventQueue()->getCurrentEventState(); 66 TRACE("Not fixed mouse range: %g %g %g %g", ea->getXmin(), ea->getXmax(), ea->getYmin(), ea->getYmax()); 67 } 59 68 if (_viewer->getViewerStats() != NULL) { 60 69 TRACE("Enabling stats"); … … 80 89 _map = mapNode->getMap(); 81 90 } 91 if (_mouseCoordsTool.valid()) 92 _viewer->removeEventHandler(_mouseCoordsTool); 93 _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode); 94 _mouseCoordsTool->addCallback(_coordsCallback); 95 _viewer->addEventHandler(_mouseCoordsTool); 82 96 _viewer->setSceneData(_sceneRoot.get()); 83 97 _manipulator->setNode(NULL); … … 194 208 void Renderer::setCameraOrientation(const double quat[4], bool absolute) 195 209 { 210 _manipulator->setRotation(osg::Quat(quat[1], quat[2], quat[3], quat[0])); 196 211 _needsRedraw = true; 197 212 } … … 254 269 255 270 _manipulator->zoom(0, z); 271 _needsRedraw = true; 272 } 273 274 void Renderer::mouseDoubleClick(int button, double x, double y) 275 { 276 _viewer->getEventQueue()->mouseDoubleButtonPress((float)x, (float)y, button); 277 _needsRedraw = true; 278 } 279 280 void Renderer::mouseClick(int button, double x, double y) 281 { 282 _viewer->getEventQueue()->mouseButtonPress((float)x, (float)y, button); 283 _needsRedraw = true; 284 } 285 286 void Renderer::mouseDrag(int button, double x, double y) 287 { 288 _viewer->getEventQueue()->mouseMotion((float)x, (float)y); 289 _needsRedraw = true; 290 } 291 292 void Renderer::mouseRelease(int button, double x, double y) 293 { 294 _viewer->getEventQueue()->mouseButtonRelease((float)x, (float)y, button); 295 _needsRedraw = true; 296 } 297 298 void Renderer::mouseMotion(double x, double y) 299 { 300 _viewer->getEventQueue()->mouseMotion((float)x, (float)y); 301 _needsRedraw = true; 302 } 303 304 void Renderer::mouseScroll(int direction) 305 { 306 _viewer->getEventQueue()->mouseScroll((direction > 0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN)); 256 307 _needsRedraw = true; 257 308 } -
trunk/packages/vizservers/geovis/Renderer.h
r4013 r4014 25 25 #include <osgEarth/TileSource> 26 26 #include <osgEarth/ModelSource> 27 #include <osgEarth/GeoData> 27 28 #include <osgEarthUtil/EarthManipulator> 29 #include <osgEarthUtil/MouseCoordsTool> 28 30 29 31 #include "Types.h" … … 78 80 }; 79 81 82 class MouseCoordsCallback : public osgEarth::Util::MouseCoordsTool::Callback 83 { 84 public: 85 MouseCoordsCallback() : 86 osgEarth::Util::MouseCoordsTool::Callback(), 87 _havePoint(false) 88 {} 89 90 void set(const osgEarth::GeoPoint& p, osg::View* view, osgEarth::MapNode* mapNode) 91 { 92 // p.y(), p.x() 93 _pt = p; 94 _havePoint = true; 95 } 96 97 void reset(osg::View* view, osgEarth::MapNode* mapNode) 98 { 99 // Out of range click 100 //_havePoint = false; 101 } 102 103 bool report(double *x, double *y, double *z) 104 { 105 if (_havePoint) { 106 *x = _pt.x(); 107 *y = _pt.y(); 108 *z = _pt.z(); 109 _havePoint = false; 110 return true; 111 } 112 return false; 113 } 114 115 private: 116 bool _havePoint; 117 osgEarth::GeoPoint _pt; 118 }; 119 80 120 /** 81 121 * \brief GIS Renderer … … 143 183 void zoomCamera(double z, bool absolute = false); 144 184 185 // Mouse events 186 187 void mouseClick(int button, double x, double y); 188 189 void mouseDoubleClick(int button, double x, double y); 190 191 void mouseDrag(int button, double x, double y); 192 193 void mouseRelease(int button, double x, double y); 194 195 void mouseMotion(double x, double y); 196 197 void mouseScroll(int direction); 198 145 199 // Rendering an image 146 200 … … 152 206 153 207 osg::Image *getRenderedFrame(); 208 209 bool getMousePoint(double *x, double *y, double *z) 210 { 211 return _coordsCallback->report(x, y, z); 212 } 154 213 155 214 private: … … 161 220 162 221 osg::ref_ptr<osg::Node> _sceneRoot; 222 osg::ref_ptr<osgEarth::MapNode> _mapNode; 163 223 osg::ref_ptr<osgEarth::Map> _map; 164 224 osg::ref_ptr<osgViewer::Viewer> _viewer; 165 225 osg::ref_ptr<ScreenCaptureCallback> _captureCallback; 226 osg::ref_ptr<osgEarth::Util::MouseCoordsTool> _mouseCoordsTool; 227 osg::ref_ptr<MouseCoordsCallback> _coordsCallback; 166 228 osg::ref_ptr<osgEarth::Util::EarthManipulator> _manipulator; 167 229 }; -
trunk/packages/vizservers/geovis/RendererCmd.cpp
r4009 r4014 309 309 lastCmdStatus = TCL_BREAK; 310 310 return TCL_OK; 311 } 312 313 static int 314 MouseClickOp(ClientData clientData, Tcl_Interp *interp, int objc, 315 Tcl_Obj *const *objv) 316 { 317 int button; 318 double x, y; 319 320 if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) { 321 return TCL_ERROR; 322 } 323 if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK || 324 Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) { 325 return TCL_ERROR; 326 } 327 328 g_renderer->mouseClick(button, x, y); 329 return TCL_OK; 330 } 331 332 static int 333 MouseDoubleClickOp(ClientData clientData, Tcl_Interp *interp, int objc, 334 Tcl_Obj *const *objv) 335 { 336 int button; 337 double x, y; 338 339 if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) { 340 return TCL_ERROR; 341 } 342 if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK || 343 Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) { 344 return TCL_ERROR; 345 } 346 347 g_renderer->mouseDoubleClick(button, x, y); 348 return TCL_OK; 349 } 350 351 static int 352 MouseDragOp(ClientData clientData, Tcl_Interp *interp, int objc, 353 Tcl_Obj *const *objv) 354 { 355 int button; 356 double x, y; 357 358 if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) { 359 return TCL_ERROR; 360 } 361 if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK || 362 Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) { 363 return TCL_ERROR; 364 } 365 366 g_renderer->mouseDrag(button, x, y); 367 return TCL_OK; 368 } 369 370 static int 371 MouseMotionOp(ClientData clientData, Tcl_Interp *interp, int objc, 372 Tcl_Obj *const *objv) 373 { 374 double x, y; 375 376 if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK || 377 Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) { 378 return TCL_ERROR; 379 } 380 381 g_renderer->mouseMotion(x, y); 382 return TCL_OK; 383 } 384 385 static int 386 MouseReleaseOp(ClientData clientData, Tcl_Interp *interp, int objc, 387 Tcl_Obj *const *objv) 388 { 389 int button; 390 double x, y; 391 392 if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) { 393 return TCL_ERROR; 394 } 395 if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK || 396 Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) { 397 return TCL_ERROR; 398 } 399 400 g_renderer->mouseRelease(button, x, y); 401 return TCL_OK; 402 } 403 404 static int 405 MouseScrollOp(ClientData clientData, Tcl_Interp *interp, int objc, 406 Tcl_Obj *const *objv) 407 { 408 int direction; 409 410 if (Tcl_GetIntFromObj(interp, objv[2], &direction) != TCL_OK) { 411 return TCL_ERROR; 412 } 413 414 g_renderer->mouseScroll(direction); 415 return TCL_OK; 416 } 417 418 static Rappture::CmdSpec mouseOps[] = { 419 {"click", 1, MouseClickOp, 5, 5, "button x y"}, 420 {"dblclick", 2, MouseDoubleClickOp, 5, 5, "button x y"}, 421 {"drag", 2, MouseDragOp, 5, 5, "button x y"}, 422 {"motion", 1, MouseMotionOp, 4, 4, "x y"}, 423 {"release", 1, MouseReleaseOp, 5, 5, "button x y"}, 424 {"scroll", 1, MouseScrollOp, 3, 3, "direction"}, 425 }; 426 static int nMouseOps = NumCmdSpecs(mouseOps); 427 428 static int 429 MouseCmd(ClientData clientData, Tcl_Interp *interp, int objc, 430 Tcl_Obj *const *objv) 431 { 432 Tcl_ObjCmdProc *proc; 433 434 proc = Rappture::GetOpFromObj(interp, nMouseOps, mouseOps, 435 Rappture::CMDSPEC_ARG1, objc, objv, 0); 436 if (proc == NULL) { 437 return TCL_ERROR; 438 } 439 return (*proc) (clientData, interp, objc, objv); 311 440 } 312 441 … … 536 665 Tcl_CreateObjCommand(interp, "clientinfo", ClientInfoCmd, clientData, NULL); 537 666 Tcl_CreateObjCommand(interp, "imgflush", ImageFlushCmd, clientData, NULL); 667 Tcl_CreateObjCommand(interp, "mouse", MouseCmd, clientData, NULL); 538 668 Tcl_CreateObjCommand(interp, "renderer", RendererCmd, clientData, NULL); 539 669 Tcl_CreateObjCommand(interp, "screen", ScreenCmd, clientData, NULL); … … 548 678 Tcl_DeleteCommand(interp, "clientinfo"); 549 679 Tcl_DeleteCommand(interp, "imgflush"); 680 Tcl_DeleteCommand(interp, "mouse"); 550 681 Tcl_DeleteCommand(interp, "renderer"); 551 682 Tcl_DeleteCommand(interp, "screen");
Note: See TracChangeset
for help on using the changeset viewer.