27 #include "MetaData.hh"
28 #include <Base/Debug/Error.hh>
48 if (data != NULL) {
delete[] data; data = NULL; }
63 if (data != NULL)
delete[] data;
65 data =
new char[length];
66 memcpy(data, app.
data, length);
75 if (data)
delete[] data; data=NULL;
84 if (tag==MD_USE_ASCII){
85 string::size_type pos;
86 string::size_type last=sdata.length()-1;
92 while ((pos=sdata.find(
'\n', (pos==0)?0:pos+1))!=string::npos){
93 if (pos==last || sdata[pos+1]!=
'#'){
94 BIASERR(
"there should be no CR without an immediatly following '#' in "
95 <<
"ascii meta data "<<sdata);
101 while ((pos=sdata.find(
'#', (pos==0)?0:pos+1))!=string::npos){
102 if (pos==0 || sdata[pos-1]!=
'\n'){
103 BIASERR(
"there should be no '#' without a leading CR in "
104 <<
"ascii meta data\nthe first '#' is added automatically "
105 <<stag<<endl<<sdata<<
" "<<pos);
111 last=stag.length()-1;
113 BIASERR(
"stag too short, stag should look like this: "
114 <<
"'#[a tag]': "<<last+1<<
" "<<stag);
118 BIASERR(
"wrong stag format, stag should start with '#[' "<<stag);
122 BIASERR(
"wrong stag format, stag should start with '#[' "<<stag);
125 if (stag[last]!=
']'){
126 BIASERR(
"wrong stag format, stag should end with ']' "<<stag);
130 if (stag!=
"" || sdata!=
""){
131 BIASERR(
"stag or sdata is set but tag is not MD_USE_ASCII");
135 BIASERR(
"invalid length "<<length);
174 default: os <<
"unknown TAppData.tag: "<<(int)ta;
break;
182 #ifdef DEBUG_METADATA
183 cerr <<
"writing binary: "<<ad.
tag<<
" length "<<ad.
length
184 <<
" at pos: "<<(int)os.tellp()<<endl;
187 os.write((
char*)&ad.
length,
sizeof(
int));
190 #ifdef DEBUG_METADATA
191 cerr <<
"writing ascii: "<< ad.
stag <<
"\n# "<<ad.
sdata;
192 cerr<<
"read binary AppData, type: "<<ad.
tag<<
" length: "<<ad.
length<<endl;
193 cout <<
"length "<<ad.
sdata.length();
194 if (ad.
sdata.length()>0)
195 cout <<
" first "<<ad.
sdata.c_str()[0];
197 cout <<
"tag: '"<< ad.
stag <<
"'\ndata : '"<< ad.
sdata<<
"'\n";
199 if (ad.
sdata.length()>0 && ad.
sdata.c_str()[0]==
'#'){
203 #ifdef DEBUG_METADATA
211 #define MD_LINE_LENGTH 4096
215 char id[2]={
' ',
' '};
216 is.read(
id, 2*
sizeof(
char));
217 if (is.fail() && is.eof()){
222 if (
id[0]==
'#' &&
id[1]==
'[') {
226 char line[MD_LINE_LENGTH];
231 is.getline(line, MD_LINE_LENGTH);
232 string checkString(line);
233 if(checkString.size() == MD_LINE_LENGTH) {
234 BIASERR(
"you supposedly ran out of line length!");
242 if (is.peek()!=
'#')
break;
244 if (line[0]==
'#' && line[1]==
'[') {
251 is.getline(line, MD_LINE_LENGTH);
256 if (ad.
stag!=
"#[PTU Data]" && ad.
stag!=
"#[Inertial Sensor]"){
261 ad.
sdata.erase(0, 1);
264 ad.
sdata.erase(0, 1);
269 #ifdef DEBUG_METADATA
270 cerr <<
"read ascii AppData : stag: "<<ad.
stag<<
"\t:"<<ad.
sdata<<endl;
275 BIASERR(
"this image contains probably MetaData in old format"
276 <<
"\n use '/usr/net/bin/convasciidata' to convert it");
278 is.setstate(ios::badbit | ios::failbit);
280 is.setstate(ios_base::badbit | ios_base::failbit);
285 #ifdef DEBUG_METADATA
286 cerr<<
"read binary AppData at pos: "<<(int)is.tellg()<<endl;
290 is.read((
char*)&ad.
tag,
sizeof(ad.
tag));
296 #ifdef DEBUG_METADATA
297 cerr<<
"read binary AppData, type: "<<ad.
tag<<
" length: "<<ad.
length<<endl;
299 char *data =
new char[ad.
length];
350 if (
Find(tag, ad)>=0)
365 MetaData::const_iterator it;
367 bool ascii_present=
false;
368 for (i=0, it=begin(); it!=end(); it++, i++){
370 if ((*it).tag == tag) {
386 MetaData::const_iterator it;
388 bool binary_present=
false;
389 for (i=0, it=begin(); it!=end(); it++, i++){
392 if ((*it).stag == tag) {
412 if ((res=
Find(tag, data))==-2)
413 res=
Find(stag, data);
419 MetaData::iterator it;
420 for (it=begin(); it!=end(); it++){
421 if ((*it).tag == tag) {
430 MetaData::iterator it;
431 for (it=begin(); it!=end(); it++){
432 if ((*it).stag == tag) {
441 MetaData::const_iterator it;
442 for (it=begin(); it!=end(); it++){
451 MetaData::const_iterator it;
452 for (it=begin(); it!=end(); it++){
462 for (
unsigned int i=0; i<size(); i++)
463 switch ((*
this)[i].tag) {
465 os <<
"PMatrix ("<<(*this)[i].length<<
"): ";
466 double *d = (
double*)(*
this)[i].data;
467 for (
int i=0; i<12; i++) os <<
" "<<d[i];
471 os<<
"MD_Projection("<<(*this)[i].length<<
"): ";
472 os <<(*this)[i].data;
476 os <<
"MD_Orientation("<<(*this)[i].length<<
"): ";
480 os <<
"MD_TimeStamp("<<(*this)[i].length<<
"): ";
484 os <<
"MD_PTU_Data("<<(*this)[i].length<<
"): ";
488 os <<
"MD_Inertial_Sensor("<<(*this)[i].length<<
"): ";
492 os <<
"MD_ASCII_DATA: "<<(*this)[i].data<<endl;
495 os <<
"MD_RMatrix("<<(*this)[i].length<<
"): ";
499 os <<
"MD_KMatrix("<<(*this)[i].length<<
"): ";
503 os <<
"MD_CVector("<<(*this)[i].length<<
"): ";
507 os <<
"MD_HomgPoint2D: [";
508 double *d = (
double*)(*
this)[i].data;
509 for (
int i=0; i<3; i++) os <<
" "<<d[i];
513 os <<
"MD_Invalid("<<(*this)[i].length<<
"): ";
517 os <<
"MD_UUID("<<(*this)[i].length<<
"): "<< (
char*)(*
this)[i].data<<endl;
520 os << (*this)[i].stag <<
" - " << (*this)[i].sdata << endl;
523 os <<
"MD_Focal_Length("<<(*this)[i].length<<
"): " <<
" - "
524 <<*((
double*)(*
this)[i].data)<<endl;
527 BIASERR(
"unknown tag: "<<(
int)(*
this)[i].tag);
536 #ifdef DEBUG_METADATA
537 cerr <<
"A reading binary MetaDatas at pos: "<<is.tellg() << endl;
541 if (is.peek()==
'#') binary=
false;
542 #ifdef DEBUG_METADATA
543 cerr <<
"B reading binary MetaDatas at pos: "<<is.tellg() << endl;
546 #ifdef DEBUG_METADATA
547 cerr <<
"reading binary MetaDatas" << endl;
556 #ifdef DEBUG_METADATA
557 cerr <<
"reading ascii MetaDatas" << endl;
560 char line[MD_LINE_LENGTH];
561 while(is && is.peek()==
'#'){
562 is.read(
id, 2*
sizeof(
char));
565 if (
id[0]==
'#' &&
id[1]==
'[') {
572 is.getline(line, MD_LINE_LENGTH);
574 #ifdef BIAS_EXTRA_WARN
575 BIASERR(
"skipping non-meta data image comments: "<<line);
587 BIASERR(
"MetaData::AppendToOStream(): ostream not writable!");
590 MetaData::const_iterator it;
591 for (it=md.begin(); it!=md.end(); it++){
std::string stag
the tag as given in ascii meta data
int length
number of bytes used by the data block
void Clear()
Resets all members.
std::string sdata
the data as given in ascii meta data
char * data
pointer to block of data
enum TAppData tag
The tag defines the type of data, e.g.
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
AppData & operator=(const AppData &app)
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
int CheckFormat()
checks if stag and sdata have the correct format
this is a chunk of metadata, also see MetaData