blob: 84e78c735e8527869daad1bdb49b34a7f8f2c2da (
plain)
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
|
#include "graphics/meshloader.h"
#define TINYOBJLOADER_IMPLEMENTATION
#include "util/tiny_obj_loader.h"
#include <iostream>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QRegularExpression>
using namespace Eigen;
bool MeshLoader::loadTetMesh(const std::string &filepath, std::vector<Eigen::Vector3d> &vertices, std::vector<Eigen::Vector4i> &tets)
{
QString qpath = QString::fromStdString(filepath);
QFile file(qpath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
std::cout << "Error opening file: " << filepath << std::endl;
return false;
}
QTextStream in(&file);
QRegularExpression vrxp("v (-?\\d*\\.?\\d+) +(-?\\d*\\.?\\d+) +(-?\\d*\\.?\\d+)");
QRegularExpression trxp("t (\\d+) +(\\d+) +(\\d+) +(\\d+)");
while(!in.atEnd()) {
QString line = in.readLine();
auto match = vrxp.match(line);
if(match.hasMatch()) {
vertices.emplace_back(match.captured(1).toDouble(),
match.captured(2).toDouble(),
match.captured(3).toDouble());
continue;
}
match = trxp.match(line);
if(match.hasMatch()) {
tets.emplace_back(match.captured(1).toInt(),
match.captured(2).toInt(),
match.captured(3).toInt(),
match.captured(4).toInt());
}
}
file.close();
return true;
}
MeshLoader::MeshLoader()
{
}
|