Changeset 5938


Ignore:
Timestamp:
Dec 3, 2015 12:30:50 PM (7 years ago)
Author:
ldelgass
Message:

Try finding FeatureSourceIndexNodes? in scene graph to lookup global ID for a
feature ID.

Location:
geovis/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Makefile.in

    r5873 r5938  
    206206PPMWriter.o: PPMWriter.h ResponseQueue.h Trace.h
    207207ReadBuffer.o: ReadBuffer.h Trace.h
    208 Renderer.o: Renderer.h Trace.h Picker.h MouseCoordsTool.h ScaleBar.h FileUtil.h
     208Renderer.o: Renderer.h Trace.h Picker.h MouseCoordsTool.h ScaleBar.h FileUtil.h Util.h
    209209RendererCmd.o: Renderer.h ReadBuffer.h ResponseQueue.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h
    210210RenderServer.o: RenderServer.h RendererCmd.h Renderer.h ReadBuffer.h ResponseQueue.h Trace.h PPMWriter.h TGAWriter.h Stats.h
  • geovis/trunk/Picker.cpp

    r5890 r5938  
    2929
    3030static const char *highlightVert =
    31     "#version 130\n"
     31    "#version " GLSL_VERSION_STR "\n"
    3232    "uniform uint objectid_to_highlight; \n"
    3333    "uint oe_index_objectid;      // Stage global containing object id \n"
     
    3939
    4040static const char *highlightFrag =
    41     "#version 130\n"
     41    "#version " GLSL_VERSION_STR "\n"
    4242    "flat in int selected; \n"
    4343    "void highlightFragment(inout vec4 color) \n"
     
    5151static void installHighlighter(osg::StateSet *stateSet, int attrLocation)
    5252{
     53    TRACE("GLSL Version: %s", GLSL_VERSION_STR);
    5354    // This shader program will highlight the selected object.
    5455    osgEarth::VirtualProgram *vp = osgEarth::VirtualProgram::getOrCreate(stateSet);
     
    6263    s_highlightUniform = new osg::Uniform("objectid_to_highlight", 0u);
    6364    stateSet->addUniform(s_highlightUniform);
     65}
     66
     67void GeoVis::setHighlightByObjectID(osgEarth::ObjectID id)
     68{
     69    if (s_highlightUniform != NULL) {
     70        s_highlightUniform->set(id);
     71    }
     72}
     73
     74void GeoVis::clearHighlight()
     75{
     76    if (s_highlightUniform != NULL) {
     77        s_highlightUniform->set(0U);
     78    }
    6479}
    6580
  • geovis/trunk/Picker.h

    r5873 r5938  
    99
    1010#include <osgEarth/Picker>
     11#include <osgEarth/ObjectIndex>
    1112
    1213namespace GeoVis {
     
    5354};
    5455
     56extern void setHighlightByObjectID(osgEarth::ObjectID id);
     57extern void clearHighlight();
     58
    5559}
    5660
  • geovis/trunk/Renderer.cpp

    r5930 r5938  
    4141#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
    4242#include <osgEarth/MapNode>
     43#include <osgEarth/TerrainEngineNode>
    4344#include <osgEarth/Bounds>
    4445#include <osgEarth/Profile>
     
    6263#include <osgEarth/Pickers>
    6364#endif
     65#include <osgEarthFeatures/FeatureModelSource>
    6466#include <osgEarthFeatures/Feature>
    6567#include <osgEarthSymbology/Color>
     
    101103#include "ScaleBar.h"
    102104#include "FileUtil.h"
     105#include "Util.h"
    103106#include "Trace.h"
    104107
     
    15331536{
    15341537    TRACE("Select layer '%s', num features: %u", layerName, featureIDs.size());
     1538    if (featureIDs.size() == 0) {
     1539        // clear selection
     1540        return;
     1541    }
    15351542    osgEarth::ModelLayer *layer = _map->getModelLayerByName(layerName);
    15361543    if (layer == NULL) {
     
    15381545        return;
    15391546    }
     1547#ifdef WANT_TRACE
    15401548    for (unsigned int i = 0; i < featureIDs.size(); i++) {
    15411549        TRACE("feature ID: %u", featureIDs.at(i));
     1550    }
     1551#endif
     1552    unsigned long fid = featureIDs.at(0);
     1553
     1554    osgEarth::ModelSource *modelSource = layer->getModelSource();
     1555    osgEarth::Features::FeatureModelSource *fms = dynamic_cast<osgEarth::Features::FeatureModelSource *>(modelSource);
     1556    if (fms != NULL) {
     1557        osgEarth::Features::FeatureSource *fs = fms->getFeatureSource();
     1558        FindFeatureSourceIndexNodeVisitor visitor;
     1559        visitor.source = fs;
     1560        _sceneRoot->accept(visitor);
     1561        TRACE("Num FeatureSourceIndexNodes found: %lu", visitor.nodes.size());
     1562        for (size_t i = 0; i < visitor.nodes.size(); i++) {
     1563            osgEarth::Features::FeatureIndex *index = visitor.nodes[i]->getIndex();
     1564#if OSGEARTH_MIN_VERSION_REQUIRED(3, 0, 0)
     1565            osgEarth::ObjectID id = index->getObjectID(fid);
     1566            setHighlightByObjectID(id);
     1567            TRACE("FID %lu = OID %d", fid, id);
     1568#endif
     1569        }
    15421570    }
    15431571}
  • geovis/trunk/Util.h

    r5873 r5938  
    88#define GEOVIS_UTIL_H
    99
     10#include <cstring>
    1011#include <string>
    1112
     13#include <osg/NodeVisitor>
     14#include <osgEarthFeatures/FeatureIndex>
     15#include <osgEarthFeatures/FeatureSourceIndexNode>
     16
    1217namespace GeoVis {
     18
     19class FindFeatureSourceIndexNodeVisitor : public osg::NodeVisitor {
     20public:
     21    FindFeatureSourceIndexNodeVisitor() :
     22        osg::NodeVisitor(TRAVERSE_ALL_CHILDREN),
     23        source(NULL)
     24    {
     25    }
     26
     27    virtual ~FindFeatureSourceIndexNodeVisitor() {}
     28
     29    virtual void apply(osg::Node& node)
     30    {
     31        if (strcmp(node.className(), "FeatureSourceIndexNode") == 0) {
     32            osgEarth::Features::FeatureSourceIndexNode *fsin = dynamic_cast<osgEarth::Features::FeatureSourceIndexNode *>(&node);
     33            osgEarth::Features::FeatureSourceIndex *index = fsin->getIndex();
     34            if (source == NULL || index->getFeatureSource() == source) {
     35                nodes.push_back(fsin);
     36            }
     37        }
     38        traverse(node);
     39    }
     40
     41    osgEarth::Features::FeatureSource *source;
     42    std::vector<osgEarth::Features::FeatureSourceIndexNode *> nodes;
     43};
    1344
    1445extern std::string loadCSVLayer(const char *filename, const char *longitudeColName = "longitude", const char *latitudeColName = "latitude");
  • geovis/trunk/geovis_protocol.txt

    r5924 r5938  
    215215<clamptechnique> = drape|gpu|scene|map
    216216
     217map layer add <layerName> feature <driver> <format> <typeName> <url> <cache> <style> <?scripts?> <?selectors?> <?visibilityRangeMin?> <?visibilityRangeMax?>
     218    <style> = CSS styles
     219    <scripts> = JavaScript
     220    <selectors> = List of name/value pairs
    217221map layer add <layerName> icon <driver> <format> <typeName> <url> <cache> <icon> <scale> <heading> <declutter> <placement> <alignment> <?visibilityRangeMin?> <?visibilityRangeMax?>
    218222    Add an icon feature layer from a file or URL
Note: See TracChangeset for help on using the changeset viewer.