Ejemplo n.º 1
0
void CvWindow_Sink::prepareInterface() {
	CLOG(LTRACE) << "CvWindow_Sink::configure\n";

	h_onRefresh.setup(this, &CvWindow_Sink::onRefresh);
	registerHandler("onRefresh", &h_onRefresh);

	addDependency("onRefresh", NULL);

	Base::EventHandler2 * hand;
	for (int i = 0; i < count; ++i) {
		char id = '0' + i;
		hand = new Base::EventHandler2;
		hand->setup(boost::bind(&CvWindow_Sink::onNewImageN, this, i));
		handlers.push_back(hand);
		registerHandler(std::string("onNewImage") + id, hand);

		Base::DataStreamIn<cv::Mat, Base::DataStreamBuffer::Newest,
				Base::Synchronization::Mutex> * stream =
				new Base::DataStreamIn<cv::Mat, Base::DataStreamBuffer::Newest,
						Base::Synchronization::Mutex>;
		in_img.push_back(stream);
		registerStream(std::string("in_img") + id,
				(Base::DataStreamInterface*) (in_img[i]));
		addDependency(std::string("onNewImage") + id, stream);

		in_draw.push_back(new Base::DataStreamInPtr<Types::Drawable>);
		registerStream(std::string("in_draw") + id, in_draw[i]);

		out_point.push_back(new Base::DataStreamOut<cv::Point>);
		registerStream(std::string("out_point") + id, out_point[i]);

		// save handlers
		hand = new Base::EventHandler2;
		hand->setup(boost::bind(&CvWindow_Sink::onSaveImageN, this, i));
		handlers.push_back(hand);
		registerHandler(std::string("onSaveImage") + id, hand);
	}

	h_onSaveAllImages.setup(this, &CvWindow_Sink::onSaveAllImages);
	registerHandler("onSaveAllImages", &h_onSaveAllImages);

	// register aliases for first handler and streams
	registerHandler("onNewImage", handlers[0]);
	registerStream("in_img", in_img[0]);
	registerStream("in_draw", in_draw[0]);

	img.resize(count);
	to_draw.resize(count);

	// Split window titles.
	std::string t = title;
	boost::split(titles, t, boost::is_any_of(","));
	if ((titles.size() == 1) && (count > 1))
		titles.clear();
	for (int i = titles.size(); i < count; ++i) {
		char id = '0' + i;
		titles.push_back(std::string(title) + id);
	}
}
Ejemplo n.º 2
0
void ImageWriter::prepareInterface() {
	CLOG(LTRACE) << name() << "::prepareInterface()";

	// Register handlers
	Base::EventHandler2 * hand;
	for (int i = 0; i < count; ++i) {
		char id = '0'+i;
		hand = new Base::EventHandler2;
		hand->setup(boost::bind(&ImageWriter::write_image_N, this, i));
		handlers.push_back(hand);
		registerHandler(std::string("write_image_")+id, hand);

		Base::DataStreamIn<cv::Mat, Base::DataStreamBuffer::Newest> * stream = new Base::DataStreamIn<cv::Mat, Base::DataStreamBuffer::Newest>;
		in_img.push_back(stream);
		registerStream( std::string("in_img")+id, (Base::DataStreamInterface*)(in_img[i]));
		addDependency(std::string("write_image_")+id, stream);

		// Add n flags for manual trigger.
		bool tmp_flag = false;
		save_flags.push_back(tmp_flag);
	}


	// register aliases for first handler and streams
	registerHandler("write_image", handlers[0]);
	registerStream("in_img", in_img[0]);

	counts.resize(count, 0);

	std::string t = base_name;
	boost::split(base_names, t, boost::is_any_of(","));
	if ( (base_names.size() == 1) && (count > 1) ) base_names.clear();
	for (int i = base_names.size(); i < count; ++i) {
		char id = '0' + i;
		base_names.push_back(std::string(base_name) + id);
	}

	std::string f = format;
	boost::split(formats, f, boost::is_any_of(","));
	if ( (formats.size() == 1) && (count > 1) ) formats.clear();
	for (int i = formats.size(); i < count; ++i) {
		formats.push_back(format);
	}

    // Register handlers - next image, can be triggered manually (from GUI) or by new data present in_load_next_image_trigger dataport.
    // 1st version - manually.
    registerHandler("SaveImage", boost::bind(&ImageWriter::onSaveButtonPressed, this));

    // 2nd version - external trigger.
    registerHandler("onSaveTriggered", boost::bind(&ImageWriter::onSaveTriggered, this));
    addDependency("onSaveTriggered", &in_trigger);

}
Ejemplo n.º 3
0
void MultiXYZCloudsViewer::prepareInterface() {
	LOG(LTRACE) << "MultiXYZCloudsViewer::prepareInterface";

	// Check colours.
	assert(((cv::Mat)clouds_colours).size[0] ==  count);
	assert(((cv::Mat)clouds_colours).size[1] ==  3);

	// Register data streams and event handlers depending on the number of clouds.
	Base::EventHandler2 * hand;
	for (int i = 0; i < count; ++i) {
		char id = '0' + i;
		
		// Create datastream for i-th cloud.
		Base::DataStreamIn<pcl::PointCloud<pcl::PointXYZ>::Ptr, Base::DataStreamBuffer::Newest,
				Base::Synchronization::Mutex> * stream =
				new Base::DataStreamIn<pcl::PointCloud<pcl::PointXYZ>::Ptr, Base::DataStreamBuffer::Newest,
						Base::Synchronization::Mutex>;
		in_clouds.push_back(stream);
		// Register i-th stream.
		registerStream(std::string("in_cloud_xyz") + id,
				(Base::DataStreamInterface*) (in_clouds[i]));

		// Create new handler for i-th cloud.
		hand = new Base::EventHandler2;
		hand->setup(boost::bind(&MultiXYZCloudsViewer::on_cloud_xyzN, this, i));
		handlers.push_back(hand);
		registerHandler(std::string("on_cloud_xyz") + id, hand);
		// Add dependency for i-th stream.
		addDependency(std::string("on_cloud_xyz") + id, stream);
	}

	// Register aliases for first handler and streams.
	registerStream("in_cloud_xyz", in_clouds[0]);
	registerHandler("on_cloud_xyz", handlers[0]);


	// Register spin handler.
	h_on_spin.setup(boost::bind(&MultiXYZCloudsViewer::on_spin, this));
	registerHandler("on_spin", &h_on_spin);
	addDependency("on_spin", NULL);
}