Skip to content

Commit 6dc84a0

Browse files
committed
Add imgui
1 parent e406194 commit 6dc84a0

File tree

40 files changed

+715
-1595
lines changed

40 files changed

+715
-1595
lines changed

.vscode/c_cpp_properties.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/usr/include/**"
8+
],
9+
"defines": [],
10+
"compilerPath": "/usr/bin/clang-10",
11+
"cStandard": "c11",
12+
"cppStandard": "c++14",
13+
"intelliSenseMode": "linux-clang-x64"
14+
}
15+
],
16+
"version": 4
17+
}

CMakeLists.txt

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,35 @@ project(path_finding_visualizer)
33

44
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread")
55

6-
include_directories(/usr/local/include)
76
include_directories(include)
87
include_directories(include/States)
98
include_directories(include/States/Algorithms)
10-
include_directories(include/States/Algorithms/BFS)
11-
include_directories(include/States/Algorithms/DFS)
12-
include_directories(include/States/Algorithms/DIJKSTRA)
13-
include_directories(include/States/Algorithms/ASTAR)
14-
include_directories(include/States/Algorithms/RRT)
15-
include_directories(include/States/Algorithms/RRT_STAR)
9+
include_directories(include/States/Algorithms/GraphBased)
10+
include_directories(include/States/Algorithms/GraphBased/BFS)
11+
include_directories(include/States/Algorithms/GraphBased/DFS)
12+
include_directories(include/States/Algorithms/GraphBased/DIJKSTRA)
13+
include_directories(include/States/Algorithms/GraphBased/ASTAR)
1614

1715
set(EXECUTABLE_NAME "main")
1816

1917
add_executable(${EXECUTABLE_NAME}
2018
src/main.cpp
2119
src/Game.cpp
2220
src/State.cpp
23-
src/Gui.cpp
24-
src/States/Algorithms/Algorithm.cpp
25-
src/States/Algorithms/SamplingBased.cpp
26-
src/States/Algorithms/Node.cpp
21+
src/States/Algorithms/GraphBased/GraphBased.cpp
22+
src/States/Algorithms/GraphBased/Node.cpp
23+
src/States/Algorithms/GraphBased/BFS/BFS.cpp
24+
src/States/Algorithms/GraphBased/DFS/DFS.cpp
25+
src/States/Algorithms/GraphBased/DIJKSTRA/DIJKSTRA.cpp
26+
src/States/Algorithms/GraphBased/ASTAR/ASTAR.cpp
2727
)
2828

29-
add_library(main_menu
30-
src/States/MainMenu_State.cpp
31-
)
32-
33-
add_library(bfs
34-
src/States/Algorithms/BFS/BFS.cpp
35-
)
36-
37-
add_library(dfs
38-
src/States/Algorithms/DFS/DFS.cpp
39-
)
40-
41-
add_library(dijkstra
42-
src/States/Algorithms/DIJKSTRA/DIJKSTRA.cpp
43-
)
44-
45-
add_library(astar
46-
src/States/Algorithms/ASTAR/ASTAR.cpp
47-
)
48-
49-
add_library(rrt
50-
src/States/Algorithms/RRT/RRT.cpp
51-
)
52-
53-
add_library(rrt_star
54-
src/States/Algorithms/RRT_STAR/RRT_STAR.cpp
55-
)
56-
57-
# Find any version 2.X of SFML
58-
find_package(SFML 2.5.1 COMPONENTS system window graphics network audio)
5929
find_package(Boost COMPONENTS system filesystem REQUIRED)
6030

61-
include_directories(${SFML_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})
62-
63-
target_link_libraries(${EXECUTABLE_NAME}
64-
${Boost_LIBRARIES}
65-
sfml-graphics
66-
sfml-window
67-
sfml-system
31+
target_link_libraries(
32+
${EXECUTABLE_NAME}
33+
PRIVATE
34+
ImGui-SFML::ImGui-SFML
6835
)
6936

70-
target_link_libraries(${EXECUTABLE_NAME}
71-
main_menu
72-
bfs
73-
dfs
74-
dijkstra
75-
astar
76-
rrt
77-
rrt_star
78-
)
37+
add_subdirectory(dependencies)

README.md

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,28 @@
1-
2-
![](figures/img0.png)
31
# Pathfinding Visualizer
42

53
## Overview
64

7-
A tool for visualizing numerous pathfinding algorithms.
5+
A tool for visualizing numerous pathfinding algorithms in two dimensions.
86

9-
Current implementation of the project involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star, and two sampling-based planning algorithms: RRT and RRT*. The project extensively uses SFML and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
7+
This project involves minimal implementations of the popular planning algorithms, including both graph-based and sampling-based planners. We provide an easy-to-use GUI to control the animation process and explore different planner configurations. This is an ongoing work and current implementation of the project only involves four search-based planning algorithms: BFS, DFS, DIJKSTRA and A-Star. The project extensively uses SFML, ImGui and Modern C++ features such as smart pointers, lamda expressions along with multi-threading concepts.
108

11-
![](figures/img1.gif)
9+
![](figures/img0.png)
1210

1311
## How to use
1412

1513
- to place/remove obstacle cells (`left-CLICKED`)
1614
- to change starting cell (`left-SHIFT + left-CLICKED`)
1715
- to change end cell (`left-CTRL + left-CLICKED`)
1816

19-
## Dependencies
20-
21-
* cmake >= 2.8
22-
* All OSes: [click here for installation instructions](https://cmake.org/install/)
23-
* make >= 4.1 (Linux, Mac), 3.81 (Windows)
24-
* Linux: make is installed by default on most Linux distros
25-
* Mac: [install Xcode command line tools to get make](https://developer.apple.com/xcode/features/)
26-
* Windows: [Click here for installation instructions](http://gnuwin32.sourceforge.net/packages/make.htm)
27-
* SFML >= 2.5.1
28-
* All OSes: [click here for installation instructions](https://www.sfml-dev.org/tutorials/2.5/#getting-started)
29-
* Linux: Details installation instructions are provided below.
30-
* gcc/g++ >= 5.4
31-
* Linux: gcc / g++ is installed by default on most Linux distros
32-
* Mac: same deal as make - [install Xcode command line tools](https://developer.apple.com/xcode/features/)
33-
* Windows: recommend using [MinGW](http://www.mingw.org/)
34-
3517
## Basic Build Instructions
3618

19+
The project depends on [SFML](https://github.com/SFML/SFML), [Dear ImGui](https://github.com/ocornut/imgui) and [ImGui-SFML](https://github.com/eliasdaler/imgui-sfml). However, you are not required to install external dependencies by yourself. The following build instructions will manage all the necessary external dependencies for you.
20+
3721
1. Clone this repo.
3822
2. Make a build directory in the top level project directory: `mkdir build && cd build`
3923
3. Compile: `cmake .. && make`
4024
4. Run it: `./main`.
4125

42-
## SFML Installation on Linux
43-
44-
There are different approaches to the installation of SFML on Linux. For example, on Debian you would do:
45-
46-
`sudo apt-get install libsfml-dev`
47-
48-
>Please note that the minimum version of SFML required in this project is 2.5.1. and at the time of writing you can only install sfml-v2.5.1 directly from debain distribution's package repository for Ubuntu 20.04, otherwise please install it from source.
49-
50-
### SFML Installation from source
51-
52-
For Ubuntu versions less than 20.04., SFML v2.5.1. can only be installed from source. There is a linker error when attempting to compile and link a C++ program with the SFML libraries from souce. You can follow this [thread](https://en.sfml-dev.org/forums/index.php?topic=20638.0) to build SFML. I have also described the same installation instructions below.
53-
54-
1. Download the [SFML source code](https://www.sfml-dev.org/files/SFML-2.5.1-sources.zip). Unpack it. Navigate to the root directory of the unzipped source code.
55-
56-
2. Open the CMakeLists.txt file in the path */src/SFML/Graphics/CMakeLists.txt*.
57-
58-
3. Add the following lines at the end of the file.
59-
60-
```
61-
if(SFML_COMPILER_GCC AND BUILD_SHARED_LIBS)
62-
message(WARNING "Applying workaround for https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899")
63-
list(APPEND GRAPHICS_EXT_LIBS "-lgcc_s -lgcc")
64-
endif()
65-
```
66-
67-
4. Then **cd** to root dir of unpacked source.
68-
69-
5. Install with the steps below.
70-
71-
```
72-
cmake .
73-
make all
74-
sudo make install
75-
```
76-
77-
> Note that if you have errors during the `cmake` command, please read the section below which is from [official SFML documentation](https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php).
78-
79-
SFML depends on a few other libraries, so before starting to configure you must have their development files installed.
80-
81-
On Windows and macOS, all the required dependencies are provided alongside SFML so you won't have to download/install anything else. Building will work out of the box.
82-
83-
On Linux however, nothing is provided. SFML relies on you to install all of its dependencies on your own. Here is a list of what you need to install before building SFML:
84-
85-
- freetype
86-
- x11
87-
- xrandr
88-
- udev
89-
- opengl
90-
- flac
91-
- ogg
92-
- vorbis
93-
- vorbisenc
94-
- vorbisfile
95-
- openal
96-
- pthread
97-
98-
The exact name of the packages may vary from distribution to distribution. Once those packages are installed, don't forget to install their development headers as well.
99-
10026
## TODO
10127

