ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pointsreader.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "pointsreader.h"
9 
10 #include <QDebug>
11 #include <QFile>
12 
13 // Qt5/Qt6 Compatibility
14 #include <QtCompat.h>
15 
16 namespace VtkUtils {
17 
18 PointsReader::PointsReader(const QString& file) : m_file(file) {}
19 
21  QFile file(m_file);
22  if (!file.open(QIODevice::ReadOnly)) {
23  qDebug() << QString("PointsReader::run() : cannot open file \"%1\" for "
24  "reading.")
25  .arg(m_file);
26  return;
27  }
28 
29  QTextStream ts(&file);
30  QString line;
31  QStringList parts;
32  while (!ts.atEnd()) {
33  line = ts.readLine();
34  parts = line.split('\t'); // separated by tab
35  parts.removeAll(QString()); // remove empty strings
36 
37  if (parts.size() == 3)
38  m_points.append(Point3F{parts.at(0).toDouble(),
39  parts.at(1).toDouble(),
40  parts.at(2).toDouble()});
41  }
42 
43  emit finished();
44 }
45 
46 const QList<Point3F>& PointsReader::points() const { return m_points; }
47 
48 } // namespace VtkUtils
const QList< Point3F > & points() const
PointsReader(const QString &file)