compoundUpdateInputVisitor.cpp

00001 
00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "compoundUpdateInputVisitor.h"
00019 
00020 #include "frame.h"
00021 #include "frameData.h"
00022 
00023 #include <eq/client/log.h>
00024 
00025 using namespace std;
00026 using namespace stde;
00027 using namespace eq::base;
00028 
00029 namespace eq
00030 {
00031 namespace server
00032 {
00033 CompoundUpdateInputVisitor::CompoundUpdateInputVisitor(
00034     const stde::hash_map<std::string, Frame*>& outputFrames )
00035         : _outputFrames( outputFrames )
00036 {}
00037 
00038 VisitorResult CompoundUpdateInputVisitor::visit( Compound* compound )
00039 {
00040     if( !compound->isActive( ))
00041         return TRAVERSE_PRUNE;    
00042 
00043     const std::vector< Frame* >& inputFrames = compound->getInputFrames();
00044     const Channel*               channel     = compound->getChannel();
00045 
00046     if( !compound->testInheritTask( eq::TASK_ASSEMBLE ) || !channel )
00047         return TRAVERSE_CONTINUE;
00048 
00049     if( inputFrames.empty( ))
00050     {
00051         compound->unsetInheritTask( eq::TASK_ASSEMBLE );
00052         return TRAVERSE_CONTINUE;
00053     }
00054 
00055     for( vector<Frame*>::const_iterator i = inputFrames.begin(); 
00056          i != inputFrames.end(); ++i )
00057     {
00058         //----- Find corresponding output frame
00059         Frame*                             frame = *i;
00060         const std::string&                 name = frame->getName();
00061         Compound::FrameMap::const_iterator iter =_outputFrames.find( name );
00062 
00063         if( iter == _outputFrames.end())
00064         {
00065             EQVERB << "Can't find matching output frame, ignoring input frame "
00066                    << name << endl;
00067             frame->unsetData();
00068             continue;
00069         }
00070 
00071         //----- Set frame parameters:
00072         // 1) Frame offset
00073         Frame*                 outputFrame = iter->second;
00074         const eq::Viewport&        frameVP = frame->getViewport();
00075         const eq::PixelViewport& inheritPVP=compound->getInheritPixelViewport();
00076         eq::PixelViewport         framePVP = inheritPVP.getSubPVP( frameVP );
00077         Vector2i frameOffset = outputFrame->getMasterData()->getOffset();
00078 
00079         frameOffset += frame->getOffset();
00080          
00081         if( channel != compound->getInheritChannel() &&
00082             compound->getIAttribute( Compound::IATTR_HINT_OFFSET ) != eq::ON )
00083         {
00084             // compute delta offset between source and destination, since the
00085             // channel's native origin (as opposed to destination) is used.
00086             frameOffset.x() -= framePVP.x;
00087             frameOffset.y() -= framePVP.y;
00088         }
00089         frame->setInheritOffset( frameOffset );
00090 
00091         // 2) zoom
00092         _updateZoom( compound, frame, outputFrame );
00093 
00094         // 3) TODO input frames are moved using the offset. The pvp signifies
00095         //    the pixels to be used from the frame data.
00096         //framePVP.x = static_cast< int32_t >( frameVP.x * inheritPVP.w );
00097         //framePVP.y = static_cast< int32_t >( frameVP.y * inheritPVP.h );
00098         //frame->setInheritPixelViewport( framePVP );
00099 
00100         //----- Link input frame to output frame (connects frame data)
00101         outputFrame->addInputFrame( frame, compound->getInheritEyes( ));
00102 
00103         //----- Commit
00104         frame->commit();
00105         EQLOG( eq::LOG_ASSEMBLY )
00106             << "Input frame  \"" << name << "\" on channel \"" 
00107             << channel->getName() << "\" id " << frame->getID() << " v"
00108             << frame->getVersion() << "\" tile pos " << frameOffset << ' ' 
00109             << frame->getInheritZoom() << endl;
00110     }
00111 
00112     return TRAVERSE_CONTINUE;
00113 }
00114 
00115 void CompoundUpdateInputVisitor::_updateZoom( const Compound* compound,
00116                                               Frame* frame, 
00117                                               const Frame* outputFrame )
00118 {
00119     Zoom zoom = frame->getZoom();
00120     if( !zoom.isValid( )) // if zoom is not set, inherit from parent
00121         zoom = compound->getInheritZoom();
00122 
00123     // Zoom difference between output and input
00124     const FrameData* frameData = outputFrame->getMasterData();
00125     zoom /= frameData->getZoom();
00126 
00127     frame->setInheritZoom( zoom );
00128 }
00129 
00130 }
00131 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8