source: flair-src/trunk/lib/FlairSensorActuator/src/SimuCamera.cpp @ 150

Last change on this file since 150 was 150, checked in by Bayard Gildas, 5 years ago

SimuCamera? thread is now working at simulated camera frequency

File size: 2.7 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]4// %flair:license}
5//  created:    2014/03/06
6//  filename:   SimuCamera.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Class for a simulation camera
14//
15//
16/*********************************************************************/
17
18#include "SimuCamera.h"
19#include <FrameworkManager.h>
[137]20#include <GroupBox.h>
[3]21#include <SpinBox.h>
[137]22//#include <cvimage.h>
[3]23#include <SharedMem.h>
24#include <sstream>
25
26using std::string;
27using std::ostringstream;
28using namespace flair::core;
29using namespace flair::gui;
30
[15]31namespace flair {
32namespace sensor {
[3]33
[137]34SimuCamera::SimuCamera(string name,
[15]35                       uint16_t width, uint16_t height, uint8_t channels,
36                       uint32_t dev_id, uint8_t priority)
[137]37    : Thread(getFrameworkManager(), name, priority),
38      Camera(name, width, height, cvimage::Type::Format::BGR) {
[150]39//  data_rate =
40//      new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 200, 1, 50);
[3]41
[15]42  buf_size = width * height * channels;
[3]43
[15]44  img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
45  output->img->imageData = img->imageData;
[3]46
[15]47  ostringstream dev_name;
48  dev_name << "simu_cam_" << dev_id;
[150]49  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size, SharedMem::Type::producerConsumer);
[3]50}
51
[15]52SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width,
53                       uint16_t height, uint8_t channels, uint32_t dev_id)
[137]54    : Thread(parent, name, 0), Camera(parent,name) {
[150]55//  data_rate = NULL;
[3]56
[15]57  ostringstream dev_name;
58  dev_name << "simu_cam_" << dev_id;
59  shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
[150]60                        width * height * channels, SharedMem::Type::producerConsumer);
[3]61}
62
63SimuCamera::~SimuCamera() {
[15]64  SafeStop();
65  Join();
[3]66}
67
68void SimuCamera::Run(void) {
[150]69//  if (data_rate == NULL) {
70//    Thread::Err("not applicable for simulation part.\n");
71//    return;
72//  }
[3]73
[150]74//  SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
75  shmem->ReaderReady();
[3]76
[15]77  while (!ToBeStopped()) {
[150]78//    WaitPeriod();
[3]79
[150]80//    if (data_rate->ValueChanged() == true) {
81//      SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
82//    }
[3]83
[15]84    output->GetMutex();
[144]85    //blocking read
[15]86    shmem->Read((char *)img->imageData, buf_size); // remplacer copie par
87                                                   // échange de pointeur sur
88                                                   // double buffering
89    output->ReleaseMutex();
[3]90
[15]91    output->SetDataTime(GetTime());
[3]92
[15]93    ProcessUpdate(output);
94  }
[3]95}
96
97} // end namespace sensor
98} // end namespace flair
Note: See TracBrowser for help on using the repository browser.