diff --git a/CMakeLists.txt b/CMakeLists.txt index db03b67..87531dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,23 +2,29 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/" "${CMAKE_SOURCE_DIR}/resources") +include(VersionFromGit) + string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M") message(STATUS "Saving build timestamp: ${BUILD_TIME}") +version_from_git(LOG ON TIMESTAMP "%Y-%m-%d-%H:%M:%S") + project( SamplinSafari DESCRIPTION "A research tool to visualize and interactively inspect high-dimensional (quasi) Monte Carlo samplers." - VERSION 2.0.0 + VERSION ${SEMVER} LANGUAGES C CXX ) if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(APP_BITS_VERSION "64 bit") +set(VERSION_LONG "${SEMVER} (64 bit)") elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(APP_BITS_VERSION "32 bit") +set(VERSION_LONG "${SEMVER} (32 bit)") endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/src/common.cpp @ONLY) + include(sanitizers) # Set ourselves as the startup project in visual studio. Not available until cmake 3.6, but doesn't break older @@ -194,22 +200,22 @@ add_library(samplerlib OBJECT STATIC include/sampler/Random.h include/sampler/RandomPermutation.h include/sampler/Sobol.h - src/Misc.cpp - src/Halton.cpp - src/Jittered.cpp - src/LP.cpp - src/MultiJittered.cpp - src/NRooks.cpp - src/OA.cpp - src/OAAddelmanKempthorne.cpp - src/OABose.cpp - src/OABoseBush.cpp - src/OABush.cpp - src/OACMJND.cpp - src/SOA.cpp - src/Random.cpp - src/Sobol.cpp - src/SobolMatrices.cpp) + src/sampler/Misc.cpp + src/sampler/Halton.cpp + src/sampler/Jittered.cpp + src/sampler/LP.cpp + src/sampler/MultiJittered.cpp + src/sampler/NRooks.cpp + src/sampler/OA.cpp + src/sampler/OAAddelmanKempthorne.cpp + src/sampler/OABose.cpp + src/sampler/OABoseBush.cpp + src/sampler/OABush.cpp + src/sampler/OACMJND.cpp + src/sampler/SOA.cpp + src/sampler/Random.cpp + src/sampler/Sobol.cpp + src/sampler/SobolMatrices.cpp) # Link dependencies target_link_libraries( @@ -229,14 +235,17 @@ set(HELLO_IMGUI_ICON_DISPLAY_NAME ${output_name}) set(HELLO_IMGUI_BUNDLE_NAME ${output_name}) set(HELLO_IMGUI_BUNDLE_COPYRIGHT "© Wojciech Jarosz, ${YEAR}") set(HELLO_IMGUI_BUNDLE_EXECUTABLE ${output_name}) -set(HELLO_IMGUI_BUNDLE_VERSION ${APP_BITS_VERSION}) -set(HELLO_IMGUI_BUNDLE_SHORT_VERSION ${PROJECT_VERSION}) +set(HELLO_IMGUI_BUNDLE_VERSION ${SEMVER}) +set(HELLO_IMGUI_BUNDLE_SHORT_VERSION ${SEMVER}) set(HELLO_IMGUI_BUNDLE_ICON_FILE icon.icns) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/shell.emscripten.html.in ${CMAKE_CURRENT_SOURCE_DIR}/shell.emscripten.html @ONLY) + hello_imgui_add_app(SamplinSafari - gui/app.cpp - gui/shader.cpp - gui/export_to_file.cpp + src/app.cpp + ${CMAKE_CURRENT_BINARY_DIR}/src/common.cpp + src/shader.cpp + src/export_to_file.cpp ) set_target_properties(SamplinSafari PROPERTIES diff --git a/cmake/VersionFromGit.cmake b/cmake/VersionFromGit.cmake index 45e6686..b09c318 100644 --- a/cmake/VersionFromGit.cmake +++ b/cmake/VersionFromGit.cmake @@ -62,9 +62,10 @@ function( version_from_git ) ERROR_STRIP_TRAILING_WHITESPACE ) if( NOT git_result EQUAL 0 ) - message( FATAL_ERROR + message( WARNING "[VersionFromGit] Failed to execute Git: ${git_error}" ) + set( git_describe "" ) endif() # Get Git tag @@ -78,9 +79,10 @@ function( version_from_git ) ERROR_STRIP_TRAILING_WHITESPACE ) if( NOT git_result EQUAL 0 ) - message( FATAL_ERROR + message( WARNING "[VersionFromGit] Failed to execute Git: ${git_error}" ) + set( git_tag "" ) endif() if( git_tag MATCHES "^v(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$" ) @@ -90,9 +92,14 @@ function( version_from_git ) set( identifiers "${CMAKE_MATCH_4}" ) set( metadata "${CMAKE_MATCH_5}" ) else() - message( FATAL_ERROR + message( WARNING "[VersionFromGit] Git tag isn't valid semantic version: [${git_tag}]" ) + set( version_major "0" ) + set( version_minor "0" ) + set( version_patch "0" ) + set( identifiers "" ) + set( metadata "" ) endif() if( "${git_tag}" STREQUAL "${git_describe}" ) diff --git a/gui/app.h b/include/app.h similarity index 97% rename from gui/app.h rename to include/app.h index dc981eb..18e90e9 100644 --- a/gui/app.h +++ b/include/app.h @@ -4,6 +4,7 @@ #pragma once +#include "common.h" #include "linalg.h" using namespace linalg::aliases; @@ -34,8 +35,8 @@ using namespace linalg::aliases; } #include "arcball.h" -// #include "gui_app.h" #include "hello_imgui/hello_imgui.h" +#include "misc/cpp/imgui_stdlib.h" #include "shader.h" #include #include @@ -108,6 +109,7 @@ class SampleViewer void update_GPU_grids(); void set_view(CameraType view); void draw_editor(); + void draw_about_dialog(); void process_hotkeys(); void populate_point_subset(); void generate_grid(vector &positions, int gridRes); @@ -155,6 +157,7 @@ class SampleViewer float m_time1 = 0.f, m_time2 = 0.f; float3 m_point_color = {0.9f, 0.55f, 0.1f}; + float3 m_bg_color = {0.0f, 0.0f, 0.0f}; HelloImGui::RunnerParams m_params; bool m_idling_backup = false; diff --git a/gui/arcball.h b/include/arcball.h similarity index 100% rename from gui/arcball.h rename to include/arcball.h diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..b89d507 --- /dev/null +++ b/include/common.h @@ -0,0 +1,28 @@ +// +// Copyright (C) Wojciech Jarosz . All rights reserved. +// Use of this source code is governed by a BSD-style license that can +// be found in the LICENSE.txt file. +// + +#pragma once + +#if defined(_MSC_VER) +// Make MS cmath define M_PI but not the min/max macros +#define _USE_MATH_DEFINES +#define NOMINMAX +#endif + +#include + +std::vector split(std::string text, const std::string &delim); +std::string to_lower(std::string str); +std::string to_upper(std::string str); + +int version_major(); +int version_minor(); +int version_patch(); +std::string version(); +std::string git_hash(); +std::string git_describe(); +std::string build_timestamp(); +std::string backend(); \ No newline at end of file diff --git a/gui/export_to_file.h b/include/export_to_file.h similarity index 100% rename from gui/export_to_file.h rename to include/export_to_file.h diff --git a/include/imgui_ext.h b/include/imgui_ext.h new file mode 100644 index 0000000..5f44ca4 --- /dev/null +++ b/include/imgui_ext.h @@ -0,0 +1,36 @@ +#include "imgui.h" + +namespace ImGui +{ + +inline bool ToggleButton(const char *label, bool *active) +{ + ImGui::PushStyleColor(ImGuiCol_Button, *active ? GetColorU32(ImGuiCol_ButtonActive) : GetColorU32(ImGuiCol_Button)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, GetColorU32(ImGuiCol_FrameBgHovered)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, GetColorU32(ImGuiCol_FrameBgActive)); + + bool ret; + if ((ret = ImGui::Button(label))) + *active = !*active; + ImGui::PopStyleColor(3); + return ret; +} + +inline void Text(const string &text) +{ + return TextUnformatted(text.c_str()); +} + +// return true when activated. +inline bool MenuItem(const string &label, const string &shortcut = "", bool selected = false, bool enabled = true) +{ + return MenuItem(label.c_str(), shortcut.c_str(), selected, enabled); +} + +// return true when activated + toggle (*p_selected) if p_selected != NULL +inline bool MenuItem(const string &label, const string &shortcut, bool *p_selected, bool enabled = true) +{ + return MenuItem(label.c_str(), shortcut.c_str(), p_selected, enabled); +} + +} // namespace ImGui \ No newline at end of file diff --git a/gui/shader.h b/include/shader.h similarity index 100% rename from gui/shader.h rename to include/shader.h diff --git a/gui/timer.h b/include/timer.h similarity index 100% rename from gui/timer.h rename to include/timer.h diff --git a/gui/traits.h b/include/traits.h similarity index 100% rename from gui/traits.h rename to include/traits.h diff --git a/shell.emscripten.html b/shell.emscripten.html.in similarity index 99% rename from shell.emscripten.html rename to shell.emscripten.html.in index 14a78e2..998b037 100644 --- a/shell.emscripten.html +++ b/shell.emscripten.html.in @@ -5,7 +5,7 @@ - Samplin Safari2 + @HELLO_IMGUI_ICON_DISPLAY_NAME@