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

Last change on this file since 135 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 2.6 KB
Line 
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 <SpinBox.h>
21#include <GroupBox.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(const FrameworkManager *parent, string name,
35 uint16_t width, uint16_t height, uint8_t channels,
36 uint32_t dev_id, uint8_t priority)
37 : Thread(parent, name, priority),
38 Camera(parent, name, width, height, cvimage::Type::Format::BGR) {
39 data_rate =
40 new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 100, 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);
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);
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
76 while (!ToBeStopped()) {
77 WaitPeriod();
78
79 if (data_rate->ValueChanged() == true) {
80 SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
81 }
82
83 output->GetMutex();
84 shmem->Read((char *)img->imageData, buf_size); // remplacer copie par
85 // échange de pointeur sur
86 // double buffering
87 output->ReleaseMutex();
88
89 output->SetDataTime(GetTime());
90
91 ProcessUpdate(output);
92 }
93}
94
95} // end namespace sensor
96} // end namespace flair
Note: See TracBrowser for help on using the repository browser.