14 #ifndef _DS3D_COMMON_FUNC_UTILS__H
15 #define _DS3D_COMMON_FUNC_UTILS__H
17 #include <ds3d/common/abi_frame.h>
18 #include <ds3d/common/common.h>
19 #include <ds3d/common/idatatype.h>
25 using LockMutex = std::unique_lock<std::mutex>;
54 static const std::unordered_map<ErrCode, const char*> kCodeTable = {
55 #define __DS3D_ERR_STR_DEF(code) {ErrCode::code, #code}
67 #undef __DS3D_ERR_STR_DEF
69 auto iter = kCodeTable.find(code);
70 if (iter == kCodeTable.cend()) {
82 throw Exception(code, msg);
85 template <
class F,
typename... Args>
90 DS3D_TRY { code = f(std::forward<Args>(args)...); }
108 cppString(const
char* str,
size_t len = 0)
111 return (len ? std::string(str, len) : std::string(str));
113 return std::string(
"");
116 template <
typename T>
125 return sizeof(T) * 4;
128 return sizeof(T) * 3;
130 return sizeof(T) * 3;
132 return sizeof(T) * 4;
134 return sizeof(T) * 3;
136 LOG_ERROR(
"bytesPerPixel with unsupported frametype: %d",
static_cast<int>(f));
145 #define __DS3D_DATATYPE_BYTES(t) \
147 return sizeof(NativeData<DataType::t>::type)
158 #undef __DS3D_DATATYPE_BYTES
168 if (!shape.numDims) {
171 if (std::any_of(shape.d, shape.d + shape.numDims, [](
int d) { return d < 0; })) {
175 return (
size_t)std::accumulate(
176 shape.d, shape.d + shape.numDims, 1, [](
int s,
int i) { return s * i; });
182 if (a.numDims != b.numDims) {
185 for (uint32_t i = 0; i < a.numDims; ++i) {
186 if (a.d[i] != b.d[i]) {
200 readFile(
const std::string& path, std::string& context)
202 std::ifstream fileIn(path, std::ios::in | std::ios::binary);
205 fileIn.seekg(0, std::ios::end);
206 size_t fileSize = fileIn.tellg();
207 context.resize(fileSize, 0);
208 fileIn.seekg(0, std::ios::beg);
209 fileIn.read(&context[0], fileSize);
216 static bool debug = std::getenv(
"DS3D_ENABLE_DEBUG") ? true :
false;
220 template <
typename Data>
224 for (
int i = 0; i < 3; ++i) {
225 to.data[i] = from[i];
232 if (fabs(a - b) <= std::numeric_limits<float>::epsilon())
237 inline TransformMatrix
240 TransformMatrix mat = {{
241 {{param.fx, 0.0f, 0.0f, 0.0f}},
242 {{0.0f, param.fy, 0.0f, 0.0f}},
243 {{param.centerX, param.centerY, 1.0f, 0.0f}},
244 {{0.0f, 0.0f, 0.0f, 1.0f}},
255 #endif // _DS3D_COMMON_FUNC_UTILS__H