Difference between revisions of "NaviTrack Tutorial:Integrating:Passing coordinates data"
Line 26: | Line 26: | ||
=Receiving side= | =Receiving side= | ||
− | ==Modify MyTutorialSink== | + | ==Modify MyTutorialSink and MyTutorialModule== |
+ | |||
+ | An event to pull coordinate data is handled in onEventGenerated() function in MyTutorialSink. | ||
+ | There are two steps to pass the coordinate data to your application: STEP 1) onEventGenerated() stores the data into member variables in MyTutorialSinke; STEP 2) your application fetch the data from MyTutorialSink through MyTutorialModule. | ||
+ | |||
+ | Bellows are examples to implement STEP 1 and STEP 2. | ||
+ | |||
+ | MyTutorialSink.h: Add member variables to hold the coordinate data: | ||
+ | private: | ||
+ | std::vector<float> position; | ||
+ | std::vector<float> orientation; | ||
+ | |||
+ | MyTutorialSink.cxx: | ||
+ | void MyTutorialSink::onEventGenerated( Event& event, Node& generator) | ||
+ | { | ||
+ | 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; | ||
+ | } | ||
+ | |||
+ | if (event.hasAttribute("orientation")) | ||
+ | { | ||
+ | for (int i = 0; i < 4; i ++) { | ||
+ | orientation[i]= event.getOrientation()[i]; | ||
+ | } | ||
+ | std::cout << "orientation !!!" << std::endl; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | orientation[0]=0.0; | ||
+ | orientation[1]=0.0; | ||
+ | orientation[2]=0.0; | ||
+ | orientation[3]=0.0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | MyTutorialModule.cxx (and .h): add follwing functions: | ||
+ | |||
==pullpos.cxx== | ==pullpos.cxx== | ||
Revision as of 04:32, 25 May 2007
Home < NaviTrack Tutorial:Integrating:Passing coordinates dataWhat you need to do
- Create NaviTrack module to provide a node that can be accessed by you application.
- Modify your application to push and pull NaviTrack events cyclically with certain interval.
- Create NaviTrack configuration XML file to build tree structure of data flow.
Sending side
Modify MyTutorialModule
void MyTutorialModule::setTracker(std::vector<float> pos,std::vector<float> quat) { if (pos.size() != 3 || quat.size() != 4) { std::cout << "MyTutorialModule::setTracker(): illegal vector size." << std::endl; return; } if(source!=NULL) { ot::Event *event = new ot::Event(); event->setAttribute("position",pos); event->setAttribute("orientation",quat); event->timeStamp(); source->updateObservers( *event ); } }
pushpos.cxx
Receiving side
Modify MyTutorialSink and MyTutorialModule
An event to pull coordinate data is handled in onEventGenerated() function in MyTutorialSink. There are two steps to pass the coordinate data to your application: STEP 1) onEventGenerated() stores the data into member variables in MyTutorialSinke; STEP 2) your application fetch the data from MyTutorialSink through MyTutorialModule.
Bellows are examples to implement STEP 1 and STEP 2.
MyTutorialSink.h: Add member variables to hold the coordinate data:
private: std::vector<float> position; std::vector<float> orientation;
MyTutorialSink.cxx:
void MyTutorialSink::onEventGenerated( Event& event, Node& generator) { 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;
}
if (event.hasAttribute("orientation")) { for (int i = 0; i < 4; i ++) { orientation[i]= event.getOrientation()[i]; } std::cout << "orientation !!!" << std::endl; } else {
orientation[0]=0.0; orientation[1]=0.0; orientation[2]=0.0; orientation[3]=0.0;
} }
MyTutorialModule.cxx (and .h): add follwing functions:
pullpos.cxx
Testing
Let's try to send position data from pushpos to pullpos program through network.
tutorial_source.xml (for pushpos)
tutorial_sink.xml (for pullpos)
Run the programs
Open two terminals and go to the directory where the programs exists.
Terminal 1 (pushpos: sending side)
$ ./pushpos tutorial_source.xml
Terminal 2 (pullpos: receiving side)
$ ./pullpos tutorial_sink.xml
Back to Integrating into your application.