ai_array.h
Go to the documentation of this file.
1 // Copyright 2020 Autodesk, Inc. All rights reserved.
2 //
3 // Use of this software is subject to the terms of the Autodesk license
4 // agreement provided at the time of installation or download, or which
5 // otherwise accompanies this software in either electronic or hard copy form.
6 
12 #pragma once
13 #include "ai_color.h"
14 #include "ai_math.h"
15 #include "ai_matrix.h"
16 #include "ai_string.h"
17 #include "ai_vector.h"
18 #include "ai_api.h"
19 #include <stdint.h> // uint32_t etc
20 
39 class AtArray;
40 
41 AI_API AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, ...);
42 AI_API AtArray* AiArrayAllocate(uint32_t nelements, uint8_t nkeys, uint8_t type);
43 AI_API void AiArrayDestroy(AtArray* array);
44 AI_API AtArray* AiArrayConvert(uint32_t nelements, uint8_t nkeys, uint8_t type, const void* data);
45 AI_API void AiArrayResize(AtArray* array, uint32_t nelements, uint8_t nkeys);
46 AI_API AtArray* AiArrayCopy(const AtArray* array);
47 AI_API bool AiArraySetKey(AtArray* array, uint8_t key, const void* data);
48 AI_API void* AiArrayMap(AtArray* array);
49 AI_API void* AiArrayMapKey(AtArray* array, uint8_t key);
50 AI_API void AiArrayUnmap(AtArray* array);
51 AI_API AI_PURE uint32_t AiArrayGetNumElements(const AtArray* array);
52 AI_API AI_PURE uint8_t AiArrayGetNumKeys(const AtArray* array);
53 AI_API AI_PURE uint8_t AiArrayGetType(const AtArray* array);
54 AI_API AI_PURE size_t AiArrayGetDataSize(const AtArray* array);
55 AI_API AI_PURE size_t AiArrayGetKeySize(const AtArray* array);
56 AI_API AI_PURE AtVector AiArrayInterpolateVec(const AtArray* array, float time, uint32_t idx);
57 AI_API AI_PURE AtRGB AiArrayInterpolateRGB(const AtArray* array, float time, uint32_t idx);
58 AI_API AI_PURE AtRGBA AiArrayInterpolateRGBA(const AtArray* array, float time, uint32_t idx);
59 AI_API AI_PURE float AiArrayInterpolateFlt(const AtArray* array, float time, uint32_t idx);
60 AI_API AI_PURE AtMatrix AiArrayInterpolateMtx(const AtArray* array, float time, uint32_t idx);
61 
75 #define AiArrayGetBool(a,i) AiArrayGetBoolFunc (a,i,__AI_FILE__,__AI_LINE__)
76 #define AiArrayGetByte(a,i) AiArrayGetByteFunc (a,i,__AI_FILE__,__AI_LINE__)
77 #define AiArrayGetInt(a,i) AiArrayGetIntFunc (a,i,__AI_FILE__,__AI_LINE__)
78 #define AiArrayGetUInt(a,i) AiArrayGetUIntFunc (a,i,__AI_FILE__,__AI_LINE__)
79 #define AiArrayGetFlt(a,i) AiArrayGetFltFunc (a,i,__AI_FILE__,__AI_LINE__)
80 #define AiArrayGetRGB(a,i) AiArrayGetRGBFunc (a,i,__AI_FILE__,__AI_LINE__)
81 #define AiArrayGetRGBA(a,i) AiArrayGetRGBAFunc (a,i,__AI_FILE__,__AI_LINE__)
82 #define AiArrayGetVec2(a,i) AiArrayGetVec2Func (a,i,__AI_FILE__,__AI_LINE__)
83 #define AiArrayGetVec(a,i) AiArrayGetVecFunc (a,i,__AI_FILE__,__AI_LINE__)
84 #define AiArrayGetMtx(a,i) AiArrayGetMtxFunc (a,i,__AI_FILE__,__AI_LINE__)
85 #define AiArrayGetStr(a,i) AiArrayGetStrFunc (a,i,__AI_FILE__,__AI_LINE__)
86 #define AiArrayGetPtr(a,i) AiArrayGetPtrFunc (a,i,__AI_FILE__,__AI_LINE__)
87 #define AiArrayGetArray(a,i) AiArrayGetArrayFunc(a,i,__AI_FILE__,__AI_LINE__)
88 /*\}*/
89 
99 #define AiArraySetBool(a,i,val) AiArraySetBoolFunc (a,i,val,__AI_FILE__,__AI_LINE__)
100 #define AiArraySetByte(a,i,val) AiArraySetByteFunc (a,i,val,__AI_FILE__,__AI_LINE__)
101 #define AiArraySetInt(a, i,val) AiArraySetIntFunc (a,i,val,__AI_FILE__,__AI_LINE__)
102 #define AiArraySetUInt(a,i,val) AiArraySetUIntFunc (a,i,val,__AI_FILE__,__AI_LINE__)
103 #define AiArraySetFlt(a,i,val) AiArraySetFltFunc (a,i,val,__AI_FILE__,__AI_LINE__)
104 #define AiArraySetRGB(a,i,val) AiArraySetRGBFunc (a,i,val,__AI_FILE__,__AI_LINE__)
105 #define AiArraySetRGBA(a,i,val) AiArraySetRGBAFunc (a,i,val,__AI_FILE__,__AI_LINE__)
106 #define AiArraySetVec2(a,i,val) AiArraySetVec2Func (a,i,val,__AI_FILE__,__AI_LINE__)
107 #define AiArraySetVec(a,i,val) AiArraySetVecFunc (a,i,val,__AI_FILE__,__AI_LINE__)
108 #define AiArraySetMtx(a,i,val) AiArraySetMtxFunc (a,i,val,__AI_FILE__,__AI_LINE__)
109 #define AiArraySetStr(a,i,val) AiArraySetStrFunc (a,i,val,__AI_FILE__,__AI_LINE__)
110 #define AiArraySetPtr(a,i,val) AiArraySetPtrFunc (a,i,val,__AI_FILE__,__AI_LINE__)
111 #define AiArraySetArray(a,i,val) AiArraySetArrayFunc(a,i,val,__AI_FILE__,__AI_LINE__)
112 /*\}*/
113 
114 /*\}*/
115 
116 AI_API AI_PURE bool AiArrayGetBoolFunc (const AtArray* a, uint32_t i, const char*, int line);
117 AI_API AI_PURE uint8_t AiArrayGetByteFunc (const AtArray* a, uint32_t i, const char*, int line);
118 AI_API AI_PURE int AiArrayGetIntFunc (const AtArray* a, uint32_t i, const char*, int line);
119 AI_API AI_PURE uint32_t AiArrayGetUIntFunc (const AtArray* a, uint32_t i, const char*, int line);
120 AI_API AI_PURE float AiArrayGetFltFunc (const AtArray* a, uint32_t i, const char*, int line);
121 AI_API AI_PURE AtRGB AiArrayGetRGBFunc (const AtArray* a, uint32_t i, const char*, int line);
122 AI_API AI_PURE AtRGBA AiArrayGetRGBAFunc (const AtArray* a, uint32_t i, const char*, int line);
123 AI_API AI_PURE AtVector2 AiArrayGetVec2Func (const AtArray* a, uint32_t i, const char*, int line);
124 AI_API AI_PURE AtVector AiArrayGetVecFunc (const AtArray* a, uint32_t i, const char*, int line);
125 AI_API AI_PURE AtMatrix AiArrayGetMtxFunc (const AtArray* a, uint32_t i, const char*, int line);
126 AI_API AI_PURE AtString AiArrayGetStrFunc (const AtArray* a, uint32_t i, const char*, int line);
127 AI_API AI_PURE void* AiArrayGetPtrFunc (const AtArray* a, uint32_t i, const char*, int line);
128 AI_API AI_PURE AtArray* AiArrayGetArrayFunc(const AtArray* a, uint32_t i, const char*, int line);
129 
130 AI_API bool AiArraySetBoolFunc (AtArray* a, uint32_t i, bool val, const char*, int line);
131 AI_API bool AiArraySetByteFunc (AtArray* a, uint32_t i, uint8_t val, const char*, int line);
132 AI_API bool AiArraySetIntFunc (AtArray* a, uint32_t i, int val, const char*, int line);
133 AI_API bool AiArraySetUIntFunc (AtArray* a, uint32_t i, uint32_t val, const char*, int line);
134 AI_API bool AiArraySetFltFunc (AtArray* a, uint32_t i, float val, const char*, int line);
135 AI_API bool AiArraySetRGBFunc (AtArray* a, uint32_t i, AtRGB val, const char*, int line);
136 AI_API bool AiArraySetRGBAFunc (AtArray* a, uint32_t i, AtRGBA val, const char*, int line);
137 AI_API bool AiArraySetVec2Func (AtArray* a, uint32_t i, AtVector2 val, const char*, int line);
138 AI_API bool AiArraySetVecFunc (AtArray* a, uint32_t i, AtVector val, const char*, int line);
139 AI_API bool AiArraySetMtxFunc (AtArray* a, uint32_t i, AtMatrix val, const char*, int line);
140 AI_API bool AiArraySetStrFunc (AtArray* a, uint32_t i, AtString val, const char*, int line);
141 AI_API bool AiArraySetPtrFunc (AtArray* a, uint32_t i, void* val, const char*, int line);
142 AI_API bool AiArraySetArrayFunc(AtArray* a, uint32_t i, AtArray* val, const char*, int line);
143 
144 #ifdef AI_CPU_COMPILER
145 // this is slower than the AtString version
146 inline bool AiArraySetStrFunc (AtArray* a, uint32_t i, const char* val, const char* filename, int line) {
147  return AiArraySetStrFunc(a, i, AtString(val), filename, line);
148 }
149 #endif
150 
151 // Helper functions for compilers that warn about trivial objects being passed
152 // as variadic args:
153 
154 // do not use these directly.
155 struct POD_tempf2{float f[2];};
156 struct POD_tempf3{float f[3];};
157 struct POD_tempf4{float f[4];};
158 
159 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1) {
160  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1));
161 }
162 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2) {
163  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2));
164 }
165 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3) {
166  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3));
167 }
168 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3, AtVector v4) {
169  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3), reinterpret_type<POD_tempf3>(v4));
170 }
171 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3, AtVector v4, AtVector v5) {
172  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3), reinterpret_type<POD_tempf3>(v4), reinterpret_type<POD_tempf3>(v5));
173 }
174 
175 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1) {
176  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1));
177 }
178 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2) {
179  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2));
180 }
181 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3) {
182  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2), reinterpret_type<POD_tempf2>(v3));
183 }
184 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3, AtVector2 v4) {
185  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2), reinterpret_type<POD_tempf2>(v3), reinterpret_type<POD_tempf2>(v4));
186 }
187 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3, AtVector2 v4, AtVector2 v5) {
188  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2), reinterpret_type<POD_tempf2>(v3), reinterpret_type<POD_tempf2>(v4), reinterpret_type<POD_tempf2>(v5));
189 }
190 
191 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1) {
192  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1));
193 }
194 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2) {
195  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2));
196 }
197 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3) {
198  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3));
199 }
200 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3, AtRGB v4) {
201  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3), reinterpret_type<POD_tempf3>(v4));
202 }
203 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3, AtRGB v4, AtRGB v5) {
204  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3), reinterpret_type<POD_tempf3>(v4), reinterpret_type<POD_tempf3>(v5));
205 }
206 
207 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1) {
208  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1));
209 }
210 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2) {
211  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2));
212 }
213 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3) {
214  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2), reinterpret_type<POD_tempf4>(v3));
215 }
216 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3, AtRGBA v4) {
217  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2), reinterpret_type<POD_tempf4>(v3), reinterpret_type<POD_tempf4>(v4));
218 }
219 inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3, AtRGBA v4, AtRGBA v5) {
220  return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2), reinterpret_type<POD_tempf4>(v3), reinterpret_type<POD_tempf4>(v4), reinterpret_type<POD_tempf4>(v5));
221 }
AI_API bool AiArraySetKey(AtArray *array, uint8_t key, const void *data)
Initializes data for all the elements in a specific key of an array.
Definition: ai_array.cpp:178
RGB color.
Definition: ai_color.h:31
AI_API AtArray * AiArrayAllocate(uint32_t nelements, uint8_t nkeys, uint8_t type)
Create an empty (uninitialized) array of the specified type.
Definition: ai_array.cpp:27
Definition: ai_array.h:155
Vector math types, operators and utilities.
Math operations.
AI_API AI_PURE AtRGB AiArrayInterpolateRGB(const AtArray *array, float time, uint32_t idx)
Interpolate a color at a given time from an array.
Definition: ai_array.cpp:352
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
3D point (single precision)
Definition: ai_vector.h:29
AI_API AtArray * AiArrayCopy(const AtArray *array)
Create a copy of an array.
Definition: ai_array.cpp:143
AI_API AtArray * AiArrayConvert(uint32_t nelements, uint8_t nkeys, uint8_t type, const void *data)
Create an array and initialize it from an existing data buffer.
Definition: ai_array.cpp:114
Color types and utilities.
AI_API void AiArrayUnmap(AtArray *array)
Notifies the array that construction is finished.
Definition: ai_array.cpp:244
AI_API AI_PURE float AiArrayInterpolateFlt(const AtArray *array, float time, uint32_t idx)
Interpolate a float at a given time from an array.
Definition: ai_array.cpp:326
Definition: ai_matrix.h:30
DLL export prefix for API functions (necessary for multi-platform development)
2D point
Definition: ai_vector.h:254
AI_API AI_PURE uint8_t AiArrayGetNumKeys(const AtArray *array)
Get the number of keys.
Definition: ai_array.cpp:267
AI_API AtArray * AiArray(uint32_t nelements, uint8_t nkeys, int type,...)
Create an array and initialize it with supplied data.
Definition: ai_array.cpp:70
Definition: ai_array.h:157
AI_API void * AiArrayMapKey(AtArray *array, uint8_t key)
Obtains a pointer to a specific key in the internal array data for construction.
Definition: ai_array.cpp:229
AI_API AI_PURE AtRGBA AiArrayInterpolateRGBA(const AtArray *array, float time, uint32_t idx)
Interpolate an AtRGBA at a given time from an array.
Definition: ai_array.cpp:365
AI_API AI_PURE uint8_t AiArrayGetType(const AtArray *array)
Get the type of array elements.
Definition: ai_array.cpp:278
Definition: ai_array.h:156
AI_API void AiArrayDestroy(AtArray *array)
Deallocate an array object.
Definition: ai_array.cpp:37
AI_API AI_PURE size_t AiArrayGetDataSize(const AtArray *array)
Get the total size in bytes of the data buffer for this array.
Definition: ai_array.cpp:289
RGB color + alpha.
Definition: ai_color.h:266
AI_API AI_PURE AtVector AiArrayInterpolateVec(const AtArray *array, float time, uint32_t idx)
Interpolate a vector at a given time from an array.
Definition: ai_array.cpp:313
AI_API void AiArrayResize(AtArray *array, uint32_t nelements, uint8_t nkeys)
Resize an existing array contents in place.
Definition: ai_array.cpp:128
AI_API void * AiArrayMap(AtArray *array)
Obtains a pointer to the internal array data for construction.
Definition: ai_array.cpp:211
AI_API AI_PURE AtMatrix AiArrayInterpolateMtx(const AtArray *array, float time, uint32_t idx)
Interpolate a matrix at a given time from an array.
Definition: ai_array.cpp:339
AI_API AI_PURE size_t AiArrayGetKeySize(const AtArray *array)
Get the total size in bytes of the data for one key.
Definition: ai_array.cpp:300
AI_API AI_PURE uint32_t AiArrayGetNumElements(const AtArray *array)
Get the number of elements on each key of the array.
Definition: ai_array.cpp:256
Matrix math type and methods.
AtString class for fast comparisons.

© 2020 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com