Skip to content

Commit b640084

Browse files
author
Erika
committed
added loadText function
1 parent 7181194 commit b640084

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

depthmap/depthmap.cpp

+39-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "depthmap.h"
88
#include "../src/bni_normal_integration.h"
99
#include <QFile>
10+
#include <QRegularExpression>
1011
#include <fstream>
1112

1213
using namespace std;
@@ -697,29 +698,54 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
697698
//depthIntegrateNormals();
698699

699700
}
700-
void Depthmap::sampleDepth() {
701-
std::vector<float> sampledDepths;
702-
float sum = 0.0f;
701+
bool Depthmap::loadPly(const char *textPath, const char *outputPath){
703702

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);
708716

709-
cout << "Sampled Depth at (" << x << ", " << y << "): " << depth << endl;
710717

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+
}
712728
}
713729
}
714730

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);
717734

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;
720743
}
744+
745+
return true;
721746
}
722747

748+
723749
//take the x=160,14 e y=140
724750
//the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.
725751

depthmap/depthmap.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Depthmap {
4141
bool loadDepth(const char *depth_path);
4242
bool loadMask(const char *mask_path);
4343
bool loadNormals(const char *normals_path);
44+
bool loadPly(const char *textPath, const char *outputPath);
4445
void saveDepth(const char *depth_path);
4546
void saveMask(const char *depth_path);
4647
void saveNormals(const char *normals_path);
@@ -50,7 +51,7 @@ class Depthmap {
5051
void computeNormals();
5152
void depthIntegrateNormals();
5253
void resizeNormals(int factorPowerOfTwo, int step = 1);
53-
void sampleDepth();
54+
5455

5556
protected:
5657
bool loadTiff(const char *tiff, std::vector<float> &elevation, uint32_t &w, uint32_t &h);

depthmap/main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ int main(int argc, char *argv[]) {
2424
QString depthmapPath = base + "testcenterRel_copia/photogrammetry/Malt/Z_Num7_DeZoom4_STD-MALT.tif";
2525
QString orientationXmlPath = base + "testcenterRel_copia/photogrammetry/Ori-Relative/Orientation-L05C12.tif.xml";
2626
QString maskPath = base + "testcenterRel_copia/photogrammetry/Malt/Masq_STD-MALT_DeZoom4.tif";
27+
QString plyFile = base +"testcenterRel_copia/photogrammetry/AperiCloud_Relative__mini.ply";
2728
Depthmap depth;
2829

2930
//output
3031
QString outputPath = base + "testcenterRel_copia/photogrammetry/depthmap_projectL05C13.png";
3132
QString output_mask = base + "testcenterRel_copia/photogrammetry/mask_test.tif";
3233
QString output_depth = base + "testcenterRel_copia/photogrammetry/depth_test.tif";
34+
QString output_text = base + "testcenterRel_copia/photogrammetry/point.txt";
3335

3436
OrthoDepthmap ortho;
3537

@@ -43,6 +45,7 @@ int main(int argc, char *argv[]) {
4345

4446
ortho.saveDepth(qPrintable(output_depth));
4547
ortho.saveMask(qPrintable(output_mask));
48+
ortho.loadText(qPrintable(plyFile), qPrintable(output_text));
4649

4750
Camera camera;
4851
camera.loadXml(orientationXmlPath);

0 commit comments

Comments
 (0)