Skip to content

Commit c56c599

Browse files
committed
vss bin
1 parent bcda5e6 commit c56c599

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

common_utils/common_utils.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdint.h>
1313
#include <numeric>
1414
#include <stdexcept>
15+
#include <typeinfo>
1516
//#STOP_GRAB_TO_INCLUDES_LIST
1617

1718
namespace dvs {
@@ -131,8 +132,8 @@ bool saveVecVec(const vector<vector<T>>& vecVec, const string& filename, dv::con
131132
} else {
132133
size_t rows = vecVec.size();
133134
size_t cols = vecVec.at(0).size();
134-
for (int i = 0; i < rows; ++i) {
135-
for (int j = 0; j < cols; ++j) {
135+
for (size_t i = 0; i < rows; ++i) {
136+
for (size_t j = 0; j < cols; ++j) {
136137
double val = vecVec.at(i).at(j);
137138
fout << val;
138139
if (j < cols - 1) { // we dont need sep at row end
@@ -178,6 +179,31 @@ vector<double> doubleAndReverse(const vector<double>& input, const vector<double
178179
std::string reverseString(const std::string& input);
179180

180181

182+
template <typename T>
183+
std::vector<std::vector<T>> readBinaryFile(const std::string& filePath,
184+
size_t rowLength) {
185+
std::ifstream file(filePath, std::ios::binary);
186+
if (!file) {
187+
throw std::runtime_error("Cannot open file");
188+
}
189+
190+
std::vector<std::vector<T>> data;
191+
std::vector<T> row(rowLength);
192+
193+
while (file.read(reinterpret_cast<char*>(row.data()), rowLength * sizeof(T))) {
194+
data.push_back(row);
195+
}
196+
197+
// Handle the last row if it's not fully filled
198+
if (file.gcount() > 0) {
199+
row.resize(file.gcount() / sizeof(T));
200+
data.push_back(row);
201+
}
202+
203+
file.close();
204+
return data;
205+
}
206+
181207
//#STOP_GRAB_TO_DVS_NAMESPACE
182208
}; // namespace dvs
183209

davis_one/davis.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdexcept>
2121
#include <stdint.h>
2222
#include <string>
23+
#include <typeinfo>
2324
#include <vector>
2425
namespace dvs {
2526
extern const char kAppName[];
@@ -359,8 +360,8 @@ bool saveVecVec(const vector<vector<T>>& vecVec, const string& filename, dv::con
359360
} else {
360361
size_t rows = vecVec.size();
361362
size_t cols = vecVec.at(0).size();
362-
for (int i = 0; i < rows; ++i) {
363-
for (int j = 0; j < cols; ++j) {
363+
for (size_t i = 0; i < rows; ++i) {
364+
for (size_t j = 0; j < cols; ++j) {
364365
double val = vecVec.at(i).at(j);
365366
fout << val;
366367
if (j < cols - 1) { // we dont need sep at row end
@@ -406,6 +407,31 @@ vector<double> doubleAndReverse(const vector<double>& input, const vector<double
406407
std::string reverseString(const std::string& input);
407408

408409

410+
template <typename T>
411+
std::vector<std::vector<T>> readBinaryFile(const std::string& filePath,
412+
size_t rowLength) {
413+
std::ifstream file(filePath, std::ios::binary);
414+
if (!file) {
415+
throw std::runtime_error("Cannot open file");
416+
}
417+
418+
std::vector<std::vector<T>> data;
419+
std::vector<T> row(rowLength);
420+
421+
while (file.read(reinterpret_cast<char*>(row.data()), rowLength * sizeof(T))) {
422+
data.push_back(row);
423+
}
424+
425+
// Handle the last row if it's not fully filled
426+
if (file.gcount() > 0) {
427+
row.resize(file.gcount() / sizeof(T));
428+
data.push_back(row);
429+
}
430+
431+
file.close();
432+
return data;
433+
}
434+
409435

410436
} // namespace dvs end
411437

gui/davis_gui.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,28 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
941941
}
942942
QString filePath = file_list.first();
943943
QFileInfo info(filePath);
944+
945+
QString suffix = info.suffix();
946+
QStringList suffixes = {"jpg", "bmp", "png", "svg", "mp4"};
947+
for (int i = 0; i < suffixes.size(); ++i) {
948+
if (suffix == suffixes[i]) {
949+
QProcess process;
950+
process.startDetached("cmd.exe", QStringList() << "/C" << filePath);
951+
return;
952+
}
953+
}
954+
if (suffix == "json") {
955+
readJsonToPlot(filePath);
956+
return;
957+
}
958+
if (suffix == "bin") {
959+
if (info.size() == 4177936) {
960+
std::vector<std::vector<uint8_t>> data = dvs::readBinaryFile<uint8_t>(filePath.toLatin1().data(), 2044);
961+
dv::show(data);
962+
}
963+
return;
964+
}
965+
944966
if (info.exists()) {
945967
QTime time;
946968
time.start();
@@ -952,19 +974,7 @@ void DavisGUI::visualizeFiles(const QStringList& file_list) {
952974
return;
953975
};
954976

955-
QString suffix = info.suffix();
956-
QStringList suffixes = {"jpg", "bmp", "png", "svg", "mp4"};
957-
for (int i = 0; i < suffixes.size(); ++i) {
958-
if (suffix == suffixes[i]) {
959-
QProcess process;
960-
process.startDetached("cmd.exe", QStringList() << "/C" << filePath);
961-
return;
962-
}
963-
}
964-
if (suffix == "json") {
965-
readJsonToPlot(filePath);
966-
return;
967-
}
977+
968978

969979
QString line;
970980
QStringList str_lines;

0 commit comments

Comments
 (0)