15 #include <QXmlStreamWriter>
32 const QString& parentName = QString()) {
35 if (parentName.isEmpty()) {
38 name = QStringLiteral(
"%1.%2").arg(parentName, object->
getName());
50 std::vector<ccHObject*> clouds;
52 unsigned int npoints = 0;
55 if (npoints <= p->
size()) {
71 *out <<
object->getMetaData(
"Strike").toString() <<
","
72 <<
object->getMetaData(
"Dip").toString() <<
","
73 <<
object->getMetaData(
"DipDir").toString() <<
",";
74 *out <<
object->getMetaData(
"Cx").toString() <<
","
75 <<
object->getMetaData(
"Cy").toString() <<
","
76 <<
object->getMetaData(
"Cz").toString() <<
",";
77 *out <<
object->getMetaData(
"Nx").toString() <<
","
78 <<
object->getMetaData(
"Ny").toString() <<
","
79 <<
object->getMetaData(
"Nz").toString() <<
",";
80 *out <<
object->getMetaData(
"Radius").toString() <<
","
81 <<
object->getMetaData(
"RMS").toString() <<
",";
87 *out << G.
x <<
"," << G.
y <<
"," << G.
z <<
",";
104 if (N.z < 0.0) N *= -1.0;
115 *out << strike <<
"," << dip <<
"," << dipdir
117 *out << L.
x <<
"," << L.
y <<
"," << L.
z <<
",";
118 *out << N.x <<
"," << N.y <<
"," << N.z <<
",";
136 for (
unsigned i = 0; i <
object->getChildrenNumber(); i++) {
138 n += _writePlanes(rootObject, o, out,
name);
146 const QString& parentName = QString()) {
149 if (parentName.isEmpty()) {
150 name = QStringLiteral(
"%1").arg(object->
getName());
152 name = QStringLiteral(
"%1.%2").arg(parentName, object->
getName());
165 int tID =
object->getUniqueID();
166 if (p->
size() >= 2) {
171 for (
unsigned i = 1; i < p->
size(); i++) {
186 *out << i - 1 <<
",";
201 for (
unsigned i = 0; i <
object->getChildrenNumber(); i++) {
203 n += _writeTraces(o, out,
name);
211 const QString& parentName = QString(),
212 bool thicknesses =
false) {
215 if (parentName.isEmpty()) {
216 name = QStringLiteral(
"%1").arg(object->
getName());
218 name = QStringLiteral(
"%1.%2").arg(parentName, object->
getName());
223 if (((thicknesses ==
false) &&
225 ((thicknesses ==
true) &&
230 *out <<
object->getMetaData(
"Sx").toString() <<
","
231 <<
object->getMetaData(
"Sy").toString() <<
","
232 <<
object->getMetaData(
"Sz").toString() <<
",";
233 *out <<
object->getMetaData(
"Ex").toString() <<
","
234 <<
object->getMetaData(
"Ey").toString() <<
","
235 <<
object->getMetaData(
"Ez").toString() <<
",";
236 *out <<
object->getMetaData(
"Trend").toString() <<
","
237 <<
object->getMetaData(
"Plunge").toString() <<
","
243 for (
unsigned i = 0; i <
object->getChildrenNumber(); i++) {
245 n += _writeLineations(o, out,
name, thicknesses);
268 *out <<
"<polyline fill=\"none\" stroke=\"black\" points=\"";
271 for (
unsigned i = 0; i < line->
size(); i++) {
277 cameraParams.
project(P, coords2D);
280 *out << QString::asprintf(
281 "%.3f,%.3f ", coords2D.
x * zoom,
293 for (
unsigned i = 0; i <
object->getChildrenNumber(); i++) {
294 n += _writeTracesSVG(cameraParams, object->
getChild(i), out,
height,
302 int _writeObjectXML(
ccHObject*
object, QXmlStreamWriter* out) {
307 out->writeStartElement(
"GEO_OBJECT");
310 out->writeStartElement(
"PLANE");
313 out->writeStartElement(
"TRACE");
316 out->writeStartElement(
"THICKNESS");
318 out->writeStartElement(
"SNE");
321 out->writeStartElement(
"LINEATION");
323 out->writeStartElement(
"CLOUD");
327 out->writeStartElement(
"POLYLINE");
330 out->writeStartElement(
335 out->writeStartElement(
"FACET");
338 out->writeStartElement(
"OBJECT");
342 out->writeAttribute(
"name", object->
getName());
343 out->writeAttribute(
"id", QString::asprintf(
"%d", object->
getUniqueID()));
346 const auto& metaData =
object->metaData();
348 for (
const auto& key : metaData.keys()) {
349 out->writeTextElement(key, metaData.value(key).toString());
357 out->writeTextElement(
368 const auto& tempMetaData = temp->
metaData();
370 for (
const auto& key : tempMetaData.keys()) {
371 out->writeTextElement(key, tempMetaData.value(key).toString());
385 trace =
static_cast<ccTrace*
>(object);
408 bool hasNormals =
false;
410 if (poly->
size() >= 2) {
412 for (
unsigned i = 1; i < poly->
size(); i++) {
418 x += QString::asprintf(
"%f,", p1.
x);
419 y += QString::asprintf(
"%f,", p1.
y);
420 z += QString::asprintf(
"%f,", p1.
z);
427 cost += QString::asprintf(
"%d,", c);
431 nx += QString::asprintf(
"%f,", n1.
x);
432 ny += QString::asprintf(
"%f,", n1.
y);
433 nz += QString::asprintf(
"%f,", n1.
z);
434 if (!hasNormals && !(n1.
x == 0 && n1.
y == 0 && n1.
z == 0)) {
443 x += QString::asprintf(
"%f", p2.
x);
444 y += QString::asprintf(
"%f", p2.
y);
445 z += QString::asprintf(
"%f", p2.
z);
448 nx += QString::asprintf(
"%f", n2.
x);
449 ny += QString::asprintf(
"%f", n2.
y);
450 nz += QString::asprintf(
"%f", n2.
z);
454 cost += QStringLiteral(
"0");
461 wIDs += QString::asprintf(
"%d,", trace->
getWaypoint(w));
471 for (; i < trace->
size(); i++) {
478 w_local_ids += QString::asprintf(
"%d,", i);
483 out->writeStartElement(
"POINTS");
484 out->writeAttribute(
"count", QString::asprintf(
"%d", poly->
size()));
487 out->writeAttribute(
"normals",
"True");
489 out->writeAttribute(
"normals",
"False");
492 out->writeTextElement(
"x", x);
493 out->writeTextElement(
"y", y);
494 out->writeTextElement(
"z", z);
497 out->writeTextElement(
"nx", nx);
498 out->writeTextElement(
"ny", ny);
499 out->writeTextElement(
"nz", nz);
504 out->writeTextElement(
"cost", cost);
505 out->writeTextElement(
"control_point_cloud_ids", wIDs);
506 out->writeTextElement(
"control_point_local_ids", w_local_ids);
510 out->writeEndElement();
517 out->writeTextElement(
"GLOBAL_SCALE",
519 out->writeTextElement(
521 out->writeTextElement(
523 out->writeTextElement(
529 out->writeStartElement(
"POINTS");
530 out->writeAttribute(
"count",
531 QString::asprintf(
"%d", cloud->
size()));
553 for (
unsigned p = 0; p < cloud->
size(); p++) {
554 x += QString::asprintf(
"%f,", cloud->
getPoint(p)->
x);
555 y += QString::asprintf(
"%f,", cloud->
getPoint(p)->
y);
556 z += QString::asprintf(
"%f,", cloud->
getPoint(p)->
z);
560 weight += QString::asprintf(
"%f,", wSF->
getValue(p));
561 trend += QString::asprintf(
"%f,", trendSF->
getValue(p));
562 plunge += QString::asprintf(
"%f,", plungeSF->
getValue(p));
567 thickness += QString::asprintf(
"%f,", tSF->
getValue(p));
572 out->writeTextElement(
"x", x);
573 out->writeTextElement(
"y", y);
574 out->writeTextElement(
"z", z);
575 out->writeTextElement(
"nx", nx);
576 out->writeTextElement(
"ny", ny);
577 out->writeTextElement(
"nz", nz);
578 out->writeTextElement(
"weight", weight);
579 out->writeTextElement(
"trend", trend);
580 out->writeTextElement(
"plunge", plunge);
581 if (tSF !=
nullptr) {
582 out->writeTextElement(
"thickness", thickness);
586 out->writeEndElement();
594 out->writeTextElement(
"Nx", QString::asprintf(
"%f", f->
getNormal().
x));
595 out->writeTextElement(
"Ny", QString::asprintf(
"%f", f->
getNormal().
y));
596 out->writeTextElement(
"Nz", QString::asprintf(
"%f", f->
getNormal().
z));
597 out->writeTextElement(
"Cx", QString::asprintf(
"%f", f->
getCenter().
x));
598 out->writeTextElement(
"Cy", QString::asprintf(
"%f", f->
getCenter().
y));
599 out->writeTextElement(
"Cz", QString::asprintf(
"%f", f->
getCenter().
z));
600 out->writeTextElement(
"rms", QString::asprintf(
"%f", f->
getRMS()));
601 out->writeTextElement(
"surface",
606 for (
unsigned i = 0; i <
object->getChildrenNumber(); i++) {
607 n += _writeObjectXML(object->
getChild(i), out);
611 out->writeEndElement();
632 QString baseName = fi.absolutePath() +
"/" + fi.completeBaseName();
633 QString ext = fi.suffix();
634 if (!ext.isEmpty()) {
637 QString plane_fn = baseName + QStringLiteral(
"_planes") + ext;
638 QString trace_fn = baseName + QStringLiteral(
"_traces") + ext;
639 QString lineation_fn = baseName + QStringLiteral(
"_lineations") + ext;
640 QString thickness_fn = baseName + QStringLiteral(
"_thickness") + ext;
643 QFile plane_file(plane_fn);
644 QFile trace_file(trace_fn);
645 QFile lineation_file(lineation_fn);
646 QFile thickness_file(thickness_fn);
649 if (plane_file.open(QIODevice::WriteOnly) &&
650 trace_file.open(QIODevice::WriteOnly) &&
651 lineation_file.open(QIODevice::WriteOnly) &&
652 thickness_file.open(QIODevice::WriteOnly)) {
654 QTextStream plane_stream(&plane_file);
655 QTextStream trace_stream(&trace_file);
656 QTextStream lineation_stream(&lineation_file);
657 QTextStream thickness_stream(&thickness_file);
660 plane_stream <<
"Name,Strike,Dip,Dip_Dir,Cx,Cy,Cz,Nx,Ny,Nz,Sample_"
661 "Radius,RMS,Gx,Gy,Gz,Length"
663 trace_stream <<
"Name,Trace_id,Point_id,Start_x,Start_y,Start_z,End_x,"
664 "End_y,End_z,Cost,Cost_Mode"
666 lineation_stream <<
"Name,Sx,Sy,Sz,Ex,Ey,Ez,Trend,Plunge,Length"
668 thickness_stream <<
"Name,Sx,Sy,Sz,Ex,Ey,Ez,Trend,Plunge,Thickness"
674 for (
unsigned i = 0; i < app->
dbRootObject()->getChildrenNumber();
679 planes += _writePlanes(rootObject, o, &plane_stream);
680 traces += _writeTraces(o, &trace_stream);
682 _writeLineations(o, &lineation_stream, QString(),
false);
684 _writeLineations(o, &thickness_stream, QString(),
true);
688 plane_stream.flush();
690 trace_stream.flush();
692 lineation_stream.flush();
693 lineation_file.close();
694 thickness_stream.flush();
695 thickness_file.close();
699 app->
dispToConsole(
"[ccCompass] Successfully exported plane data.",
707 app->
dispToConsole(
"[ccCompass] Successfully exported trace data.",
716 "[ccCompass] Successfully exported lineation data.",
721 lineation_file.remove();
725 "[ccCompass] Successfully exported thickness data.",
730 thickness_file.remove();
734 "[ccCompass] Could not open output files... ensure CC has "
735 "write access to this location.",
742 std::vector<ccHObject*>
749 if (o->isVisible()) {
751 o->setVisible(
false);
759 QString pngFile = QString(
"%1/%2.png")
760 .arg(fileInfo.absolutePath())
761 .arg(fileInfo.baseName());
771 if (!img.load(pngFile)) {
772 QFile(pngFile).remove();
778 bu.open(QIODevice::WriteOnly);
779 img.save(&bu,
"PNG");
781 QFile(pngFile).remove();
786 if (svg_file.open(QIODevice::WriteOnly)) {
787 QTextStream svg_stream(&svg_file);
796 svg_stream << QString::asprintf(
"<svg width=\"%d\" height=\"%d\">",
801 svg_stream << QString::asprintf(
802 "<image height = \"%d\" width = \"%d\" "
803 "xlink:href = \"data:image/png;base64,",
830 "[ccCompass] Successfully saved %d polylines to .svg file.",
836 "[ccCompass] Could not write polylines to .svg - no "
847 if (file.open(QIODevice::WriteOnly))
849 QXmlStreamWriter xmlWriter(&file);
851 xmlWriter.setAutoFormatting(
true);
852 xmlWriter.writeStartDocument();
867 _writeObjectXML(rootObject, &xmlWriter);
870 xmlWriter.writeEndDocument();
877 "[ccCompass] Successfully exported data-tree to xml.",
881 "[ccCompass] Could not open output files... ensure CC has "
882 "write access to this location.",
cmdLineReadable * params[]
virtual bool isVisible() const
Returns whether entity is visible or not.
double getSurface() const
Returns associated surface area.
CCVector3 getNormal() const override
Returns the entity normal.
double getRMS() const
Returns associated RMS.
const CCVector3 & getCenter() const
Returns the facet center.
static bool isFitPlane(ccHObject *object)
Vector3Tpl< T > getTranslationAsVec3D() const
Returns a copy of the translation as a CCVector3.
virtual ccGLMatrix & getTransformation()
Returns the transformation that is currently applied to the vertices.
static bool isGeoObject(ccHObject *object)
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
unsigned filterChildren(Container &filteredChildren, bool recursive=false, CV_CLASS_ENUM filter=CV_TYPES::OBJECT, bool strict=false) const
Collects the children corresponding to a certain pattern.
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
ccHObject * getChild(unsigned childPos) const
Returns the ith child.
static bool isLineation(ccHObject *obj)
static void ConvertNormalToStrikeAndDip(const CCVector3 &N, PointCoordinateType &strike_deg, PointCoordinateType &dip_deg)
static void ConvertNormalToDipAndDipDir(const CCVector3 &N, PointCoordinateType &dip_deg, PointCoordinateType &dipDir_deg)
Converts a normal vector to geological 'dip direction & dip' parameters.
const QVariantMap & metaData() const
Returns meta-data map (const only)
virtual QString getName() const
Returns object name.
virtual unsigned getUniqueID() const
Returns object unique ID.
bool isA(CV_CLASS_ENUM type) const
QVariant getMetaData(const QString &key) const
Returns a given associated meta data.
bool isKindOf(CV_CLASS_ENUM type) const
CCVector3 getNormal() const override
Returns the entity normal.
PointCoordinateType getXWidth() const
Returns 'X' width.
PointCoordinateType getYWidth() const
Returns 'Y' width.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
const CCVector3 & getPointNormal(unsigned pointIndex) const override
Returns normal corresponding to a given point.
static bool isSNECloud(ccHObject *obj)
CCVector3d toGlobal3d(const Vector3Tpl< T > &Plocal) const
Returns the point back-projected into the original coordinates system.
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
static bool isThickness(ccHObject *obj)
size_t waypoint_count() const
static bool isTrace(ccHObject *object)
CCVector3f getPointNormal(int pointIdx)
int getSegmentCost(int p1, int p2)
int getScalarFieldIndexByName(const char *name) const
Returns the index of a scalar field represented by its name.
ScalarField * getScalarField(int index) const
Returns a pointer to a specific scalar field.
unsigned size() const override
const CCVector3 * getPoint(unsigned index) const override
unsigned size() const override
Returns the number of points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
A simple scalar field (to be associated to a point cloud)
ScalarType & getValue(std::size_t index)
Main application interface (for plugins)
virtual ccHObject * dbRootObject()=0
Returns DB root (as a ccHObject)
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
__host__ __device__ int2 abs(int2 v)
QTextStream & endl(QTextStream &stream)
void saveSVG(ecvMainAppInterface *app, const QString &filename, float zoom)
void saveCSV(ecvMainAppInterface *app, const QString &filename)
void saveXML(ecvMainAppInterface *app, const QString &filename)
OpenGL camera parameters.
bool project(const CCVector3d &input3D, CCVector3d &output2D, bool *inFrustum=nullptr) const
Projects a 3D point in 2D (+ normalized 'z' coordinate)