Develop and Download Open Source Software

Browse Subversion Repository

Contents of /rangesCtrl/RangesDrawSurface.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 315 - (show annotations) (download) (as text)
Fri Mar 28 20:04:23 2008 UTC (16 years ago) by satofumi
File MIME type: text/x-c++src
File size: 3532 byte(s)
adjust scripts
1 /*!
2 \file
3 \brief レンジセンサデータの描画コンポーネント
4
5 \author Satofumi KAMIMURA
6
7 $Id$
8
9 \todo 描画オフセットの角度の対応がおかしくないか、を確認する
10 \todo 背景色は透明にする
11 \todo いずれ、RangesDrawSurface.cpp にする
12 */
13
14 #include "RangesDrawSurface.h"
15 #include "RangeSensorInterface.h"
16 #include "ConvertToGrid.h"
17 #include "DrawPanelSurface.h"
18 #include "Component.h"
19 #include "GuiColors.h"
20 #include "SdlUtils.h"
21
22 using namespace beego;
23 using namespace SDL;
24
25
26 struct RangesDrawSurface::pImpl {
27 RangeSensorInterface& ranges;
28 size_t width;
29 size_t height;
30 bool is_changed;
31 std::vector<Grid<int> > points;
32 size_t data_max;
33 long* data_buffer;
34 unsigned long pre_timestamp;
35 boost::shared_ptr<DrawPanelSurface> draw_panel;
36 Position<int> draw_offset;
37 size_t pixels;
38
39 pImpl(RangeSensorInterface& range_sensor, size_t w, size_t h)
40 : ranges(range_sensor), width(w), height(h), is_changed(true),
41 pre_timestamp(0), draw_panel(new DrawPanelSurface(width, height)),
42 pixels(DefalutPixelMagnify) {
43
44 data_max = ranges.getMaxDataLength();
45 data_buffer = new long[data_max];
46
47 draw_panel->setNoBackground();
48 }
49
50 ~pImpl(void) {
51 delete [] data_buffer;
52 }
53
54 void drawCaptures(const SDL_Rect& position,
55 std::vector<Grid<int> >& points, unsigned long timestamp) {
56
57 draw_panel->clear();
58 int division = (pixels == 0) ? 1 : 1000 / static_cast<int>(pixels);
59 for (std::vector<Grid<int> >::iterator it = points.begin();
60 it != points.end(); ++it) {
61 Grid<int> draw_position;
62 set_Grid<int>(&draw_position,
63 position.x + width/2 + (it->x / division),
64 position.y + height/2 + (it->y / division));
65 draw_panel->drawPoint(draw_position, White);
66 }
67 }
68 };
69
70
71 RangesDrawSurface::RangesDrawSurface(RangeSensorInterface& ranges,
72 size_t width, size_t height)
73 : pimpl(new pImpl(ranges, width, height)) {
74 }
75
76
77 RangesDrawSurface::~RangesDrawSurface(void) {
78 }
79
80
81 void RangesDrawSurface::draw(std::vector<SDL_Rect>& update_rects,
82 const SDL_Rect* pos, const SDL_Rect* area,
83 size_t ticks) {
84
85 pimpl->drawCaptures(*pos, pimpl->points, pimpl->pre_timestamp);
86 pimpl->draw_panel->draw(update_rects, pos, area);
87 }
88
89
90 size_t RangesDrawSurface::getWidth(void) {
91 return pimpl->width;
92 }
93
94
95 size_t RangesDrawSurface::getHeight(void) {
96 return pimpl->height;
97 }
98
99
100 void RangesDrawSurface::forceSetChanged(void) {
101 pimpl->is_changed = true;
102 }
103
104 bool RangesDrawSurface::isChanged(void) {
105 bool ret = pimpl->is_changed;
106 pimpl->is_changed = false;
107 return ret;
108 }
109
110
111 bool RangesDrawSurface::isTransparent(void) {
112
113 // !!!
114 // !!! 将来的には、透過にもなりうるはず
115 return false;
116 }
117
118
119 void RangesDrawSurface::update(void) {
120
121 // データ取得と描画の更新を行う
122 int n = pimpl->ranges.capture(pimpl->data_buffer, pimpl->data_max);
123 if (n <= 0) {
124 return;
125 }
126 unsigned long timestamp = pimpl->ranges.getTimestamp();
127 if (pimpl->pre_timestamp != timestamp) {
128 pimpl->pre_timestamp = timestamp;
129
130 // データを2次元展開して描画
131 pimpl->points.clear();
132 convertToGrid(pimpl->points, pimpl->data_buffer, n,
133 &pimpl->ranges, pimpl->draw_offset);
134
135 pimpl->is_changed = true;
136 }
137 }
138
139
140 void RangesDrawSurface::setDrawOffset(const Position<int>& offset) {
141 pimpl->draw_offset = offset;
142 }
143
144
145 size_t RangesDrawSurface::setPixelMagnify(size_t pixels) {
146 pimpl->pixels = pixels;
147 return pimpl->pixels;
148 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26