Path Tracer
types.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2020, 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 #pragma once
46 #ifndef AI_TYPES_H_INC
47 #define AI_TYPES_H_INC
48 
49 #ifdef __GNUC__
50 #pragma GCC system_header
51 #endif
52 
53 // Some runtime headers
54 #include <limits.h>
55 #include <stddef.h>
56 #include <stdint.h>
57 #include <string.h>
58 #include <sys/types.h>
59 
60 // Our compile configuration
61 #include <assimp/defs.h>
62 
63 // Some types moved to separate header due to size of operators
64 #include <assimp/vector2.h>
65 #include <assimp/vector3.h>
66 #include <assimp/color4.h>
67 #include <assimp/matrix3x3.h>
68 #include <assimp/matrix4x4.h>
69 #include <assimp/quaternion.h>
70 
71 typedef int32_t ai_int32;
72 typedef uint32_t ai_uint32;
73 
74 #ifdef __cplusplus
75 
76 #include <cstring>
77 #include <new> // for std::nothrow_t
78 #include <string> // for aiString::Set(const std::string&)
79 
80 namespace Assimp {
82 namespace Intern {
83 // --------------------------------------------------------------------
95 // --------------------------------------------------------------------
96 #ifndef SWIG
97 struct ASSIMP_API AllocateFromAssimpHeap {
98  // http://www.gotw.ca/publications/mill15.htm
99 
100  // new/delete overload
101  void *operator new(size_t num_bytes) /* throw( std::bad_alloc ) */;
102  void *operator new(size_t num_bytes, const std::nothrow_t &) throw();
103  void operator delete(void *data);
104 
105  // array new/delete overload
106  void *operator new[](size_t num_bytes) /* throw( std::bad_alloc ) */;
107  void *operator new[](size_t num_bytes, const std::nothrow_t &) throw();
108  void operator delete[](void *data);
109 
110 }; // struct AllocateFromAssimpHeap
111 #endif
112 } // namespace Intern
114 } // namespace Assimp
115 
116 extern "C" {
117 #endif
118 
120 #ifdef __cplusplus
121 static const size_t MAXLEN = 1024;
122 #else
123 #define MAXLEN 1024
124 #endif
125 
126 // ----------------------------------------------------------------------------------
129 struct aiPlane {
130 #ifdef __cplusplus
131  aiPlane() AI_NO_EXCEPT : a(0.f), b(0.f), c(0.f), d(0.f) {}
132  aiPlane(ai_real _a, ai_real _b, ai_real _c, ai_real _d) :
133  a(_a), b(_b), c(_c), d(_d) {}
134 
135  aiPlane(const aiPlane &o) :
136  a(o.a), b(o.b), c(o.c), d(o.d) {}
137 
138 #endif // !__cplusplus
139 
141  ai_real a, b, c, d;
142 }; // !struct aiPlane
143 
144 // ----------------------------------------------------------------------------------
147 struct aiRay {
148 #ifdef __cplusplus
149  aiRay() AI_NO_EXCEPT {}
150  aiRay(const aiVector3D &_pos, const aiVector3D &_dir) :
151  pos(_pos), dir(_dir) {}
152 
153  aiRay(const aiRay &o) :
154  pos(o.pos), dir(o.dir) {}
155 
156 #endif // !__cplusplus
157 
159  C_STRUCT aiVector3D pos, dir;
160 }; // !struct aiRay
161 
162 // ----------------------------------------------------------------------------------
165 struct aiColor3D {
166 #ifdef __cplusplus
167  aiColor3D() AI_NO_EXCEPT : r(0.0f), g(0.0f), b(0.0f) {}
168  aiColor3D(ai_real _r, ai_real _g, ai_real _b) :
169  r(_r), g(_g), b(_b) {}
170  explicit aiColor3D(ai_real _r) :
171  r(_r), g(_r), b(_r) {}
172  aiColor3D(const aiColor3D &o) :
173  r(o.r), g(o.g), b(o.b) {}
174 
175  aiColor3D &operator=(const aiColor3D &o) {
176  r = o.r;
177  g = o.g;
178  b = o.b;
179  return *this;
180  }
181 
183  // TODO: add epsilon?
184  bool operator==(const aiColor3D &other) const { return r == other.r && g == other.g && b == other.b; }
185 
187  // TODO: add epsilon?
188  bool operator!=(const aiColor3D &other) const { return r != other.r || g != other.g || b != other.b; }
189 
191  // TODO: add epsilon?
192  bool operator<(const aiColor3D &other) const {
193  return r < other.r || (r == other.r && (g < other.g || (g == other.g && b < other.b)));
194  }
195 
197  aiColor3D operator+(const aiColor3D &c) const {
198  return aiColor3D(r + c.r, g + c.g, b + c.b);
199  }
200 
202  aiColor3D operator-(const aiColor3D &c) const {
203  return aiColor3D(r - c.r, g - c.g, b - c.b);
204  }
205 
207  aiColor3D operator*(const aiColor3D &c) const {
208  return aiColor3D(r * c.r, g * c.g, b * c.b);
209  }
210 
212  aiColor3D operator*(ai_real f) const {
213  return aiColor3D(r * f, g * f, b * f);
214  }
215 
217  ai_real operator[](unsigned int i) const {
218  return *(&r + i);
219  }
220 
222  ai_real &operator[](unsigned int i) {
223  if (0 == i) {
224  return r;
225  } else if (1 == i) {
226  return g;
227  } else if (2 == i) {
228  return b;
229  }
230  return r;
231  }
232 
234  bool IsBlack() const {
235  static const ai_real epsilon = ai_real(10e-3);
236  return std::fabs(r) < epsilon && std::fabs(g) < epsilon && std::fabs(b) < epsilon;
237  }
238 
239 #endif // !__cplusplus
240 
242  ai_real r, g, b;
243 }; // !struct aiColor3D
244 
245 // ----------------------------------------------------------------------------------
266 struct aiString {
267 #ifdef __cplusplus
268 
269  aiString() AI_NO_EXCEPT
270  : length(0) {
271  data[0] = '\0';
272 
273 #ifdef ASSIMP_BUILD_DEBUG
274  // Debug build: overwrite the string on its full length with ESC (27)
275  memset(data + 1, 27, MAXLEN - 1);
276 #endif
277  }
278 
280  aiString(const aiString &rOther) :
281  length(rOther.length) {
282  // Crop the string to the maximum length
283  length = length >= MAXLEN ? MAXLEN - 1 : length;
284  memcpy(data, rOther.data, length);
285  data[length] = '\0';
286  }
287 
289  explicit aiString(const std::string &pString) :
290  length((ai_uint32)pString.length()) {
291  length = length >= MAXLEN ? MAXLEN - 1 : length;
292  memcpy(data, pString.c_str(), length);
293  data[length] = '\0';
294  }
295 
297  void Set(const std::string &pString) {
298  if (pString.length() > MAXLEN - 1) {
299  return;
300  }
301  length = (ai_uint32)pString.length();
302  memcpy(data, pString.c_str(), length);
303  data[length] = 0;
304  }
305 
307  void Set(const char *sz) {
308  const ai_int32 len = (ai_uint32)::strlen(sz);
309  if (len > (ai_int32)MAXLEN - 1) {
310  return;
311  }
312  length = len;
313  memcpy(data, sz, len);
314  data[len] = 0;
315  }
316 
318  aiString &operator=(const aiString &rOther) {
319  if (this == &rOther) {
320  return *this;
321  }
322 
323  length = rOther.length;
324  ;
325  memcpy(data, rOther.data, length);
326  data[length] = '\0';
327  return *this;
328  }
329 
331  aiString &operator=(const char *sz) {
332  Set(sz);
333  return *this;
334  }
335 
337  aiString &operator=(const std::string &pString) {
338  Set(pString);
339  return *this;
340  }
341 
343  bool operator==(const aiString &other) const {
344  return (length == other.length && 0 == memcmp(data, other.data, length));
345  }
346 
348  bool operator!=(const aiString &other) const {
349  return (length != other.length || 0 != memcmp(data, other.data, length));
350  }
351 
353  void Append(const char *app) {
354  const ai_uint32 len = (ai_uint32)::strlen(app);
355  if (!len) {
356  return;
357  }
358  if (length + len >= MAXLEN) {
359  return;
360  }
361 
362  memcpy(&data[length], app, len + 1);
363  length += len;
364  }
365 
367  void Clear() {
368  length = 0;
369  data[0] = '\0';
370 
371 #ifdef ASSIMP_BUILD_DEBUG
372  // Debug build: overwrite the string on its full length with ESC (27)
373  memset(data + 1, 27, MAXLEN - 1);
374 #endif
375  }
376 
378  const char *C_Str() const {
379  return data;
380  }
381 
382 #endif // !__cplusplus
383 
387  ai_uint32 length;
388 
390  char data[MAXLEN];
391 }; // !struct aiString
392 
393 // ----------------------------------------------------------------------------------
397 typedef enum aiReturn {
400 
403 
408 
412  _AI_ENFORCE_ENUM_SIZE = 0x7fffffff
413 
415 } aiReturn; // !enum aiReturn
416 
417 // just for backwards compatibility, don't use these constants anymore
418 #define AI_SUCCESS aiReturn_SUCCESS
419 #define AI_FAILURE aiReturn_FAILURE
420 #define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY
421 
422 // ----------------------------------------------------------------------------------
426 enum aiOrigin {
429 
432 
435 
439  _AI_ORIGIN_ENFORCE_ENUM_SIZE = 0x7fffffff
440 
442 }; // !enum aiOrigin
443 
444 // ----------------------------------------------------------------------------------
452 
455 
458 
463 
467  _AI_DLS_ENFORCE_ENUM_SIZE = 0x7fffffff
469 }; // !enum aiDefaultLogStream
470 
471 // just for backwards compatibility, don't use these constants anymore
472 #define DLS_FILE aiDefaultLogStream_FILE
473 #define DLS_STDOUT aiDefaultLogStream_STDOUT
474 #define DLS_STDERR aiDefaultLogStream_STDERR
475 #define DLS_DEBUGGER aiDefaultLogStream_DEBUGGER
476 
477 // ----------------------------------------------------------------------------------
482 struct aiMemoryInfo {
483 #ifdef __cplusplus
484 
486  aiMemoryInfo() AI_NO_EXCEPT
487  : textures(0),
488  materials(0),
489  meshes(0),
490  nodes(0),
491  animations(0),
492  cameras(0),
493  lights(0),
494  total(0) {}
495 
496 #endif
497 
499  unsigned int textures;
500 
502  unsigned int materials;
503 
505  unsigned int meshes;
506 
508  unsigned int nodes;
509 
511  unsigned int animations;
512 
514  unsigned int cameras;
515 
517  unsigned int lights;
518 
520  unsigned int total;
521 }; // !struct aiMemoryInfo
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 
527 // Include implementation files
528 #include "vector2.inl"
529 #include "vector3.inl"
530 #include "color4.inl"
531 #include "matrix3x3.inl"
532 #include "matrix4x4.inl"
533 #include "quaternion.inl"
534 
535 #endif // AI_TYPES_H_INC
MAXLEN
#define MAXLEN
Definition: types.h:123
aiMemoryInfo::total
unsigned int total
Definition: types.h:520
aiMemoryInfo::aiMemoryInfo
aiMemoryInfo() AI_NO_EXCEPT
Definition: types.h:486
matrix3x3.h
Definition of a 3x3 matrix, including operators when compiling in C++.
aiMemoryInfo::animations
unsigned int animations
Definition: types.h:511
aiRay
Definition: types.h:147
aiVector3D
Definition: vector3.h:136
aiOrigin
aiOrigin
Definition: types.h:426
aiDefaultLogStream_DEBUGGER
@ aiDefaultLogStream_DEBUGGER
Definition: types.h:462
aiOrigin_SET
@ aiOrigin_SET
Definition: types.h:428
aiDefaultLogStream_STDOUT
@ aiDefaultLogStream_STDOUT
Definition: types.h:454
quaternion.h
Quaternion structure, including operators when compiling in C++.
aiDefaultLogStream_FILE
@ aiDefaultLogStream_FILE
Definition: types.h:451
aiOrigin_END
@ aiOrigin_END
Definition: types.h:434
matrix3x3.inl
Inline implementation of the 3x3 matrix operators.
aiReturn
aiReturn
Definition: types.h:397
aiString::length
ai_uint32 length
Definition: types.h:387
aiMemoryInfo::meshes
unsigned int meshes
Definition: types.h:505
vector2.h
2D vector structure, including operators when compiling in C++
color4.inl
Inline implementation of aiColor4t<TReal> operators.
matrix4x4.h
4x4 matrix structure, including operators when compiling in C++
aiPlane
Definition: types.h:129
aiMemoryInfo::lights
unsigned int lights
Definition: types.h:517
aiColor3D
Definition: types.h:165
aiDefaultLogStream
aiDefaultLogStream
Enumerates predefined log streaming destinations. Logging to these streams can be enabled with a sing...
Definition: types.h:449
matrix4x4.inl
Inline implementation of the 4x4 matrix operators.
aiPlane::a
ai_real a
Plane equation.
Definition: types.h:141
aiDefaultLogStream_STDERR
@ aiDefaultLogStream_STDERR
Definition: types.h:457
aiMemoryInfo::materials
unsigned int materials
Definition: types.h:502
aiMemoryInfo::nodes
unsigned int nodes
Definition: types.h:508
aiString
Definition: types.h:266
vector3.h
3D vector structure, including operators when compiling in C++
aiString::data
char data[MAXLEN]
Definition: types.h:390
vector2.inl
Inline implementation of aiVector2t<TReal> operators.
vector3.inl
Inline implementation of aiVector3t<TReal> operators.
aiRay::pos
C_STRUCT aiVector3D pos
Position and direction of the ray.
Definition: types.h:159
defs.h
Assimp build configuration setup. See the notes in the comment blocks to find out how to customize yo...
aiColor3D::r
ai_real r
Red, green and blue color values.
Definition: types.h:242
aiMemoryInfo
Definition: types.h:482
aiReturn_OUTOFMEMORY
@ aiReturn_OUTOFMEMORY
Definition: types.h:407
color4.h
RGBA color structure, including operators when compiling in C++.
aiMemoryInfo::textures
unsigned int textures
Definition: types.h:499
Assimp
Definition: ai_assert.h:50
aiMemoryInfo::cameras
unsigned int cameras
Definition: types.h:514
quaternion.inl
Inline implementation of aiQuaterniont<TReal> operators.
aiReturn_SUCCESS
@ aiReturn_SUCCESS
Definition: types.h:399
aiOrigin_CUR
@ aiOrigin_CUR
Definition: types.h:431
aiReturn_FAILURE
@ aiReturn_FAILURE
Definition: types.h:402