From ae4455e6515807287a26a1b22e94d4fccd57c555 Mon Sep 17 00:00:00 2001 From: CHrlS98 Date: Wed, 28 Jul 2021 13:45:23 -0400 Subject: [PATCH] Simple installation script and update readme --- .gitignore | 3 ++- CMakeLists.txt | 3 ++- Engine/CMakeLists.txt | 2 ++ Engine/src/main.cpp | 23 +++++++++++++++++------ README.md | 28 ++++++++++++++++++++++------ install.sh | 27 +++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 14 deletions(-) create mode 100755 install.sh diff --git a/.gitignore b/.gitignore index 505aaef2..e3075917 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ [bB]uild third/vcpkg *.jpg -*.ini \ No newline at end of file +*.ini +.cache-install \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2da7bebd..ad178f65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,10 @@ +set(CMAKE_GENERATOR "Unix Makefiles") set(CMAKE_TOOLCHAIN_FILE ./third/vcpkg-export-20210512-131839/scripts/buildsystems/vcpkg.cmake) #========== Global Configurations =============# #----------------------------------------------# cmake_minimum_required(VERSION 3.11) -project(stunningsuccotash) +project(rtfodfslicer) set(CMAKE_CXX_STANDARD 17) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt index e6b331ce..ef94bdea 100644 --- a/Engine/CMakeLists.txt +++ b/Engine/CMakeLists.txt @@ -10,6 +10,8 @@ target_link_libraries(rtfodfslicer PRIVATE IMGUI) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +add_compile_definitions(RTFODFSLICER_SHADERS_DIR="${CMAKE_CURRENT_BINARY_DIR}/shaders") + add_custom_command(TARGET rtfodfslicer POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/shaders $/shaders diff --git a/Engine/src/main.cpp b/Engine/src/main.cpp index 0fe027ef..73589366 100644 --- a/Engine/src/main.cpp +++ b/Engine/src/main.cpp @@ -19,6 +19,10 @@ #include #include +#ifndef RTFODFSLICER_SHADERS_DIR + #error "RTFODFSLICER_SHADERS_DIR PREPROCESSOR DEFINITION NOT FOUND." +#endif + namespace { const int DEFAULT_SPHERE_RESOLUTION = 25; @@ -31,6 +35,7 @@ struct CLArgs std::string absWorkingDir = ""; std::string imagePath = ""; int sphereRes = DEFAULT_SPHERE_RESOLUTION; + bool success = true; }; State::Mouse mouseState; @@ -122,7 +127,7 @@ int main(const CLArgs& args) const int height = 600; const float aspectRatio = static_cast(width) / static_cast(height); - GLFWwindow* window = glfwCreateWindow(width, height, "stunning-succotash", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(width, height, "RTfODF Slicer", NULL, NULL); glfwMakeContextCurrent(window); glfwSetWindowUserPointer(window, NULL); @@ -141,8 +146,8 @@ int main(const CLArgs& args) } // vertex+fragment shaders - const std::string absPathVS = args.absWorkingDir + "shaders/triangle.vert"; - const std::string absPathFS = args.absWorkingDir + "shaders/triangle.frag"; + const std::string absPathVS = std::string(RTFODFSLICER_SHADERS_DIR) + "/triangle.vert"; + const std::string absPathFS = std::string(RTFODFSLICER_SHADERS_DIR) + "/triangle.frag"; std::vector shaders; shaders.push_back(Scene::ShaderProgram(absPathVS, GL_VERTEX_SHADER)); @@ -150,7 +155,7 @@ int main(const CLArgs& args) Scene::ProgramPipeline programPipeline(shaders); // compute shader - std::string absPathCS = args.absWorkingDir + "shaders/compute.glsl"; + std::string absPathCS = std::string(RTFODFSLICER_SHADERS_DIR) + "/compute.glsl"; Scene::ShaderProgram computeShader(absPathCS, GL_COMPUTE_SHADER); // load our image @@ -224,11 +229,13 @@ int main(const CLArgs& args) Engine::CLArgs parseArguments(int argc, char** argv) { + Engine::CLArgs args; if(argc < 2) { - throw std::runtime_error("Missing required argument: imagePath."); + std::cout << "Missing mandatory argument: [imagePath]" << std::endl; + args.success = false; + return args; } - Engine::CLArgs args; args.absWorkingDir = extractPath(argv[0]); args.imagePath = argv[1]; if(argc > 2) @@ -241,5 +248,9 @@ Engine::CLArgs parseArguments(int argc, char** argv) int main(int argc, char** argv) { Engine::CLArgs args = parseArguments(argc, argv); + if(!args.success) + { + return -1; + } return Engine::main(args); } \ No newline at end of file diff --git a/README.md b/README.md index 5faf62cb..d6220604 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,20 @@ -# RTfODFSlicer +# RTfODF Slicer A real-time fiber ODF slicing application for Linux using `OpenGL 4.6`. ## Installation -`Cmake` minimum version 3.11 is required for installing the application. +`Cmake` minimum version 3.11 is required for installing the application. The generator used by default is `GNU Make`. Make sure you have `git` installed; it is used for fetching the [`nifticlib` library](https://github.com/NIFTI-Imaging/nifti_clib). -To build the project using `GNU Make`: + +### Quick installation +The program can be installed by running: +``` +./install.sh +``` +The above script creates the build directory, runs `Cmake` and `make` and add the executable path the system `PATH`. + +### Step-by-step installation +Alternatively, the program can be built by running: ``` mkdir build cd build @@ -13,9 +22,16 @@ cmake .. make ``` -To run the executable: +The executable file will be in the folder `${project_root}/build/Engine`. + +Then you can add the path to the directory containing the executable to your `.bashrc` configuration to make it available system-wide. + ``` -./build/Engine/rtfodfslicer path/to/image.nii.gz +export PATH='${absolute_path_to_project}/build/Engine':$PATH ``` -If you experience problems with the installation, make sure you have `git` installed; it is used for fetching the [`nifticlib`](https://github.com/NIFTI-Imaging/nifti_clib) library. +## Running the application +To run the executable: +``` +rtfodfslicer path/to/image.nii.gz +``` diff --git a/install.sh b/install.sh new file mode 100755 index 00000000..f7cd929c --- /dev/null +++ b/install.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +script="$(readlink -f "${BASH_SOURCE[0]}")" +project_dir="$(dirname "$script")" + +if [ -d "$project_dir/build" ] +then + echo "Build directory $project_dir/build already exists." +else + echo "Creating build directory $project_dir/build." + mkdir "$project_dir/build" +fi + +cd "$project_dir/build" || exit +cmake .. +make + +if [ -e "$project_dir/.cache-install" ] +then + echo "Skipping path update. Delete .cache-install file and rerun to update." +else + echo "Updating path..." + echo "export PATH='$project_dir/build/Engine':\$PATH" >> ~/.bashrc + source ~/.bashrc + touch "$project_dir/.cache-install" +fi +echo "Done!"