[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>
|
---|
| 20 | #include <SpinBox.h>
|
---|
| 21 | #include <GroupBox.h>
|
---|
| 22 | #include <cvimage.h>
|
---|
| 23 | #include <SharedMem.h>
|
---|
| 24 | #include <sstream>
|
---|
| 25 |
|
---|
| 26 | using std::string;
|
---|
| 27 | using std::ostringstream;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 | using namespace flair::gui;
|
---|
| 30 |
|
---|
[15] | 31 | namespace flair {
|
---|
| 32 | namespace sensor {
|
---|
[3] | 33 |
|
---|
[15] | 34 | SimuCamera::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);
|
---|
[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;
|
---|
| 49 | shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size);
|
---|
[3] | 50 | }
|
---|
| 51 |
|
---|
[15] | 52 | SimuCamera::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;
|
---|
[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(),
|
---|
| 60 | width * height * channels);
|
---|
[3] | 61 | }
|
---|
| 62 |
|
---|
| 63 | SimuCamera::~SimuCamera() {
|
---|
[15] | 64 | SafeStop();
|
---|
| 65 | Join();
|
---|
[3] | 66 | }
|
---|
| 67 |
|
---|
| 68 | void SimuCamera::Run(void) {
|
---|
[15] | 69 | if (data_rate == NULL) {
|
---|
| 70 | Thread::Err("not applicable for simulation part.\n");
|
---|
| 71 | return;
|
---|
| 72 | }
|
---|
[3] | 73 |
|
---|
[15] | 74 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
[3] | 75 |
|
---|
[15] | 76 | while (!ToBeStopped()) {
|
---|
| 77 | WaitPeriod();
|
---|
[3] | 78 |
|
---|
[15] | 79 | if (data_rate->ValueChanged() == true) {
|
---|
| 80 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
| 81 | }
|
---|
[3] | 82 |
|
---|
[15] | 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();
|
---|
[3] | 88 |
|
---|
[15] | 89 | output->SetDataTime(GetTime());
|
---|
[3] | 90 |
|
---|
[15] | 91 | ProcessUpdate(output);
|
---|
| 92 | }
|
---|
[3] | 93 | }
|
---|
| 94 |
|
---|
| 95 | } // end namespace sensor
|
---|
| 96 | } // end namespace flair
|
---|