Changeset 4246 for trunk/packages


Ignore:
Timestamp:
Mar 16, 2014, 5:57:37 PM (11 years ago)
Author:
ldelgass
Message:

Map renderer updates: add bounds to map reset, set default projection to
spherical mercator (like Google/Bing?/OSM), add wms/tms layer protocol, add
protocol for creating feature layers as point/line/polygon/text

Location:
trunk/packages/vizservers/geovis
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/geovis/RenderServer.h

    r4028 r4246  
    1919class ResponseQueue;
    2020
    21 #define GEOVIS_VERSION_STRING "0.1"
     21#define GEOVIS_VERSION_STRING "0.2"
    2222
    2323#define MSECS_ELAPSED(t1, t2) \
  • trunk/packages/vizservers/geovis/Renderer.cpp

    r4087 r4246  
    2121#include <osgEarth/Version>
    2222#include <osgEarth/MapNode>
     23#include <osgEarth/Bounds>
     24#include <osgEarth/Profile>
    2325#include <osgEarth/TerrainLayer>
    2426#include <osgEarth/ImageLayer>
     
    2830#include <osgEarthUtil/AutoClipPlaneHandler>
    2931#include <osgEarthUtil/MouseCoordsTool>
     32#include <osgEarthUtil/GLSLColorFilter>
    3033#include <osgEarthDrivers/gdal/GDALOptions>
     34#include <osgEarthDrivers/engine_mp/MPTerrainEngineOptions>
    3135
    3236#include "Renderer.h"
     
    3640    ((t1).tv_sec == (t2).tv_sec ? (((t2).tv_usec - (t1).tv_usec)/1.0e+3) : \
    3741     (((t2).tv_sec - (t1).tv_sec))*1.0e+3 + (double)((t2).tv_usec - (t1).tv_usec)/1.0e+3)
     42
     43#define BASE_IMAGE "/usr/share/osgearth/data/world.tif"
    3844
    3945using namespace GeoVis;
     
    5864    osgEarth::MapOptions mapOpts;
    5965    mapOpts.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED;
    60     mapOpts.profile() = osgEarth::ProfileOptions("global-geodetic");
     66    mapOpts.profile() = osgEarth::ProfileOptions("global-mercator");
    6167    osgEarth::Map *map = new osgEarth::Map(mapOpts);
    6268    _map = map;
    6369    osgEarth::Drivers::GDALOptions bopts;
    64     bopts.url() = "/usr/share/osgearth/data/world.tif";
     70    bopts.url() = BASE_IMAGE;
    6571    addImageLayer("base", bopts);
    66     osgEarth::MapNodeOptions mapNodeOpts;
     72    osgEarth::Drivers::MPTerrainEngineOptions mpOpt;
     73    // Set background layer color
     74    mpOpt.color() = osg::Vec4(1, 1, 1, 1);
     75    //mpOpt.minLOD() = 1;
     76    osgEarth::MapNodeOptions mapNodeOpts(mpOpt);
    6777    mapNodeOpts.enableLighting() = false;
    6878    osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts);
     
    8191    _viewer->setUpViewInWindow(0, 0, _windowWidth, _windowHeight);
    8292    _viewer->realize();
     93    initColorMaps();
    8394#ifdef DEBUG
    8495    if (_viewer->getViewerStats() != NULL) {
     
    110121
    111122    TRACE("Leave");
     123}
     124
     125void Renderer::initColorMaps()
     126{
     127    osg::TransferFunction1D *defaultColorMap = new osg::TransferFunction1D;
     128    defaultColorMap->allocate(256);
     129    defaultColorMap->setColor(0.00, osg::Vec4f(0,0,1,1), false);
     130    defaultColorMap->setColor(0.25, osg::Vec4f(0,1,1,1), false);
     131    defaultColorMap->setColor(0.50, osg::Vec4f(0,1,0,1), false);
     132    defaultColorMap->setColor(0.75, osg::Vec4f(1,1,0,1), false);
     133    defaultColorMap->setColor(1.00, osg::Vec4f(1,0,0,1), false);
     134    defaultColorMap->updateImage();
     135    addColorMap("default", defaultColorMap);
     136    osg::TransferFunction1D *defaultGrayColorMap = new osg::TransferFunction1D;
     137    defaultGrayColorMap->allocate(256);
     138    defaultGrayColorMap->setColor(0, osg::Vec4f(0,0,0,1), false);
     139    defaultGrayColorMap->setColor(1, osg::Vec4f(1,1,1,1), false);
     140    defaultGrayColorMap->updateImage();
     141    addColorMap("grayDefault", defaultGrayColorMap);
     142}
     143
     144void Renderer::addColorMap(const ColorMapId& id, osg::TransferFunction1D *xfer)
     145{
     146    _colorMaps[id] = xfer;
     147#if 0
     148    osgEarth::Drivers::GDALOptions opts;
     149    char *url =  Tcl_GetString(objv[4]);
     150    std::ostringstream oss;
     151    oss << "_cmap_" << id;
     152
     153    opts.url() = url;
     154
     155    addImageLayer(oss.str().c_str(), opts);
     156#endif
     157}
     158
     159void Renderer::deleteColorMap(const ColorMapId& id)
     160{
     161    ColorMapHashmap::iterator itr;
     162    bool doAll = false;
     163
     164    if (id.compare("all") == 0) {
     165        itr = _colorMaps.begin();
     166        doAll = true;
     167    } else {
     168        itr = _colorMaps.find(id);
     169    }
     170
     171    if (itr == _colorMaps.end()) {
     172        ERROR("Unknown ColorMap %s", id.c_str());
     173        return;
     174    }
     175
     176    do {
     177        if (itr->first.compare("default") == 0 ||
     178            itr->first.compare("grayDefault") == 0) {
     179            if (id.compare("all") != 0) {
     180                WARN("Cannot delete a default color map");
     181            }
     182            continue;
     183        }
     184
     185        TRACE("Deleting ColorMap %s", itr->first.c_str());
     186        itr = _colorMaps.erase(itr);
     187    } while (doAll && itr != _colorMaps.end());
     188}
     189
     190void Renderer::setColorMapNumberOfTableEntries(const ColorMapId& id,
     191                                               int numEntries)
     192{
     193    ColorMapHashmap::iterator itr;
     194    bool doAll = false;
     195
     196    if (id.compare("all") == 0) {
     197        itr = _colorMaps.begin();
     198        doAll = true;
     199    } else {
     200        itr = _colorMaps.find(id);
     201    }
     202
     203    if (itr == _colorMaps.end()) {
     204        ERROR("Unknown ColorMap %s", id.c_str());
     205        return;
     206    }
     207
     208    do {
     209        itr->second->allocate(numEntries);
     210        itr->second->updateImage();
     211    } while (doAll && ++itr != _colorMaps.end());
    112212}
    113213
     
    152252}
    153253
    154 void Renderer::resetMap(osgEarth::MapOptions::CoordinateSystemType type, const char *profile)
     254void Renderer::resetMap(osgEarth::MapOptions::CoordinateSystemType type,
     255                        const char *profile,
     256                        double bounds[4])
    155257{
    156258    TRACE("Restting map with type %d, profile %s", type, profile);
     
    159261    mapOpts.coordSysType() = type;
    160262    if (profile != NULL) {
    161         mapOpts.profile() = osgEarth::ProfileOptions(profile);
     263        if (bounds != NULL) {
     264            mapOpts.profile() = osgEarth::ProfileOptions();
     265            if (strcmp(profile, "geodetic") == 0) {
     266                mapOpts.profile()->srsString() = "epsg:4326";
     267            } else if (strcmp(profile, "spherical-mercator") == 0) {
     268                // Projection used by Google/Bing/OSM
     269                // aka epsg:900913 meters in x/y
     270                // aka WGS84 Web Mercator (Auxiliary Sphere)
     271                // X/Y: -20037508.34m to 20037508.34m
     272                mapOpts.profile()->srsString() = "epsg:3857";
     273            } else {
     274                mapOpts.profile()->srsString() = profile;
     275            }
     276            mapOpts.profile()->bounds() =
     277                osgEarth::Bounds(bounds[0], bounds[1], bounds[2], bounds[3]);
     278        } else {
     279            mapOpts.profile() = osgEarth::ProfileOptions(profile);
     280        }
    162281    } else if (type == osgEarth::MapOptions::CSTYPE_PROJECTED) {
    163         mapOpts.profile() = osgEarth::ProfileOptions("global-geodetic");
     282        mapOpts.profile() = osgEarth::ProfileOptions("global-mercator");
     283    }
     284    if (bounds != NULL) {
     285        TRACE("Setting profile bounds: %g %g %g %g",
     286              bounds[0], bounds[1], bounds[2], bounds[3]);
     287        mapOpts.profile()->bounds() =
     288            osgEarth::Bounds(bounds[0], bounds[1], bounds[2], bounds[3]);
    164289    }
    165290    osgEarth::Map *map = new osgEarth::Map(mapOpts);
    166291    _map = map;
    167     osgEarth::MapNodeOptions mapNodeOpts;
     292    osgEarth::Drivers::GDALOptions bopts;
     293    bopts.url() = BASE_IMAGE;
     294    addImageLayer("base", bopts);
     295    osgEarth::Drivers::MPTerrainEngineOptions mpOpt;
     296    // Set background layer color
     297    mpOpt.color() = osg::Vec4(1, 1, 1, 1);
     298    //mpOpt.minLOD() = 1;
     299    osgEarth::MapNodeOptions mapNodeOpts(mpOpt);
    168300    mapNodeOpts.enableLighting() = false;
    169301    osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts);
     
    212344}
    213345
    214 void Renderer::addImageLayer(const char *name, const osgEarth::TileSourceOptions& opts)
     346void Renderer::addImageLayer(const char *name,
     347                             const osgEarth::TileSourceOptions& opts,
     348                             bool makeShared,
     349                             bool visible)
    215350{
    216351    osgEarth::ImageLayerOptions layerOpts(name, opts);
     352    if (makeShared) {
     353        layerOpts.shared() = true;
     354    }
     355    if (!visible) {
     356        layerOpts.visible() = false;
     357    }
    217358    _map->addImageLayer(new osgEarth::ImageLayer(layerOpts));
     359    _needsRedraw = true;
     360}
     361
     362void Renderer::addColorFilter(const char *name,
     363                              const char *shader)
     364{
     365     osgEarth::ImageLayer *layer = _map->getImageLayerByName(name);
     366     if (layer == NULL) {
     367         TRACE("Image layer not found: %s", name);
     368         return;
     369     }
     370     osgEarth::Util::GLSLColorFilter *filter = new osgEarth::Util::GLSLColorFilter;
     371     filter->setCode(shader);
     372     //filter->setCode("color.rgb = color.r > 0.5 ? vec3(1.0) : vec3(0.0);");
     373     layer->addColorFilter(filter);
     374     _needsRedraw = true;
     375}
     376
     377void Renderer::removeColorFilter(const char *name, int idx)
     378{
     379    osgEarth::ImageLayer *layer = _map->getImageLayerByName(name);
     380    if (layer == NULL) {
     381        TRACE("Image layer not found: %s", name);
     382        return;
     383    }
     384    if (idx < 0) {
     385        while (!layer->getColorFilters().empty()) {
     386            layer->removeColorFilter(layer->getColorFilters()[0]);
     387        }
     388    } else {
     389        layer->removeColorFilter(layer->getColorFilters().at(idx));
     390    }
    218391    _needsRedraw = true;
    219392}
     
    265438}
    266439
    267 void Renderer::addElevationLayer(const char *name, const osgEarth::TileSourceOptions& opts)
    268 {
     440void Renderer::addElevationLayer(const char *name,
     441                                 const osgEarth::TileSourceOptions& opts)
     442{
     443    // XXX: GDAL does not report vertical datum, it should be specified here
    269444    osgEarth::ElevationLayerOptions layerOpts(name, opts);
     445    //layerOpts.verticalDatum() = "";
    270446    _map->addElevationLayer(new osgEarth::ElevationLayer(layerOpts));
    271447    _needsRedraw = true;
  • trunk/packages/vizservers/geovis/Renderer.h

    r4054 r4246  
    1717#include <osg/Node>
    1818#include <osg/Image>
     19#include <osg/TransferFunction>
    1920#include <osgViewer/Viewer>
    2021
     
    126127{
    127128public:
     129    typedef std::string ColorMapId;
     130
    128131    Renderer();
    129132    virtual ~Renderer();
    130133
     134    // Colormaps
     135
     136    void addColorMap(const ColorMapId& id, osg::TransferFunction1D *xfer);
     137
     138    void deleteColorMap(const ColorMapId& id);
     139
     140    void setColorMapNumberOfTableEntries(const ColorMapId& id, int numEntries);
     141
    131142    // Scene
    132143
    133144    void loadEarthFile(const char *path);
    134145
    135     void resetMap(osgEarth::MapOptions::CoordinateSystemType type, const char *profile = NULL);
     146    void resetMap(osgEarth::MapOptions::CoordinateSystemType type,
     147                  const char *profile = NULL,
     148                  double bounds[4] = NULL);
    136149
    137150    void clearMap();
     
    148161    }
    149162
    150     void addImageLayer(const char *name, const osgEarth::TileSourceOptions& opts);
     163    void addImageLayer(const char *name, const osgEarth::TileSourceOptions& opts,
     164                       bool makeShared = false, bool visible = true);
    151165
    152166    void removeImageLayer(const char *name);
     
    158172    void setImageLayerVisibility(const char *name, bool state);
    159173
     174    void addColorFilter(const char *name, const char *shader);
     175
     176    void removeColorFilter(const char *name, int idx = -1);
     177
    160178    // Elevation raster layers
    161179
     
    256274
    257275private:
     276    typedef std::tr1::unordered_map<ColorMapId, osg::ref_ptr<osg::TransferFunction1D> > ColorMapHashmap;
     277
     278    void initColorMaps();
     279
    258280    void initCamera();
    259281
     
    270292    double _minFrameTime;
    271293    double _lastFrameTime;
     294
     295    ColorMapHashmap _colorMaps;
    272296
    273297    osg::ref_ptr<osg::Node> _sceneRoot;
  • trunk/packages/vizservers/geovis/RendererCmd.cpp

    r4110 r4246  
    1919#include <tcl.h>
    2020
     21#include <osgEarth/Registry>
    2122#include <osgEarthFeatures/FeatureModelSource>
    2223#include <osgEarthSymbology/Color>
     
    2728
    2829#include <osgEarthDrivers/gdal/GDALOptions>
     30#include <osgEarthDrivers/tms/TMSOptions>
     31#include <osgEarthDrivers/wms/WMSOptions>
    2932#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>
    3033#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
     
    333336
    334337static int
     338ColorMapAddOp(ClientData clientData, Tcl_Interp *interp, int objc,
     339              Tcl_Obj *const *objv)
     340{
     341    const char *name = Tcl_GetString(objv[2]);
     342    int cmapc, omapc;
     343    Tcl_Obj **cmapv = NULL;
     344    Tcl_Obj **omapv = NULL;
     345
     346    if (Tcl_ListObjGetElements(interp, objv[3], &cmapc, &cmapv) != TCL_OK) {
     347        return TCL_ERROR;
     348    }
     349    if ((cmapc % 4) != 0) {
     350        Tcl_AppendResult(interp, "wrong # elements in colormap: should be ",
     351                         "{ value r g b ... }", (char*)NULL);
     352        return TCL_ERROR;
     353    }
     354
     355    osg::TransferFunction1D *colorMap = new osg::TransferFunction1D;
     356    colorMap->allocate(256);
     357
     358    for (int i = 0; i < cmapc; i += 4) {
     359        double val[4];
     360        for (int j = 0; j < 4; j++) {
     361            if (Tcl_GetDoubleFromObj(interp, cmapv[i+j], &val[j]) != TCL_OK) {
     362                delete colorMap;
     363                return TCL_ERROR;
     364            }
     365            if ((val[j] < 0.0) || (val[j] > 1.0)) {
     366                Tcl_AppendResult(interp, "bad colormap value \"",
     367                                 Tcl_GetString(cmapv[i+j]),
     368                                 "\": should be in the range [0,1]", (char*)NULL);
     369                delete colorMap;
     370                return TCL_ERROR;
     371            }
     372        }
     373        colorMap->setColor(val[0], osg::Vec4f(val[1], val[2], val[3], 1.0), false);
     374    }
     375
     376    colorMap->updateImage();
     377
     378    if (Tcl_ListObjGetElements(interp, objv[4], &omapc, &omapv) != TCL_OK) {
     379        delete colorMap;
     380        return TCL_ERROR;
     381    }
     382    if ((omapc % 2) != 0) {
     383        Tcl_AppendResult(interp, "wrong # elements in opacitymap: should be ",
     384                         "{ value alpha ... }", (char*)NULL);
     385        delete colorMap;
     386        return TCL_ERROR;
     387    }
     388    for (int i = 0; i < omapc; i += 2) {
     389        double val[2];
     390        for (int j = 0; j < 2; j++) {
     391            if (Tcl_GetDoubleFromObj(interp, omapv[i+j], &val[j]) != TCL_OK) {
     392                delete colorMap;
     393                return TCL_ERROR;
     394            }
     395            if ((val[j] < 0.0) || (val[j] > 1.0)) {
     396                Tcl_AppendResult(interp, "bad opacitymap value \"",
     397                                 Tcl_GetString(omapv[i+j]),
     398                                 "\": should be in the range [0,1]", (char*)NULL);
     399                delete colorMap;
     400                return TCL_ERROR;
     401            }
     402        }
     403#if 0
     404        ColorMap::OpacityControlPoint ocp;
     405        ocp.value = val[0];
     406        ocp.alpha = val[1];
     407        colorMap->addOpacityControlPoint(ocp);
     408#endif
     409    }
     410
     411    //colorMap->build();
     412    g_renderer->addColorMap(name, colorMap);
     413    return TCL_OK;
     414}
     415
     416static int
     417ColorMapDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc,
     418                 Tcl_Obj *const *objv)
     419{
     420    if (objc == 3) {
     421        const char *name = Tcl_GetString(objv[2]);
     422        g_renderer->deleteColorMap(name);
     423    } else {
     424        g_renderer->deleteColorMap("all");
     425    }
     426
     427    return TCL_OK;
     428}
     429
     430static int
     431ColorMapNumTableEntriesOp(ClientData clientData, Tcl_Interp *interp, int objc,
     432                          Tcl_Obj *const *objv)
     433{
     434    int numEntries;
     435    if (Tcl_GetIntFromObj(interp, objv[2], &numEntries) != TCL_OK) {
     436        const char *str = Tcl_GetString(objv[2]);
     437        if (str[0] == 'd' && strcmp(str, "default") == 0) {
     438            numEntries = -1;
     439        } else {
     440            Tcl_AppendResult(interp, "bad colormap resolution value \"", str,
     441                             "\": should be a positive integer or \"default\"", (char*)NULL);
     442            return TCL_ERROR;
     443        }
     444    } else if (numEntries < 1) {
     445        Tcl_AppendResult(interp, "bad colormap resolution value \"", Tcl_GetString(objv[2]),
     446                         "\": should be a positive integer or \"default\"", (char*)NULL);
     447        return TCL_ERROR;
     448    }
     449    if (objc == 4) {
     450        const char *name = Tcl_GetString(objv[3]);
     451
     452        g_renderer->setColorMapNumberOfTableEntries(name, numEntries);
     453    } else {
     454        g_renderer->setColorMapNumberOfTableEntries("all", numEntries);
     455    }
     456    return TCL_OK;
     457}
     458
     459static CmdSpec colorMapOps[] = {
     460    {"add",    1, ColorMapAddOp,             5, 5, "colorMapName colormap alphamap"},
     461    {"define", 3, ColorMapAddOp,             5, 5, "colorMapName colormap alphamap"},
     462    {"delete", 3, ColorMapDeleteOp,          2, 3, "?colorMapName?"},
     463    {"res",    1, ColorMapNumTableEntriesOp, 3, 4, "numTableEntries ?colorMapName?"}
     464};
     465static int nColorMapOps = NumCmdSpecs(colorMapOps);
     466
     467static int
     468ColorMapCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     469            Tcl_Obj *const *objv)
     470{
     471    Tcl_ObjCmdProc *proc;
     472
     473    proc = GetOpFromObj(interp, nColorMapOps, colorMapOps,
     474                        CMDSPEC_ARG1, objc, objv, 0);
     475    if (proc == NULL) {
     476        return TCL_ERROR;
     477    }
     478    return (*proc) (clientData, interp, objc, objv);
     479}
     480
     481static int
    335482ImageFlushCmd(ClientData clientData, Tcl_Interp *interp, int objc,
    336483              Tcl_Obj *const *objv)
     
    399546
    400547        g_renderer->addImageLayer(name, opts);
     548    } else if (type[0] == 't' && strcmp(type, "tms") == 0) {
     549        osgEarth::Drivers::TMSOptions opts;
     550        char *url =  Tcl_GetString(objv[4]);
     551        //char *tmsType = Tcl_GetString(objv[5]);
     552        //char *format = Tcl_GetString(objv[6]);
     553        char *name = Tcl_GetString(objv[5]);
     554
     555        opts.url() = url;
     556        //opts.tmsType() = tmsType;
     557        //opts.format() = format;
     558
     559        g_renderer->addImageLayer(name, opts);
     560    } else if (type[0] == 'w' && strcmp(type, "wms") == 0) {
     561        osgEarth::Drivers::WMSOptions opts;
     562        char *url =  Tcl_GetString(objv[4]);
     563        char *wmsLayers = Tcl_GetString(objv[5]);
     564        char *format = Tcl_GetString(objv[6]);
     565        bool transparent;
     566        if (GetBooleanFromObj(interp, objv[7], &transparent) != TCL_OK) {
     567            return TCL_ERROR;
     568        }
     569        char *name = Tcl_GetString(objv[8]);
     570
     571        opts.url() = url;
     572        opts.layers() = wmsLayers;
     573        opts.format() = format;
     574        opts.transparent() = transparent;
     575
     576        g_renderer->addImageLayer(name, opts);
    401577    } else if (type[0] == 'e' && strcmp(type, "elevation") == 0) {
    402578        osgEarth::Drivers::GDALOptions opts;
     
    407583
    408584        g_renderer->addElevationLayer(name, opts);
    409     } else if (type[0] == 'm' && strcmp(type, "model") == 0) {
     585    } else if (type[0] == 'p' && strcmp(type, "point") == 0) {
    410586        osgEarth::Drivers::OGRFeatureOptions opts;
    411587        char *url =  Tcl_GetString(objv[4]);
     
    414590
    415591        osgEarth::Symbology::Style style;
     592        osgEarth::Symbology::PointSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::PointSymbol>();
     593        ls->fill()->color() = osgEarth::Symbology::Color::Black;
     594        ls->size() = 2.0f;
     595
     596        osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>();
     597        rs->depthOffset()->enabled() = true;
     598        rs->depthOffset()->minBias() = 1000;
     599
     600        osgEarth::Drivers::FeatureGeomModelOptions geomOpts;
     601        geomOpts.featureOptions() = opts;
     602        geomOpts.styles() = new osgEarth::Symbology::StyleSheet();
     603        geomOpts.styles()->addStyle(style);
     604        geomOpts.enableLighting() = false;
     605        g_renderer->addModelLayer(name, geomOpts);
     606    } else if (type[0] == 'p' && strcmp(type, "polygon") == 0) {
     607        osgEarth::Drivers::OGRFeatureOptions opts;
     608        char *url =  Tcl_GetString(objv[4]);
     609        char *name = Tcl_GetString(objv[5]);
     610        opts.url() = url;
     611
     612        osgEarth::Symbology::Style style;
     613        osgEarth::Symbology::PolygonSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::PolygonSymbol>();
     614        ls->fill()->color() = osgEarth::Symbology::Color::White;
     615
     616        osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>();
     617        rs->depthOffset()->enabled() = true;
     618        rs->depthOffset()->minBias() = 1000;
     619
     620        osgEarth::Drivers::FeatureGeomModelOptions geomOpts;
     621        geomOpts.featureOptions() = opts;
     622        geomOpts.styles() = new osgEarth::Symbology::StyleSheet();
     623        geomOpts.styles()->addStyle(style);
     624        geomOpts.enableLighting() = false;
     625        g_renderer->addModelLayer(name, geomOpts);
     626    } else if (type[0] == 'l' && strcmp(type, "line") == 0) {
     627        osgEarth::Drivers::OGRFeatureOptions opts;
     628        char *url =  Tcl_GetString(objv[4]);
     629        char *name = Tcl_GetString(objv[5]);
     630        opts.url() = url;
     631
     632        osgEarth::Symbology::Style style;
    416633        osgEarth::Symbology::LineSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::LineSymbol>();
    417634        ls->stroke()->color() = osgEarth::Symbology::Color::Black;
    418635        ls->stroke()->width() = 2.0f;
     636
     637        osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>();
     638        rs->depthOffset()->enabled() = true;
     639        rs->depthOffset()->minBias() = 1000;
     640
     641        osgEarth::Drivers::FeatureGeomModelOptions geomOpts;
     642        geomOpts.featureOptions() = opts;
     643        geomOpts.styles() = new osgEarth::Symbology::StyleSheet();
     644        geomOpts.styles()->addStyle(style);
     645        geomOpts.enableLighting() = false;
     646        g_renderer->addModelLayer(name, geomOpts);
     647   } else if (type[0] == 't' && strcmp(type, "text") == 0) {
     648        osgEarth::Drivers::OGRFeatureOptions opts;
     649        char *url =  Tcl_GetString(objv[4]);
     650        char *name = Tcl_GetString(objv[5]);
     651        opts.url() = url;
     652
     653        osgEarth::Symbology::Style style;
     654        osgEarth::Symbology::TextSymbol *ts = style.getOrCreateSymbol<osgEarth::Symbology::TextSymbol>();
     655        ts->halo()->color() = osgEarth::Symbology::Color::White;
     656        ts->halo()->width() = 2.0f;
     657        ts->fill()->color() = osgEarth::Symbology::Color::Black;
    419658
    420659        osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>();
     
    511750
    512751static CmdSpec mapLayerOps[] = {
    513     {"add",     1, MapLayerAddOp,       6, 6, "type url name"},
     752    {"add",     1, MapLayerAddOp,       6, 9, "type url ?args? name"},
    514753    {"delete",  1, MapLayerDeleteOp,    3, 4, "?name?"},
    515754    {"move",    1, MapLayerMoveOp,      5, 5, "pos name"},
     
    584823    } else {
    585824        Tcl_AppendResult(interp, "bad map type \"", typeStr,
    586                          "\": must be geocentric, geocentric_cube or projected", (char*)NULL);
    587         return TCL_ERROR;
    588     }
    589 
    590     char *profile = NULL;
    591     if (objc > 3) {
    592         profile = Tcl_GetString(objv[3]);
    593     }
    594 
    595     g_renderer->resetMap(type, profile);
     825                         "\": must be geocentric or projected", (char*)NULL);
     826        return TCL_ERROR;
     827    }
     828
     829    if (type == osgEarth::MapOptions::CSTYPE_PROJECTED) {
     830        if (objc < 4) {
     831            Tcl_AppendResult(interp, "wrong # arguments: profile required for projected maps", (char*)NULL);
     832            return TCL_ERROR;
     833        }
     834        char *profile = Tcl_GetString(objv[3]);
     835        if (objc > 4) {
     836            if (objc < 8) {
     837                Tcl_AppendResult(interp, "wrong # arguments: 4 bounds arguments required", (char*)NULL);
     838                return TCL_ERROR;
     839            }
     840            double bounds[4];
     841            for (int i = 0; i < 4; i++) {
     842                if (Tcl_GetDoubleFromObj(interp, objv[4+i], &bounds[i]) != TCL_OK) {
     843                    return TCL_ERROR;
     844                }
     845            }
     846            // Check if min > max
     847            if (bounds[0] > bounds[2] ||
     848                bounds[1] > bounds[3]) {
     849                Tcl_AppendResult(interp, "invalid bounds", (char*)NULL);
     850                return TCL_ERROR;
     851            }
     852            if (strcmp(profile, "geodetic") == 0 ||
     853                strcmp(profile, "epsg:4326") == 0 ) {
     854                if (bounds[0] < -180. || bounds[0] > 180. ||
     855                    bounds[2] < -180. || bounds[2] > 180. ||
     856                    bounds[1] < -90. || bounds[1] > 90. ||
     857                    bounds[3] < -90. || bounds[3] > 90.) {
     858                    Tcl_AppendResult(interp, "invalid bounds", (char*)NULL);
     859                    return TCL_ERROR;
     860                }
     861            } else if (strcmp(profile, "spherical-mercator") == 0 ||
     862                       strcmp(profile, "epsg:900913") == 0 ||
     863                       strcmp(profile, "epsg:3857") == 0) {
     864                for (int i = 0; i < 4; i++) {
     865                    if (bounds[i] < -20037508.34 || bounds[i] > 20037508.34) {
     866                        Tcl_AppendResult(interp, "invalid bounds", (char*)NULL);
     867                        return TCL_ERROR;
     868                    }
     869                }
     870            }
     871
     872            g_renderer->resetMap(type, profile, bounds);
     873        } else {
     874            if (osgEarth::Registry::instance()->getNamedProfile(profile) == NULL) {
     875                Tcl_AppendResult(interp, "bad named profile \"", profile,
     876                                 "\": must be e.g. 'global-geodetic', 'global-mercator'...", (char*)NULL);
     877                return TCL_ERROR;
     878            }
     879            g_renderer->resetMap(type, profile);
     880        }
     881    } else {
     882        // No profile required for geocentric (3D) maps
     883        g_renderer->resetMap(type);
     884    }
    596885
    597886    return TCL_OK;
     
    599888
    600889static CmdSpec mapOps[] = {
    601     {"layer",    2, MapLayerOp,       3, 6, "op ?params...?"},
     890    {"layer",    2, MapLayerOp,       3, 9, "op ?params...?"},
    602891    {"load",     2, MapLoadOp,        4, 5, "options"},
    603     {"reset",    1, MapResetOp,       3, 4, "type ?profile?"},
     892    {"reset",    1, MapResetOp,       3, 8, "type ?profile xmin ymin xmax ymax?"},
    604893};
    605894static int nMapOps = NumCmdSpecs(mapOps);
     
    9131202    }
    9141203    while (inBufPtr->isLineAvailable() ||
    915            (select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr) > 0)) {
     1204           (ret = select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr)) > 0) {
    9161205        size_t numBytes;
    9171206        unsigned char *buffer;
     
    10211310    Tcl_CreateObjCommand(interp, "camera",         CameraCmd,         clientData, NULL);
    10221311    Tcl_CreateObjCommand(interp, "clientinfo",     ClientInfoCmd,     clientData, NULL);
     1312    Tcl_CreateObjCommand(interp, "colormap",       ColorMapCmd,       clientData, NULL);
    10231313    Tcl_CreateObjCommand(interp, "imgflush",       ImageFlushCmd,     clientData, NULL);
    10241314    Tcl_CreateObjCommand(interp, "key",            KeyCmd,            clientData, NULL);
     
    10361326    Tcl_DeleteCommand(interp, "camera");
    10371327    Tcl_DeleteCommand(interp, "clientinfo");
     1328    Tcl_DeleteCommand(interp, "colormap");
    10381329    Tcl_DeleteCommand(interp, "imgflush");
    10391330    Tcl_DeleteCommand(interp, "key");
  • trunk/packages/vizservers/geovis/geovis_protocol.txt

    r4053 r4246  
    5959screen size <width> <height>
    6060
    61 map layer add <type> <url> <layerName>
     61General form:
     62map layer add <type> <url> ... <layerName>
     63    <type> = image|wms|tms|elevation|point|polygon|line|text
     64
     65map layer add image <url> <layerName>
    6266    Add a GDAL image layer from a file or URL
    63     <type> = image|terrain|model
     67map layer add wms <url> <layers> <format> <transparent> <layerName>
     68    Add a WMS image layer from a URL/layer string
     69    <url> = URL of WMS service
     70    <layers> = layers string for WMS server
     71    <format> = Image format to return (e.g. 'png')
     72    <transparent> = bool
     73map layer add tms <url> <tmsType> <format> <layerName>
     74    Add a WMS image layer from a URL/layer string
     75    <url> = URL of WMS service
     76    <layers> = layers string for WMS server
     77map layer add elevation <url> <layerName>
     78    Add a GDAL elevation image layer from a file or URL
     79map layer add point <url> <layerName>
     80    Add a point feature layer from a file or URL
     81map layer add polygon <url> <layerName>
     82    Add a polygon feature layer from a file or URL
     83map layer add line <url> <layerName>
     84    Add a line feature layer from a file or URL
     85map layer add text <url> <layerName>
     86    Add a GDAL image layer from a file or URL
     87
    6488map layer delete <layerName>
    6589map layer opacity <opacity> <layerName>
     
    7296map load url <url>
    7397    Load an .earth file from a network address
    74 map reset <type> <?profile?>
     98map reset <type> <?profile?> <?xmin?> <?ymin?> <?xmax?> <?ymax?>
    7599    type = geocentric|projected
    76     profile = Well known profile string, e.g. 'global-geodetic' (default)
    77               'global-mercator'
     100    profile = Well known profile string, e.g. 'global-geodetic',
     101    'global-mercator'
     102    xmin,ymin,xmax,ymax = map bounds (in profile projection/units)
    78103
    79104================================================================================
Note: See TracChangeset for help on using the changeset viewer.