Esempio n. 1
0
void 
LineOfSightTether::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
    if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
    {
        LineOfSightNode* los = static_cast<LineOfSightNode*>(node);

        if (_startNode.valid())
        {
            osg::Vec3d worldStart = getNodeCenter(_startNode);

            //Convert to mappoint since that is what LOS expects
            GeoPoint mapStart;
            los->getMapNode()->getMap()->worldPointToMapPoint( worldStart, mapStart );
            los->setStart( mapStart.vec3d() );
        }

        if (_endNode.valid())
        {
            osg::Vec3d worldEnd = getNodeCenter( _endNode );

            //Convert to mappoint since that is what LOS expects
            GeoPoint mapEnd;
            los->getMapNode()->getMap()->worldPointToMapPoint( worldEnd, mapEnd );
            los->setEnd( mapEnd.vec3d() );
        }
    }
    traverse(node, nv);
}
      bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
      {
          if (ea.getEventType() == ea.PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
          {
              osg::Vec3d world;
              if ( _mapNode->getTerrain()->getWorldCoordsUnderMouse( aa.asView(), ea.getX(), ea.getY(), world ))
              {
                  GeoPoint mapPoint;
                  _mapNode->getMap()->worldPointToMapPoint( world, mapPoint );

                  if (!_startValid)
                  {
                      _startValid = true;
                      _start = mapPoint.vec3d();
                      if (_featureNode.valid())
                      {
                          _root->removeChild( _featureNode.get() );
                          _featureNode = 0;
                      }
                  }
                  else
                  {
                      _end = mapPoint.vec3d();
                      compute();
                      _startValid = false;                    
                  }
              }        
          }
          return false;
      }
Esempio n. 3
0
bool
LineOfSightNode::computeLOS( osgEarth::MapNode* mapNode, const osg::Vec3d& start, const osg::Vec3d& end, AltitudeModeEnum altitudeMode, osg::Vec3d& hit )
{
    const SpatialReference* mapSRS = mapNode->getMapSRS();

    osg::Vec3d startWorld, endWorld;
    if (altitudeMode == AltitudeMode::ABSOLUTE)
    {
        mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS, start), startWorld );
        mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS, end), endWorld );
    }
    else
    {
        getRelativeWorld(start.x(), start.y(), start.z(), mapNode, startWorld);
        getRelativeWorld(end.x(), end.y(), end.z(), mapNode, endWorld);
    }
    
    osgSim::LineOfSight los;
    los.setDatabaseCacheReadCallback(0);
    unsigned int index = los.addLOS(startWorld, endWorld);
    los.computeIntersections(mapNode);
    osgSim::LineOfSight::Intersections hits = los.getIntersections(0);    
    if (hits.size() > 0)
    {
        osg::Vec3d hitWorld = *hits.begin();
        GeoPoint mapHit;
        mapNode->getMap()->worldPointToMapPoint(hitWorld, mapHit);
        hit = mapHit.vec3d();
        return false;
    }
    return true;
}
Esempio n. 4
0
bool
AddPointHandler::addPoint( float x, float y, osgViewer::View* view )
{
    osg::Vec3d world;    
    MapNode* mapNode = _featureNode->getMapNode();

    if ( mapNode->getTerrain()->getWorldCoordsUnderMouse( view, x, y, world ) )
    {
        // Get the map point from the world
        GeoPoint mapPoint;
        mapPoint.fromWorld( mapNode->getMapSRS(), world );

        Feature* feature = _featureNode->getFeature();

        if ( feature )            
        {
            // Convert the map point to the feature's SRS
            GeoPoint featurePoint = mapPoint.transform( feature->getSRS() );

            feature->getGeometry()->push_back( featurePoint.vec3d() );            
            _featureNode->init();            
            return true;
        }        
    }
    return false;
}
Esempio n. 5
0
bool
MapInfo::toWorldPoint( const GeoPoint& input, osg::Vec3d& output ) const
{
    return input.isValid() ?
        input.getSRS()->transformToWorld(input.vec3d(), output) :
        false;
}
Esempio n. 6
0
void 
RadialLineOfSightTether::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
    if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
    {
        RadialLineOfSightNode* los = static_cast<RadialLineOfSightNode*>(node);

        osg::Vec3d worldCenter = getNodeCenter( _node );

        //Convert center to mappoint since that is what LOS expects
        GeoPoint mapCenter;
        los->getMapNode()->getMap()->worldPointToMapPoint( worldCenter, mapCenter );

        los->setCenter( mapCenter.vec3d() );      
    }
    traverse(node, nv);
}
void LOSControlWidget::onItemDoubleClicked(QListWidgetItem* item)
{
  if (!_manager.valid() || !_map.valid() || _views.size() == 0)
    return;

  LOSListWidgetItem* losItem = dynamic_cast<LOSListWidgetItem*>(item);
  if (losItem && losItem->los())
  {
    osg::Vec3d center = losItem->los()->getBound().center();

    GeoPoint output;
    _map->worldPointToMapPoint(center, output);

    double range = losItem->los()->getBound().radius() / 0.267949849;

    _manager->doAction(this, new SetViewpointAction(osgEarth::Viewpoint(output.vec3d(), 0.0, -90.0, range), _views));
  }
}
Esempio n. 8
0
void
LineOfSightNode::compute(osg::Node* node, bool backgroundThread)
{
    if (_start != _end)
    {
      const SpatialReference* mapSRS = _mapNode->getMapSRS();

      //Computes the LOS and redraws the scene
      if (_startAltitudeMode == AltitudeMode::ABSOLUTE)
          _mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS,_start), _startWorld );
      else
          getRelativeWorld(_start.x(), _start.y(), _start.z(), _mapNode.get(), _startWorld);

      if (_endAltitudeMode == AltitudeMode::ABSOLUTE)
          _mapNode->getMap()->toWorldPoint( GeoPoint(mapSRS,_end), _endWorld );
      else
          getRelativeWorld(_end.x(), _end.y(), _end.z(), _mapNode.get(), _endWorld);
      
      osgSim::LineOfSight los;
      los.setDatabaseCacheReadCallback(0);
      unsigned int index = los.addLOS(_startWorld, _endWorld);
      los.computeIntersections(node);
      osgSim::LineOfSight::Intersections hits = los.getIntersections(0);    
      if (hits.size() > 0)
      {
          _hasLOS = false;
          _hitWorld = *hits.begin();
          GeoPoint mapHit;
          _mapNode->getMap()->worldPointToMapPoint( _hitWorld, mapHit);
          _hit = mapHit.vec3d();
      }
      else
      {
          _hasLOS = true;
      }
    }

    draw(backgroundThread);

    for( ChangedCallbackList::iterator i = _changedCallbacks.begin(); i != _changedCallbacks.end(); i++ )
    {
        i->get()->onChanged();
    }	
}
Esempio n. 9
0
bool
OrthoNode::updateTransforms( const GeoPoint& p, osg::Node* patch )
{
    if ( getMapNode() )
    {
        //OE_NOTICE << "updateTransforms" << std::endl;
        // make sure the point is absolute to terrain
        GeoPoint absPos(p);
        if ( !makeAbsolute(absPos, patch) )
            return false;

        osg::Matrixd local2world;
        if ( !absPos.createLocalToWorld(local2world) )
            return false;

        // apply the local tangent plane offset:
        local2world.preMult( osg::Matrix::translate(_localOffset) );

        // update the xforms:
        _autoxform->setPosition( local2world.getTrans() );
        _matxform->setMatrix( local2world );
        
        osg::Vec3d world = local2world.getTrans();
        if (_horizonCuller.valid())
        {
            _horizonCuller->_world = world;
        }

        if (_occlusionCuller.valid())
        {                                
            _occlusionCuller->setWorld( adjustOcclusionCullingPoint( world ));
        } 
    }
    else
    {
        osg::Vec3d absPos = p.vec3d() + _localOffset;
        _autoxform->setPosition( absPos );
        _matxform->setMatrix( osg::Matrix::translate(absPos) );
    }

    dirtyBound();
    return true;
}
void LOSCreationDialog::centerMapOnNode(osg::Node* node)
{
  if (node && _map.valid() && _manager.valid() && _views)
  {
    AnnotationNode* annoNode = dynamic_cast<AnnotationNode*>(node);
    if (annoNode && annoNode->getAnnotationData() && annoNode->getAnnotationData()->getViewpoint())
    {
      _manager->doAction(this, new SetViewpointAction(osgEarth::Viewpoint(*annoNode->getAnnotationData()->getViewpoint()), *_views));
    }
    else
    {
      osg::Vec3d center = node->getBound().center();

      GeoPoint output;
      _map->worldPointToMapPoint(center, output);

      _manager->doAction(this, new SetViewpointAction(osgEarth::Viewpoint(output.vec3d(), 0.0, -90.0, 1e5), *_views));
    }
  }
}
Esempio n. 11
0
bool
LocalizedNode::updateTransform( const GeoPoint& p, osg::Node* patch )
{
    if ( p.isValid() )
    {
        GeoPoint absPos(p);
        if ( !makeAbsolute(absPos, patch) )
            return false;

        OE_DEBUG << LC << "Update transforms for position: " << absPos.x() << ", " << absPos.y() << ", " << absPos.z()
            << std::endl;

        osg::Matrixd local2world;
        absPos.createLocalToWorld( local2world );
        
        // apply the local offsets
        local2world.preMult( osg::Matrix::translate(_localOffset) );

        getTransform()->setMatrix( 
            osg::Matrix::scale (_scale)         * 
            osg::Matrix::rotate(_localRotation) *
            local2world  );
    }
    else
    {
        osg::Vec3d absPos = p.vec3d() + _localOffset;

        getTransform()->setMatrix(
            osg::Matrix::scale    (_scale)         * 
            osg::Matrix::rotate   (_localRotation) *
            osg::Matrix::translate(absPos) );
    }
    

    dirtyBound();

    return true;
}
Esempio n. 12
0
    void update( float x, float y, osgViewer::View* view )
    {
        bool yes = false;

        // look under the mouse:
        osg::Vec3d world;
        osgUtil::LineSegmentIntersector::Intersections hits;
        if ( view->computeIntersections(x, y, hits) )
        {
            world = hits.begin()->getWorldIntersectPoint();

            // convert to map coords:
            GeoPoint mapPoint;
            mapPoint.fromWorld( _terrain->getSRS(), world );
            mapPoint.z() = 0;

            // do an elevation query:
            double query_resolution = 0; // max.
            double out_hamsl        = 0.0;
            double out_resolution   = 0.0;

            bool ok = _query.getElevation( 
                mapPoint,
                out_hamsl,
                query_resolution, 
                &out_resolution );
            mapPoint.z() = out_hamsl;
            _mapPoint = mapPoint;

            

            GeometryFactory factory(SpatialReference::create("wgs84"));
            Geometry* geom = 0;
            if (_tool == TOOL_RECTANGLE)
            {
                geom = factory.createRectangle(mapPoint.vec3d(), _radius,_radius);
            }
            else if (_tool == TOOL_CIRCLE || _tool == TOOL_BLAST)
            {
                geom = factory.createCircle(mapPoint.vec3d(), _radius);
            }

            Feature* feature = new Feature(geom, SpatialReference::create("wgs84"));

            if (_featureNode.valid())
            {
                _root->removeChild( _featureNode );
                _featureNode = 0;
            }

            Style style;
            style.getOrCreateSymbol<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
            style.getOrCreateSymbol<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;
            if (_tool != TOOL_BLAST)
            {
                style.getOrCreateSymbol<PolygonSymbol>()->fill()->color() = Color(Color::Cyan, 0.5);
            }
            else
            {
                style.getOrCreateSymbol<PolygonSymbol>()->fill()->color() = Color(Color::Red, 0.5);
            }

            _featureNode = new FeatureNode( s_mapNode,
                feature,
                style);
            _root->addChild( _featureNode );
        }
    }
