vrshoot

annotate libs/assimp/BaseProcess.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file Base class of all import post processing steps */
nuclear@0 42 #ifndef INCLUDED_AI_BASEPROCESS_H
nuclear@0 43 #define INCLUDED_AI_BASEPROCESS_H
nuclear@0 44
nuclear@0 45 #include <map>
nuclear@0 46
nuclear@0 47 #include "assimp/types.h"
nuclear@0 48 #include "GenericProperty.h"
nuclear@0 49
nuclear@0 50 struct aiScene;
nuclear@0 51
nuclear@0 52 namespace Assimp {
nuclear@0 53
nuclear@0 54 class Importer;
nuclear@0 55
nuclear@0 56 // ---------------------------------------------------------------------------
nuclear@0 57 /** Helper class to allow post-processing steps to interact with each other.
nuclear@0 58 *
nuclear@0 59 * The class maintains a simple property list that can be used by pp-steps
nuclear@0 60 * to provide additional information to other steps. This is primarily
nuclear@0 61 * intended for cross-step optimizations.
nuclear@0 62 */
nuclear@0 63 class SharedPostProcessInfo
nuclear@0 64 {
nuclear@0 65 public:
nuclear@0 66
nuclear@0 67 struct Base
nuclear@0 68 {
nuclear@0 69 virtual ~Base()
nuclear@0 70 {}
nuclear@0 71 };
nuclear@0 72
nuclear@0 73 //! Represents data that is allocated on the heap, thus needs to be deleted
nuclear@0 74 template <typename T>
nuclear@0 75 struct THeapData : public Base
nuclear@0 76 {
nuclear@0 77 THeapData(T* in)
nuclear@0 78 : data (in)
nuclear@0 79 {}
nuclear@0 80
nuclear@0 81 ~THeapData()
nuclear@0 82 {
nuclear@0 83 delete data;
nuclear@0 84 }
nuclear@0 85 T* data;
nuclear@0 86 };
nuclear@0 87
nuclear@0 88 //! Represents static, by-value data not allocated on the heap
nuclear@0 89 template <typename T>
nuclear@0 90 struct TStaticData : public Base
nuclear@0 91 {
nuclear@0 92 TStaticData(T in)
nuclear@0 93 : data (in)
nuclear@0 94 {}
nuclear@0 95
nuclear@0 96 ~TStaticData()
nuclear@0 97 {}
nuclear@0 98
nuclear@0 99 T data;
nuclear@0 100 };
nuclear@0 101
nuclear@0 102 // some typedefs for cleaner code
nuclear@0 103 typedef unsigned int KeyType;
nuclear@0 104 typedef std::map<KeyType, Base*> PropertyMap;
nuclear@0 105
nuclear@0 106 public:
nuclear@0 107
nuclear@0 108 //! Destructor
nuclear@0 109 ~SharedPostProcessInfo()
nuclear@0 110 {
nuclear@0 111 Clean();
nuclear@0 112 }
nuclear@0 113
nuclear@0 114 //! Remove all stored properties from the table
nuclear@0 115 void Clean()
nuclear@0 116 {
nuclear@0 117 // invoke the virtual destructor for all stored properties
nuclear@0 118 for (PropertyMap::iterator it = pmap.begin(), end = pmap.end();
nuclear@0 119 it != end; ++it)
nuclear@0 120 {
nuclear@0 121 delete (*it).second;
nuclear@0 122 }
nuclear@0 123 pmap.clear();
nuclear@0 124 }
nuclear@0 125
nuclear@0 126 //! Add a heap property to the list
nuclear@0 127 template <typename T>
nuclear@0 128 void AddProperty( const char* name, T* in ){
nuclear@0 129 AddProperty(name,(Base*)new THeapData<T>(in));
nuclear@0 130 }
nuclear@0 131
nuclear@0 132 //! Add a static by-value property to the list
nuclear@0 133 template <typename T>
nuclear@0 134 void AddProperty( const char* name, T in ){
nuclear@0 135 AddProperty(name,(Base*)new TStaticData<T>(in));
nuclear@0 136 }
nuclear@0 137
nuclear@0 138
nuclear@0 139 //! Get a heap property
nuclear@0 140 template <typename T>
nuclear@0 141 bool GetProperty( const char* name, T*& out ) const
nuclear@0 142 {
nuclear@0 143 THeapData<T>* t = (THeapData<T>*)GetPropertyInternal(name);
nuclear@0 144 if(!t)
nuclear@0 145 {
nuclear@0 146 out = NULL;
nuclear@0 147 return false;
nuclear@0 148 }
nuclear@0 149 out = t->data;
nuclear@0 150 return true;
nuclear@0 151 }
nuclear@0 152
nuclear@0 153 //! Get a static, by-value property
nuclear@0 154 template <typename T>
nuclear@0 155 bool GetProperty( const char* name, T& out ) const
nuclear@0 156 {
nuclear@0 157 TStaticData<T>* t = (TStaticData<T>*)GetPropertyInternal(name);
nuclear@0 158 if(!t)return false;
nuclear@0 159 out = t->data;
nuclear@0 160 return true;
nuclear@0 161 }
nuclear@0 162
nuclear@0 163 //! Remove a property of a specific type
nuclear@0 164 void RemoveProperty( const char* name) {
nuclear@0 165 SetGenericPropertyPtr<Base>(pmap,name,NULL);
nuclear@0 166 }
nuclear@0 167
nuclear@0 168 private:
nuclear@0 169
nuclear@0 170 void AddProperty( const char* name, Base* data) {
nuclear@0 171 SetGenericPropertyPtr<Base>(pmap,name,data);
nuclear@0 172 }
nuclear@0 173
nuclear@0 174 Base* GetPropertyInternal( const char* name) const {
nuclear@0 175 return GetGenericProperty<Base*>(pmap,name,NULL);
nuclear@0 176 }
nuclear@0 177
nuclear@0 178 private:
nuclear@0 179
nuclear@0 180 //! Map of all stored properties
nuclear@0 181 PropertyMap pmap;
nuclear@0 182 };
nuclear@0 183
nuclear@0 184 #if 0
nuclear@0 185
nuclear@0 186 // ---------------------------------------------------------------------------
nuclear@0 187 /** @brief Represents a dependency table for a postprocessing steps.
nuclear@0 188 *
nuclear@0 189 * For future use.
nuclear@0 190 */
nuclear@0 191 struct PPDependencyTable
nuclear@0 192 {
nuclear@0 193 unsigned int execute_me_before_these;
nuclear@0 194 unsigned int execute_me_after_these;
nuclear@0 195 unsigned int only_if_these_are_not_specified;
nuclear@0 196 unsigned int mutually_exclusive_with;
nuclear@0 197 };
nuclear@0 198
nuclear@0 199 #endif
nuclear@0 200
nuclear@0 201
nuclear@0 202 #define AI_SPP_SPATIAL_SORT "$Spat"
nuclear@0 203
nuclear@0 204 // ---------------------------------------------------------------------------
nuclear@0 205 /** The BaseProcess defines a common interface for all post processing steps.
nuclear@0 206 * A post processing step is run after a successful import if the caller
nuclear@0 207 * specified the corresponding flag when calling ReadFile().
nuclear@0 208 * Enum #aiPostProcessSteps defines which flags are available.
nuclear@0 209 * After a successful import the Importer iterates over its internal array
nuclear@0 210 * of processes and calls IsActive() on each process to evaluate if the step
nuclear@0 211 * should be executed. If the function returns true, the class' Execute()
nuclear@0 212 * function is called subsequently.
nuclear@0 213 */
nuclear@0 214 class ASSIMP_API_WINONLY BaseProcess
nuclear@0 215 {
nuclear@0 216 friend class Importer;
nuclear@0 217
nuclear@0 218 public:
nuclear@0 219
nuclear@0 220 /** Constructor to be privately used by Importer */
nuclear@0 221 BaseProcess();
nuclear@0 222
nuclear@0 223 /** Destructor, private as well */
nuclear@0 224 virtual ~BaseProcess();
nuclear@0 225
nuclear@0 226 public:
nuclear@0 227
nuclear@0 228 // -------------------------------------------------------------------
nuclear@0 229 /** Returns whether the processing step is present in the given flag.
nuclear@0 230 * @param pFlags The processing flags the importer was called with. A
nuclear@0 231 * bitwise combination of #aiPostProcessSteps.
nuclear@0 232 * @return true if the process is present in this flag fields,
nuclear@0 233 * false if not.
nuclear@0 234 */
nuclear@0 235 virtual bool IsActive( unsigned int pFlags) const = 0;
nuclear@0 236
nuclear@0 237 // -------------------------------------------------------------------
nuclear@0 238 /** Check whether this step expects its input vertex data to be
nuclear@0 239 * in verbose format. */
nuclear@0 240 virtual bool RequireVerboseFormat() const;
nuclear@0 241
nuclear@0 242 // -------------------------------------------------------------------
nuclear@0 243 /** Executes the post processing step on the given imported data.
nuclear@0 244 * The function deletes the scene if the postprocess step fails (
nuclear@0 245 * the object pointer will be set to NULL).
nuclear@0 246 * @param pImp Importer instance (pImp->mScene must be valid)
nuclear@0 247 */
nuclear@0 248 void ExecuteOnScene( Importer* pImp);
nuclear@0 249
nuclear@0 250 // -------------------------------------------------------------------
nuclear@0 251 /** Called prior to ExecuteOnScene().
nuclear@0 252 * The function is a request to the process to update its configuration
nuclear@0 253 * basing on the Importer's configuration property list.
nuclear@0 254 */
nuclear@0 255 virtual void SetupProperties(const Importer* pImp);
nuclear@0 256
nuclear@0 257 // -------------------------------------------------------------------
nuclear@0 258 /** Executes the post processing step on the given imported data.
nuclear@0 259 * A process should throw an ImportErrorException* if it fails.
nuclear@0 260 * This method must be implemented by deriving classes.
nuclear@0 261 * @param pScene The imported data to work at.
nuclear@0 262 */
nuclear@0 263 virtual void Execute( aiScene* pScene) = 0;
nuclear@0 264
nuclear@0 265
nuclear@0 266 // -------------------------------------------------------------------
nuclear@0 267 /** Assign a new SharedPostProcessInfo to the step. This object
nuclear@0 268 * allows multiple postprocess steps to share data.
nuclear@0 269 * @param sh May be NULL
nuclear@0 270 */
nuclear@0 271 inline void SetSharedData(SharedPostProcessInfo* sh) {
nuclear@0 272 shared = sh;
nuclear@0 273 }
nuclear@0 274
nuclear@0 275 // -------------------------------------------------------------------
nuclear@0 276 /** Get the shared data that is assigned to the step.
nuclear@0 277 */
nuclear@0 278 inline SharedPostProcessInfo* GetSharedData() {
nuclear@0 279 return shared;
nuclear@0 280 }
nuclear@0 281
nuclear@0 282 protected:
nuclear@0 283
nuclear@0 284 /** See the doc of #SharedPostProcessInfo for more details */
nuclear@0 285 SharedPostProcessInfo* shared;
nuclear@0 286
nuclear@0 287 /** Currently active progress handler */
nuclear@0 288 ProgressHandler* progress;
nuclear@0 289 };
nuclear@0 290
nuclear@0 291
nuclear@0 292 } // end of namespace Assimp
nuclear@0 293
nuclear@0 294 #endif // AI_BASEPROCESS_H_INC