Go to the documentation of this file.00001
00002
00003
00004
00005 #include "bvgl_labelme_parser.h"
00006
00007 #include <vcl_sstream.h>
00008 #include <vcl_cstring.h>
00009 #include <vcl_iostream.h>
00010 #include <vcl_cstdio.h>
00011
00012
00013
00014 bvgl_labelme_parser::bvgl_labelme_parser(vcl_string& filename)
00015 {
00016 vcl_FILE* xmlFile = vcl_fopen(filename.c_str(), "r");
00017 if (!xmlFile) {
00018 vcl_cerr << filename << " error on opening\n";
00019 throw -1;
00020 }
00021 if (!this->parseFile(xmlFile)) {
00022 vcl_cerr << XML_ErrorString(this->XML_GetErrorCode()) << " at line "
00023 << this->XML_GetCurrentLineNumber() << '\n';
00024 throw -1;
00025 }
00026 }
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 void
00040 bvgl_labelme_parser::startElement(const char* name, const char** atts)
00041 {
00042
00043 active_tag_ = vcl_string(name);
00044
00045
00046 if(vcl_strcmp(name, POLYGON_TAG)==0)
00047 pts_.clear();
00048 }
00049
00050
00051 void bvgl_labelme_parser::endElement(const XML_Char* name)
00052 {
00053
00054 if(vcl_strcmp(name, POLYGON_TAG)==0) {
00055 vgl_polygon<double> poly(pts_);
00056 polygons_.push_back(poly);
00057 }
00058
00059
00060 if(vcl_strcmp(name, Y_TAG)==0) {
00061 vgl_point_2d<double> pt(x_, y_);
00062 pts_.push_back(pt);
00063 }
00064 }
00065
00066
00067
00068 void bvgl_labelme_parser::charData(const XML_Char* s, int len)
00069 {
00070 if(active_tag_ == X_TAG || active_tag_ == Y_TAG) {
00071 int val;
00072 convert(vcl_string(s,len), val);
00073 if(active_tag_ == X_TAG)
00074 x_ = (double) val;
00075 if(active_tag_ == Y_TAG)
00076 y_ = (double) val;
00077 }
00078
00079 if(active_tag_ == FILENAME_TAG)
00080 image_name_ = vcl_string(s, len);
00081
00082 if(active_tag_ == NAME_TAG) {
00083 vcl_string name = vcl_string(s,len);
00084 obj_names_.push_back(name);
00085 }
00086 }
00087