Difference between revisions of "NaviTrack Tutorial:Creating module:Module structure"

From NAMIC Wiki
Jump to: navigation, search
Line 94: Line 94:
  
 
== Sink class (MyTutorialSink.h, MyTutorialSink.cxx) ==
 
== Sink class (MyTutorialSink.h, MyTutorialSink.cxx) ==
 +
This class is used to configure and manage source and sink nodes.
  
 +
The following example class contains only essential functions for a NaviTrack module.
 +
 +
MyTutorialSink.h:
 +
This class is used to configure and manage source and sink nodes.
 +
 +
The following example class contains only essential functions for a NaviTrack module.
 +
 +
MyTutorialModule.h:
 +
#ifndef __MY_TUTORIAL_SINK_H__
 +
#define __MY_TUTORIAL_SINK_H__
 +
 +
class MyTutorialSink : public ot::Node
 +
{
 +
  public:
 +
 +
  MyTutorialSink() {};
 +
  ~MyTutorialSink() {};
 +
 +
  public:
 +
 +
  virtual int isEventGenerator() {return 1;};
 +
  virtual void onEventGenerated( ot::Event& event, ot::Node& generator) {};
 +
 +
  protected:
 +
 +
  friend class MyTutorialSinkModule;
 +
};
 +
 +
#endif // end of __MY_TUTORIAL_SINK_H
  
 
== Source class (MyTutorialSource.h, MyTutorialSource.cxx) ==
 
== Source class (MyTutorialSource.h, MyTutorialSource.cxx) ==

Revision as of 15:49, 15 May 2007

Home < NaviTrack Tutorial:Creating module:Module structure

Three types of nodes

  • Sink nodes (XxxxSink.h, [XxxxSink.cxx])
    • Leaves in the graph and receive their data values from external sources, such as Polaris optraciking system, and send put the data into NaviTrack data flow graph.
  • Source nodes (XxxxSource.h, [XxxxSource.cxx])
    • Leaves to propagate their data values received from other nodes to external outputs.
  • Filter nodes (we don't use this in the tutorial)
    • Intermediate nodes and modify the values received from other nodes.


Classes for module "MyTutorialModule"

Module class (MyTutorialModule.h, MyTutorialModule.cxx)

This class is used to configure and manage source and sink nodes.

The following example class contains only essential functions for a NaviTrack module.

MyTutorialModule.h:

#ifndef __MY_TUTORIAL_MODULE_H__
#define __MY_TUTORIAL_MODULE_H__

#include <OpenTracker/OpenTracker.h>
#include <OpenTracker/dllinclude.h>
#include <OpenTracker/input/SPLModules.h>
#include <OpenTracker/input/MyTutorialSink.h>
#include <OpenTracker/input/MyTutorialSource.h>
#include <string>

namespace ot {

class OPENTRACKER_API MyTutorialModule : public Module, public NodeFactory
{   
 public:
 
  // Constructor and destructor
  MyTutorialModule();
  virtual ~MyTutorialModule();
  
  Node* createNode( const std::string& name,  ot::StringTable& attributes);
  void  pushEvent();
  void  pullEvent() {};
  void  init(StringTable&, ConfigNode *);
 
 private:
  MyTutorialSink*   sink;
  MyTutorialSource* source;
  
  friend class  MyTutorialSink;
  friend class  MyTutorialSource;
};

OT_MODULE(MyTutorialModule);

} // end of namespace ot
#endif // __MY_TUTORIAL_MODULE_H__

init()

Function init() is called when the NaviTrack detects MyTutorialConfig in configuration section of the XML file, during starting up. You can put codes to initialize the module into this function.

createNode()

When the NaviTrack detects either MyTutorialSource or MyTutorialSink in the XML file, function createNode is called. The code for this function might be as following:

ot::Node * MyTutorialModule::createNode( const std::string& name,  ot::StringTable& attributes)
{
  if( name.compare("MyTutorialSink") == 0 )
    {
      sink =  new MyTutorialSink();
      return sink;
    }
  if(name.compare("MyTutorialSource") == 0 )
    {
      std::string stationName=attributes.get("name");
      source = new MyTutorialSource(stationName);
      return source;
    }
  return NULL;
}

Note that the class in above example can have only one sink node and one source node. But you can manage more than two nodes with same type, by using array or vector, since createNode is called each time the NaviTrack detects the corresponding type of node.

pushEvent() and pullEvent()

These are a sort of event handling function. These are called whenever a push or pull event occurs.

Sink class (MyTutorialSink.h, MyTutorialSink.cxx)

This class is used to configure and manage source and sink nodes.

The following example class contains only essential functions for a NaviTrack module.

MyTutorialSink.h: This class is used to configure and manage source and sink nodes.

The following example class contains only essential functions for a NaviTrack module.

MyTutorialModule.h:

#ifndef __MY_TUTORIAL_SINK_H__
#define __MY_TUTORIAL_SINK_H__

class MyTutorialSink : public ot::Node
{
 public: 

  MyTutorialSink() {};
  ~MyTutorialSink() {}; 

 public: 

  virtual int isEventGenerator() {return 1;};
  virtual void onEventGenerated( ot::Event& event, ot::Node& generator) {};

 protected: 

  friend class MyTutorialSinkModule;
};

#endif // end of __MY_TUTORIAL_SINK_H

Source class (MyTutorialSource.h, MyTutorialSource.cxx)

Go back to Creating module.