Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ö__D_
Beginner
51 Views

Binding Pipeline Filters

Hello,

I'm trying to constuct a pipeline with two filter (filter number will be increase later). I need to bind or connect filters and pass images, parameters etc. among them. Here my first experiments' codes.

//AFilter.h !!!!!!!!!!!

#ifndef PIPELINE_AFILTER_H_
#define PIPELINE_AFILTER_H_

#include "ATypes.h"
namespace A
{
	namespace Pipeline
	{
		class AFilter : public tbb::filter{
		public:
			AFilter(bool isSerial, cv::Mat *img = NULL );
			virtual ~AFilter();
			void* operator()(void *parameters);
			virtual void* filterMain(void *parameters) = 0;
			void enable();
			cv::Mat* getDestinationImage(){return &m_dstImg;}
			void bindTo(AFilter &rfr){this->m_srcImg = rfr.m_dstImg;}

		protected:
			cv::Mat m_srcImg;
			cv::Mat m_dstImg;
			ABool	m_enabled;
		private:
		};
	}
}

#endif /* PIPELINE_AFILTER_H_ */

 

//AFilter.cpp !!!!!!!!!!!!

 

#include <Pipeline/AFilter.h>

using namespace A::Pipeline;

AFilter::AFilter(bool isSerial, cv::Mat *pImg) : filter(isSerial), /*m_srcImg(*pImg), m_dstImg(*pImg),/**/ m_enabled(true) {
	// TODO Auto-generated constructor stub

}

AFilter::~AFilter() {
	// TODO Auto-generated destructor stub
}

void * AFilter::operator ()(void * parameters)
{
	return filterMain(parameters);
}

 

//main.cpp!!!!!!!!!!!!!!!!!!!!!

 

/*
 * main.cpp
 *
 *  Created on: Nov 3, 2014
 *      Author: omerorkun
 */

#include "ATypes.h"
#include "Filters/AGrayScaleFilter.h"
#include "Filters/AReadImageFromFile.h"
#include "Pipeline/APipeLine.h"
#include "tbb/task_scheduler_init.h"

using namespace A::Pipeline;
using namespace tbb;

int main()
{

	task_scheduler_init init(task_scheduler_init::automatic);
	AReadImageFromFile rif(true);
	AGrayScaleFilter gsf(true);
	gsf.bindTo(rif);

	APipeline pipeline;

	pipeline.add_filter(rif);
	pipeline.add_filter(gsf);

	pipeline.run(100);
	return 0;
}

 

In my sample code I try to bind to filters with pointers. AReadImageFromFile reads image and AGrayScaleFilter convert it to gray scale and show. But it doesn't work. While debugging I saw that rif's (AReadImageFilter) m_dstImage has correct data but gsf's (AGrayScaleFilter) m_srcImage has dummy data. I will implement template connector class and I will bind its pointers between filters. To construct such an architechure how can i implement my classes.

0 Kudos
1 Reply
RafSchietekat
Black Belt
51 Views

"In my sample code I try to bind to filters with pointers."

That seems like a recipe for disaster. TBB will try to let both filters do work at the same time (that's the whole point of having a parallel pipeline), even if they're both serial filters (meaning only that each filter by itself can only do one thing at a time), so there's no obviously useful relation between their states. There's no reason to use instance variables to keep state to an individual data item, since its lifetime should be limited to the operator() call, and then you might as well use local variables instead, i.e., it's not necessarily a bug but you're walking on the edge of a cliff if you do use member state in a serial filter (don't even think about it in a parallel filter). Only use the operator() API to pass data, even if that means casting to and from void*.

Also consider using parallel_pipeline() instead, especially if you can rely on C++11.

Reply