10228
### Search-based planners
@@ -109,15 +35,18 @@ The exact name of the packages may vary from distribution to distribution. Once
10935
- [ ] LPA*
11036

11137
### Sampling-based planners
112-
- [x] RRT
38+
- [ ] RRT
11339
- [ ] RRT-Connect
114-
- [x] RRT*
40+
- [ ] RRT*
11541
- [ ] Informed-RRT*
11642
- [ ] FMT*
11743
- [ ] BIT*
11844
- [ ] ABIT*
11945
- [ ] AIT*
12046

12147
## Related Publications
48+
- [DIJKSTRA](https://ir.cwi.nl/pub/9256/9256D.pdf): A Note on Two Problems in Connexion with Graphs
49+
- [A*](https://ieeexplore.ieee.org/abstract/document/4082128?casa_token=0ltx8josfO0AAAAA:nA2z0T2qvr00C6rIhIM3Z7GhWJTQpFrYsdzpY9xc_VicZ0DZr5Q9KcclJT1215N3If6pae87MXRHHd0): A Formal Basis for the Heuristic Determination of Minimum Cost Paths
50+
- [LPA*](https://www.cs.cmu.edu/~maxim/files/aij04.pdf): Lifelong Planning A*
12251
- [RRT](https://www.cs.csustan.edu/~xliang/Courses/CS4710-21S/Papers/06%20RRT.pdf): Rapidly-exploring random trees: A new tool for path planning
12352
- [RRT*](https://journals.sagepub.com/doi/abs/10.1177/0278364911406761): Sampling-based algorithms for optimal motion planning

dependencies/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include(FetchContent)
2+
3+
FetchContent_Declare(
4+
sfml
5+
GIT_REPOSITORY "https://github.com/SFML/SFML"
6+
GIT_TAG 2f11710abc5aa478503a7ff3f9e654bd2078ebab # 2.5.1
7+
)
8+
9+
add_subdirectory(sfml)
10+
11+
FetchContent_Declare(
12+
imgui
13+
GIT_REPOSITORY https://github.com/ocornut/imgui
14+
GIT_TAG 35b1148efb839381b84de9290d9caf0b66ad7d03
15+
)
16+
17+
FetchContent_Declare(
18+
imgui-sfml
19+
GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml
20+
GIT_TAG 82dc2033e51b8323857c3ae1cf1f458b3a933c35
21+
)
22+
23+
FetchContent_MakeAvailable(imgui)
24+
add_subdirectory(imgui-sfml)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
message(STATUS "Fetching ImGui-SFML...")
2+
3+
set(IMGUI_DIR ${imgui_SOURCE_DIR})
4+
set(IMGUI_SFML_FIND_SFML OFF)
5+
set(IMGUI_SFML_IMGUI_DEMO ON)
6+
7+
FetchContent_MakeAvailable(imgui-sfml)

dependencies/sfml/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
message(STATUS "Fetching SFML...")
2+
3+
# No need to build audio and network modules
4+
set(SFML_BUILD_AUDIO FALSE)
5+
set(SFML_BUILD_NETWORK FALSE)
6+
7+
FetchContent_MakeAvailable(sfml)

figures/img0.png

-6.9 KB
Loading

figures/img1.gif

-1.47 MB
Binary file not shown.

include/Game.h

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
#pragma once
22

3-
#include "MainMenu_State.h"
3+
#include <imgui-SFML.h>
4+
#include <imgui.h>
45

5-
class Game {
6-
private:
7-
sf::RenderWindow* window_;
8-
sf::Event ev_;
9-
sf::Clock dtClock_;
10-
float dt_;
6+
#include <iostream>
7+
#include <map>
8+
#include <stack>
9+
#include <string>
10+
#include <vector>
1111

12-
// States
13-
std::stack<std::unique_ptr<State>> states_;
12+
#include "State.h"
13+
14+
namespace path_finding_visualizer {
15+
16+
static const std::vector<std::string> PLANNER_NAMES{"BFS", "DFS", "DIJKSTRA",
17+
"A*"};
18+
enum PLANNERS_IDS { BFS, DFS, DIJKSTRA, AStar };
1419

20+
class Game {
1521
public:
1622
// Constructors
17-
Game(sf::RenderWindow* window, unsigned int frameLimit);
23+
Game(sf::RenderWindow* window);
1824

1925
// Destructors
2026
virtual ~Game();
@@ -27,4 +33,17 @@ class Game {
2733
void updateDt();
2834
void update();
2935
void render();
36+
void initGuiTheme();
37+
void renderGui();
38+
void setPlanner(const int id);
39+
40+
private:
41+
sf::RenderWindow* window_;
42+
sf::Event ev_;
43+
sf::Clock dtClock_;
44+
float dt_;
45+
std::stack<std::unique_ptr<State>> states_;
46+
std::string curr_planner_;
3047
};
48+
49+
} // namespace path_finding_visualizer

0 commit comments

Comments
 (0)