32 #include "configEvent.h"
34 #include "modelAssigner.h"
36 #include <admin/addWindow.h>
37 #include <admin/removeWindow.h>
43 : eq::Config( parent )
57 for( ModelsCIter i = _models.begin(); i != _models.end(); ++i )
61 for( ModelDistsCIter i = _modelDist.begin(); i != _modelDist.end(); ++i )
63 LBASSERT( !(*i)->isAttached() );
71 if( !_animation.isValid( ))
72 _animation.loadAnimation( _initData.getPathFilename( ));
75 if( !_initData.useColor( ))
76 _frameData.setColorMode( COLOR_WHITE );
78 _frameData.setRenderMode( _initData.getRenderMode( ));
82 _initData.setFrameDataID( _frameData.getID( ));
96 if( canvases.empty( ))
99 _currentCanvas = canvases.front();
101 _setMessage(
"Welcome to eqPly\nPress F1 for help" );
117 static bool _isPlyfile(
const std::string& filename )
119 const size_t size = filename.length();
123 if( filename[size-4] !=
'.' || filename[size-3] !=
'p' ||
124 filename[size-2] !=
'l' || filename[size-1] !=
'y' )
132 void Config::_loadModels()
134 if( !_models.empty( ))
137 eq::Strings filenames = _initData.getFilenames();
138 while( !filenames.empty( ))
140 const std::string filename = filenames.back();
141 filenames.pop_back();
143 if( _isPlyfile( filename ))
145 Model* model =
new Model;
147 if( _initData.useInvertedFaces() )
148 model->useInvertedFaces();
150 if( !model->readFromFile( filename.c_str( )))
152 LBWARN <<
"Can't load model: " << filename << std::endl;
156 _models.push_back( model );
160 const std::string basename = lunchbox::getFilename( filename );
161 if( basename ==
"." || basename ==
".." )
165 const eq::Strings subFiles = lunchbox::searchDirectory( filename,
167 for(eq::StringsCIter i = subFiles.begin(); i != subFiles.end(); ++i)
168 filenames.push_back( filename +
'/' + *i );
173 void Config::_registerModels()
176 const bool createDist = _modelDist.empty();
177 const size_t nModels = _models.size();
178 LBASSERT( createDist || _modelDist.size() == nModels );
180 for(
size_t i = 0; i < nModels; ++i )
182 Model* model = _models[i];
183 ModelDist* modelDist = 0;
186 modelDist =
new ModelDist( model );
187 _modelDist.push_back( modelDist );
190 modelDist = _modelDist[i];
193 LBASSERT( modelDist->isAttached() );
195 _frameData.setModelID( modelDist->getID( ));
198 LBASSERT( _modelDist.size() == nModels );
200 if( !_modelDist.empty( ))
202 ModelAssigner assigner( _modelDist );
207 void Config::_deregisterData()
209 for( ModelDistsCIter i = _modelDist.begin(); i != _modelDist.end(); ++i )
211 ModelDist* modelDist = *i;
212 if( !modelDist->isAttached() )
215 LBASSERT( modelDist->isMaster( ));
216 modelDist->deregisterTree();
222 _initData.setFrameDataID( eq::uint128_t( ));
223 _frameData.setModelID( eq::uint128_t( ));
226 bool Config::loadInitData(
const eq::uint128_t&
id )
228 LBASSERT( !_initData.isAttached( ));
232 const Model* Config::getModel(
const eq::uint128_t& modelID )
239 const bool needModelLock = (node->
getPipes().size() > 1);
240 lunchbox::ScopedWrite _mutex( needModelLock ? &_modelLock : 0 );
242 const size_t nModels = _models.size();
243 LBASSERT( _modelDist.size() == nModels );
245 for(
size_t i = 0; i < nModels; ++i )
247 const ModelDist* dist = _modelDist[ i ];
248 if( dist->getID() == modelID )
252 _modelDist.push_back(
new ModelDist );
256 _models.push_back( model );
264 const eq::uint128_t& version = _frameData.commit();
270 void Config::_updateData()
273 if( _animation.isValid( ))
275 const eq::Vector3f& modelRotation = _animation.getModelRotation();
278 _frameData.setModelRotation( modelRotation);
279 _frameData.setRotation( curStep.rotation );
280 _frameData.setCameraPosition( curStep.position );
284 if( _frameData.usePilotMode())
285 _frameData.spinCamera( -0.001f * _spinX, -0.001f * _spinY );
287 _frameData.spinModel( -0.001f * _spinX, -0.001f * _spinY, 0.f );
289 _frameData.moveCamera( 0.0f, 0.0f, 0.001f * _advance );
295 LBASSERT( _numFramesAA > 0 );
296 _frameData.setIdle(
true );
299 _frameData.setIdle(
false );
304 bool Config::isIdleAA()
306 return ( !_needNewFrame() && _numFramesAA > 0 );
309 bool Config::needRedraw()
311 return( _needNewFrame() || _numFramesAA > 0 );
314 uint32_t Config::getAnimationFrame()
316 return _animation.getCurrentFrame();
319 bool Config::_needNewFrame()
321 if( _messageTime > 0 )
323 if(
getTime() - _messageTime > 2000 )
326 _frameData.setMessage(
"" );
331 return ( _spinX != 0 || _spinY != 0 || _advance != 0 || _redraw );
336 switch( event->
data.type )
338 case eq::Event::KEY_PRESS:
340 if( _handleKeyEvent( event->
data.keyPress ))
348 case eq::Event::CHANNEL_POINTER_BUTTON_PRESS:
350 const eq::uint128_t& viewID =
event->data.context.view.identifier;
351 _frameData.setCurrentViewID( viewID );
358 const View* view = _getCurrentView();
362 i != canvases.end(); ++i )
367 if( canvasLayout == layout )
369 _currentCanvas = canvas;
376 case eq::Event::CHANNEL_POINTER_BUTTON_RELEASE:
378 const eq::PointerEvent& releaseEvent =
379 event->data.pointerButtonRelease;
380 if( releaseEvent.buttons == eq::PTR_BUTTON_NONE)
382 if( releaseEvent.button == eq::PTR_BUTTON1 )
384 _spinX = releaseEvent.dy;
385 _spinY = releaseEvent.dx;
389 if( releaseEvent.button == eq::PTR_BUTTON2 )
391 _advance = -releaseEvent.dy;
398 case eq::Event::CHANNEL_POINTER_MOTION:
400 switch( event->
data.pointerMotion.buttons )
402 case eq::PTR_BUTTON1:
406 if( _frameData.usePilotMode())
407 _frameData.spinCamera(
408 -0.005f * event->
data.pointerMotion.dy,
409 -0.005f * event->
data.pointerMotion.dx );
411 _frameData.spinModel(
412 -0.005f * event->
data.pointerMotion.dy,
413 -0.005f * event->
data.pointerMotion.dx, 0.f );
417 case eq::PTR_BUTTON2:
418 _advance = -
event->data.pointerMotion.dy;
419 _frameData.moveCamera( 0.f, 0.f, .005f * _advance );
423 case eq::PTR_BUTTON3:
424 _frameData.moveCamera( .0005f * event->
data.pointerMotion.dx,
425 -.0005f * event->
data.pointerMotion.dy,
433 case eq::Event::CHANNEL_POINTER_WHEEL:
435 _frameData.moveCamera( -0.05f * event->
data.pointerWheel.xAxis,
437 0.05f * event->
data.pointerWheel.yAxis );
442 case eq::Event::MAGELLAN_AXIS:
447 _frameData.spinModel( 0.0001f * event->
data.magellan.xRotation,
448 0.0001f * event->
data.magellan.yRotation,
449 0.0001f * event->
data.magellan.zRotation );
450 _frameData.moveCamera( 0.0001f * event->
data.magellan.xAxis,
451 0.0001f * event->
data.magellan.yAxis,
452 0.0001f * event->
data.magellan.zAxis );
457 case eq::Event::MAGELLAN_BUTTON:
459 if( event->
data.magellan.button == eq::PTR_BUTTON1 )
460 _frameData.toggleColorMode();
466 case eq::Event::WINDOW_EXPOSE:
467 case eq::Event::WINDOW_RESIZE:
468 case eq::Event::WINDOW_CLOSE:
469 case eq::Event::VIEW_RESIZE:
488 const int32_t steps = command.read< int32_t >();
489 _numFramesAA = LB_MAX( _numFramesAA, steps );
503 bool Config::_handleKeyEvent(
const eq::KeyEvent& event )
508 _adjustEyeBase( -0.1f );
511 _adjustEyeBase( 0.1f );
514 _adjustModelScale( 0.1f );
517 _adjustModelScale( 10.0f );
520 _adjustTileSize( -1 );
523 _adjustTileSize( 1 );
526 _frameData.toggleCompression();
531 _frameData.togglePilotMode();
539 _setHeadMatrix( eq::Matrix4f::IDENTITY );
543 _useIdleAA = !_useIdleAA;
549 if( rng.get<
bool >( ))
550 _frameData.toggleOrtho();
551 if( rng.get<
bool >( ))
552 _frameData.toggleStatistics();
553 if( rng.get<
bool >( ))
555 if( rng.get<
bool >( ))
557 if( rng.get<
bool >( ))
559 if( rng.get<
bool >( ))
561 if( rng.get<
bool >( ))
562 eqAdmin::addWindow( _getAdminServer(), rng.get<
bool >( ));
563 if( rng.get<
bool >( ))
565 eqAdmin::removeWindow( _getAdminServer( ));
568 if( rng.get<
bool >( ))
575 _frameData.toggleOrtho();
580 _frameData.toggleStatistics();
584 _freezeLoadBalancing(
true );
588 _freezeLoadBalancing(
false );
594 _frameData.toggleHelp();
599 _frameData.toggleColorMode();
603 _frameData.adjustQuality( -.1f );
607 _frameData.adjustQuality( .1f );
634 _frameData.toggleWireframe();
639 _frameData.toggleRenderMode();
646 eqAdmin::addWindow( _getAdminServer(),
false );
649 eqAdmin::addWindow( _getAdminServer(),
true );
652 eqAdmin::removeWindow( _getAdminServer( ));
660 eq::Matrix4f headMatrix = _getHeadMatrix();
661 headMatrix.y() += 0.1f;
662 _setHeadMatrix( headMatrix );
667 eq::Matrix4f headMatrix = _getHeadMatrix();
668 headMatrix.y() -= 0.1f;
669 _setHeadMatrix( headMatrix );
674 eq::Matrix4f headMatrix = _getHeadMatrix();
675 headMatrix.x() += 0.1f;
676 _setHeadMatrix( headMatrix );
681 eq::Matrix4f headMatrix = _getHeadMatrix();
682 headMatrix.x() -= 0.1f;
683 _setHeadMatrix( headMatrix );
686 case eq::KC_PAGE_DOWN:
688 eq::Matrix4f headMatrix = _getHeadMatrix();
689 headMatrix.z() += 0.1f;
690 _setHeadMatrix( headMatrix );
695 eq::Matrix4f headMatrix = _getHeadMatrix();
696 headMatrix.z() -= 0.1f;
697 _setHeadMatrix( headMatrix );
702 eq::Matrix4f headMatrix = _getHeadMatrix();
703 headMatrix.pre_rotate_x( .1f );
704 _setHeadMatrix( headMatrix );
709 eq::Matrix4f headMatrix = _getHeadMatrix();
710 headMatrix.pre_rotate_x( -.1f );
711 _setHeadMatrix( headMatrix );
716 eq::Matrix4f headMatrix = _getHeadMatrix();
717 headMatrix.pre_rotate_y( .1f );
718 _setHeadMatrix( headMatrix );
723 eq::Matrix4f headMatrix = _getHeadMatrix();
724 headMatrix.pre_rotate_y( -.1f );
725 _setHeadMatrix( headMatrix );
730 eq::Matrix4f headMatrix = _getHeadMatrix();
731 headMatrix.pre_rotate_z( -.1f );
732 _setHeadMatrix( headMatrix );
737 eq::Matrix4f headMatrix = _getHeadMatrix();
738 headMatrix.pre_rotate_z( .1f );
739 _setHeadMatrix( headMatrix );
744 _changeFocusDistance( .1f );
748 _changeFocusDistance( -.1f );
752 _setFocusMode( eq::FOCUSMODE_FIXED );
756 _setFocusMode( eq::FOCUSMODE_RELATIVE_TO_ORIGIN );
760 _setFocusMode( eq::FOCUSMODE_RELATIVE_TO_OBSERVER );
764 _adjustResistance( 1 );
768 _adjustResistance( -1 );
784 co::uint128_t Config::sync(
const co::uint128_t& version )
786 if( _admin.isValid() && _admin->isConnected( ))
787 _admin->syncConfig( getID(), version );
789 return eq::Config::sync( version );
792 void Config::_switchCanvas()
795 if( canvases.empty( ))
798 _frameData.setCurrentViewID( eq::uint128_t( ));
800 if( !_currentCanvas )
802 _currentCanvas = canvases.front();
807 LBASSERT( i != canvases.end( ));
810 if( i == canvases.end( ))
811 _currentCanvas = canvases.front();
817 void Config::_switchView()
820 if( !_currentCanvas && !canvases.empty( ))
821 _currentCanvas = canvases.front();
823 if( !_currentCanvas )
826 const eq::Layout* layout = _currentCanvas->getActiveLayout();
830 const View* view = _getCurrentView();
832 LBASSERT( !views.empty( ));
836 _frameData.setCurrentViewID( views.front()->getID( ));
841 if( i != views.end( ))
843 if( i == views.end( ))
844 _frameData.setCurrentViewID( eq::uint128_t( ));
846 _frameData.setCurrentViewID( (*i)->getID( ));
849 void Config::_switchModel()
851 if( _modelDist.empty( ))
855 View* view = _getCurrentView();
856 const eq::uint128_t& currentID = view ? view->getModelID() :
857 _frameData.getModelID();
860 for( i = _modelDist.begin(); i != _modelDist.end(); ++i )
862 if( (*i)->getID() != currentID )
868 if( i == _modelDist.end( ))
869 i = _modelDist.begin();
872 const eq::uint128_t& modelID = (*i)->getID();
874 view->setModelID( modelID );
876 _frameData.setModelID( modelID );
880 const Model* model = getModel( modelID );
881 _setMessage(
"Using " + lunchbox::getFilename( model->getName( )));
885 void Config::_switchViewMode()
887 View* view = _getCurrentView();
895 _setMessage(
"Switched to stereoscopic rendering" );
900 _setMessage(
"Switched to monoscopic rendering" );
904 void Config::_freezeLoadBalancing(
const bool onOff )
906 View* view = _getCurrentView();
908 view->getEqualizer().setFrozen( onOff );
911 void Config::_adjustEyeBase(
const float delta )
919 eq::Vector3f( -delta, 0.f, 0.f ));
922 eq::Vector3f( delta, 0.f, 0.f ));
923 std::ostringstream stream;
924 stream <<
"Set eyes to " << observer->
getEyePosition( eq::EYE_LEFT )
926 _setMessage( stream.str( ));
930 void Config::_adjustTileSize(
const int delta )
932 View* view = _getCurrentView();
936 eq::Vector2i tileSize = view->getEqualizer().getTileSize();
937 if( tileSize == eq::Vector2i( -1, -1 ) )
938 tileSize = eq::Vector2i( 64, 64 );
940 view->getEqualizer().setTileSize( tileSize );
943 void Config::_adjustResistance(
const int delta )
945 View* view = _getCurrentView();
949 eq::Vector2i size = view->getEqualizer().getResistance2i();
951 size.x() = LB_MAX( size.x(), 0 );
952 size.y() = LB_MAX( size.y(), 0 );
953 std::ostringstream stream;
954 stream <<
"Set load equalizer resistance to " << size;
955 _setMessage( stream.str( ));
956 view->getEqualizer().setResistance( size );
959 void Config::_adjustModelScale(
const float factor )
961 View* view = _getCurrentView();
965 const float current = view->getModelUnit() * factor;
966 if( current > std::numeric_limits<float>::epsilon( ))
967 view->setModelUnit( current );
969 std::ostringstream stream;
970 stream <<
"Set model unit to " << view->getModelUnit();
971 _setMessage( stream.str( ));
974 void Config::_switchLayout( int32_t increment )
976 if( !_currentCanvas )
979 _frameData.setCurrentViewID( eq::uint128_t( ));
981 int64_t index = _currentCanvas->getActiveLayoutIndex() + increment;
982 const eq::Layouts& layouts = _currentCanvas->getLayouts();
983 LBASSERT( !layouts.empty( ));
985 index = ( index % layouts.size( ));
986 _currentCanvas->useLayout( uint32_t( index ));
989 std::ostringstream stream;
993 const std::string& name = layout->
getName();
1002 stream <<
" active";
1003 _setMessage( stream.str( ));
1006 void Config::_toggleEqualizer()
1008 View* view = _getCurrentView();
1010 view->toggleEqualizer();
1014 void Config::_setHeadMatrix(
const eq::Matrix4f& matrix )
1019 (*i)->setHeadMatrix( matrix );
1023 matrix.get_translation( trans );
1024 std::ostringstream stream;
1025 stream <<
"Observer at " << trans;
1026 _setMessage( stream.str( ));
1029 const eq::Matrix4f& Config::_getHeadMatrix()
const
1032 if( observers.empty( ))
1033 return eq::Matrix4f::IDENTITY;
1035 return observers[0]->getHeadMatrix();
1038 void Config::_changeFocusDistance(
const float delta )
1045 std::ostringstream stream;
1047 _setMessage( stream.str( ));
1051 void Config::_setFocusMode(
const eq::FocusMode mode )
1055 (*i)->setFocusMode( mode );
1057 std::ostringstream stream;
1058 stream <<
"Set focus mode to " << mode;
1059 _setMessage( stream.str( ));
1062 void Config::_setMessage(
const std::string& message )
1064 _frameData.setMessage( message );
1068 eq::admin::ServerPtr Config::_getAdminServer()
1071 if( _admin.isValid() && _admin->isConnected( ))
1075 eq::admin::ClientPtr client =
new eq::admin::Client;
1076 if( !client->initLocal( 0, 0 ))
1078 _setMessage(
"Can't init admin client" );
1082 _admin =
new eq::admin::Server;
1083 if( !client->connectServer( _admin ))
1085 _setMessage(
"Can't open connection to administrate server" );
1086 client->exitLocal();
1093 void Config::_closeAdminServer()
1098 eq::admin::ClientPtr client = _admin->getClient();
1099 client->disconnectServer( _admin );
1100 client->exitLocal();
1101 LBASSERT( client->getRefCount() == 1 );
1102 LBASSERT( _admin->getRefCount() == 1 );
1108 View* Config::_getCurrentView()
1110 const eq::uint128_t& viewID = _frameData.getCurrentViewID();
1111 eq::View* view = find< eq::View >( viewID );
1112 return static_cast< View*
>( view );
1115 const View* Config::_getCurrentView()
const
1117 const eq::uint128_t& viewID = _frameData.getCurrentViewID();
1118 const eq::View* view = find< eq::View >( viewID );
1119 return static_cast< const View*
>( view );
const Observers & getObservers() const
virtual EQ_API bool init(const uint128_t &initID)
Initialize this configuration.
Render in stereo (left & right eye)
EQFABRIC_INL void setFocusDistance(const float focusDistance)
Set the focal distance.
A canvas represents a logical 2D projection surface.
const Pipes & getPipes() const
EQFABRIC_INL VisitorResult accept(ConfigVisitor &visitor)
Perform a depth-first traversal of this config.
Canvases::const_iterator CanvasesCIter
A const_iterator over a eq::Canvas vector.
virtual EQ_API bool exit()
Exit this configuration.
EQ_API bool update()
Update the configuration.
A Node represents a single computer in the cluster.
virtual bool handleEvent(eq::EventICommand command)
EQ_API void stopFrames()
Asynchronously signal all channels to interrupt their rendering.
EQFABRIC_INL void setEyePosition(const Eye eye, const Vector3f &pos)
Set the position of the given eye relative to the observer.
const Nodes & getNodes() const
virtual EQ_API uint32_t startFrame(const uint128_t &frameID)
Request a new frame of rendering.
EQ_API int64_t getTime() const
Get the current time in milliseconds.
std::vector< Layout * > Layouts
A vector of pointers to eq::Layout.
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
EQFABRIC_INL const Vector3f & getEyePosition(const Eye eye) const
A command specialization for config events.
EQFABRIC_API const std::string & getName() const
EQFABRIC_INL const L * getActiveLayout() const
std::vector< View * > Views
A vector of pointers to eq::View.
float getFocusDistance() const
Mode
The current rendering mode.
const Canvases & getCanvases() const
std::vector< Observer * > Observers
A vector of pointers to eq::Observer.
std::vector< Canvas * > Canvases
A vector of pointers to eq::Canvas.
EQFABRIC_API bool exit()
De-initialize the Equalizer fabric namespace.
A layout groups one or more View, logically belonging together.
A View is a 2D area of a Layout.
EQ_API ClientPtr getClient()
EQFABRIC_API bool init(const int argc, char **argv)
Initialize the Equalizer fabric namespace.
virtual ~Config()
Destruct a config.
Views::const_iterator ViewsCIter
A const_iterator over a eq::View vector.
virtual EQ_API bool registerObject(co::Object *object)
Register a distributed object.
EQ_API co::NodePtr getApplicationNode()
An Observer looks at one or more views from a certain position (head matrix) with a given eye separat...
virtual EQ_API bool handleEvent(const ConfigEvent *event)
Handle one (old) config event.
virtual EQ_API void deregisterObject(co::Object *object)
Deregister a distributed object.
Render in mono (cyclop eye)
Observers::const_iterator ObserversCIter
A const_iterator over a eq::Observer vector.
virtual uint32_t startFrame(const eq::uint128_t &frameID)
uint32_t getLatency() const
const Views & getViews() const
Get the list of views.
EQ_API uint32_t getEventType() const
Returns the event type.