BRE12
types.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2012, assimp team
7 
8 All rights reserved.
9 
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:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
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.
22 
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.
27 
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 */
41 
45 #ifndef AI_TYPES_H_INC
46 #define AI_TYPES_H_INC
47 
48 // Some runtime headers
49 #include <sys/types.h>
50 #include <memory.h>
51 #include <math.h>
52 #include <stddef.h>
53 #include <string.h>
54 #include <limits.h>
55 
56 // Our compile configuration
57 #include "defs.h"
58 
59 // Some types moved to separate header due to size of operators
60 #include "vector3.h"
61 #include "vector2.h"
62 #include "color4.h"
63 #include "matrix3x3.h"
64 #include "matrix4x4.h"
65 #include "quaternion.h"
66 
67 #ifdef __cplusplus
68 #include <cstring>
69 #include <new> // for std::nothrow_t
70 #include <string> // for aiString::Set(const std::string&)
71 
72 namespace Assimp {
74 namespace Intern {
75  // --------------------------------------------------------------------
87  // --------------------------------------------------------------------
88 #ifndef SWIG
89  struct ASSIMP_API AllocateFromAssimpHeap {
90  // http://www.gotw.ca/publications/mill15.htm
91 
92  // new/delete overload
93  void *operator new ( size_t num_bytes) /* throw( std::bad_alloc ) */;
94  void *operator new ( size_t num_bytes, const std::nothrow_t& ) throw();
95  void operator delete ( void* data);
96 
97  // array new/delete overload
98  void *operator new[] ( size_t num_bytes) /* throw( std::bad_alloc ) */;
99  void *operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw();
100  void operator delete[] ( void* data);
101 
102  }; // struct AllocateFromAssimpHeap
103 #endif
104 } // namespace Intern
106 } // namespace Assimp
107 
108 extern "C" {
109 #endif
110 
112 #ifdef __cplusplus
113 const size_t MAXLEN = 1024;
114 #else
115 # define MAXLEN 1024
116 #endif
117 
118 #include "./Compiler/pushpack1.h"
119 
120 // ----------------------------------------------------------------------------------
123 struct aiPlane
124 {
125 #ifdef __cplusplus
126  aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
127  aiPlane (float _a, float _b, float _c, float _d)
128  : a(_a), b(_b), c(_c), d(_d) {}
129 
130  aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
131 
132 #endif // !__cplusplus
133 
135  float a,b,c,d;
136 } PACK_STRUCT; // !struct aiPlane
137 
138 // ----------------------------------------------------------------------------------
141 struct aiRay
142 {
143 #ifdef __cplusplus
144  aiRay () {}
145  aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
146  : pos(_pos), dir(_dir) {}
147 
148  aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}
149 
150 #endif // !__cplusplus
151 
153  C_STRUCT aiVector3D pos, dir;
154 } PACK_STRUCT; // !struct aiRay
155 
156 // ----------------------------------------------------------------------------------
159 struct aiColor3D
160 {
161 #ifdef __cplusplus
162  aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
163  aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {}
164  aiColor3D (float _r) : r(_r), g(_r), b(_r) {}
165  aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
166 
168  // TODO: add epsilon?
169  bool operator == (const aiColor3D& other) const
170  {return r == other.r && g == other.g && b == other.b;}
171 
173  // TODO: add epsilon?
174  bool operator != (const aiColor3D& other) const
175  {return r != other.r || g != other.g || b != other.b;}
176 
178  // TODO: add epsilon?
179  bool operator < (const aiColor3D& other) const {
180  return r < other.r || (
181  r == other.r && (g < other.g ||
182  (g == other.g && b < other.b)
183  )
184  );
185  }
186 
188  aiColor3D operator+(const aiColor3D& c) const {
189  return aiColor3D(r+c.r,g+c.g,b+c.b);
190  }
191 
193  aiColor3D operator-(const aiColor3D& c) const {
194  return aiColor3D(r-c.r,g-c.g,b-c.b);
195  }
196 
198  aiColor3D operator*(const aiColor3D& c) const {
199  return aiColor3D(r*c.r,g*c.g,b*c.b);
200  }
201 
203  aiColor3D operator*(float f) const {
204  return aiColor3D(r*f,g*f,b*f);
205  }
206 
208  float operator[](unsigned int i) const {
209  return *(&r + i);
210  }
211 
213  float& operator[](unsigned int i) {
214  return *(&r + i);
215  }
216 
218  bool IsBlack() const {
219  static const float epsilon = 10e-3f;
220  return fabs( r ) < epsilon && fabs( g ) < epsilon && fabs( b ) < epsilon;
221  }
222 
223 #endif // !__cplusplus
224 
226  float r, g, b;
227 } PACK_STRUCT; // !struct aiColor3D
228 #include "./Compiler/poppack1.h"
229 
230 // ----------------------------------------------------------------------------------
251 struct aiString
252 {
253 #ifdef __cplusplus
254 
255  aiString() :
256  length(0)
257  {
258  data[0] = '\0';
259 
260 #ifdef ASSIMP_BUILD_DEBUG
261  // Debug build: overwrite the string on its full length with ESC (27)
262  memset(data+1,27,MAXLEN-1);
263 #endif
264  }
265 
267  aiString(const aiString& rOther) :
268  length(rOther.length)
269  {
270  // Crop the string to the maximum length
271  length = length>=MAXLEN?MAXLEN-1:length;
272  memcpy( data, rOther.data, length);
273  data[length] = '\0';
274  }
275 
277  explicit aiString(const std::string& pString) :
278  length(pString.length())
279  {
280  length = length>=MAXLEN?MAXLEN-1:length;
281  memcpy( data, pString.c_str(), length);
282  data[length] = '\0';
283  }
284 
286  void Set( const std::string& pString) {
287  if( pString.length() > MAXLEN - 1) {
288  return;
289  }
290  length = pString.length();
291  memcpy( data, pString.c_str(), length);
292  data[length] = 0;
293  }
294 
296  void Set( const char* sz) {
297  const size_t len = ::strlen(sz);
298  if( len > MAXLEN - 1) {
299  return;
300  }
301  length = len;
302  memcpy( data, sz, len);
303  data[len] = 0;
304  }
305 
307  aiString& operator = (const char* sz) {
308  Set(sz);
309  return *this;
310  }
311 
313  aiString& operator = ( const std::string& pString) {
314  Set(pString);
315  return *this;
316  }
317 
319  bool operator==(const aiString& other) const {
320  return (length == other.length && 0 == memcmp(data,other.data,length));
321  }
322 
324  bool operator!=(const aiString& other) const {
325  return (length != other.length || 0 != memcmp(data,other.data,length));
326  }
327 
329  void Append (const char* app) {
330  const size_t len = ::strlen(app);
331  if (!len) {
332  return;
333  }
334  if (length + len >= MAXLEN) {
335  return;
336  }
337 
338  memcpy(&data[length],app,len+1);
339  length += len;
340  }
341 
343  void Clear () {
344  length = 0;
345  data[0] = '\0';
346 
347 #ifdef ASSIMP_BUILD_DEBUG
348  // Debug build: overwrite the string on its full length with ESC (27)
349  memset(data+1,27,MAXLEN-1);
350 #endif
351  }
352 
354  const char* C_Str() const {
355  return data;
356  }
357 
358 #endif // !__cplusplus
359 
363  size_t length;
364 
366  char data[MAXLEN];
367 } ; // !struct aiString
368 
369 
370 // ----------------------------------------------------------------------------------
374 typedef enum aiReturn
375 {
377  aiReturn_SUCCESS = 0x0,
378 
380  aiReturn_FAILURE = -0x1,
381 
385  aiReturn_OUTOFMEMORY = -0x3,
386 
390  _AI_ENFORCE_ENUM_SIZE = 0x7fffffff
391 } aiReturn; // !enum aiReturn
392 
393 // just for backwards compatibility, don't use these constants anymore
394 #define AI_SUCCESS aiReturn_SUCCESS
395 #define AI_FAILURE aiReturn_FAILURE
396 #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY
397 
398 // ----------------------------------------------------------------------------------
402 enum aiOrigin
403 {
405  aiOrigin_SET = 0x0,
406 
408  aiOrigin_CUR = 0x1,
409 
411  aiOrigin_END = 0x2,
412 
416  _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff
417 }; // !enum aiOrigin
418 
419 // ----------------------------------------------------------------------------------
425 enum aiDefaultLogStream
426 {
428  aiDefaultLogStream_FILE = 0x1,
429 
431  aiDefaultLogStream_STDOUT = 0x2,
432 
434  aiDefaultLogStream_STDERR = 0x4,
435 
439  aiDefaultLogStream_DEBUGGER = 0x8,
440 
444  _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
445 }; // !enum aiDefaultLogStream
446 
447 // just for backwards compatibility, don't use these constants anymore
448 #define DLS_FILE aiDefaultLogStream_FILE
449 #define DLS_STDOUT aiDefaultLogStream_STDOUT
450 #define DLS_STDERR aiDefaultLogStream_STDERR
451 #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER
452 
453 // ----------------------------------------------------------------------------------
458 struct aiMemoryInfo
459 {
460 #ifdef __cplusplus
461 
463  aiMemoryInfo()
464  : textures (0)
465  , materials (0)
466  , meshes (0)
467  , nodes (0)
468  , animations (0)
469  , cameras (0)
470  , lights (0)
471  , total (0)
472  {}
473 
474 #endif
475 
477  unsigned int textures;
478 
480  unsigned int materials;
481 
483  unsigned int meshes;
484 
486  unsigned int nodes;
487 
489  unsigned int animations;
490 
492  unsigned int cameras;
493 
495  unsigned int lights;
496 
498  unsigned int total;
499 }; // !struct aiMemoryInfo
500 
501 #ifdef __cplusplus
502 }
503 #endif
504 
505 // Include implementation files
506 #include "vector2.inl"
507 #include "vector3.inl"
508 #include "color4.inl"
509 #include "quaternion.inl"
510 #include "matrix3x3.inl"
511 #include "matrix4x4.inl"
512 #endif
float a
Plane equation.
Definition: types.h:135
Assimp&#39;s CPP-API and all internal APIs.
Definition: DefaultLogger.hpp:51
Represents a plane in a three-dimensional, euclidean space.
Definition: types.h:123
Definition of a 3x3 matrix, including operators when compiling in C++.
Represents a ray.
Definition: types.h:141
C_STRUCT aiVector3D pos
Position and direction of the ray.
Definition: types.h:153
Represents an UTF-8 string, zero byte terminated.
Definition: types.h:251
#define MAXLEN
Maximum dimension for strings, ASSIMP strings are zero terminated.
Definition: types.h:115
4x4 matrix structure, including operators when compiling in C++
size_t length
Binary length of the string excluding the terminal 0.
Definition: types.h:363
Definition: vector3.h:134
Represents a color in Red-Green-Blue space.
Definition: types.h:159
Quaternion structure, including operators when compiling in C++.
char data[MAXLEN]
String buffer.
Definition: types.h:366
float r
Red, green and blue color values.
Definition: types.h:226