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( ))
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 const 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::UUID( ));
223 _frameData.setModelID( eq::UUID( ));
226 bool Config::loadData(
const eq::uint128_t& initDataID )
228 if( !_initData.isAttached( ))
230 const uint32_t request =
mapObjectNB( &_initData, initDataID,
239 LBASSERT( _initData.getID() == initDataID );
244 const Model* Config::getModel(
const eq::uint128_t& modelID )
251 const bool needModelLock = (node->
getPipes().size() > 1);
252 lunchbox::ScopedWrite _mutex( needModelLock ? &_modelLock : 0 );
254 const size_t nModels = _models.size();
255 LBASSERT( _modelDist.size() == nModels );
257 for(
size_t i = 0; i < nModels; ++i )
260 if( dist->getID() == modelID )
268 _models.push_back( model );
276 const eq::uint128_t& version = _frameData.commit();
282 void Config::_updateData()
285 if( _animation.isValid( ))
287 const eq::Vector3f& modelRotation = _animation.getModelRotation();
290 _frameData.setModelRotation( modelRotation);
291 _frameData.setRotation( curStep.rotation );
292 _frameData.setCameraPosition( curStep.position );
296 if( _frameData.usePilotMode())
297 _frameData.spinCamera( -0.001f * _spinX, -0.001f * _spinY );
299 _frameData.spinModel( -0.001f * _spinX, -0.001f * _spinY, 0.f );
301 _frameData.moveCamera( 0.0f, 0.0f, 0.001f * _advance );
307 LBASSERT( _numFramesAA > 0 );
308 _frameData.setIdle(
true );
311 _frameData.setIdle(
false );
316 bool Config::isIdleAA()
318 return ( !_needNewFrame() && _numFramesAA > 0 );
321 bool Config::needRedraw()
323 return( _needNewFrame() || _numFramesAA > 0 );
326 uint32_t Config::getAnimationFrame()
328 return _animation.getCurrentFrame();
331 bool Config::_needNewFrame()
333 if( _messageTime > 0 )
335 if(
getTime() - _messageTime > 2000 )
338 _frameData.setMessage(
"" );
343 return ( _spinX != 0 || _spinY != 0 || _advance != 0 || _redraw );
362 const eq::uint128_t& viewID =
event->data.context.view.identifier;
363 _frameData.setCurrentViewID( viewID );
370 const View* view = _getCurrentView();
374 i != canvases.end(); ++i )
379 if( canvasLayout == layout )
381 _currentCanvas = canvas;
391 event->data.pointerButtonRelease;
392 if( releaseEvent.
buttons == eq::PTR_BUTTON_NONE)
394 if( releaseEvent.
button == eq::PTR_BUTTON1 )
396 _spinX = releaseEvent.
dy;
397 _spinY = releaseEvent.
dx;
401 if( releaseEvent.
button == eq::PTR_BUTTON2 )
403 _advance = -releaseEvent.
dy;
410 case eq::Event::CHANNEL_POINTER_MOTION:
414 case eq::PTR_BUTTON1:
418 if( _frameData.usePilotMode())
419 _frameData.spinCamera(
423 _frameData.spinModel(
429 case eq::PTR_BUTTON2:
430 _advance = -
event->data.pointerMotion.dy;
431 _frameData.moveCamera( 0.f, 0.f, .005f * _advance );
435 case eq::PTR_BUTTON3:
472 _frameData.toggleColorMode();
500 const int32_t steps = command.get< int32_t >();
501 _numFramesAA = LB_MAX( _numFramesAA, steps );
515 bool Config::_handleKeyEvent(
const eq::KeyEvent& event )
520 _adjustEyeBase( -0.1f );
523 _adjustEyeBase( 0.1f );
526 _adjustModelScale( 0.1f );
529 _adjustModelScale( 10.0f );
532 _adjustTileSize( -1 );
535 _adjustTileSize( 1 );
538 _frameData.toggleCompression();
543 _frameData.togglePilotMode();
551 _setHeadMatrix( eq::Matrix4f::IDENTITY );
555 _useIdleAA = !_useIdleAA;
561 if( rng.get<
bool >( ))
562 _frameData.toggleOrtho();
563 if( rng.get<
bool >( ))
564 _frameData.toggleStatistics();
565 if( rng.get<
bool >( ))
567 if( rng.get<
bool >( ))
569 if( rng.get<
bool >( ))
571 if( rng.get<
bool >( ))
573 if( rng.get<
bool >( ))
574 eqAdmin::addWindow( _getAdminServer(), rng.get<
bool >( ));
575 if( rng.get<
bool >( ))
577 eqAdmin::removeWindow( _getAdminServer( ));
580 if( rng.get<
bool >( ))
587 _frameData.toggleOrtho();
592 _frameData.toggleStatistics();
596 _freezeLoadBalancing(
true );
600 _freezeLoadBalancing(
false );
606 _frameData.toggleHelp();
611 _frameData.toggleColorMode();
615 _frameData.adjustQuality( -.1f );
619 _frameData.adjustQuality( .1f );
646 _frameData.toggleWireframe();
651 _frameData.toggleRenderMode();
658 eqAdmin::addWindow( _getAdminServer(),
false );
661 eqAdmin::addWindow( _getAdminServer(),
true );
664 eqAdmin::removeWindow( _getAdminServer( ));
672 eq::Matrix4f headMatrix = _getHeadMatrix();
673 headMatrix.y() += 0.1f;
674 _setHeadMatrix( headMatrix );
679 eq::Matrix4f headMatrix = _getHeadMatrix();
680 headMatrix.y() -= 0.1f;
681 _setHeadMatrix( headMatrix );
686 eq::Matrix4f headMatrix = _getHeadMatrix();
687 headMatrix.x() += 0.1f;
688 _setHeadMatrix( headMatrix );
693 eq::Matrix4f headMatrix = _getHeadMatrix();
694 headMatrix.x() -= 0.1f;
695 _setHeadMatrix( headMatrix );
698 case eq::KC_PAGE_DOWN:
700 eq::Matrix4f headMatrix = _getHeadMatrix();
701 headMatrix.z() += 0.1f;
702 _setHeadMatrix( headMatrix );
707 eq::Matrix4f headMatrix = _getHeadMatrix();
708 headMatrix.z() -= 0.1f;
709 _setHeadMatrix( headMatrix );
714 eq::Matrix4f headMatrix = _getHeadMatrix();
715 headMatrix.pre_rotate_x( .1f );
716 _setHeadMatrix( headMatrix );
721 eq::Matrix4f headMatrix = _getHeadMatrix();
722 headMatrix.pre_rotate_x( -.1f );
723 _setHeadMatrix( headMatrix );
728 eq::Matrix4f headMatrix = _getHeadMatrix();
729 headMatrix.pre_rotate_y( .1f );
730 _setHeadMatrix( headMatrix );
735 eq::Matrix4f headMatrix = _getHeadMatrix();
736 headMatrix.pre_rotate_y( -.1f );
737 _setHeadMatrix( headMatrix );
742 eq::Matrix4f headMatrix = _getHeadMatrix();
743 headMatrix.pre_rotate_z( -.1f );
744 _setHeadMatrix( headMatrix );
749 eq::Matrix4f headMatrix = _getHeadMatrix();
750 headMatrix.pre_rotate_z( .1f );
751 _setHeadMatrix( headMatrix );
756 _changeFocusDistance( .1f );
760 _changeFocusDistance( -.1f );
764 _setFocusMode( eq::FOCUSMODE_FIXED );
768 _setFocusMode( eq::FOCUSMODE_RELATIVE_TO_ORIGIN );
772 _setFocusMode( eq::FOCUSMODE_RELATIVE_TO_OBSERVER );
776 _adjustResistance( 1 );
780 _adjustResistance( -1 );
796 co::uint128_t Config::sync(
const co::uint128_t& version )
798 if( _admin.isValid() && _admin->isConnected( ))
799 _admin->syncConfig( getID(), version );
801 return eq::Config::sync( version );
804 void Config::_switchCanvas()
807 if( canvases.empty( ))
810 _frameData.setCurrentViewID( eq::UUID( ));
812 if( !_currentCanvas )
814 _currentCanvas = canvases.front();
819 LBASSERT( i != canvases.end( ));
822 if( i == canvases.end( ))
823 _currentCanvas = canvases.front();
829 void Config::_switchView()
832 if( !_currentCanvas && !canvases.empty( ))
833 _currentCanvas = canvases.front();
835 if( !_currentCanvas )
838 const eq::Layout* layout = _currentCanvas->getActiveLayout();
842 const View* view = _getCurrentView();
844 LBASSERT( !views.empty( ));
848 _frameData.setCurrentViewID( views.front()->getID( ));
853 if( i != views.end( ))
855 if( i == views.end( ))
856 _frameData.setCurrentViewID( eq::UUID( ));
858 _frameData.setCurrentViewID( (*i)->getID( ));
861 void Config::_switchModel()
863 if( _modelDist.empty( ))
867 View* view = _getCurrentView();
868 const eq::uint128_t& currentID = view ? view->getModelID() :
869 _frameData.getModelID();
872 for( i = _modelDist.begin(); i != _modelDist.end(); ++i )
874 if( (*i)->getID() != currentID )
880 if( i == _modelDist.end( ))
881 i = _modelDist.begin();
884 const eq::uint128_t& modelID = (*i)->getID();
886 view->setModelID( modelID );
888 _frameData.setModelID( modelID );
892 const Model* model = getModel( modelID );
893 _setMessage(
"Using " + lunchbox::getFilename( model->getName( )));
897 void Config::_switchViewMode()
899 View* view = _getCurrentView();
907 _setMessage(
"Switched to stereoscopic rendering" );
912 _setMessage(
"Switched to monoscopic rendering" );
916 void Config::_freezeLoadBalancing(
const bool onOff )
918 View* view = _getCurrentView();
920 view->getEqualizer().setFrozen( onOff );
923 void Config::_adjustEyeBase(
const float delta )
931 eq::Vector3f( -delta, 0.f, 0.f ));
934 eq::Vector3f( delta, 0.f, 0.f ));
935 std::ostringstream stream;
936 stream <<
"Set eyes to " << observer->
getEyePosition( eq::EYE_LEFT )
938 _setMessage( stream.str( ));
942 void Config::_adjustTileSize(
const int delta )
944 View* view = _getCurrentView();
948 eq::Vector2i tileSize = view->getEqualizer().getTileSize();
949 if( tileSize == eq::Vector2i( -1, -1 ) )
950 tileSize = eq::Vector2i( 64, 64 );
952 view->getEqualizer().setTileSize( tileSize );
955 void Config::_adjustResistance(
const int delta )
957 View* view = _getCurrentView();
961 eq::Vector2i size = view->getEqualizer().getResistance2i();
963 size.x() = LB_MAX( size.x(), 0 );
964 size.y() = LB_MAX( size.y(), 0 );
965 std::ostringstream stream;
966 stream <<
"Set load equalizer resistance to " << size;
967 _setMessage( stream.str( ));
968 view->getEqualizer().setResistance( size );
971 void Config::_adjustModelScale(
const float factor )
973 View* view = _getCurrentView();
977 const float current = view->getModelUnit() * factor;
978 if( current > std::numeric_limits<float>::epsilon( ))
979 view->setModelUnit( current );
981 std::ostringstream stream;
982 stream <<
"Set model unit to " << view->getModelUnit();
983 _setMessage( stream.str( ));
986 void Config::_switchLayout( int32_t increment )
988 if( !_currentCanvas )
991 _frameData.setCurrentViewID( eq::UUID( ));
993 int64_t index = _currentCanvas->getActiveLayoutIndex() + increment;
994 const eq::Layouts& layouts = _currentCanvas->getLayouts();
995 LBASSERT( !layouts.empty( ));
997 index = ( index % layouts.size( ));
998 _currentCanvas->useLayout( uint32_t( index ));
1001 std::ostringstream stream;
1002 stream <<
"Layout ";
1005 const std::string& name = layout->
getName();
1014 stream <<
" active";
1015 _setMessage( stream.str( ));
1018 void Config::_toggleEqualizer()
1020 View* view = _getCurrentView();
1022 view->toggleEqualizer();
1026 void Config::_setHeadMatrix(
const eq::Matrix4f& matrix )
1031 (*i)->setHeadMatrix( matrix );
1035 matrix.get_translation( trans );
1036 std::ostringstream stream;
1037 stream <<
"Observer at " << trans;
1038 _setMessage( stream.str( ));
1041 const eq::Matrix4f& Config::_getHeadMatrix()
const
1044 if( observers.empty( ))
1045 return eq::Matrix4f::IDENTITY;
1047 return observers[0]->getHeadMatrix();
1050 void Config::_changeFocusDistance(
const float delta )
1057 std::ostringstream stream;
1059 _setMessage( stream.str( ));
1063 void Config::_setFocusMode(
const eq::FocusMode mode )
1067 (*i)->setFocusMode( mode );
1069 std::ostringstream stream;
1070 stream <<
"Set focus mode to " << mode;
1071 _setMessage( stream.str( ));
1074 void Config::_setMessage(
const std::string& message )
1076 _frameData.setMessage( message );
1080 eq::admin::ServerPtr Config::_getAdminServer()
1083 if( _admin.isValid() && _admin->isConnected( ))
1087 eq::admin::ClientPtr client =
new eq::admin::Client;
1088 if( !client->initLocal( 0, 0 ))
1090 _setMessage(
"Can't init admin client" );
1094 _admin =
new eq::admin::Server;
1095 if( !client->connectServer( _admin ))
1097 _setMessage(
"Can't open connection to administrate server" );
1098 client->exitLocal();
1105 void Config::_closeAdminServer()
1110 eq::admin::ClientPtr client = _admin->getClient();
1111 client->disconnectServer( _admin );
1112 client->exitLocal();
1113 LBASSERT( client->getRefCount() == 1 );
1114 LBASSERT( _admin->getRefCount() == 1 );
1120 View* Config::_getCurrentView()
1122 const eq::uint128_t& viewID = _frameData.getCurrentViewID();
1123 eq::View* view = find< eq::View >( viewID );
1124 return static_cast< View*
>( view );
1127 const View* Config::_getCurrentView()
const
1129 const eq::uint128_t& viewID = _frameData.getCurrentViewID();
1130 const eq::View* view = find< eq::View >( viewID );
1131 return static_cast< const View*
>( view );
SpaceMouse button data in magellan.
A command specialization for config events.
int32_t dx
X position change since last event.
Event for a pointer (mouse) motion or click.
uint32_t getLatency() const
A window has been closed.
int32_t xAxis
x wheel rotation
int32_t yAxis
y wheel rotation
Window resize data in resize.
const Pipes & getPipes() const
const Canvases & getCanvases() const
Render in stereo (left & right eye)
virtual bool init(const uint128_t &initID)
Initialize this configuration.
Canvases::const_iterator CanvasesCIter
A const_iterator over a eq::Canvas vector.
virtual ~Config()
Destruct a config.
A View is a 2D area of a Layout.
Window pointer Mouse wheel data in wheel.
uint32_t button
fired button
int64_t getTime() const
Get the current time in milliseconds.
int16_t yRotation
Y rotation.
int32_t dy
Y position change since last event.
A layout groups one or more View, logically belonging together.
co::NodePtr getApplicationNode()
const Observers & getObservers() const
A canvas represents a logical 2D projection surface.
virtual void unmapObject(co::Object *object)
Unmap a mapped object.
float getFocusDistance() const
View resize data in resize.
uint32_t getEventType() const
Returns the event type.
A Node represents a single computer in the cluster.
void stopFrames()
Asynchronously signal all channels to interrupt their rendering.
std::vector< Layout * > Layouts
A vector of pointers to eq::Layout.
const Views & getViews() const
Get the list of views.
bool exit()
De-initialize the Equalizer fabric namespace.
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
virtual void deregisterObject(co::Object *object)
Deregister a distributed object.
virtual uint32_t mapObjectNB(co::Object *object, const UUID &id, const uint128_t &version=co::VERSION_OLDEST)
Start mapping a distributed object.
Key press data in keyPress.
virtual bool handleEvent(const ConfigEvent *event)
Handle one (old) config event.
virtual uint32_t startFrame(const uint128_t &frameID)
Request a new frame of rendering.
int16_t xRotation
X rotation.
co::Object to distribute a model, holds a VertexBufferBase node.
Render in solid white (mostly for anaglyph stereo)
EQFABRIC_INL const Vector3f & getEyePosition(const Eye eye) const
std::vector< View * > Views
A vector of pointers to eq::View.
virtual uint32_t startFrame(const eq::uint128_t &frameID)
PointerEvent pointerWheel
Mouse wheel motion data.
uint32_t buttons
current state of all buttons
const Nodes & getNodes() const
int16_t xAxis
X translation.
std::vector< Observer * > Observers
A vector of pointers to eq::Observer.
std::vector< Canvas * > Canvases
A vector of pointers to eq::Canvas.
An Observer looks at one or more views from a certain position (head matrix) with a given eye separat...
Channel pointer button press data in pointerButtonPress.
Render in mono (cyclop eye)
uint32_t type
The event type.
int16_t zAxis
Z translation.
KeyEvent keyPress
Key press event data.
virtual bool registerObject(co::Object *object)
Register a distributed object.
bool update()
Update the configuration.
EQFABRIC_INL void setFocusDistance(const float focusDistance)
Set the focal distance.
MagellanEvent magellan
SpaceMouse data.
EQFABRIC_INL const L * getActiveLayout() const
uint32_t button
fired button
Channel pointer button release data in pointerButtonRelease.
PointerEvent pointerMotion
Pointer motion data.
Views::const_iterator ViewsCIter
A const_iterator over a eq::View vector.
SpaceMouse movement data in magellan.
virtual bool exit()
Exit this configuration.
int16_t zRotation
Z rotation.
virtual bool mapObjectSync(const uint32_t requestID)
Finalize the mapping of a distributed object.
const std::string & getName() const
virtual bool handleEvent(eq::EventICommand command)
int16_t yAxis
Y translation.
EQFABRIC_INL VisitorResult accept(ConfigVisitor &visitor)
Perform a depth-first traversal of this config.
Event for a key press or release.
uint32_t key
KeyCode for special keys, ascii code otherwise.
EQFABRIC_INL void setEyePosition(const Eye eye, const Vector3f &pos)
Set the position of the given eye relative to the observer.
Observers::const_iterator ObserversCIter
A const_iterator over a eq::Observer vector.
Mode
The current rendering mode.
bool init(const int argc, char **argv)
Initialize the Equalizer fabric namespace.