14 #include <sys/types.h> 19 #define STB_IMAGE_WRITE_IMPLEMENTATION 20 #include <stb_image_write.h> 27 #include <KnownFolders.h> 31 #if (defined(_WIN32) || defined(_WIN64)) 35 #if defined __linux__ || defined __APPLE__ 37 #include <sys/types.h> 49 if (str.length() >
width)
52 ss << str.substr(0, width / 3) <<
"..." << str.substr(str.length() - width / 3);
53 return ss.str().c_str();
60 #if (defined(_WIN32) || defined(_WIN64)) 61 if (reinterpret_cast<int>(ShellExecuteA(
NULL,
"open", url,
NULL,
NULL, SW_SHOW)) < 32)
62 throw std::runtime_error(
"Failed opening URL");
63 #elif defined __linux__ || defined(__linux__) 66 if (
system(command.c_str()))
67 throw std::runtime_error(
"Failed opening URL");
71 if (
system(command.c_str()))
72 throw std::runtime_error(
"Failed opening URL");
74 #pragma message ( "\nLibrealsense couldn't establish OS/Build environment. \ 75 Some auxillary functionalities might be affected. Please report this message if encountered") 81 std::vector<std::string>
result;
83 auto i = input.begin();
85 i = find_if_not(
i,
e, [delim](
char c) {
return c == delim; });
88 result.emplace_back(
i,
j);
102 return{ (float)xpos, (
float)
ypos,
103 (float)width, (
float)height };
113 return{ (float)xpos, (
float)
ypos,
124 if (count == 0)
return 1;
128 float best_area = 0.f;
131 auto int_area = window_rect.intersection(
133 if (int_area >= best_area)
135 best_area = int_area;
145 if (widthMM * heightMM == 0)
return 1;
150 float how_many_pixels_in_mm =
152 float scale = sqrt(how_many_pixels_in_mm) / 5.f;
153 if (scale < 1.
f)
return 1;
154 return (
int)(floor(scale));
161 if (stat(dir, &info ) != 0)
163 else if (info.st_mode & S_IFDIR)
174 if (default_name && default_path) def +=
"/";
175 if (default_name) def += default_name;
176 const char* def_ptr =
nullptr;
177 if (default_name || default_path)
178 def_ptr = def.c_str();
179 int num_filters = filters ==
nullptr ? 0 : 1;
181 char const *
const * aFilterPatterns =
nullptr;
182 char const * aSingleFilterDescription =
nullptr;
184 std::vector<std::string> filters_split;
189 while (*curr !=
'\0')
191 auto end = curr + strlen(curr);
192 filters_split.push_back({ curr,
end });
197 std::vector<const char*>
filter;
199 if (filters_split.size() == 2)
201 filter.push_back(filters_split[1].c_str());
202 aFilterPatterns = filter.data();
203 aSingleFilterDescription = filters_split[0].c_str();
208 return tinyfd_saveFileDialog(
"Save File", def_ptr, num_filters, aFilterPatterns, aSingleFilterDescription);
212 return tinyfd_openFileDialog(
"Open File", def_ptr, num_filters, aFilterPatterns, aSingleFilterDescription, 0);
218 size_t pixel_width,
size_t pixels_height,
size_t bytes_per_pixel,
219 const void* raster_data,
size_t stride_bytes)
221 return stbi_write_png(filename, (
int)pixel_width, (
int)pixels_height, (
int)bytes_per_pixel, raster_data, (
int)stride_bytes);
227 for (
auto rit = path.rbegin(); rit != path.rend(); ++rit)
229 if (*rit ==
'\\' || *rit ==
'/')
233 std::reverse(file_name.begin(), file_name.end());
239 std::time_t
now = std::time(
NULL);
240 std::tm * ptm = std::localtime(&now);
243 std::strftime(buffer, 16,
"%Y%m%d_%H%M%S", ptm);
254 if (GetTempPath(MAX_PATH, buf) != 0)
257 wcstombs(str, buf, 1023);
274 case app_data: folder = FOLDERID_RoamingAppData;
277 throw std::invalid_argument(
280 PWSTR folder_path =
NULL;
281 HRESULT hr = SHGetKnownFolderPath(folder, KF_FLAG_DEFAULT_PATH,
NULL, &folder_path);
285 wcstombs(str, folder_path, 1023);
286 CoTaskMemFree(folder_path);
292 throw std::runtime_error(
"Failed to get requested special folder");
296 #if defined __linux__ || defined __APPLE__ 299 const char* tmp_dir = getenv(
"TMPDIR");
300 res = tmp_dir ? tmp_dir :
"/tmp/";
304 const char* home_dir = getenv(
"HOME");
307 struct passwd* pw = getpwuid(getuid());
308 home_dir = (pw && pw->pw_dir) ? pw->pw_dir :
"";
326 throw std::invalid_argument(
331 #endif // defined __linux__ || defined __APPLE__ 337 auto i = s.rbegin(),
j = suffix.rbegin();
338 for (;
i != s.rend() &&
j != suffix.rend() && *
i == *
j;
340 return j == suffix.rend();
345 auto i = s.begin(),
j = prefix.begin();
346 for (;
i != s.end() &&
j != prefix.end() && *
i == *
j;
348 return j == prefix.end();
386 ostringstream escaped;
390 for (string::const_iterator
i = value.begin(),
n = value.end();
i !=
n; ++
i) {
391 string::value_type
c = (*i);
394 if (isalnum(c) || c ==
'-' || c ==
'_' || c ==
'.' || c ==
'~') {
400 escaped << uppercase;
401 escaped <<
'%' << setw(2) << int((
unsigned char)c);
402 escaped << nouppercase;
405 return escaped.str();
char const * tinyfd_saveFileDialog(char const *const aTitle, char const *const aDefaultPathAndFile, int const aNumOfFilterPatterns, char const *const *const aFilterPatterns, char const *const aSingleFilterDescription)
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
The header of the GLFW 3 API.
GLenum GLenum GLenum GLenum GLenum scale
GLsizei const GLchar *const * path
GLFWAPI const GLFWvidmode * glfwGetVideoMode(GLFWmonitor *monitor)
Returns the current mode of the specified monitor.
struct GLFWmonitor GLFWmonitor
std::string get_folder_path(special_folder f)
std::string get_timestamped_file_name()
rect get_monitor_rect(GLFWmonitor *monitor)
GLsizei const GLchar *const * string
std::vector< std::string > split_string(std::string &input, char delim)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
bool ends_with(const std::string &s, const std::string &suffix)
std::string truncate_string(const std::string &str, size_t width)
bool directory_exists(const char *dir)
GLenum GLuint GLenum GLsizei const GLchar * buf
GLFWAPI GLFWmonitor ** glfwGetMonitors(int *count)
Returns the currently connected monitors.
void open_url(const char *url)
std::string url_encode(const std::string &value)
GLint GLsizei GLsizei height
const char * file_dialog_open(file_dialog_mode flags, const char *filters, const char *default_path, const char *default_name)
int save_to_png(const char *filename, size_t pixel_width, size_t pixels_height, size_t bytes_per_pixel, const void *raster_data, size_t stride_bytes)
int pick_scale_factor(GLFWwindow *window)
GLFWAPI void glfwGetMonitorPos(GLFWmonitor *monitor, int *xpos, int *ypos)
Returns the position of the monitor's viewport on the virtual screen.
std::string get_file_name(const std::string &path)
char const * tinyfd_openFileDialog(char const *const aTitle, char const *const aDefaultPathAndFile, int const aNumOfFilterPatterns, char const *const *const aFilterPatterns, char const *const aSingleFilterDescription, int const aAllowMultipleSelects)
GLFWAPI void glfwGetWindowPos(GLFWwindow *window, int *xpos, int *ypos)
Retrieves the position of the client area of the specified window.
GLenum GLenum GLenum input
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
rect get_window_rect(GLFWwindow *window)
GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor *monitor, int *widthMM, int *heightMM)
Returns the physical size of the monitor.
bool starts_with(const std::string &s, const std::string &prefix)
std::string get_os_name()
static const char * default_path
struct GLFWwindow GLFWwindow
std::string to_string(T value)