1 | #ifndef FILE_H
|
---|
2 | #define FILE_H
|
---|
3 |
|
---|
4 | /* 3dv-client/file.h
|
---|
5 | *
|
---|
6 | * Copyright (C) 2013 VisLab
|
---|
7 | *
|
---|
8 | * This file is part of 3dv-client; you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU Lesser General Public License as published by
|
---|
10 | * the Free Software Foundation; either version 3 of the License, or (at
|
---|
11 | * your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful, but
|
---|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | * General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU Lesser General Public License
|
---|
19 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include <lib3dv/image.h>
|
---|
23 | #include <lib3dv/motion.h>
|
---|
24 | #include <lib3dv/classification.h>
|
---|
25 | #include <lib3dv/obstacle.h>
|
---|
26 | #include <lib3dv/point.h>
|
---|
27 | #include <lib3dv/terrain.h>
|
---|
28 | #include <lib3dv/calibration.h>
|
---|
29 |
|
---|
30 |
|
---|
31 | #include <boost/archive/binary_oarchive.hpp>
|
---|
32 | #include <boost/archive/text_oarchive.hpp>
|
---|
33 | #include <boost/date_time/posix_time/posix_time.hpp>
|
---|
34 | #include <boost/filesystem.hpp>
|
---|
35 | #include <boost/filesystem/path.hpp>
|
---|
36 | #include <boost/shared_ptr.hpp>
|
---|
37 | #include <boost/serialization/serialization.hpp>
|
---|
38 | #include <boost/serialization/vector.hpp>
|
---|
39 | #include <boost/date_time/posix_time/time_serialize.hpp>
|
---|
40 |
|
---|
41 | #include <stdint.h>
|
---|
42 | #include <vector>
|
---|
43 |
|
---|
44 | #include "pnm.h"
|
---|
45 |
|
---|
46 | struct device_params
|
---|
47 | {
|
---|
48 | lib3dv::calibration::camera_intrinsics intrinsics;
|
---|
49 | lib3dv::calibration::position position;
|
---|
50 | lib3dv::calibration::orientation orientation;
|
---|
51 | float baseline;
|
---|
52 | uint32_t downsample;
|
---|
53 | double area_step;
|
---|
54 | };
|
---|
55 |
|
---|
56 |
|
---|
57 | namespace boost
|
---|
58 | {
|
---|
59 | namespace serialization
|
---|
60 | {
|
---|
61 | template<class Archive>
|
---|
62 | void serialize(Archive& archive, lib3dv::point3& point, const unsigned int version)
|
---|
63 | {
|
---|
64 | archive & point.m_x;
|
---|
65 | archive & point.m_y;
|
---|
66 | archive & point.m_z;
|
---|
67 | }
|
---|
68 |
|
---|
69 | template<class Archive>
|
---|
70 | void serialize(Archive& archive, lib3dv::terrain& terrain, const unsigned int version)
|
---|
71 | {
|
---|
72 | archive & terrain.m_data;
|
---|
73 | }
|
---|
74 |
|
---|
75 | template<class Archive>
|
---|
76 | void serialize(Archive& archive, lib3dv::stixel& stixel, const unsigned int version)
|
---|
77 | {
|
---|
78 | archive & stixel.m_dx;
|
---|
79 | archive & stixel.m_dy;
|
---|
80 | archive & stixel.m_x;
|
---|
81 | archive & stixel.m_y;
|
---|
82 | archive & stixel.m_z;
|
---|
83 | archive & stixel.m_height;
|
---|
84 | }
|
---|
85 |
|
---|
86 | template<class Archive>
|
---|
87 | void serialize(Archive& archive, lib3dv::obstacle& obstacle, const unsigned int version)
|
---|
88 | {
|
---|
89 | archive & obstacle.m_guid;
|
---|
90 | archive & obstacle.m_data;
|
---|
91 | }
|
---|
92 |
|
---|
93 | template<class Archive>
|
---|
94 | void serialize(Archive& archive, lib3dv::pose& pose, const unsigned int version)
|
---|
95 | {
|
---|
96 | archive & pose.m_timestamp;
|
---|
97 | archive & pose.m_type;
|
---|
98 | archive & pose.m_data;
|
---|
99 | }
|
---|
100 |
|
---|
101 | template<class Archive>
|
---|
102 | void serialize(Archive& archive, lib3dv::motion& motion, const unsigned int version)
|
---|
103 | {
|
---|
104 | archive & motion.m_poses;
|
---|
105 | }
|
---|
106 |
|
---|
107 | template<class Archive>
|
---|
108 | void serialize(Archive& archive, lib3dv::candidate& candidate, const unsigned int version)
|
---|
109 | {
|
---|
110 | archive & candidate.m_guid;
|
---|
111 | archive & candidate.m_x0;
|
---|
112 | archive & candidate.m_y0;
|
---|
113 | archive & candidate.m_x1;
|
---|
114 | archive & candidate.m_y1;
|
---|
115 | archive & candidate.m_confidence;
|
---|
116 | archive & candidate.m_wp_lb;
|
---|
117 | archive & candidate.m_category;
|
---|
118 | }
|
---|
119 |
|
---|
120 | template<class Archive>
|
---|
121 | void serialize(Archive& archive, lib3dv::classification& classification, const unsigned int version)
|
---|
122 | {
|
---|
123 | archive & classification.m_timestamp;
|
---|
124 | archive & classification.m_candidates;
|
---|
125 | }
|
---|
126 |
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | namespace data_file_format
|
---|
132 | {
|
---|
133 | enum types {RAW, BINARY, TEXT, GNUPLOT};
|
---|
134 |
|
---|
135 | inline std::istream& operator>>(std::istream& in, types& format_type)
|
---|
136 | {
|
---|
137 | std::string token;
|
---|
138 |
|
---|
139 | in >> token;
|
---|
140 |
|
---|
141 | if(token == "text")
|
---|
142 | format_type = TEXT;
|
---|
143 | else if(token == "binary")
|
---|
144 | format_type = BINARY;
|
---|
145 | else if(token == "gnuplot")
|
---|
146 | format_type = GNUPLOT;
|
---|
147 | else
|
---|
148 | format_type = RAW;
|
---|
149 |
|
---|
150 | return in;
|
---|
151 | }
|
---|
152 |
|
---|
153 | inline std::ostream& operator<<(std::ostream& out, types& format_type)
|
---|
154 | {
|
---|
155 | out << (format_type == TEXT ? "text" : (format_type == BINARY ? "binary" : (format_type == GNUPLOT ? "gnuplot" : "raw")));
|
---|
156 |
|
---|
157 | return out;
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | #ifdef ARCHIVE
|
---|
162 |
|
---|
163 | namespace archive_file_format
|
---|
164 | {
|
---|
165 | enum types { ZIP, TAR };
|
---|
166 |
|
---|
167 | inline std::istream& operator>>(std::istream& in, types& archive_type)
|
---|
168 | {
|
---|
169 | std::string token;
|
---|
170 |
|
---|
171 | in >> token;
|
---|
172 |
|
---|
173 | if(token == "zip")
|
---|
174 | archive_type = ZIP;
|
---|
175 | else if(token == "tar")
|
---|
176 | archive_type = TAR;
|
---|
177 |
|
---|
178 | return in;
|
---|
179 | }
|
---|
180 |
|
---|
181 | inline std::ostream& operator<<(std::ostream& out, types& archive_type)
|
---|
182 | {
|
---|
183 | out << (archive_type == ZIP ? "zip" : "tar");
|
---|
184 |
|
---|
185 | return out;
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | struct archive;
|
---|
190 |
|
---|
191 | archive* open_archive(const boost::filesystem::path& path, const std::string& archive_name, archive_file_format::types format,device_params params, uint8_t log_level);
|
---|
192 |
|
---|
193 | bool close_archive(archive* archive, uint8_t log_level);
|
---|
194 |
|
---|
195 |
|
---|
196 | bool write_image_archive(boost::shared_ptr<const lib3dv::image> image, uint32_t guid, uint8_t guid_type, archive* archive, bool autonumber, uint8_t log_level);
|
---|
197 |
|
---|
198 | bool write_terrain_archive(boost::shared_ptr<const lib3dv::terrain> terrain, uint32_t guid, uint8_t guid_type, archive* archive, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
199 |
|
---|
200 | bool write_obstacles_archive(boost::shared_ptr<const std::vector<lib3dv::obstacle> > obstacles, uint32_t guid, uint8_t guid_type, archive* archive, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
201 |
|
---|
202 | bool write_motion_archive(boost::shared_ptr<const lib3dv::motion> motion, uint32_t guid, uint8_t guid_type, archive* archive, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
203 |
|
---|
204 | bool write_classification_archive(boost::shared_ptr<const lib3dv::classification> classificat, uint32_t guid, uint8_t guid_type, archive* archive, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
205 |
|
---|
206 | bool write_classification_archive(boost::shared_ptr<const lib3dv::classification> classificat, uint32_t guid, archive* archive, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | bool write_image_file(boost::shared_ptr<const lib3dv::image> image, uint32_t guid, uint8_t guid_type, const boost::filesystem::path& path, bool autonumber, uint8_t log_level);
|
---|
210 |
|
---|
211 | bool write_terrain_file(boost::shared_ptr<const lib3dv::terrain> terrain, uint32_t guid, uint8_t guid_type, const boost::filesystem::path& path, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
212 |
|
---|
213 | bool write_obstacles_file(boost::shared_ptr<const std::vector<lib3dv::obstacle> > obstacles, uint32_t guid, uint8_t guid_type, const boost::filesystem::path& path, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
214 |
|
---|
215 | bool write_motion_file(boost::shared_ptr<const lib3dv::motion> motion, uint32_t guid, uint8_t guid_type, const boost::filesystem::path& path, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
216 |
|
---|
217 | bool write_classification_file(boost::shared_ptr<const lib3dv::classification> motion, uint32_t guid, uint8_t guid_type, const boost::filesystem::path& path, bool autonumber, data_file_format::types format, uint8_t log_level);
|
---|
218 |
|
---|
219 | #endif
|
---|