[3] | 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 |
|
---|
| 26 | using std::string;
|
---|
| 27 | using std::ostringstream;
|
---|
| 28 | using namespace flair::core;
|
---|
| 29 | using namespace flair::gui;
|
---|
| 30 |
|
---|
| 31 | namespace flair { namespace sensor {
|
---|
| 32 |
|
---|
| 33 | SimuCamera::SimuCamera(const FrameworkManager* parent,string name,uint16_t width,uint16_t height,uint8_t channels,uint32_t dev_id,uint8_t priority) :Thread(parent,name,priority),Camera(parent,name,width,height,cvimage::Type::Format::BGR) {
|
---|
| 34 | data_rate=new SpinBox(GetGroupBox()->NewRow(),"data rate"," Hz",1,100,1,50);
|
---|
| 35 |
|
---|
| 36 | buf_size=width*height*channels;
|
---|
| 37 |
|
---|
| 38 | img=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
|
---|
| 39 | output->img->imageData=img->imageData;
|
---|
| 40 |
|
---|
| 41 | ostringstream dev_name;
|
---|
| 42 | dev_name << "simu_cam_" << dev_id;
|
---|
| 43 | shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),buf_size);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | SimuCamera::SimuCamera(const IODevice* parent,string name,uint16_t width,uint16_t height,uint8_t channels,uint32_t dev_id) : Thread(parent,name,0),Camera(parent,name) {
|
---|
| 47 | data_rate=NULL;
|
---|
| 48 |
|
---|
| 49 | ostringstream dev_name;
|
---|
| 50 | dev_name << "simu_cam_" << dev_id;
|
---|
| 51 | shmem=new SharedMem((Thread*)this,dev_name.str().c_str(),width*height*channels);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | SimuCamera::~SimuCamera() {
|
---|
| 55 | SafeStop();
|
---|
| 56 | Join();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | void SimuCamera::Run(void) {
|
---|
| 60 | if(data_rate==NULL) {
|
---|
| 61 | Thread::Err("not applicable for simulation part.\n");
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
|
---|
| 66 |
|
---|
| 67 | while(!ToBeStopped()) {
|
---|
| 68 | WaitPeriod();
|
---|
| 69 |
|
---|
| 70 | if(data_rate->ValueChanged()==true) {
|
---|
| 71 | SetPeriodUS((uint32_t)(1000000./data_rate->Value()));
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | output->GetMutex();
|
---|
| 75 | shmem->Read((char*)img->imageData,buf_size); // remplacer copie par échange de pointeur sur double buffering
|
---|
| 76 | output->ReleaseMutex();
|
---|
| 77 |
|
---|
| 78 | output->SetDataTime(GetTime());
|
---|
| 79 |
|
---|
| 80 | ProcessUpdate(output);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | } // end namespace sensor
|
---|
| 85 | } // end namespace flair
|
---|