rectfile.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <fvutils/rectification/rectinfo.h>
00025 #include <fvutils/rectification/rectfile.h>
00026 #include <fvutils/rectification/rectinfo_block.h>
00027 #include <fvutils/rectification/rectinfo_lut_block.h>
00028
00029 #include <core/exceptions/system.h>
00030
00031 #include <cstring>
00032 #include <cstdio>
00033 #include <errno.h>
00034 #include <netinet/in.h>
00035 #include <cstdlib>
00036
00037 namespace firevision {
00038 #if 0
00039 }
00040 #endif
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 RectificationInfoFile::RectificationInfoFile(uint64_t cam_guid, const char *model)
00061 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
00062 {
00063 _spec_header = calloc(1, sizeof(rectinfo_header_t));
00064 _spec_header_size = sizeof(rectinfo_header_t);
00065 _header = (rectinfo_header_t *)_spec_header;
00066
00067 _cam_guid = cam_guid;
00068 _model = strdup(model);
00069
00070 strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00071 _header->guid = _cam_guid;
00072 }
00073
00074
00075
00076
00077
00078
00079 RectificationInfoFile::RectificationInfoFile()
00080 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
00081 {
00082 _spec_header = calloc(1, sizeof(rectinfo_header_t));
00083 _spec_header_size = sizeof(rectinfo_header_t);
00084 _header = (rectinfo_header_t *)_spec_header;
00085
00086 _cam_guid = 0;
00087 _model = strdup("");
00088
00089 strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00090 _header->guid = _cam_guid;
00091 }
00092
00093
00094
00095 RectificationInfoFile::~RectificationInfoFile()
00096 {
00097 free(_model);
00098 }
00099
00100
00101
00102
00103
00104 uint64_t
00105 RectificationInfoFile::guid()
00106 {
00107 return _header->guid;
00108 }
00109
00110
00111
00112
00113
00114 const char *
00115 RectificationInfoFile::model()
00116 {
00117 return _model;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 void
00127 RectificationInfoFile::add_rectinfo_block(RectificationInfoBlock *block)
00128 {
00129 add_block(block);
00130 }
00131
00132
00133
00134
00135
00136 RectificationInfoFile::RectInfoBlockVector *
00137 RectificationInfoFile::rectinfo_blocks()
00138 {
00139 FireVisionDataFile::BlockList &b = blocks();
00140 printf("Processing blocks: %zu\n", b.size());
00141 RectInfoBlockVector *rv = new RectInfoBlockVector();
00142 for (std::list<FireVisionDataFileBlock *>::iterator i = b.begin(); i != b.end(); ++i) {
00143 printf("Processing block\n");
00144 if ((*i)->type() == FIREVISION_RECTINFO_TYPE_LUT_16x16) {
00145 printf("Pushing lut block\n");
00146 RectificationLutInfoBlock *libl = new RectificationLutInfoBlock(*i);
00147 rv->push_back(libl);
00148 }
00149 }
00150
00151 return rv;
00152 }
00153
00154
00155 void
00156 RectificationInfoFile::read(const char *filename)
00157 {
00158 FireVisionDataFile::read(filename);
00159
00160 _header = (rectinfo_header_t *)_spec_header;
00161
00162 if (_model) free(_model);
00163 _model = strndup(_header->camera_model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00164 _cam_guid = _header->guid;
00165 }
00166
00167
00168 RectificationInfoFile::RectInfoBlockVector::~RectInfoBlockVector()
00169 {
00170 for (iterator i = begin(); i != end(); ++i) {
00171 delete *i;
00172 }
00173 }
00174
00175 }