使用Qt从PLY文件中读取二进制数据
Read binary data from PLY file using Qt
我正在尝试从此文件中读取数据:
其中包含以二进制形式存储的 ascii 文本和浮点数。我正在尝试通过执行以下操作来阅读它:
QTextStream in(file);
QString line;
line = in.readLine();
while (!line.startsWith(QString("element vertex"))) {
line = in.readLine();
}
point_count = line.split(QString(" ")).last().toInt();
qDebug() << "PC: " << point_count;
while (line != "end_header") {
line = in.readLine();
}
QDataStream* stream = new QDataStream(file);
stream->skipRawData(in.pos());
stream->setFloatingPointPrecision(QDataStream::SinglePrecision);
float number;
(*stream) >> number;
qDebug() << "Float: " << number;
但是我读到-1.98117e+13,我猜是错误的,我做错了什么?
QDataStream的默认字节顺序是big endian;将其更改为小端:
stream->setByteOrder(QDataStream::LittleEndian)
我正在尝试从此文件中读取数据:
其中包含以二进制形式存储的 ascii 文本和浮点数。我正在尝试通过执行以下操作来阅读它:
QTextStream in(file);
QString line;
line = in.readLine();
while (!line.startsWith(QString("element vertex"))) {
line = in.readLine();
}
point_count = line.split(QString(" ")).last().toInt();
qDebug() << "PC: " << point_count;
while (line != "end_header") {
line = in.readLine();
}
QDataStream* stream = new QDataStream(file);
stream->skipRawData(in.pos());
stream->setFloatingPointPrecision(QDataStream::SinglePrecision);
float number;
(*stream) >> number;
qDebug() << "Float: " << number;
但是我读到-1.98117e+13,我猜是错误的,我做错了什么?
QDataStream的默认字节顺序是big endian;将其更改为小端:
stream->setByteOrder(QDataStream::LittleEndian)