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

Last change on this file since 4 was 3, checked in by Sanahuja Guillaume, 6 years ago

sensoractuator

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