diff --git a/src/BundleCeres.cpp b/src/BundleCeres.cpp index 863edcd..b789fc8 100644 --- a/src/BundleCeres.cpp +++ b/src/BundleCeres.cpp @@ -7,8 +7,11 @@ #include #include #include +#if defined(_WIN32) || defined(_WIN64) +#include "time_unix.h" +#else #include - +#endif #include "matrix.h" #include "qsort.h" #include "util.h" @@ -19,6 +22,7 @@ #include #include "snavely_reprojection_error.h" +#include "ceres/rotation.h" #include diff --git a/src/time_unix.cpp b/src/time_unix.cpp new file mode 100644 index 0000000..ede75af --- /dev/null +++ b/src/time_unix.cpp @@ -0,0 +1,22 @@ +#include "time_unix.h" + +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} \ No newline at end of file diff --git a/src/time_unix.h b/src/time_unix.h new file mode 100644 index 0000000..d762e0f --- /dev/null +++ b/src/time_unix.h @@ -0,0 +1,17 @@ +#pragma once +//original +//https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows + +#define WIN32_LEAN_AND_MEAN +#include +#include // portable: uint64_t MSVC: __int64 + +#undef ERROR + +// MSVC defines this in winsock2.h!? +typedef struct timeval { + long tv_sec; + long tv_usec; +} timeval; + +int gettimeofday(struct timeval * tp, struct timezone * tzp); \ No newline at end of file