Fawkes API  Fawkes Development Version
rectfile.cpp
1 
2 /***************************************************************************
3  * rectfile.cpp - Rectification info file
4  *
5  * Created: Wed Oct 31 11:48:07 2007
6  * Copyright 2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvutils/rectification/rectinfo.h>
25 #include <fvutils/rectification/rectfile.h>
26 #include <fvutils/rectification/rectinfo_block.h>
27 #include <fvutils/rectification/rectinfo_lut_block.h>
28 
29 #include <core/exceptions/system.h>
30 #include <utils/misc/strndup.h>
31 
32 #include <cstring>
33 #include <cstdio>
34 #include <errno.h>
35 #include <netinet/in.h>
36 #include <cstdlib>
37 
38 namespace firevision {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 /** @class RectificationInfoFile <fvutils/rectification/rectfile.h>
44  * Rectification Info File.
45  * This class provides access files that contain rectification info.
46  * Currently it supports writing and reading of such data and supports
47  * any number of rectificatoin info blocks (although this is limited
48  * by the file format!).
49  *
50  * It follows the file format as defined in rectinfo.h. Files that are written
51  * are always of the current version. The endianess is automatically set to the
52  * current's system endianess.
53  *
54  * @author Tim Niemueller
55  */
56 
57 /** Constructor.
58  * @param cam_guid Camera globally unique identifier.
59  * @param model String with the model name of the camera
60  */
61 RectificationInfoFile::RectificationInfoFile(uint64_t cam_guid, const char *model)
62  : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
63 {
64  _spec_header = calloc(1, sizeof(rectinfo_header_t));
66  _header = (rectinfo_header_t *)_spec_header;
67 
68  _cam_guid = cam_guid;
69  _model = strdup(model);
70 
71  strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
72  _header->guid = _cam_guid;
73 }
74 
75 
76 /** Constructor.
77  * This constructor may only be used for reading files, as the GUID of the camera
78  * is invalid for writing.
79  */
81  : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
82 {
83  _spec_header = calloc(1, sizeof(rectinfo_header_t));
85  _header = (rectinfo_header_t *)_spec_header;
86 
87  _cam_guid = 0;
88  _model = strdup("");
89 
90  strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
91  _header->guid = _cam_guid;
92 }
93 
94 
95 /** Destructor. */
97 {
98  free(_model);
99 }
100 
101 
102 /** Get the GUID of camera.
103  * @return GUID of the camera this rectification info file belongs to.
104  */
105 uint64_t
107 {
108  return _header->guid;
109 }
110 
111 
112 /** Get the model of the camera.
113  * @return string with the camera's model name
114  */
115 const char *
117 {
118  return _model;
119 }
120 
121 
122 /** Add a rectification info block.
123  * This instance takes over ownership of the rectinfo block. This means that the
124  * object is automatically deleted if this instance is deleted.
125  * @param block block to add
126  */
127 void
129 {
130  add_block(block);
131 }
132 
133 
134 /** Get all rectification info blocks.
135  * @return reference to internal vector of rectinfo blocks.
136  */
139 {
141  printf("Processing blocks: %zu\n", b.size());
143  for (std::list<FireVisionDataFileBlock *>::iterator i = b.begin(); i != b.end(); ++i) {
144  printf("Processing block\n");
145  if ((*i)->type() == FIREVISION_RECTINFO_TYPE_LUT_16x16) {
146  printf("Pushing lut block\n");
148  rv->push_back(libl);
149  }
150  }
151 
152  return rv;
153 }
154 
155 
156 void
157 RectificationInfoFile::read(const char *filename)
158 {
159  FireVisionDataFile::read(filename);
160 
161  _header = (rectinfo_header_t *)_spec_header;
162 
163  if (_model) free(_model);
164  _model = strndup(_header->camera_model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
165  _cam_guid = _header->guid;
166 }
167 
168 
169 RectificationInfoFile::RectInfoBlockVector::~RectInfoBlockVector()
170 {
171  for (iterator i = begin(); i != end(); ++i) {
172  delete *i;
173  }
174 }
175 
176 } // end namespace firevision
size_t _spec_header_size
Size in bytes of _spec_header.
Definition: fvfile.h:69
const char * model()
Get the model of the camera.
Definition: rectfile.cpp:116
virtual void add_block(FireVisionDataFileBlock *block)
Add a block.
Definition: fvfile.cpp:242
char camera_model[FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH]
camera model
Definition: rectinfo.h:91
Recitification Lookup Table Block.
uint64_t guid
GUID of camera.
Definition: rectinfo.h:90
void add_rectinfo_block(RectificationInfoBlock *block)
Add a rectification info block.
Definition: rectfile.cpp:128
RectificationInfoFile()
Constructor.
Definition: rectfile.cpp:80
std::list< FireVisionDataFileBlock * > BlockList
List of FireVision data file blocks.
Definition: fvfile.h:64
Vector that is used for maintaining the rectification info blocks.
Definition: rectfile.h:49
uint64_t guid()
Get the GUID of camera.
Definition: rectfile.cpp:106
virtual void read(const char *file_name)
Read file.
Definition: fvfile.cpp:308
~RectificationInfoFile()
Destructor.
Definition: rectfile.cpp:96
void * _spec_header
Content specific header.
Definition: fvfile.h:68
virtual void read(const char *filename)
Read file.
Definition: rectfile.cpp:157
FireVision File Format for data files.
Definition: fvfile.h:37
Rectification info block.
Header for a rectification information file (rectinfo).
Definition: rectinfo.h:89
RectInfoBlockVector * rectinfo_blocks()
Get all rectification info blocks.
Definition: rectfile.cpp:138
BlockList & blocks()
Get blocks.
Definition: fvfile.cpp:252