source: pacpussensors/trunk/StdDbtPlayerComponents/DbtPlyStereoManager.cpp@ 132

Last change on this file since 132 was 50, checked in by phudelai, 10 years ago

Flea3Component: Shared memory changed for stereovision
StereoVisionDisparity: Added for the PFE of Pierre

File size: 4.4 KB
RevLine 
[16]1/// purpose: Dbite Player Stereo Manager implementation
2///
3/// created @date 2008/01/19 - 21:23
4/// @author Sergio Rodriguez
5/// @version $Id: $
6
7#include "DbtPlyStereoManager.h"
8
9#include <iostream>
10
[50]11#include "Pacpus/kernel/ComponentManager.h"
12#include "Pacpus/kernel/DbiteFileTypes.h"
13#include "Pacpus/kernel/Log.h"
[16]14
15namespace pacpus {
16
17using namespace std;
18
19DECLARE_STATIC_LOGGER("pacpus.base.DbtPlyStereoManager");
20
21/// Construction de la fabrique de composant DbtPlyStereoManager
22static ComponentFactory<DbtPlyStereoManager> sFactory("DbtPlyStereoManager");
23
24DbtPlyStereoManager::DbtPlyStereoManager(QString name)
25 : DbtPlyFileManager(name)
26{
27 firstTime = true;
28 tobeRead = NULL;
29
30 left0 = NULL;
31 right0 = NULL;
32 timeStamp0 = NULL;
33 timeRange0 = NULL;
34
35 left1 = NULL;
36 right1 = NULL;
37 timeStamp1 = NULL;
38 timeRange1 = NULL;
39}
40
41DbtPlyStereoManager::~DbtPlyStereoManager()
42{
43 delete tobeRead;
44 delete left0;
45 delete right0;
46 delete timeStamp0;
47 delete timeRange0;
48 delete left1;
49 delete right1;
50 delete timeStamp1;
51 delete timeRange1;
52}
53
54//processData unix
55void DbtPlyStereoManager::processData(road_time_t t, road_timerange_t tr, void * buf)
56{
57 if (!buf) {
58 return;
59 }
60
61 const size_t imageSize = width_ * height_ * depth_;
62
63 // look at the dbt index in file manager and get the identifier of dbt structure
64 hdfile_header_t::DataTypeT id = dbt_[dbtIndex_].pfile->getType();
65
66 if (firstTime) {
67 tobeRead = new ShMem("OFFSET", sizeof(bool)); //Offset pointer to read
68
69 left0 = new ShMem("BufferLeft0", imageSize);
70 right0 = new ShMem("BufferRight0", imageSize);
71 timeStamp0 = new ShMem("BufferTimeStamp0", sizeof(road_time_t));
72 timeRange0 = new ShMem("BufferTimeRange0", sizeof(road_timerange_t));
73
74 left1 = new ShMem("BufferLeft1", imageSize);
75 right1 = new ShMem("BufferRight1", imageSize);
76 timeStamp1 = new ShMem("BufferTimeStamp1", sizeof(road_time_t));
77 timeRange1 = new ShMem("BufferTimeRange1", sizeof(road_timerange_t));
78
79 firstTime = false;
80 leftStatus = false;
81 rightStatus = false;
82 offset = false;
83
84 if (tobeRead == NULL) {
85 LOG_FATAL("Crashing because of shared memory");
86 }
87 }
88
89 //dropping stereo images
90 switch (id) {
91 case STEREO_LEFT_IMAGE:
92 if (!offset)
93 left0->write(buf, imageSize);
94 else
95 left1->write(buf, imageSize);
96 leftStatus = true;
97 break;
98 case STEREO_RIGHT_IMAGE:
99 if (!offset)
100 right0->write(buf, imageSize);
101 else
102 right1->write(buf, imageSize);
103 rightStatus = true;
104 break;
105 default:
106 //Unkown id data type
107 break;
108 }
109
110 if ((leftStatus)&&(rightStatus)) { // synchronized stereo data is available
111 //dropping time stamp
112 if (!offset) {
113 timeStamp0->write(&t, sizeof(road_time_t));
114 timeRange0->write(&tr, sizeof(road_timerange_t));
115 } else {
116 timeStamp1->write(&t, sizeof(road_time_t));
117 timeRange1->write(&tr, sizeof(road_timerange_t));
118 }
119 if (mVerbose >= 1) {
120 cout << "[Shmem update Event] at " << t << std::endl;
121 }
122 //setting read flag
123 tobeRead->write((char*)&offset, sizeof(bool));
124 if (!offset)
125 offset = true;
126 else
127 offset =false;
128
129 leftStatus = false;
130 rightStatus = false;
131 }
132}
133
134ComponentBase::COMPONENT_CONFIGURATION DbtPlyStereoManager::configureComponent(XmlComponentConfig config)
135{
136 //default stereo image parameters
137 width_ = 320; // pixels
138 height_ = 240; // pixels
139 depth_ = 1; // bytes-per-pixel
140
141 //load stereo image parameters
[50]142 width_ = config.getProperty("width").toInt();
143 height_ = config.getProperty("height").toInt();
144 depth_ = config.getProperty("depth").toInt();
[16]145
146 return DbtPlyFileManager::configureComponent(config);
147}
148
149void DbtPlyStereoManager::startActivity()
150{
151 DbtPlyFileManager::startActivity();
152}
153
154void DbtPlyStereoManager::stopActivity()
155{
156 DbtPlyFileManager::stopActivity();
157}
158
159void DbtPlyStereoManager::displayUI()
160{
161 // TODO: not implemented
162}
163
164void DbtPlyStereoManager::tic()
165{
166 tic_ = road_time();
167}
168
169void DbtPlyStereoManager::toc(char * text)
170{
171 cout << "duration = " << (int)(road_time() - tic_) << " " << text << "\n";
172}
173
174} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.