OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

ToolIOModule.cxx

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
00035  * ======================================================================== */
00043 /* ======================================================================= */
00044 
00045 #include "ToolIOModule.h"
00046 #include "ToolSource.h"
00047 #include "ToolSink.h"
00048 
00049 // constructor method
00050 
00051 ToolIOModule::ToolIOModule( QTable * out_ ) :
00052     Module(), NodeFactory(), output( out_ ), quit(0)
00053 {
00054     output->setNumRows( 0 );    
00055 }
00056      
00057 // Destructor method, clears nodes member.
00058 
00059 ToolIOModule::~ToolIOModule()
00060 {
00061     sinks.clear();
00062     sources.clear();
00063 }
00064 
00065 // initializes the tracker module.
00066 
00067 void ToolIOModule::init(StringTable& attributes, ConfigNode * localTree)
00068 {
00069     Module::init( attributes, localTree );
00070 }
00071 
00072 // creates new nodes
00073 
00074 Node * ToolIOModule::createNode( const std::string& name, StringTable& attributes)
00075 {
00076     if( name.compare("ConsoleSink") == 0 || name.compare("ToolSink") == 0 )
00077     {
00078         ToolSink * sink = new ToolSink( attributes.get("comment"));
00079         sinks.push_back( sink );
00080         //        cout << "Built ToolSink node for ConsoleSink" << endl;       
00081         return sink;
00082     } else if( name.compare("ConsoleSource") == 0 || name.compare("ToolSource") == 0)
00083     {
00084         int number;
00085         if( sscanf( attributes.get("number").c_str()," %i", &number ) == 1 )
00086         {
00087             if( number >= 0 && number < 10 )
00088             {
00089                 ToolSource * source = new ToolSource( number );
00090                 sources.push_back( source );
00091                 //                cout << "Build ToolSource node." << endl;
00092                 return source;
00093             } else
00094             {
00095                 //                cout << "ToolSource station number not in [0,9] : " << number << endl;
00096             }
00097         }
00098     }
00099     return NULL;
00100 }
00101 
00102 // reads out node events and displays them
00103 
00104 void ToolIOModule::pullEvent()
00105 {
00106     QString s;
00107     int row;
00108     double diff;
00109     for(NodeVector::iterator it = sinks.begin(); it != sinks.end(); it++ )
00110     {
00111         ToolSink * sink = (ToolSink *)(*it);
00112         if( sink->changed == 1 )
00113         {
00114             row = it - sinks.begin();
00115             Event & event = sink->event;
00116             diff = OSUtils::currentTime() - event.time;
00117             s.sprintf("%f %f %f", event.getPosition()[0],event.getPosition()[1],event.getPosition()[2]);
00118             output->setText( row, 0, s );
00119             s.sprintf("%f %f %f %f", event.getOrientation()[0], event.getOrientation()[1], 
00120                       event.getOrientation()[2], event.getOrientation()[3] );
00121             output->setText( row, 1, s );
00122             s.sprintf("%hx", event.getButton() );
00123             output->setText( row, 2, s );
00124             s.sprintf("%f", event.getConfidence() );
00125             output->setText( row, 3, s );
00126             s.sprintf("%lf", event.time );
00127             output->setText( row, 4, s );
00128             s.sprintf("%lf", diff );
00129             output->setText( row, 5, s );
00130             sink->changed = 0;
00131         }
00132     }
00133 }
00134 
00135 // sets the table properties
00136 
00137 void ToolIOModule::start()
00138 {
00139     output->setNumRows( sinks.size());
00140     QHeader * head = output->verticalHeader();
00141     for(NodeVector::iterator it = sinks.begin(); it != sinks.end(); it++ )
00142     {
00143         ToolSink * sink = (ToolSink *)(*it);
00144         head->setLabel(it - sinks.begin(),sink->comment.c_str()); 
00145     }
00146     head->adjustSize();
00147     Module::start();
00148 }
00149 
00150 void ToolIOModule::close()
00151 {
00152 }
00153 
00154 int ToolIOModule::stop()
00155 {
00156     return quit;
00157 }
00158 
00159 /* 
00160  * ------------------------------------------------------------
00161  *   End of ToolIOModule.cxx
00162  * ------------------------------------------------------------
00163  *   Automatic Emacs configuration follows.
00164  *   Local Variables:
00165  *   mode:c++
00166  *   c-basic-offset: 4
00167  *   eval: (c-set-offset 'substatement-open 0)
00168  *   eval: (c-set-offset 'case-label '+)
00169  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00170  *   eval: (setq indent-tabs-mode nil)
00171  *   End:
00172  * ------------------------------------------------------------ 
00173  */

copyright (c) 2006 Graz University of Technology