Changeset 5775


Ignore:
Timestamp:
Jul 24, 2015, 5:37:02 PM (9 years ago)
Author:
ldelgass
Message:

Add alignment param for label layer. Fixes for osgearth 2.7

Location:
geovis/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/RenderServer.cpp

    r5118 r5775  
    4040#endif
    4141
     42#if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1)
     43#define NEW_VIEWPOINT_API
     44#endif
     45
    4246using namespace GeoVis;
    4347
     
    6670    size_t len = 0;
    6771    oss << "nv>camera get "
     72#ifdef NEW_VIEWPOINT_API
     73        << view.focalPoint()->x() << " "
     74        << view.focalPoint()->y() << " "
     75        << view.focalPoint()->z() << " "
     76        << view.heading()->getValue() << " "
     77        << view.pitch()->getValue() << " "
     78        << view.range()->getValue()
     79        << " {" << ((view.focalPoint()->getSRS() == NULL) ? "" : view.focalPoint()->getSRS()->getHorizInitString()) << "}"
     80        << " {" << ((view.focalPoint()->getSRS() == NULL) ? "" : view.focalPoint()->getSRS()->getVertInitString()) << "}"
     81#else
    6882        << view.x() << " "
    6983        << view.y() << " "
     
    7488        << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getHorizInitString()) << "}"
    7589        << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getVertInitString()) << "}"
     90#endif
    7691        << "\n";
    7792    std::string ostr = oss.str();
     
    358373    g_renderer->setResourcePath(resourcePath);
    359374
     375    TRACE("Default Tcl encoding dir: %s", Tcl_GetDefaultEncodingDir());
     376    //Tcl_SetDefaultEncodingDir("encoding");
     377
    360378    Tcl_Interp *interp = Tcl_CreateInterp();
     379    initTcl(interp, NULL);
    361380
    362381#ifdef USE_THREADS
     
    368387    }
    369388#endif
    370     initTcl(interp, NULL);
    371389
    372390    osg::ref_ptr<osg::Image> imgData;
  • geovis/trunk/Renderer.cpp

    r5152 r5775  
    4747#include <osgEarth/ModelLayer>
    4848#include <osgEarth/DateTime>
     49#if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0)
     50#include <osgEarth/IntersectionPicker>
     51#else
    4952#include <osgEarth/Pickers>
     53#endif
    5054#include <osgEarthFeatures/Feature>
    5155#include <osgEarthSymbology/Color>
     
    8892#include "FileUtil.h"
    8993#include "Trace.h"
     94
     95#if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1)
     96#define NEW_VIEWPOINT_API
     97#endif
    9098
    9199#define MSECS_ELAPSED(t1, t2) \
     
    452460void Renderer::setAttribution(const std::string& attrib)
    453461{
     462    TRACE("Setting map attribution: '%s'", attrib.c_str());
    454463    _attribution = attrib;
    455464    if (_copyrightLabel.valid()) {
     
    10001009    if (_manipulator.valid()) {
    10011010        TRACE("Setting viewpoint: %g %g %g %g %g %g",
    1002               v.x(), v.y(), v.z(), v.getHeading(), v.getPitch(), v.getRange());
     1011#ifdef NEW_VIEWPOINT_API
     1012              v.focalPoint()->x(), v.focalPoint()->y(), v.focalPoint()->z(),
     1013              v.heading()->as(osgEarth::Units::DEGREES),
     1014              v.pitch()->as(osgEarth::Units::DEGREES),
     1015              v.range()->as(osgEarth::Units::METERS));
     1016#else
     1017              v.x(), v.y(), v.z(),
     1018              v.getHeading(), v.getPitch(), v.getRange());
     1019#endif
    10031020        _manipulator->setViewpoint(v, durationSecs);
    10041021        _needsRedraw = true;
     
    16141631    initAnnotations();
    16151632
    1616     const osgEarth::SpatialReference* geoSRS = _mapNode->getMapSRS()->getGeographicSRS();
     1633    const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS();
    16171634
    16181635    osgEarth::Symbology::Style pin;
     
    16821699}
    16831700#endif
     1701#if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0)
    16841702void Renderer::hoverPlaceNode(int x, int y, bool invertY)
    16851703{
     
    16881706        return;
    16891707    }
     1708
     1709    osgEarth::IntersectionPicker picker(_viewer.get(), _sceneRoot.get());
     1710    osgEarth::IntersectionPicker::Hits hits;
     1711    float mouseX = (float)x;
     1712    float mouseY = (float)y;
     1713    if (invertY) {
     1714        mouseY = ((float)_windowHeight - mouseY);
     1715    }
     1716    std::set<osgEarth::Annotation::AnnotationNode*> toUnHover;
     1717    for (std::set<osgEarth::Annotation::AnnotationNode*>::iterator itr = _hovered.begin();
     1718         itr != _hovered.end(); ++itr) {
     1719        toUnHover.insert(*itr);
     1720    }
     1721    if (picker.pick(mouseX, mouseY, hits)) {
     1722        TRACE("Picker hits: %d", hits.size());
     1723        for (osgEarth::IntersectionPicker::Hits::const_iterator hitr = hits.begin();
     1724             hitr != hits.end(); ++hitr) {
     1725            TRACE("Hit: node %p drawable %p idx %d", picker.getNode<osg::Node>(*hitr), hitr->drawable.get(), hitr->primitiveIndex);
     1726            osgEarth::Annotation::AnnotationNode *anno =
     1727                picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr);
     1728            if (anno != NULL && anno->getDecoration().empty()) {
     1729                TRACE("Hit AnnotationNode: %p", anno);
     1730                if (_hovered.find(anno) == _hovered.end()) {
     1731                    _hovered.insert(anno);
     1732                    anno->setDecoration("hover");
     1733                    _needsRedraw = true;
     1734                }
     1735                toUnHover.erase(anno);
     1736            }
     1737        }
     1738#if 0
     1739        writeScene("/tmp/test.osgt");
     1740#endif
     1741    }
     1742    for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = toUnHover.begin();
     1743         itr != toUnHover.end(); ++itr) {
     1744        _hovered.erase(*itr);
     1745        (*itr)->clearDecoration();
     1746        _needsRedraw = true;
     1747    }
     1748}
     1749
     1750void Renderer::deletePlaceNode(int x, int y, bool invertY)
     1751{
     1752    if (!_placeNodes.valid()) {
     1753        TRACE("No place nodes");
     1754        return;
     1755    }
     1756    osgEarth::IntersectionPicker picker(_viewer.get(), _placeNodes.get());
     1757    osgEarth::IntersectionPicker::Hits hits;
     1758    float mouseX = (float)x;
     1759    float mouseY = (float)y;
     1760    if (invertY) {
     1761        mouseY = ((float)_windowHeight - mouseY);
     1762    }
     1763    if (picker.pick(mouseX, mouseY, hits)) {
     1764        TRACE("Picker hit!");
     1765        // prevent multiple hits on the same instance
     1766        std::set<osgEarth::Annotation::AnnotationNode *> fired;
     1767        for (osgEarth::IntersectionPicker::Hits::const_iterator hitr = hits.begin();
     1768             hitr != hits.end(); ++hitr) {
     1769            osgEarth::Annotation::AnnotationNode *anno =
     1770                picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr);
     1771            if (anno != NULL && fired.find(anno) == fired.end()) {
     1772                fired.insert(anno);
     1773                _needsRedraw = true;
     1774            }
     1775        }
     1776        for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = fired.begin();
     1777             itr != fired.end(); ++itr) {
     1778            (*itr)->clearDecoration();
     1779            _placeNodes->removeChild(*itr);
     1780            if (_hovered.find(*itr) != _hovered.end()) {
     1781                _hovered.erase(*itr);
     1782            }
     1783        }
     1784    } else {
     1785        TRACE("NO Picker hits");
     1786    }
     1787#if 0
     1788    writeScene("/tmp/test.osg");
     1789#endif
     1790}
     1791#else
     1792void Renderer::hoverPlaceNode(int x, int y, bool invertY)
     1793{
     1794    if (!_placeNodes.valid()) {
     1795        TRACE("No place nodes");
     1796        return;
     1797    }
     1798
    16901799    osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get());
    16911800    osgEarth::Picker::Hits hits;
     
    17701879#endif
    17711880}
    1772 
     1881#endif
    17731882void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts)
    17741883{
  • geovis/trunk/Renderer.h

    r5118 r5775  
    1919#include <osg/Image>
    2020#include <osg/TransferFunction>
     21#include <osgText/String>
    2122#include <osgViewer/Viewer>
    2223#include <osgGA/StateSetManipulator>
  • geovis/trunk/RendererCmd.cpp

    r5155 r5775  
    5959#endif
    6060
     61#if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1)
     62#define NEW_VIEWPOINT_API
     63#endif
     64
    6165using namespace GeoVis;
    6266
     
    154158}
    155159
     160static osgEarth::Symbology::TextSymbol::Alignment
     161ParseTextAlignment(const char *align,
     162                   osgEarth::Symbology::TextSymbol::Alignment defAlign =
     163                   osgEarth::Symbology::TextSymbol::ALIGN_LEFT_BASE_LINE)
     164{
     165    osgEarth::Symbology::TextSymbol::Alignment alignment = defAlign;
     166    if (align[0] == 'l' && strcmp(align, "left_top") == 0) {
     167        alignment = osgEarth::Symbology::TextSymbol::ALIGN_LEFT_TOP;
     168    } else if (align[0] == 'l' && strcmp(align, "left_center") == 0) {
     169        alignment = osgEarth::Symbology::TextSymbol::ALIGN_LEFT_CENTER;
     170    } else if (align[0] == 'l' && strcmp(align, "left_bottom") == 0) {
     171        alignment = osgEarth::Symbology::TextSymbol::ALIGN_LEFT_BOTTOM;
     172    } else if (align[0] == 'c' && strcmp(align, "center_top") == 0) {
     173        alignment = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_TOP;
     174    } else if (align[0] == 'c' && strcmp(align, "center_center") == 0) {
     175        alignment = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_CENTER;
     176    } else if (align[0] == 'c' && strcmp(align, "center_bottom") == 0) {
     177        alignment = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_BOTTOM;
     178    } else if (align[0] == 'r' && strcmp(align, "right_top") == 0) {
     179        alignment = osgEarth::Symbology::TextSymbol::ALIGN_RIGHT_TOP;
     180    } else if (align[0] == 'r' && strcmp(align, "right_center") == 0) {
     181        alignment = osgEarth::Symbology::TextSymbol::ALIGN_RIGHT_CENTER;
     182    } else if (align[0] == 'r' && strcmp(align, "right_bottom") == 0) {
     183        alignment = osgEarth::Symbology::TextSymbol::ALIGN_RIGHT_BOTTOM;
     184    } else if (align[0] == 'l' && strcmp(align, "left_baseline") == 0) {
     185        alignment = osgEarth::Symbology::TextSymbol::ALIGN_LEFT_BASE_LINE;
     186    } else if (align[0] == 'c' && strcmp(align, "center_baseline") == 0) {
     187        alignment = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_BASE_LINE;
     188    } else if (align[0] == 'r' && strcmp(align, "right_baseline") == 0) {
     189        alignment = osgEarth::Symbology::TextSymbol::ALIGN_RIGHT_BASE_LINE;
     190    } else  if (align[0] == 'l' && strcmp(align, "left_bottom_baseline") == 0) {
     191        alignment = osgEarth::Symbology::TextSymbol::ALIGN_LEFT_BOTTOM_BASE_LINE;
     192    } else if (align[0] == 'c' && strcmp(align, "center_bottom_baseline") == 0) {
     193        alignment = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_BOTTOM_BASE_LINE;
     194    } else if (align[0] == 'r' && strcmp(align, "right_bottom_baseline") == 0) {
     195        alignment = osgEarth::Symbology::TextSymbol::ALIGN_RIGHT_BOTTOM_BASE_LINE;
     196    }
     197    return alignment;
     198}
     199
    156200static int
    157201CameraDeleteViewpointOp(ClientData clientData, Tcl_Interp *interp, int objc,
     
    173217    size_t len = 0;
    174218    oss << "nv>camera get "
     219#ifdef NEW_VIEWPOINT_API
     220        << view.focalPoint()->x() << " "
     221        << view.focalPoint()->y() << " "
     222        << view.focalPoint()->z() << " "
     223        << view.heading()->getValue() << " "
     224        << view.pitch()->getValue() << " "
     225        << view.range()->getValue()
     226        << " {" << ((view.focalPoint()->getSRS() == NULL) ? "" : view.focalPoint()->getSRS()->getHorizInitString()) << "}"
     227        << " {" << ((view.focalPoint()->getSRS() == NULL) ? "" : view.focalPoint()->getSRS()->getVertInitString()) << "}"
     228#else
    175229        << view.x() << " "
    176230        << view.y() << " "
     
    181235        << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getHorizInitString()) << "}"
    182236        << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getVertInitString()) << "}"
     237#endif
    183238        << "\n";
    184239    std::string ostr = oss.str();
     
    221276    if (g_renderer->mapMouseCoords(x, y, mapPoint)) {
    222277        osgEarth::Viewpoint vpt = g_renderer->getViewpoint();
     278#ifdef NEW_VIEWPOINT_API
     279        vpt.focalPoint() = mapPoint;
     280        vpt.range()->set(vpt.range()->getValue() * zoom, osgEarth::Units::METERS);
     281#else
    223282        vpt.x() = mapPoint.x();
    224283        vpt.y() = mapPoint.y();
    225284        vpt.z() = mapPoint.z();
    226285        vpt.setRange(vpt.getRange() * zoom);
     286#endif
    227287        g_renderer->setViewpoint(vpt, duration);
    228288    } else {
     
    361421        }
    362422    }
     423    const osgEarth::SpatialReference *srs = g_renderer->getMapSRS();
    363424    if (objc > 9) {
    364425        char *srsInit = Tcl_GetString(objv[9]);
    365426        if (strlen(srsInit) > 0) {
    366             osgEarth::SpatialReference *srs = NULL;
    367427            if (objc > 10) {
    368428                char *vertDatum = Tcl_GetString(objv[10]);
     
    372432            }
    373433            if (srs == NULL) {
     434                ERROR("Couldn't get SRS from init string: %s", srsInit);
    374435                return TCL_ERROR;
    375436            }
    376             osgEarth::Viewpoint view(x, y, z, heading, pitch, distance, srs);
    377             g_renderer->setViewpoint(view, duration);
    378         } else {
    379             osgEarth::Viewpoint view(x, y, z, heading, pitch, distance);
    380             g_renderer->setViewpoint(view, duration);
    381         }
    382     } else {
    383         osgEarth::Viewpoint view(x, y, z, heading, pitch, distance);
    384         g_renderer->setViewpoint(view, duration);
    385     }
     437        }
     438    }
     439#ifdef NEW_VIEWPOINT_API
     440    osgEarth::Viewpoint view;
     441    view.focalPoint() = osgEarth::GeoPoint(srs, x, y, z);
     442    view.heading() = osgEarth::Angle(heading, osgEarth::Units::DEGREES);
     443    view.pitch() = osgEarth::Angle(pitch, osgEarth::Units::DEGREES);
     444    view.range() = osgEarth::Distance(distance, osgEarth::Units::METERS);
     445#else
     446    osgEarth::Viewpoint view(x, y, z, heading, pitch, distance, srs);
     447#endif
     448    g_renderer->setViewpoint(view, duration);
    386449    return TCL_OK;
    387450}
     
    834897                 Tcl_Obj *const *objv)
    835898{
    836     g_renderer->setAttribution(Tcl_GetString(objv[2]));
     899    int len;
     900    char *str = Tcl_GetStringFromObj(objv[2], &len);
     901#if 0
     902    Tcl_DString attrib;
     903    Tcl_DStringInit(&attrib);
     904    Tcl_Encoding encoding = Tcl_GetEncoding(interp, "identity");
     905    Tcl_ExternalToUtfDString(encoding, str, len, &attrib);
     906    Tcl_FreeEncoding(encoding);
     907    str = Tcl_DStringValue(&attrib);
     908#endif
     909    g_renderer->setAttribution(str);
     910#if 0
     911    Tcl_DStringFree(&attrib);
     912#endif
    837913    return TCL_OK;
    838914}
     
    11771253        ps->fill()->color() = osgEarth::Symbology::Color(r, g, b);
    11781254        ps->size() = ptSize;
    1179 
     1255#if 1
     1256        osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>();
     1257        alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN;
     1258        alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE;
     1259        //alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_GPU;
     1260#endif
     1261#if 0
    11801262        osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>();
    11811263        rs->depthOffset()->enabled() = true;
    11821264        rs->depthOffset()->minBias() = 1000;
    1183 
     1265#endif
    11841266        osgEarth::Drivers::FeatureGeomModelOptions geomOpts;
    11851267        geomOpts.featureOptions() = opts;
     
    13121394            return TCL_ERROR;
    13131395        }
     1396        osgEarth::Symbology::TextSymbol::Alignment alignment =
     1397            ParseTextAlignment(Tcl_GetString(objv[18]));
    13141398        opts.url() = url;
    13151399
     
    13261410        //ts->font() = "Arial";
    13271411        ts->size() = ftSize;
    1328         ts->alignment() = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_CENTER;
     1412        ts->alignment() = alignment;
    13291413        ts->declutter() = declutter;
    13301414        ts->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8;
     
    13411425        geomOpts.minRange() = 0.f;
    13421426        geomOpts.maxRange() = FLT_MAX;
    1343         if (objc > 18) {
     1427        if (objc > 19) {
    13441428            float min, max;
    1345             if (GetFloatFromObj(interp, objv[18], &min) != TCL_OK ||
    1346                 GetFloatFromObj(interp, objv[19], &max) != TCL_OK) {
     1429            if (GetFloatFromObj(interp, objv[19], &min) != TCL_OK ||
     1430                GetFloatFromObj(interp, objv[20], &max) != TCL_OK) {
    13471431                return TCL_ERROR;
    13481432            }
     
    17181802                strcmp(profile, "epsg:4326") == 0 ||
    17191803                strcmp(profile, "wgs84") == 0 ||
    1720                 strcmp(profile, "plate-carre") == 0) {
     1804                strcmp(profile, "plate-carre") == 0 ||
     1805                strcmp(profile, "plate-carree") == 0) {
    17211806                if (bounds[0] < -180. || bounds[0] > 180. ||
    17221807                    bounds[2] < -180. || bounds[2] > 180. ||
     
    23912476            }
    23922477        }
     2478#if 0
     2479        Tcl_DString tmp;
     2480        Tcl_DStringInit(&tmp);
     2481        Tcl_Encoding encoding = Tcl_GetEncoding(interp, "identity");
     2482        TRACE("Encoding name: %s", Tcl_GetEncodingName(encoding));
     2483        Tcl_ExternalToUtfDString(encoding, (const char *)buffer, numBytes, &tmp);
     2484        Tcl_FreeEncoding(encoding);
     2485        Tcl_DStringAppend(&command, Tcl_DStringValue(&tmp), Tcl_DStringLength(&tmp));
     2486        Tcl_DStringFree(&tmp);
     2487#else
    23932488        Tcl_DStringAppend(&command, (char *)buffer, numBytes);
     2489#endif
    23942490        if (Tcl_CommandComplete(Tcl_DStringValue(&command))) {
    23952491            struct timeval start, finish;
     
    24812577GeoVis::initTcl(Tcl_Interp *interp, ClientData clientData)
    24822578{
     2579    TRACE("LANG: %s", getenv("LANG"));
     2580    Tcl_GetEncodingNames(interp);
     2581    TRACE("Supported encodings: %s", Tcl_GetStringResult(interp));
     2582    int result = Tcl_Eval(interp, "encoding system\n");
     2583    if (result == TCL_OK) {
     2584        TRACE("Current system encoding: %s", Tcl_GetStringResult(interp));
     2585    } else {
     2586        ERROR("Couldn't determine system encoding");
     2587    }
     2588    const char *encoding = "utf-8";
     2589    if (Tcl_SetSystemEncoding(interp, encoding) != TCL_OK) {
     2590        TRACE("Failed to set Tcl encoding to %s", encoding);
     2591    } else {
     2592        TRACE("Set system encoding to %s", encoding);
     2593    }
     2594
    24832595    Tcl_MakeSafe(interp);
     2596
    24842597    Tcl_CreateObjCommand(interp, "camera",         CameraCmd,         clientData, NULL);
    24852598    Tcl_CreateObjCommand(interp, "clientinfo",     ClientInfoCmd,     clientData, NULL);
  • geovis/trunk/geovis_protocol.txt

    r5151 r5775  
    178178map layer add <layerName> line <url> <r> <g> <b> <width>
    179179    Add a line feature layer from a file or URL
    180 map layer add <layerName> text <url> <content> <priority> <fgR> <fgG> <fgB> <bgR> <bgG> <bgB> <haloWidth> <fontSize> <removeDupes> <declutter> <visibilityRangeMin> <visibilityRangeMax>
     180map layer add <layerName> text <url> <content> <priority> <fgR> <fgG> <fgB> <bgR> <bgG> <bgB> <haloWidth> <fontSize> <removeDupes> <declutter> <alignment> <visibilityRangeMin> <visibilityRangeMax>
    181181    Add a text symbol layer from a file or URL
    182182
Note: See TracChangeset for help on using the changeset viewer.