div class="twikiTopBar">

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

ErrorVisualizerService.cpp

00001 /* ========================================================================
00002  * Copyright (C) 2000-2004  Technische Universitaet Muenchen
00003  * License: GPL v2 (or later)
00004  *
00005  * For further information please contact the DWARF team at
00006  * <dwarf-gnu@augmentedreality.de>
00007  *
00008  * ErrorVisualizerService.cpp
00009  * Daniel Pustka <pustka@in.tum.de> April 2004
00010  * Distributed Wearable Augmented Reality Framework - www.augmentedreality.de
00011  * For documentation and instructions, see the DWARF documentation website at
00012  * http://wwwbruegge.in.tum.de/projects/dwarf/doc/
00013  *
00014  * For further questions about DWARF, please contact us at
00015  * <dwarf@augmentedreality.de>
00016  * For questions about this particular service, contact
00017  * Daniel Pustka <pustka@in.tum.de>
00018  *
00019  * $Id: ErrorVisualizerService.cpp,v 1.4 2006/02/15 17:49:03 pustka Exp $
00020  */
00021 
00022 
00023 #include <debug.h>
00024 #include <corbainit.h>
00025 #include <segfaulthandler.h>
00026 #include <dwarfutil.h>
00027 #include <ErrorVisualizerService.h>
00028 #include <algorithm>
00029 #include <ubitrack/EasyPoseData.h>
00030 
00031 using std::string;
00032 using namespace DWARF;
00033 
00034 
00035 ErrorVisualizerService::ErrorVisualizerService()
00036         : m_ViewerNeed( this )
00037         {
00038         DEBUGSTREAM( 5, "Constructor called." );
00039         }
00040 
00041 
00042 ErrorVisualizerService::~ErrorVisualizerService()
00043         {
00044         DEBUGSTREAM( 5, "Destructor called." );
00045         }
00046 
00047 
00048 CORBA::Object_ptr ErrorVisualizerService::createNeedObject( DWARF::NeedDescription_ptr needDescr )
00049         {
00050         if ( needDescr->getName() == string( "Viewer" ) )
00051                 return m_ViewerNeed._this();
00052         else
00053                 // delegate to parent object
00054                 return PoseService::createNeedObject( needDescr );
00055         }
00056 
00057 
00058 void ErrorVisualizerService::onImport( DWARF::ViewerControl_ptr pInterface,
00059         ObjrefImporterNeed<DWARF::ViewerControl>* pImporter )
00060         {
00061         DEBUGSTREAM( 5, "Got a viewer" );
00062         omni_mutex_lock l( m_Mutex );
00063 
00064         // create objects for all abilities in the viewer
00065         for ( auto_vector< ErrorPoseAbility >::iterator it = m_Abilities.begin();
00066                 it != m_Abilities.end(); it++ )
00067                 (*it)->SetViewer( m_ViewerNeed.getInterface() );
00068         }
00069 
00070 
00071 void ErrorVisualizerService::onEvent( PoseData& P )
00072         {
00073         if ( !EasyPoseData::isSane( P ) )
00074       {
00075       DEBUGSTREAM( 5, "Got insane pose - check sender!" );
00076                 return;
00077       }
00078 
00079         omni_mutex_lock l( m_Mutex );
00080 
00081         // check map for ErrorPoseAbility
00082         string sID = string( P.source ) + "&" + string( P.target );
00083         AbilityMapT::iterator it = m_AbilityMap.find( sID );
00084    DEBUGSTREAM( 20, "Got event: " << sID );
00085 
00086         if ( it != m_AbilityMap.end() )
00087                 // ErrorPoseAbility already created -> send error pose event
00088       if ( m_ViewerNeed.hasInterface() )
00089                    it->second->TransformAndSendEvent( P );
00090       else;
00091         else
00092                 {
00093                 // create a new ErrorPoseAbility
00094                 ActiveServiceDescription_var ServiceDesc( getServiceDesc() );
00095                 m_Abilities.push_back( std::auto_ptr<ErrorPoseAbility>(
00096                         new ErrorPoseAbility( P.source, P.target, ServiceDesc ) ) );
00097                 m_AbilityMap[ sID ] = m_Abilities.back();
00098 
00099                 // create objects in viewer
00100                 if ( m_ViewerNeed.hasInterface() )
00101                         m_Abilities.back()->SetViewer( m_ViewerNeed.getInterface() );
00102 
00103                 // we won't send this pose as it is highly unlikely that someone will receive it now
00104                 }
00105         }
00106 
00107 
00108 void ErrorVisualizerService::run()
00109         {
00110         while( m_shouldRun )
00111                 sleep( 1 );
00112         }
00113 
00114 
00115 int main( int argc, char** argv )
00116         {
00117         registerSegFaultHandler();
00118 
00119         // set up the communication with the service manager
00120         CorbaInit *myOrbConnection = CorbaInit::initializeOrb( argc, argv );
00121         ErrorVisualizerService MyService;
00122         myOrbConnection->registerService( "ErrorVisualizer", MyService._this() );
00123         myOrbConnection->run();
00124         myOrbConnection->destroy();
00125 
00126         return 0;
00127         }
00128 

ErrorVisualizerService.cpp Source File | generated on Sun Apr 29 02:00:59 2007 by Doxygen 1.4.1 for DWARF