vrshoot
diff libs/assimp/BaseProcess.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/BaseProcess.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,294 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file Base class of all import post processing steps */ 1.45 +#ifndef INCLUDED_AI_BASEPROCESS_H 1.46 +#define INCLUDED_AI_BASEPROCESS_H 1.47 + 1.48 +#include <map> 1.49 + 1.50 +#include "assimp/types.h" 1.51 +#include "GenericProperty.h" 1.52 + 1.53 +struct aiScene; 1.54 + 1.55 +namespace Assimp { 1.56 + 1.57 +class Importer; 1.58 + 1.59 +// --------------------------------------------------------------------------- 1.60 +/** Helper class to allow post-processing steps to interact with each other. 1.61 + * 1.62 + * The class maintains a simple property list that can be used by pp-steps 1.63 + * to provide additional information to other steps. This is primarily 1.64 + * intended for cross-step optimizations. 1.65 + */ 1.66 +class SharedPostProcessInfo 1.67 +{ 1.68 +public: 1.69 + 1.70 + struct Base 1.71 + { 1.72 + virtual ~Base() 1.73 + {} 1.74 + }; 1.75 + 1.76 + //! Represents data that is allocated on the heap, thus needs to be deleted 1.77 + template <typename T> 1.78 + struct THeapData : public Base 1.79 + { 1.80 + THeapData(T* in) 1.81 + : data (in) 1.82 + {} 1.83 + 1.84 + ~THeapData() 1.85 + { 1.86 + delete data; 1.87 + } 1.88 + T* data; 1.89 + }; 1.90 + 1.91 + //! Represents static, by-value data not allocated on the heap 1.92 + template <typename T> 1.93 + struct TStaticData : public Base 1.94 + { 1.95 + TStaticData(T in) 1.96 + : data (in) 1.97 + {} 1.98 + 1.99 + ~TStaticData() 1.100 + {} 1.101 + 1.102 + T data; 1.103 + }; 1.104 + 1.105 + // some typedefs for cleaner code 1.106 + typedef unsigned int KeyType; 1.107 + typedef std::map<KeyType, Base*> PropertyMap; 1.108 + 1.109 +public: 1.110 + 1.111 + //! Destructor 1.112 + ~SharedPostProcessInfo() 1.113 + { 1.114 + Clean(); 1.115 + } 1.116 + 1.117 + //! Remove all stored properties from the table 1.118 + void Clean() 1.119 + { 1.120 + // invoke the virtual destructor for all stored properties 1.121 + for (PropertyMap::iterator it = pmap.begin(), end = pmap.end(); 1.122 + it != end; ++it) 1.123 + { 1.124 + delete (*it).second; 1.125 + } 1.126 + pmap.clear(); 1.127 + } 1.128 + 1.129 + //! Add a heap property to the list 1.130 + template <typename T> 1.131 + void AddProperty( const char* name, T* in ){ 1.132 + AddProperty(name,(Base*)new THeapData<T>(in)); 1.133 + } 1.134 + 1.135 + //! Add a static by-value property to the list 1.136 + template <typename T> 1.137 + void AddProperty( const char* name, T in ){ 1.138 + AddProperty(name,(Base*)new TStaticData<T>(in)); 1.139 + } 1.140 + 1.141 + 1.142 + //! Get a heap property 1.143 + template <typename T> 1.144 + bool GetProperty( const char* name, T*& out ) const 1.145 + { 1.146 + THeapData<T>* t = (THeapData<T>*)GetPropertyInternal(name); 1.147 + if(!t) 1.148 + { 1.149 + out = NULL; 1.150 + return false; 1.151 + } 1.152 + out = t->data; 1.153 + return true; 1.154 + } 1.155 + 1.156 + //! Get a static, by-value property 1.157 + template <typename T> 1.158 + bool GetProperty( const char* name, T& out ) const 1.159 + { 1.160 + TStaticData<T>* t = (TStaticData<T>*)GetPropertyInternal(name); 1.161 + if(!t)return false; 1.162 + out = t->data; 1.163 + return true; 1.164 + } 1.165 + 1.166 + //! Remove a property of a specific type 1.167 + void RemoveProperty( const char* name) { 1.168 + SetGenericPropertyPtr<Base>(pmap,name,NULL); 1.169 + } 1.170 + 1.171 +private: 1.172 + 1.173 + void AddProperty( const char* name, Base* data) { 1.174 + SetGenericPropertyPtr<Base>(pmap,name,data); 1.175 + } 1.176 + 1.177 + Base* GetPropertyInternal( const char* name) const { 1.178 + return GetGenericProperty<Base*>(pmap,name,NULL); 1.179 + } 1.180 + 1.181 +private: 1.182 + 1.183 + //! Map of all stored properties 1.184 + PropertyMap pmap; 1.185 +}; 1.186 + 1.187 +#if 0 1.188 + 1.189 +// --------------------------------------------------------------------------- 1.190 +/** @brief Represents a dependency table for a postprocessing steps. 1.191 + * 1.192 + * For future use. 1.193 + */ 1.194 + struct PPDependencyTable 1.195 + { 1.196 + unsigned int execute_me_before_these; 1.197 + unsigned int execute_me_after_these; 1.198 + unsigned int only_if_these_are_not_specified; 1.199 + unsigned int mutually_exclusive_with; 1.200 + }; 1.201 + 1.202 +#endif 1.203 + 1.204 + 1.205 +#define AI_SPP_SPATIAL_SORT "$Spat" 1.206 + 1.207 +// --------------------------------------------------------------------------- 1.208 +/** The BaseProcess defines a common interface for all post processing steps. 1.209 + * A post processing step is run after a successful import if the caller 1.210 + * specified the corresponding flag when calling ReadFile(). 1.211 + * Enum #aiPostProcessSteps defines which flags are available. 1.212 + * After a successful import the Importer iterates over its internal array 1.213 + * of processes and calls IsActive() on each process to evaluate if the step 1.214 + * should be executed. If the function returns true, the class' Execute() 1.215 + * function is called subsequently. 1.216 + */ 1.217 +class ASSIMP_API_WINONLY BaseProcess 1.218 +{ 1.219 + friend class Importer; 1.220 + 1.221 +public: 1.222 + 1.223 + /** Constructor to be privately used by Importer */ 1.224 + BaseProcess(); 1.225 + 1.226 + /** Destructor, private as well */ 1.227 + virtual ~BaseProcess(); 1.228 + 1.229 +public: 1.230 + 1.231 + // ------------------------------------------------------------------- 1.232 + /** Returns whether the processing step is present in the given flag. 1.233 + * @param pFlags The processing flags the importer was called with. A 1.234 + * bitwise combination of #aiPostProcessSteps. 1.235 + * @return true if the process is present in this flag fields, 1.236 + * false if not. 1.237 + */ 1.238 + virtual bool IsActive( unsigned int pFlags) const = 0; 1.239 + 1.240 + // ------------------------------------------------------------------- 1.241 + /** Check whether this step expects its input vertex data to be 1.242 + * in verbose format. */ 1.243 + virtual bool RequireVerboseFormat() const; 1.244 + 1.245 + // ------------------------------------------------------------------- 1.246 + /** Executes the post processing step on the given imported data. 1.247 + * The function deletes the scene if the postprocess step fails ( 1.248 + * the object pointer will be set to NULL). 1.249 + * @param pImp Importer instance (pImp->mScene must be valid) 1.250 + */ 1.251 + void ExecuteOnScene( Importer* pImp); 1.252 + 1.253 + // ------------------------------------------------------------------- 1.254 + /** Called prior to ExecuteOnScene(). 1.255 + * The function is a request to the process to update its configuration 1.256 + * basing on the Importer's configuration property list. 1.257 + */ 1.258 + virtual void SetupProperties(const Importer* pImp); 1.259 + 1.260 + // ------------------------------------------------------------------- 1.261 + /** Executes the post processing step on the given imported data. 1.262 + * A process should throw an ImportErrorException* if it fails. 1.263 + * This method must be implemented by deriving classes. 1.264 + * @param pScene The imported data to work at. 1.265 + */ 1.266 + virtual void Execute( aiScene* pScene) = 0; 1.267 + 1.268 + 1.269 + // ------------------------------------------------------------------- 1.270 + /** Assign a new SharedPostProcessInfo to the step. This object 1.271 + * allows multiple postprocess steps to share data. 1.272 + * @param sh May be NULL 1.273 + */ 1.274 + inline void SetSharedData(SharedPostProcessInfo* sh) { 1.275 + shared = sh; 1.276 + } 1.277 + 1.278 + // ------------------------------------------------------------------- 1.279 + /** Get the shared data that is assigned to the step. 1.280 + */ 1.281 + inline SharedPostProcessInfo* GetSharedData() { 1.282 + return shared; 1.283 + } 1.284 + 1.285 +protected: 1.286 + 1.287 + /** See the doc of #SharedPostProcessInfo for more details */ 1.288 + SharedPostProcessInfo* shared; 1.289 + 1.290 + /** Currently active progress handler */ 1.291 + ProgressHandler* progress; 1.292 +}; 1.293 + 1.294 + 1.295 +} // end of namespace Assimp 1.296 + 1.297 +#endif // AI_BASEPROCESS_H_INC