source: flair-src/branches/mavlink/lib/FlairSensorActuator/src/Camera.cpp @ 46

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

sources reformatted with flair-format-dir script

File size: 2.7 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
41  // do not allocate imagedata, allocation is done by the camera
42  output = new cvimage((IODevice *)this, width, height, format, "out", false);
43
44  // station sol
45  main_tab = new Tab(parent->GetTabWidget(), name);
46  tab = new TabWidget(main_tab->NewRow(), name);
47  sensor_tab = new Tab(tab, "Setup");
48  setup_groupbox = new GroupBox(sensor_tab->NewRow(), name);
49  setup_layout = new GridLayout(sensor_tab->NewRow(), "setup");
50}
51
52Camera::Camera(const IODevice *parent, std::string name)
53    : IODevice(parent, name) {
54  plot_tab = NULL;
55  main_tab = NULL;
56  tab = NULL;
57  sensor_tab = NULL;
58  setup_groupbox = NULL;
59
60  output = NULL;
61}
62
63Camera::~Camera() {
64  if (main_tab != NULL)
65    delete main_tab;
66}
67
68DataType const &Camera::GetOutputDataType() const {
69  return output->GetDataType();
70}
71
72GroupBox *Camera::GetGroupBox(void) const { return setup_groupbox; }
73
74GridLayout *Camera::GetLayout(void) const { return setup_layout; }
75
76void Camera::UseDefaultPlot(const core::cvimage *image) {
77  if (tab == NULL) {
78    Err("not applicable for simulation part.\n");
79    return;
80  }
81
82  plot_tab = new Tab(tab, "Picture");
83  Picture *plot = new Picture(plot_tab->NewRow(), ObjectName(), image);
84}
85
86Tab *Camera::GetPlotTab(void) const { return plot_tab; }
87
88uint16_t Camera::Width(void) const { return output->GetDataType().GetWidth(); }
89
90uint16_t Camera::Height(void) const {
91  return output->GetDataType().GetHeight();
92}
93
94core::cvimage *Camera::Output(void) { return output; }
95
96void Camera::SaveToFile(string filename) const {
97  Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
98  std::ofstream pFile;
99  pFile.open(filename);
100  output->GetMutex();
101  pFile.write(output->img->imageData, output->img->imageSize);
102  output->ReleaseMutex();
103
104  pFile.close();
105}
106
107} // end namespace sensor
108} // end namespace flair
Note: See TracBrowser for help on using the repository browser.