You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, 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 Base class of all import post processing steps */
  34. #ifndef INCLUDED_AI_BASEPROCESS_H
  35. #define INCLUDED_AI_BASEPROCESS_H
  36. #include <map>
  37. #include "../include/assimp/types.h"
  38. #include "GenericProperty.h"
  39. struct aiScene;
  40. namespace Assimp {
  41. class Importer;
  42. // ---------------------------------------------------------------------------
  43. /** Helper class to allow post-processing steps to interact with each other.
  44. *
  45. * The class maintains a simple property list that can be used by pp-steps
  46. * to provide additional information to other steps. This is primarily
  47. * intended for cross-step optimizations.
  48. */
  49. class SharedPostProcessInfo
  50. {
  51. public:
  52. struct Base
  53. {
  54. virtual ~Base()
  55. {}
  56. };
  57. //! Represents data that is allocated on the heap, thus needs to be deleted
  58. template <typename T>
  59. struct THeapData : public Base
  60. {
  61. THeapData(T* in)
  62. : data (in)
  63. {}
  64. ~THeapData()
  65. {
  66. delete data;
  67. }
  68. T* data;
  69. };
  70. //! Represents static, by-value data not allocated on the heap
  71. template <typename T>
  72. struct TStaticData : public Base
  73. {
  74. TStaticData(T in)
  75. : data (in)
  76. {}
  77. ~TStaticData()
  78. {}
  79. T data;
  80. };
  81. // some typedefs for cleaner code
  82. typedef unsigned int KeyType;
  83. typedef std::map<KeyType, Base*> PropertyMap;
  84. public:
  85. //! Destructor
  86. ~SharedPostProcessInfo()
  87. {
  88. Clean();
  89. }
  90. //! Remove all stored properties from the table
  91. void Clean()
  92. {
  93. // invoke the virtual destructor for all stored properties
  94. for (PropertyMap::iterator it = pmap.begin(), end = pmap.end();
  95. it != end; ++it)
  96. {
  97. delete (*it).second;
  98. }
  99. pmap.clear();
  100. }
  101. //! Add a heap property to the list
  102. template <typename T>
  103. void AddProperty( const char* name, T* in ){
  104. AddProperty(name,(Base*)new THeapData<T>(in));
  105. }
  106. //! Add a static by-value property to the list
  107. template <typename T>
  108. void AddProperty( const char* name, T in ){
  109. AddProperty(name,(Base*)new TStaticData<T>(in));
  110. }
  111. //! Get a heap property
  112. template <typename T>
  113. bool GetProperty( const char* name, T*& out ) const
  114. {
  115. THeapData<T>* t = (THeapData<T>*)GetPropertyInternal(name);
  116. if(!t)
  117. {
  118. out = NULL;
  119. return false;
  120. }
  121. out = t->data;
  122. return true;
  123. }
  124. //! Get a static, by-value property
  125. template <typename T>
  126. bool GetProperty( const char* name, T& out ) const
  127. {
  128. TStaticData<T>* t = (TStaticData<T>*)GetPropertyInternal(name);
  129. if(!t)return false;
  130. out = t->data;
  131. return true;
  132. }
  133. //! Remove a property of a specific type
  134. void RemoveProperty( const char* name) {
  135. SetGenericPropertyPtr<Base>(pmap,name,NULL);
  136. }
  137. private:
  138. void AddProperty( const char* name, Base* data) {
  139. SetGenericPropertyPtr<Base>(pmap,name,data);
  140. }
  141. Base* GetPropertyInternal( const char* name) const {
  142. return GetGenericProperty<Base*>(pmap,name,NULL);
  143. }
  144. private:
  145. //! Map of all stored properties
  146. PropertyMap pmap;
  147. };
  148. #if 0
  149. // ---------------------------------------------------------------------------
  150. /** @brief Represents a dependency table for a postprocessing steps.
  151. *
  152. * For future use.
  153. */
  154. struct PPDependencyTable
  155. {
  156. unsigned int execute_me_before_these;
  157. unsigned int execute_me_after_these;
  158. unsigned int only_if_these_are_not_specified;
  159. unsigned int mutually_exclusive_with;
  160. };
  161. #endif
  162. #define AI_SPP_SPATIAL_SORT "$Spat"
  163. // ---------------------------------------------------------------------------
  164. /** The BaseProcess defines a common interface for all post processing steps.
  165. * A post processing step is run after a successful import if the caller
  166. * specified the corresponding flag when calling ReadFile().
  167. * Enum #aiPostProcessSteps defines which flags are available.
  168. * After a successful import the Importer iterates over its internal array
  169. * of processes and calls IsActive() on each process to evaluate if the step
  170. * should be executed. If the function returns true, the class' Execute()
  171. * function is called subsequently.
  172. */
  173. class ASSIMP_API_WINONLY BaseProcess
  174. {
  175. friend class Importer;
  176. public:
  177. /** Constructor to be privately used by Importer */
  178. BaseProcess();
  179. /** Destructor, private as well */
  180. virtual ~BaseProcess();
  181. public:
  182. // -------------------------------------------------------------------
  183. /** Returns whether the processing step is present in the given flag.
  184. * @param pFlags The processing flags the importer was called with. A
  185. * bitwise combination of #aiPostProcessSteps.
  186. * @return true if the process is present in this flag fields,
  187. * false if not.
  188. */
  189. virtual bool IsActive( unsigned int pFlags) const = 0;
  190. // -------------------------------------------------------------------
  191. /** Check whether this step expects its input vertex data to be
  192. * in verbose format. */
  193. virtual bool RequireVerboseFormat() const;
  194. // -------------------------------------------------------------------
  195. /** Executes the post processing step on the given imported data.
  196. * The function deletes the scene if the postprocess step fails (
  197. * the object pointer will be set to NULL).
  198. * @param pImp Importer instance (pImp->mScene must be valid)
  199. */
  200. void ExecuteOnScene( Importer* pImp);
  201. // -------------------------------------------------------------------
  202. /** Called prior to ExecuteOnScene().
  203. * The function is a request to the process to update its configuration
  204. * basing on the Importer's configuration property list.
  205. */
  206. virtual void SetupProperties(const Importer* pImp);
  207. // -------------------------------------------------------------------
  208. /** Executes the post processing step on the given imported data.
  209. * A process should throw an ImportErrorException* if it fails.
  210. * This method must be implemented by deriving classes.
  211. * @param pScene The imported data to work at.
  212. */
  213. virtual void Execute( aiScene* pScene) = 0;
  214. // -------------------------------------------------------------------
  215. /** Assign a new SharedPostProcessInfo to the step. This object
  216. * allows multiple postprocess steps to share data.
  217. * @param sh May be NULL
  218. */
  219. inline void SetSharedData(SharedPostProcessInfo* sh) {
  220. shared = sh;
  221. }
  222. // -------------------------------------------------------------------
  223. /** Get the shared data that is assigned to the step.
  224. */
  225. inline SharedPostProcessInfo* GetSharedData() {
  226. return shared;
  227. }
  228. protected:
  229. /** See the doc of #SharedPostProcessInfo for more details */
  230. SharedPostProcessInfo* shared;
  231. /** Currently active progress handler */
  232. ProgressHandler* progress;
  233. };
  234. } // end of namespace Assimp
  235. #endif // AI_BASEPROCESS_H_INC