close Warning: Can't use blame annotator:
svn blame failed on trunk/lib/FlairSensorActuator/src/SimuCamera.cpp: 200029 - Couldn't perform atomic initialization

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

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

SimuCamera thread is now working at simulated camera frequency

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