bool
LocalizedNode::updateTransforms( const GeoPoint& p, osg::Node* patch )
{
    if ( p.isValid() )
    {
        GeoPoint absPos(p);
        if ( !makeAbsolute(absPos, patch) )
            return false;

        OE_DEBUG << LC << "Update transforms for position: " << absPos.x() << ", " << absPos.y() << ", " << absPos.z()
            << std::endl;

        osg::Matrixd local2world;
        absPos.createLocalToWorld( local2world );
        
        // apply the local offsets
        local2world.preMult( osg::Matrix::translate(_localOffset) );

        if ( _autoTransform )
        {
            static_cast<osg::AutoTransform*>(_xform.get())->setPosition( local2world.getTrans() );
            static_cast<osg::AutoTransform*>(_xform.get())->setScale( _scale );
            static_cast<osg::AutoTransform*>(_xform.get())->setRotation( _localRotation );
        }
        else
        {
            static_cast<osg::MatrixTransform*>(_xform.get())->setMatrix( 
                osg::Matrix::scale(_scale) * 
                osg::Matrix::rotate(_localRotation) *
                local2world  );
        }

        
        CullNodeByHorizon* culler = dynamic_cast<CullNodeByHorizon*>(_xform->getCullCallback());
        if ( culler )
            culler->_world = local2world.getTrans();
    }
    else
    {
        osg::Vec3d absPos = p.vec3d() + _localOffset;

        if ( _autoTransform )
        {
            static_cast<osg::AutoTransform*>(_xform.get())->setPosition( absPos );
            static_cast<osg::AutoTransform*>(_xform.get())->setScale( _scale );
            static_cast<osg::AutoTransform*>(_xform.get())->setRotation( _localRotation );
        }
        else
        {
            static_cast<osg::MatrixTransform*>(_xform.get())->setMatrix(
                osg::Matrix::scale(_scale) * 
                osg::Matrix::rotate(_localRotation) *
                osg::Matrix::translate(absPos) );
        }
    }
    

    dirtyBound();

    return true;
}