Пример #1
0
void ossimPlanetViewer::findNodesWithId(ossimPlanetViewer::PlanetNodeList& nodeList,
                                        const ossimString& id)
{
   ossimPlanetViewerFindNodesVisitor visitor(id, &nodeList, false);
   
   if(getSceneData())
   {
      getSceneData()->accept(visitor);
   }
}
Пример #2
0
void OSGViewerWidget::startRendering()
{
  addEventHandler(new StateSetManipulator(getSceneData()->getOrCreateStateSet()));

  threaded_painter_.moveToThread(&gl_thread_);
  connect(&gl_thread_, SIGNAL(started()), &threaded_painter_, SLOT(start()));
  gl_thread_.start();
}
Пример #3
0
osg::ref_ptr<ossimPlanetNode> ossimPlanetViewer::findFirstNodeWithId(const ossimString& id)
{
   osg::ref_ptr<ossimPlanetNode> result = 0;
   ossimPlanetViewer::PlanetNodeList nodeList;
   ossimPlanetViewerFindNodesVisitor visitor(id, &nodeList, true);
   
   if(getSceneData())
   {
      getSceneData()->accept(visitor);
   }
   
   if(nodeList.size())
   {
      result = nodeList[0].get();
   }
   
   return result;
}
Пример #4
0
bool ossimPlanetSceneView::pickObjects(osgUtil::IntersectVisitor::HitList& hits,
                                       osg::Node* startNode,
                                       double vx, double vy,
                                       double /*startPointShift*/)
{
   osg::Node* rootNode = 0;
   if(startNode)
   {
      rootNode = startNode;
   }
   else
   {
      rootNode = getSceneData();
   }
   osg::Matrixd proj   = getProjectionMatrix();
   osg::Matrixd view   = getViewMatrix();
   const osg::Viewport* viewport = getViewport();
   osg::Matrixd projToWindow = viewport->computeWindowMatrix();
   osg::Vec3d projPt(vx, vy, 1.0);
   osg::Vec3d windowPt = projPt*projToWindow;
   
   osg::NodePathList parentNodePaths = rootNode->getParentalNodePaths(rootNode);
   for(unsigned int i=0;i<parentNodePaths.size();++i)
   {
      osg::NodePath& nodePath = parentNodePaths[i];
      
      // remove the intersection node from the nodePath as it'll be accounted for
      // in the PickVisitor traversal, so we don't double account for its transform.
      if (!nodePath.empty()) nodePath.pop_back();  
      
      osg::Matrixd modelview(view);
      // modify the view matrix so that it accounts for this nodePath's accumulated transform
      if (!nodePath.empty()) modelview.preMult(computeLocalToWorld(nodePath));
      
      osgUtil::PickVisitor pick(viewport, proj, modelview, windowPt[0], windowPt[1]);
      pick.setTraversalMask(0xffffffff);
      rootNode->accept(pick);
      
      // copy all the hits across to the external hits list
      for(osgUtil::PickVisitor::LineSegmentHitListMap::iterator itr = pick.getSegHitList().begin();
          itr != pick.getSegHitList().end();
          ++itr)
      {
         hits.insert(hits.end(), itr->second.begin(), itr->second.end());
      }
      
   }

   return !hits.empty();
}
Пример #5
0
bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage, osg::Viewport *viewport)
{

    if (!_camera || !viewport) return false;

    osg::ref_ptr<RefMatrix> proj = new osg::RefMatrix(projection);
    osg::ref_ptr<RefMatrix> mv = new osg::RefMatrix(modelview);

    // collect any occluder in the view frustum.
    if (_camera->containsOccluderNodes())
    {
        //std::cout << "Scene graph contains occluder nodes, searching for them"<<std::endl;
        
        
        if (!_collectOccludersVisitor) _collectOccludersVisitor = new osg::CollectOccludersVisitor;
        
        _collectOccludersVisitor->inheritCullSettings(*this);
        
        _collectOccludersVisitor->reset();
        
        _collectOccludersVisitor->setFrameStamp(_frameStamp.get());

        // use the frame number for the traversal number.
        if (_frameStamp.valid())
        {
             _collectOccludersVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
        }

        _collectOccludersVisitor->pushViewport(viewport);
        _collectOccludersVisitor->pushProjectionMatrix(proj.get());
        _collectOccludersVisitor->pushModelViewMatrix(mv.get(),osg::Transform::ABSOLUTE_RF);

        // traverse the scene graph to search for occluder in there new positions.
        _collectOccludersVisitor->traverse(*_camera);

        _collectOccludersVisitor->popModelViewMatrix();
        _collectOccludersVisitor->popProjectionMatrix();
        _collectOccludersVisitor->popViewport();
        
        // sort the occluder from largest occluder volume to smallest.
        _collectOccludersVisitor->removeOccludedOccluders();
        
        
        osg::notify(osg::DEBUG_INFO) << "finished searching for occluder - found "<<_collectOccludersVisitor->getCollectedOccluderSet().size()<<std::endl;
           
        cullVisitor->getOccluderList().clear();
        std::copy(_collectOccludersVisitor->getCollectedOccluderSet().begin(),_collectOccludersVisitor->getCollectedOccluderSet().end(), std::back_insert_iterator<CullStack::OccluderList>(cullVisitor->getOccluderList()));
    }
    


    cullVisitor->reset();

    cullVisitor->setFrameStamp(_frameStamp.get());

    // use the frame number for the traversal number.
    if (_frameStamp.valid())
    {
         cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
    }

    cullVisitor->inheritCullSettings(*this);

    cullVisitor->setStateGraph(rendergraph);
    cullVisitor->setRenderStage(renderStage);

    cullVisitor->setRenderInfo( _renderInfo );

    renderStage->reset();

    // comment out reset of rendergraph since clean is more efficient.
    //  rendergraph->reset();

    // use clean of the rendergraph rather than reset, as it is able to
    // reuse the structure on the rendergraph in the next frame. This
    // achieves a certain amount of frame cohereancy of memory allocation.
    rendergraph->clean();

    renderStage->setViewport(viewport);
    renderStage->setClearColor(_camera->getClearColor());
    renderStage->setClearDepth(_camera->getClearDepth());
    renderStage->setClearAccum(_camera->getClearAccum());
    renderStage->setClearStencil(_camera->getClearStencil());
    renderStage->setClearMask(_camera->getClearMask());
    
#if 1    
    renderStage->setCamera(_camera.get());
#endif

    #if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
        switch(_lightingMode)
        {
        case(HEADLIGHT):
            if (_light.valid()) renderStage->addPositionedAttribute(NULL,_light.get());
            else osg::notify(osg::WARN)<<"Warning: no osg::Light attached to ogUtil::SceneView to provide head light.*/"<<std::endl;
            break;
        case(SKY_LIGHT):
            if (_light.valid()) renderStage->addPositionedAttribute(mv.get(),_light.get());
            else osg::notify(osg::WARN)<<"Warning: no osg::Light attached to ogUtil::SceneView to provide sky light.*/"<<std::endl;
            break;
        default:
            break;
        }            
    #endif
    
    if (_globalStateSet.valid()) cullVisitor->pushStateSet(_globalStateSet.get());
    if (_secondaryStateSet.valid()) cullVisitor->pushStateSet(_secondaryStateSet.get());
    if (_localStateSet.valid()) cullVisitor->pushStateSet(_localStateSet.get());


    cullVisitor->pushViewport(viewport);
    cullVisitor->pushProjectionMatrix(proj.get());
    cullVisitor->pushModelViewMatrix(mv.get(),osg::Transform::ABSOLUTE_RF);

    // traverse the scene graph to generate the rendergraph.    
    // If the camera has a cullCallback execute the callback which has the  
    // requirement that it must traverse the camera's children.
    {
       osg::NodeCallback* callback = _camera->getCullCallback();
       if (callback) (*callback)(_camera.get(), cullVisitor);
       else cullVisitor->traverse(*_camera);
    }


    cullVisitor->popModelViewMatrix();
    cullVisitor->popProjectionMatrix();
    cullVisitor->popViewport();

    if (_localStateSet.valid()) cullVisitor->popStateSet();
    if (_secondaryStateSet.valid()) cullVisitor->popStateSet();
    if (_globalStateSet.valid()) cullVisitor->popStateSet();
    

    renderStage->sort();

    // prune out any empty StateGraph children.
    // note, this would be not required if the rendergraph had been
    // reset at the start of each frame (see top of this method) but
    // a clean has been used instead to try to minimize the amount of
    // allocation and deleteing of the StateGraph nodes.
    rendergraph->prune();
    
    // set the number of dynamic objects in the scene.    
    _dynamicObjectCount += renderStage->computeNumberOfDynamicRenderLeaves();


    bool computeNearFar = (cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) && getSceneData()!=0;
    return computeNearFar;
}