Skip to content
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(OpenGL_GL_PREFERENCE GLVND)

if(BUILD_WITH_MARCH_NATIVE)
Expand All @@ -26,7 +26,7 @@ endif()

find_package(OpenGL REQUIRED)

find_package(glm)
find_package(glm 1.0.1 CONFIG REQUIRED)
find_package(glfw3)
find_package(Eigen3)
find_package(PNG)
Expand Down Expand Up @@ -96,7 +96,7 @@ else()
endif()

if(${assimp_FOUND})
list(APPEND EXTRA_LIBRARIES assimp)
list(APPEND EXTRA_LIBRARIES ${ASSIMP_LIBRARIES})
list(APPEND EXTRA_SOURCE src/glk/io/mesh_io.cpp)
endif()

Expand Down Expand Up @@ -298,6 +298,7 @@ endif()

install(DIRECTORY include/ DESTINATION ${INCLUDE_INSTALL_DIR})
install(DIRECTORY thirdparty/gl3w/GL/ DESTINATION ${INCLUDE_INSTALL_DIR}/GL)
install(DIRECTORY thirdparty/gl3w/KHR/ DESTINATION ${INCLUDE_INSTALL_DIR}/KHR)
install(FILES thirdparty/imgui/imgui.h thirdparty/imgui/imconfig.h thirdparty/imgui/imgui_internal.h thirdparty/imgui/imstb_textedit.h DESTINATION ${INCLUDE_INSTALL_DIR})
install(FILES thirdparty/implot/implot.h thirdparty/implot/implot_internal.h DESTINATION ${INCLUDE_INSTALL_DIR})
install(FILES thirdparty/portable-file-dialogs/portable-file-dialogs.h DESTINATION ${INCLUDE_INSTALL_DIR})
Expand Down
3 changes: 3 additions & 0 deletions cmake/iridescence-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ find_dependency(OpenGL REQUIRED)
find_dependency(Eigen3 REQUIRED)
find_dependency(PNG)
find_dependency(JPEG)
find_dependency(glm)
find_dependency(assimp)
find_dependency(glfw3)

include("${CMAKE_CURRENT_LIST_DIR}/iridescence-targets.cmake")
add_library(Iridescence::Iridescence ALIAS Iridescence::iridescence)
1 change: 1 addition & 0 deletions src/glk/pointcloud_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <glk/pointcloud_buffer.hpp>

#include <random>
#include <cassert>
#include <numeric>
#include <iostream>
#include <cassert>
Expand Down
7 changes: 4 additions & 3 deletions src/guik/gl_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,18 @@ float GLCanvas::pick_depth(const Eigen::Vector2i& p, int window) const {
}

std::sort(ps.begin(), ps.end(), [=](const Eigen::Vector2i& lhs, const Eigen::Vector2i& rhs) { return lhs.norm() < rhs.norm(); });
float min_depth = 1;
for (int i = 0; i < ps.size(); i++) {
Eigen::Vector2i p_ = p + ps[i];
int index = ((size[1] - p[1]) * size[0] + p_[0]);
float depth = pixels[index];

if (depth < 1.0f) {
return depth;
if (depth < 1.0f && depth < min_depth) {
min_depth = depth;
}
}

return 1.0f;
return min_depth;
}

