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 #ifdef __FreeBSD__
00037 # include <strfunc.h>
00038 #endif
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 RectificationInfoFile::RectificationInfoFile(uint64_t cam_guid, const char *model)
00059 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
00060 {
00061 _spec_header = calloc(1, sizeof(rectinfo_header_t));
00062 _spec_header_size = sizeof(rectinfo_header_t);
00063 _header = (rectinfo_header_t *)_spec_header;
00064
00065 _cam_guid = cam_guid;
00066 _model = strdup(model);
00067
00068 strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00069 _header->guid = _cam_guid;
00070 }
00071
00072
00073
00074
00075
00076
00077 RectificationInfoFile::RectificationInfoFile()
00078 : FireVisionDataFile(FIREVISION_RECTINFO_MAGIC, FIREVISION_RECTINFO_CURVER)
00079 {
00080 _spec_header = calloc(1, sizeof(rectinfo_header_t));
00081 _spec_header_size = sizeof(rectinfo_header_t);
00082 _header = (rectinfo_header_t *)_spec_header;
00083
00084 _cam_guid = 0;
00085 _model = strdup("");
00086
00087 strncpy(_header->camera_model, _model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00088 _header->guid = _cam_guid;
00089 }
00090
00091
00092
00093 RectificationInfoFile::~RectificationInfoFile()
00094 {
00095 free(_model);
00096 }
00097
00098
00099
00100
00101
00102 uint64_t
00103 RectificationInfoFile::guid()
00104 {
00105 return _header->guid;
00106 }
00107
00108
00109
00110
00111
00112 const char *
00113 RectificationInfoFile::model()
00114 {
00115 return _model;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 void
00125 RectificationInfoFile::add_rectinfo_block(RectificationInfoBlock *block)
00126 {
00127 add_block(block);
00128 }
00129
00130
00131
00132
00133
00134 RectificationInfoFile::RectInfoBlockVector *
00135 RectificationInfoFile::rectinfo_blocks()
00136 {
00137 FireVisionDataFile::BlockList &b = blocks();
00138 printf("Processing blocks: %zu\n", b.size());
00139 RectInfoBlockVector *rv = new RectInfoBlockVector();
00140 for (std::list<FireVisionDataFileBlock *>::iterator i = b.begin(); i != b.end(); ++i) {
00141 printf("Processing block\n");
00142 if ((*i)->type() == FIREVISION_RECTINFO_TYPE_LUT_16x16) {
00143 printf("Pushing lut block\n");
00144 RectificationLutInfoBlock *libl = new RectificationLutInfoBlock(*i);
00145 rv->push_back(libl);
00146 }
00147 }
00148
00149 return rv;
00150 }
00151
00152
00153 void
00154 RectificationInfoFile::read(const char *filename)
00155 {
00156 FireVisionDataFile::read(filename);
00157
00158 _header = (rectinfo_header_t *)_spec_header;
00159
00160 if (_model) free(_model);
00161 _model = strndup(_header->camera_model, FIREVISION_RECTINFO_CAMERA_MODEL_MAXLENGTH);
00162 _cam_guid = _header->guid;
00163 }
00164
00165
00166 RectificationInfoFile::RectInfoBlockVector::~RectInfoBlockVector()
00167 {
00168 for (iterator i = begin(); i != end(); ++i) {
00169 delete *i;
00170 }
00171 }
00172