Changeset 4632


Ignore:
Timestamp:
Sep 10, 2014, 1:49:20 PM (10 years ago)
Author:
ldelgass
Message:

Add pin annotations for testing

Location:
geovis/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/RenderServer.cpp

    r4628 r4632  
    118118             TARGA_BYTES_PER_PIXEL);
    119119#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,
    121123             imgData,
    122124             g_renderer->getWindowWidth(),
     
    401403            if (cmdStatus > 1) {
    402404                sendAck();
     405            } else {
     406                TRACE("No render required and status = %d", cmdStatus);
    403407            }
    404408        }
  • geovis/trunk/Renderer.cpp

    r4629 r4632  
    1111#include <cmath>
    1212#include <cstdlib>
     13
     14#include <set>
    1315
    1416#include <sys/types.h>
     
    4143#include <osgEarth/ModelLayer>
    4244#include <osgEarth/DateTime>
     45#include <osgEarth/Pickers>
     46#include <osgEarthAnnotation/AnnotationNode>
     47#include <osgEarthAnnotation/PlaceNode>
     48#include <osgEarthAnnotation/HighlightDecoration>
     49#include <osgEarthAnnotation/ScaleDecoration>
    4350#include <osgEarthUtil/EarthManipulator>
    4451#if defined(USE_OSGEARTH_TRUNK) || OSGEARTH_MIN_VERSION_REQUIRED(2, 5, 1)
     
    7279
    7380#define BASE_IMAGE "/usr/share/osgearth/data/world.tif"
     81#define PIN_ICON "/usr/share/osgearth/data/placemark32.png"
    7482
    7583using namespace GeoVis;
     
    8795    _bgColor[2] = 0;
    8896    //setMaximumFrameRateInHertz(15.0);
    89     // 100Mbit
     97    // 100 Mbps
    9098    setMaximumBitrate(1.0e8);
    9199    _lastFrameTime = _minFrameTime;
    92100    TRACE("Bandwidth target: %.2f Mbps", (float)(getMaximumBitrate()/1.0e6));
    93101    TRACE("Frame rate target: %.2f Hz", (float)getMaximumFrameRateInHertz());
     102    TRACE("Frame time target: %.2f msec", _minFrameTime * 1000.0f);
    94103
    95104    char *base = getenv("MAP_BASE_URI");
     
    12291238}
    12301239
     1240void 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
     1270void 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
     1308void 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
    12311343void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts)
    12321344{
     
    16251737        return -1L;
    16261738    if (_lastFrameTime < _minFrameTime) {
    1627         return (long)1000000.0*(_minFrameTime - _lastFrameTime);
     1739        return (long)1.0e6*(_minFrameTime - _lastFrameTime);
    16281740    } else {
    16291741        // No timeout (poll)
     
    16741786    osg::Timer_t endFrameTick = osg::Timer::instance()->tick();
    16751787    _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    }
    16771793#ifdef USE_THROTTLING_SLEEP
    16781794    if (_lastFrameTime < _minFrameTime) {
    1679         TRACE("Sleeping for %g secs", _minFrameTime - _lastFrameTime);
     1795        TRACE("Sleeping for %.2f msec", (_minFrameTime - _lastFrameTime)*1000.0f);
    16801796        OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*(_minFrameTime - _lastFrameTime)));
    16811797    }
     
    16931809    if (_viewer.valid() && checkNeedToDoFrame()) {
    16941810        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();
    16981812        TRACE("Before frame()");
    16991813        _viewer->frame();
    17001814        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);
    17011818#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;
    17051820#ifdef USE_THROTTLING_SLEEP
    17061821        if (_lastFrameTime < _minFrameTime) {
    1707             TRACE("Sleeping for %g secs", _minFrameTime - _lastFrameTime);
    1708             OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.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)));
    17091824        }
    17101825#endif
     
    17171832        _needsRedraw = false;
    17181833        return true;
    1719     } else
     1834    } else {
     1835        _renderStartTime = _renderStopTime = osg::Timer::instance()->tick();
     1836        _renderTime = 0;
    17201837        return false;
     1838    }
    17211839}
    17221840
  • geovis/trunk/Renderer.h

    r4629 r4632  
    3131#include <osgEarth/ModelSource>
    3232#include <osgEarth/GeoData>
     33#include <osgEarthAnnotation/AnnotationNode>
    3334#include <osgEarthUtil/EarthManipulator>
    3435#include <osgEarthUtil/MouseCoordsTool>
     
    349350    }
    350351
     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
    351358    bool getMousePoint(double *x, double *y, double *z)
    352359    {
     
    439446    double _minFrameTime;
    440447    double _lastFrameTime;
     448    double _renderTime;
    441449    osg::Timer_t _startFrameTime;
     450    osg::Timer_t _renderStartTime;
     451    osg::Timer_t _renderStopTime;
    442452
    443453    ColorMapHashmap _colorMaps;
     
    448458    osg::ref_ptr<osg::Group> _sceneRoot;
    449459    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;
    450463    osg::ref_ptr<osgEarth::MapNode> _mapNode;
    451464    osg::ref_ptr<osgEarth::Map> _map;
  • geovis/trunk/RendererCmd.cpp

    r4629 r4632  
    12771277    }
    12781278    return TCL_OK;
     1279}
     1280
     1281static int
     1282MapPinAddOp(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
     1318static int
     1319MapPinDeleteOp(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
     1332static int
     1333MapPinHoverOp(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
     1346static 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};
     1351static int nMapPinOps = NumCmdSpecs(mapPinOps);
     1352
     1353static int
     1354MapPinOp(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);
    12791365}
    12801366
     
    15541640    {"layer",    2, MapLayerOp,           3, 0, "op ?params...?"},
    15551641    {"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?"},
    15571644    {"reset",    1, MapResetOp,           3, 8, "type ?profile xmin ymin xmax ymax?"},
    15581645    {"scalebar", 1, MapScaleBarOp,        3, 4, "bool ?units?"},
     
    19512038            struct timeval start, finish;
    19522039            gettimeofday(&start, NULL);
     2040            g_stats.nCommands++;
    19532041            status = ExecuteCommand(interp, &command);
    19542042            gettimeofday(&finish, NULL);
    19552043            g_stats.cmdTime += (MSECS_ELAPSED(start, finish) / 1.0e+3);
    1956             g_stats.nCommands++;
    19572044            if (status == TCL_BREAK) {
    19582045                return 2;               /* This was caused by a "imgflush"
Note: See TracChangeset for help on using the changeset viewer.