main.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE LIGHT VIEWER #
  4. //# #
  5. //# This project has been initiated under funding from ANR/CIFRE #
  6. //# #
  7. //# This program is free software; you can redistribute it and/or modify #
  8. //# it under the terms of the GNU General Public License as published by #
  9. //# the Free Software Foundation; version 2 or later of the License. #
  10. //# #
  11. //# This program is distributed in the hope that it will be useful, #
  12. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  13. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  14. //# GNU General Public License for more details. #
  15. //# #
  16. //# +++ COPYRIGHT: EDF R&D + TELECOM ParisTech (ENST-TSI) +++ #
  17. //# #
  18. //##########################################################################
  19. //Qt
  20. #include <QDir>
  21. #include <QGLFormat>
  22. //Local
  23. #include "ccviewerlog.h"
  24. //qCC_db
  25. #include <ccIncludeGL.h>
  26. #include <ccNormalVectors.h>
  27. #include <ccColorScalesManager.h>
  28. #include <ccMaterial.h>
  29. #include <ccPointCloud.h>
  30. //qCC_io
  31. #include <FileIOFilter.h>
  32. #ifdef USE_VLD
  33. //VLD
  34. #include <vld.h>
  35. #endif
  36. #include "ccviewer.h"
  37. #include "ccViewerApplication.h"
  38. int main(int argc, char *argv[])
  39. {
  40. #ifdef Q_OS_WIN
  41. //enables automatic scaling based on the monitor's pixel density
  42. ccViewerApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  43. #endif
  44. ccViewerApplication::InitOpenGL();
  45. // Convert the input arguments to QString before the application is initialized
  46. // (as it will force utf8, which might prevent from properly reading filenmaes from the command line)
  47. QStringList argumentsLocal8Bit;
  48. for (int i = 0; i < argc; ++i)
  49. {
  50. argumentsLocal8Bit << QString::fromLocal8Bit(argv[i]);
  51. }
  52. ccViewerApplication a(argc, argv, false);
  53. #ifdef CC_GAMEPAD_SUPPORT
  54. #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
  55. #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
  56. QGamepadManager::instance(); //potential workaround to bug https://bugreports.qt.io/browse/QTBUG-61553
  57. #endif
  58. #endif
  59. #endif
  60. #ifdef USE_VLD
  61. VLDEnable();
  62. #endif
  63. QDir workingDir = QCoreApplication::applicationDirPath();
  64. #ifdef Q_OS_MAC
  65. // This makes sure that our "working directory" is not within the application bundle
  66. if ( workingDir.dirName() == "MacOS" )
  67. {
  68. workingDir.cdUp();
  69. workingDir.cdUp();
  70. workingDir.cdUp();
  71. }
  72. #endif
  73. QDir::setCurrent(workingDir.absolutePath());
  74. if (!QGLFormat::hasOpenGL())
  75. {
  76. QMessageBox::critical(nullptr, "Error", "This application needs OpenGL to run!");
  77. return EXIT_FAILURE;
  78. }
  79. if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_1) == 0)
  80. {
  81. QMessageBox::critical(nullptr, "Error", "This application needs OpenGL 2.1 at least to run!");
  82. return EXIT_FAILURE;
  83. }
  84. //common data initialization
  85. FileIOFilter::InitInternalFilters(); //load all known I/O filters (plugins will come later!)
  86. ccNormalVectors::GetUniqueInstance(); //force pre-computed normals array initialization
  87. ccColorScalesManager::GetUniqueInstance(); //force pre-computed color tables initialization
  88. ccViewer w;
  89. a.setViewer(&w);
  90. //register minimal logger to display errors
  91. ccViewerLog logger(&w);
  92. ccLog::RegisterInstance(&logger);
  93. w.show();
  94. //files to open are passed as argument
  95. if (argc > 1)
  96. {
  97. //parse arguments
  98. QStringList filenames;
  99. int i = 1;
  100. while (i < argc)
  101. {
  102. QString argument = argumentsLocal8Bit[i++];
  103. QString upperArgument = argument.toUpper();
  104. //Argument '-WIN X Y W H' (to set window size and position)
  105. if (upperArgument == "-WIN")
  106. {
  107. bool ok = true;
  108. if (i + 3 < argc)
  109. {
  110. bool converionOk;
  111. int x = argumentsLocal8Bit[i ].toInt(&converionOk); ok &= converionOk;
  112. int y = argumentsLocal8Bit[i + 1].toInt(&converionOk); ok &= converionOk;
  113. int width = argumentsLocal8Bit[i + 2].toInt(&converionOk); ok &= converionOk;
  114. int height = argumentsLocal8Bit[i + 3].toInt(&converionOk); ok &= converionOk;
  115. i += 4;
  116. if (ok)
  117. {
  118. //change window position and size
  119. w.move(x,y);
  120. w.resize(width,height);
  121. }
  122. }
  123. if (!ok)
  124. {
  125. ccLog::Warning("Invalid arguments! 4 integer values are expected after '-win' (X Y W H)");
  126. break;
  127. }
  128. }
  129. else if (upperArgument == "-MAX")
  130. {
  131. w.showMaximized();
  132. }
  133. else if (upperArgument == "-TOP")
  134. {
  135. w.setWindowFlags(w.windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
  136. w.show();
  137. }
  138. else //any other argument is assumed to be a filename (that will we try to load)
  139. {
  140. filenames << argument;
  141. }
  142. }
  143. if (!filenames.empty())
  144. {
  145. w.addToDB(filenames);
  146. }
  147. }
  148. #ifdef Q_OS_MAC
  149. // process events to load any files on the command line
  150. QCoreApplication::processEvents();
  151. #endif
  152. w.checkForLoadedEntities();
  153. int result = a.exec();
  154. //release global structures
  155. FileIOFilter::UnregisterAll();
  156. ccPointCloud::ReleaseShaders();
  157. return result;
  158. }