OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

TestModule.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  * ======================================================================== */
00042 /* ======================================================================= */
00043 
00044 // this will remove the warning 4786
00045 #include "../tool/disable4786.h"
00046 #include <stdlib.h>
00047 
00048 #include "TestModule.h"
00049 
00050 
00051 #ifndef OT_NO_TESTMODULE_SUPPORT
00052 
00053 
00054 #include "TestSource.h"
00055 
00056 #include "MathUtils.h"
00057 
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 // #include <iostream> FIXME Why was this included ?
00061 
00062 #include <ace/Log_Msg.h>
00063 
00064 //using namespace std;
00065 
00066 // Destructor method
00067 
00068 namespace ot {
00069 
00070     TestModule::~TestModule()
00071     {
00072         nodes.clear();
00073     }
00074 
00075     // This method is called to construct a new Node.
00076 
00077     Node * TestModule::createNode( const std::string& name, StringTable& attributes)
00078     {
00079         if( name.compare("TestSource") == 0 )
00080         {
00081             int frequency;
00082             int offset;
00083             int num = sscanf(attributes.get("frequency").c_str(), " %i", &frequency );
00084             if( num == 0 ){
00085                 frequency = 1;
00086             }
00087             num = sscanf(attributes.get("offset").c_str(), " %i", &offset );
00088             if( num == 0 ){
00089                 offset = 0;
00090             }
00091             TestSource * source = new TestSource( frequency, offset );
00092             attributes.get("position", source->event.getPosition(), 3);
00093             attributes.get("orientation", source->event.getOrientation(), 4);
00094             sscanf( attributes.get("button").c_str(), " %hu", &(source->event.getButton()) );
00095             sscanf( attributes.get("confidence").c_str(), " %f", &(source->event.getConfidence()) );
00096             if( attributes.containsKey("noise") )
00097             {
00098                 attributes.get("noise",&source->noise);
00099             }
00100             else
00101             {
00102                 source->noise = -1;
00103             }
00104             nodes.push_back( source );
00105 
00106             ACE_DEBUG((LM_DEBUG, ACE_TEXT("ot:Build TestSource node\n")));
00107             initialized = 1;
00108             return source;
00109         }
00110         return NULL;
00111     }
00112 
00113     // pushes events into the tracker tree.
00114 
00115     void TestModule::pushEvent()
00116     {
00117         for( NodeVector::iterator it = nodes.begin(); it != nodes.end(); it++ )
00118         {
00119             TestSource *source = (TestSource *) *it;
00120             if((cycle + source->offset) % source->frequency == 0 )
00121             {
00122                 source->push();
00123             }
00124         }
00125         cycle++;
00126     }
00127 
00128 
00129     void TestSource::push(void)
00130     {
00131         static int count;
00132         if( noise > 0 )
00133         {
00134             perturbed.setAttribute("intAttr", count++);
00135             perturbed.setAttribute("chrAttr", (char)(33 + count % 92));
00136             perturbed.setAttribute("dblAttr", (double)(count / 7.3));
00137             perturbed.setAttribute("fltAttr", (float)(count / 7.3));
00138 
00139             int i;
00140             for( i = 0; i < 3; i++ )
00141             {
00142                 perturbed.getPosition()[i] = (float)(event.getPosition()[i] + ((float)rand()/RAND_MAX)*noise - noise / 2.0);
00143                 perturbed.getOrientation()[i] = (float)(event.getOrientation()[i] + (float)(rand()/RAND_MAX)*noise - noise / 2.0);
00144             }
00145             perturbed.getOrientation()[3] = (float)(event.getOrientation()[3] + ((float)rand()/RAND_MAX)*noise - noise / 2.0);
00146             MathUtils::normalizeQuaternion( perturbed.getOrientation() );
00147             if( ((float)rand()/RAND_MAX) < noise  )
00148             {
00149                 perturbed.getOrientation()[0] = -perturbed.getOrientation()[0];
00150                 perturbed.getOrientation()[1] = -perturbed.getOrientation()[1];
00151                 perturbed.getOrientation()[2] = -perturbed.getOrientation()[2];
00152                 perturbed.getOrientation()[3] = -perturbed.getOrientation()[3];
00153             }
00154             perturbed.setConfidence(static_cast<float>((rand()/RAND_MAX)*noise - noise / 2.0));
00155             perturbed.setButton(count % 16);
00156 
00157             perturbed.timeStamp();
00158             updateObservers( perturbed );
00159         }
00160         else
00161         {
00162             event.timeStamp();
00163             updateObservers( event );
00164         }
00165     }
00166 
00167 } //namespace ot
00168 
00169 
00170 #endif //OT_NO_TESTMODULE_SUPPORT
00171 
00172 /* 
00173  * ------------------------------------------------------------
00174  *   End of TestModule.h
00175  * ------------------------------------------------------------
00176  *   Automatic Emacs configuration follows.
00177  *   Local Variables:
00178  *   mode:c++
00179  *   c-basic-offset: 4
00180  *   eval: (c-set-offset 'substatement-open 0)
00181  *   eval: (c-set-offset 'case-label '+)
00182  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00183  *   eval: (setq indent-tabs-mode nil)
00184  *   End:
00185  * ------------------------------------------------------------ 
00186  */

copyright (c) 2006 Graz University of Technology