Changeset 4655
- Timestamp:
- Oct 21, 2014, 10:26:44 PM (10 years ago)
- Location:
- geovis/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/Renderer.cpp
r4654 r4655 1073 1073 } 1074 1074 } 1075 1075 #if 0 1076 bool Renderer::mapToLatLong(osgEarth::GeoPoint& mapPoint) 1077 { 1078 if (getMapSRS() == NULL) 1079 return false; 1080 const osgEarth::SpatialReference *outSRS = 1081 getMapSRS()->getGeographicSRS(); 1082 if (outSRS == NULL) 1083 return false; 1084 mapPoint = mapPoint.transform(outSRS); 1085 return true; 1086 } 1087 #endif 1076 1088 /** 1077 1089 * \brief Map screen mouse coordinates to map coordinates … … 1368 1380 (*geom)[3] = osg::Vec3d(longMax, latMax, 0); 1369 1381 node->init(); 1382 for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = _selected.begin(); 1383 itr != _selected.end(); ++itr) { 1384 (*itr)->clearDecoration(); 1385 } 1386 _selected.clear(); 1387 SelectPlaceNodesVisitor spnv(this, latMin, latMax, longMin, longMax); 1388 _sceneRoot->accept(spnv); 1370 1389 _needsRedraw = true; 1390 } 1391 1392 void SelectPlaceNodesVisitor::apply(osg::Node& node) 1393 { 1394 osgEarth::Annotation::PlaceNode *placeNode = 1395 dynamic_cast<osgEarth::Annotation::PlaceNode*>(&node); 1396 if (placeNode != NULL) { 1397 const osgEarth::SpatialReference *outSRS = 1398 _renderer->getMapSRS()->getGeographicSRS(); 1399 osgEarth::GeoPoint pt = placeNode->getPosition(); 1400 pt = pt.transform(outSRS); 1401 if (pt.x() >= _longMin && pt.x() <= _longMax && 1402 pt.y() >= _latMin && pt.y() <= _latMax) { 1403 if (_renderer->select(placeNode)) { 1404 //TRACE("SELECT IT: %p", placeNode); 1405 placeNode->setDecoration("select"); 1406 } 1407 } 1408 } 1409 traverse(node); 1371 1410 } 1372 1411 … … 1377 1416 _selectionBox = NULL; 1378 1417 } 1418 for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = _selected.begin(); 1419 itr != _selected.end(); ++itr) { 1420 (*itr)->clearDecoration(); 1421 } 1422 _selected.clear(); 1379 1423 _needsRedraw = true; 1380 1424 } … … 1450 1494 osgEarth::Annotation::AnnotationNode *anno = 1451 1495 new osgEarth::Annotation::PlaceNode(_mapNode, osgEarth::GeoPoint(geoSRS, longitude, latitude), labelText, pin); 1496 anno->setName(labelText); 1452 1497 _placeNodes->addChild(anno); 1453 1498 osgEarth::Annotation::DecorationInstaller 1454 highlightInstaller("hover", new osgEarth::Annotation::HighlightDecoration()); 1455 _annotations->accept(highlightInstaller); 1499 highlightInstaller("select", new osgEarth::Annotation::HighlightDecoration(osg::Vec4f(1,1,0,0.5))); 1500 _placeNodes->accept(highlightInstaller); 1501 _mapNode->accept(highlightInstaller); 1456 1502 // scale labels when hovering: 1457 1503 osgEarth::Annotation::DecorationInstaller 1458 1504 scaleInstaller("hover", new osgEarth::Annotation::ScaleDecoration(1.1f)); 1459 1505 _placeNodes->accept(scaleInstaller); 1506 _mapNode->accept(scaleInstaller); 1460 1507 #if 0 1461 1508 writeScene("/tmp/test.osg"); … … 1463 1510 _needsRedraw = true; 1464 1511 } 1465 1466 void Renderer::hover PlaceNode(int x, int y, bool invertY)1467 { 1468 if (!_ placeNodes.valid()) {1469 ERROR("No place nodes");1470 return; 1471 } 1472 osgEarth::Picker picker(_viewer.get(), _ placeNodes.get());1512 #if 0 1513 void Renderer::hoverFeatureNodes(int x, int y, bool invertY) 1514 { 1515 if (!_mapNode.valid()) { 1516 ERROR("No map node"); 1517 return; 1518 } 1519 osgEarth::Picker picker(_viewer.get(), _mapNode.get()); 1473 1520 osgEarth::Picker::Hits hits; 1474 1521 float mouseX = (float)x; … … 1477 1524 mouseY = ((float)_windowHeight - mouseY); 1478 1525 } 1526 std::set<osgEarth::Annotation::FeatureNode*> toUnHover; 1527 for (std::set<osgEarth::Annotation::FeatureNode*>::iterator itr = _hovered.begin(); 1528 itr != _hovered.end(); ++itr) { 1529 toUnHover.insert(*itr); 1530 } 1531 if (picker.pick(mouseX, mouseY, hits)) { 1532 TRACE("Picker hits: %d", hits.size()); 1533 for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin(); 1534 hitr != hits.end(); ++hitr) { 1535 osgEarth::Annotation::FeatureNode *anno = 1536 picker.getNode<osgEarth::Annotation::FeatureNode>(*hitr); 1537 if (anno != NULL) { 1538 if (_hovered.find(anno) == _hovered.end()) { 1539 _hovered.insert(anno); 1540 anno->setDecoration("hover"); 1541 _needsRedraw = true; 1542 } 1543 toUnHover.erase(anno); 1544 } 1545 } 1546 #if 0 1547 writeScene("/tmp/test.osgt"); 1548 #endif 1549 } 1550 for (std::set<osgEarth::Annotation::FeatureNode *>::iterator itr = toUnHover.begin(); 1551 itr != toUnHover.end(); ++itr) { 1552 _hovered.erase(*itr); 1553 (*itr)->clearDecoration(); 1554 _needsRedraw = true; 1555 } 1556 } 1557 #endif 1558 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1559 { 1560 if (!_placeNodes.valid()) { 1561 ERROR("No place nodes"); 1562 return; 1563 } 1564 osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get()); 1565 osgEarth::Picker::Hits hits; 1566 float mouseX = (float)x; 1567 float mouseY = (float)y; 1568 if (invertY) { 1569 mouseY = ((float)_windowHeight - mouseY); 1570 } 1479 1571 std::set<osgEarth::Annotation::AnnotationNode*> toUnHover; 1480 1572 for (std::set<osgEarth::Annotation::AnnotationNode*>::iterator itr = _hovered.begin(); … … 1483 1575 } 1484 1576 if (picker.pick(mouseX, mouseY, hits)) { 1485 TRACE("Picker hit !");1577 TRACE("Picker hits: %d", hits.size()); 1486 1578 for (osgEarth::Picker::Hits::const_iterator hitr = hits.begin(); 1487 1579 hitr != hits.end(); ++hitr) { 1580 TRACE("Hit: node %p drawable %p idx %d", picker.getNode<osg::Node>(*hitr), hitr->drawable.get(), hitr->primitiveIndex); 1488 1581 osgEarth::Annotation::AnnotationNode *anno = 1489 1582 picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr); 1490 if (anno != NULL) { 1583 if (anno != NULL && anno->getDecoration().empty()) { 1584 TRACE("Hit AnnotationNode: %p", anno); 1491 1585 if (_hovered.find(anno) == _hovered.end()) { 1492 1586 _hovered.insert(anno); … … 2272 2366 { 2273 2367 if (_sceneRoot.valid()) { 2274 osgDB::writeNodeFile(*_sceneRoot.get(), file); 2275 } 2276 } 2368 GraphPrintVisitor gpv; 2369 _sceneRoot->accept(gpv); 2370 //osgDB::writeNodeFile(*_sceneRoot.get(), file); 2371 } 2372 } -
geovis/trunk/Renderer.h
r4645 r4655 434 434 void clearBoxSelection(); 435 435 436 bool select(osgEarth::Annotation::AnnotationNode *node) 437 { 438 if (_selected.find(node) == _selected.end()) { 439 _selected.insert(node); 440 return true; 441 } else { 442 return false; 443 } 444 } 445 436 446 private: 437 447 typedef std::tr1::unordered_map<ColorMapId, osg::ref_ptr<osg::TransferFunction1D> > ColorMapHashmap; … … 490 500 osg::ref_ptr<osg::Group> _placeNodes; 491 501 std::set<osgEarth::Annotation::AnnotationNode *> _hovered; 502 std::set<osgEarth::Annotation::AnnotationNode *> _selected; 492 503 osg::ref_ptr<osgEarth::MapNode> _mapNode; 493 504 osg::ref_ptr<osgEarth::Map> _map; … … 524 535 }; 525 536 537 class SelectPlaceNodesVisitor : public osg::NodeVisitor 538 { 539 public: 540 SelectPlaceNodesVisitor(Renderer *renderer, 541 double latMin, double latMax, 542 double longMin, double longMax) : 543 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 544 _renderer(renderer), 545 _latMin(latMin), _latMax(latMax), 546 _longMin(longMin), _longMax(longMax) 547 {} 548 549 virtual void apply(osg::Node& node); 550 551 private: 552 Renderer *_renderer; 553 double _latMin, _latMax, _longMin, _longMax; 554 }; 555 526 556 } 527 557 -
geovis/trunk/RendererCmd.cpp
r4645 r4655 1079 1079 osgEarth::Symbology::PolygonSymbol *ls = style.getOrCreateSymbol<osgEarth::Symbology::PolygonSymbol>(); 1080 1080 ls->fill()->color() = osgEarth::Symbology::Color::White; 1081 #if 01081 #if 1 1082 1082 osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>(); 1083 1083 alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; … … 1111 1111 ls->stroke()->color() = osgEarth::Symbology::Color::Black; 1112 1112 ls->stroke()->width() = 2.0f; 1113 #if 01113 #if 1 1114 1114 osgEarth::Symbology::AltitudeSymbol *alt = style.getOrCreateSymbol<osgEarth::Symbology::AltitudeSymbol>(); 1115 1115 alt->clamping() = osgEarth::Symbology::AltitudeSymbol::CLAMP_TO_TERRAIN; -
geovis/trunk/Trace.h
r4422 r4655 9 9 #define GEOVIS_TRACE_H 10 10 11 #include <cstring> 11 12 #include <string> 12 13 13 14 #include <syslog.h> 15 16 #include <osg/NodeVisitor> 14 17 15 18 namespace GeoVis { … … 39 42 #define USER_ERROR(...) GeoVis::logUserMessage(__VA_ARGS__) 40 43 44 class GraphPrintVisitor : public osg::NodeVisitor 45 { 46 public: 47 GraphPrintVisitor() 48 : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 49 {} 50 51 virtual void apply(osg::Node& node) 52 { 53 char space[256]; 54 size_t len = getNodePath().size(); 55 memset(space, ' ', len); 56 space[len] = '\0'; 57 TRACE("%s%s (%s) %p", space, node.className(), node.getName().c_str(), &node); 58 traverse(node); 59 } 60 }; 61 41 62 } 42 63
Note: See TracChangeset
for help on using the changeset viewer.