/**
Expand Down
119 changes: 117 additions & 2 deletions src/guik/imgui_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,125 @@ Application ::~Application() {
glfwTerminate();
}

// Retrieve monitor that contains most of a window.
static bool glfw_get_window_monitor(GLFWmonitor** monitor, GLFWwindow* window) {
bool success = false;

int window_rectangle[4] = {0};
glfwGetWindowPos(window, &window_rectangle[0], &window_rectangle[1]);
glfwGetWindowSize(window, &window_rectangle[2], &window_rectangle[3]);

int monitors_size = 0;
GLFWmonitor** monitors = glfwGetMonitors(&monitors_size);

GLFWmonitor* closest_monitor = NULL;
int max_overlap_area = 0;

for (int i = 0; i < monitors_size; ++i)
{
int monitor_rectangle[4] = {0};
glfwGetMonitorWorkarea(monitors[i], &monitor_rectangle[0], &monitor_rectangle[1], &monitor_rectangle[2], &monitor_rectangle[3]);

const GLFWvidmode* monitor_video_mode = glfwGetVideoMode(monitors[i]);

if (
!(
((window_rectangle[0] + window_rectangle[2]) < monitor_rectangle[0]) ||
(window_rectangle[0] > (monitor_rectangle[0] + monitor_rectangle[2])) ||
((window_rectangle[1] + window_rectangle[3]) < monitor_rectangle[1]) ||
(window_rectangle[1] > (monitor_rectangle[1] + monitor_rectangle[3]))
)
) {
int intersection_rectangle[4] = {0};

// x, width
if (window_rectangle[0] < monitor_rectangle[0])
{
intersection_rectangle[0] = monitor_rectangle[0];

if ((window_rectangle[0] + window_rectangle[2]) < (monitor_rectangle[0] + monitor_rectangle[2]))
{
intersection_rectangle[2] = (window_rectangle[0] + window_rectangle[2]) - intersection_rectangle[0];
}
else
{
intersection_rectangle[2] = monitor_rectangle[2];
}
}
else
{
intersection_rectangle[0] = window_rectangle[0];

if ((monitor_rectangle[0] + monitor_rectangle[2]) < (window_rectangle[0] + window_rectangle[2]))
{
intersection_rectangle[2] = (monitor_rectangle[0] + monitor_rectangle[2]) - intersection_rectangle[0];
}
else
{
intersection_rectangle[2] = window_rectangle[2];
}
}

// y, height
if (window_rectangle[1] < monitor_rectangle[1])
{
intersection_rectangle[1] = monitor_rectangle[1];

if ((window_rectangle[1] + window_rectangle[3]) < (monitor_rectangle[1] + monitor_rectangle[3]))
{
intersection_rectangle[3] = (window_rectangle[1] + window_rectangle[3]) - intersection_rectangle[1];
}
else
{
intersection_rectangle[3] = monitor_rectangle[3];
}
}
else
{
intersection_rectangle[1] = window_rectangle[1];

if ((monitor_rectangle[1] + monitor_rectangle[3]) < (window_rectangle[1] + window_rectangle[3]))
{
intersection_rectangle[3] = (monitor_rectangle[1] + monitor_rectangle[3]) - intersection_rectangle[1];
}
else
{
intersection_rectangle[3] = window_rectangle[3];
}
}

int overlap_area = intersection_rectangle[2] * intersection_rectangle[3];
if (overlap_area > max_overlap_area)
{
closest_monitor = monitors[i];
max_overlap_area = overlap_area;
}
}
}

if (closest_monitor)
{
*monitor = closest_monitor;
success = true;
}

// true: monitor contains the monitor the window is most on
// false: monitor is unmodified
return success;
}

// dirty implementation
std::unordered_map<GLFWwindow*, Application*> appmap;
void fb_size_callback(GLFWwindow* window, int width, int height) {
appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width, height));
float xscale = 1, yscale = 1;

// retrieve display scaling factor (needed on macos, otherwise resizing breaks mouse
// interaction)
GLFWmonitor* screen;
if (glfw_get_window_monitor(&screen, window)) {
glfwGetMonitorContentScale(screen, &xscale, &yscale);
}
appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width/xscale, height/yscale));
}

bool Application::init(const Eigen::Vector2i& size, const char* glsl_version, bool background, const std::string& title) {
Expand All @@ -48,7 +163,7 @@ bool Application::init(const Eigen::Vector2i& size, const char* glsl_version, bo
}

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

if (background) {
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
Expand Down
Loading