GraphicsAPI_2020C
types.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2017, assimp team
7 
8 
9 All rights reserved.
10 
11 Redistribution and use of this software in source and binary forms,
12 with or without modification, are permitted provided that the following
13 conditions are met:
14 
15 * Redistributions of source code must retain the above
16  copyright notice, this list of conditions and the
17  following disclaimer.
18 
19 * Redistributions in binary form must reproduce the above
20  copyright notice, this list of conditions and the
21  following disclaimer in the documentation and/or other
22  materials provided with the distribution.
23 
24 * Neither the name of the assimp team, nor the names of its
25  contributors may be used to endorse or promote products
26  derived from this software without specific prior
27  written permission of the assimp team.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ---------------------------------------------------------------------------
41 */
42 
46 #pragma once
47 #ifndef AI_TYPES_H_INC
48 #define AI_TYPES_H_INC
49 
50 // Some runtime headers
51 #include <sys/types.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 static
114 const size_t MAXLEN = 1024;
115 #else
116 # define MAXLEN 1024
117 #endif
118 
119 // ----------------------------------------------------------------------------------
122 struct aiPlane
123 {
124 #ifdef __cplusplus
125  aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
126  aiPlane (ai_real _a, ai_real _b, ai_real _c, ai_real _d)
127  : a(_a), b(_b), c(_c), d(_d) {}
128 
129  aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
130 
131 #endif // !__cplusplus
132 
134  ai_real a,b,c,d;
135 }; // !struct aiPlane
136 
137 // ----------------------------------------------------------------------------------
140 struct aiRay
141 {
142 #ifdef __cplusplus
143  aiRay () {}
144  aiRay (const aiVector3D& _pos, const aiVector3D& _dir)
145  : pos(_pos), dir(_dir) {}
146 
147  aiRay (const aiRay& o) : pos (o.pos), dir (o.dir) {}
148 
149 #endif // !__cplusplus
150 
152  C_STRUCT aiVector3D pos, dir;
153 }; // !struct aiRay
154 
155 // ----------------------------------------------------------------------------------
158 struct aiColor3D
159 {
160 #ifdef __cplusplus
161  aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
162  aiColor3D (ai_real _r, ai_real _g, ai_real _b) : r(_r), g(_g), b(_b) {}
163  explicit aiColor3D (ai_real _r) : r(_r), g(_r), b(_r) {}
164  aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
165 
167  // TODO: add epsilon?
168  bool operator == (const aiColor3D& other) const
169  {return r == other.r && g == other.g && b == other.b;}
170 
172  // TODO: add epsilon?
173  bool operator != (const aiColor3D& other) const
174  {return r != other.r || g != other.g || b != other.b;}
175 
177  // TODO: add epsilon?
178  bool operator < (const aiColor3D& other) const {
179  return r < other.r || ( r == other.r && (g < other.g || (g == other.g && b < other.b ) ) );
180  }
181 
183  aiColor3D operator+(const aiColor3D& c) const {
184  return aiColor3D(r+c.r,g+c.g,b+c.b);
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*(ai_real f) const {
199  return aiColor3D(r*f,g*f,b*f);
200  }
201 
203  ai_real operator[](unsigned int i) const {
204  return *(&r + i);
205  }
206 
208  ai_real& operator[](unsigned int i) {
209  if ( 0 == i ) {
210  return r;
211  } else if ( 1 == i ) {
212  return g;
213  } else if ( 2 == i ) {
214  return b;
215  }
216  return r;
217  }
218 
220  bool IsBlack() const {
221  static const ai_real epsilon = ai_real(10e-3);
222  return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
223  }
224 
225 #endif // !__cplusplus
226 
228  ai_real r, g, b;
229 }; // !struct aiColor3D
230 
231 // ----------------------------------------------------------------------------------
252 struct aiString
253 {
254 #ifdef __cplusplus
255 
256  aiString() :
257  length(0)
258  {
259  data[0] = '\0';
260 
261 #ifdef ASSIMP_BUILD_DEBUG
262  // Debug build: overwrite the string on its full length with ESC (27)
263  memset(data+1,27,MAXLEN-1);
264 #endif
265  }
266 
268  aiString(const aiString& rOther) :
269  length(rOther.length)
270  {
271  // Crop the string to the maximum length
272  length = length>=MAXLEN?MAXLEN-1:length;
273  memcpy( data, rOther.data, length);
274  data[length] = '\0';
275  }
276 
278  explicit aiString(const std::string& pString) :
279  length(pString.length())
280  {
281  length = length>=MAXLEN?MAXLEN-1:length;
282  memcpy( data, pString.c_str(), length);
283  data[length] = '\0';
284  }
285 
287  void Set( const std::string& pString) {
288  if( pString.length() > MAXLEN - 1) {
289  return;
290  }
291  length = pString.length();
292  memcpy( data, pString.c_str(), length);
293  data[length] = 0;
294  }
295 
297  void Set( const char* sz) {
298  const size_t len = ::strlen(sz);
299  if( len > MAXLEN - 1) {
300  return;
301  }
302  length = len;
303  memcpy( data, sz, len);
304  data[len] = 0;
305  }
306 
308  aiString& operator = (const char* sz) {
309  Set(sz);
310  return *this;
311  }
312 
314  aiString& operator = ( const std::string& pString) {
315  Set(pString);
316  return *this;
317  }
318 
320  bool operator==(const aiString& other) const {
321  return (length == other.length && 0 == memcmp(data,other.data,length));
322  }
323 
325  bool operator!=(const aiString& other) const {
326  return (length != other.length || 0 != memcmp(data,other.data,length));
327  }
328 
330  void Append (const char* app) {
331  const size_t len = ::strlen(app);
332  if (!len) {
333  return;
334  }
335  if (length + len >= MAXLEN) {
336  return;
337  }
338 
339  memcpy(&data[length],app,len+1);
340  length += len;
341  }
342 
344  void Clear () {
345  length = 0;
346  data[0] = '\0';
347 
348 #ifdef ASSIMP_BUILD_DEBUG
349  // Debug build: overwrite the string on its full length with ESC (27)
350  memset(data+1,27,MAXLEN-1);
351 #endif
352  }
353 
355  const char* C_Str() const {
356  return data;
357  }
358 
359 #endif // !__cplusplus
360 
364  size_t length;
365 
367  char data[MAXLEN];
368 } ; // !struct aiString
369 
370 
371 // ----------------------------------------------------------------------------------
375 typedef enum aiReturn
376 {
379 
382 
387 
391  _AI_ENFORCE_ENUM_SIZE = 0x7fffffff
392 
394 } aiReturn; // !enum aiReturn
395 
396 // just for backwards compatibility, don't use these constants anymore
397 #define AI_SUCCESS aiReturn_SUCCESS
398 #define AI_FAILURE aiReturn_FAILURE
399 #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY
400 
401 // ----------------------------------------------------------------------------------
406 {
409 
412 
415 
419  _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff
420 
422 }; // !enum aiOrigin
423 
424 // ----------------------------------------------------------------------------------
430 {
433 
436 
439 
444 
448  _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
450 }; // !enum aiDefaultLogStream
451 
452 // just for backwards compatibility, don't use these constants anymore
453 #define DLS_FILE aiDefaultLogStream_FILE
454 #define DLS_STDOUT aiDefaultLogStream_STDOUT
455 #define DLS_STDERR aiDefaultLogStream_STDERR
456 #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER
457 
458 // ----------------------------------------------------------------------------------
464 {
465 #ifdef __cplusplus
466 
469  : textures (0)
470  , materials (0)
471  , meshes (0)
472  , nodes (0)
473  , animations (0)
474  , cameras (0)
475  , lights (0)
476  , total (0)
477  {}
478 
479 #endif
480 
482  unsigned int textures;
483 
485  unsigned int materials;
486 
488  unsigned int meshes;
489 
491  unsigned int nodes;
492 
494  unsigned int animations;
495 
497  unsigned int cameras;
498 
500  unsigned int lights;
501 
503  unsigned int total;
504 }; // !struct aiMemoryInfo
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 // Include implementation files
511 #include "vector2.inl"
512 #include "vector3.inl"
513 #include "color4.inl"
514 #include "quaternion.inl"
515 #include "matrix3x3.inl"
516 #include "matrix4x4.inl"
517 
518 #endif // AI_TYPES_H_INC
Beginning of the file.
Definition: types.h:408
3D vector structure, including operators when compiling in C++
Assimp&#39;s CPP-API and all internal APIs.
Definition: DefaultIOStream.h:51
ai_real r
Red, green and blue color values.
Definition: types.h:228
Stream the log to std::cout.
Definition: types.h:435
Represents a plane in a three-dimensional, euclidean space.
Definition: types.h:122
unsigned int lights
Storage allocated for light data.
Definition: types.h:500
Definition of a 3x3 matrix, including operators when compiling in C++.
Represents a ray.
Definition: types.h:140
unsigned int total
Total storage allocated for the full import.
Definition: types.h:503
Assimp build configuration setup.
Stream the log to std::cerr.
Definition: types.h:438
Stores the memory requirements for different components (e.g.
Definition: types.h:463
C_STRUCT aiVector3D pos
Position and direction of the ray.
Definition: types.h:152
aiReturn
Standard return type for some library functions.
Definition: types.h:375
unsigned int animations
Storage allocated for animation data.
Definition: types.h:494
Inline implementation of the 3x3 matrix operators.
unsigned int meshes
Storage allocated for mesh data.
Definition: types.h:488
GLM_FUNC_QUALIFIER T length(vec< L, T, Q > const &v)
Returns the length of x, i.e., sqrt(x * x).
Definition: func_geometric.inl:136
GLM_FUNC_DECL GLM_CONSTEXPR genType epsilon()
Return the epsilon constant for floating point types.
Definition: scalar_constants.inl:6
aiOrigin
Seek origins (for the virtual file system API).
Definition: types.h:405
unsigned int textures
Storage allocated for texture data.
Definition: types.h:482
Indicates that not enough memory was available to perform the requested operation.
Definition: types.h:386
MSVC only: Stream the log the the debugger (this relies on OutputDebugString from the Win32 SDK) ...
Definition: types.h:443
End of the file, offsets must be negative.
Definition: types.h:414
Represents an UTF-8 string, zero byte terminated.
Definition: types.h:252
Current position of the file pointer.
Definition: types.h:411
#define MAXLEN
Maximum dimension for strings, ASSIMP strings are zero terminated.
Definition: types.h:116
Inline implementation of the 4x4 matrix operators.
unsigned int cameras
Storage allocated for camera data.
Definition: types.h:497
4x4 matrix structure, including operators when compiling in C++
Inline implementation of aiVector2t<TReal> operators.
size_t length
Binary length of the string excluding the terminal 0.
Definition: types.h:364
Stream the log to a file.
Definition: types.h:432
aiDefaultLogStream
Enumerates predefined log streaming destinations.
Definition: types.h:429
Definition: vector3.h:135
GLM_FUNC_DECL GLM_CONSTEXPR genType e()
Return e constant.
Definition: constants.inl:102
Represents a color in Red-Green-Blue space.
Definition: types.h:158
Inline implementation of aiColor4t<TReal> operators.
Indicates that a function was successful.
Definition: types.h:378
unsigned int nodes
Storage allocated for node data.
Definition: types.h:491
ai_real a
Plane equation.
Definition: types.h:134
Inline implementation of aiVector3t<TReal> operators.
aiMemoryInfo()
Default constructor.
Definition: types.h:468
Quaternion structure, including operators when compiling in C++.
char data[MAXLEN]
String buffer.
Definition: types.h:367
RGBA color structure, including operators when compiling in C++.
Indicates that a function failed.
Definition: types.h:381
2D vector structure, including operators when compiling in C++
unsigned int materials
Storage allocated for material data.
Definition: types.h:485