18 #ifndef _DS3D_COMMON_FUNC_UTILS__H
19 #define _DS3D_COMMON_FUNC_UTILS__H
21 #include <ds3d/common/abi_frame.h>
22 #include <ds3d/common/common.h>
23 #include <ds3d/common/idatatype.h>
29 using LockMutex = std::unique_lock<std::mutex>;
58 static const std::unordered_map<ErrCode, const char*> kCodeTable = {
59 #define __DS3D_ERR_STR_DEF(code) {ErrCode::code, #code}
71 #undef __DS3D_ERR_STR_DEF
73 auto iter = kCodeTable.find(code);
74 if (iter == kCodeTable.cend()) {
86 throw Exception(code, msg);
89 template <
class F,
typename... Args>
94 DS3D_TRY { code = f(std::forward<Args>(args)...); }
112 cppString(const
char* str,
size_t len = 0)
115 return (len ? std::string(str, len) : std::string(str));
117 return std::string(
"");
120 template <
typename T>
129 return sizeof(T) * 4;
132 return sizeof(T) * 3;
134 return sizeof(T) * 3;
136 return sizeof(T) * 4;
138 return sizeof(T) * 3;
140 LOG_ERROR(
"bytesPerPixel with unsupported frametype: %d",
static_cast<int>(f));
149 #define __DS3D_DATATYPE_BYTES(t) \
151 return sizeof(NativeData<DataType::t>::type)
162 #undef __DS3D_DATATYPE_BYTES
172 if (!shape.numDims) {
175 if (std::any_of(shape.d, shape.d + shape.numDims, [](
int d) { return d < 0; })) {
179 return (
size_t)std::accumulate(
180 shape.d, shape.d + shape.numDims, 1, [](
int s,
int i) { return s * i; });
186 if (a.numDims != b.numDims) {
189 for (uint32_t i = 0; i < a.numDims; ++i) {
190 if (a.d[i] != b.d[i]) {
204 readFile(
const std::string& path, std::string& context)
206 std::ifstream fileIn(path, std::ios::in | std::ios::binary);
209 fileIn.seekg(0, std::ios::end);
210 size_t fileSize = fileIn.tellg();
211 context.resize(fileSize, 0);
212 fileIn.seekg(0, std::ios::beg);
213 fileIn.read(&context[0], fileSize);
220 static bool debug = std::getenv(
"DS3D_ENABLE_DEBUG") ? true :
false;
224 template <
typename Data>
228 for (
int i = 0; i < 3; ++i) {
229 to.data[i] = from[i];
236 if (fabs(a - b) <= std::numeric_limits<float>::epsilon())
241 inline TransformMatrix
244 TransformMatrix mat = {{
245 {{param.fx, 0.0f, 0.0f, 0.0f}},
246 {{0.0f, param.fy, 0.0f, 0.0f}},
247 {{param.centerX, param.centerY, 1.0f, 0.0f}},
248 {{0.0f, 0.0f, 0.0f, 1.0f}},
259 #endif // _DS3D_COMMON_FUNC_UTILS__H