• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1829 (tree)
日時2010-05-20 13:48:55
作者satofumi

ログメッセージ

added csv file handling for ScipPlayer

変更サマリ

差分

--- trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1828)
+++ trunk/widgets/UrgDrawWidget/UrgDrawWidget.cpp (revision 1829)
@@ -403,7 +403,7 @@
403403 void UrgDrawWidget::clear(void)
404404 {
405405 pimpl->draw_data_.clear();
406- redraw();
406+ //redraw();
407407 }
408408
409409
--- trunk/libs/gui/Canvas.cpp (revision 1828)
+++ trunk/libs/gui/Canvas.cpp (revision 1829)
@@ -29,6 +29,7 @@
2929 GLenum mode;
3030 size_t size;
3131 GLfloat line_width;
32+ //vector<GLfloat> intertwined;
3233 } draw_t;
3334
3435 typedef vector<draw_t> Draws;
@@ -38,25 +39,30 @@
3839 {
3940 Rect<long> rect_;
4041 float alpha_;
41- Color clear_color_;
4242 Color draw_color_;
4343 GLfloat line_width_;
4444 Font* font_;
4545 vector<draw_t> draws_;
46- vector<GLubyte> indices_;
47- GLuint indices_buffer_;
46+ draw_t clear_draw_;
4847
4948
5049 pImpl(const Rect<long>& rect)
51- : rect_(rect), alpha_(1.0),
52- clear_color_(Color(0.0, 0.0, 0.0, 1.0)),
53- draw_color_(Color(1.0, 1.0, 1.0, 1.0)),
54- line_width_(1.0f), font_(NULL), indices_buffer_(createBuffer())
50+ : rect_(rect), alpha_(1.0), draw_color_(Color(1.0, 1.0, 1.0, 1.0)),
51+ line_width_(1.0f), font_(NULL)
5552 {
5653 clearBuffers();
54+ setClearColor(Color(0.0f, 0.0f, 0.0f));
5755 }
5856
5957
58+ ~pImpl(void)
59+ {
60+ clearBuffers();
61+
62+ // !!! clear_draw_ のリソースを解放する
63+ }
64+
65+
6066 GLuint createBuffer(void)
6167 {
6268 GLuint id;
@@ -72,11 +78,10 @@
7278 glDeleteBuffers(1, &it->buffer);
7379 }
7480 draws_.clear();
75- indices_.clear();
7681 }
7782
7883
79- void setColor(vector<GLfloat>& intertwined)
84+ void registerColor(vector<GLfloat>& intertwined)
8085 {
8186 intertwined.push_back(draw_color_.r);
8287 intertwined.push_back(draw_color_.g);
@@ -84,41 +89,96 @@
8489 }
8590
8691
87- void expandIndices(size_t n)
92+ void setClearColor(const Color& color)
8893 {
89- if (n < indices_.size()) {
90- return;
94+ vector<Point<long> > points;
95+ points.push_back(Point<long>(0, 0));
96+ points.push_back(Point<long>(0, rect_.h));
97+ points.push_back(Point<long>(rect_.w, 0));
98+ points.push_back(Point<long>(rect_.w, rect_.h));
99+
100+ // クリア用の矩形を作成する
101+ Color stored_color = draw_color_;
102+ draw_color_ = color;
103+ registerPrimitive(clear_draw_, points, GL_QUAD_STRIP);
104+ draw_color_ = stored_color;
105+ }
106+
107+
108+ void registerPrimitive(draw_t& draw,
109+ const vector<Point<long> >& points, GLenum mode)
110+ {
111+ draw.mode = mode;
112+ draw.line_width = line_width_;
113+ draw.buffer = createBuffer();
114+ draw.size = points.size();
115+
116+ vector<GLfloat> intertwined;
117+ for (vector<Point<long> >::const_iterator it = points.begin();
118+ it != points.end(); ++it) {
119+ registerColor(intertwined);
120+ intertwined.push_back(it->x);
121+ intertwined.push_back(it->y);
122+ intertwined.push_back(0.0f);
91123 }
92- assert(n <= 255);
93124
94- for (size_t i = indices_.size(); i < n; ++i) {
95- indices_.push_back(i);
96- }
125+ glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
126+ size_t array_size =
127+ intertwined.size() * sizeof(intertwined[0]);
128+ glBufferData(GL_ARRAY_BUFFER, array_size,
129+ &intertwined[0], GL_STATIC_DRAW);
130+
131+ glBindBuffer(GL_ARRAY_BUFFER, 0);
97132 }
98133
134+
135+ void drawLineStrip(const vector<Point<long> >& points)
136+ {
137+ draw_t draw;
138+ registerPrimitive(draw, points, GL_LINE_STRIP);
139+ draws_.push_back(draw);
140+ }
141+
142+
143+ void drawQuadsStrip(const vector<Point<long> >& points)
144+ {
145+ draw_t draw;
146+ registerPrimitive(draw, points, GL_QUAD_STRIP);
147+ draws_.push_back(draw);
148+ }
149+
150+
151+ void drawPrimitive(const draw_t& draw)
152+ {
153+ glLineWidth(draw.line_width);
154+ glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
155+ glInterleavedArrays(GL_C3F_V3F, 0, NULL);
156+ glDrawArrays(draw.mode, 0, draw.size);
157+ glBindBuffer(GL_ARRAY_BUFFER, 0);
158+ }
159+
160+
99161 void draw(const Rect<long>* src, const Rect<long>* dest)
100162 {
163+ // !!! 指定されている描画範囲でクリッピングする
101164 (void)src;
102165 (void)dest;
103166
167+ // !!! 位置にオフセットを加えて描画する
168+
104169 // !!!
105170
106171 glEnableClientState(GL_VERTEX_ARRAY);
172+ glEnableClientState(GL_COLOR_ARRAY);
107173
174+ drawPrimitive(clear_draw_);
175+
108176 for (Draws::const_iterator it = draws_.begin();
109177 it != draws_.end(); ++it) {
110-
111- glLineWidth(it->line_width);
112- glBindBuffer(GL_ARRAY_BUFFER, it->buffer);
113-
114- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_);
115- glBufferData(GL_ELEMENT_ARRAY_BUFFER,
116- it->size * sizeof(indices_[0]),
117- &indices_[0], GL_STATIC_DRAW);
118-
119- glDrawElements(it->mode, it->size, GL_UNSIGNED_BYTE, NULL);
178+ drawPrimitive(*it);
120179 }
121180
181+ glDisableClientState(GL_COLOR_ARRAY);
122182 glDisableClientState(GL_VERTEX_ARRAY);
123183 }
124184 };
@@ -179,7 +239,7 @@
179239
180240 void Canvas::setClearColor(const qrk::Color& color)
181241 {
182- pimpl->clear_color_ = color;
242+ pimpl->setClearColor(color);
183243 }
184244
185245
@@ -201,34 +261,13 @@
201261 }
202262
203263
204-void Canvas::drawLines(const std::vector<qrk::Point<long> >& points)
264+void Canvas::drawLineStrip(const std::vector<qrk::Point<long> >& points)
205265 {
206266 if (points.empty()) {
207267 return;
208268 }
209269
210- draw_t draw;
211- draw.mode = GL_LINE_STRIP;
212- draw.line_width = pimpl->line_width_;
213- draw.buffer = pimpl->createBuffer();
214- draw.size = points.size();
215-
216- vector<GLfloat> intertwined;
217- for (vector<Point<long> >::const_iterator it = points.begin();
218- it != points.end(); ++it) {
219- pimpl->setColor(intertwined);
220- intertwined.push_back(it->x);
221- intertwined.push_back(it->y);
222- intertwined.push_back(0.0f);
223- }
224- pimpl->expandIndices(draw.size);
225-
226- glBindBuffer(GL_ARRAY_BUFFER, draw.buffer);
227- size_t array_size = intertwined.size() * sizeof(intertwined[0]);
228- glBufferData(GL_ARRAY_BUFFER, array_size, &intertwined[0], GL_STATIC_DRAW);
229- glInterleavedArrays(GL_C3F_V3F, 0, NULL);
230-
231- pimpl->draws_.push_back(draw);
270+ pimpl->drawLineStrip(points);
232271 }
233272
234273
@@ -240,12 +279,13 @@
240279 }
241280
242281
243-void Canvas::drawPolygons(const std::vector<qrk::Point<long> >& points)
282+void Canvas::drawQuadStrip(const std::vector<qrk::Point<long> >& points)
244283 {
245- (void)points;
246- // !!!
284+ if (points.empty()) {
285+ return;
286+ }
247287
248- // !!! GL_QUADS
288+ pimpl->drawQuadsStrip(points);
249289 }
250290
251291
--- trunk/libs/gui/Canvas.h (revision 1828)
+++ trunk/libs/gui/Canvas.h (revision 1829)
@@ -42,9 +42,9 @@
4242 void setColor(const qrk::Color& color);
4343 void setLineWidth(float width);
4444
45- void drawLines(const std::vector<qrk::Point<long> >& points);
45+ void drawLineStrip(const std::vector<qrk::Point<long> >& points);
4646 void drawCircle(const qrk::Point<long>& center, float radius);
47- void drawPolygons(const std::vector<qrk::Point<long> >& points);
47+ void drawQuadStrip(const std::vector<qrk::Point<long> >& points);
4848 void drawText(const char* text, const Point<long>& position);
4949
5050 private:
--- trunk/libs/gui/samples/canvasDraw.cpp (revision 1828)
+++ trunk/libs/gui/samples/canvasDraw.cpp (revision 1829)
@@ -29,16 +29,29 @@
2929 screen.clear();
3030 Rect<long> dest_rect = canvas.rect();
3131
32+ canvas.setClearColor(Color(0.5, 0.5, 0.5));
3233 canvas.setColor(Color(0.0, 0.0, 1.0));
33- canvas.setLineWidth(4.0);
3434
35+ canvas.setLineWidth(1.0);
3536 vector<Point<long> > points;
36- points.push_back(Point<long>(0, 1));
37+ points.push_back(Point<long>(30, 1));
3738 points.push_back(Point<long>(50, 1));
3839 points.push_back(Point<long>(50, 100));
40+ points.push_back(Point<long>(70, 100));
41+ canvas.drawLineStrip(points);
42+
43+ canvas.setLineWidth(2.0);
44+ points.clear();
45+ points.push_back(Point<long>(0, 0));
3946 points.push_back(Point<long>(100, 100));
40- canvas.drawLines(points);
47+ canvas.drawLineStrip(points);
4148
49+ canvas.setLineWidth(4.0);
50+ points.clear();
51+ points.push_back(Point<long>(100, 0));
52+ points.push_back(Point<long>(0, 100));
53+ canvas.drawLineStrip(points);
54+
4255 canvas.draw(NULL, &dest_rect);
4356
4457 SDL_GL_SwapBuffers();
--- trunk/programs/ScipPlayer/ScipDataReader.h (revision 1828)
+++ trunk/programs/ScipPlayer/ScipDataReader.h (revision 1829)
@@ -20,18 +20,18 @@
2020 */
2121 class ScipDataReader
2222 {
23- ScipDataReader(const ScipDataReader& rhs);
24- ScipDataReader& operator = (const ScipDataReader& rhs);
23+ ScipDataReader(const ScipDataReader& rhs);
24+ ScipDataReader& operator = (const ScipDataReader& rhs);
2525
26- struct pImpl;
27- std::auto_ptr<pImpl> pimpl;
26+ struct pImpl;
27+ std::auto_ptr<pImpl> pimpl;
2828
2929 public:
30- ScipDataReader(const std::string& log_file);
31- ~ScipDataReader(void);
30+ ScipDataReader(const std::string& log_file);
31+ ~ScipDataReader(void);
3232
33- bool isEmpty(void);
34- bool readReplyLines(std::vector<std::string>& line_block);
33+ bool isEmpty(void);
34+ bool readReplyLines(std::vector<std::string>& line_block);
3535 };
3636
3737 #endif /* !SCIP_DATA_READER_H */
--- trunk/programs/ScipPlayer/ScipPlayerWindow.cpp (revision 1828)
+++ trunk/programs/ScipPlayer/ScipPlayerWindow.cpp (revision 1829)
@@ -31,360 +31,469 @@
3131
3232 namespace
3333 {
34- const char* Organization = "Hokuyo LTD.";
35- const char* Application = "Scip Player";
34+ const char* Organization = "Hokuyo LTD.";
35+ const char* Application = "Scip Player";
3636
37- typedef vector<string> ScipData;
37+ typedef vector<string> ScipData;
3838 }
3939
4040
4141 struct ScipPlayerWindow::pImpl
4242 {
43- ScipPlayerWindow* widget_;
44- UrgDrawWidget urg_draw_widget_;
45- ScipDataReader* data_reader_;
43+ ScipPlayerWindow* widget_;
44+ UrgDrawWidget urg_draw_widget_;
45+ ScipDataReader* data_reader_;
4646
47- ScipData scip_data_;
48- long current_timestamp_;
49- long last_timestamp_;
47+ ScipData scip_data_;
48+ long current_timestamp_;
49+ long last_timestamp_;
5050
51- CustomConnection con_;
52- UrgDevice urg_;
51+ CustomConnection con_;
52+ UrgDevice urg_;
5353
54- QTimer continuous_timer_;
55- int play_ratio_;
56- bool led_on_;
54+ QTimer continuous_timer_;
55+ int play_ratio_;
56+ bool led_on_;
5757
58- pImpl(ScipPlayerWindow* parent)
59- : widget_(parent), data_reader_(NULL),
60- current_timestamp_(0), last_timestamp_(0),
61- play_ratio_(0), led_on_(false)
62- {
63- urg_.setConnection(&con_);
64- continuous_timer_.setSingleShot(true);
65- urg_draw_widget_.setDrawPeriod(1);
66- }
58+ QStringList csv_files_;
59+ QString csv_files_dir_;
60+ bool csv_mode_;
61+ int csv_index_;
6762
6863
69- ~pImpl(void)
70- {
71- delete data_reader_;
72- }
64+ pImpl(ScipPlayerWindow* parent)
65+ : widget_(parent), data_reader_(NULL),
66+ current_timestamp_(0), last_timestamp_(0),
67+ play_ratio_(0), led_on_(false), csv_mode_(false), csv_index_(0)
68+ {
69+ urg_.setConnection(&con_);
70+ continuous_timer_.setSingleShot(true);
71+ urg_draw_widget_.setDrawPeriod(1);
72+ }
7373
7474
75- void initializeForm(void)
76- {
77- // 表示ウィジット
78- widget_->dummy_label_->hide();
79- widget_->main_layout_->addWidget(&urg_draw_widget_);
75+ ~pImpl(void)
76+ {
77+ delete data_reader_;
78+ }
8079
81- widget_->path_edit_->setAcceptDrops(false);
82- widget_->setAcceptDrops(true);
8380
84- // イベント
85- connect(widget_->path_button_, SIGNAL(clicked()),
86- widget_, SLOT(pathPressed()));
87- connect(widget_->reload_button_, SIGNAL(clicked()),
88- widget_, SLOT(reloadPressed()));
89- connect(widget_->next_button_, SIGNAL(clicked()),
90- widget_, SLOT(nextPressed()));
91- connect(widget_->continuous_button_, SIGNAL(clicked()),
92- widget_, SLOT(continuousPressed()));
93- connect(&continuous_timer_, SIGNAL(timeout()),
94- widget_, SLOT(timerTimeout()));
81+ void initializeForm(void)
82+ {
83+ // 表示ウィジット
84+ widget_->dummy_label_->hide();
85+ widget_->main_layout_->addWidget(&urg_draw_widget_);
9586
96- // メニュー
97- connect(widget_->action_about_, SIGNAL(triggered()),
98- widget_, SLOT(aboutApplication()));
99- connect(widget_->action_quit_, SIGNAL(triggered()),
100- widget_, SLOT(close()));
87+ widget_->path_edit_->setAcceptDrops(false);
88+ widget_->setAcceptDrops(true);
10189
102- // ショートカット
103- (void) new QShortcut(Qt::Key_Return, widget_, SLOT(initializeView()));
104- (void) new QShortcut(Qt::Key_F5, widget_, SLOT(reloadPressed()));
105- (void) new QShortcut(Qt::Key_Less, widget_, SLOT(zoomSmaller()));
106- (void) new QShortcut(Qt::Key_Comma, widget_, SLOT(zoomSmaller()));
107- (void) new QShortcut(Qt::Key_Greater, widget_, SLOT(zoomLarger()));
108- (void) new QShortcut(Qt::Key_Period, widget_, SLOT(zoomLarger()));
109- }
90+ // イベント
91+ connect(widget_->path_button_, SIGNAL(clicked()),
92+ widget_, SLOT(pathPressed()));
93+ connect(widget_->reload_button_, SIGNAL(clicked()),
94+ widget_, SLOT(reloadPressed()));
95+ connect(widget_->next_button_, SIGNAL(clicked()),
96+ widget_, SLOT(nextPressed()));
97+ connect(widget_->continuous_button_, SIGNAL(clicked()),
98+ widget_, SLOT(continuousPressed()));
99+ connect(&continuous_timer_, SIGNAL(timeout()),
100+ widget_, SLOT(timerTimeout()));
110101
102+ // メニュー
103+ connect(widget_->action_about_, SIGNAL(triggered()),
104+ widget_, SLOT(aboutApplication()));
105+ connect(widget_->action_quit_, SIGNAL(triggered()),
106+ widget_, SLOT(close()));
111107
112- void saveSettings(void)
113- {
114- QSettings settings(Organization, Application);
108+ // ショートカット
109+ (void) new QShortcut(Qt::Key_Return, widget_, SLOT(initializeView()));
110+ (void) new QShortcut(Qt::Key_F5, widget_, SLOT(reloadPressed()));
111+ (void) new QShortcut(Qt::Key_Less, widget_, SLOT(zoomSmaller()));
112+ (void) new QShortcut(Qt::Key_Comma, widget_, SLOT(zoomSmaller()));
113+ (void) new QShortcut(Qt::Key_Greater, widget_, SLOT(zoomLarger()));
114+ (void) new QShortcut(Qt::Key_Period, widget_, SLOT(zoomLarger()));
115+ }
115116
116- settings.setValue("geometry", widget_->saveGeometry());
117- settings.setValue("file_path", widget_->path_edit_->text());
118- }
119117
118+ void saveSettings(void)
119+ {
120+ QSettings settings(Organization, Application);
120121
121- void loadSettings(void)
122- {
123- QSettings settings(Organization, Application);
122+ settings.setValue("geometry", widget_->saveGeometry());
123+ settings.setValue("file_path", widget_->path_edit_->text());
124+ }
124125
125- widget_->restoreGeometry(settings.value("geometry").toByteArray());
126- QString log_file = settings.value("file_path", "").toString();
127- widget_->path_edit_->setText(log_file);
128- }
129126
127+ void loadSettings(void)
128+ {
129+ QSettings settings(Organization, Application);
130130
131- void reload(void)
132- {
133- // !!! この初期化処理は、適切にまとめるべき
134- continuous_timer_.stop();
135- delete data_reader_;
136- data_reader_ = NULL;
137- scip_data_.clear();
138- con_.clear();
139- urg_draw_widget_.clear();
140- current_timestamp_ = 0;
141- play_ratio_ = 0;
142- led_on_ = false;
131+ widget_->restoreGeometry(settings.value("geometry").toByteArray());
132+ QString log_file = settings.value("file_path", "").toString();
133+ widget_->path_edit_->setText(log_file);
134+ }
143135
144- QString log_file = widget_->path_edit_->text();
145- string std_log_file = qrk::toStdStringPath(log_file);
146- data_reader_ = new ScipDataReader(std_log_file);
147136
148- prepareUrgReply();
149- // !!! 接続に失敗したら、ファイルフォーマットが無効、という表示をすべき
150- if (! urg_.connect("dummy")) {
151- fprintf(stderr, "UrgDevice::connect: %s\n", urg_.what());
152- }
137+ void reload(void)
138+ {
139+ // !!! この初期化処理は、適切にまとめるべき
140+ continuous_timer_.stop();
141+ delete data_reader_;
142+ data_reader_ = NULL;
143+ scip_data_.clear();
144+ con_.clear();
145+ urg_draw_widget_.clear();
146+ current_timestamp_ = 0;
147+ play_ratio_ = 0;
148+ led_on_ = false;
153149
154- // 最初の描画、次データの取得、と2回のデータ更新を行う
155- for (int i = 0; i < 2; ++i) {
156- while ((! data_reader_->isEmpty()) && (! updateDrawData())) {
157- ;
158- }
150+ QString log_file = widget_->path_edit_->text();
151+
152+ QFileInfo file_info(log_file);
153+ QString suffix = file_info.suffix().toLower();
154+ csv_mode_ = (! suffix.compare("csv")) ? true : false;
155+ if (csv_mode_) {
156+ // 拡張子が CSV だったら、専用のモードでファイルを処理する
157+ handleCsvFile(log_file);
158+
159+ } else {
160+ handleRawFile(log_file);
161+ }
159162 }
160- }
161163
162164
163- void prepareUrgReply(void)
164- {
165- con_.clear();
166- con_.setReadData("QT\r00P\r\r");
165+ void handleRawFile(const QString& log_file)
166+ {
167+ string std_log_file = qrk::toStdStringPath(log_file);
168+ data_reader_ = new ScipDataReader(std_log_file);
167169
168- // ダミーデータ
169- con_.setReadData("PP\r"
170- "00P\r"
171- "MODL:URG-04LX(Hokuyo Automatic Co.,Ltd.);N\r"
172- "DMIN:20;4\r"
173- "DMAX:5600;_\r"
174- "ARES:1024;\r"
175- "AMIN:44;7\r"
176- "AMAX:725;o\r"
177- "AFRT:384;6\r"
178- "SCAN:600;e\r"
179- "\r");
180- }
170+ prepareUrgReply();
171+ // !!! 接続に失敗したら、ファイルフォーマットが無効、という表示をすべき
172+ if (! urg_.connect("dummy")) {
173+ fprintf(stderr, "UrgDevice::connect: %s\n", urg_.what());
174+ }
181175
176+ // 最初の描画、次データの取得、と2回のデータ更新を行う
177+ for (int i = 0; i < 2; ++i) {
178+ while ((! data_reader_->isEmpty()) && (! updateDrawData())) {
179+ ;
180+ }
181+ }
182+ }
182183
183- bool updateDrawData(void)
184- {
185- if (! scip_data_.empty()) {
186- // 保持しているデータを描画
187- current_timestamp_ = timestamp(scip_data_);
188- setScipData(scip_data_);
189- urg_draw_widget_.setUrgData(&urg_);
190- urg_draw_widget_.redraw();
191- scip_data_.clear();
192184
193- QString message = QString("timestamp: %1 [msec] (%2)")
194- .arg(current_timestamp_).arg(current_timestamp_ - last_timestamp_);
195- widget_->statusBar()->showMessage(message, 60 * 1000);
196- last_timestamp_ = current_timestamp_;
185+ void handleCsvFile(const QString& file_name)
186+ {
187+ // ディレクトリ中の CSV ファイルを、名前順に読み出す
188+ QFileInfo file_info(file_name);
189+ QDir dir = file_info.dir();
190+ csv_files_dir_ = file_info.absolutePath();
191+ QStringList filters;
192+ filters << "*.csv" << "*.CSV";
193+ dir.setNameFilters(filters);
194+ csv_files_ =
195+ dir.entryList(QDir::Files | QDir::NoSymLinks |
196+ QDir::NoDotAndDotDot | QDir::Readable, QDir::Name);
197+
198+ // 初期化
199+ csv_index_ = 0;
200+ current_timestamp_ = 0;
201+#if 0
202+ size_t n = csv_files_.size();
203+ for (size_t i = 0; i < n; ++i) {
204+ cout << csv_files_[i].toStdString() << endl;
205+ }
206+#endif
197207 }
198208
199- ScipData line_block;
200- while (data_reader_->readReplyLines(line_block)) {
201209
202- string& first_line = line_block[0];
203- if (! first_line.compare(0, 2, "BM")) {
204- con_.setReadData("BM\r00P\r\r");
210+ bool updateCsvFile(void)
211+ {
212+ if (csv_index_ >= csv_files_.size()) {
213+ return false;
214+ }
205215
206- } else if (! first_line.compare(0, 2, "PP")) {
207- // パラメータ読み出し
208- setScipData(line_block);
209- urg_.loadParameter();
216+ // !!!
217+ //cout << csv_files_[csv_index_].toStdString() << endl;
210218
211- } else if (! first_line.compare(0, 1, "G")) {
212- // Gx データの読み出し
213- swap(scip_data_, line_block);
214- setPlayEnabled(true);
219+ // CSV データを配置する
220+ QFile file(csv_files_dir_ + "/" + csv_files_[csv_index_]);
221+ //cout << csv_files_dir_.toStdString() << "/" << csv_files_[csv_index_].toStdString() << endl;
222+ file.open(QIODevice::ReadOnly | QIODevice::Text);
223+ // !!! エラー処理をすべき
224+
225+ vector<Point<long> > points;
226+ while (! file.atEnd()) {
227+ QByteArray line = file.readLine();
228+ setLine(points, line);
229+ }
230+
231+ urg_draw_widget_.clear();
232+ urg_draw_widget_.setUrgData(points, 0);
233+ urg_draw_widget_.redraw();
234+
235+ ++csv_index_;
215236 return true;
237+ }
216238
217- } else if (! first_line.compare(0, 1, "M")) {
218239
219- if (line_block.size() <= 2) {
220- // MD を RawManualCapture で無理矢理に再生させるための処理
221- // !!! 重複をどうにかする
222- if (! led_on_) {
223- con_.setReadData("BM\r00P\r\r");
224- led_on_ = true;
225- }
240+ void setLine(vector<Point<long> >& points, const QByteArray& line)
241+ {
242+ QList<QByteArray> tokens = line.split(',');
243+ if (tokens.size() < 5) {
244+ // トークンが不足していたら戻る
245+ return;
246+ }
226247
248+ // !!! Top-URG の場合は 23 なのを考慮すべき
249+ if (atoi(tokens[1]) < 20) {
250+ // 距離データがエラー値の場合は戻る
251+ return;
252+ }
253+ long x = atoi(tokens[3]);
254+ long y = atoi(tokens[4]);
255+ points.push_back(Point<long>(-y, x));
256+ }
257+
258+
259+ void prepareUrgReply(void)
260+ {
261+ con_.clear();
262+ con_.setReadData("QT\r00P\r\r");
263+
264+ // ダミーデータ
265+ con_.setReadData("PP\r"
266+ "00P\r"
267+ "MODL:URG-04LX(Hokuyo Automatic Co.,Ltd.);N\r"
268+ "DMIN:20;4\r"
269+ "DMAX:5600;_\r"
270+ "ARES:1024;\r"
271+ "AMIN:44;7\r"
272+ "AMAX:725;o\r"
273+ "AFRT:384;6\r"
274+ "SCAN:600;e\r"
275+ "\r");
276+ }
277+
278+
279+ bool updateDrawData(void)
280+ {
281+
282+ if (csv_mode_) {
283+ return updateCsvFile();
227284 } else {
228- // Mx データの読み出し
229- // !!! 重複をどうにかする
230- swap(scip_data_, line_block);
231- setPlayEnabled(true);
232- return true;
285+ return updateRawDraw();
233286 }
234- }
235287 }
236288
237- setPlayEnabled(false);
238- return false;
239- }
240289
241290
242- void setPlayEnabled(bool enable)
243- {
244- widget_->next_button_->setEnabled(enable);
245- widget_->continuous_button_->setEnabled(enable);
246- }
291+ bool updateRawDraw(void)
292+ {
293+ if (! scip_data_.empty()) {
294+ // 保持しているデータを描画
295+ current_timestamp_ = timestamp(scip_data_);
296+ setScipData(scip_data_);
297+ urg_draw_widget_.setUrgData(&urg_);
298+ urg_draw_widget_.redraw();
299+ scip_data_.clear();
247300
301+ QString message = QString("timestamp: %1 [msec] (%2)")
302+ .arg(current_timestamp_)
303+ .arg(current_timestamp_ - last_timestamp_);
304+ widget_->statusBar()->showMessage(message, 60 * 1000);
305+ last_timestamp_ = current_timestamp_;
306+ }
248307
249- void setScipData(const ScipData& line_block)
250- {
251- for (ScipData::const_iterator it = line_block.begin();
252- it != line_block.end(); ++it) {
253- con_.setReadData(*it + "\r");
308+ ScipData line_block;
309+ while (data_reader_->readReplyLines(line_block)) {
310+
311+ string& first_line = line_block[0];
312+ if (! first_line.compare(0, 2, "BM")) {
313+ con_.setReadData("BM\r00P\r\r");
314+
315+ } else if (! first_line.compare(0, 2, "PP")) {
316+ // パラメータ読み出し
317+ setScipData(line_block);
318+ urg_.loadParameter();
319+
320+ } else if (! first_line.compare(0, 1, "G")) {
321+ // Gx データの読み出し
322+ swap(scip_data_, line_block);
323+ setPlayEnabled(true);
324+ return true;
325+
326+ } else if (! first_line.compare(0, 1, "M")) {
327+
328+ if (line_block.size() <= 2) {
329+ // MD を RawManualCapture で無理矢理に再生させるための処理
330+ // !!! 重複をどうにかする
331+ if (! led_on_) {
332+ con_.setReadData("BM\r00P\r\r");
333+ led_on_ = true;
334+ }
335+
336+ } else {
337+ // Mx データの読み出し
338+ // !!! 重複をどうにかする
339+ swap(scip_data_, line_block);
340+ setPlayEnabled(true);
341+ return true;
342+ }
343+ }
344+ }
345+
346+ setPlayEnabled(false);
347+ return false;
254348 }
255- }
256349
257350
258- void continuousPlay(void)
259- {
260- if (updateDrawData()) {
261- long delay = timestamp(scip_data_) - current_timestamp_;
262- if (play_ratio_ > 0) {
263- delay /= play_ratio_;
264- }
265- continuous_timer_.start(max(delay, 1L));
351+ void setPlayEnabled(bool enable)
352+ {
353+ widget_->next_button_->setEnabled(enable);
354+ widget_->continuous_button_->setEnabled(enable);
266355 }
267- }
268356
269357
270- long timestamp(const ScipData& data)
271- {
272- if (data.size() <= 2) {
273- return 0;
358+ void setScipData(const ScipData& line_block)
359+ {
360+ for (ScipData::const_iterator it = line_block.begin();
361+ it != line_block.end(); ++it) {
362+ con_.setReadData(*it + "\r");
363+ }
274364 }
275- return ScipHandler::decode(data[2].c_str(), 4);
276- }
365+
366+
367+ void continuousPlay(void)
368+ {
369+ if (updateDrawData()) {
370+ long delay = timestamp(scip_data_) - current_timestamp_;
371+ if (play_ratio_ > 0) {
372+ delay /= play_ratio_;
373+ }
374+ continuous_timer_.start(max(delay, 1L));
375+ }
376+ }
377+
378+
379+ long timestamp(const ScipData& data)
380+ {
381+ if (data.size() <= 2) {
382+ return 100;
383+ }
384+ return ScipHandler::decode(data[2].c_str(), 4);
385+ }
277386 };
278387
279388
280389 ScipPlayerWindow::ScipPlayerWindow(void) : pimpl(new pImpl(this))
281390 {
282- setupUi(this);
283- pimpl->initializeForm();
284- pimpl->loadSettings();
391+ setupUi(this);
392+ pimpl->initializeForm();
393+ pimpl->loadSettings();
285394
286- pimpl->reload();
395+ pimpl->reload();
287396 }
288397
289398
290399 ScipPlayerWindow::~ScipPlayerWindow(void)
291400 {
292- pimpl->saveSettings();
401+ pimpl->saveSettings();
293402 }
294403
295404
296405 void ScipPlayerWindow::aboutApplication(void)
297406 {
298- QMessageBox::about(this, tr("About Scip Player"),
299- tr("<h2>Scip Player ($Rev$)</h2>"
300- "<p>Demo Application for URG sensor</p>"
301- "<p>Report bugs to "
302- "&lt;s-kamimura@hokuyo-aut.co.jp&gt;</p>"));
407+ QMessageBox::about(this, tr("About Scip Player"),
408+ tr("<h2>Scip Player ($Rev$)</h2>"
409+ "<p>Demo Application for URG sensor</p>"
410+ "<p>Report bugs to "
411+ "&lt;s-kamimura@hokuyo-aut.co.jp&gt;</p>"));
303412 }
304413
305414
306415 void ScipPlayerWindow::pathPressed(void)
307416 {
308- QString file_name =
309- QFileDialog::getOpenFileName(this, tr("SCIP Log file"),
310- path_edit_->text(),
311- tr("Log files (*.txt *.log)"));
312- if (file_name.isEmpty()) {
313- return;
314- }
417+ QString file_name =
418+ QFileDialog::getOpenFileName(this, tr("SCIP Log file"),
419+ path_edit_->text(),
420+ tr("Log files (*.txt *.log *.csv)"));
421+ if (file_name.isEmpty()) {
422+ return;
423+ }
315424
316- path_edit_->setText(file_name);
317- pimpl->reload();
425+ path_edit_->setText(file_name);
426+ pimpl->reload();
318427 }
319428
320429
321430 void ScipPlayerWindow::reloadPressed(void)
322431 {
323- pimpl->reload();
432+ pimpl->reload();
324433 }
325434
326435
327436 void ScipPlayerWindow::nextPressed(void)
328437 {
329- pimpl->continuous_timer_.stop();
330- if (pimpl->play_ratio_ > 0) {
331- --pimpl->play_ratio_;
332- }
333- pimpl->updateDrawData();
438+ pimpl->continuous_timer_.stop();
439+ if (pimpl->play_ratio_ > 0) {
440+ --pimpl->play_ratio_;
441+ }
442+ pimpl->updateDrawData();
334443 }
335444
336445
337446 void ScipPlayerWindow::timerTimeout(void)
338447 {
339- pimpl->continuousPlay();
448+ pimpl->continuousPlay();
340449 }
341450
342451
343452 void ScipPlayerWindow::continuousPressed(void)
344453 {
345- ++pimpl->play_ratio_;
346- pimpl->continuousPlay();
454+ ++pimpl->play_ratio_;
455+ pimpl->continuousPlay();
347456 }
348457
349458
350459 void ScipPlayerWindow::dragEnterEvent(QDragEnterEvent* event)
351460 {
352- if (event->mimeData()->hasFormat("text/uri-list")) {
353- event->acceptProposedAction();
354- }
461+ if (event->mimeData()->hasFormat("text/uri-list")) {
462+ event->acceptProposedAction();
463+ }
355464 }
356465
357466
358467 void ScipPlayerWindow::dropEvent(QDropEvent* event)
359468 {
360- QList<QUrl> urls = event->mimeData()->urls();
361- if (urls.isEmpty()) {
362- return;
363- }
469+ QList<QUrl> urls = event->mimeData()->urls();
470+ if (urls.isEmpty()) {
471+ return;
472+ }
364473
365- QString file_name = urls.first().toLocalFile();
366- if (file_name.isEmpty()) {
367- return;
368- }
474+ QString file_name = urls.first().toLocalFile();
475+ if (file_name.isEmpty()) {
476+ return;
477+ }
369478
370- path_edit_->setText(file_name);
371- pimpl->reload();
479+ path_edit_->setText(file_name);
480+ pimpl->reload();
372481 }
373482
374483
375484 void ScipPlayerWindow::zoomSmaller(void)
376485 {
377- pimpl->urg_draw_widget_.updateZoomRatio(+1);
486+ pimpl->urg_draw_widget_.updateZoomRatio(+1);
378487 }
379488
380489
381490 void ScipPlayerWindow::zoomLarger(void)
382491 {
383- pimpl->urg_draw_widget_.updateZoomRatio(-1);
492+ pimpl->urg_draw_widget_.updateZoomRatio(-1);
384493 }
385494
386495
387496 void ScipPlayerWindow::initializeView(void)
388497 {
389- pimpl->urg_draw_widget_.initializeView();
498+ pimpl->urg_draw_widget_.initializeView();
390499 }
--- trunk/programs/ScipPlayer/ScipPlayerWindow.h (revision 1828)
+++ trunk/programs/ScipPlayer/ScipPlayerWindow.h (revision 1829)
@@ -19,30 +19,30 @@
1919 */
2020 class ScipPlayerWindow : public QMainWindow, private Ui::ScipPlayerWindowForm
2121 {
22- Q_OBJECT;
22+ Q_OBJECT;
2323
24- ScipPlayerWindow(const ScipPlayerWindow& rhs);
25- ScipPlayerWindow& operator = (const ScipPlayerWindow& rhs);
24+ ScipPlayerWindow(const ScipPlayerWindow& rhs);
25+ ScipPlayerWindow& operator = (const ScipPlayerWindow& rhs);
2626
27- struct pImpl;
28- std::auto_ptr<pImpl> pimpl;
27+ struct pImpl;
28+ std::auto_ptr<pImpl> pimpl;
2929
3030 protected slots:
31- void aboutApplication(void);
32- void pathPressed(void);
33- void reloadPressed(void);
34- void nextPressed(void);
35- void continuousPressed(void);
36- void timerTimeout(void);
37- void dragEnterEvent(QDragEnterEvent* event);
38- void dropEvent(QDropEvent* event);
39- void zoomSmaller(void);
40- void zoomLarger(void);
41- void initializeView(void);
31+ void aboutApplication(void);
32+ void pathPressed(void);
33+ void reloadPressed(void);
34+ void nextPressed(void);
35+ void continuousPressed(void);
36+ void timerTimeout(void);
37+ void dragEnterEvent(QDragEnterEvent* event);
38+ void dropEvent(QDropEvent* event);
39+ void zoomSmaller(void);
40+ void zoomLarger(void);
41+ void initializeView(void);
4242
4343 public:
44- ScipPlayerWindow(void);
45- ~ScipPlayerWindow(void);
44+ ScipPlayerWindow(void);
45+ ~ScipPlayerWindow(void);
4646 };
4747
4848 #endif /* !SCIP_PLAYER_WINDOW_H */
旧リポジトリブラウザで表示