-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstlmanager.cpp
74 lines (64 loc) · 1.44 KB
/
stlmanager.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
#include "stlmanager.h"
#include <QRegexp>
#include <QDeBug>
STLManager::STLManager()
{
}
STLManager::~STLManager()
{
}
void STLManager::clear()
{
m_fileSTL.clear();
m_STLPoint.clear();
}
void STLManager::addLine(const QString & string)
{
m_fileSTL.append(string);
}
int STLManager::pointCount()
{
return m_STLPoint.count();
}
void STLManager::fileToPoint()
{
//点坐标
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
//面片法向量
float nx = 0.0f;
float ny = 0.0f;
float nz = 0.0f;
//法向量正则表达式
QRegExp normalRx("facet normal ([^ ]+) ([^ ]+) ([^ ]+)");
normalRx.setMinimal(false);
//顶点正则表达式
QRegExp positionRx("vertex ([^ ]+) ([^ ]+) ([^ ]+)");
positionRx.setMinimal(false);
int pos = 0;
auto it = m_STLPoint.begin();
for (auto it = m_fileSTL.cbegin(); it != m_fileSTL.cend(); it++) {
//若为法向量
if ((pos = normalRx.indexIn(*it)) != -1) { //注意indexIn(str,int offset=0)!offset不能为-1;
nx = normalRx.cap(1).toFloat();
ny = normalRx.cap(2).toFloat();
nz = normalRx.cap(3).toFloat();
}
//若为顶点坐标
else if ((pos = positionRx.indexIn(*it)) != -1) {
x = positionRx.cap(1).toFloat();
y = positionRx.cap(2).toFloat();
z = positionRx.cap(3).toFloat();
m_STLPoint.append({ QVector3D(x,y,z),QVector3D(nx,ny,nz) });
}
}
}
QVector<PointData>::iterator STLManager::pointBegin()
{
return m_STLPoint.begin();
}
QVector<PointData>::iterator STLManager::pointEnd()
{
return m_STLPoint.end();
}