source: flair-src/trunk/lib/FlairSensorActuator/src/Camera.cpp@ 122

Last change on this file since 122 was 122, checked in by Sanahuja Guillaume, 7 years ago

modifs uav vrpn i686

File size: 3.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: Camera.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Virtual class for Camera
14//
15//
16/*********************************************************************/
17
18#include "Camera.h"
19#include <FrameworkManager.h>
20#include <Tab.h>
21#include <TabWidget.h>
22#include <GroupBox.h>
23#include <GridLayout.h>
24#include <DataPlot1D.h>
25#include <Picture.h>
26#include <highgui.h>
27#include <fstream>
28
29using std::string;
30using namespace flair::core;
31using namespace flair::gui;
32
33namespace flair {
34namespace sensor {
35
36Camera::Camera(const FrameworkManager *parent, string name, uint16_t width,
37 uint16_t height, cvimage::Type::Format format)
38 : IODevice(parent, name) {
39 plot_tab = NULL;
40 logFormat=LogFormat::NONE;
41
42 // do not allocate imagedata, allocation is done by the camera
43 output = new cvimage((IODevice *)this, width, height, format, "out", false);
44
45 // station sol
46 main_tab = new Tab(parent->GetTabWidget(), name);
47 tab = new TabWidget(main_tab->NewRow(), name);
48 sensor_tab = new Tab(tab, "Setup");
49 setup_groupbox = new GroupBox(sensor_tab->NewRow(), name);
50 setup_layout = new GridLayout(sensor_tab->NewRow(), "setup");
51}
52
53//This contructor must only be called for a simulated device.
54Camera::Camera(const IODevice *parent, std::string name)
55 : IODevice(parent, name) {
56 plot_tab = NULL;
57 main_tab = NULL;
58 tab = NULL;
59 sensor_tab = NULL;
60 setup_groupbox = NULL;
61
62 output = NULL;
63 logFormat=LogFormat::NONE;
64}
65
66Camera::~Camera() {
67 if (main_tab != NULL)
68 delete main_tab;
69}
70
71void Camera::SetLogFormat(LogFormat logFormat) {
72 this->logFormat=logFormat;
73 switch(logFormat) {
74 case LogFormat::RAW:
75 AddDataToLog(output);
76 Warn("raw log of cvimage is not yet implemented\n");
77 break;
78 case LogFormat::JPG:
79 Warn("logging cvimage to jpeg\n");
80 Warn("jpeg are not included in classical dbt file, as dbt does not handle variable length\n");
81 break;
82 default:
83 Warn("LogFormat unknown\n");
84 }
85}
86
87DataType const &Camera::GetOutputDataType() const {
88 return output->GetDataType();
89}
90
91GroupBox *Camera::GetGroupBox(void) const { return setup_groupbox; }
92
93GridLayout *Camera::GetLayout(void) const { return setup_layout; }
94
95void Camera::UseDefaultPlot(const core::cvimage *image) {
96 if (tab == NULL) {
97 Err("not applicable for simulation part.\n");
98 return;
99 }
100
101 plot_tab = new Tab(tab, "Picture");
102 Picture *plot = new Picture(plot_tab->NewRow(), ObjectName(), image);
103}
104
105Tab *Camera::GetPlotTab(void) const { return plot_tab; }
106
107uint16_t Camera::Width(void) const { return output->GetDataType().GetWidth(); }
108
109uint16_t Camera::Height(void) const {
110 return output->GetDataType().GetHeight();
111}
112
113core::cvimage *Camera::Output(void) { return output; }
114
115void Camera::ProcessUpdate(core::io_data* data) {
116 if(getFrameworkManager()->IsLogging() && getFrameworkManager()->IsDeviceLogged(this)) {
117 switch(logFormat) {
118 case LogFormat::JPG:
119 IplImage *img=((cvimage*)data)->img;
120 //dspSaveToJpeg(img,"toto");
121 break;
122 }
123 }
124 IODevice::ProcessUpdate(data);
125}
126
127void Camera::SaveToFile(string filename) const {
128 Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
129 std::ofstream pFile;
130 pFile.open(filename);
131 output->GetMutex();
132 pFile.write(output->img->imageData, output->img->imageSize);
133 output->ReleaseMutex();
134
135 pFile.close();
136}
137
138} // end namespace sensor
139} // end namespace flair
Note: See TracBrowser for help on using the repository browser.