ProgressHandler.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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 = default;
  57. public:
  58. /// @brief Virtual destructor.
  59. virtual ~ProgressHandler () = default;
  60. // -------------------------------------------------------------------
  61. /** @brief Progress callback.
  62. * @param percentage An estimate of the current loading progress,
  63. * in percent. Or -1.f if such an estimate is not available.
  64. *
  65. * There are restriction on what you may do from within your
  66. * implementation of this method: no exceptions may be thrown and no
  67. * non-const #Importer methods may be called. It is
  68. * not generally possible to predict the number of callbacks
  69. * fired during a single import.
  70. *
  71. * @return Return false to abort loading at the next possible
  72. * occasion (loaders and Assimp are generally allowed to perform
  73. * all needed cleanup tasks prior to returning control to the
  74. * caller). If the loading is aborted, #Importer::ReadFile()
  75. * returns always nullptr.
  76. * */
  77. virtual bool Update(float percentage = -1.f) = 0;
  78. // -------------------------------------------------------------------
  79. /** @brief Progress callback for file loading steps
  80. * @param numberOfSteps The number of total post-processing
  81. * steps
  82. * @param currentStep The index of the current post-processing
  83. * step that will run, or equal to numberOfSteps if all of
  84. * them has finished. This number is always strictly monotone
  85. * increasing, although not necessarily linearly.
  86. *
  87. * @note This is currently only used at the start and the end
  88. * of the file parsing.
  89. * */
  90. virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  91. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  92. Update( f * 0.5f );
  93. }
  94. // -------------------------------------------------------------------
  95. /** @brief Progress callback for post-processing steps
  96. * @param numberOfSteps The number of total post-processing
  97. * steps
  98. * @param currentStep The index of the current post-processing
  99. * step that will run, or equal to numberOfSteps if all of
  100. * them has finished. This number is always strictly monotone
  101. * increasing, although not necessarily linearly.
  102. * */
  103. virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  104. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  105. Update( f * 0.5f + 0.5f );
  106. }
  107. // -------------------------------------------------------------------
  108. /** @brief Progress callback for export steps.
  109. * @param numberOfSteps The number of total processing
  110. * steps
  111. * @param currentStep The index of the current post-processing
  112. * step that will run, or equal to numberOfSteps if all of
  113. * them has finished. This number is always strictly monotone
  114. * increasing, although not necessarily linearly.
  115. * */
  116. virtual void UpdateFileWrite(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
  117. float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
  118. Update(f * 0.5f);
  119. }
  120. }; // !class ProgressHandler
  121. // ------------------------------------------------------------------------------------
  122. } // Namespace Assimp
  123. #endif // AI_PROGRESSHANDLER_H_INC