forked from torrtuga/QT-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
betafacepoints.cpp
108 lines (99 loc) · 3.54 KB
/
betafacepoints.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "betafacepoints.h"
#include "imagelist.h"
#include <QDomDocument>
#include <QDomElement>
#include <QDomText>
#include <QDebug>
#include <string>
using namespace std;
BetafacePoints::BetafacePoints(string newName)
{
name = newName;
}
QString BetafacePoints::getXMLPath()
{
ImageList imageList;
string path = imageList.getPath();
path = path + '/'+ name + "/shape/faceData.xml";
QString filePath = QString::fromStdString(path);
return filePath;
}
map <string,string> BetafacePoints::getExtraData()
{
QDomDocument xmlDocument;
map<string,string> extraData;
QFile xmlFile(getXMLPath());
if(!xmlFile.exists()){
cout << "XML file not found";
return extraData;
}
xmlDocument.setContent(&xmlFile);
xmlFile.close();
QDomElement root=xmlDocument.documentElement();
QDomElement faces = root.firstChildElement("faces");
QDomElement faceInfo = faces.firstChildElement("FaceInfo");
QDomElement angle = faceInfo.firstChildElement("angle");
QDomElement height = faceInfo.firstChildElement("height");
QDomElement width = faceInfo.firstChildElement("width");
QDomElement x = faceInfo.firstChildElement("x");
QDomElement y = faceInfo.firstChildElement("y");
QDomElement uid = faceInfo.firstChildElement("uid");
extraData.insert(pair<string,string>("angle",angle.text().toStdString()));
extraData.insert(pair<string,string>("height",height.text().toStdString()));
extraData.insert(pair<string,string>("width",width.text().toStdString()));
extraData.insert(pair<string,string>("x",x.text().toStdString()));
extraData.insert(pair<string,string>("y",y.text().toStdString()));
extraData.insert(pair<string,string>("uid",uid.text().toStdString()));
return extraData;
}
map<double,QPointF> BetafacePoints::generatePoints()
{
QFile xmlFile(getXMLPath());
if(!xmlFile.exists()){
cout << "XML file not found";
return facialPoints;
}
QString errMsg;
QFileDevice::FileError err = QFileDevice::NoError;
if (!xmlFile.open(QIODevice::ReadOnly)) {
errMsg = xmlFile.errorString();
err = xmlFile.error();
cout << "Error Message" << errMsg.toStdString() <<" : "<< err;
return facialPoints;
}
QXmlStreamReader Rxml;
Rxml.setDevice(&xmlFile);
while(!Rxml.atEnd()){
if(Rxml.isStartElement()){
if(Rxml.name()!="PointInfo"){
Rxml.readNextStartElement();
}else{
QPointF point;
double type;
Rxml.readNext();
while(Rxml.name()!="PointInfo"){
QString value = Rxml.readElementText();
QString node = Rxml.name().toString();
if(node=="x"){
double val = value.toDouble();
point.setX(val);
//qDebug() << "XXX" << Rxml.name() <<":"<<val;
}else if(node=="y"){
float val = value.toDouble();
point.setY(val);
//qDebug() << "YYY" << Rxml.name() <<":"<<val;
}else if(node=="type"){
type = value.toFloat();
//qDebug() << "Others" << Rxml.name() <<":"<<type;
}
Rxml.readNextStartElement();
}
facialPoints.insert(pair<double,QPointF>(type,point));
}
}else{
Rxml.readNext();
}
}
xmlFile.close();
return facialPoints;
}