Use of one box to trigger another

Concerning processing components: filters, file load/save, visualizations, communication ...
ddvlamin
Posts: 160
Joined: Thu Aug 13, 2009 8:39 am
Location: Ghent University
Contact:

Re: Use of one box to trigger another

Post by ddvlamin »

Hi,

Again the code I'm showing is in the old style as it is an example of how I did it for a project last year. I do not know if the new style can also be used for this as on the help page of the codec toolkit one only talks about box algorithms, i.e. it is expected that the template of the codec is a box algorithm, but I would like someone else to confirm this.

If someone of the core team reads this (or anybody else that knows the answer). Can this codec toolkit also be used in the above scenario?


Anyway to explain how I did this, I had to pass a string from my algorithm to my box, you will probably use floats.

In the .h file of your algorithm you need to add input and output parameters

Code: Select all

				
//you will probably need something of type OpenViBE::Kernel::ParameterType_Float
rAlgorithmPrototype.addInputParameter(OVP_Algorithm_WordPredictionSystem_InputParameterId, "Prefix string", OpenViBE::Kernel::ParameterType_String, NULL);
				rAlgorithmPrototype.addOutputParameter(OVP_Algorithm_WordPredictionSystem_OutputParameterId, "Predicted word", OpenViBE::Kernel::ParameterType_String, NULL);
In your initialize method of your box you will need to initialize your algorithm and create a variable that you point to the output of the variable of the algorithm (similar for inputs if you have an input to your algorithm).
The code in the box algorithm looked like:

Code: Select all

//in- and outputs that will be connected to in- and outputs of your algorithm, instead you will probably need an OpenViBE::float64
OpenViBE::Kernel::TParameterHandler<OpenViBE::CString*> ip_pPrefixString;
OpenViBE::Kernel::TParameterHandler<OpenViBE::CString*> op_pPredictedWord;

//initialization of my algorithm
m_pWordPredictor = &this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_ClassId_Algorithm_WordPredictionSystem));
m_pWordPredictor->initialize();

//connecting in- and output variables in the box algorithm to the in- and output of my algorithm	ip_pPrefixString.initialize(m_pWordPredictor->getInputParameter(OVP_Algorithm_WordPredictionSystem_InputParameterId));
	op_pPredictedWord.initialize(m_pWordPredictor->getOutputParameter(OVP_Algorithm_WordPredictionSystem_OutputParameterId));
Somewhere in the process method of my box I had to call my algorithm and this is done through

Code: Select all

this->m_pWordPredictor->process(OVP_Algorithm_WordPredictionSystem_InputTriggerId_Process);
							if(m_pWordPredictor->isOutputTriggerActive(OVP_Algorithm_WordPredictionSystem_OutputTriggerId_Done)) {
//do some stuff
}


You will also need to define triggers (e.g. OVP_Algorithm_WordPredictionSystem_OutputTriggerId_Done) in your algorithm to indicate the processing is done, in your algorithm you do this by activating the trigger

Code: Select all

this->activateOutputTrigger(OVP_Algorithm_WordPredictionSystem_OutputTriggerId_Done, true);
I think the easiest thing to do is to take other algorithms as an example. Again, I'm not sure if you can apply the faster coding style of the codec toolkit.

Best regards,
Dieter

lbonnet
Site Admin
Posts: 417
Joined: Wed Oct 07, 2009 12:11 pm

Re: Use of one box to trigger another

Post by lbonnet »

Hi !

We recently released new tutorials on the website. They could really help you understanding the algorithm/box/codec mechanics.

The introduction, along with the stream description page contain useful "General" information.

Tutorial 1 cover the box implementation using the dev tools (codec toolkit, skeleton-generator)

The tutorial 2 shows how to integrate an algorithm in a box that uses the Codec Toolkit.
You will see that everything is compatible ;)

I hope this helps.

Laurent
Follow us on twitter >> openvibebci

Checkout my (old) blog for some OpenViBE tips & tricks : here !

ddvlamin
Posts: 160
Joined: Thu Aug 13, 2009 8:39 am
Location: Ghent University
Contact:

Re: Use of one box to trigger another

Post by ddvlamin »

Ok, thanks for the info, I was looking for such tutorial yesterday, but could not find it, probably because it has been updated very recently :)

lbonnet
Site Admin
Posts: 417
Joined: Wed Oct 07, 2009 12:11 pm

Re: Use of one box to trigger another

Post by lbonnet »

In fact I just uploaded it this morning :)

I was following this topic, and I was about to answer with some code snippets but... I thought that the time was good for a brand new tutorial !
More reusability ;)

L
Follow us on twitter >> openvibebci

Checkout my (old) blog for some OpenViBE tips & tricks : here !

Post Reply