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

From NAMIC Wiki
Jump to: navigation, search
Line 50: Line 50:
 
   void MyTutorialModule::getImage(Image& img, int& w, int& h)
 
   void MyTutorialModule::getImage(Image& img, int& w, int& h)
 
   {
 
   {
    std::cout << "MyTutorialModule::getImage() is called." << std::endl;
 
 
 
 
     if(sink != NULL)
 
     if(sink != NULL)
 
       {
 
       {

Revision as of 05:02, 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::setImage(Image& img, int w, int h)
 {  
   if(source!=NULL)
     {
       Event event;
       event.setAttribute("image", img);
       event.setAttribute("xsize", w);
       event.setAttribute("ysize", h);
       event.timeStamp();
       source->updateObservers( event );
     }
 }

pushpos.cxx

Receiving side

Modify MyTutorialSink and MyTutorialModule

MyTutorialSink.h: Add member variables to hold the coordinate data:

 private:
   Image image;
   int width;
   int height;

MyTutorialSink.cxx:

 void MyTutorialSink::onEventGenerated( Event& event, Node& generator)
 {
   if (event.hasAttribute("image") &&
       event.hasAttribute("xsize") &&
       event.hasAttribute("ysize"))
     {
       image = event.getAttribute((Image*)NULL, "image");
       width  = event.getAttribute(std::string("xsize"),0);
       height = event.getAttribute(std::string("ysize"),0);
     }
   else
     {
       width  = 0;
       height = 0;
     }
 }

MyTutorialModule.cxx (and .h): add the follwing function:

 void MyTutorialModule::getImage(Image& img, int& w, int& h)
 {
   if(sink != NULL)
     {
       sink->getImage(img, w, h);
     }
 
 }

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.