Changeset 5775
- Timestamp:
- Jul 24, 2015, 5:37:02 PM (9 years ago)
- Location:
- geovis/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/RenderServer.cpp
r5118 r5775 40 40 #endif 41 41 42 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1) 43 #define NEW_VIEWPOINT_API 44 #endif 45 42 46 using namespace GeoVis; 43 47 … … 66 70 size_t len = 0; 67 71 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 68 82 << view.x() << " " 69 83 << view.y() << " " … … 74 88 << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getHorizInitString()) << "}" 75 89 << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getVertInitString()) << "}" 90 #endif 76 91 << "\n"; 77 92 std::string ostr = oss.str(); … … 358 373 g_renderer->setResourcePath(resourcePath); 359 374 375 TRACE("Default Tcl encoding dir: %s", Tcl_GetDefaultEncodingDir()); 376 //Tcl_SetDefaultEncodingDir("encoding"); 377 360 378 Tcl_Interp *interp = Tcl_CreateInterp(); 379 initTcl(interp, NULL); 361 380 362 381 #ifdef USE_THREADS … … 368 387 } 369 388 #endif 370 initTcl(interp, NULL);371 389 372 390 osg::ref_ptr<osg::Image> imgData; -
geovis/trunk/Renderer.cpp
r5152 r5775 47 47 #include <osgEarth/ModelLayer> 48 48 #include <osgEarth/DateTime> 49 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0) 50 #include <osgEarth/IntersectionPicker> 51 #else 49 52 #include <osgEarth/Pickers> 53 #endif 50 54 #include <osgEarthFeatures/Feature> 51 55 #include <osgEarthSymbology/Color> … … 88 92 #include "FileUtil.h" 89 93 #include "Trace.h" 94 95 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1) 96 #define NEW_VIEWPOINT_API 97 #endif 90 98 91 99 #define MSECS_ELAPSED(t1, t2) \ … … 452 460 void Renderer::setAttribution(const std::string& attrib) 453 461 { 462 TRACE("Setting map attribution: '%s'", attrib.c_str()); 454 463 _attribution = attrib; 455 464 if (_copyrightLabel.valid()) { … … 1000 1009 if (_manipulator.valid()) { 1001 1010 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 1003 1020 _manipulator->setViewpoint(v, durationSecs); 1004 1021 _needsRedraw = true; … … 1614 1631 initAnnotations(); 1615 1632 1616 const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS();1633 const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS(); 1617 1634 1618 1635 osgEarth::Symbology::Style pin; … … 1682 1699 } 1683 1700 #endif 1701 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0) 1684 1702 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1685 1703 { … … 1688 1706 return; 1689 1707 } 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 1750 void 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 1792 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1793 { 1794 if (!_placeNodes.valid()) { 1795 TRACE("No place nodes"); 1796 return; 1797 } 1798 1690 1799 osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get()); 1691 1800 osgEarth::Picker::Hits hits; … … 1770 1879 #endif 1771 1880 } 1772 1881 #endif 1773 1882 void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts) 1774 1883 { -
geovis/trunk/Renderer.h
r5118 r5775 19 19 #include <osg/Image> 20 20 #include <osg/TransferFunction> 21 #include <osgText/String> 21 22 #include <osgViewer/Viewer> 22 23 #include <osgGA/StateSetManipulator> -
geovis/trunk/RendererCmd.cpp
r5155 r5775 59 59 #endif 60 60 61 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1) 62 #define NEW_VIEWPOINT_API 63 #endif 64 61 65 using namespace GeoVis; 62 66 … … 154 158 } 155 159 160 static osgEarth::Symbology::TextSymbol::Alignment 161 ParseTextAlignment(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 156 200 static int 157 201 CameraDeleteViewpointOp(ClientData clientData, Tcl_Interp *interp, int objc, … … 173 217 size_t len = 0; 174 218 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 175 229 << view.x() << " " 176 230 << view.y() << " " … … 181 235 << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getHorizInitString()) << "}" 182 236 << " {" << ((view.getSRS() == NULL) ? "" : view.getSRS()->getVertInitString()) << "}" 237 #endif 183 238 << "\n"; 184 239 std::string ostr = oss.str(); … … 221 276 if (g_renderer->mapMouseCoords(x, y, mapPoint)) { 222 277 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 223 282 vpt.x() = mapPoint.x(); 224 283 vpt.y() = mapPoint.y(); 225 284 vpt.z() = mapPoint.z(); 226 285 vpt.setRange(vpt.getRange() * zoom); 286 #endif 227 287 g_renderer->setViewpoint(vpt, duration); 228 288 } else { … … 361 421 } 362 422 } 423 const osgEarth::SpatialReference *srs = g_renderer->getMapSRS(); 363 424 if (objc > 9) { 364 425 char *srsInit = Tcl_GetString(objv[9]); 365 426 if (strlen(srsInit) > 0) { 366 osgEarth::SpatialReference *srs = NULL;367 427 if (objc > 10) { 368 428 char *vertDatum = Tcl_GetString(objv[10]); … … 372 432 } 373 433 if (srs == NULL) { 434 ERROR("Couldn't get SRS from init string: %s", srsInit); 374 435 return TCL_ERROR; 375 436 } 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); 386 449 return TCL_OK; 387 450 } … … 834 897 Tcl_Obj *const *objv) 835 898 { 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 837 913 return TCL_OK; 838 914 } … … 1177 1253 ps->fill()->color() = osgEarth::Symbology::Color(r, g, b); 1178 1254 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 1180 1262 osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>(); 1181 1263 rs->depthOffset()->enabled() = true; 1182 1264 rs->depthOffset()->minBias() = 1000; 1183 1265 #endif 1184 1266 osgEarth::Drivers::FeatureGeomModelOptions geomOpts; 1185 1267 geomOpts.featureOptions() = opts; … … 1312 1394 return TCL_ERROR; 1313 1395 } 1396 osgEarth::Symbology::TextSymbol::Alignment alignment = 1397 ParseTextAlignment(Tcl_GetString(objv[18])); 1314 1398 opts.url() = url; 1315 1399 … … 1326 1410 //ts->font() = "Arial"; 1327 1411 ts->size() = ftSize; 1328 ts->alignment() = osgEarth::Symbology::TextSymbol::ALIGN_CENTER_CENTER;1412 ts->alignment() = alignment; 1329 1413 ts->declutter() = declutter; 1330 1414 ts->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8; … … 1341 1425 geomOpts.minRange() = 0.f; 1342 1426 geomOpts.maxRange() = FLT_MAX; 1343 if (objc > 1 8) {1427 if (objc > 19) { 1344 1428 float min, max; 1345 if (GetFloatFromObj(interp, objv[1 8], &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) { 1347 1431 return TCL_ERROR; 1348 1432 } … … 1718 1802 strcmp(profile, "epsg:4326") == 0 || 1719 1803 strcmp(profile, "wgs84") == 0 || 1720 strcmp(profile, "plate-carre") == 0) { 1804 strcmp(profile, "plate-carre") == 0 || 1805 strcmp(profile, "plate-carree") == 0) { 1721 1806 if (bounds[0] < -180. || bounds[0] > 180. || 1722 1807 bounds[2] < -180. || bounds[2] > 180. || … … 2391 2476 } 2392 2477 } 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 2393 2488 Tcl_DStringAppend(&command, (char *)buffer, numBytes); 2489 #endif 2394 2490 if (Tcl_CommandComplete(Tcl_DStringValue(&command))) { 2395 2491 struct timeval start, finish; … … 2481 2577 GeoVis::initTcl(Tcl_Interp *interp, ClientData clientData) 2482 2578 { 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 2483 2595 Tcl_MakeSafe(interp); 2596 2484 2597 Tcl_CreateObjCommand(interp, "camera", CameraCmd, clientData, NULL); 2485 2598 Tcl_CreateObjCommand(interp, "clientinfo", ClientInfoCmd, clientData, NULL); -
geovis/trunk/geovis_protocol.txt
r5151 r5775 178 178 map layer add <layerName> line <url> <r> <g> <b> <width> 179 179 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>180 map layer add <layerName> text <url> <content> <priority> <fgR> <fgG> <fgB> <bgR> <bgG> <bgB> <haloWidth> <fontSize> <removeDupes> <declutter> <alignment> <visibilityRangeMin> <visibilityRangeMax> 181 181 Add a text symbol layer from a file or URL 182 182
Note: See TracChangeset
for help on using the changeset viewer.