Difference between revisions of "NaviTrack Tutorial:Creating module:Testing"
Line 5: | Line 5: | ||
===tutorial_consolesink.xml=== | ===tutorial_consolesink.xml=== | ||
− | This file is used to receive | + | This file is used to receive coordinate data |
from NetworkSink and display the value onto a console by | from NetworkSink and display the value onto a console by | ||
using ConsoleSink. | using ConsoleSink. | ||
===tutorial_source.xml=== | ===tutorial_source.xml=== | ||
− | This file is used to send | + | This file is used to send coordinate data, |
which is generated by pushEvent() in MyTutorialModule, | which is generated by pushEvent() in MyTutorialModule, | ||
to other hosts, by using NetworkSink. | to other hosts, by using NetworkSink. | ||
===tutorial_sink.xml=== | ===tutorial_sink.xml=== | ||
− | This file is used to receive | + | This file is used to receive coodinate data |
from NetworkSink and display the value onto a console by | from NetworkSink and display the value onto a console by | ||
using MyTutorialSink. | using MyTutorialSink. | ||
Line 21: | Line 21: | ||
=Testing MyTutorialSource= | =Testing MyTutorialSource= | ||
− | === | + | Let us see how MyTutorialSource works by sending coordinate data |
+ | generated by MyTutorialSource to another NaviTrack. | ||
+ | |||
+ | In a console, run: | ||
+ | $ middleware tutorial_consolesink.xml | ||
+ | |||
+ | and in another console, run: | ||
+ | $ middleware tutorial_source.xml | ||
+ | |||
+ | Then you can see coordinate values are varying on the console, | ||
+ | where you run a NaviTrack with tutorial_consolesink.xml. | ||
+ | |||
+ | In this testing, the essential part of generating cordinate values is in | ||
+ | pushEvent() of MyTutorialSource.cxx. | ||
+ | In this function, you could see the following code: | ||
+ | void MyTutorialModule::pushEvent() | ||
+ | { | ||
+ | if(source) | ||
+ | { | ||
+ | std::cout << "MyTutorialModule::pushEvent() is called." << std::endl; | ||
+ | source->event.getPosition()[0] += 0.01; | ||
+ | source->event.getPosition()[1] += 0.02; | ||
+ | source->event.getPosition()[2] += 0.03; | ||
+ | source->event.getOrientation()[0] += 0.01; | ||
+ | source->event.getOrientation()[1] += 0.02; | ||
+ | source->event.getOrientation()[2] += 0.03; | ||
+ | source->event.getOrientation()[3] += 0.04; | ||
+ | |||
+ | source->event.timeStamp(); | ||
+ | source->updateObservers( source->event ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | =Testing MyTutorialSink= | ||
+ | Next, we use MyTutorialSink instead of ConsoleSink. | ||
+ | Stop the NaviTrack launched with tutorial_consolesink.xml and, | ||
+ | run: | ||
+ | $ middleware tutorial_sink.xml | ||
+ | |||
+ | In this case, you could see the output from MyTutorialSink. | ||
+ | |||
+ | The actual code to display coordinate data is in onEventGenerated() of | ||
+ | MyTutorialSink. The following code is implemented in this function: | ||
+ | void MyTutorialSink::onEventGenerated( Event& event, Node& generator) | ||
+ | { | ||
+ | float orientation[4]; | ||
+ | float position[3]; | ||
+ | |||
+ | if (event.hasAttribute("orientation")) | ||
+ | { | ||
+ | for (int i = 0; i < 4; i ++) | ||
+ | orientation[i]=-event.getOrientation()[i]; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | orientation[0]=0.0; | ||
+ | orientation[1]=1.0; | ||
+ | orientation[2]=0.0; | ||
+ | orientation[3]=0.0; | ||
+ | } | ||
+ | if(event.hasAttribute("position")) | ||
+ | for(int i = 0; i < 3; i ++) | ||
+ | position[i]=event.getPosition()[i]; | ||
+ | else | ||
+ | { | ||
+ | position[0]=0.0; | ||
+ | position[1]=0.0; | ||
+ | position[2]=0.0; | ||
+ | } | ||
+ | std::cout << "MyTutorialSink::onEventGenerated(): pos = (" | ||
+ | << position[0] << ", " << position[1] << ", " << position[2] << ")" | ||
+ | << std::endl; | ||
+ | std::cout << "MyTutorialSink::onEventGenerated(): ori = (" | ||
+ | << orientation[0] << ", " << orientation[1] << ", " << orientation[2] << "," | ||
+ | << orientation[3] << ")" << std::endl; | ||
+ | |||
+ | } |
Revision as of 21:18, 15 May 2007
Home < NaviTrack Tutorial:Creating module:TestingContents
In this testing, we use three NaviTrack configuration files included in the sample source codes archive that you have already downloaded. (File:NTTutorial May2007.zip)
tutorial_consolesink.xml
This file is used to receive coordinate data from NetworkSink and display the value onto a console by using ConsoleSink.
tutorial_source.xml
This file is used to send coordinate data, which is generated by pushEvent() in MyTutorialModule, to other hosts, by using NetworkSink.
tutorial_sink.xml
This file is used to receive coodinate data from NetworkSink and display the value onto a console by using MyTutorialSink.
Testing MyTutorialSource
Let us see how MyTutorialSource works by sending coordinate data generated by MyTutorialSource to another NaviTrack.
In a console, run:
$ middleware tutorial_consolesink.xml
and in another console, run:
$ middleware tutorial_source.xml
Then you can see coordinate values are varying on the console, where you run a NaviTrack with tutorial_consolesink.xml.
In this testing, the essential part of generating cordinate values is in pushEvent() of MyTutorialSource.cxx. In this function, you could see the following code:
void MyTutorialModule::pushEvent() { if(source) { std::cout << "MyTutorialModule::pushEvent() is called." << std::endl; source->event.getPosition()[0] += 0.01; source->event.getPosition()[1] += 0.02; source->event.getPosition()[2] += 0.03; source->event.getOrientation()[0] += 0.01; source->event.getOrientation()[1] += 0.02; source->event.getOrientation()[2] += 0.03; source->event.getOrientation()[3] += 0.04; source->event.timeStamp(); source->updateObservers( source->event ); } }
Testing MyTutorialSink
Next, we use MyTutorialSink instead of ConsoleSink. Stop the NaviTrack launched with tutorial_consolesink.xml and, run:
$ middleware tutorial_sink.xml
In this case, you could see the output from MyTutorialSink.
The actual code to display coordinate data is in onEventGenerated() of MyTutorialSink. The following code is implemented in this function:
void MyTutorialSink::onEventGenerated( Event& event, Node& generator) { float orientation[4]; float position[3];
if (event.hasAttribute("orientation")) { for (int i = 0; i < 4; i ++) orientation[i]=-event.getOrientation()[i]; } else {
orientation[0]=0.0; orientation[1]=1.0; orientation[2]=0.0; orientation[3]=0.0;
} if(event.hasAttribute("position")) for(int i = 0; i < 3; i ++) position[i]=event.getPosition()[i]; else {
position[0]=0.0; position[1]=0.0; position[2]=0.0;
} std::cout << "MyTutorialSink::onEventGenerated(): pos = (" << position[0] << ", " << position[1] << ", " << position[2] << ")" << std::endl; std::cout << "MyTutorialSink::onEventGenerated(): ori = (" << orientation[0] << ", " << orientation[1] << ", " << orientation[2] << "," << orientation[3] << ")" << std::endl; }