@@ -698,224 +698,215 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
698
698
// depthIntegrateNormals();
699
699
700
700
}
701
- bool Depthmap::loadText (const char *textPath, const char *outputPath ){
701
+ void Depthmap::loadPointCloud (const char *textPath, std::vector< float > &points ){
702
702
703
703
// apri file di testo e scarta tutto quello che non è un numero. fai un char vettore di punti
704
704
QFile file (textPath);
705
705
if (!file.open (QIODevice::ReadOnly | QIODevice::Text)) {
706
- cerr << " Error opening input file: " << textPath << endl;
707
- return false ;
706
+ throw QString (" Error opening input file: " )+ textPath;
708
707
}
709
708
710
709
QTextStream in (&file);
711
- QVector<QString> validLines;
712
710
713
711
while (!in.atEnd ()) {
714
712
QString line = in.readLine ().trimmed ();
715
713
QStringList parts = line.split (QRegularExpression (" \\ s+" ), Qt::SkipEmptyParts);
716
- if (line.isEmpty () || !line[0 ].isDigit () && line[0 ] != ' -' && line[0 ] != ' +' ) {
714
+ if (line.isEmpty () || ( !line[0 ].isDigit () && line[0 ] != ' -' && line[0 ] != ' +' ) || parts. size () != 6 ) {
717
715
continue ;
718
716
}
719
- QVector<QString> numbers;
720
717
718
+ // check the line if the line not begin with float number break
721
719
bool isValid = true ;
722
- for (int i = 0 ; i < 3 && i < parts.size (); ++i) {
720
+ float v[3 ];
721
+ for (int i = 0 ; i < 3 ; ++i) {
723
722
bool isNumber = false ;
724
- parts[i].toFloat (&isNumber);
723
+ v[i] = parts[i].toFloat (&isNumber);
725
724
if (!isNumber) {
726
725
isValid = false ;
727
726
break ;
728
727
}
729
728
}
730
- if (isValid) {
731
- for (const QString &part : parts) {
732
- bool isNumber = false ;
733
- part.toFloat (&isNumber);
734
- if (isNumber) {
735
- numbers.append (part);
736
- }
737
- }
738
- if (!numbers.isEmpty ()) {
739
- validLines.append (numbers.join (" " ));
740
- }
729
+ if (!isValid)
730
+ throw QString (" Invalide ply" );
731
+
732
+ for (int i = 0 ; i < 3 ; ++i){
733
+ points.push_back (v[i]);
741
734
}
742
735
}
743
736
744
- QFile outFile (outputPath);
745
- if (!outFile.open (QIODevice::WriteOnly | QIODevice::Text)) {
746
- cerr << " Errore nell'aprire il file di output: " << outputPath << endl;
747
- return false ;
748
- }
749
- QTextStream out (&outFile);
750
- for (const QString &line : validLines) {
751
- out << line << " \n " ;
752
- }
737
+ }
738
+
739
+ // funzione inversa da 3d a xyh; xy z=0 h? pixel,pixel, h
740
+ void Depthmap::t3DToCamera (P){
741
+ // xyz coord 3d fai l'inversa: aperi txt, x e y. prendi funz 3d la trosformi in x y e h e poi applichi quella già fatta camerato3d e deve venire uguale
742
+ // poi prendi apericloud e vedi se coincide con la depth
743
+ // 2. scrivi la funzione inversa da un punto in 3d ci trova la x e la y in pixel e la h dalla depth del mic mac
744
+ // 3. verifica se la h trovata per i punti di aperi corrisponde all h della depth map
753
745
754
- cout << " Punti salvati in " << outputPath << endl;
755
746
756
- return true ;
757
747
}
758
748
759
749
750
+ // take the x=160,14 e y=140
751
+ // the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.
760
752
761
- // take the x=160,14 e y=140
762
- // the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.
753
+ /* ---------------------------------------------------------------------------------------------------------------------------*/
754
+ // start OrthoDepthMap class
755
+ // MicMac depth and features
763
756
764
- /* ---------------------------------------------------------------------------------------------------------------------------*/
765
- // start OrthoDepthMap class
757
+ bool OrthoDepthmap::loadXml (const char *xmlPath){
758
+ // depthmap in Malt Z deZoom ecc
759
+ QFile file (xmlPath);
760
+ if (!file.open (QIODevice::ReadOnly)) {
761
+ cerr << " Cannot open XML file: " << xmlPath << endl;
762
+ return false ;
763
+ }
766
764
767
- bool OrthoDepthmap::loadXml (const char *xmlPath){
768
- // depthmap in Malt Z deZoom ecc
769
- QFile file (xmlPath);
770
- if (!file.open (QIODevice::ReadOnly)) {
771
- cerr << " Cannot open XML file: " << xmlPath << endl;
772
- return false ;
773
- }
765
+ QDomDocument doc;
766
+ doc.setContent (&file);
774
767
775
- QDomDocument doc;
776
- doc.setContent (&file);
768
+ QDomElement root = doc.documentElement ();
769
+ QDomNodeList originePlaniNodes = root.elementsByTagName (" OriginePlani" );
770
+ QDomNodeList resolutionPlaniNodes = root.elementsByTagName (" ResolutionPlani" );
771
+ QDomNodeList origineAltiNodes = root.elementsByTagName (" OrigineAlti" );
772
+ QDomNodeList resolutionAltiNodes = root.elementsByTagName (" ResolutionAlti" );
777
773
778
- QDomElement root = doc.documentElement ();
779
- QDomNodeList originePlaniNodes = root.elementsByTagName (" OriginePlani" );
780
- QDomNodeList resolutionPlaniNodes = root.elementsByTagName (" ResolutionPlani" );
781
- QDomNodeList origineAltiNodes = root.elementsByTagName (" OrigineAlti" );
782
- QDomNodeList resolutionAltiNodes = root.elementsByTagName (" ResolutionAlti" );
783
774
775
+ if (originePlaniNodes.isEmpty () || resolutionPlaniNodes.isEmpty () ||
776
+ origineAltiNodes.isEmpty () || resolutionAltiNodes.isEmpty ()) {
777
+ cerr << " OriginePlani, ResolutionPlani, OrigineAlti, or ResolutionAlti not found in XML." << endl;
778
+ return false ;
784
779
785
- if (originePlaniNodes.isEmpty () || resolutionPlaniNodes.isEmpty () ||
786
- origineAltiNodes.isEmpty () || resolutionAltiNodes.isEmpty ()) {
787
- cerr << " OriginePlani, ResolutionPlani, OrigineAlti, or ResolutionAlti not found in XML." << endl;
788
- return false ;
780
+ }
789
781
790
- }
782
+ // <OriginePlani>-2.72 3.04</OriginePlani>
783
+ QStringList origineValues = originePlaniNodes.at (0 ).toElement ().text ().split (" " );
784
+ if (origineValues.size () >= 2 ) {
785
+ origin[0 ] = origineValues.at (0 ).toFloat ();
786
+ origin[1 ] = origineValues.at (1 ).toFloat ();
787
+ }
788
+ QStringList resolutionValues = resolutionPlaniNodes.at (0 ).toElement ().text ().split (" " );
789
+ if (resolutionValues.size () >= 2 ) {
790
+ resolution[0 ] = resolutionValues.at (0 ).toFloat ();
791
+ resolution[1 ] = resolutionValues.at (1 ).toFloat ();
792
+ }
791
793
792
- // <OriginePlani>-2.72 3.04</OriginePlani>
793
- QStringList origineValues = originePlaniNodes.at (0 ).toElement ().text ().split (" " );
794
- if (origineValues.size () >= 2 ) {
795
- origin[0 ] = origineValues.at (0 ).toFloat ();
796
- origin[1 ] = origineValues.at (1 ).toFloat ();
797
- }
798
- QStringList resolutionValues = resolutionPlaniNodes.at (0 ).toElement ().text ().split (" " );
799
- if (resolutionValues.size () >= 2 ) {
800
- resolution[0 ] = resolutionValues.at (0 ).toFloat ();
801
- resolution[1 ] = resolutionValues.at (1 ).toFloat ();
802
- }
794
+ // <ResolutionPlani>0.128 -0.128</ResolutionPlani> passo
803
795
804
- // <ResolutionPlani>0.128 -0.128</ResolutionPlani> passo
796
+ // resAlti e oriAlti
797
+ origin[2 ] = origineAltiNodes.at (0 ).toElement ().text ().toFloat ();
798
+ resolution[2 ] = resolutionAltiNodes.at (0 ).toElement ().text ().toFloat ();
805
799
806
- // resAlti e oriAlti
807
- origin[ 2 ] = origineAltiNodes. at ( 0 ). toElement (). text (). toFloat ();
808
- resolution[ 2 ] = resolutionAltiNodes. at ( 0 ). toElement (). text (). toFloat ();
800
+ return true ;
801
+
802
+ }
809
803
810
- return true ;
804
+ bool OrthoDepthmap::load ( const char *depth_path, const char *mask_path){
811
805
806
+ QString qdepth_path = QString (depth_path);
807
+ if (!loadDepth (qdepth_path.toStdString ().c_str ())){
808
+ cerr << " Failed to load ortho depth tiff file: " << qdepth_path.toStdString () << endl;
809
+ return false ;
812
810
}
813
811
814
- bool OrthoDepthmap::load (const char *depth_path, const char *mask_path){
812
+ QString qmask_path = QString (mask_path);
813
+ if (!loadMask (qmask_path.toStdString ().c_str ())){
814
+ cerr << " Failed to load ortho mask tiff file: " << qmask_path.toStdString () << endl;
815
+ return false ;
816
+ }
815
817
816
- QString qdepth_path = QString (depth_path);
817
- if (!loadDepth (qdepth_path.toStdString ().c_str ())){
818
- cerr << " Failed to load ortho depth tiff file: " << qdepth_path.toStdString () << endl;
819
- return false ;
820
- }
818
+ QString xmlPath = qdepth_path.left (qdepth_path.lastIndexOf (' .' )) + " .xml" ;
819
+ if (!loadXml (xmlPath.toStdString ().c_str ())) {
820
+ cerr << " Failed to load XML file: " << xmlPath.toStdString () << endl;
821
+ return false ;
822
+ }
823
+ return true ;
821
824
822
- QString qmask_path = QString (mask_path);
823
- if (!loadMask (qmask_path.toStdString ().c_str ())){
824
- cerr << " Failed to load ortho mask tiff file: " << qmask_path.toStdString () << endl;
825
- return false ;
826
- }
825
+ }
826
+ Eigen::Vector3f OrthoDepthmap::pixelToRealCoordinates (int pixelX, int pixelY, float pixelZ) {
827
827
828
- QString xmlPath = qdepth_path.left (qdepth_path.lastIndexOf (' .' )) + " .xml" ;
829
- if (!loadXml (xmlPath.toStdString ().c_str ())) {
830
- cerr << " Failed to load XML file: " << xmlPath.toStdString () << endl;
831
- return false ;
832
- }
833
- return true ;
828
+ // converto in punti 3d. origine dell'img + passoX * 160x
829
+ float realX = origin[0 ] + resolution[0 ] * pixelX;
830
+ float realY = origin[1 ] + resolution[1 ] * pixelY;
831
+ float realZ = origin[2 ] + resolution[2 ] * pixelZ;
834
832
835
- }
836
- Eigen::Vector3f OrthoDepthmap::pixelToRealCoordinates ( int pixelX, int pixelY, float pixelZ) {
833
+ return Eigen::Vector3f (realX, realY, realZ);
834
+ }
837
835
838
- // converto in punti 3d. origine dell'img + passoX * 160x
839
- float realX = origin[0 ] + resolution[0 ] * pixelX;
840
- float realY = realY = origin[1 ] + resolution[1 ] * pixelY;
841
- float realZ = origin[2 ] + resolution[2 ] * pixelZ;
842
836
843
- return Eigen::Vector3f (realX, realY, realZ);
837
+ void OrthoDepthmap::saveObj (const char *filename){
838
+ // use QFile for write the file and after QTextStream
839
+ QFile file (filename);
840
+ if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) {
841
+ qDebug () << " Cannot open file for writing:" << filename;
842
+ return ;
844
843
}
844
+ QTextStream out (&file);
845
845
846
-
847
- void OrthoDepthmap::saveObj (const char *filename){
848
- // use QFile for write the file and after QTextStream
849
- QFile file (filename);
850
- if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) {
851
- qDebug () << " Cannot open file for writing:" << filename;
852
- return ;
846
+ for (uint32_t y = 0 ; y < height; y++) {
847
+ for (uint32_t x = 0 ; x < width; x++) {
848
+ float z = elevation[x + y * width];
849
+ Eigen::Vector3f realPos = pixelToRealCoordinates (x, y, z);
850
+ // obj coordinates of a point v first string v second string etc. and then exit call in main
851
+ out << " v " << realPos.x () << " " << realPos.y () << " " << realPos.z () << " \n " ;
853
852
}
854
- QTextStream out (&file);
855
-
856
- for (uint32_t y = 0 ; y < height; y++) {
857
- for (uint32_t x = 0 ; x < width; x++) {
858
- float z = elevation[x + y * width];
859
- Eigen::Vector3f realPos = pixelToRealCoordinates (x, y, z);
860
- // obj coordinates of a point v first string v second string etc. and then exit call in main
861
- out << " v " << realPos.x () << " " << realPos.y () << " " << realPos.z () << " \n " ;
862
- }
853
+ }
854
+ }
855
+ void OrthoDepthmap::projectToCameraDepthMap (const Camera& camera, const QString& outputPath) {
856
+
857
+ QImage depthMapImage (camera.width , camera.height , QImage::Format_RGB888);
858
+ depthMapImage.fill (qRgb (0 , 0 , 0 ));
859
+ // find the minimum and maximum for the Z coordinates
860
+ float minZ = std::numeric_limits<float >::max ();
861
+ float maxZ = std::numeric_limits<float >::lowest ();
862
+ for (int y = 0 ; y < height; y++) {
863
+ for (int x = 0 ; x < width; x++) {
864
+ float pixelZ = elevation[x + y * width];
865
+
866
+ Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
867
+ Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
868
+ minZ = std::min (minZ, imageCoords[2 ]);
869
+ maxZ = std::max (maxZ, imageCoords[2 ]);
870
+
863
871
}
864
872
}
865
- void OrthoDepthmap::projectToCameraDepthMap (const Camera& camera, const QString& outputPath) {
873
+ if (minZ >= maxZ) {
874
+ qWarning (" MinZ and MaxZ invalid. Skip depth map generation." );
875
+ return ;
876
+ }
877
+ for (int y = 0 ; y < height; y++) {
878
+ for (int x = 0 ; x < width; x++) {
879
+ if (mask[x+ y *width]==0 .0f )
880
+ continue ;
881
+ float pixelZ = elevation[x + y * width];
866
882
867
- QImage depthMapImage (camera.width , camera.height , QImage::Format_RGB888);
868
- depthMapImage.fill (qRgb (0 , 0 , 0 ));
869
- // find the minimum and maximum for the Z coordinates
870
- float minZ = std::numeric_limits<float >::max ();
871
- float maxZ = std::numeric_limits<float >::lowest ();
872
- for (int y = 0 ; y < height; y++) {
873
- for (int x = 0 ; x < width; x++) {
874
- float pixelZ = elevation[x + y * width];
883
+ Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
884
+ Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
885
+ int pixelValue = (int )round (((imageCoords[2 ] - minZ) / (maxZ - minZ)) * 255 );
886
+ pixelValue = std::min (std::max (pixelValue, 0 ), 255 );
875
887
876
- Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
877
- Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
878
- minZ = std::min (minZ, imageCoords[2 ]);
879
- maxZ = std::max (maxZ, imageCoords[2 ]);
888
+ int imageX = (int )round (imageCoords[0 ]);
889
+ int imageY = (int )round (imageCoords[1 ]);
880
890
891
+ if (imageX >= 0 && imageX < camera.width && imageY >= 0 && imageY < camera.height ) {
892
+ depthMapImage.setPixel (imageX, imageY, qRgb (pixelValue, pixelValue, pixelValue));
893
+ // cout << "Pixel projected (" << x << ", " << y << ") -> (" << imageX << ", " << imageY << "), Z = "
894
+ // << pixelZ << ", pixelValue = " << pixelValue << endl;
881
895
}
882
896
}
883
- if (minZ >= maxZ) {
884
- qWarning (" MinZ and MaxZ invalid. Skip depth map generation." );
885
- return ;
886
- }
887
- for (int y = 0 ; y < height; y++) {
888
- for (int x = 0 ; x < width; x++) {
889
- if (mask[x+ y *width]==0 .0f )
890
- continue ;
891
- float pixelZ = elevation[x + y * width];
892
-
893
- Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
894
- Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
895
- int pixelValue = (int )round (((imageCoords[2 ] - minZ) / (maxZ - minZ)) * 255 );
896
- pixelValue = std::min (std::max (pixelValue, 0 ), 255 );
897
-
898
- int imageX = (int )round (imageCoords[0 ]);
899
- int imageY = (int )round (imageCoords[1 ]);
900
-
901
- if (imageX >= 0 && imageX < camera.width && imageY >= 0 && imageY < camera.height ) {
902
- depthMapImage.setPixel (imageX, imageY, qRgb (pixelValue, pixelValue, pixelValue));
903
- // cout << "Pixel projected (" << x << ", " << y << ") -> (" << imageX << ", " << imageY << "), Z = "
904
- // << pixelZ << ", pixelValue = " << pixelValue << endl;
905
- }
906
- }
907
- }
908
- depthMapImage.save (outputPath, " png" );
909
- }
910
- void OrthoDepthmap::resizeNormals (int factorPowerOfTwo, int step) {
911
- int factor = 1 << factorPowerOfTwo;
912
- Depthmap::resizeNormals (factorPowerOfTwo, step);
913
- resolution *= factor;
914
- origin /= factor;
915
897
}
898
+ depthMapImage.save (outputPath, " png" );
899
+ }
900
+ void OrthoDepthmap::resizeNormals (int factorPowerOfTwo, int step) {
901
+ int factor = 1 << factorPowerOfTwo;
902
+ Depthmap::resizeNormals (factorPowerOfTwo, step);
903
+ resolution *= factor;
904
+ origin /= factor;
905
+ }
916
906
917
907
918
908
919
- /* ---------------------------------------------------------------------------------------------------------------------------*/
909
+
910
+ /* ---------------------------------------------------------------------------------------------------------------------------*/
920
911
921
912
0 commit comments