|
7 | 7 | #include "depthmap.h"
|
8 | 8 | #include "../src/bni_normal_integration.h"
|
9 | 9 | #include <QFile>
|
| 10 | +#include <QRegularExpression> |
10 | 11 | #include <fstream>
|
11 | 12 |
|
12 | 13 | using namespace std;
|
@@ -697,29 +698,54 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
|
697 | 698 | //depthIntegrateNormals();
|
698 | 699 |
|
699 | 700 | }
|
700 |
| -void Depthmap::sampleDepth() { |
701 |
| - std::vector<float> sampledDepths; |
702 |
| - float sum = 0.0f; |
| 701 | +bool Depthmap::loadPly(const char *textPath, const char *outputPath){ |
703 | 702 |
|
704 |
| - for (int y = 0; y < height; y += 100) { |
705 |
| - for (int x = 0; x < width; x += 100) { |
706 |
| - float depth = elevation[y * width + x]; |
707 |
| - sampledDepths.push_back(depth); |
| 703 | + //apri file di testo e scarta tutto quello che non è un numero. fai un char vettore di punti |
| 704 | + QFile file(textPath); |
| 705 | + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 706 | + cerr << "Error opening input file: " << textPath << endl; |
| 707 | + return false; |
| 708 | + } |
| 709 | + |
| 710 | + QTextStream in(&file); |
| 711 | + QVector<QString> validLines; |
| 712 | + |
| 713 | + while (!in.atEnd()) { |
| 714 | + QString line = in.readLine().trimmed(); |
| 715 | + QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts); |
708 | 716 |
|
709 |
| - cout << "Sampled Depth at (" << x << ", " << y << "): " << depth << endl; |
710 | 717 |
|
711 |
| - sum += depth; |
| 718 | + if (parts.size() >= 3) { |
| 719 | + bool isNumber1 = false, isNumber2 = false, isNumber3 = false; |
| 720 | + |
| 721 | + parts[0].toDouble(&isNumber1); |
| 722 | + parts[1].toDouble(&isNumber2); |
| 723 | + parts[2].toDouble(&isNumber3); |
| 724 | + |
| 725 | + if (isNumber1 && isNumber2 && isNumber3) { |
| 726 | + validLines.append(line); |
| 727 | + } |
712 | 728 | }
|
713 | 729 | }
|
714 | 730 |
|
715 |
| - float dz = (sampledDepths.size() > 0) ? (sum / sampledDepths.size()) : 0.0f; |
716 |
| - cout << "Average Depth (DZ): " << dz << endl; |
| 731 | + QFile outFile(outputPath); |
| 732 | + if (outFile.open(QIODevice::WriteOnly | QIODevice::Text)) { |
| 733 | + QTextStream out(&outFile); |
717 | 734 |
|
718 |
| - for (int i = 0; i < sampledDepths.size(); i++) { |
719 |
| - cout << "Sampled Depth[" << i << "]: " << sampledDepths[i] << endl; |
| 735 | + for (const QString &line : validLines) { |
| 736 | + out << line << "\n"; |
| 737 | + } |
| 738 | + |
| 739 | + cout << "Punti salvati in " << outputPath << endl; |
| 740 | + } else { |
| 741 | + cerr << "Errore nell'aprire il file di output: " << outputPath << endl; |
| 742 | + return false; |
720 | 743 | }
|
| 744 | + |
| 745 | + return true; |
721 | 746 | }
|
722 | 747 |
|
| 748 | + |
723 | 749 | //take the x=160,14 e y=140
|
724 | 750 | //the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.
|
725 | 751 |
|
|
0 commit comments