vrshoot

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