Changeset 4645 for geovis/trunk
- Timestamp:
- Oct 8, 2014, 10:25:39 AM (10 years ago)
- Location:
- geovis/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/Renderer.cpp
r4643 r4645 24 24 #endif 25 25 26 #include <osgDB/WriteFile> 26 27 #include <osgDB/FileUtils> 27 28 #include <osgDB/FileNameUtils> … … 45 46 #include <osgEarth/DateTime> 46 47 #include <osgEarth/Pickers> 48 #include <osgEarthFeatures/Feature> 49 #include <osgEarthSymbology/Color> 50 #include <osgEarthSymbology/Geometry> 51 #include <osgEarthSymbology/Style> 52 #include <osgEarthSymbology/StyleSheet> 53 #include <osgEarthSymbology/IconSymbol> 54 #include <osgEarthSymbology/LineSymbol> 55 47 56 #include <osgEarthAnnotation/AnnotationNode> 57 #include <osgEarthAnnotation/FeatureNode> 48 58 #include <osgEarthAnnotation/PlaceNode> 49 59 #include <osgEarthAnnotation/HighlightDecoration> … … 999 1009 return false; 1000 1010 } 1011 bool ret = true; 1001 1012 osg::Camera *cam = _viewer->getCamera(); 1002 1013 osg::Matrixd MVP = cam->getViewMatrix() * cam->getProjectionMatrix(); … … 1019 1030 std::numeric_limits<double>::quiet_NaN(), 1020 1031 std::numeric_limits<double>::quiet_NaN()); 1032 ret = false; 1021 1033 continue; 1022 1034 } … … 1039 1051 TRACE("screen: %g,%g,%g", itr->x(), itr->y(), itr->z()); 1040 1052 } 1041 return true; 1053 return ret; 1054 } 1055 1056 bool Renderer::mouseToLatLong(int mouseX, int mouseY, 1057 double *latitude, double *longitude) 1058 { 1059 if (getMapSRS() == NULL) 1060 return false; 1061 const osgEarth::SpatialReference *outSRS = 1062 getMapSRS()->getGeographicSRS(); 1063 if (outSRS == NULL) 1064 return false; 1065 osgEarth::GeoPoint mapPoint; 1066 if (mapMouseCoords(mouseX, mouseY, mapPoint)) { 1067 mapPoint = mapPoint.transform(outSRS); 1068 *longitude = mapPoint.x(); 1069 *latitude = mapPoint.y(); 1070 return true; 1071 } else { 1072 return false; 1073 } 1042 1074 } 1043 1075 … … 1273 1305 } 1274 1306 1275 void Renderer::addPlaceNode(double latitude, double longitude, char *labelText) 1307 void Renderer::initAnnotations() 1308 { 1309 if (!_annotations.valid()) { 1310 _annotations = new osg::Group(); 1311 _annotations->setName("Annotations"); 1312 _sceneRoot->addChild(_annotations.get()); 1313 _placeNodes = new osg::Group(); 1314 _placeNodes->setName("Place Nodes"); 1315 osgEarth::Decluttering::setEnabled(_placeNodes->getOrCreateStateSet(), true); 1316 _annotations->addChild(_placeNodes.get()); 1317 } 1318 } 1319 1320 void Renderer::initBoxSelection(int x, int y) 1321 { 1322 double latitude, longitude; 1323 if (!mouseToLatLong(x, y, &latitude, &longitude)) { 1324 return; 1325 } 1326 _anchorLat = latitude; 1327 _anchorLong = longitude; 1328 addRhumbBox(latitude, latitude, longitude, longitude); 1329 } 1330 1331 void Renderer::updateBoxSelection(int x, int y) 1332 { 1333 osgEarth::Annotation::FeatureNode *node = _selectionBox.get(); 1334 double nlat, nlong; 1335 if (!mouseToLatLong(x, y, &nlat, &nlong)) { 1336 return; 1337 } 1338 double latMin, latMax, longMin, longMax; 1339 if (nlong >= _anchorLong && nlat >= _anchorLat) { 1340 // +x +y 1341 longMin = _anchorLong; 1342 latMin = _anchorLat; 1343 longMax = nlong; 1344 latMax = nlat; 1345 } else if (nlong < _anchorLong && nlat >= _anchorLat) { 1346 // -x +y 1347 longMin = nlong; 1348 latMin = _anchorLat; 1349 longMax = _anchorLong; 1350 latMax = nlat; 1351 } else if (nlong < _anchorLong && nlat < _anchorLat) { 1352 // -x -y 1353 longMin = nlong; 1354 latMin = nlat; 1355 longMax = _anchorLong; 1356 latMax = _anchorLat; 1357 } else { 1358 // +x -y 1359 longMin = _anchorLong; 1360 latMin = nlat; 1361 longMax = nlong; 1362 latMax = _anchorLat; 1363 } 1364 osgEarth::Symbology::Geometry *geom = node->getFeature()->getGeometry(); 1365 (*geom)[0] = osg::Vec3d(longMax, latMin, 0); 1366 (*geom)[1] = osg::Vec3d(longMin, latMin, 0); 1367 (*geom)[2] = osg::Vec3d(longMin, latMax, 0); 1368 (*geom)[3] = osg::Vec3d(longMax, latMax, 0); 1369 node->init(); 1370 _needsRedraw = true; 1371 } 1372 1373 void Renderer::clearBoxSelection() 1374 { 1375 if (_annotations.valid() && _selectionBox.valid()) { 1376 _annotations->removeChild(_selectionBox.get()); 1377 _selectionBox = NULL; 1378 } 1379 _needsRedraw = true; 1380 } 1381 1382 void Renderer::addRhumbBox(double latMin, double latMax, 1383 double longMin, double longMax) 1276 1384 { 1277 1385 if (!_mapNode.valid()) { … … 1279 1387 return; 1280 1388 } 1281 if (!_annotations.valid()) { 1282 _annotations = new osg::Group(); 1283 _sceneRoot->addChild(_annotations.get()); 1284 _placeNodes = new osg::Group(); 1285 osgEarth::Decluttering::setEnabled(_placeNodes->getOrCreateStateSet(), true); 1286 _annotations->addChild(_placeNodes.get()); 1287 } 1389 initAnnotations(); 1390 1391 if (_selectionBox.valid()) { 1392 osgEarth::Symbology::Geometry *geom = _selectionBox->getFeature()->getGeometry(); 1393 (*geom)[0] = osg::Vec3d(longMax, latMin, 0); 1394 (*geom)[1] = osg::Vec3d(longMin, latMin, 0); 1395 (*geom)[2] = osg::Vec3d(longMin, latMax, 0); 1396 (*geom)[3] = osg::Vec3d(longMax, latMax, 0); 1397 _selectionBox->init(); 1398 } else { 1399 const osgEarth::SpatialReference* geoSRS = _mapNode->getMapSRS()->getGeographicSRS(); 1400 osgEarth::Symbology::Geometry *geom = new osgEarth::Symbology::Polygon(); 1401 geom->push_back(osg::Vec3d(longMax, latMin, 0)); 1402 geom->push_back(osg::Vec3d(longMin, latMin, 0)); 1403 geom->push_back(osg::Vec3d(longMin, latMax, 0)); 1404 geom->push_back(osg::Vec3d(longMax, latMax, 0)); 1405 osgEarth::Symbology::Style boxStyle; 1406 #if 1 1407 osgEarth::Symbology::PolygonSymbol *poly = boxStyle.getOrCreate<osgEarth::Symbology::PolygonSymbol>(); 1408 poly->fill()->color() = osgEarth::Symbology::Color::Cyan; 1409 poly->fill()->color().a() = 0.5; 1410 //#else 1411 osgEarth::Symbology::LineSymbol *line = boxStyle.getOrCreate<osgEarth::Symbology::LineSymbol>(); 1412 line->stroke()->color() = osgEarth::Symbology::Color::Yellow; 1413 line->stroke()->width() = 2.0f; 1414 //line->creaseAngle() = 45.0f; 1415 line->tessellation() = 10; 1416 #endif 1417 osgEarth::Symbology::AltitudeSymbol *alt = boxStyle.getOrCreate<osgEarth::Symbology::AltitudeSymbol>(); 1418 alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; 1419 //alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_GPU; 1420 alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE; 1421 //alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_SCENE; 1422 #if 0 1423 osgEarth::Symbology::RenderSymbol* rs = boxStyle.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>(); 1424 rs->depthOffset()->enabled() = true; 1425 rs->depthOffset()->minBias() = 1000; 1426 #endif 1427 osgEarth::Features::Feature *feature = new osgEarth::Features::Feature(geom, geoSRS, boxStyle); 1428 //feature->geoInterp() = osgEarth::GEOINTERP_GREAT_CIRCLE; 1429 feature->geoInterp() = osgEarth::GEOINTERP_RHUMB_LINE; 1430 _selectionBox = 1431 new osgEarth::Annotation::FeatureNode(_mapNode, feature); 1432 _annotations->addChild(_selectionBox.get()); 1433 } 1434 1435 _needsRedraw = true; 1436 } 1437 1438 void Renderer::addPlaceNode(double latitude, double longitude, char *labelText) 1439 { 1440 if (!_mapNode.valid()) { 1441 ERROR("No map node"); 1442 return; 1443 } 1444 initAnnotations(); 1288 1445 1289 1446 const osgEarth::SpatialReference* geoSRS = _mapNode->getMapSRS()->getGeographicSRS(); … … 1291 1448 osgEarth::Symbology::Style pin; 1292 1449 pin.getOrCreate<osgEarth::Symbology::IconSymbol>()->url()->setLiteral(getPinIcon()); 1293 osgEarth::Annotation::AnnotationNode *anno = new osgEarth::Annotation::PlaceNode(_mapNode, osgEarth::GeoPoint(geoSRS, longitude, latitude), labelText, pin); 1450 osgEarth::Annotation::AnnotationNode *anno = 1451 new osgEarth::Annotation::PlaceNode(_mapNode, osgEarth::GeoPoint(geoSRS, longitude, latitude), labelText, pin); 1294 1452 _placeNodes->addChild(anno); 1295 1453 osgEarth::Annotation::DecorationInstaller … … 1300 1458 scaleInstaller("hover", new osgEarth::Annotation::ScaleDecoration(1.1f)); 1301 1459 _placeNodes->accept(scaleInstaller); 1460 #if 0 1461 writeScene("/tmp/test.osg"); 1462 #endif 1302 1463 _needsRedraw = true; 1303 1464 } … … 1332 1493 } 1333 1494 } 1495 #if 0 1496 writeScene("/tmp/test.osgt"); 1497 #endif 1334 1498 } 1335 1499 for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = toUnHover.begin(); … … 1374 1538 TRACE("NO Picker hits"); 1375 1539 } 1540 #if 0 1541 writeScene("/tmp/test.osg"); 1542 #endif 1376 1543 } 1377 1544 … … 1610 1777 1611 1778 if (_manipulator.valid()) { 1779 // +y = zoom out, -y = zoom in 1612 1780 TRACE("camDist: %g", _manipulator->getDistance()); 1613 // FIXME: zoom here wants y mouse coords in normalized viewport coords 1781 if ((_mapScale < 0.0 && y > 0.0) || 1782 (_mapScale < 0.1 && y < 0.0) || 1783 (_mapScale > 40000.0 && y > 0.0)) 1784 return; 1614 1785 #if 1 1615 1786 _manipulator->zoom(0, y); … … 2001 2172 //double scaleUSSurveyFeet = scale * 3937.0/1200.0; // US survey foot = 1200/3937 m 2002 2173 TRACE("m: %g px: %g m/px: %g", meters, pixelWidth, scale); 2174 _mapScale = scale; 2003 2175 switch (_scaleBarUnits) { 2004 2176 case UNITS_NAUTICAL_MILES: { … … 2088 2260 return retStr; 2089 2261 } 2262 2263 void Renderer::writeScene(const std::string& file) 2264 { 2265 if (_sceneRoot.valid()) { 2266 osgDB::writeNodeFile(*_sceneRoot.get(), file); 2267 } 2268 } -
geovis/trunk/Renderer.h
r4636 r4645 32 32 #include <osgEarth/GeoData> 33 33 #include <osgEarthAnnotation/AnnotationNode> 34 #include <osgEarthAnnotation/FeatureNode> 34 35 #include <osgEarthUtil/EarthManipulator> 35 36 #include <osgEarthUtil/MouseCoordsTool> … … 371 372 } 372 373 374 bool mouseToLatLong(int mouseX, int mouseY, double *latitude, double *longitude); 375 373 376 bool getWorldCoords(const osgEarth::GeoPoint& mapPt, osg::Vec3d *world); 374 377 … … 423 426 std::string getCanonicalPath(const std::string& url) const; 424 427 428 void writeScene(const std::string& file); 429 430 void addRhumbBox(double latMin, double latMax, double longMin, double longMax); 431 432 void initBoxSelection(int x, int y); 433 void updateBoxSelection(int x, int y); 434 void clearBoxSelection(); 435 425 436 private: 426 437 typedef std::tr1::unordered_map<ColorMapId, osg::ref_ptr<osg::TransferFunction1D> > ColorMapHashmap; … … 429 440 void setupCache(); 430 441 442 void initAnnotations(); 443 431 444 void initViewer(); 432 445 … … 454 467 bool _needsRedraw; 455 468 int _windowWidth, _windowHeight; 469 double _mapScale; 456 470 float _bgColor[3]; 457 471 … … 472 486 osg::ref_ptr<osg::Group> _graticule; 473 487 osg::ref_ptr<osg::Group> _annotations; 488 double _anchorLat, _anchorLong; 489 osg::ref_ptr<osgEarth::Annotation::FeatureNode> _selectionBox; 474 490 osg::ref_ptr<osg::Group> _placeNodes; 475 491 std::set<osgEarth::Annotation::AnnotationNode *> _hovered; -
geovis/trunk/RendererCmd.cpp
r4636 r4645 28 28 #include <osgEarthSymbology/Style> 29 29 #include <osgEarthSymbology/StyleSheet> 30 #include <osgEarthSymbology/IconSymbol> 30 31 #include <osgEarthSymbology/LineSymbol> 31 32 #include <osgEarthSymbology/RenderSymbol> … … 762 763 proc = GetOpFromObj(interp, nKeyOps, keyOps, 763 764 CMDSPEC_ARG1, objc, objv, 0); 765 if (proc == NULL) { 766 return TCL_ERROR; 767 } 768 return (*proc) (clientData, interp, objc, objv); 769 } 770 771 772 static int 773 MapBoxClearOp(ClientData clientData, Tcl_Interp *interp, int objc, 774 Tcl_Obj *const *objv) 775 { 776 g_renderer->clearBoxSelection(); 777 778 return TCL_OK; 779 } 780 781 static int 782 MapBoxInitOp(ClientData clientData, Tcl_Interp *interp, int objc, 783 Tcl_Obj *const *objv) 784 { 785 int x, y; 786 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 787 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 788 return TCL_ERROR; 789 } 790 g_renderer->initBoxSelection(x, y); 791 return TCL_OK; 792 } 793 794 static int 795 MapBoxUpdateOp(ClientData clientData, Tcl_Interp *interp, int objc, 796 Tcl_Obj *const *objv) 797 { 798 int x, y; 799 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 800 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 801 return TCL_ERROR; 802 } 803 g_renderer->updateBoxSelection(x, y); 804 return TCL_OK; 805 } 806 807 static CmdSpec mapBoxOps[] = { 808 {"clear", 1, MapBoxClearOp, 3, 3, ""}, 809 {"init", 1, MapBoxInitOp, 5, 5, "x y"}, 810 {"update", 1, MapBoxUpdateOp, 5, 5, "x y"}, 811 }; 812 static int nMapBoxOps = NumCmdSpecs(mapBoxOps); 813 814 static int 815 MapBoxOp(ClientData clientData, Tcl_Interp *interp, int objc, 816 Tcl_Obj *const *objv) 817 { 818 Tcl_ObjCmdProc *proc; 819 820 proc = GetOpFromObj(interp, nMapBoxOps, mapBoxOps, 821 CMDSPEC_ARG2, objc, objv, 0); 764 822 if (proc == NULL) { 765 823 return TCL_ERROR; … … 1021 1079 osgEarth::Symbology::PolygonSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::PolygonSymbol>(); 1022 1080 ls->fill()->color() = osgEarth::Symbology::Color::White; 1023 1081 #if 0 1082 osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>(); 1083 alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; 1084 alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_DRAPE; 1085 //alt->technique() = osgEarth::Symbology::AltitudeSymbol::TECHNIQUE_GPU; 1086 #endif 1024 1087 osgEarth::Symbology::RenderSymbol* rs = style.getOrCreateSymbol<osgEarth::Symbology::RenderSymbol>(); 1025 1088 rs->depthOffset()->enabled() = true; … … 1330 1393 // Get lat/long 1331 1394 double latitude, longitude; 1332 const osgEarth::SpatialReference *outSRS = 1333 g_renderer->getMapSRS()->getGeographicSRS(); 1334 osgEarth::GeoPoint mapPoint; 1335 if (g_renderer->mapMouseCoords(x, y, mapPoint)) { 1336 mapPoint = mapPoint.transform(outSRS); 1337 longitude = mapPoint.x(); 1338 latitude = mapPoint.y(); 1339 } else { 1395 if (!g_renderer->mouseToLatLong(x, y, &latitude, &longitude)) { 1340 1396 USER_ERROR("Can't add pin here"); 1341 1397 return TCL_OK; … … 1666 1722 1667 1723 static CmdSpec mapOps[] = { 1724 {"box", 1, MapBoxOp, 3, 0, "op ?params..."}, 1668 1725 {"coords", 1, MapCoordsOp, 4, 6, "token coords ?srs? ?verticalDatum?"}, 1669 1726 {"grid", 1, MapGraticuleOp, 3, 4, "bool ?type?"},
Note: See TracChangeset
for help on using the changeset viewer.