vrshoot

view libs/assimp/assimp/types.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
42 /** @file types.h
43 * Basic data types and primitives, such as vectors or colors.
44 */
45 #ifndef AI_TYPES_H_INC
46 #define AI_TYPES_H_INC
48 // Some runtime headers
49 #include <sys/types.h>
50 #include <memory.h>
51 #include <math.h>
52 #include <stddef.h>
53 #include <limits.h>
55 // Our compile configuration
56 #include "defs.h"
58 // Some types moved to separate header due to size of operators
59 #include "vector3.h"
60 #include "vector2.h"
61 #include "color4.h"
62 #include "matrix3x3.h"
63 #include "matrix4x4.h"
64 #include "quaternion.h"
66 #ifdef __cplusplus
67 #include <new> // for std::nothrow_t
68 #include <string> // for aiString::Set(const std::string&)
70 namespace Assimp {
71 //! @cond never
72 namespace Intern {
73 // --------------------------------------------------------------------
74 /** @brief Internal helper class to utilize our internal new/delete
75 * routines for allocating object of this and derived classes.
76 *
77 * By doing this you can safely share class objects between Assimp
78 * and the application - it works even over DLL boundaries. A good
79 * example is the #IOSystem where the application allocates its custom
80 * #IOSystem, then calls #Importer::SetIOSystem(). When the Importer
81 * destructs, Assimp calls operator delete on the stored #IOSystem.
82 * If it lies on a different heap than Assimp is working with,
83 * the application is determined to crash.
84 */
85 // --------------------------------------------------------------------
86 #ifndef SWIG
87 struct ASSIMP_API AllocateFromAssimpHeap {
88 // http://www.gotw.ca/publications/mill15.htm
90 // new/delete overload
91 void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */;
92 void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw();
93 void operator delete ( void* data);
95 // array new/delete overload
96 void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */;
97 void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw();
98 void operator delete[] ( void* data);
100 }; // struct AllocateFromAssimpHeap
101 #endif
102 } // namespace Intern
103 //! @endcond
104 } // namespace Assimp
106 extern "C" {
107 #endif
109 /** Maximum dimension for strings, ASSIMP strings are zero terminated. */
110 #ifdef __cplusplus
111 const size_t MAXLEN = 1024;
112 #else
113 # define MAXLEN 1024
114 #endif
116 #include "./Compiler/pushpack1.h"
118 // ----------------------------------------------------------------------------------
119 /** Represents a plane in a three-dimensional, euclidean space
120 */
121 struct aiPlane
122 {
123 #ifdef __cplusplus
124 aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
125 aiPlane (float _a, float _b, float _c, float _d)
126 : a(_a), b(_b), c(_c), d(_d) {}
128 aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
130 #endif // !__cplusplus
132 //! Plane equation
133 float a,b,c,d;
134 } PACK_STRUCT; // !struct aiPlane
136 // ----------------------------------------------------------------------------------
137 /** Represents a ray
138 */
139 struct aiRay
140 {
141 #ifdef __cplusplus
142 aiRay () {}
143 aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
144 : pos(_pos), dir(_dir) {}
146 aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}
148 #endif // !__cplusplus
150 //! Position and direction of the ray
151 C_STRUCT aiVector3D pos, dir;
152 } PACK_STRUCT; // !struct aiRay
154 // ----------------------------------------------------------------------------------
155 /** Represents a color in Red-Green-Blue space.
156 */
157 struct aiColor3D
158 {
159 #ifdef __cplusplus
160 aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
161 aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
162 aiColor3D (float _r) : r(_r), g(_r), b(_r) {}
163 aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
165 /** Component-wise comparison */
166 // TODO: add epsilon?
167 bool operator == (const aiColor3D& other) const
168 {return r == other.r && g == other.g && b == other.b;}
170 /** Component-wise inverse comparison */
171 // TODO: add epsilon?
172 bool operator != (const aiColor3D& other) const
173 {return r != other.r || g != other.g || b != other.b;}
175 /** Component-wise addition */
176 aiColor3D operator+(const aiColor3D& c) const {
177 return aiColor3D(r+c.r,g+c.g,b+c.b);
178 }
180 /** Component-wise subtraction */
181 aiColor3D operator-(const aiColor3D& c) const {
182 return aiColor3D(r-c.r,g-c.g,b-c.b);
183 }
185 /** Component-wise multiplication */
186 aiColor3D operator*(const aiColor3D& c) const {
187 return aiColor3D(r*c.r,g*c.g,b*c.b);
188 }
190 /** Multiply with a scalar */
191 aiColor3D operator*(float f) const {
192 return aiColor3D(r*f,g*f,b*f);
193 }
195 /** Access a specific color component */
196 float operator[](unsigned int i) const {
197 return *(&r + i);
198 }
200 /** Access a specific color component */
201 float& operator[](unsigned int i) {
202 return *(&r + i);
203 }
205 /** Check whether a color is black */
206 bool IsBlack() const {
207 static const float epsilon = 10e-3f;
208 return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon;
209 }
211 #endif // !__cplusplus
213 //! Red, green and blue color values
214 float r, g, b;
215 } PACK_STRUCT; // !struct aiColor3D
216 #include "./Compiler/poppack1.h"
218 // ----------------------------------------------------------------------------------
219 /** Represents an UTF-8 string, zero byte terminated.
220 *
221 * The character set of an aiString is explicitly defined to be UTF-8. This Unicode
222 * transformation was chosen in the belief that most strings in 3d files are limited
223 * to ASCII, thus the character set needed to be strictly ASCII compatible.
224 *
225 * Most text file loaders provide proper Unicode input file handling, special unicode
226 * characters are correctly transcoded to UTF8 and are kept throughout the libraries'
227 * import pipeline.
228 *
229 * For most applications, it will be absolutely sufficient to interpret the
230 * aiString as ASCII data and work with it as one would work with a plain char*.
231 * Windows users in need of proper support for i.e asian characters can use the
232 * #MultiByteToWideChar(), #WideCharToMultiByte() WinAPI functionality to convert the
233 * UTF-8 strings to their working character set (i.e. MBCS, WideChar).
234 *
235 * We use this representation instead of std::string to be C-compatible. The
236 * (binary) length of such a string is limited to MAXLEN characters (including the
237 * the terminating zero).
238 */
239 struct aiString
240 {
241 #ifdef __cplusplus
242 /** Default constructor, the string is set to have zero length */
243 aiString() :
244 length(0)
245 {
246 data[0] = '\0';
248 #ifdef _DEBUG
249 // Debug build: overwrite the string on its full length with ESC (27)
250 memset(data+1,27,MAXLEN-1);
251 #endif
252 }
254 /** Copy constructor */
255 aiString(const aiString& rOther) :
256 length(rOther.length)
257 {
258 // Crop the string to the maximum length
259 length = length>=MAXLEN?MAXLEN-1:length;
260 memcpy( data, rOther.data, length);
261 data[length] = '\0';
262 }
264 /** Constructor from std::string */
265 explicit aiString(const std::string& pString) :
266 length(pString.length())
267 {
268 length = length>=MAXLEN?MAXLEN-1:length;
269 memcpy( data, pString.c_str(), length);
270 data[length] = '\0';
271 }
273 /** Copy a std::string to the aiString */
274 void Set( const std::string& pString) {
275 if( pString.length() > MAXLEN - 1) {
276 return;
277 }
278 length = pString.length();
279 memcpy( data, pString.c_str(), length);
280 data[length] = 0;
281 }
283 /** Copy a const char* to the aiString */
284 void Set( const char* sz) {
285 const size_t len = ::strlen(sz);
286 if( len > MAXLEN - 1) {
287 return;
288 }
289 length = len;
290 memcpy( data, sz, len);
291 data[len] = 0;
292 }
294 /** Assign a const char* to the string */
295 aiString& operator = (const char* sz) {
296 Set(sz);
297 return *this;
298 }
300 /** Assign a cstd::string to the string */
301 aiString& operator = ( const std::string& pString) {
302 Set(pString);
303 return *this;
304 }
306 /** Comparison operator */
307 bool operator==(const aiString& other) const {
308 return (length == other.length && 0 == memcmp(data,other.data,length));
309 }
311 /** Inverse comparison operator */
312 bool operator!=(const aiString& other) const {
313 return (length != other.length || 0 != memcmp(data,other.data,length));
314 }
316 /** Append a string to the string */
317 void Append (const char* app) {
318 const size_t len = ::strlen(app);
319 if (!len) {
320 return;
321 }
322 if (length + len >= MAXLEN) {
323 return;
324 }
326 memcpy(&data[length],app,len+1);
327 length += len;
328 }
330 /** Clear the string - reset its length to zero */
331 void Clear () {
332 length = 0;
333 data[0] = '\0';
335 #ifdef _DEBUG
336 // Debug build: overwrite the string on its full length with ESC (27)
337 memset(data+1,27,MAXLEN-1);
338 #endif
339 }
341 /** Returns a pointer to the underlying zero-terminated array of characters */
342 const char* C_Str() const {
343 return data;
344 }
346 #endif // !__cplusplus
348 /** Binary length of the string excluding the terminal 0. This is NOT the
349 * logical length of strings containing UTF-8 multibyte sequences! It's
350 * the number of bytes from the beginning of the string to its end.*/
351 size_t length;
353 /** String buffer. Size limit is MAXLEN */
354 char data[MAXLEN];
355 } ; // !struct aiString
358 // ----------------------------------------------------------------------------------
359 /** Standard return type for some library functions.
360 * Rarely used, and if, mostly in the C API.
361 */
362 enum aiReturn
363 {
364 /** Indicates that a function was successful */
365 aiReturn_SUCCESS = 0x0,
367 /** Indicates that a function failed */
368 aiReturn_FAILURE = -0x1,
370 /** Indicates that not enough memory was available
371 * to perform the requested operation
372 */
373 aiReturn_OUTOFMEMORY = -0x3,
375 /** @cond never
376 * Force 32-bit size enum
377 */
378 _AI_ENFORCE_ENUM_SIZE = 0x7fffffff
379 }; // !enum aiReturn
381 // just for backwards compatibility, don't use these constants anymore
382 #define AI_SUCCESS aiReturn_SUCCESS
383 #define AI_FAILURE aiReturn_FAILURE
384 #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY
386 // ----------------------------------------------------------------------------------
387 /** Seek origins (for the virtual file system API).
388 * Much cooler than using SEEK_SET, SEEK_CUR or SEEK_END.
389 */
390 enum aiOrigin
391 {
392 /** Beginning of the file */
393 aiOrigin_SET = 0x0,
395 /** Current position of the file pointer */
396 aiOrigin_CUR = 0x1,
398 /** End of the file, offsets must be negative */
399 aiOrigin_END = 0x2,
401 /** @cond never
402 * Force 32-bit size enum
403 */
404 _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff
405 }; // !enum aiOrigin
407 // ----------------------------------------------------------------------------------
408 /** @brief Enumerates predefined log streaming destinations.
409 * Logging to these streams can be enabled with a single call to
410 * #LogStream::createDefaultStream or #aiAttachPredefinedLogStream(),
411 * respectively.
412 */
413 enum aiDefaultLogStream
414 {
415 /** Stream the log to a file */
416 aiDefaultLogStream_FILE = 0x1,
418 /** Stream the log to std::cout */
419 aiDefaultLogStream_STDOUT = 0x2,
421 /** Stream the log to std::cerr */
422 aiDefaultLogStream_STDERR = 0x4,
424 /** MSVC only: Stream the log the the debugger
425 * (this relies on OutputDebugString from the Win32 SDK)
426 */
427 aiDefaultLogStream_DEBUGGER = 0x8,
429 /** @cond never
430 * Force 32-bit size enum
431 */
432 _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
433 }; // !enum aiDefaultLogStream
435 // just for backwards compatibility, don't use these constants anymore
436 #define DLS_FILE aiDefaultLogStream_FILE
437 #define DLS_STDOUT aiDefaultLogStream_STDOUT
438 #define DLS_STDERR aiDefaultLogStream_STDERR
439 #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER
441 // ----------------------------------------------------------------------------------
442 /** Stores the memory requirements for different components (e.g. meshes, materials,
443 * animations) of an import. All sizes are in bytes.
444 * @see Importer::GetMemoryRequirements()
445 */
446 struct aiMemoryInfo
447 {
448 #ifdef __cplusplus
450 /** Default constructor */
451 aiMemoryInfo()
452 : textures (0)
453 , materials (0)
454 , meshes (0)
455 , nodes (0)
456 , animations (0)
457 , cameras (0)
458 , lights (0)
459 , total (0)
460 {}
462 #endif
464 /** Storage allocated for texture data */
465 unsigned int textures;
467 /** Storage allocated for material data */
468 unsigned int materials;
470 /** Storage allocated for mesh data */
471 unsigned int meshes;
473 /** Storage allocated for node data */
474 unsigned int nodes;
476 /** Storage allocated for animation data */
477 unsigned int animations;
479 /** Storage allocated for camera data */
480 unsigned int cameras;
482 /** Storage allocated for light data */
483 unsigned int lights;
485 /** Total storage allocated for the full import. */
486 unsigned int total;
487 }; // !struct aiMemoryInfo
489 #ifdef __cplusplus
490 }
491 #endif //! __cplusplus
493 // Include implementation files
494 #include "vector2.inl"
495 #include "vector3.inl"
496 #include "color4.inl"
497 #include "quaternion.inl"
498 #include "matrix3x3.inl"
499 #include "matrix4x4.inl"
500 #endif