00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <qvsfm.h>
00026
00027
00028
00029 bool readNumbersFromTextStream(QTextStream &stream, QVVector &numbers, const int estimatedSize)
00030 {
00031 numbers.clear();
00032 numbers.reserve(estimatedSize);
00033
00034 double sign = +1.0;
00035 int idx = 0;
00036 char buffer[256] = "";
00037
00038 while (not stream.atEnd())
00039 {
00040 char c;
00041 stream >> c;
00042
00043
00044
00045 if ( ( (c >= '0') and (c <= '9') ) or
00046 ( (idx > 0) and (c == 'e') ) or
00047 (c == '.')
00048 )
00049 buffer[idx++] = c;
00050
00051 else if ( c == '#' )
00052 {
00053 while ( (c != '\n') and (not stream.atEnd()) )
00054 stream >> c;
00055
00056 if (stream.atEnd())
00057 break;
00058 }
00059 else
00060 {
00061 buffer[idx] = '\0';
00062
00063 if (idx > 0)
00064 numbers << sign * atof(buffer);
00065
00066 idx = 0;
00067
00068 if (c == '-')
00069 sign = -1.0;
00070 else
00071 sign = +1.0;
00072 }
00073
00074 if(idx >= 256)
00075 {
00076 std::cout << "[readNumbersFromFile] Error: buffer overrun." << std::endl;
00077 exit(0);
00078 }
00079 }
00080
00081 return true;
00082 }
00083
00084
00085
00086
00087 bool readNumbersFromFile(QFile &file, QVVector &numbers, const int estimatedSize)
00088 {
00089 numbers.clear();
00090 numbers.reserve(estimatedSize);
00091
00092 double sign = +1.0;
00093 int idx = 0;
00094 char buffer[256] = "";
00095
00096 while (not file.atEnd())
00097 {
00098 char c;
00099 file.getChar(&c);
00100
00101
00102 if ( ( (c >= '0') and (c <= '9') ) or
00103 ( (idx > 0) and (c == 'e') ) or
00104 (c == '.')
00105 )
00106 buffer[idx++] = c;
00107
00108 else if ( c == '#' )
00109 {
00110 while ( (c != '\n') and (not file.atEnd()) )
00111 file.getChar(&c);
00112 if (file.atEnd())
00113 break;
00114 }
00115 else
00116 {
00117 buffer[idx] = '\0';
00118
00119 if (idx > 0)
00120 numbers << sign * atof(buffer);
00121
00122 idx = 0;
00123
00124 if (c == '-')
00125 sign = -1.0;
00126 else
00127 sign = +1.0;
00128 }
00129
00130 if(idx >= 256)
00131 {
00132 std::cout << "[readNumbersFromFile] Error: buffer overrun." << std::endl;
00133 exit(0);
00134 }
00135 }
00136
00137 return true;
00138 }
00139
00140
00141
00142 bool readNumbersFromFile(const QString fileName, QVVector &numbers, const int estimatedSize)
00143 {
00144 QFile file(fileName);
00145 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00146 {
00147 std::cout << "[readNumbersFromFile] Cannot open file " << qPrintable(fileName) << std::endl;
00148 return false;
00149 }
00150
00151 return readNumbersFromFile(file, numbers, estimatedSize);
00152 }
00153
00154 QVVector readVector(QFile &file)
00155 {
00156 bool ok = false;
00157 while(not file.atEnd())
00158 {
00159 const QString line = file.readLine();
00160 if (line.contains("#"))
00161 continue;
00162
00163 const QStringList stringList = line.split(" ", QString::SkipEmptyParts);
00164
00165 QList<double> vector;
00166 foreach(QString string, stringList)
00167 {
00168 const double value = string.toDouble(&ok);
00169 if (ok)
00170 vector << value;
00171 }
00172 return vector.toVector();
00173 }
00174 return QVVector(0,0.0);
00175 }
00176
00177 QVVector readVector(const QString &line)
00178 {
00179 bool ok = false;
00180 const QStringList stringList = line.split(" ", QString::SkipEmptyParts);
00181
00182 QList<double> vector;
00183 foreach(QString string, stringList)
00184 {
00185 const double value = string.toDouble(&ok);
00186 if (ok)
00187 vector << value;
00188 }
00189 return vector.toVector();
00190 }
00191
00192
00193 QVMatrix readMatrix(const QString fileName)
00194 {
00195 QFile file(fileName);
00196 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00197 return QVMatrix();
00198
00199 QList<QVVector> rows;
00200 while (!file.atEnd())
00201 {
00202 const QString line = file.readLine();
00203 if (line.contains("#"))
00204 continue;
00205
00206 const QStringList stringList = line.split (" ", QString::SkipEmptyParts);
00207
00208 QVVector v;
00209 foreach(QString string, stringList)
00210 {
00211 bool ok = false;
00212 const double value = string.toDouble(&ok);
00213 if (ok)
00214 v << value;
00215 }
00216
00217 rows << v;
00218 }
00219 return QVMatrix(rows);
00220 }
00221
00222 bool readReconstruction_NVM( const QString fileName,
00223 QList<QString> &imageFiles,
00224 QList<QVMatrix> &cameraCalibrationMatrices,
00225 QList<QVCameraPose> &cameraPoses,
00226 QList<QV3DPointF> &points3D,
00227 QList< QColor > &rgbColors,
00228 QList< QHash< int, QPointF> > &pointTrackings)
00229 {
00230 QVVector temp;
00231
00232 imageFiles.clear();
00233 cameraCalibrationMatrices.clear();
00234 cameraPoses.clear();
00235 points3D.clear();
00236 rgbColors.clear();
00237 pointTrackings.clear();
00238
00239 int numline = 0;
00240 std::cout << "[readReconstruction_NVM] Opening file" << std::endl;
00241 QFile file(fileName);
00242 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00243 return false;
00244
00245 const QString line = file.readLine();
00246 if (not line.startsWith("NVM_V3"))
00247 return false;
00248
00249
00250 file.readLine();
00251 temp = readVector(file);
00252 if (temp.count() != 1)
00253 return false;
00254 const int numCameras = temp[0];
00255 std::cout << "[readReconstruction_NVM] Reading " << numCameras << " cameras...";
00256
00257 for (int idx = 0; idx < numCameras; idx++)
00258 {
00259 const QStringList tokens = QString(file.readLine()).split('\t');
00260 if (tokens.count() != 2)
00261 return false;
00262
00263 temp = readVector(tokens[1]);
00264
00265 if (temp.count() != 10)
00266 return false;
00267
00268 imageFiles << tokens[0];
00269 cameraCalibrationMatrices << QVMatrix::cameraCalibrationMatrix(temp[0]);
00270 cameraPoses << QVCameraPose( QVQuaternion(temp[2], temp[3], temp[4], temp[1]), QV3DPointF(temp[5], temp[6], temp[7]));
00271 }
00272
00273 std::cout << "done." << std::endl;
00274
00275
00276 file.readLine();
00277 temp = readVector(file);
00278 if (temp.count() != 1)
00279 return false;
00280 const int numPoints = temp[0];
00281 std::cout << "[readReconstruction_NVM] Reading " << numPoints << " points..." << std::endl;
00282
00283 for(int i = 0; i < numPoints; i++)
00284 {
00285 temp = readVector(file);
00286
00287 points3D << QV3DPointF(temp[0], temp[1], temp[2]);
00288 rgbColors << QColor(temp[3], temp[4], temp[5]);
00289 const int numMeasurements = temp[6];
00290
00291 if(temp.count() - 7 != numMeasurements * 4)
00292 return false;
00293
00294 QHash< int, QPointF> tracking;
00295 for(int j = 7; j < temp.count(); j+=4)
00296 tracking[ temp[j] ] = QPointF(temp[j+2], temp[j+3]);
00297 pointTrackings << tracking;
00298 }
00299
00300 return true;
00301
00302 std::cout << "[readReconstruction_NVM] Readed " << numPoints << " points, " << numCameras << " cameras." << std::endl;
00303 file.close();
00304 return true;
00305 }
00306
00307
00308 bool readReconstruction_BAITL( const QString fileName,
00309 QList<QVMatrix> &cameraCalibrations,
00310 QList<QVCameraPose> &cameraPoses,
00311 QList<QV3DPointF> &points3D,
00312 QList< QColor > &rgbColors,
00313 QList< QHash< int, QPointF> > &pointTrackings)
00314 {
00315 const QVMatrix A1 = QVMatrix::diagonal(QV3DPointF(+1.0, -1.0, +1.0)),
00316 A2 = QVMatrix::diagonal(QV3DPointF(+1.0, +1.0, -1.0)),
00317 A3 = QVMatrix::diagonal(QV3DPointF(-1.0, +1.0, +1.0));
00318
00319 cameraPoses.clear();
00320 points3D.clear();
00321 rgbColors.clear();
00322 pointTrackings.clear();
00323
00324 int numline = 0;
00325 std::cout << "[readReconstruction_BAITL] Opening file" << std::endl;
00326 QFile file(fileName);
00327 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00328 return false;
00329
00330 bool ok = false;
00331 int numCameras = -1, numPoints = -1, numProjections = -1;
00332
00333
00334 while (not ok and not file.atEnd())
00335 {
00336 const QString line = file.readLine();
00337 if (line.contains("#"))
00338 continue;
00339
00340 const QStringList stringList = line.split (" ", QString::SkipEmptyParts);
00341
00342 numCameras = stringList[0].toInt(&ok);
00343 numPoints = stringList[1].toInt(&ok);
00344 numProjections = stringList[2].toInt(&ok);
00345 numline++;
00346 }
00347
00348 const int fractionCameras = numCameras / 7, fractionPoints = numPoints / 7, fractionProjections = numProjections / 7;
00349
00350
00351 for(int i = 0; i < numPoints; i++)
00352 pointTrackings << QHash< int, QPointF>();
00353
00354 std::cout << "[readReconstruction_BAITL] Reading " << numProjections << " projections" << std::endl;
00355 for(int numProjection = 0; numProjection < numProjections; numProjection++)
00356 {
00357 const QVVector line = readVector(file);
00358 numline++;
00359
00360 if (line.count() != 4)
00361 std::cout << "Error: in point projections list." << std::endl;
00362
00363 const int numCamera = line[0], numPoint = line[1];
00364 const QPointF projection(line[2], line[3]);
00365
00366 if (numCamera +1 > numCameras or numCamera < 0)
00367 std::cout << "Error: camera index out of bounds." << std::endl;
00368 if (numPoint +1 > numPoints or numPoint < 0)
00369 std::cout << "Error: point index out of bounds." << std::endl;
00370 pointTrackings[numPoint][numCamera] = -projection;
00371
00372 if ( numProjection % fractionProjections == 0 )
00373 std::cout << "[readReconstruction_BAITL]\t" << int(double(100*numProjection) / double(numProjections)) << "% loaded." << std::endl;
00374 }
00375
00376 QHash<int, int> fileCameraIndexToRealCameraIndex;
00377 std::cout << "[readReconstruction_BAITL] Reading " << numCameras << " cameras" << std::endl;
00378 for(int numCamera = 0; numCamera < numCameras; numCamera++)
00379 {
00380 QVVector rodriguesRotation, cameraCenter;
00381
00382 for(int i = 0; i < 3; i++)
00383 {
00384 rodriguesRotation << readVector(file)[0];
00385 }
00386 numline+=3;
00387
00388 for(int i = 0; i < 3; i++)
00389 cameraCenter << readVector(file)[0];
00390 numline+=3;
00391
00392 const double focal = readVector(file)[0],
00393 k1 = readVector(file)[0],
00394 k2 = readVector(file)[0];
00395 Q_UNUSED(k1);
00396 Q_UNUSED(k2);
00397 numline+=3;
00398
00399
00400 if (ABS(focal) < 1e-1)
00401 {
00402 std::cout << "******* SMALL FOCAL at line " << numline << " for camera "<< numCamera << " !!! " << focal << std::endl;
00403 continue;
00404 }
00405
00406 if (ABS( focal ) > 1e+10)
00407 {
00408 std::cout << "******* LARGE FOCAL at line " << numline << " for camera "<< numCamera << " !!! " << focal << std::endl;
00409 continue;
00410 }
00411
00412 const double angle = rodriguesRotation.norm2();
00413 const QVVector rotationVector = rodriguesRotation / angle;
00414 const QVMatrix R = expSO3(rotationVector * angle);
00415
00416 const QVQuaternion q(R);
00417 const QVEuclideanMapping3 cameraPose(q, cameraCenter);
00418 QVMatrix K = focal * QVMatrix::identity(3);
00419 K(2,2) = 1.0;
00420
00421
00422 fileCameraIndexToRealCameraIndex[numCamera] = cameraPoses.count();
00423 cameraCalibrations << K;
00424 cameraPoses << cameraPose;
00425
00426
00427
00428
00429 if ( numCamera % fractionCameras == 0 )
00430 std::cout << "[readReconstruction_BAITL]\t" << int(double(100*numCamera) / double(numCameras)) << "% loaded." << std::endl;
00431 }
00432
00433
00434
00435 for(int i = 0; i < pointTrackings.size(); i++)
00436 {
00437 const QHash< int, QPointF> &oldCorrespondences = pointTrackings[i];
00438
00439 QHash< int, QPointF> newCorrespondences;
00440
00441 foreach(int numCamera, oldCorrespondences.keys())
00442 if (fileCameraIndexToRealCameraIndex.contains(numCamera))
00443 newCorrespondences[ fileCameraIndexToRealCameraIndex[ numCamera ] ] = oldCorrespondences[numCamera];
00444
00445 pointTrackings[i] = newCorrespondences;
00446 }
00447
00448 std::cout << "[readReconstruction_BAITL] Reading " << numPoints << " points" << std::endl;
00449
00450
00451 for(int numPoint = 0; numPoint < numPoints; numPoint++)
00452 {
00453 QVVector point;
00454 for(int i = 0; i < 3; i++)
00455 point << readVector(file)[0];
00456 points3D << point;
00457 rgbColors << QColor(128,128,128);
00458
00459 if ( numPoint % fractionPoints == 0 )
00460 std::cout << "[readReconstruction_BAITL]\t" << int(double(100*numPoint) / double(numPoints)) << "% loaded." << std::endl;
00461 }
00462
00463 std::cout << "[readReconstruction_BundlerOutput] Readed " << numPoints << " points, " << numCameras << " cameras." << std::endl;
00464 file.close();
00465 return true;
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 bool readReconstruction_BundlerOutput( const QString &fileName,
00590 QList<QVMatrix> &cameraCalibrations,
00591 QList<QVVector> &cameraRadialParameters,
00592 QList<QVCameraPose> &cameraPoses,
00593 QList<QV3DPointF> &points3D,
00594 QList<QHash<int, QPointF> > &pointTrackings,
00595 QList< QColor > &rgbColors
00596 )
00597
00598 {
00599 cameraCalibrations.clear();
00600 cameraRadialParameters.clear();
00601 cameraPoses.clear();
00602 points3D.clear();
00603 pointTrackings.clear();
00604 rgbColors.clear();
00605
00606 std::cout << "[readReconstruction_BundlerOutput] Opening file" << std::endl;
00607 QFile file(fileName);
00608 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00609 {
00610 std::cout << "[readReconstruction_BundlerOutput] Could not open file '" << qPrintable(fileName) << "'" << std::endl;
00611 return false;
00612 }
00613
00614
00615 const QString line = file.readLine();
00616 if (not line.contains("# Bundle file v0.3"))
00617 {
00618 std::cout << "[readReconstruction_BundlerOutput] The file does not seems to contain a valid Bulde 0.3 format." << std::endl;
00619 file.close();
00620 return false;
00621 }
00622
00623
00624 bool ok = false;
00625 int numCameras = -1, numPoints = -1;
00626
00627 while (not ok and not file.atEnd())
00628 {
00629 const QString line = file.readLine();
00630 if (line.contains("#"))
00631 continue;
00632
00633 const QStringList stringList = line.split (" ", QString::SkipEmptyParts);
00634
00635 numCameras = stringList[0].toInt(&ok);
00636 numPoints = stringList[1].toInt(&ok);
00637 }
00638
00639 const int fractionCameras = numCameras / 7, fractionPoints = numPoints / 7;
00640
00641 std::cout << "[readReconstruction_BundlerOutput] Reading " << numCameras << " cameras." << std::endl;
00642
00643
00644 int numCamera, numPoint, numProjections = 0;
00645 QHash<int, int> virtualCameraIndexToRealCameraIndex;
00646 for(numCamera = 0; numCamera < numCameras and not file.atEnd(); numCamera++)
00647 {
00648 const QVVector intrinsics = readVector(file);
00649
00650 QList<QVVector> Rlist;
00651 Rlist << readVector(file);
00652 Rlist << readVector(file);
00653 Rlist << readVector(file);
00654
00655 const QVMatrix R(Rlist);
00656 const QVVector t = readVector(file);
00657
00658 if ( numCamera % fractionCameras == 0 )
00659 std::cout << "[readReconstruction_BundlerOutput]\t" << int(double(100*numCamera) / double(numCameras)) << "% loaded." << std::endl;
00660
00661 if (R.norm2() == 0)
00662 continue;
00663
00664 Q_ASSERT( (QVMatrix::identity(3)-R.transpose()* R).norm2() < 1e-6 );
00665
00666 if (t != QV3DPointF(0.0, 0.0, 0.0))
00667 {
00668 virtualCameraIndexToRealCameraIndex[numCamera] = cameraPoses.count();
00669 cameraCalibrations << QVMatrix::cameraCalibrationMatrix(intrinsics[0]);
00670 cameraPoses << QVEuclideanMapping3(R | t);
00671 cameraRadialParameters << intrinsics.mid(1);
00672 }
00673 }
00674
00675 std::cout << "[readReconstruction_BundlerOutput] Reading points" << std::endl;
00676
00677 for(numPoint = 0, numProjections = 0; numPoint < numPoints and not file.atEnd(); numPoint++)
00678 {
00679 const QVVector position = readVector(file),
00680 color = readVector(file),
00681 viewList = readVector(file);
00682
00683 points3D << position;
00684 rgbColors << QColor(int(color[0]), int(color[1]),int(color[2]));
00685
00686 if (viewList[0] != (viewList.count() -1) / 4)
00687 std::cout << "Error: in point projections list." << std::endl;
00688 else {
00689 QHash< int, QPointF> projections;
00690 for (int i = 1; i < viewList.count(); i+=4)
00691 {
00692 const int numCamera = viewList[i];
00693 const double coorX = viewList[i+2], coorY = viewList[i+3];
00694 if (numCamera +1 > numCameras or numCamera < 0)
00695 std::cout << "Error: camera index out of bounds." << std::endl;
00696 if (virtualCameraIndexToRealCameraIndex.contains( numCamera ))
00697 projections[ virtualCameraIndexToRealCameraIndex[ numCamera ] ] = -QPointF( coorX, coorY );
00698 else
00699 std::cout << "Error: found point projection for uninitialized camera pose." << std::endl;
00700 }
00701 pointTrackings << projections;
00702 numProjections += projections.count();
00703 }
00704 if ( numPoint % fractionPoints == 0 )
00705 std::cout << "[readReconstruction_BundlerOutput]\t" << int(double(100*numPoint) / double(numPoints)) << "% loaded." << std::endl;
00706 }
00707
00708 file.close();
00709 return true;
00710 }
00711
00712 bool readCameras_laSBA(const QString fileName, QList<QVCameraPose> &cameraPoses)
00713 {
00714 QFile file(fileName);
00715 if (not file.open(QIODevice::ReadOnly | QIODevice::Text))
00716 return false;
00717
00718 while (not file.atEnd())
00719 {
00720 const QString line = file.readLine();
00721 if (line.contains("#"))
00722 continue;
00723
00724 const QStringList stringList = line.split (" ", QString::SkipEmptyParts);
00725
00726 QVVector v;
00727 foreach(QString string, stringList)
00728 {
00729 bool ok = false;
00730 const double value = string.toDouble(&ok);
00731 if (ok)
00732 v << value;
00733 }
00734
00735 const QVQuaternion q(v[1], v[2], v[3], v[0]);
00736 const QV3DPointF t(v[4], v[5], v[6]);
00737
00738 cameraPoses << QVEuclideanMapping3(q, t);
00739 }
00740
00741 return true;
00742 }
00743
00744 bool readPoints_laSBA(const QString fileName, QList<QV3DPointF> &points3D, QList<QHash<int, QPointF> > &pointTrackings)
00745 {
00746 QFile file(fileName);
00747 if (not file.open(QIODevice::ReadOnly | QIODevice::Text))
00748 return false;
00749
00750 while (not file.atEnd())
00751 {
00752 const QString line = file.readLine();
00753
00754 if (line.contains("#"))
00755 continue;
00756
00757 const QStringList stringList = line.split (" ", QString::SkipEmptyParts);
00758 QVVector v;
00759 foreach(QString string, stringList)
00760 {
00761 bool ok = false;
00762 const double value = string.toDouble(&ok);
00763 if (ok)
00764 v << value;
00765 }
00766
00767 const QV3DPointF t(v[0], v[1], v[2]);
00768
00769 QHash<int, QPointF> projections;
00770 for(int i = 4; i < v.size(); i+=3)
00771 projections[ v[i] ] = QPointF(v[i+1], v[i+2]);
00772 pointTrackings << projections;
00773 points3D << t;
00774 }
00775
00776 return true;
00777 }
00778
00779 bool readSfMReconstruction_laSBA( const QString &filesPath,
00780 QList<QVMatrix> &cameraCalibrations,
00781 QList<QVCameraPose> &cameraPoses,
00782 QList<QV3DPointF> &points3D,
00783 QList<QHash<int, QPointF> > &pointTrackings
00784 )
00785 {
00786 cameraCalibrations.clear();
00787 cameraPoses.clear();
00788 points3D.clear();
00789 pointTrackings.clear();
00790
00791 const QVMatrix Ks = readMatrix(filesPath + "/calib.txt");
00792 Q_ASSERT(Ks.getCols() == 3);
00793 Q_ASSERT(Ks.getRows() == 3);
00794
00795 for(int i = 0; i < Ks.getRows(); i+=3)
00796 cameraCalibrations << Ks.getSubmatrix(i, i+2, 0, 2);
00797
00798 if (not readCameras_laSBA(filesPath + "/cams.txt", cameraPoses))
00799 {
00800 std::cout << "[readSfMReconstruction_laSBA] Error: could not read file " << qPrintable(filesPath + "/cams.txt") << std::endl;
00801 return false;
00802 }
00803
00804 if (not readPoints_laSBA(filesPath + "/pts.txt", points3D, pointTrackings))
00805 {
00806 std::cout << "[readSfMReconstruction_laSBA] Error: could not read file " << qPrintable(filesPath + "/pts.txt") << std::endl;
00807 return false;
00808 }
00809
00810 Q_ASSERT_X( (cameraCalibrations.count() == 1) or (cameraCalibrations.count() == cameraPoses.count()), "[readSfMReconstruction_laSBA]", "Error reading calibrations from file: incorrect number.");
00811
00812 return true;
00813 }
00814
00815 #include <QFileInfo>
00816 bool readSfMReconstruction( const QString &path,
00817 QList<QVMatrix> &cameraCalibrations,
00818 QList<QVCameraPose> &initialCameraPoses,
00819 QList<QV3DPointF> &filePoints3D,
00820 QList<QHash<int, QPointF> > &pointsProjections
00821 )
00822 {
00823 const QFileInfo info(path);
00824
00825 if (not info.exists())
00826 {
00827 std::cout << "[readSfMReconstruction] Error: specified path '" << qPrintable(path) << "' does not exists." << std::endl;
00828 return false;
00829 }
00830 else if (info.isDir())
00831 {
00832 if (not readSfMReconstruction_laSBA(path, cameraCalibrations, initialCameraPoses, filePoints3D, pointsProjections))
00833 {
00834 std::cout << "[readSfMReconstruction] Specified path is a directory, but one of the files is missing: 'calib.txt', 'pts.txt' or 'cams.txt'." << std::endl;
00835 return false;
00836 }
00837 }
00838 else if (info.isFile())
00839 {
00840 QList< QColor > rgbColors;
00841 QList<QVVector> cameraRadialParameters;
00842
00843 if ( not readReconstruction_BundlerOutput(path, cameraCalibrations, cameraRadialParameters, initialCameraPoses, filePoints3D, pointsProjections, rgbColors) )
00844
00845 if ( not readReconstruction_BAITL(path, cameraCalibrations, initialCameraPoses, filePoints3D, rgbColors, pointsProjections) )
00846 {
00847 std::cout << "[readSfMReconstruction] Could not load reconstruction from specified file." << std::endl;
00848 return false;
00849 }
00850 }
00851
00852 return true;
00853 }
00854
00855
00856 #include <QTextStream>
00857 bool saveMatrix(const QString fileName, const QVMatrix &matrix)
00858 {
00859 QFile file(fileName);
00860 if (not file.open(QIODevice::WriteOnly | QIODevice::Text))
00861 return false;
00862
00863 QTextStream stream(&file);
00864
00865 stream.setRealNumberPrecision(16);
00866
00867 const double *data = matrix.getReadData();
00868 for (int i=0; i < matrix.getRows(); i++)
00869 {
00870 for (int j = 0; j < matrix.getCols(); j++)
00871 stream << qPrintable(QString("%1").arg(data[i*matrix.getCols() + j], -8, 'f', 6)) << " ";
00872 stream << "\n";
00873 }
00874
00875 file.close();
00876 return true;
00877 }
00878
00879 void writeCameras_laSBA(const QString &fileName, const QList<QVCameraPose> &cameraPoses)
00880 {
00881 QList<QVVector> cameraVectors;
00882 foreach(QVCameraPose cameraPose, cameraPoses)
00883 cameraVectors << cameraPose.operator QVEuclideanMapping3();
00884
00885 const QVMatrix cameraPosesMatrixPre(cameraVectors);
00886 const QVMatrix cameraPosesMatrix = QVMatrix(cameraPosesMatrixPre.getCol(3)).transpose()
00887 | cameraPosesMatrixPre.getCol(0)
00888 | cameraPosesMatrixPre.getCol(1)
00889 | cameraPosesMatrixPre.getCol(2)
00890 | cameraPosesMatrixPre.getCol(4)
00891 | cameraPosesMatrixPre.getCol(5)
00892 | cameraPosesMatrixPre.getCol(6);
00893
00894 saveMatrix(fileName, cameraPosesMatrix);
00895 }
00896
00897 #include <fstream>
00898 #include <iostream>
00899 void writePoints_laSBA(const QString fileName, const QList<QV3DPointF> &points3D, const QList<QHash<int, QPointF> > &pointTrackings)
00900 {
00901 QFile file(fileName);
00902 if (not file.open(QIODevice::WriteOnly | QIODevice::Text))
00903 return;
00904
00905 QTextStream stream(&file);
00906
00907 stream.setRealNumberPrecision(16);
00908
00909 for (int i=0; i < points3D.size(); i++)
00910 {
00911 for (int j = 0; j < points3D[i].size(); j++)
00912 stream << qPrintable(QString("%1").arg(points3D[i][j], -8, 'f', 6)) << " ";
00913 stream << qPrintable(QString("%1").arg(pointTrackings[i].count(), -8)) << " ";
00914 foreach(int index, pointTrackings[i].keys())
00915 stream << qPrintable(QString("%1").arg(index, -8)) << " "
00916 << qPrintable(QString("%1").arg(pointTrackings[i][index].x(), -8, 'f', 6)) << " "
00917 << qPrintable(QString("%1").arg(pointTrackings[i][index].y(), -8, 'f', 6)) << " ";
00918 stream << "\n";
00919 }
00920
00921 file.close();
00922 }
00923