├── .gitignore ├── .gitmodules ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-3RD-PARTY.md ├── README.md ├── cpp ├── .clang-format ├── CMakeLists.txt ├── axes │ ├── CMakeLists.txt │ ├── axes.h │ ├── axes_interactor.cpp │ ├── axes_interactor.h │ ├── axes_painter.cpp │ ├── axes_painter.h │ ├── plot_box │ │ ├── plot_box_coordinate_arrows.cpp │ │ ├── plot_box_coordinate_arrows.h │ │ ├── plot_box_grid.cpp │ │ ├── plot_box_grid.h │ │ ├── plot_box_grid_numbers.cpp │ │ ├── plot_box_grid_numbers.h │ │ ├── plot_box_outline.cpp │ │ ├── plot_box_outline.h │ │ ├── plot_box_walls.cpp │ │ └── plot_box_walls.h │ └── structures │ │ ├── axes_limits.cpp │ │ ├── axes_limits.h │ │ ├── axes_settings.cpp │ │ ├── axes_settings.h │ │ ├── coordinate_converter.cpp │ │ ├── coordinate_converter.h │ │ ├── grid_vectors.h │ │ ├── view_angles.cpp │ │ └── view_angles.h ├── communication │ ├── CMakeLists.txt │ ├── cpp_interface │ │ ├── image │ │ │ └── image.h │ │ ├── internal │ │ │ ├── client.h │ │ │ ├── communication_functions.h │ │ │ └── communication_variables.h │ │ ├── logging.h │ │ ├── math │ │ │ ├── coordinates.h │ │ │ ├── coordinates │ │ │ │ ├── class_defs │ │ │ │ │ ├── complex_class_def.h │ │ │ │ │ ├── cylindrical_class_def.h │ │ │ │ │ ├── polar_class_def.h │ │ │ │ │ └── spherical_class_def.h │ │ │ │ ├── complex.h │ │ │ │ ├── cylindrical.h │ │ │ │ ├── polar.h │ │ │ │ └── spherical.h │ │ │ ├── geometry.h │ │ │ ├── geometry │ │ │ │ ├── circle.h │ │ │ │ ├── class_defs │ │ │ │ │ ├── circle_class_def.h │ │ │ │ │ ├── line_2d_class_def.h │ │ │ │ │ ├── line_3d_class_def.h │ │ │ │ │ ├── plane_class_def.h │ │ │ │ │ ├── sphere_class_def.h │ │ │ │ │ └── triangle_class_def.h │ │ │ │ ├── line_2d.h │ │ │ │ ├── line_3d.h │ │ │ │ ├── plane.h │ │ │ │ └── sphere.h │ │ │ ├── lin_alg.h │ │ │ ├── lin_alg │ │ │ │ ├── matrix_dynamic │ │ │ │ │ ├── class_defs │ │ │ │ │ │ └── matrix_dynamic_class_def.h │ │ │ │ │ ├── matrix_dynamic.h │ │ │ │ │ └── matrix_math_functions.h │ │ │ │ ├── matrix_fixed │ │ │ │ │ └── matrix_fixed.h │ │ │ │ ├── matrix_vector_dynamic.h │ │ │ │ ├── matrix_vector_fixed.h │ │ │ │ ├── vector_dynamic │ │ │ │ │ ├── class_defs │ │ │ │ │ │ └── vector_dynamic_class_def.h │ │ │ │ │ ├── vector_dynamic.h │ │ │ │ │ └── vector_math_functions.h │ │ │ │ ├── vector_fixed │ │ │ │ │ └── vector_fixed.h │ │ │ │ └── vector_low_dim │ │ │ │ │ ├── class_defs │ │ │ │ │ ├── vec2d_class_def.h │ │ │ │ │ ├── vec3d_class_def.h │ │ │ │ │ └── vec4d_class_def.h │ │ │ │ │ ├── vec2d.h │ │ │ │ │ ├── vec3d.h │ │ │ │ │ └── vec4d.h │ │ │ ├── math.h │ │ │ ├── math_core.h │ │ │ ├── misc │ │ │ │ ├── math_macros.h │ │ │ │ └── math_type_definitions.h │ │ │ ├── structures.h │ │ │ ├── structures │ │ │ │ ├── end_index.h │ │ │ │ ├── index_span.h │ │ │ │ └── interval_1d.h │ │ │ ├── transformations.h │ │ │ └── transformations │ │ │ │ ├── axis_angle.h │ │ │ │ ├── class_defs │ │ │ │ ├── axis_angle_class_def.h │ │ │ │ ├── pose_class_def.h │ │ │ │ ├── quaternion_class_def.h │ │ │ │ └── roll_pitch_yaw_class_def.h │ │ │ │ ├── pose.h │ │ │ │ ├── quaternion.h │ │ │ │ └── roll_pitch_yaw.h │ │ ├── plot_tool.h │ │ └── shared │ │ │ ├── base_types.h │ │ │ ├── enumerations.h │ │ │ ├── plot_attributes.h │ │ │ ├── transmission.h │ │ │ └── util_functions.h │ ├── demos │ │ ├── build_demos.sh │ │ ├── demo0.cpp │ │ ├── demo1.cpp │ │ ├── demo2 │ │ └── demo2.cpp │ ├── rx_classes.h │ ├── rx_list.h │ ├── rx_list_helper_functions.h │ ├── server.cpp │ ├── server.h │ ├── shared │ │ ├── base_types.h │ │ ├── enumerations.h │ │ ├── plot_attributes.h │ │ ├── transmission.h │ │ └── util_functions.h │ └── socket_communication_utilities.h ├── io_devices │ ├── CMakeLists.txt │ ├── io_devices.h │ ├── keyboard_state.cpp │ ├── keyboard_state.h │ ├── mouse_state.cpp │ └── mouse_state.h ├── main_application │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ ├── main_window_plot_handler.cpp │ ├── plot_data.cpp │ ├── plot_data.h │ ├── plot_objects │ │ ├── draw_line3d.h │ │ ├── draw_line_between_points_3d.h │ │ ├── draw_plane_xy.h │ │ ├── draw_plane_xz.h │ │ ├── draw_plane_yz.h │ │ ├── draw_polygon_4_points.h │ │ ├── plot2d.h │ │ ├── plot3d.h │ │ ├── plot_object_base.h │ │ ├── plot_objects.h │ │ ├── scatter.h │ │ ├── scatter3.h │ │ └── surf.h │ ├── plot_window.cpp │ ├── plot_window.h │ ├── plot_window_gl_pane.cpp │ └── plot_window_gl_pane.h ├── misc │ ├── CMakeLists.txt │ ├── misc.h │ └── number_formatting.cpp ├── opengl_low_level │ ├── 2d │ │ ├── opengl_2d_functions.cpp │ │ ├── opengl_2d_functions.h │ │ ├── opengl_2d_shape_primitives.cpp │ │ └── opengl_2d_shape_primitives.h │ ├── 3d │ │ ├── opengl_3d_functions.cpp │ │ ├── opengl_3d_functions.h │ │ ├── opengl_3d_shape_primitives.cpp │ │ └── opengl_3d_shape_primitives.h │ ├── CMakeLists.txt │ ├── data_structures.h │ ├── opengl_header.h │ ├── opengl_low_level.h │ ├── opengl_text.cpp │ └── opengl_text.h └── plot_functions │ ├── CMakeLists.txt │ ├── plot_functions.cpp │ └── plot_functions.h ├── docker ├── Dockerfile ├── docker_build.sh ├── docker_delete_containers.sh ├── docker_full_clean.sh └── docker_stop_running.sh └── media ├── demo.gif ├── plot0.png ├── plot01.png └── plot1.png /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | .vscode 4 | cpp/build 5 | 6 | cpp/communication/demos/demo0 7 | cpp/communication/demos/demo1 8 | 9 | debug 10 | release 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cpp/externals/arl"] 2 | path = cpp/externals/arl 3 | url = https://github.com/Danpihl/arl.git 4 | [submodule "cpp/externals/googletest"] 5 | path = cpp/externals/googletest 6 | url = https://github.com/google/googletest.git 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Send me an email on daniel.pihlquist@gmail.com if you want to contribute. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Daniel Pihlquist 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /LICENSE-3RD-PARTY.md: -------------------------------------------------------------------------------- 1 | ### Eigen 2 | This software uses the MPL2-licensed features of Eigen, a C++ template library for linear algebra. 3 | A copy of the MPL2 license is available at https://www.mozilla.org/en-US/MPL/2.0/. 4 | The source code of the Eigen library can be obtained at http://eigen.tuxfamily.org/. 5 | 6 | ### wxWidgets 7 | This software uses the wxWidgets, a cross platform GUI framework. A copy of the license is available at https://www.wxwidgets.org/about/licence/. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # plot_tool 2 | A data visualization tool to speed up the development process. 3 | 4 | ### Vision 5 | An application runnable on different platforms, to which you can send visualization commands through IPC, from different programming languages. The only required integration to the 'Application Under Test' shall be including a header only library, thus eliminating the need for integrating and running a 'heavy' GUI/data visualization library into your application. 6 | 7 | ### Demonstration 8 | ![](media/demo.gif) 9 | 10 | ### Example 11 | With just a few lines of code you can bring data visualization to your application, without heavy integration of big and slow graphical frameworks. 12 | ```cpp 13 | #include 14 | 15 | using namespace plot_tool; 16 | 17 | // Establish a socket with plot_tool 18 | initialize(); 19 | 20 | // --- Create some arbitrary data --- 21 | 22 | Matrix x_mat; 23 | Matrix z_mat; 24 | std::tie(x_mat, z_mat) = meshGrid(-4.0, 4.0, -4.0, 4.0, 50, 50); 25 | 26 | Matrix r = sqrt((x_mat ^ x_mat) + (z_mat ^ z_mat)); 27 | Matrix y_mat = sin(2.0 * r) / r + 0.1412; 28 | 29 | Vector x = linspaceFromPointsAndCount(-1.0, 1.0, 100); 30 | Vector y = sin(x * 4.0); 31 | Vector z = cos(x * 3.0 + 2.0); 32 | 33 | // --- Visualize --- 34 | 35 | figure(1); 36 | holdOn(); 37 | 38 | plot3(x, y, z, Color(1.0f, 0.0f, 0.0f), Linewidth(4.0f)); 39 | scatter3(x, y, z, PointSize(13.0f), Color(0.0f, 0.5f, 1.0f)); 40 | 41 | axis({-1.0, -1.0, -1.0}, {1.0, 1.0, 1.0}); 42 | 43 | 44 | figure(2); 45 | holdOn(); 46 | 47 | surf(x_mat, y_mat, z_mat, ColorMap(ColorMap::MAGMA)); 48 | surf(x_mat + 8.0, y_mat, z_mat + 8.0, EdgeColor(1.0f, 1.0f, 1.0f)); 49 | surf(x_mat, y_mat, z_mat + 8.0, ColorMap(ColorMap::VIRIDIS)); 50 | surf(x_mat + 8.0, y_mat, z_mat, FaceColor(0.1f, 0.5f, 0.7f)); 51 | 52 | axis({-4.0, -1.0, -12.0}, {12.0, 7.0, 4.0}); 53 | 54 | // Close the socket 55 | deinitialize(); 56 | ``` 57 | 58 | This produces the following output: 59 | ![Plot0](/media/plot01.png) 60 | 61 | ### State of the code 62 | The code is currently a bit of a mess. C++11 is the only supported interface language for now. Looking for people who can help make it better, add functionality and clean up the code. 63 | 64 | ### License 65 | The software is licensed with the MIT license. 66 | 67 | ### Dependencies 68 | plot_tool uses wxWidgets for the GUI backend. This is only required for building, and not for running. The tested version is currently 3.1.3, which can be downloaded [here](https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.3/wxWidgets-3.1.3.zip). It's important that wxWidgets is built with OpenGL. 69 | Configure wxWidgets with the following command: 70 | #### Ubuntu 71 | ```./configure --with-opengl --with-gtk=2 --disable-shared --disable-dynamicloader --without-libpng --without-libjpeg --without-libtiff --without-libjbig --enable-svg=off``` 72 | 73 | #### Mac: 74 | ```./configure --with-opengl --with-osx_cocoa --disable-shared --disable-dynamicloader --without-libpng --without-libjpeg --without-libtiff --without-libjbig --enable-svg=off``` 75 | 76 | 77 | ### Platforms 78 | The only tested platforms for now are Ubuntu 16.04 and newer version of MacOS. Pretty sure other version of Ubuntu work though. 79 | 80 | 81 | ### TODO 82 | - Write TODO list 83 | -------------------------------------------------------------------------------- /cpp/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlinesLeft: true 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: true 12 | AllowShortBlocksOnASingleLine: true 13 | AllowShortCaseLabelsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: Empty 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: None 18 | AlwaysBreakAfterReturnType: None 19 | AlwaysBreakBeforeMultilineStrings: true 20 | AlwaysBreakTemplateDeclarations: false 21 | BinPackArguments: false 22 | BinPackParameters: false 23 | BraceWrapping: 24 | AfterClass: true 25 | AfterControlStatement: true 26 | AfterEnum: true 27 | AfterFunction: true 28 | AfterNamespace: true 29 | AfterObjCDeclaration: true 30 | AfterStruct: true 31 | AfterUnion: true 32 | BeforeCatch: true 33 | BeforeElse: true 34 | IndentBraces: false 35 | BreakBeforeBinaryOperators: None 36 | BreakBeforeBraces: Custom 37 | BreakBeforeTernaryOperators: true 38 | BreakConstructorInitializersBeforeComma: false 39 | ColumnLimit: 100 40 | CommentPragmas: '^ IWYU pragma:' 41 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 42 | ConstructorInitializerIndentWidth: 4 43 | ContinuationIndentWidth: 4 44 | Cpp11BracedListStyle: true 45 | DerivePointerAlignment: false 46 | DisableFormat: false 47 | ExperimentalAutoDetectBinPacking: false 48 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 49 | IncludeCategories: 50 | - Regex: '^<.*\.h>' 51 | Priority: 1 52 | - Regex: '^<.*' 53 | Priority: 2 54 | - Regex: '.*' 55 | Priority: 3 56 | IndentCaseLabels: true 57 | IndentWidth: 4 58 | IndentWrappedFunctionNames: false 59 | KeepEmptyLinesAtTheStartOfBlocks: false 60 | MacroBlockBegin: '' 61 | MacroBlockEnd: '' 62 | MaxEmptyLinesToKeep: 1 63 | NamespaceIndentation: None 64 | ObjCBlockIndentWidth: 4 65 | ObjCSpaceAfterProperty: false 66 | ObjCSpaceBeforeProtocolList: false 67 | PenaltyBreakBeforeFirstCallParameter: 1 68 | PenaltyBreakComment: 300 69 | PenaltyBreakFirstLessLess: 120 70 | PenaltyBreakString: 1000 71 | PenaltyExcessCharacter: 1000000 72 | PenaltyReturnTypeOnItsOwnLine: 200 73 | PointerAlignment: Left 74 | ReflowComments: true 75 | SortIncludes: true 76 | SpaceAfterCStyleCast: false 77 | SpaceBeforeAssignmentOperators: true 78 | SpaceBeforeParens: ControlStatements 79 | SpaceInEmptyParentheses: false 80 | SpacesBeforeTrailingComments: 2 81 | SpacesInAngles: false 82 | SpacesInContainerLiterals: true 83 | SpacesInCStyleCastParentheses: false 84 | SpacesInParentheses: false 85 | SpacesInSquareBrackets: false 86 | Standard: Cpp11 87 | TabWidth: 8 88 | UseTab: Never 89 | ... 90 | -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6 FATAL_ERROR) 2 | 3 | project(plot_tool CXX) 4 | 5 | 6 | # ***************************** 7 | # ********* Set flags ********* 8 | # ***************************** 9 | 10 | set(CMAKE_CXX_STANDARD 11) 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings -Wno-deprecated \ 12 | -Wall -Wextra -pedantic -fdiagnostics-color") 13 | 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -std=c++11 -fPIC") 15 | 16 | set(TOP_LEVEL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 17 | # ********************************** 18 | # ********* Set build type ********* 19 | # ********************************** 20 | 21 | if(NOT CMAKE_BUILD_TYPE) 22 | set(CMAKE_BUILD_TYPE "DEBUG") 23 | endif() 24 | 25 | if (CMAKE_BUILD_TYPE MATCHES DEBUG) 26 | message("") 27 | message("BUILD TYPE IS DEBUG") 28 | message("") 29 | set(OUTPUT_BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/debug") 30 | execute_process (COMMAND bash -c "rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/release") 31 | 32 | else() 33 | message("") 34 | message("BUILD TYPE IS RELEASE") 35 | message("") 36 | set(OUTPUT_BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/release") 37 | execute_process (COMMAND bash -c "rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/debug") 38 | endif() 39 | 40 | execute_process (COMMAND bash -c "mkdir -p ${OUTPUT_BUILD_DIRECTORY}") 41 | 42 | # ********************************************* 43 | # ********* Platform macro definition ********* 44 | # ********************************************* 45 | 46 | if(UNIX AND NOT APPLE) 47 | set(PLATFORM_LINUX TRUE) 48 | add_compile_definitions(PLATFORM_LINUX_M) 49 | elseif(APPLE) 50 | set(PLATFORM_APPLE TRUE) 51 | add_compile_definitions(PLATFORM_APPLE_M) 52 | elseif(WIN32) 53 | set(PLATFORM_WINDOWS TRUE) 54 | add_compile_definitions(PLATFORM_WINDOWS_M) 55 | else() 56 | message(FATAL_ERROR "Unknown platform!" ) 57 | endif() 58 | 59 | 60 | # ********************************* 61 | # ********* Find packages ********* 62 | # ********************************* 63 | 64 | # ****** OpenGL ****** 65 | find_package(OpenGL REQUIRED) 66 | find_package(GLUT REQUIRED) 67 | 68 | # ****** Eigen ****** 69 | find_package(Eigen3 REQUIRED) 70 | 71 | # ****** wxWidgets ****** 72 | find_package(wxWidgets COMPONENTS core base gl) 73 | 74 | # *************************************** 75 | # ********* Include directories ********* 76 | # *************************************** 77 | 78 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 79 | include_directories("${EIGEN3_INCLUDE_DIR}") 80 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/gtest/googletest/include) 81 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/arl/include) 82 | include_directories(${OPENGL_INCLUDE_DIRS}) 83 | include_directories(${wxWidgets_INCLUDE_DIRS}) 84 | include_directories(${TOP_LEVEL_SOURCE_DIR}/communication) 85 | 86 | # ************************************ 87 | # ********* Link directories ********* 88 | # ************************************ 89 | link_directories(${OUTPUT_BUILD_DIRECTORY}) 90 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/gtest/build/lib) 91 | link_directories(${wxWidgets_LIBRARY_DIRS}) 92 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/arl/build/source/utilities/color_map/) 93 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/arl/build/source/utilities/misc/) 94 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/arl/build/source/utilities/string/) 95 | 96 | # *************************************** 97 | # ********* Include cmake files ********* 98 | # *************************************** 99 | include(${wxWidgets_USE_FILE}) 100 | 101 | # ***************************************** 102 | # ********* Adding subdirectories ********* 103 | # ***************************************** 104 | 105 | # ****** Libraries ****** 106 | add_subdirectory(misc) 107 | add_subdirectory(communication) 108 | add_subdirectory(axes) 109 | add_subdirectory(opengl_low_level) 110 | add_subdirectory(plot_functions) 111 | add_subdirectory(io_devices) 112 | 113 | # ****** Main application ****** 114 | add_subdirectory(main_application) 115 | -------------------------------------------------------------------------------- /cpp/axes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project(axes) 4 | 5 | set(OPENGL_CPP_SOURCE_FILES axes_interactor.cpp 6 | axes_painter.cpp 7 | structures/view_angles.cpp 8 | structures/axes_settings.cpp 9 | structures/axes_limits.cpp 10 | structures/coordinate_converter.cpp 11 | plot_box/plot_box_walls.cpp 12 | plot_box/plot_box_outline.cpp 13 | plot_box/plot_box_coordinate_arrows.cpp 14 | plot_box/plot_box_grid.cpp 15 | plot_box/plot_box_grid_numbers.cpp) 16 | 17 | # axes library 18 | add_library(axes STATIC ${OPENGL_CPP_SOURCE_FILES}) 19 | target_link_libraries(axes opengl-low-level 20 | io-devices 21 | plot-tool-misc) 22 | 23 | set_target_properties(axes 24 | PROPERTIES 25 | LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_BUILD_DIRECTORY}") 26 | -------------------------------------------------------------------------------- /cpp/axes/axes.h: -------------------------------------------------------------------------------- 1 | #ifndef AXES_H_ 2 | #define AXES_H_ 3 | 4 | #include "axes/axes_interactor.h" 5 | #include "axes/axes_painter.h" 6 | #include "axes/structures/axes_limits.h" 7 | #include "axes/structures/axes_settings.h" 8 | #include "axes/structures/grid_vectors.h" 9 | #include "axes/structures/view_angles.h" 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /cpp/axes/axes_interactor.h: -------------------------------------------------------------------------------- 1 | #ifndef AXES_INTERACTOR_H_ 2 | #define AXES_INTERACTOR_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "axes/axes_interactor.h" 11 | #include "axes/structures/axes_limits.h" 12 | #include "axes/structures/axes_settings.h" 13 | #include "axes/structures/coordinate_converter.h" 14 | #include "axes/structures/grid_vectors.h" 15 | #include "axes/structures/view_angles.h" 16 | #include "io_devices/io_devices.h" 17 | 18 | double findFirstPointInInterval(const double min_point, 19 | const double max_point, 20 | const double start_point, 21 | const double inc); 22 | double findFirstPointBeforeMin(const double min_point, const double start_point, const double inc); 23 | 24 | class AxesInteractor 25 | { 26 | private: 27 | // Variables 28 | const double rotation_mouse_gain = 0.01; 29 | const double pan_mouse_gain = 0.005; 30 | const double zoom_mouse_gain = 0.005; 31 | 32 | MouseActivity current_mouse_activity; 33 | 34 | ViewAngles view_angles_; 35 | ViewAngles default_view_angles_; 36 | 37 | AxesLimits axes_limits_; 38 | AxesLimits default_axes_limits_; 39 | 40 | AxesSettings axes_settings_; 41 | 42 | CoordinateConverter coord_converter_; 43 | 44 | arl::Vec3Dd inc0; 45 | 46 | // Functions 47 | void changePan(const double dx, const double dy); 48 | void changeZoom(const double dy); 49 | void changeRotation(const double dx, const double dy); 50 | 51 | public: 52 | AxesInteractor(const AxesSettings& axes_settings); 53 | 54 | void update(const InteractionType interaction_type, 55 | const int window_width, 56 | const int window_height); 57 | void resetView(); 58 | void setViewAngles(const double azimuth, const double elevation); 59 | void setAxesLimits(const arl::Vec3Dd& min_vec, const arl::Vec3Dd& max_vec); 60 | void setAxesLimits(const arl::Vec2Dd& min_vec, const arl::Vec2Dd& max_vec); 61 | 62 | void registerMouseDragInput(const int dx, const int dy); 63 | void updateMouseActivity(const InteractionType interaction_type); 64 | 65 | GridVectors generateGridVectors(); 66 | ViewAngles getViewAngles() const; 67 | AxesLimits getAxesLimits() const; 68 | CoordinateConverter getCoordConverter() const; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /cpp/axes/axes_painter.h: -------------------------------------------------------------------------------- 1 | #ifndef AXES_PAINTER_H_ 2 | #define AXES_PAINTER_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "axes/structures/axes_limits.h" 11 | #include "axes/structures/axes_settings.h" 12 | #include "axes/structures/coordinate_converter.h" 13 | #include "axes/structures/grid_vectors.h" 14 | #include "axes/structures/view_angles.h" 15 | #include "opengl_low_level/opengl_low_level.h" 16 | 17 | class AxesPainter 18 | { 19 | // Variables 20 | ViewAngles view_angles_; 21 | AxesLimits axes_limits_; 22 | 23 | AxesSettings axes_settings_; 24 | CoordinateConverter coord_converter_; 25 | 26 | GridVectors gv_; 27 | 28 | // Functions 29 | void printViewAnglesInPlotWindow() const; 30 | 31 | void setOpenGLStateForPlotBox() const; 32 | void setOpenGLStateForAxesGrid() const; 33 | 34 | void drawAxesArrows() const; 35 | 36 | void enableClipPlanes() const; 37 | void disableClipPlanes() const; 38 | 39 | public: 40 | void plotBegin(); 41 | void plotEnd(); 42 | 43 | AxesPainter() = default; 44 | AxesPainter(const AxesSettings& axes_settings); 45 | 46 | void paint(const AxesLimits& axes_limits, 47 | const ViewAngles& view_angles, 48 | const GridVectors& gv, 49 | const CoordinateConverter& coord_converter); 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_coordinate_arrows.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/plot_box/plot_box_coordinate_arrows.h" 2 | 3 | #include 4 | 5 | #include "opengl_low_level/opengl_low_level.h" 6 | 7 | using namespace arl; 8 | 9 | void drawCoordinateAxesLines(const AxesSettings& axes_settings) 10 | { 11 | glLineWidth(1.0f); 12 | const double ext_fac = axes_settings.getCoordAxExtFac(); 13 | const double f = axes_settings.getPlotBoxSizeFactor(); 14 | 15 | setColor(1.0f, 0.0f, 0.0f); 16 | drawLine3D({f, -f, -f}, {ext_fac * f, -f, -f}); 17 | 18 | setColor(0.0f, 1.0f, 0.0f); 19 | drawLine3D({-f, f, -f}, {-f, ext_fac * f, -f}); 20 | 21 | setColor(0.0f, 0.0f, 1.0f); 22 | drawLine3D({-f, -f, f}, {-f, -f, ext_fac * f}); 23 | } 24 | 25 | void drawArrowHead(const Vec3Dd& v0, const Vec3Dd& v1, const CoordinateConverter& coord_converter) 26 | { 27 | const Vec2Dd v0_2d = coord_converter.modelToViewCoordinate(v0); 28 | const Vec2Dd v1_2d = coord_converter.modelToViewCoordinate(v1); 29 | 30 | const Vec2Dd v01 = v1_2d.normalizedVectorBetweenPoints(v0_2d); 31 | 32 | const double arrow_angle = M_PI / 10.0; 33 | 34 | const Vec2Dd a0 = rotationMatrix2D(arrow_angle) * v01; 35 | const Vec2Dd a1 = rotationMatrix2D(-arrow_angle) * v01; 36 | 37 | const double f = 0.04; 38 | 39 | drawLine2D(v1_2d.x, v1_2d.y, v1_2d.x + a0.x * f, v1_2d.y + a0.y * f); 40 | drawLine2D(v1_2d.x, v1_2d.y, v1_2d.x + a1.x * f, v1_2d.y + a1.y * f); 41 | } 42 | 43 | void drawCoordinateArrowHead(const AxesSettings& axes_settings, 44 | const CoordinateConverter& coord_conv) 45 | { 46 | const double ext_fac = axes_settings.getCoordAxExtFac(); 47 | 48 | const double f = axes_settings.getPlotBoxSizeFactor(); 49 | const Vec3Dd x1(ext_fac * f, -f, -f); 50 | const Vec3Dd y1(-f, ext_fac * f, -f); 51 | const Vec3Dd z1(-f, -f, ext_fac * f); 52 | 53 | const Vec3Dd x0 = x1 - Vec3Dd(1.0, 0.0, 0.0); 54 | const Vec3Dd y0 = y1 - Vec3Dd(0.0, 1.0, 0.0); 55 | const Vec3Dd z0 = z1 - Vec3Dd(0.0, 0.0, 1.0); 56 | 57 | setColor(1.0, 0.0, 0.0); 58 | drawArrowHead(x0, x1, coord_conv); 59 | setColor(0.0, 1.0, 0.0); 60 | drawArrowHead(y0, y1, coord_conv); 61 | setColor(0.0, 0.0, 1.0); 62 | drawArrowHead(z0, z1, coord_conv); 63 | } 64 | 65 | void drawCoordinateAxesLetters(const AxesSettings& axes_settings, 66 | const CoordinateConverter& coord_conv) 67 | { 68 | // Extend a little bit (1.1) so letters are not "on" the arrow head 69 | const double ext_fac = axes_settings.getCoordAxExtFac() * 1.1; 70 | 71 | const double f = axes_settings.getPlotBoxSizeFactor(); 72 | Vec3Dd xpos(ext_fac * f, -f, -f); 73 | Vec3Dd ypos(-f, ext_fac * f, -f); 74 | Vec3Dd zpos(-f, -f, ext_fac * f); 75 | 76 | const Vec2Dd x_vec = coord_conv.modelToViewCoordinate(xpos); 77 | const Vec2Dd y_vec = coord_conv.modelToViewCoordinate(ypos); 78 | const Vec2Dd z_vec = coord_conv.modelToViewCoordinate(zpos); 79 | 80 | setColor(0.0, 0.0, 0.0); 81 | putTextAt("X", x_vec.x, x_vec.y); 82 | putTextAt("Y", y_vec.x, y_vec.y); 83 | putTextAt("Z", z_vec.x, z_vec.y); 84 | } 85 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_coordinate_arrows.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_BOX_COORDINATE_ARROWS_H_ 2 | #define PLOT_BOX_COORDINATE_ARROWS_H_ 3 | 4 | #include 5 | 6 | #include "axes/structures/axes_settings.h" 7 | #include "axes/structures/coordinate_converter.h" 8 | #include "axes/structures/view_angles.h" 9 | 10 | void drawCoordinateAxesLines(const AxesSettings& axes_settings); 11 | void drawCoordinateArrowHead(const AxesSettings& axes_settings, 12 | const CoordinateConverter& coord_conv); 13 | void drawCoordinateAxesLetters(const AxesSettings& axes_settings, 14 | const CoordinateConverter& coord_conv); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_grid.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/plot_box/plot_box_grid.h" 2 | 3 | #include 4 | 5 | #include "opengl_low_level/opengl_low_level.h" 6 | 7 | using namespace arl; 8 | 9 | void drawXZGrid(const double y_coord, 10 | const Vectord& x_values, 11 | const Vectord& z_values, 12 | const double x0, 13 | const double x1, 14 | const double z0, 15 | const double z1) 16 | { 17 | assert((x_values.size()) > 0 && (z_values.size() > 0)); 18 | for (size_t k = 0; k < x_values.size(); k++) 19 | { 20 | drawLine3D(Vec3Dd(x_values(k), y_coord, z0), Vec3Dd(x_values(k), y_coord, z1)); 21 | } 22 | for (size_t k = 0; k < z_values.size(); k++) 23 | { 24 | drawLine3D(Vec3Dd(x0, y_coord, z_values(k)), Vec3Dd(x1, y_coord, z_values(k))); 25 | } 26 | } 27 | 28 | void drawXYGrid(const double z_coord, 29 | const Vectord& x_values, 30 | const Vectord& y_values, 31 | const double x0, 32 | const double x1, 33 | const double y0, 34 | const double y1) 35 | { 36 | assert((x_values.size()) > 0 && (y_values.size() > 0)); 37 | for (size_t k = 0; k < x_values.size(); k++) 38 | { 39 | drawLine3D(Vec3Dd(x_values(k), y0, z_coord), Vec3Dd(x_values(k), y1, z_coord)); 40 | } 41 | for (size_t k = 0; k < y_values.size(); k++) 42 | { 43 | drawLine3D(Vec3Dd(x0, y_values(k), z_coord), Vec3Dd(x1, y_values(k), z_coord)); 44 | } 45 | } 46 | 47 | void drawYZGrid(const double x_coord, 48 | const Vectord& y_values, 49 | const Vectord& z_values, 50 | const double y0, 51 | const double y1, 52 | const double z0, 53 | const double z1) 54 | { 55 | assert((z_values.size()) > 0 && (y_values.size() > 0)); 56 | for (size_t k = 0; k < y_values.size(); k++) 57 | { 58 | drawLine3D(Vec3Dd(x_coord, y_values(k), z0), Vec3Dd(x_coord, y_values(k), z1)); 59 | } 60 | for (size_t k = 0; k < z_values.size(); k++) 61 | { 62 | drawLine3D(Vec3Dd(x_coord, y0, z_values(k)), Vec3Dd(x_coord, y1, z_values(k))); 63 | } 64 | } 65 | 66 | void drawGrid(const GridVectors& gv, 67 | const AxesSettings& axes_settings, 68 | const AxesLimits& axes_limits, 69 | const ViewAngles& view_angles) 70 | { 71 | glLineWidth(1.0f); 72 | setColor(axes_settings.getGridColor()); 73 | 74 | const Vec3Dd s = axes_limits.getAxesScale(); 75 | 76 | const double box_x_2 = s.x / 2.0f; 77 | const double box_y_2 = s.y / 2.0f; 78 | const double box_z_2 = s.z / 2.0f; 79 | 80 | const double azimuth = view_angles.getSnappedAzimuth(); 81 | const double elevation = view_angles.getSnappedElevation(); 82 | 83 | if ((azimuth > -M_PI_2) && (azimuth < M_PI_2)) 84 | { 85 | drawXYGrid(-box_z_2, gv.x, gv.y, -box_x_2, box_x_2, -box_y_2, box_y_2); 86 | } 87 | else 88 | { 89 | drawXYGrid(box_z_2, gv.x, gv.y, -box_x_2, box_x_2, -box_y_2, box_y_2); 90 | } 91 | 92 | if ((azimuth > 0.0) && (azimuth < M_PI)) 93 | { 94 | drawYZGrid(box_x_2, gv.y, gv.z, -box_y_2, box_y_2, -box_z_2, box_z_2); 95 | } 96 | else 97 | { 98 | drawYZGrid(-box_x_2, gv.y, gv.z, -box_y_2, box_y_2, -box_z_2, box_z_2); 99 | } 100 | 101 | if (elevation < 0.0) 102 | { 103 | drawXZGrid(box_y_2, gv.x, gv.z, -box_x_2, box_x_2, -box_z_2, box_z_2); 104 | } 105 | else 106 | { 107 | drawXZGrid(-box_y_2, gv.x, gv.z, -box_x_2, box_x_2, -box_z_2, box_z_2); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_grid.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_BOX_GRID_H_ 2 | #define PLOT_BOX_GRID_H_ 3 | 4 | #include 5 | 6 | #include "axes/structures/axes_limits.h" 7 | #include "axes/structures/axes_settings.h" 8 | #include "axes/structures/grid_vectors.h" 9 | #include "axes/structures/view_angles.h" 10 | 11 | void drawGrid(const GridVectors& gv, 12 | const AxesSettings& axes_settings, 13 | const AxesLimits& axes_limits, 14 | const ViewAngles& view_angles); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_grid_numbers.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_BOX_GRID_NUMBERS_H_ 2 | #define PLOT_BOX_GRID_NUMBERS_H_ 3 | 4 | #include 5 | 6 | #include "axes/structures/axes_limits.h" 7 | #include "axes/structures/coordinate_converter.h" 8 | #include "axes/structures/grid_vectors.h" 9 | #include "axes/structures/view_angles.h" 10 | 11 | void drawAxisNumbers(const GridVectors& gv, 12 | const AxesLimits& axes_limits, 13 | const ViewAngles& view_angles, 14 | const CoordinateConverter& coord_converter); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_outline.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/plot_box/plot_box_outline.h" 2 | 3 | #include 4 | 5 | #include "opengl_low_level/opengl_low_level.h" 6 | 7 | using namespace arl; 8 | 9 | void drawOutline(const AxesSettings& axes_settings, const ViewAngles& view_angles) 10 | { 11 | setLinewidth(1.5f); 12 | setColor(0.0f, 0.0f, 0.0f); 13 | const double width = axes_settings.getPlotBoxSizeFactor(); 14 | const double height = axes_settings.getPlotBoxSizeFactor(); 15 | const double depth = axes_settings.getPlotBoxSizeFactor(); 16 | 17 | double width_to_use, height_to_use, depth_to_use; 18 | 19 | if ((view_angles.getSnappedAzimuth() > -M_PI_2) && (view_angles.getSnappedAzimuth() < M_PI_2)) 20 | { 21 | depth_to_use = depth; 22 | } 23 | else 24 | { 25 | depth_to_use = -depth; 26 | } 27 | 28 | if ((view_angles.getSnappedAzimuth() > 0.0) && (view_angles.getSnappedAzimuth() < M_PI)) 29 | { 30 | width_to_use = -width; 31 | } 32 | else 33 | { 34 | width_to_use = width; 35 | } 36 | 37 | if (view_angles.getSnappedElevation() < 0.0f) 38 | { 39 | height_to_use = height; 40 | } 41 | else 42 | { 43 | height_to_use = -height; 44 | } 45 | 46 | drawLine3D({-width, height_to_use, depth_to_use}, {width, height_to_use, depth_to_use}); 47 | drawLine3D({width_to_use, height_to_use, -depth}, {width_to_use, height_to_use, depth}); 48 | 49 | drawLine3D({-width, -height_to_use, -depth_to_use}, {width, -height_to_use, -depth_to_use}); 50 | drawLine3D({-width_to_use, -height_to_use, -depth}, {-width_to_use, -height_to_use, depth}); 51 | 52 | drawLine3D({width_to_use, height, -depth_to_use}, {width_to_use, -height, -depth_to_use}); 53 | drawLine3D({-width_to_use, height, depth_to_use}, {-width_to_use, -height, depth_to_use}); 54 | } 55 | 56 | void drawDottedBox(const AxesSettings& axes_settings) 57 | { 58 | setLinewidth(1.0f); 59 | glPushAttrib(GL_ENABLE_BIT); 60 | setColor(0.0f, 0.0f, 0.0f); 61 | glLineStipple(1, 4450); 62 | glEnable(GL_LINE_STIPPLE); 63 | const double f = axes_settings.getPlotBoxSizeFactor(); 64 | 65 | drawLine3D({-f, -f, -f}, {-f, -f, f}); 66 | drawLine3D({-f, -f, -f}, {-f, f, -f}); 67 | drawLine3D({-f, -f, -f}, {f, -f, -f}); 68 | drawLine3D({f, f, f}, {f, f, -f}); 69 | drawLine3D({f, f, f}, {f, -f, f}); 70 | drawLine3D({f, f, f}, {-f, f, f}); 71 | drawLine3D({-f, -f, f}, {f, -f, f}); 72 | drawLine3D({f, -f, -f}, {f, -f, f}); 73 | drawLine3D({f, -f, -f}, {f, f, -f}); 74 | drawLine3D({-f, -f, f}, {-f, f, f}); 75 | drawLine3D({-f, f, -f}, {-f, f, f}); 76 | drawLine3D({-f, f, -f}, {f, f, -f}); 77 | 78 | glPopAttrib(); 79 | } -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_outline.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_BOX_OUTLINE_H_ 2 | #define PLOT_BOX_OUTLINE_H_ 3 | 4 | #include "axes/structures/axes_settings.h" 5 | #include "axes/structures/view_angles.h" 6 | 7 | void drawDottedBox(const AxesSettings& axes_settings); 8 | void drawOutline(const AxesSettings& axes_settings, const ViewAngles& view_angles); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_walls.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/plot_box/plot_box_walls.h" 2 | 3 | #include 4 | 5 | #include "opengl_low_level/opengl_low_level.h" 6 | 7 | using namespace arl; 8 | 9 | void drawPlotBoxWalls(const AxesSettings& axes_settings, const ViewAngles& view_angles) 10 | { 11 | setLinewidth(1.0f); 12 | setColor(axes_settings.getPlotBoxWallColor()); 13 | const Vec3Dd s = Vec3Dd(1.0, 1.0, 1.0) * axes_settings.getPlotBoxSizeFactor(); 14 | 15 | if ((view_angles.getSnappedAzimuth() > -M_PI_2) && (view_angles.getSnappedAzimuth() < M_PI_2)) 16 | { 17 | glBegin(GL_QUADS); 18 | glVertex3f(s.x, s.y, -s.z); 19 | glVertex3f(s.x, -s.y, -s.z); 20 | glVertex3f(-s.x, -s.y, -s.z); 21 | glVertex3f(-s.x, s.y, -s.z); 22 | glEnd(); 23 | } 24 | else 25 | { 26 | glBegin(GL_QUADS); 27 | glVertex3f(s.x, s.y, s.z); 28 | glVertex3f(s.x, -s.y, s.z); 29 | glVertex3f(-s.x, -s.y, s.z); 30 | glVertex3f(-s.x, s.y, s.z); 31 | glEnd(); 32 | } 33 | 34 | if ((view_angles.getSnappedAzimuth() > 0.0) && (view_angles.getSnappedAzimuth() < M_PI)) 35 | { 36 | glBegin(GL_QUADS); 37 | glVertex3f(s.x, s.y, s.z); 38 | glVertex3f(s.x, s.y, -s.z); 39 | glVertex3f(s.x, -s.y, -s.z); 40 | glVertex3f(s.x, -s.y, s.z); 41 | glEnd(); 42 | } 43 | else 44 | { 45 | glBegin(GL_QUADS); 46 | glVertex3f(-s.x, s.y, s.z); 47 | glVertex3f(-s.x, s.y, -s.z); 48 | glVertex3f(-s.x, -s.y, -s.z); 49 | glVertex3f(-s.x, -s.y, s.z); 50 | glEnd(); 51 | } 52 | 53 | if (view_angles.getSnappedElevation() < 0.0f) 54 | { 55 | glBegin(GL_QUADS); 56 | glVertex3f(s.x, s.y, s.z); 57 | glVertex3f(s.x, s.y, -s.z); 58 | glVertex3f(-s.x, s.y, -s.z); 59 | glVertex3f(-s.x, s.y, s.z); 60 | glEnd(); 61 | } 62 | else 63 | { 64 | glBegin(GL_QUADS); 65 | glVertex3f(s.x, -s.y, s.z); 66 | glVertex3f(s.x, -s.y, -s.z); 67 | glVertex3f(-s.x, -s.y, -s.z); 68 | glVertex3f(-s.x, -s.y, s.z); 69 | glEnd(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /cpp/axes/plot_box/plot_box_walls.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_BOX_WALLS_H_ 2 | #define PLOT_BOX_WALLS_H_ 3 | 4 | #include "axes/structures/axes_settings.h" 5 | #include "axes/structures/view_angles.h" 6 | 7 | void drawPlotBoxWalls(const AxesSettings& axes_settings, const ViewAngles& view_angles); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /cpp/axes/structures/axes_limits.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/structures/axes_limits.h" 2 | 3 | #include 4 | 5 | using namespace arl; 6 | 7 | AxesLimits::AxesLimits(const arl::Vec3Dd& min_vec, const arl::Vec3Dd& max_vec) 8 | { 9 | lim_min_ = min_vec; 10 | tick_begin_ = min_vec; 11 | lim_max_ = max_vec; 12 | } 13 | 14 | void AxesLimits::setTickBegin(const arl::Vec3Dd& tick_begin_vec) 15 | { 16 | tick_begin_ = tick_begin_vec; 17 | } 18 | 19 | void AxesLimits::setMin(const Vec3Dd& min_vec) 20 | { 21 | lim_min_ = min_vec; 22 | } 23 | 24 | void AxesLimits::setMax(const Vec3Dd& max_vec) 25 | { 26 | lim_max_ = max_vec; 27 | } 28 | 29 | void AxesLimits::incrementMinMax(const arl::Vec3Dd& dv) 30 | { 31 | lim_min_ = lim_min_ + dv; 32 | lim_max_ = lim_max_ + dv; 33 | } 34 | 35 | Vec3Dd AxesLimits::getMin() const 36 | { 37 | return lim_min_; 38 | } 39 | 40 | Vec3Dd AxesLimits::getMax() const 41 | { 42 | return lim_max_; 43 | } 44 | 45 | arl::Vec3Dd AxesLimits::getTickBegin() const 46 | { 47 | return tick_begin_; 48 | } 49 | 50 | Vec3Dd AxesLimits::getAxesCenter() const 51 | { 52 | return (getMin() + getMax()) / 2.0; 53 | } 54 | 55 | Vec3Dd AxesLimits::getAxesScale() const 56 | { 57 | return getMax() - getMin(); 58 | } 59 | -------------------------------------------------------------------------------- /cpp/axes/structures/axes_limits.h: -------------------------------------------------------------------------------- 1 | #ifndef AXES_LIMITS_H_ 2 | #define AXES_LIMITS_H_ 3 | 4 | #include 5 | 6 | class AxesLimits 7 | { 8 | private: 9 | arl::Vec3Dd lim_min_; 10 | arl::Vec3Dd lim_max_; 11 | arl::Vec3Dd tick_begin_; 12 | 13 | public: 14 | AxesLimits() = default; 15 | AxesLimits(const arl::Vec3Dd& min_vec, const arl::Vec3Dd& max_vec); 16 | 17 | void setTickBegin(const arl::Vec3Dd& tick_begin_vec); 18 | 19 | void setMin(const arl::Vec3Dd& min_vec); 20 | void setMax(const arl::Vec3Dd& max_vec); 21 | 22 | void incrementMinMax(const arl::Vec3Dd& dv); 23 | 24 | arl::Vec3Dd getMin() const; 25 | arl::Vec3Dd getMax() const; 26 | 27 | arl::Vec3Dd getTickBegin() const; 28 | 29 | arl::Vec3Dd getAxesCenter() const; 30 | 31 | arl::Vec3Dd getAxesScale() const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cpp/axes/structures/axes_settings.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/structures/axes_settings.h" 2 | 3 | #include 4 | 5 | using namespace arl; 6 | 7 | AxesSettings::AxesSettings() 8 | { 9 | plot_box_wall_color_ = RGBTripletf(1.0f, 1.0f, 1.0f); 10 | plot_box_size_factor_ = 0.5; 11 | 12 | grid_on_ = false; 13 | grid_color_ = RGBTripletf(127.0f / 255.0f, 127.0f / 255.0f, 127.0f / 255.0f); 14 | 15 | coordinate_axes_on_ = true; 16 | coord_axes_extension_factor_ = 1.5; 17 | 18 | x_label_ = "x"; 19 | y_label_ = "y"; 20 | z_label_ = "z"; 21 | 22 | num_axes_ticks_ = 4; 23 | 24 | axes_state_ = AxesState::DEFAULT; 25 | 26 | min_vec_ = Vec3Dd(-1.0, -1.0, -1.0); 27 | max_vec_ = Vec3Dd(1.0, 1.0, 1.0); 28 | } 29 | 30 | AxesSettings::AxesSettings(const Vec3Dd& min_vec, const Vec3Dd& max_vec) 31 | { 32 | plot_box_wall_color_ = RGBTripletf(1.0f, 1.0f, 1.0f); 33 | plot_box_size_factor_ = 0.5; 34 | 35 | grid_on_ = false; 36 | grid_color_ = RGBTripletf(127.0f / 255.0f, 127.0f / 255.0f, 127.0f / 255.0f); 37 | 38 | coordinate_axes_on_ = true; 39 | coord_axes_extension_factor_ = 1.5; 40 | 41 | x_label_ = "x"; 42 | y_label_ = "y"; 43 | z_label_ = "z"; 44 | 45 | num_axes_ticks_ = 4; 46 | 47 | axes_state_ = AxesState::DEFAULT; 48 | 49 | min_vec_ = min_vec; 50 | max_vec_ = max_vec; 51 | } 52 | 53 | double AxesSettings::getPlotBoxSizeFactor() const 54 | { 55 | return plot_box_size_factor_; 56 | } 57 | 58 | arl::Vec3Dd AxesSettings::getMinVec() const 59 | { 60 | return min_vec_; 61 | } 62 | 63 | arl::Vec3Dd AxesSettings::getMaxVec() const 64 | { 65 | return max_vec_; 66 | } 67 | 68 | AxesState AxesSettings::getAxesState() const 69 | { 70 | return axes_state_; 71 | } 72 | 73 | std::string AxesSettings::getXLabel() const 74 | { 75 | return x_label_; 76 | } 77 | 78 | std::string AxesSettings::getYLabel() const 79 | { 80 | return y_label_; 81 | } 82 | 83 | std::string AxesSettings::getZLabel() const 84 | { 85 | return z_label_; 86 | } 87 | 88 | size_t AxesSettings::getNumAxesTicks() const 89 | { 90 | return num_axes_ticks_; 91 | } 92 | 93 | RGBTripletf AxesSettings::getGridColor() const 94 | { 95 | return grid_color_; 96 | } 97 | 98 | bool AxesSettings::getGridOn() const 99 | { 100 | return grid_on_; 101 | } 102 | 103 | bool AxesSettings::getCoordinateAxesOn() const 104 | { 105 | return coordinate_axes_on_; 106 | } 107 | 108 | RGBTripletf AxesSettings::getPlotBoxWallColor() const 109 | { 110 | return plot_box_wall_color_; 111 | } 112 | 113 | double AxesSettings::getCoordAxExtFac() const 114 | { 115 | return coord_axes_extension_factor_; 116 | } 117 | -------------------------------------------------------------------------------- /cpp/axes/structures/axes_settings.h: -------------------------------------------------------------------------------- 1 | #ifndef AXES_SETTINGS_H_ 2 | #define AXES_SETTINGS_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "opengl_low_level/opengl_low_level.h" 10 | 11 | enum class AxesState 12 | { 13 | DEFAULT, 14 | EQUAL, 15 | SQUARE 16 | }; 17 | 18 | class AxesSettings 19 | { 20 | private: 21 | RGBTripletf plot_box_wall_color_; 22 | double plot_box_size_factor_; 23 | 24 | bool grid_on_; 25 | RGBTripletf grid_color_; 26 | 27 | bool coordinate_axes_on_; 28 | double coord_axes_extension_factor_; 29 | 30 | std::string x_label_; 31 | std::string y_label_; 32 | std::string z_label_; 33 | 34 | size_t num_axes_ticks_; 35 | 36 | AxesState axes_state_; 37 | 38 | arl::Vec3Dd min_vec_; 39 | arl::Vec3Dd max_vec_; 40 | 41 | public: 42 | AxesSettings(); 43 | AxesSettings(const arl::Vec3Dd& min_vec, const arl::Vec3Dd& max_vec); 44 | 45 | AxesState getAxesState() const; 46 | std::string getXLabel() const; 47 | std::string getYLabel() const; 48 | std::string getZLabel() const; 49 | size_t getNumAxesTicks() const; 50 | RGBTripletf getGridColor() const; 51 | bool getGridOn() const; 52 | bool getCoordinateAxesOn() const; 53 | RGBTripletf getPlotBoxWallColor() const; 54 | double getCoordAxExtFac() const; 55 | arl::Vec3Dd getMinVec() const; 56 | arl::Vec3Dd getMaxVec() const; 57 | double getPlotBoxSizeFactor() const; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cpp/axes/structures/coordinate_converter.cpp: -------------------------------------------------------------------------------- 1 | #include "axes/structures/coordinate_converter.h" 2 | 3 | using namespace arl; 4 | 5 | #include 6 | 7 | CoordinateConverter::CoordinateConverter(const Vec2Dd& window_size, 8 | const ViewAngles& view_angles, 9 | const AxesLimits& axes_limits) 10 | : window_size_(window_size), view_angles_(view_angles), axes_limits_(axes_limits) 11 | { 12 | } 13 | 14 | void CoordinateConverter::updateInternalState(const Vec2Dd& window_size, 15 | const ViewAngles& view_angles, 16 | const AxesLimits& axes_limits) 17 | { 18 | window_size_ = window_size; 19 | view_angles_ = view_angles; 20 | axes_limits_ = axes_limits; 21 | } 22 | 23 | Vec2Dd CoordinateConverter::orthogonalViewToModelCoordinate(const Vec2Dd& view_coord) const 24 | { 25 | // Only works when azimuth = elevation = 0 26 | assert((view_angles_.getSnappedElevation() == 0.0) && 27 | (view_angles_.getSnappedAzimuth() == 0.0)); 28 | 29 | const Vec3Dd scale = axes_limits_.getAxesScale(); 30 | const Vec3Dd offset = axes_limits_.getAxesCenter(); 31 | const Vec3Dd res = Vec3Dd(view_coord.x, view_coord.y, 0.0).elementWiseMultiply(scale) + offset; 32 | 33 | return Vec2Dd(res.x, res.y); 34 | } 35 | 36 | Vec2Dd CoordinateConverter::modelToViewCoordinate(const Vec3Dd& model_coord) const 37 | { 38 | const Matrixd rotation_mat = view_angles_.getSnappedRotationMatrix(); 39 | const Vec3Dd vr = rotation_mat * model_coord; 40 | 41 | return Vec2Dd(vr.x, vr.y); 42 | } 43 | 44 | Vec2Dd CoordinateConverter::screenToViewCoordinate(const Vec2Dd& screen_coord) const 45 | { 46 | const double w_x = window_size_.x; 47 | const double w_y = window_size_.y; 48 | 49 | Vec2Dd vret; 50 | 51 | vret.x = 2.0 * (screen_coord.x / w_x - 0.5); 52 | vret.y = 2.0 * ((w_y - screen_coord.y + 1.0) / (w_y - 1.0) - 0.5); 53 | 54 | return vret; 55 | } 56 | 57 | Vec2Dd CoordinateConverter::viewToScreenCoordinate(const Vec2Dd& view_coord) const 58 | { 59 | const double w_x = window_size_.x; 60 | const double w_y = window_size_.y; 61 | 62 | Vec2Dd vret; 63 | vret.x = (view_coord.x / 2.0 + 0.5) * w_x; 64 | vret.y = 2.0 * w_y - ((view_coord.y / 2.0 + 0.5) * (w_y - 1.0) - 1.0 + w_y); 65 | 66 | return vret; 67 | } 68 | -------------------------------------------------------------------------------- /cpp/axes/structures/coordinate_converter.h: -------------------------------------------------------------------------------- 1 | #ifndef COORDINATE_CONVERTER_H_ 2 | #define COORDINATE_CONVERTER_H_ 3 | 4 | #include 5 | 6 | #include "axes/structures/axes_limits.h" 7 | #include "axes/structures/view_angles.h" 8 | 9 | // Model - view - screen 10 | // Model: 3D coordinates, world, defined with axes_limits_ 11 | // View: 2D gl world coordinates, defined as [-1, -1] in bottom left corner 12 | // and [1, 1] in top right corner 13 | // Screen: Window pixels, defined as [0, 0] in top left corner 14 | 15 | struct CoordinateConverter 16 | { 17 | private: 18 | arl::Vec2Dd window_size_; 19 | ViewAngles view_angles_; 20 | AxesLimits axes_limits_; 21 | 22 | public: 23 | CoordinateConverter() = default; 24 | CoordinateConverter(const arl::Vec2Dd& window_size, 25 | const ViewAngles& view_angles, 26 | const AxesLimits& axes_limits); 27 | void updateInternalState(const arl::Vec2Dd& window_size, 28 | const ViewAngles& view_angles, 29 | const AxesLimits& axes_limits); 30 | 31 | arl::Vec2Dd orthogonalViewToModelCoordinate(const arl::Vec2Dd& view_coord) const; 32 | arl::Vec2Dd screenToViewCoordinate(const arl::Vec2Dd& screen_coord) const; 33 | arl::Vec2Dd viewToScreenCoordinate(const arl::Vec2Dd& view_coord) const; 34 | arl::Vec2Dd modelToViewCoordinate(const arl::Vec3Dd& model_coord) const; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /cpp/axes/structures/grid_vectors.h: -------------------------------------------------------------------------------- 1 | #ifndef GRID_VECTORS_H_ 2 | #define GRID_VECTORS_H_ 3 | 4 | #include 5 | 6 | enum class InteractionType 7 | { 8 | UNCHANGED, 9 | PAN, 10 | ROTATE, 11 | RESET, 12 | ZOOM, 13 | }; 14 | 15 | struct GridVectors 16 | { 17 | arl::Vectord x; 18 | arl::Vectord y; 19 | arl::Vectord z; 20 | GridVectors(const size_t num_lines) 21 | { 22 | x.resize(num_lines); 23 | y.resize(num_lines); 24 | z.resize(num_lines); 25 | } 26 | GridVectors() = default; 27 | void resizeX(const size_t num_lines) 28 | { 29 | x.resize(num_lines); 30 | } 31 | void resizeY(const size_t num_lines) 32 | { 33 | y.resize(num_lines); 34 | } 35 | void resizeZ(const size_t num_lines) 36 | { 37 | z.resize(num_lines); 38 | } 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /cpp/axes/structures/view_angles.h: -------------------------------------------------------------------------------- 1 | #ifndef VIEW_ANGLES_H_ 2 | #define VIEW_ANGLES_H_ 3 | 4 | #include 5 | 6 | class ViewAngles 7 | { 8 | private: 9 | double azimuth_; 10 | double snapped_azimuth_; 11 | double elevation_; 12 | double snapped_elevation_; 13 | double angle_limit_; 14 | 15 | void setSnapAngles(); 16 | double calcElevationSnapAngle() const; 17 | double calcAzimuthSnapAngle() const; 18 | 19 | public: 20 | ViewAngles(); 21 | ViewAngles(const double azimuth, const double elevation); 22 | ViewAngles(const double azimuth, const double elevation, const double angle_limit); 23 | void setAngles(const double azimuth, const double elevation); 24 | void changeAnglesWithDelta(const double azimuth, const double elevation); 25 | double getAzimuth() const; 26 | double getElevation() const; 27 | double getSnappedAzimuth() const; 28 | double getSnappedElevation() const; 29 | arl::AxisAngled getAngleAxis() const; 30 | arl::Matrixd getRotationMatrix() const; 31 | arl::AxisAngled getSnappedAngleAxis() const; 32 | arl::Matrixd getSnappedRotationMatrix() const; 33 | bool isCloseToSnap() const; 34 | bool bothSnappedBelowAngleLimitAroundZero() const; 35 | double getAngleLimit() const; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /cpp/communication/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6 FATAL_ERROR) 2 | 3 | project(communication CXX) 4 | 5 | set(CLIENT_SERVER_SOURCE_FILES server.cpp) 6 | 7 | # client_server library 8 | add_library(communication STATIC ${CLIENT_SERVER_SOURCE_FILES}) 9 | target_link_libraries(communication pthread) 10 | 11 | set_target_properties(communication 12 | PROPERTIES 13 | LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_BUILD_DIRECTORY}") 14 | -------------------------------------------------------------------------------- /cpp/communication/cpp_interface/internal/client.h: -------------------------------------------------------------------------------- 1 | #ifndef PLOT_TOOL_CLIENT_H_ 2 | #define PLOT_TOOL_CLIENT_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "image/image.h" 18 | #include "internal/communication_functions.h" 19 | #include "internal/communication_variables.h" 20 | #include "math/math.h" 21 | 22 | namespace plot_tool 23 | { 24 | constexpr size_t max_elements_ = 2000; 25 | 26 | inline void initialize(const std::string& socket_name) 27 | { 28 | if (!getClientIsInitialized()) 29 | { 30 | const std::string socket_name_extended = "/tmp/" + socket_name; 31 | 32 | struct sockaddr_un server_addr; 33 | bzero((char*)&server_addr, sizeof(server_addr)); 34 | server_addr.sun_family = AF_UNIX; 35 | strcpy(server_addr.sun_path, socket_name_extended.c_str()); 36 | 37 | const int server_obj_length = strlen(server_addr.sun_path) + sizeof(server_addr.sun_family); 38 | if ((_Var_client_socket_handle() = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 39 | { 40 | std::cout << "Error creating socket!"; 41 | exit(-1); 42 | } 43 | setClientSocketHandle(_Var_client_socket_handle()); 44 | 45 | const int connection_successful = 46 | connect(getClientSocketHandle(), (struct sockaddr*)&server_addr, server_obj_length); 47 | 48 | if (connection_successful < 0) 49 | { 50 | std::cout << "Error connecting!"; 51 | exit(-1); 52 | } 53 | 54 | int flag = 1; 55 | setsockopt(getClientSocketHandle(), 6, TCP_NODELAY, (char*)&flag, sizeof(int)); 56 | setClientIsInitialized(true); 57 | } 58 | } 59 | 60 | inline void initialize() 61 | { 62 | initialize("socket_file"); 63 | } 64 | 65 | inline void deinitialize() 66 | { 67 | close(_Var_client_socket_handle()); 68 | } 69 | 70 | inline void sendData(const char* const buffer, const size_t num_bytes) 71 | { 72 | writeArbLenData(buffer, getClientSocketHandle(), num_bytes, max_elements_); 73 | } 74 | 75 | template