Difference between revisions of "NaviTrack Tutorial:Integrating:Passing image data"

From NAMIC Wiki
Jump to: navigation, search
Line 88: Line 88:
  
  
!!NOTE!! While passing image data through network using NaviTrack NetworkModule.
+
!!NOTE!! You may encounter application errors, while passing image data through a network using NaviTrack NetworkModule.
 
This is because NaviTrack NetworkModule uses UDP for a communication between Sink and Source.
 
This is because NaviTrack NetworkModule uses UDP for a communication between Sink and Source.
 
Each data has header information in this communication including entire size of the data,
 
Each data has header information in this communication including entire size of the data,

Revision as of 04:58, 25 May 2007

Home < NaviTrack Tutorial:Integrating:Passing image data

You can pass image data from one application to another through NaviTrack in almost same way as passing coordinate data.

Sending side

Modify MyTutorialModule

To send data through NaviTrack, it is necessary to generate a new event, which contains the data. The following code is implemented into MyTutorialModule to be called from your application.

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 the follwing function:

 void MyTutorialModule::getTracker(std::vector<float>& pos,std::vector<float>& quat)
 {
   //std::cout << "MyTutorialModule::getTracker() is called." << std::endl;
 
   if(sink!=NULL)
     {
       sink->getTracker(pos, quat);
     }
 }

pullpos.cxx

Testing

In terminal 1 (sending side: pushimage)

$ ./pushimage tutorial_source.xml

In terminal 2 (receiving side: pullimage)

$ ./pullimage tutorial_source.xml


!!NOTE!! You may encounter application errors, while passing image data through a network using NaviTrack NetworkModule. This is because NaviTrack NetworkModule uses UDP for a communication between Sink and Source. Each data has header information in this communication including entire size of the data, and packet loss causes inconsistency between data size information in header and actual data size. NaviTrack has no capability to recover this kind of error in the current version.

Back to Integrating into your application.