43 #include <visp/vpConfig.h>
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 #include <libxml/xmlmemory.h>
54 #include <visp/vpMbtXmlParser.h>
61 vpMbtXmlParser::vpMbtXmlParser()
69 vpMbtXmlParser::~vpMbtXmlParser()
77 vpMbtXmlParser::init()
81 nodeMap[
"conf"] = conf;
83 nodeMap[
"mask"] = mask;
84 nodeMap[
"size"] = size;
85 nodeMap[
"nb_mask"] = nb_mask;
86 nodeMap[
"range"] = range;
87 nodeMap[
"tracking"] = tracking;
88 nodeMap[
"contrast"] = contrast;
89 nodeMap[
"edge_threshold"] = edge_threshold;
92 nodeMap[
"sample"] = sample;
93 nodeMap[
"step"] = step;
94 nodeMap[
"nb_sample"] = nb_sample;
95 nodeMap[
"camera"] = camera;
96 nodeMap[
"height"] = height;
97 nodeMap[
"width"] = width;
112 vpMbtXmlParser::parse(
const char * filename)
114 std::string file = filename;
124 vpMbtXmlParser::writeMainClass(xmlNodePtr )
137 vpMbtXmlParser::readMainClass(xmlDocPtr doc, xmlNodePtr node)
141 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
142 if(dataNode->type == XML_ELEMENT_NODE){
143 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
144 if(iter_data != nodeMap.end()){
145 switch (iter_data->second){
147 this->lecture_ecm (doc, dataNode);
151 this->lecture_sample (doc, dataNode);
155 this->lecture_camera (doc, dataNode);
167 std::cout <<
"ERROR in 'ECM' field:\n";
168 std::cout <<
"it must contain 3 parameters\n";
183 vpMbtXmlParser::lecture_ecm (xmlDocPtr doc, xmlNodePtr node)
187 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
188 if(dataNode->type == XML_ELEMENT_NODE){
189 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
190 if(iter_data != nodeMap.end()){
191 switch (iter_data->second){
193 this->lecture_mask (doc, dataNode);
197 this->lecture_range (doc, dataNode);
201 this->lecture_contrast (doc, dataNode);
213 std::cout <<
"ERROR in 'ECM' field:\n";
214 std::cout <<
"it must contain 3 parameters\n";
228 vpMbtXmlParser::lecture_sample (xmlDocPtr doc, xmlNodePtr node)
231 double d_stp = this->m_ecm.getSampleStep();
232 int d_nb_sample = this->m_ecm.getNbTotalSample();
235 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
236 if(dataNode->type == XML_ELEMENT_NODE){
237 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
238 if(iter_data != nodeMap.end()){
239 switch (iter_data->second){
241 d_stp = xmlReadIntChild(doc, dataNode);
245 d_nb_sample = xmlReadIntChild(doc, dataNode);
257 this->m_ecm.setSampleStep(d_stp);
258 this->m_ecm.setNbTotalSample(d_nb_sample);
260 std::cout <<
"**** sample:\n";
261 std::cout <<
"sample_step "<< this->m_ecm.getSampleStep()<<std::endl;
262 std::cout <<
"n_total_sample "<< this->m_ecm.getNbTotalSample()<<std::endl;
265 std::cout <<
"ERROR in 'sample' field:\n";
266 std::cout <<
"it must contain 2 parameters\n";
280 vpMbtXmlParser::lecture_camera (xmlDocPtr doc, xmlNodePtr node)
285 double d_u0 = this->cam.
get_u0();
286 double d_v0 = this->cam.
get_v0();
287 double d_px = this->cam.
get_px();
288 double d_py = this->cam.
get_py();
291 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
292 if(dataNode->type == XML_ELEMENT_NODE){
293 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
294 if(iter_data != nodeMap.end()){
295 switch (iter_data->second){
297 xmlReadIntChild(doc, dataNode);
301 xmlReadIntChild(doc, dataNode);
305 d_u0 = xmlReadDoubleChild(doc, dataNode);
309 d_v0 = xmlReadDoubleChild(doc, dataNode);
313 d_px = xmlReadDoubleChild(doc, dataNode);
317 d_py = xmlReadDoubleChild(doc, dataNode);
331 std::cout <<
"**** camera: \n"<<nb <<std::endl;
332 std::cout <<
"u0 "<< this->cam.
get_u0() <<std::endl;
333 std::cout <<
"v0 "<< this->cam.
get_v0() <<std::endl;
334 std::cout <<
"px "<< this->cam.
get_px() <<std::endl;
335 std::cout <<
"py "<< this->cam.
get_py() <<std::endl;
338 std::cout <<
"ERROR in 'camera' field:\n";
339 std::cout <<
"it must contain 6 parameters\n";
353 vpMbtXmlParser::lecture_mask (xmlDocPtr doc, xmlNodePtr node)
356 unsigned int d_size = this->m_ecm.getMaskSize();
357 unsigned int d_nb_mask = this->m_ecm.getMaskNumber();
360 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
361 if(dataNode->type == XML_ELEMENT_NODE){
362 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
363 if(iter_data != nodeMap.end()){
364 switch (iter_data->second){
366 d_size = xmlReadUnsignedIntChild(doc, dataNode);
370 d_nb_mask = xmlReadUnsignedIntChild(doc, dataNode);
382 this->m_ecm.setMaskSize(d_size) ;
383 this->m_ecm.setMaskNumber(d_nb_mask);
385 std::cout <<
"**** mask:\n";
386 std::cout <<
"size "<< this->m_ecm.getMaskSize() <<std::endl;
387 std::cout <<
"nb_mask "<< this->m_ecm.getMaskNumber() <<std::endl;
390 std::cout <<
"ERROR in 'mask' field:\n";
391 std::cout <<
"it must contain 2 parameters\n";
405 vpMbtXmlParser::lecture_range (xmlDocPtr doc, xmlNodePtr node)
408 unsigned int m_range_tracking = this->m_ecm.getRange();
411 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
412 if(dataNode->type == XML_ELEMENT_NODE){
413 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
414 if(iter_data != nodeMap.end()){
415 switch (iter_data->second){
417 m_range_tracking = xmlReadUnsignedIntChild(doc, dataNode);
429 this->m_ecm.setRange(m_range_tracking);
430 std::cout <<
"**** range:\n";
431 std::cout <<
"tracking "<< this->m_ecm.getRange()<<std::endl;
434 std::cout <<
"ERROR in 'range' field:\n";
435 std::cout <<
"it must contain 1 parameters\n";
450 vpMbtXmlParser::lecture_contrast (xmlDocPtr doc, xmlNodePtr node)
453 double d_edge_threshold = this->m_ecm.getThreshold();
454 double d_mu1 = this->m_ecm.getMu1();
455 double d_mu2 = this->m_ecm.getMu2();
458 for(xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
459 if(dataNode->type == XML_ELEMENT_NODE){
460 std::map<std::string, int>::iterator iter_data= this->nodeMap.find((
char*)dataNode->name);
461 if(iter_data != nodeMap.end()){
462 switch (iter_data->second){
463 case edge_threshold:{
464 d_edge_threshold = xmlReadDoubleChild(doc, dataNode);
468 d_mu1 = xmlReadDoubleChild(doc, dataNode);
472 d_mu2 = xmlReadDoubleChild(doc, dataNode);
484 this->m_ecm.setMu1(d_mu1);
485 this->m_ecm.setMu2(d_mu2);
486 this->m_ecm.setThreshold(d_edge_threshold);
488 std::cout <<
"**** contrast:\n";
489 std::cout <<
"mu1 " << this->m_ecm.getMu1()<<std::endl;
490 std::cout <<
"mu2 " << this->m_ecm.getMu2()<<std::endl;
491 std::cout <<
"threshold " << this->m_ecm.getThreshold()<<std::endl;
494 std::cout <<
"ERROR in 'contrast' field:\n";
495 std::cout <<
"it must contain 3 parameters\n";
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void parse(const std::string &filename)