nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file Base class of all import post processing steps */ nuclear@0: #ifndef INCLUDED_AI_BASEPROCESS_H nuclear@0: #define INCLUDED_AI_BASEPROCESS_H nuclear@0: nuclear@0: #include nuclear@0: nuclear@0: #include "assimp/types.h" nuclear@0: #include "GenericProperty.h" nuclear@0: nuclear@0: struct aiScene; nuclear@0: nuclear@0: namespace Assimp { nuclear@0: nuclear@0: class Importer; nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** Helper class to allow post-processing steps to interact with each other. nuclear@0: * nuclear@0: * The class maintains a simple property list that can be used by pp-steps nuclear@0: * to provide additional information to other steps. This is primarily nuclear@0: * intended for cross-step optimizations. nuclear@0: */ nuclear@0: class SharedPostProcessInfo nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: struct Base nuclear@0: { nuclear@0: virtual ~Base() nuclear@0: {} nuclear@0: }; nuclear@0: nuclear@0: //! Represents data that is allocated on the heap, thus needs to be deleted nuclear@0: template nuclear@0: struct THeapData : public Base nuclear@0: { nuclear@0: THeapData(T* in) nuclear@0: : data (in) nuclear@0: {} nuclear@0: nuclear@0: ~THeapData() nuclear@0: { nuclear@0: delete data; nuclear@0: } nuclear@0: T* data; nuclear@0: }; nuclear@0: nuclear@0: //! Represents static, by-value data not allocated on the heap nuclear@0: template nuclear@0: struct TStaticData : public Base nuclear@0: { nuclear@0: TStaticData(T in) nuclear@0: : data (in) nuclear@0: {} nuclear@0: nuclear@0: ~TStaticData() nuclear@0: {} nuclear@0: nuclear@0: T data; nuclear@0: }; nuclear@0: nuclear@0: // some typedefs for cleaner code nuclear@0: typedef unsigned int KeyType; nuclear@0: typedef std::map PropertyMap; nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: //! Destructor nuclear@0: ~SharedPostProcessInfo() nuclear@0: { nuclear@0: Clean(); nuclear@0: } nuclear@0: nuclear@0: //! Remove all stored properties from the table nuclear@0: void Clean() nuclear@0: { nuclear@0: // invoke the virtual destructor for all stored properties nuclear@0: for (PropertyMap::iterator it = pmap.begin(), end = pmap.end(); nuclear@0: it != end; ++it) nuclear@0: { nuclear@0: delete (*it).second; nuclear@0: } nuclear@0: pmap.clear(); nuclear@0: } nuclear@0: nuclear@0: //! Add a heap property to the list nuclear@0: template nuclear@0: void AddProperty( const char* name, T* in ){ nuclear@0: AddProperty(name,(Base*)new THeapData(in)); nuclear@0: } nuclear@0: nuclear@0: //! Add a static by-value property to the list nuclear@0: template nuclear@0: void AddProperty( const char* name, T in ){ nuclear@0: AddProperty(name,(Base*)new TStaticData(in)); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: //! Get a heap property nuclear@0: template nuclear@0: bool GetProperty( const char* name, T*& out ) const nuclear@0: { nuclear@0: THeapData* t = (THeapData*)GetPropertyInternal(name); nuclear@0: if(!t) nuclear@0: { nuclear@0: out = NULL; nuclear@0: return false; nuclear@0: } nuclear@0: out = t->data; nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: //! Get a static, by-value property nuclear@0: template nuclear@0: bool GetProperty( const char* name, T& out ) const nuclear@0: { nuclear@0: TStaticData* t = (TStaticData*)GetPropertyInternal(name); nuclear@0: if(!t)return false; nuclear@0: out = t->data; nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: //! Remove a property of a specific type nuclear@0: void RemoveProperty( const char* name) { nuclear@0: SetGenericPropertyPtr(pmap,name,NULL); nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: void AddProperty( const char* name, Base* data) { nuclear@0: SetGenericPropertyPtr(pmap,name,data); nuclear@0: } nuclear@0: nuclear@0: Base* GetPropertyInternal( const char* name) const { nuclear@0: return GetGenericProperty(pmap,name,NULL); nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: //! Map of all stored properties nuclear@0: PropertyMap pmap; nuclear@0: }; nuclear@0: nuclear@0: #if 0 nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** @brief Represents a dependency table for a postprocessing steps. nuclear@0: * nuclear@0: * For future use. nuclear@0: */ nuclear@0: struct PPDependencyTable nuclear@0: { nuclear@0: unsigned int execute_me_before_these; nuclear@0: unsigned int execute_me_after_these; nuclear@0: unsigned int only_if_these_are_not_specified; nuclear@0: unsigned int mutually_exclusive_with; nuclear@0: }; nuclear@0: nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: #define AI_SPP_SPATIAL_SORT "$Spat" nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** The BaseProcess defines a common interface for all post processing steps. nuclear@0: * A post processing step is run after a successful import if the caller nuclear@0: * specified the corresponding flag when calling ReadFile(). nuclear@0: * Enum #aiPostProcessSteps defines which flags are available. nuclear@0: * After a successful import the Importer iterates over its internal array nuclear@0: * of processes and calls IsActive() on each process to evaluate if the step nuclear@0: * should be executed. If the function returns true, the class' Execute() nuclear@0: * function is called subsequently. nuclear@0: */ nuclear@0: class ASSIMP_API_WINONLY BaseProcess nuclear@0: { nuclear@0: friend class Importer; nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: /** Constructor to be privately used by Importer */ nuclear@0: BaseProcess(); nuclear@0: nuclear@0: /** Destructor, private as well */ nuclear@0: virtual ~BaseProcess(); nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Returns whether the processing step is present in the given flag. nuclear@0: * @param pFlags The processing flags the importer was called with. A nuclear@0: * bitwise combination of #aiPostProcessSteps. nuclear@0: * @return true if the process is present in this flag fields, nuclear@0: * false if not. nuclear@0: */ nuclear@0: virtual bool IsActive( unsigned int pFlags) const = 0; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Check whether this step expects its input vertex data to be nuclear@0: * in verbose format. */ nuclear@0: virtual bool RequireVerboseFormat() const; nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Executes the post processing step on the given imported data. nuclear@0: * The function deletes the scene if the postprocess step fails ( nuclear@0: * the object pointer will be set to NULL). nuclear@0: * @param pImp Importer instance (pImp->mScene must be valid) nuclear@0: */ nuclear@0: void ExecuteOnScene( Importer* pImp); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Called prior to ExecuteOnScene(). nuclear@0: * The function is a request to the process to update its configuration nuclear@0: * basing on the Importer's configuration property list. nuclear@0: */ nuclear@0: virtual void SetupProperties(const Importer* pImp); nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Executes the post processing step on the given imported data. nuclear@0: * A process should throw an ImportErrorException* if it fails. nuclear@0: * This method must be implemented by deriving classes. nuclear@0: * @param pScene The imported data to work at. nuclear@0: */ nuclear@0: virtual void Execute( aiScene* pScene) = 0; nuclear@0: nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Assign a new SharedPostProcessInfo to the step. This object nuclear@0: * allows multiple postprocess steps to share data. nuclear@0: * @param sh May be NULL nuclear@0: */ nuclear@0: inline void SetSharedData(SharedPostProcessInfo* sh) { nuclear@0: shared = sh; nuclear@0: } nuclear@0: nuclear@0: // ------------------------------------------------------------------- nuclear@0: /** Get the shared data that is assigned to the step. nuclear@0: */ nuclear@0: inline SharedPostProcessInfo* GetSharedData() { nuclear@0: return shared; nuclear@0: } nuclear@0: nuclear@0: protected: nuclear@0: nuclear@0: /** See the doc of #SharedPostProcessInfo for more details */ nuclear@0: SharedPostProcessInfo* shared; nuclear@0: nuclear@0: /** Currently active progress handler */ nuclear@0: ProgressHandler* progress; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: } // end of namespace Assimp nuclear@0: nuclear@0: #endif // AI_BASEPROCESS_H_INC