Beispiel #1
0
bool PrintPosterHandler::handle(
    const osgGA::GUIEventAdapter& ea
,   osgGA::GUIActionAdapter& aa)
{
    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);

    if(!view) 
        return false;

    switch(ea.getEventType())
    {
        case osgGA::GUIEventAdapter::FRAME:
        {
            // Wait until all paged LOD are processed
            if(view->getDatabasePager() && view->getDatabasePager()->getRequestsInProgress())
                break;

            if(m_isFinished)
            {
                const osg::FrameStamp* fs = view->getFrameStamp();
                if((fs->getFrameNumber() % 2) == 0)
                {
                    aggregateAndFreeTiles(); // Record images and unref them to free memory
                    std::cout << "finished" << std::endl;

                    write();
                    m_isFinished = false;
                }
            }

            if(m_make)
                make(view);

            if(m_making)
            {

                // Every "copy-to-image" process seems to be finished in 2 frames.
                // So record them and dispatch cameras to next tiles.

                const osg::FrameStamp* fs = view->getFrameStamp();

                if((fs->getFrameNumber() % 2) == 0)
                {
                    // Record images and unref them to free memory
                    aggregateAndFreeTiles();

                    osg::Camera* camera = 0;

                    while((camera = getAvailableCamera()) != NULL)
                    {
                        std::cout << "Binding sub-camera " << m_currentRow << "_" << m_currentColumn
                                    << " to image..." << std::endl;

                        bindCameraToImage(camera, m_currentRow, m_currentColumn);

                        if (m_currentColumn < m_tileColumns - 1)
                            m_currentColumn++;
                        else
                        {
                            if(m_currentRow < m_tileRows - 1)
                            {
                                m_currentRow++;
                                m_currentColumn = 0;
                            }
                            else
                            {
                                m_making = false;
                                m_isFinished = true;
                                    
                                std::cout << "Sub-cameras dispatching finished." << std::endl;
                                break;
                            }
                        }
                    }
                    m_cameraIndex = m_cameraRoot->getNumChildren();
                }
            }
            break;
        }

        case osgGA::GUIEventAdapter::KEYDOWN:
        {
            if ( ea.getKey()=='p' || ea.getKey()=='P' )
            {
                print();
                return true;
            }
            break;
        }

        default:
            break;
    }

    return false;
}
Beispiel #2
0
void PosterPrinter::frame( const osg::FrameStamp* fs, osg::Node* node )
{
    // Add cull callbacks to all existing paged nodes,
    // and advance frame when all callbacks are dispatched.
    if ( addCullCallbacks(fs, node) )
        return;
    
    if ( _isFinishing )
    {
        if ( (fs->getFrameNumber()-_lastBindingFrame)>2 )
        {
            // Record images and the final poster
            recordImages();
            if ( _finalPoster.valid() )
            {
                std::cout << "Writing final result to file..." << std::endl;
                osgDB::writeImageFile( *_finalPoster, _outputPosterName );
            }
            
            // Release all cull callbacks to free unused paged nodes
            removeCullCallbacks( node );
            _visitor->clearNames();
            
            _isFinishing = false;
            std::cout << "Recording images finished." << std::endl;
        }
    }
    
    if ( _isRunning )
    {
        // Every "copy-to-image" process seems to be finished in 2 frames.
        // So record them and dispatch camera to next tiles.
        if ( (fs->getFrameNumber()-_lastBindingFrame)>2 )
        {
            // Record images and unref them to free memory
            recordImages();
            
            // Release all cull callbacks to free unused paged nodes
            removeCullCallbacks( node );
            _visitor->clearNames();
            
            if ( _camera.valid() )
            {
                std::cout << "Binding sub-camera " << _currentRow << "_" << _currentColumn
                          << " to image..." << std::endl;
                bindCameraToImage( _camera.get(), _currentRow, _currentColumn );
                if ( _currentColumn<_tileColumns-1 )
                {
                    _currentColumn++;
                }
                else
                {
                    if ( _currentRow<_tileRows-1 )
                    {
                        _currentRow++;
                        _currentColumn = 0;
                    }
                    else
                    {
                        _isRunning = false;
                        _isFinishing = true;
                    }
                }
            }
            _lastBindingFrame = fs->getFrameNumber();
        }
    }
}