ai_array.h
Go to the documentation of this file.
1// Copyright 2021 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
39class AtArray;
40
41AI_API AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, ...);
42AI_API AtArray* AiArrayAllocate(uint32_t nelements, uint8_t nkeys, uint8_t type);
43AI_API void AiArrayDestroy(AtArray* array);
44AI_API AtArray* AiArrayConvert(uint32_t nelements, uint8_t nkeys, uint8_t type, const void* data);
45AI_API void AiArrayResize(AtArray* array, uint32_t nelements, uint8_t nkeys);
46AI_API AtArray* AiArrayCopy(const AtArray* array);
47AI_API bool AiArraySetKey(AtArray* array, uint8_t key, const void* data);
48AI_API void* AiArrayMap(AtArray* array);
49AI_API void* AiArrayMapKey(AtArray* array, uint8_t key);
50AI_API void AiArrayUnmap(AtArray* array);
51AI_API AI_PURE uint32_t AiArrayGetNumElements(const AtArray* array);
52AI_API AI_PURE uint8_t AiArrayGetNumKeys(const AtArray* array);
53AI_API AI_PURE uint8_t AiArrayGetType(const AtArray* array);
54AI_API AI_PURE size_t AiArrayGetDataSize(const AtArray* array);
55AI_API AI_PURE size_t AiArrayGetKeySize(const AtArray* array);
56AI_API AI_PURE AtVector AiArrayInterpolateVec(const AtArray* array, float time, uint32_t idx);
57AI_API AI_PURE AtRGB AiArrayInterpolateRGB(const AtArray* array, float time, uint32_t idx);
58AI_API AI_PURE AtRGBA AiArrayInterpolateRGBA(const AtArray* array, float time, uint32_t idx);
59AI_API AI_PURE float AiArrayInterpolateFlt(const AtArray* array, float time, uint32_t idx);
60AI_API AI_PURE AtMatrix AiArrayInterpolateMtx(const AtArray* array, float time, uint32_t idx);
61
70AI_API AI_PURE bool AiArrayGetBool (const AtArray* a, uint32_t i);
71AI_API AI_PURE uint8_t AiArrayGetByte (const AtArray* a, uint32_t i);
72AI_API AI_PURE int AiArrayGetInt (const AtArray* a, uint32_t i);
73AI_API AI_PURE uint32_t AiArrayGetUInt (const AtArray* a, uint32_t i);
74AI_API AI_PURE float AiArrayGetFlt (const AtArray* a, uint32_t i);
75AI_API AI_PURE AtRGB AiArrayGetRGB (const AtArray* a, uint32_t i);
76AI_API AI_PURE AtRGBA AiArrayGetRGBA (const AtArray* a, uint32_t i);
77AI_API AI_PURE AtVector2 AiArrayGetVec2 (const AtArray* a, uint32_t i);
78AI_API AI_PURE AtVector AiArrayGetVec (const AtArray* a, uint32_t i);
79AI_API AI_PURE AtMatrix AiArrayGetMtx (const AtArray* a, uint32_t i);
80AI_API AI_PURE AtString AiArrayGetStr (const AtArray* a, uint32_t i);
81AI_API AI_PURE void* AiArrayGetPtr (const AtArray* a, uint32_t i);
82AI_API AI_PURE AtArray* AiArrayGetArray(const AtArray* a, uint32_t i);
83/*\}*/
84
94AI_API bool AiArraySetBool (AtArray* a, uint32_t i, bool val);
95AI_API bool AiArraySetByte (AtArray* a, uint32_t i, uint8_t val);
96AI_API bool AiArraySetInt (AtArray* a, uint32_t i, int val);
97AI_API bool AiArraySetUInt (AtArray* a, uint32_t i, uint32_t val);
98AI_API bool AiArraySetFlt (AtArray* a, uint32_t i, float val);
99AI_API bool AiArraySetRGB (AtArray* a, uint32_t i, AtRGB val);
100AI_API bool AiArraySetRGBA (AtArray* a, uint32_t i, AtRGBA val);
101AI_API bool AiArraySetVec2 (AtArray* a, uint32_t i, AtVector2 val);
102AI_API bool AiArraySetVec (AtArray* a, uint32_t i, AtVector val);
103AI_API bool AiArraySetMtx (AtArray* a, uint32_t i, AtMatrix val);
104AI_API bool AiArraySetStr (AtArray* a, uint32_t i, AtString val);
105AI_API bool AiArraySetPtr (AtArray* a, uint32_t i, void* val);
106AI_API bool AiArraySetArray(AtArray* a, uint32_t i, AtArray* val);
107/*\}*/
108
109/*\}*/
110
111#ifdef AI_CPU_COMPILER
112// this is slower than the AtString version
113inline bool AiArraySetStr(AtArray* a, uint32_t i, const char* val)
114{
115 return AiArraySetStr(a, i, AtString(val));
116}
117#endif
118
119// Helper functions for compilers that warn about trivial objects being passed
120// as variadic args:
121
122// do not use these directly.
123struct POD_tempf2{float f[2];};
124struct POD_tempf3{float f[3];};
125struct POD_tempf4{float f[4];};
126
127inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1) {
128 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1));
129}
130inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2) {
131 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2));
132}
133inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3) {
134 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3));
135}
136inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3, AtVector v4) {
137 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));
138}
139inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector v1, AtVector v2, AtVector v3, AtVector v4, AtVector v5) {
140 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));
141}
142
143inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1) {
144 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1));
145}
146inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2) {
147 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2));
148}
149inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3) {
150 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf2>(v1), reinterpret_type<POD_tempf2>(v2), reinterpret_type<POD_tempf2>(v3));
151}
152inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3, AtVector2 v4) {
153 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));
154}
155inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtVector2 v1, AtVector2 v2, AtVector2 v3, AtVector2 v4, AtVector2 v5) {
156 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));
157}
158
159inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1) {
160 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1));
161}
162inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2) {
163 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2));
164}
165inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3) {
166 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf3>(v1), reinterpret_type<POD_tempf3>(v2), reinterpret_type<POD_tempf3>(v3));
167}
168inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3, AtRGB 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}
171inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGB v1, AtRGB v2, AtRGB v3, AtRGB v4, AtRGB 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
175inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1) {
176 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1));
177}
178inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2) {
179 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2));
180}
181inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3) {
182 return AiArray(nelements, nkeys, type, reinterpret_type<POD_tempf4>(v1), reinterpret_type<POD_tempf4>(v2), reinterpret_type<POD_tempf4>(v3));
183}
184inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3, AtRGBA v4) {
185 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));
186}
187inline AtArray* AiArray(uint32_t nelements, uint8_t nkeys, int type, AtRGBA v1, AtRGBA v2, AtRGBA v3, AtRGBA v4, AtRGBA v5) {
188 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));
189}
DLL export prefix for API functions (necessary for multi-platform development)
Color types and utilities.
Math operations.
Matrix math type and methods.
AtString class for fast comparisons.
Vector math types, operators and utilities.
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
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:369
AI_API AtArray * AiArrayCopy(const AtArray *array)
Create a copy of an array.
Definition: ai_array.cpp:146
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:115
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:304
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:71
AI_API AI_PURE uint8_t AiArrayGetNumKeys(const AtArray *array)
Get the number of keys.
Definition: ai_array.cpp:271
AI_API void AiArrayDestroy(AtArray *array)
Deallocate an array object.
Definition: ai_array.cpp:38
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:260
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:343
AI_API void * AiArrayMap(AtArray *array)
Obtains a pointer to the internal array data for construction.
Definition: ai_array.cpp:215
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:28
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:330
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:356
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:317
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:182
AI_API AI_PURE uint8_t AiArrayGetType(const AtArray *array)
Get the type of array elements.
Definition: ai_array.cpp:282
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:233
AI_API void AiArrayUnmap(AtArray *array)
Notifies the array that construction is finished.
Definition: ai_array.cpp:248
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:293
AI_API void AiArrayResize(AtArray *array, uint32_t nelements, uint8_t nkeys)
Resize an existing array contents in place.
Definition: ai_array.cpp:130
Definition: ai_matrix.h:30
RGB color + alpha.
Definition: ai_color.h:267
RGB color.
Definition: ai_color.h:32
2D point
Definition: ai_vector.h:255
3D point (single precision)
Definition: ai_vector.h:30
Definition: ai_array.h:123
Definition: ai_array.h:124
Definition: ai_array.h:125

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