- Timestamp:
- Sep 10, 2014, 1:49:20 PM (10 years ago)
- Location:
- geovis/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/RenderServer.cpp
r4628 r4632 118 118 TARGA_BYTES_PER_PIXEL); 119 119 #else 120 queuePPM(queue, "nv>image -type image -bytes", 120 char cmd[256]; 121 sprintf(cmd, "nv>image -type image -token %lu -bytes", g_stats.nCommands); 122 queuePPM(queue, cmd, 121 123 imgData, 122 124 g_renderer->getWindowWidth(), … … 401 403 if (cmdStatus > 1) { 402 404 sendAck(); 405 } else { 406 TRACE("No render required and status = %d", cmdStatus); 403 407 } 404 408 } -
geovis/trunk/Renderer.cpp
r4629 r4632 11 11 #include <cmath> 12 12 #include <cstdlib> 13 14 #include <set> 13 15 14 16 #include <sys/types.h> … … 41 43 #include <osgEarth/ModelLayer> 42 44 #include <osgEarth/DateTime> 45 #include <osgEarth/Pickers> 46 #include <osgEarthAnnotation/AnnotationNode> 47 #include <osgEarthAnnotation/PlaceNode> 48 #include <osgEarthAnnotation/HighlightDecoration> 49 #include <osgEarthAnnotation/ScaleDecoration> 43 50 #include <osgEarthUtil/EarthManipulator> 44 51 #if defined(USE_OSGEARTH_TRUNK) || OSGEARTH_MIN_VERSION_REQUIRED(2, 5, 1) … … 72 79 73 80 #define BASE_IMAGE "/usr/share/osgearth/data/world.tif" 81 #define PIN_ICON "/usr/share/osgearth/data/placemark32.png" 74 82 75 83 using namespace GeoVis; … … 87 95 _bgColor[2] = 0; 88 96 //setMaximumFrameRateInHertz(15.0); 89 // 100 Mbit97 // 100 Mbps 90 98 setMaximumBitrate(1.0e8); 91 99 _lastFrameTime = _minFrameTime; 92 100 TRACE("Bandwidth target: %.2f Mbps", (float)(getMaximumBitrate()/1.0e6)); 93 101 TRACE("Frame rate target: %.2f Hz", (float)getMaximumFrameRateInHertz()); 102 TRACE("Frame time target: %.2f msec", _minFrameTime * 1000.0f); 94 103 95 104 char *base = getenv("MAP_BASE_URI"); … … 1229 1238 } 1230 1239 1240 void Renderer::addPlaceNode(double latitude, double longitude, char *labelText) 1241 { 1242 if (!_mapNode.valid()) { 1243 ERROR("No map node"); 1244 return; 1245 } 1246 if (!_annotations.valid()) { 1247 _annotations = new osg::Group(); 1248 _sceneRoot->addChild(_annotations.get()); 1249 _placeNodes = new osg::Group(); 1250 osgEarth::Decluttering::setEnabled(_placeNodes->getOrCreateStateSet(), true); 1251 _annotations->addChild(_placeNodes.get()); 1252 } 1253 1254 const osgEarth::SpatialReference* geoSRS = _mapNode->getMapSRS()->getGeographicSRS(); 1255 1256 osgEarth::Symbology::Style pin; 1257 pin.getOrCreate<osgEarth::Symbology::IconSymbol>()->url()->setLiteral(PIN_ICON); 1258 osgEarth::Annotation::AnnotationNode *anno = new osgEarth::Annotation::PlaceNode(_mapNode, osgEarth::GeoPoint(geoSRS, longitude, latitude), labelText, pin); 1259 _placeNodes->addChild(anno); 1260 osgEarth::Annotation::DecorationInstaller 1261 highlightInstaller("hover", new osgEarth::Annotation::HighlightDecoration()); 1262 _annotations->accept(highlightInstaller); 1263 // scale labels when hovering: 1264 osgEarth::Annotation::DecorationInstaller 1265 scaleInstaller("hover", new osgEarth::Annotation::ScaleDecoration(1.1f)); 1266 _placeNodes->accept(scaleInstaller); 1267 _needsRedraw = true; 1268 } 1269 1270 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1271 { 1272 osgEarth::Picker picker(_viewer.get(), _placeNodes.get()); 1273 osgEarth::Picker::Hits hits; 1274 float mouseX = (float)x; 1275 float mouseY = (float)y; 1276 if (invertY) { 1277 mouseY = ((float)_windowHeight - mouseY); 1278 } 1279 std::set<osgEarth::Annotation::AnnotationNode*> toUnHover; 1280 for (std::set<osgEarth::Annotation::AnnotationNode*>::iterator itr = _hovered.begin(); 1281 itr != _hovered.end(); ++itr) { 1282 toUnHover.insert(*itr); 1283 } 1284 if (picker.pick(mouseX, mouseY, hits)) { 1285 TRACE("Picker hit!"); 1286 for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin(); 1287 hitr != hits.end(); ++hitr) { 1288 osgEarth::Annotation::AnnotationNode *anno = 1289 picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr); 1290 if (anno != NULL) { 1291 if (_hovered.find(anno) == _hovered.end()) { 1292 _hovered.insert(anno); 1293 anno->setDecoration("hover"); 1294 _needsRedraw = true; 1295 } 1296 toUnHover.erase(anno); 1297 } 1298 } 1299 } 1300 for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = toUnHover.begin(); 1301 itr != toUnHover.end(); ++itr) { 1302 _hovered.erase(*itr); 1303 (*itr)->clearDecoration(); 1304 _needsRedraw = true; 1305 } 1306 } 1307 1308 void Renderer::deletePlaceNode(int x, int y, bool invertY) 1309 { 1310 osgEarth::Picker picker(_viewer.get(), _placeNodes.get()); 1311 osgEarth::Picker::Hits hits; 1312 float mouseX = (float)x; 1313 float mouseY = (float)y; 1314 if (invertY) { 1315 mouseY = ((float)_windowHeight - mouseY); 1316 } 1317 if (picker.pick(mouseX, mouseY, hits)) { 1318 TRACE("Picker hit!"); 1319 // prevent multiple hits on the same instance 1320 std::set<osgEarth::Annotation::AnnotationNode *> fired; 1321 for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin(); 1322 hitr != hits.end(); ++hitr) { 1323 osgEarth::Annotation::AnnotationNode *anno = 1324 picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr); 1325 if (anno != NULL && fired.find(anno) == fired.end()) { 1326 fired.insert(anno); 1327 _needsRedraw = true; 1328 } 1329 } 1330 for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = fired.begin(); 1331 itr != fired.end(); ++itr) { 1332 (*itr)->clearDecoration(); 1333 _placeNodes->removeChild(*itr); 1334 if (_hovered.find(*itr) != _hovered.end()) { 1335 _hovered.erase(*itr); 1336 } 1337 } 1338 } else { 1339 TRACE("NO Picker hits"); 1340 } 1341 } 1342 1231 1343 void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts) 1232 1344 { … … 1625 1737 return -1L; 1626 1738 if (_lastFrameTime < _minFrameTime) { 1627 return (long)1 000000.0*(_minFrameTime - _lastFrameTime);1739 return (long)1.0e6*(_minFrameTime - _lastFrameTime); 1628 1740 } else { 1629 1741 // No timeout (poll) … … 1674 1786 osg::Timer_t endFrameTick = osg::Timer::instance()->tick(); 1675 1787 _lastFrameTime = osg::Timer::instance()->delta_s(_startFrameTime, endFrameTick); 1676 TRACE("Frame time: %g sec", _lastFrameTime); 1788 if (_lastFrameTime > _minFrameTime) { 1789 ERROR("BROKE FRAME by %.2f msec", (_lastFrameTime - _minFrameTime)*1000.0f); 1790 } else { 1791 TRACE("Frame time: %.2f msec", _lastFrameTime*1000.0f); 1792 } 1677 1793 #ifdef USE_THROTTLING_SLEEP 1678 1794 if (_lastFrameTime < _minFrameTime) { 1679 TRACE("Sleeping for % g secs", _minFrameTime - _lastFrameTime);1795 TRACE("Sleeping for %.2f msec", (_minFrameTime - _lastFrameTime)*1000.0f); 1680 1796 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*(_minFrameTime - _lastFrameTime))); 1681 1797 } … … 1693 1809 if (_viewer.valid() && checkNeedToDoFrame()) { 1694 1810 TRACE("Enter needsRedraw=%d", _needsRedraw ? 1 : 0); 1695 #ifndef SLEEP_AFTER_QUEUE_FRAME 1696 osg::Timer_t startFrameTick = osg::Timer::instance()->tick(); 1697 #endif 1811 _renderStartTime = osg::Timer::instance()->tick(); 1698 1812 TRACE("Before frame()"); 1699 1813 _viewer->frame(); 1700 1814 TRACE("After frame()"); 1815 _renderStopTime = osg::Timer::instance()->tick(); 1816 _renderTime = osg::Timer::instance()->delta_s(_renderStartTime, _renderStopTime); 1817 TRACE("Render time: %g msec", _renderTime * 1000.0); 1701 1818 #ifndef SLEEP_AFTER_QUEUE_FRAME 1702 osg::Timer_t endFrameTick = osg::Timer::instance()->tick(); 1703 _lastFrameTime = osg::Timer::instance()->delta_s(startFrameTick, endFrameTick); 1704 TRACE("Frame time: %g sec", _lastFrameTime); 1819 _lastFrameTime = _renderTime; 1705 1820 #ifdef USE_THROTTLING_SLEEP 1706 1821 if (_lastFrameTime < _minFrameTime) { 1707 TRACE("Sleeping for % g secs", _minFrameTime - _lastFrameTime);1708 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1 000000.0*(_minFrameTime - _lastFrameTime)));1822 TRACE("Sleeping for %.2f msec", (_minFrameTime - _lastFrameTime)*1000.0f); 1823 OpenThreads::Thread::microSleep(static_cast<unsigned int>(1.0e6*(_minFrameTime - _lastFrameTime))); 1709 1824 } 1710 1825 #endif … … 1717 1832 _needsRedraw = false; 1718 1833 return true; 1719 } else 1834 } else { 1835 _renderStartTime = _renderStopTime = osg::Timer::instance()->tick(); 1836 _renderTime = 0; 1720 1837 return false; 1838 } 1721 1839 } 1722 1840 -
geovis/trunk/Renderer.h
r4629 r4632 31 31 #include <osgEarth/ModelSource> 32 32 #include <osgEarth/GeoData> 33 #include <osgEarthAnnotation/AnnotationNode> 33 34 #include <osgEarthUtil/EarthManipulator> 34 35 #include <osgEarthUtil/MouseCoordsTool> … … 349 350 } 350 351 352 void addPlaceNode(double latitude, double longitude, char *labelText); 353 354 void hoverPlaceNode(int x, int y, bool invertY = true); 355 356 void deletePlaceNode(int x, int y, bool invertY = true); 357 351 358 bool getMousePoint(double *x, double *y, double *z) 352 359 { … … 439 446 double _minFrameTime; 440 447 double _lastFrameTime; 448 double _renderTime; 441 449 osg::Timer_t _startFrameTime; 450 osg::Timer_t _renderStartTime; 451 osg::Timer_t _renderStopTime; 442 452 443 453 ColorMapHashmap _colorMaps; … … 448 458 osg::ref_ptr<osg::Group> _sceneRoot; 449 459 osg::ref_ptr<osg::Group> _graticule; 460 osg::ref_ptr<osg::Group> _annotations; 461 osg::ref_ptr<osg::Group> _placeNodes; 462 std::set<osgEarth::Annotation::AnnotationNode *> _hovered; 450 463 osg::ref_ptr<osgEarth::MapNode> _mapNode; 451 464 osg::ref_ptr<osgEarth::Map> _map; -
geovis/trunk/RendererCmd.cpp
r4629 r4632 1277 1277 } 1278 1278 return TCL_OK; 1279 } 1280 1281 static int 1282 MapPinAddOp(ClientData clientData, Tcl_Interp *interp, int objc, 1283 Tcl_Obj *const *objv) 1284 { 1285 int x, y; 1286 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 1287 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 1288 return TCL_ERROR; 1289 } 1290 char *label = NULL; 1291 if (objc > 5) { 1292 label = Tcl_GetString(objv[5]); 1293 } 1294 1295 if (g_renderer->getMapSRS() == NULL) { 1296 Tcl_AppendResult(interp, "Could not get map SRS", (char*)NULL); 1297 return TCL_ERROR; 1298 } 1299 1300 // Get lat/long 1301 double latitude, longitude; 1302 const osgEarth::SpatialReference *outSRS = 1303 g_renderer->getMapSRS()->getGeographicSRS(); 1304 osgEarth::GeoPoint mapPoint; 1305 if (g_renderer->mapMouseCoords(x, y, mapPoint)) { 1306 mapPoint = mapPoint.transform(outSRS); 1307 longitude = mapPoint.x(); 1308 latitude = mapPoint.y(); 1309 } else { 1310 USER_ERROR("Can't add pin here"); 1311 return TCL_OK; 1312 } 1313 1314 g_renderer->addPlaceNode(latitude, longitude, label); 1315 return TCL_OK; 1316 } 1317 1318 static int 1319 MapPinDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 1320 Tcl_Obj *const *objv) 1321 { 1322 int x, y; 1323 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 1324 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 1325 return TCL_ERROR; 1326 } 1327 1328 g_renderer->deletePlaceNode(x, y); 1329 return TCL_OK; 1330 } 1331 1332 static int 1333 MapPinHoverOp(ClientData clientData, Tcl_Interp *interp, int objc, 1334 Tcl_Obj *const *objv) 1335 { 1336 int x, y; 1337 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 1338 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 1339 return TCL_ERROR; 1340 } 1341 1342 g_renderer->hoverPlaceNode(x, y); 1343 return TCL_OK; 1344 } 1345 1346 static CmdSpec mapPinOps[] = { 1347 {"add", 1, MapPinAddOp, 5, 6, "x y ?label?"}, 1348 {"delete", 1, MapPinDeleteOp, 5, 5, "x y"}, 1349 {"hover", 1, MapPinHoverOp, 5, 5, "x y"}, 1350 }; 1351 static int nMapPinOps = NumCmdSpecs(mapPinOps); 1352 1353 static int 1354 MapPinOp(ClientData clientData, Tcl_Interp *interp, int objc, 1355 Tcl_Obj *const *objv) 1356 { 1357 Tcl_ObjCmdProc *proc; 1358 1359 proc = GetOpFromObj(interp, nMapPinOps, mapPinOps, 1360 CMDSPEC_ARG2, objc, objv, 0); 1361 if (proc == NULL) { 1362 return TCL_ERROR; 1363 } 1364 return (*proc) (clientData, interp, objc, objv); 1279 1365 } 1280 1366 … … 1554 1640 {"layer", 2, MapLayerOp, 3, 0, "op ?params...?"}, 1555 1641 {"load", 2, MapLoadOp, 4, 5, "options"}, 1556 {"posdisp", 1, MapPositionDisplayOp, 3, 5, "bool ?format? ?precision?"}, 1642 {"pin", 2, MapPinOp, 3, 0, "op ?params...?"}, 1643 {"posdisp", 2, MapPositionDisplayOp, 3, 5, "bool ?format? ?precision?"}, 1557 1644 {"reset", 1, MapResetOp, 3, 8, "type ?profile xmin ymin xmax ymax?"}, 1558 1645 {"scalebar", 1, MapScaleBarOp, 3, 4, "bool ?units?"}, … … 1951 2038 struct timeval start, finish; 1952 2039 gettimeofday(&start, NULL); 2040 g_stats.nCommands++; 1953 2041 status = ExecuteCommand(interp, &command); 1954 2042 gettimeofday(&finish, NULL); 1955 2043 g_stats.cmdTime += (MSECS_ELAPSED(start, finish) / 1.0e+3); 1956 g_stats.nCommands++;1957 2044 if (status == TCL_BREAK) { 1958 2045 return 2; /* This was caused by a "imgflush"
Note: See TracChangeset
for help on using the changeset viewer.