MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
view.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 *
9 * A reader, writer and API for MVE views. MVE views are organized each in
10 * one directory, the directoy name being the name of the view. The view
11 * contains one special file meta.ini and one file for each embedding.
12 *
13 * Consider the following view representation in the file system:
14 *
15 * view_0000/
16 * meta.ini
17 * original.jpg
18 * undistorted.png
19 * depth-L1.mvei
20 * exif.blob
21 *
22 * The meta.ini file specifies basic view and camera information:
23 *
24 * [view]
25 * id = 10
26 * name = DSC101983
27 *
28 * [camera]
29 * focal_length = 0.812
30 * pixel_aspect = 1
31 * principal_point = 0.5 0.5
32 * rotation = 1 0 0 0 1 0 0 0 1
33 * translation = 0 0 0
34 *
35 * Altough JPEG files are allowed inside a view, saving a modified image will
36 * always use a lossless format (PNG or MVEI), and the lossy file is deleted.
37 * PNG is chosen for 1, 2, 3 and 4 channel images, MVEI for all others.
38 *
39 * TODO: File locks?
40 */
41
42#ifndef MVE_VIEW_HEADER
43#define MVE_VIEW_HEADER
44
45#include <cstdint>
46#include <map>
47#include <memory>
48#include <string>
49#include <vector>
50
51#include "mve/defines.h"
52#include "mve/camera.h"
53#include "mve/image_base.h"
54#include "mve/image.h"
55
57
65class View
66{
67public:
68 typedef std::shared_ptr<View> Ptr;
69 typedef std::shared_ptr<View const> ConstPtr;
70
76 struct MetaData
77 {
78 typedef std::map<std::string, std::string> KeyValueMap;
79
82 bool is_dirty = false;
83 };
84
87 {
89 bool is_dirty = false;
90
92 std::string name;
93
99 std::string filename;
100
101 /* These fields are initialized on-demand (get_*_proxy()). */
102 bool is_initialized = false;
103 int64_t width = 0;
104 int64_t height = 0;
105 int64_t channels = 0;
107
108 /* This field is initialized on request with get_image(). */
110 };
111
114 {
116 bool is_dirty = false;
117
119 std::string name;
120
125 std::string filename;
126
127 /* These fields are initialized on-demand. */
128 bool is_initialized = false;
129 uint64_t size = 0;
130
131 /* This field is initialized on request with get_blob(). */
133 };
134
135 typedef std::vector<ImageProxy> ImageProxies;
136 typedef std::vector<BlobProxy> BlobProxies;
137
138public:
139 static View::Ptr create (void);
140 static View::Ptr create (std::string const& path);
141
142 View (const View&) = delete;
143 View operator= (const View&) = delete;
144
145 /* --------------------- I/O interface -------------------- */
146
148 void load_view (std::string const& path);
149
151 void load_view_from_mve_file (std::string const& filename);
152
154 void reload_view (void);
155
157 void save_view_as (std::string const& path);
158
160 int save_view (void);
161
163 std::string const& get_directory (void) const;
164
166 void clear (void);
167
169 bool is_dirty (void) const;
170
172 int cache_cleanup (void);
173
175 std::size_t get_byte_size (void) const;
176
177 /* ---------------------- View Meta Data ---------------------- */
178
180 std::string get_value (std::string const& key) const;
181
183 void set_value (std::string const& key, std::string const& value);
184
186 void delete_value (std::string const& key);
187
188 /* --------------------- Meta Data Helpers -------------------- */
189
191 void set_id (int view_id);
193 int get_id (void) const;
194
196 void set_name (std::string const& name);
198 std::string get_name (void) const;
199
201 void set_camera (CameraInfo const& camera);
203 CameraInfo const& get_camera (void) const;
205 bool is_camera_valid (void) const;
206
207 /* -------------------- Managing of images -------------------- */
208
210 ImageBase::Ptr get_image (std::string const& name,
211 ImageType type = IMAGE_TYPE_UNKNOWN);
212
214 ImageProxy const* get_image_proxy (std::string const& name,
215 ImageType type = IMAGE_TYPE_UNKNOWN);
216
218 bool has_image (std::string const& name,
219 ImageType type = IMAGE_TYPE_UNKNOWN);
220
222 ByteImage::Ptr get_byte_image (std::string const& name);
223
225 FloatImage::Ptr get_float_image (std::string const& name);
226
231 void set_image (ImageBase::Ptr image, std::string const& name);
232
238 void set_image_ref (std::string const& filename, std::string name);
239
241 bool remove_image (std::string const& name);
242
243 /* --------------------- Managing of blobs -------------------- */
244
246 ByteImage::Ptr get_blob (std::string const& name);
247
249 BlobProxy const* get_blob_proxy (std::string const& name);
250
252 bool has_blob (std::string const& name);
253
258 void set_blob (ByteImage::Ptr blob, std::string const& name);
259
261 bool remove_blob (std::string const& name);
262
263 /* ----------------- Access to internal data ------------------ */
264
266 MetaData const& get_meta_data (void) const;
267
269 ImageProxies const& get_images (void) const;
270
272 BlobProxies const& get_blobs (void) const;
273
275 void debug_print (void);
276
277protected:
279 View (void);
280
282 View (std::string const& path);
283
284private:
285 void deprecated_format_check (std::string const& path);
286 void load_meta_data (std::string const& path);
287 void save_meta_data (std::string const& path);
288 void populate_images_and_blobs (std::string const& path);
289 void replace_file (std::string const& old_fn, std::string const& new_fn);
290
291 ImageProxy* find_image_intern (std::string const& name);
292 void initialize_image (ImageProxy* proxy, bool update);
293 ImageBase::Ptr load_image (ImageProxy* proxy, bool update);
294 void load_image_intern (ImageProxy* proxy, bool init_only);
295 void save_image_intern (ImageProxy* proxy);
296
297 BlobProxy* find_blob_intern (std::string const& name);
298 void initialize_blob (BlobProxy* proxy, bool update);
299 ByteImage::Ptr load_blob (BlobProxy* proxy, bool update);
300 void load_blob_intern (BlobProxy* proxy, bool init_only);
301 void save_blob_intern (BlobProxy* proxy);
302
303protected:
304 typedef std::vector<std::string> FilenameList;
305
306protected:
307 std::string path;
312};
313
314/* ---------------------------------------------------------------- */
315
316inline
317View::View (void)
318{
319}
320
321inline
322View::View (std::string const& path)
323{
324 this->load_view(path);
325}
326
327inline View::Ptr
328View::create (void)
329{
330 return Ptr(new View());
331}
332
333inline View::Ptr
334View::create (std::string const& path)
335{
336 return Ptr(new View(path));
337}
338
339inline std::string const&
340View::get_directory (void) const
341{
342 return this->path;
343}
344
345inline View::MetaData const&
346View::get_meta_data (void) const
347{
348 return this->meta_data;
349}
350
351inline View::ImageProxies const&
352View::get_images (void) const
353{
354 return this->images;
355}
356
357inline View::BlobProxies const&
358View::get_blobs (void) const
359{
360 return this->blobs;
361}
362
363inline void
364View::set_id (int view_id)
365{
366 this->set_value("view.id", util::string::get(view_id));
367}
368
369inline void
370View::set_name (std::string const& name)
371{
372 this->set_value("view.name", name);
373}
374
375inline int
376View::get_id (void) const
377{
378 std::string value = this->get_value("view.id");
379 return value.empty() ? -1 : util::string::convert<int>(value, true);
380}
381
382inline std::string
383View::get_name (void) const
384{
385 return this->get_value("view.name");
386}
387
388inline CameraInfo const&
389View::get_camera (void) const
390{
391 return this->meta_data.camera;
392}
393
394inline bool
395View::is_camera_valid (void) const
396{
397 return this->meta_data.camera.flen > 0.0f;
398}
399
400inline ByteImage::Ptr
401View::get_byte_image (std::string const& name)
402{
403 return std::dynamic_pointer_cast<ByteImage>
404 (this->get_image(name, IMAGE_TYPE_UINT8));
405}
406
407inline FloatImage::Ptr
408View::get_float_image (std::string const& name)
409{
410 return std::dynamic_pointer_cast<FloatImage>
411 (this->get_image(name, IMAGE_TYPE_FLOAT));
412}
413
415
416#endif /* MVE_VIEW_HEADER */
std::shared_ptr< ImageBase > Ptr
Definition image_base.h:55
std::shared_ptr< Image< T > > Ptr
Definition image.h:42
File system representation of a MVE view.
Definition view.h:66
std::string path
Definition view.h:307
MetaData meta_data
Definition view.h:308
std::vector< std::string > FilenameList
Definition view.h:304
View(const View &)=delete
std::vector< BlobProxy > BlobProxies
Definition view.h:136
std::shared_ptr< View > Ptr
Definition view.h:68
BlobProxies blobs
Definition view.h:310
FilenameList to_delete
Definition view.h:311
std::shared_ptr< View const > ConstPtr
Definition view.h:69
ImageProxies images
Definition view.h:309
std::vector< ImageProxy > ImageProxies
Definition view.h:135
#define MVE_NAMESPACE_BEGIN
Definition defines.h:13
#define MVE_NAMESPACE_END
Definition defines.h:14
ImageType
Identifiers for image types.
Definition image_base.h:28
@ IMAGE_TYPE_UINT8
Definition image_base.h:31
@ IMAGE_TYPE_UNKNOWN
Definition image_base.h:29
@ IMAGE_TYPE_FLOAT
Definition image_base.h:41
std::string get(T const &value)
From arbitrary types to string conversion.
Definition strings.h:108
Per-view camera information with various helper functions.
Definition camera.h:24
float flen
Focal length.
Definition camera.h:156
Proxy for BLOBs (Binary Large OBjects).
Definition view.h:114
std::string filename
Filename is empty if the BLOB has not been saved yet, or relative if the BLOB is mapped to the view o...
Definition view.h:125
std::string name
The name of the BLOB.
Definition view.h:119
ByteImage::Ptr blob
Definition view.h:132
Proxy for images.
Definition view.h:87
std::string filename
The filename is empty if the image has not been saved yet.
Definition view.h:99
std::string name
The name of the image.
Definition view.h:92
ImageBase::Ptr image
Definition view.h:109
View meta information that stores key/value pairs and the camera.
Definition view.h:77
CameraInfo camera
Definition view.h:80
KeyValueMap data
Definition view.h:81
std::map< std::string, std::string > KeyValueMap
Definition view.h:78