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 <core/exceptions/system.h>
25 #include <fvutils/rectification/rectfile.h>
26 #include <fvutils/rectification/rectinfo.h>
27 #include <fvutils/rectification/rectinfo_block.h>
28 #include <fvutils/rectification/rectinfo_lut_block.h>
29 #include <netinet/in.h>
30 #include <utils/misc/strndup.h>
31 
32 #include <cstdio>
33 #include <cstdlib>
34 #include <cstring>
35 #include <errno.h>
36 
37 namespace firevision {
38 
39 /** @class RectificationInfoFile <fvutils/rectification/rectfile.h>
40  * Rectification Info File.
41  * This class provides access files that contain rectification info.
42  * Currently it supports writing and reading of such data and supports
43  * any number of rectificatoin info blocks (although this is limited
44  * by the file format!).
45  *
46  * It follows the file format as defined in rectinfo.h. Files that are written
47  * are always of the current version. The endianess is automatically set to the
48  * current's system endianess.
49  *
50  * @author Tim Niemueller
51  */
52 
53 /** Constructor.
54  * @param cam_guid Camera globally unique identifier.
55  * @param model String with the model name of the camera
56  */
57 RectificationInfoFile::RectificationInfoFile(uint64_t cam_guid, const char *model)
58 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
59 {
60  _spec_header = calloc(1, sizeof(rectinfo_header_t));
61  _spec_header_size = sizeof(rectinfo_header_t);
62  _header = (rectinfo_header_t *)_spec_header;
63 
64  _cam_guid = cam_guid;
65  _model = strdup(model);
66 
67  strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH - 1);
68  _header->guid = _cam_guid;
69 }
70 
71 /** Constructor.
72  * This constructor may only be used for reading files, as the GUID of the camera
73  * is invalid for writing.
74  */
76 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
77 {
78  _spec_header = calloc(1, sizeof(rectinfo_header_t));
80  _header = (rectinfo_header_t *)_spec_header;
81 
82  _cam_guid = 0;
83  _model = strdup("");
84 
85  strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH - 1);
86  _header->guid = _cam_guid;
87 }
88 
89 /** Destructor. */
91 {
92  free(_model);
93 }
94 
95 /** Get the GUID of camera.
96  * @return GUID of the camera this rectification info file belongs to.
97  */
98 uint64_t
100 {
101  return _header->guid;
102 }
103 
104 /** Get the model of the camera.
105  * @return string with the camera's model name
106  */
107 const char *
109 {
110  return _model;
111 }
112 
113 /** Add a rectification info block.
114  * This instance takes over ownership of the rectinfo block. This means that the
115  * object is automatically deleted if this instance is deleted.
116  * @param block block to add
117  */
118 void
120 {
121  add_block(block);
122 }
123 
124 /** Get all rectification info blocks.
125  * @return reference to internal vector of rectinfo blocks.
126  */
129 {
131  printf("Processing blocks: %zu\n", b.size());
133  for (std::list<FireVisionDataFileBlock *>::iterator i = b.begin(); i != b.end(); ++i) {
134  printf("Processing block\n");
135  if ((*i)->type() == FIREVISION_RECTINFO_TYPE_LUT_16x16) {
136  printf("Pushing lut block\n");
138  rv->push_back(libl);
139  }
140  }
141 
142  return rv;
143 }
144 
145 void
146 RectificationInfoFile::read(const char *filename)
147 {
148  FireVisionDataFile::read(filename);
149 
151 
152  if (_model)
153  free(_model);
154  _model = strndup(_header->camera_model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
155  _cam_guid = _header->guid;
156 }
157 
158 RectificationInfoFile::RectInfoBlockVector::~RectInfoBlockVector()
159 {
160  for (iterator i = begin(); i != end(); ++i) {
161  delete *i;
162  }
163 }
164 
165 } // end namespace firevision
firevision::RectificationInfoFile::RectificationInfoFile
RectificationInfoFile()
Constructor.
Definition: rectfile.cpp:79
firevision::FireVisionDataFile::_spec_header
void * _spec_header
Definition: fvfile.h:75
firevision::FireVisionDataFile::_spec_header_size
size_t _spec_header_size
Definition: fvfile.h:76
firevision::RectificationInfoFile::~RectificationInfoFile
~RectificationInfoFile()
Destructor.
Definition: rectfile.cpp:94
firevision::RectificationLutInfoBlock
Definition: rectinfo_lut_block.h:35
firevision::RectificationInfoFile::read
virtual void read(const char *filename)
Read file.
Definition: rectfile.cpp:150
firevision::FireVisionDataFile::read
virtual void read(const char *file_name)
Read file.
Definition: fvfile.cpp:289
firevision::FireVisionDataFile
Definition: fvfile.h:39
firevision::FireVisionDataFile::BlockList
std::list< FireVisionDataFileBlock * > BlockList
List of FireVision data file blocks.
Definition: fvfile.h:71
firevision::_rectinfo_header_t
Header for a rectification information file (rectinfo).
Definition: rectinfo.h:85
firevision::RectificationInfoBlock
Definition: rectinfo_block.h:37
firevision::FireVisionDataFile::add_block
virtual void add_block(FireVisionDataFileBlock *block)
Add a block.
Definition: fvfile.cpp:224
firevision::RectificationInfoFile::add_rectinfo_block
void add_rectinfo_block(RectificationInfoBlock *block)
Add a rectification info block.
Definition: rectfile.cpp:123
firevision::RectificationInfoFile::RectInfoBlockVector
Vector that is used for maintaining the rectification info blocks.
Definition: rectfile.h:51
firevision::_rectinfo_header_t::camera_model
char camera_model[FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH]
camera model
Definition: rectinfo.h:88
firevision::RectificationInfoFile::rectinfo_blocks
RectInfoBlockVector * rectinfo_blocks()
Get all rectification info blocks.
Definition: rectfile.cpp:132
firevision::_rectinfo_header_t::guid
uint64_t guid
GUID of camera.
Definition: rectinfo.h:87
firevision::RectificationInfoFile::model
const char * model()
Get the model of the camera.
Definition: rectfile.cpp:112
firevision::FireVisionDataFile::blocks
BlockList & blocks()
Get blocks.
Definition: fvfile.cpp:233
firevision::RectificationInfoFile::guid
uint64_t guid()
Get the GUID of camera.
Definition: rectfile.cpp:103