20 #include <QTextStream>
30 assert(file.exists());
31 if (!file.open(QFile::ReadOnly | QFile::Text)) {
33 app->
dispToConsole(QString(
"Failed to open file for reading! Check "
39 QTextStream stream(&file);
44 for (
unsigned n = 0; n < 1; ++n)
48 QString headerLine = stream.readLine();
49 if (headerLine.isEmpty() || !headerLine.startsWith(
"X")) {
52 QString(
"Malformed file (origin header expected on "
58 QString centerLine = stream.readLine();
62 bool validLine =
false;
63 if (tokens.size() == 3) {
64 bool ok[3] = {
false,
false,
false};
66 tokens[0].toDouble(ok + 0));
68 tokens[1].toDouble(ok + 1));
70 tokens[2].toDouble(ok + 2));
71 validLine = ok[0] && ok[1] && ok[2];
76 QString(
"Malformed file (origin coordinates "
77 "expected on second line)"),
87 QString headerLine = stream.readLine();
88 if (headerLine.isEmpty() || !headerLine.startsWith(
"R")) {
91 QString(
"Malformed file (radii/heights header "
92 "expected on third line)"),
98 QString line = stream.readLine();
99 std::vector<CCVector2d>
points;
100 while (!line.isEmpty()) {
103 if (tokens.size() < 2) {
106 QString(
"Malformed file (radius/height couple "
107 "expected from the 4th line and "
115 P.
x = tokens[0].toDouble();
116 P.
y = tokens[1].toDouble();
120 }
catch (
const std::bad_alloc&) {
124 QString(
"Not enough memory!"),
130 line = stream.readLine();
135 unsigned count =
static_cast<unsigned>(
points.size());
145 QString(
"Not enough memory!"),
153 for (
unsigned i = 0; i <
count; ++i) {
181 QString(
"Not enough points in profile?!"),
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
QStringList qtCompatSplitRegex(const QString &str, const QString &pattern, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
static ccPolyline * Load(QString filename, CCVector3 &origin, ecvMainAppInterface *app=0)
Loads a 2D profile from a file.
virtual void showColors(bool state)
Sets colors visibility.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
virtual void setLocked(bool state)
Sets the "enabled" property.
virtual void setName(const QString &name)
Sets object name.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
void set2DMode(bool state)
Defines if the polyline is considered as 2D or 3D.
void setColor(const ecvColor::Rgb &col)
Sets the polyline color.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
void setClosed(bool state)
Sets whether the polyline is closed or not.
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
virtual bool reserve(unsigned n)
Reserves some memory for hosting the point references.
Main application interface (for plugins)
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
static void error(char *msg)
constexpr Qt::SplitBehavior SkipEmptyParts
constexpr Rgb green(0, MAX, 0)