28 QStringList{
"sx",
"sinusx"},
"sx",
29 QStringList{
"Sinusx curve (*.sx)"},
34 bool& exclusive)
const {
45 name.replace(
' ',
'_');
56 std::vector<ccPolyline*> profiles;
59 profiles.push_back(
static_cast<ccPolyline*
>(entity));
67 }
catch (
const std::bad_alloc&) {
75 if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
78 QTextStream outFile(&file);
79 static const int s_precision = 12;
80 outFile.setRealNumberNotation(QTextStream::FixedNotation);
81 outFile.setRealNumberPrecision(s_precision);
89 for (
size_t i = 0; i < profiles.size(); ++i) {
91 unsigned vertCount = poly ? poly->
size() : 0;
97 : QStringLiteral(
"unnamed")));
114 outFile <<
"CP 1 " << (poly->
isClosed() ? 1 : 0)
116 outFile <<
"CP " << (upDir == 2 ? 0 : (upDir == 1 ? 2 : 1))
119 for (
unsigned j = 0; j < vertCount; ++j) {
123 for (
unsigned k = 0; k < 3; ++k) {
125 if (P->
u[k] >= 0) outFile <<
"+";
126 outFile << QString::number(Pg.
u[k],
'E', s_precision);
154 QTextStream stream(&file);
156 QString currentLine(
"C");
159 unsigned lineNumber = 0;
161 unsigned cpIndex = 0;
164 bool firstVertex =
true;
166 while (!currentLine.isEmpty() && file.error() == QFile::NoError) {
167 currentLine = stream.readLine();
170 if (currentLine.startsWith(
"C ")) {
173 }
else if (currentLine.startsWith(
"B")) {
176 if (currentVertices && currentVertices->
size() != 0 &&
177 currentVertices->
resize(currentVertices->
size()) &&
189 if (tokens.size() < 2 || tokens[1].length() > 1) {
195 QChar curveTypeChar = tokens[1].at(0);
217 if (tokens.size() > 7) {
222 currentPoly =
new ccPolyline(currentVertices);
223 currentPoly->
addChild(currentVertices);
226 }
else if (currentPoly) {
227 if (currentLine.startsWith(
"CN")) {
228 if (currentLine.length() > 3) {
229 QString
name = currentLine.right(currentLine.length() - 3);
232 }
else if (currentLine.startsWith(
"CP")) {
240 bool ok = (tokens.size() == 3);
242 bool ok1 =
true, ok2 =
true;
243 int isConnected = tokens[1].toInt(&ok1);
244 int isClosed = tokens[2].toInt(&ok2);
247 if (isConnected == 0) {
259 QString(
"[SinusX] Line %1 is corrupted "
260 "(expected: 'CP connected_flag "
275 }
else if (curveType ==
CURVE_P) {
280 }
else if (curveType ==
CURVE_N) {
282 bool ok = (tokens.size() == 2);
284 double z = tokens[1].toDouble(&ok);
292 "corrupted (expected: "
293 "'CP const_altitude')")
300 }
else if (curveType ==
CURVE_C) {
302 int skipped = tokens.size() -
304 while (skipped < 16 && !currentLine.isEmpty() &&
305 file.error() == QFile::NoError) {
306 currentLine = stream.readLine();
311 skipped += tokens.size();
313 assert(skipped == 16);
325 bool ok = (tokens.size() == 2);
328 QChar basePlaneChar = tokens[1].at(0);
329 if (basePlaneChar ==
'0')
331 else if (basePlaneChar ==
'1')
333 else if (basePlaneChar ==
'2')
344 QString(
"[SinusX] Line %1 is corrupted "
345 "(expected: 'CP base_plane')")
358 }
else if (!currentLine.isEmpty()) {
359 assert(currentVertices);
364 bool ok = (tokens.size() == 4);
367 Pd.
x = tokens[0].toDouble(&ok);
369 Pd.
y = tokens[1].toDouble(&ok);
371 Pd.
z = tokens[2].toDouble(&ok);
374 if (currentVertices->
size() ==
377 currentVertices->
size() + 10)) {
385 bool preserveCoordinateShift =
true;
388 preserveCoordinateShift,
390 if (preserveCoordinateShift) {
399 "[SinusX::loadFile] Polyline "
400 "has been recentered! "
401 "Translation: (%.2f ; %.2f ; "
403 Pshift.
x, Pshift.
y, Pshift.
z);
415 "(expected: 'X Y Z Key ...')")
426 if (currentVertices && currentVertices->
size() != 0 &&
427 currentVertices->
resize(currentVertices->
size()) &&
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
CC_FILE_ERROR
Typical I/O filter errors.
@ CC_FERR_NOT_ENOUGH_MEMORY
QStringList qtCompatSplitRegex(const QString &str, const QString &pattern, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
QString MakeSinusxName(QString name)
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static constexpr float DEFAULT_PRIORITY
static bool HandleGlobalShift(const CCVector3d &P, CCVector3d &Pshift, bool &preserveCoordinateShift, LoadParameters &loadParameters, bool useInputCoordinatesShiftIfPossible=false)
Shortcut to the ecvGlobalShiftManager mechanism specific for files.
virtual bool canSave(CV_CLASS_ENUM type, bool &multiple, bool &exclusive) const override
Returns whether this I/O filter can save the specified type of entity.
virtual CC_FILE_ERROR loadFile(const QString &filename, ccHObject &container, LoadParameters ¶meters) override
Loads one or more entities from a file.
virtual CC_FILE_ERROR saveToFile(ccHObject *entity, const QString &filename, const SaveParameters ¶meters) override
Saves an entity (or a group of) to a file.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
virtual void setVisible(bool state)
Sets entity visibility.
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
virtual QString getName() const
Returns object name.
void setMetaData(const QString &key, const QVariant &data)
Sets a meta-data element.
bool isA(CV_CLASS_ENUM type) const
QVariant getMetaData(const QString &key) const
Returns a given associated meta data.
bool hasMetaData(const QString &key) const
Returns whether a meta-data element with the given key exists or not.
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.
bool resize(unsigned numberOfPoints) override
Resizes all the active features arrays.
virtual void setGlobalShift(const CCVector3d &shift) override
Sets shift applied to original coordinates (information storage only)
static QString MetaKeyUpDir()
bool is2DMode() const
Returns whether the polyline is considered as 2D or 3D.
static QString MetaKeyConstAltitude()
Meta data key: contour plot constant altitude (for contour plots, etc.)
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
unsigned size() const override
unsigned capacity() const
Returns cloud capacity (i.e. reserved size)
void setClosed(bool state)
Sets whether the polyline is closed or not.
bool isClosed() const
Returns whether the polyline is closed or not.
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
unsigned size() const override
Returns the number of points.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
constexpr Qt::SplitBehavior SkipEmptyParts
QTextStream & endl(QTextStream &stream)
Generic loading parameters.
Generic saving parameters.