ProgressHandler.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2021, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file ProgressHandler.hpp
  34. * @brief Abstract base class 'ProgressHandler'.
  35. */
  36. #pragma once
  37. #ifndef AI_PROGRESSHANDLER_H_INC
  38. #define AI_PROGRESSHANDLER_H_INC
  39. #ifdef __GNUC__
  40. # pragma GCC system_header
  41. #endif
  42. #include <assimp/types.h>
  43. namespace Assimp {
  44. // ------------------------------------------------------------------------------------
  45. /** @brief CPP-API: Abstract interface for custom progress report receivers.
  46. *
  47. * Each #Importer instance maintains its own #ProgressHandler. The default
  48. * implementation provided by Assimp doesn't do anything at all. */
  49. class ASSIMP_API ProgressHandler
  50. #ifndef SWIG
  51. : public Intern::AllocateFromAssimpHeap
  52. #endif
  53. {
  54. protected:
  55. /// @brief Default constructor
  56. ProgressHandler () AI_NO_EXCEPT {
  57. // empty
  58. }
  59. public:
  60. /// @brief Virtual destructor.
  61. virtual ~ProgressHandler () {
  62. }
  63. // -------------------------------------------------------------------
  64. /** @brief Progress callback.
  65. * @param percentage An estimate of the current loading progress,
  66. * in percent. Or -1.f if such an estimate is not available.
  67. *
  68. * There are restriction on what you may do from within your
  69. * implementation of this method: no exceptions may be thrown and no
  70. * non-const #Importer methods may be called. It is
  71. * not generally possible to predict the number of callbacks
  72. * fired during a single import.
  73. *
  74. * @return Return false to abort loading at the next possible
  75. * occasion (loaders and Assimp are generally allowed to perform
  76. * all needed cleanup tasks prior to returning control to the
  77. * caller). If the loading is aborted, #Importer::ReadFile()
  78. * returns always nullptr.
  79. * */
  80. virtual bool Update(float percentage = -1.f) = 0;
  81. // -------------------------------------------------------------------
  82. /** @brief Progress callback for file loading steps
  83. * @param numberOfSteps The number of total post-processing
  84. * steps
  85. * @param currentStep The index of the current post-processing
  86. * step that will run, or equal to numberOfSteps if all of
  87. * them has finished. This number is always strictly monotone
  88. * increasing, although not necessarily linearly.
  89. *
  90. * @note This is currently only used at the start and the end
  91. * of the file parsing.
  92. * */
  93. virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  94. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  95. Update( f * 0.5f );
  96. }
  97. // -------------------------------------------------------------------
  98. /** @brief Progress callback for post-processing steps
  99. * @param numberOfSteps The number of total post-processing
  100. * steps
  101. * @param currentStep The index of the current post-processing
  102. * step that will run, or equal to numberOfSteps if all of
  103. * them has finished. This number is always strictly monotone
  104. * increasing, although not necessarily linearly.
  105. * */
  106. virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  107. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  108. Update( f * 0.5f + 0.5f );
  109. }
  110. // -------------------------------------------------------------------
  111. /** @brief Progress callback for export steps.
  112. * @param numberOfSteps The number of total processing
  113. * steps
  114. * @param currentStep The index of the current post-processing
  115. * step that will run, or equal to numberOfSteps if all of
  116. * them has finished. This number is always strictly monotone
  117. * increasing, although not necessarily linearly.
  118. * */
  119. virtual void UpdateFileWrite(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  120. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  121. Update(f * 0.5f);
  122. }
  123. }; // !class ProgressHandler
  124. // ------------------------------------------------------------------------------------
  125. } // Namespace Assimp
  126. #endif // AI_PROGRESSHANDLER_H_INC