Changeset 4655 for geovis


Ignore:
Timestamp:
Oct 21, 2014 10:26:44 PM (9 years ago)
Author:
ldelgass
Message:

More selection testing

Location:
geovis/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Renderer.cpp

    r4654 r4655  
    10731073    }
    10741074}
    1075 
     1075#if 0
     1076bool Renderer::mapToLatLong(osgEarth::GeoPoint& mapPoint)
     1077{
     1078    if (getMapSRS() == NULL)
     1079        return false;
     1080    const osgEarth::SpatialReference *outSRS =
     1081        getMapSRS()->getGeographicSRS();
     1082    if (outSRS == NULL)
     1083        return false;
     1084    mapPoint = mapPoint.transform(outSRS);
     1085    return true;
     1086}
     1087#endif
    10761088/**
    10771089 * \brief Map screen mouse coordinates to map coordinates
     
    13681380    (*geom)[3] = osg::Vec3d(longMax, latMax, 0);
    13691381    node->init();
     1382    for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = _selected.begin();
     1383         itr != _selected.end(); ++itr) {
     1384        (*itr)->clearDecoration();
     1385    }
     1386    _selected.clear();
     1387    SelectPlaceNodesVisitor spnv(this, latMin, latMax, longMin, longMax);
     1388    _sceneRoot->accept(spnv);
    13701389    _needsRedraw = true;
     1390}
     1391
     1392void SelectPlaceNodesVisitor::apply(osg::Node& node)
     1393{
     1394    osgEarth::Annotation::PlaceNode *placeNode =
     1395        dynamic_cast<osgEarth::Annotation::PlaceNode*>(&node);
     1396    if (placeNode != NULL) {
     1397        const osgEarth::SpatialReference *outSRS =
     1398            _renderer->getMapSRS()->getGeographicSRS();
     1399        osgEarth::GeoPoint pt = placeNode->getPosition();
     1400        pt = pt.transform(outSRS);
     1401        if (pt.x() >= _longMin && pt.x() <= _longMax &&
     1402            pt.y() >= _latMin && pt.y() <= _latMax) {
     1403            if (_renderer->select(placeNode)) {
     1404                //TRACE("SELECT IT: %p", placeNode);
     1405                placeNode->setDecoration("select");
     1406            }
     1407        }
     1408    }
     1409    traverse(node);
    13711410}
    13721411
     
    13771416        _selectionBox = NULL;
    13781417    }
     1418    for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = _selected.begin();
     1419         itr != _selected.end(); ++itr) {
     1420        (*itr)->clearDecoration();
     1421    }
     1422    _selected.clear();
    13791423    _needsRedraw = true;
    13801424}
     
    14501494    osgEarth::Annotation::AnnotationNode *anno =
    14511495        new osgEarth::Annotation::PlaceNode(_mapNode, osgEarth::GeoPoint(geoSRS, longitude, latitude), labelText, pin);
     1496    anno->setName(labelText);
    14521497    _placeNodes->addChild(anno);
    14531498    osgEarth::Annotation::DecorationInstaller
    1454         highlightInstaller("hover", new osgEarth::Annotation::HighlightDecoration());
    1455     _annotations->accept(highlightInstaller);
     1499        highlightInstaller("select", new osgEarth::Annotation::HighlightDecoration(osg::Vec4f(1,1,0,0.5)));
     1500    _placeNodes->accept(highlightInstaller);
     1501    _mapNode->accept(highlightInstaller);
    14561502    // scale labels when hovering:
    14571503    osgEarth::Annotation::DecorationInstaller
    14581504        scaleInstaller("hover", new osgEarth::Annotation::ScaleDecoration(1.1f));
    14591505    _placeNodes->accept(scaleInstaller);
     1506    _mapNode->accept(scaleInstaller);
    14601507#if 0
    14611508    writeScene("/tmp/test.osg");
     
    14631510    _needsRedraw = true;
    14641511}
    1465 
    1466 void Renderer::hoverPlaceNode(int x, int y, bool invertY)
    1467 {
    1468     if (!_placeNodes.valid()) {
    1469         ERROR("No place nodes");
    1470         return;
    1471     }
    1472     osgEarth::Picker picker(_viewer.get(), _placeNodes.get());
     1512#if 0
     1513void Renderer::hoverFeatureNodes(int x, int y, bool invertY)
     1514{
     1515    if (!_mapNode.valid()) {
     1516        ERROR("No map node");
     1517        return;
     1518    }
     1519    osgEarth::Picker picker(_viewer.get(), _mapNode.get());
    14731520    osgEarth::Picker::Hits hits;
    14741521    float mouseX = (float)x;
     
    14771524        mouseY = ((float)_windowHeight - mouseY);
    14781525    }
     1526    std::set<osgEarth::Annotation::FeatureNode*> toUnHover;
     1527    for (std::set<osgEarth::Annotation::FeatureNode*>::iterator itr = _hovered.begin();
     1528         itr != _hovered.end(); ++itr) {
     1529        toUnHover.insert(*itr);
     1530    }
     1531    if (picker.pick(mouseX, mouseY, hits)) {
     1532        TRACE("Picker hits: %d", hits.size());
     1533        for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin();
     1534             hitr != hits.end(); ++hitr) {
     1535            osgEarth::Annotation::FeatureNode *anno =
     1536                picker.getNode<osgEarth::Annotation::FeatureNode>(*hitr);
     1537            if (anno != NULL) {
     1538                if (_hovered.find(anno) == _hovered.end()) {
     1539                    _hovered.insert(anno);
     1540                    anno->setDecoration("hover");
     1541                    _needsRedraw = true;
     1542                }
     1543                toUnHover.erase(anno);
     1544            }
     1545        }
     1546#if 0
     1547        writeScene("/tmp/test.osgt");
     1548#endif
     1549    }
     1550    for (std::set<osgEarth::Annotation::FeatureNode *>::iterator itr = toUnHover.begin();
     1551         itr != toUnHover.end(); ++itr) {
     1552        _hovered.erase(*itr);
     1553        (*itr)->clearDecoration();
     1554        _needsRedraw = true;
     1555    }
     1556}
     1557#endif
     1558void Renderer::hoverPlaceNode(int x, int y, bool invertY)
     1559{
     1560    if (!_placeNodes.valid()) {
     1561        ERROR("No place nodes");
     1562        return;
     1563    }
     1564    osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get());
     1565    osgEarth::Picker::Hits hits;
     1566    float mouseX = (float)x;
     1567    float mouseY = (float)y;
     1568    if (invertY) {
     1569        mouseY = ((float)_windowHeight - mouseY);
     1570    }
    14791571    std::set<osgEarth::Annotation::AnnotationNode*> toUnHover;
    14801572    for (std::set<osgEarth::Annotation::AnnotationNode*>::iterator itr = _hovered.begin();
     
    14831575    }
    14841576    if (picker.pick(mouseX, mouseY, hits)) {
    1485         TRACE("Picker hit!");
     1577        TRACE("Picker hits: %d", hits.size());
    14861578        for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin();
    14871579             hitr != hits.end(); ++hitr) {
     1580            TRACE("Hit: node %p drawable %p idx %d", picker.getNode<osg::Node>(*hitr), hitr->drawable.get(), hitr->primitiveIndex);
    14881581            osgEarth::Annotation::AnnotationNode *anno =
    14891582                picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr);
    1490             if (anno != NULL) {
     1583            if (anno != NULL && anno->getDecoration().empty()) {
     1584                TRACE("Hit AnnotationNode: %p", anno);
    14911585                if (_hovered.find(anno) == _hovered.end()) {
    14921586                    _hovered.insert(anno);
     
    22722366{
    22732367    if (_sceneRoot.valid()) {
    2274         osgDB::writeNodeFile(*_sceneRoot.get(), file);
    2275     }
    2276 }
     2368        GraphPrintVisitor gpv;
     2369        _sceneRoot->accept(gpv);
     2370        //osgDB::writeNodeFile(*_sceneRoot.get(), file);
     2371    }
     2372}
  • geovis/trunk/Renderer.h

    r4645 r4655  
    434434    void clearBoxSelection();
    435435
     436    bool select(osgEarth::Annotation::AnnotationNode *node)
     437    {
     438        if (_selected.find(node) == _selected.end()) {
     439            _selected.insert(node);
     440            return true;
     441        } else {
     442            return false;
     443        }
     444    }
     445
    436446private:
    437447    typedef std::tr1::unordered_map<ColorMapId, osg::ref_ptr<osg::TransferFunction1D> > ColorMapHashmap;
     
    490500    osg::ref_ptr<osg::Group> _placeNodes;
    491501    std::set<osgEarth::Annotation::AnnotationNode *> _hovered;
     502    std::set<osgEarth::Annotation::AnnotationNode *> _selected;
    492503    osg::ref_ptr<osgEarth::MapNode> _mapNode;
    493504    osg::ref_ptr<osgEarth::Map> _map;
     
    524535};
    525536
     537class SelectPlaceNodesVisitor : public osg::NodeVisitor
     538{
     539public:
     540    SelectPlaceNodesVisitor(Renderer *renderer,
     541                            double latMin, double latMax,
     542                            double longMin, double longMax) :
     543        osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
     544        _renderer(renderer),
     545        _latMin(latMin), _latMax(latMax),
     546        _longMin(longMin), _longMax(longMax)
     547    {}
     548
     549    virtual void apply(osg::Node& node);
     550
     551private:
     552    Renderer *_renderer;
     553    double _latMin, _latMax, _longMin, _longMax;
     554};
     555
    526556}
    527557
  • geovis/trunk/RendererCmd.cpp

    r4645 r4655  
    10791079        osgEarth::Symbology::PolygonSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::PolygonSymbol>();
    10801080        ls->fill()->color() = osgEarth::Symbology::Color::White;
    1081 #if 0
     1081#if 1
    10821082        osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>();
    10831083        alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
     
    11111111        ls->stroke()->color() = osgEarth::Symbology::Color::Black;
    11121112        ls->stroke()->width() = 2.0f;
    1113 #if 0
     1113#if 1
    11141114        osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>();
    11151115        alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
  • geovis/trunk/Trace.h

    r4422 r4655  
    99#define GEOVIS_TRACE_H
    1010
     11#include <cstring>
    1112#include <string>
    1213
    1314#include <syslog.h>
     15
     16#include <osg/NodeVisitor>
    1417
    1518namespace GeoVis {
     
    3942#define USER_ERROR(...) GeoVis::logUserMessage(__VA_ARGS__)
    4043
     44class GraphPrintVisitor : public osg::NodeVisitor
     45{
     46public:
     47    GraphPrintVisitor()
     48        : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
     49    {}
     50
     51    virtual void apply(osg::Node& node)
     52    {
     53        char space[256];
     54        size_t len = getNodePath().size();
     55        memset(space, ' ', len);
     56        space[len] = '\0';
     57        TRACE("%s%s (%s) %p", space, node.className(), node.getName().c_str(), &node);
     58        traverse(node);
     59    }
     60};
     61
    4162}
    4263
Note: See TracChangeset for help on using the changeset viewer.