TestModule.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044
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
00061
00062 #include <ace/Log_Msg.h>
00063
00064
00065
00066
00067
00068 namespace ot {
00069
00070 TestModule::~TestModule()
00071 {
00072 nodes.clear();
00073 }
00074
00075
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
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 }
00168
00169
00170 #endif //OT_NO_TESTMODULE_SUPPORT
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186