Skip to content

Commit c9a723f

Browse files
committed
Major updates to the visualizer
- Integrate ImGui docking - Improve UI - Window and panels can now be resizable and fullscreen - Refactor graph and sampling-based classes
1 parent ed5bab5 commit c9a723f

File tree

25 files changed

+528
-525
lines changed

25 files changed

+528
-525
lines changed

dependencies/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ add_subdirectory(sfml)
1111
FetchContent_Declare(
1212
imgui
1313
GIT_REPOSITORY https://github.com/ocornut/imgui
14-
GIT_TAG 55d35d8387c15bf0cfd71861df67af8cfbda7456
14+
# GIT_TAG 55d35d8387c15bf0cfd71861df67af8cfbda7456
15+
GIT_TAG 719d9313041b85227a3e6deb289a313819aaeab3 # latest commit of docking-branch
1516
)
1617

1718
FetchContent_Declare(

include/Game.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum SAMPLING_BASED_PLANNERS_IDS { RRT, RRT_STAR };
2222
class Game {
2323
public:
2424
// Constructors
25-
Game(sf::RenderWindow* window);
25+
Game(sf::RenderWindow* window, sf::RenderTexture* render_texture);
2626

2727
// Destructors
2828
virtual ~Game();
@@ -44,6 +44,9 @@ class Game {
4444

4545
private:
4646
sf::RenderWindow* window_;
47+
sf::RenderTexture* render_texture_;
48+
sf::Vector2f view_move_xy_;
49+
ImVec2 mouse_pos_in_canvas_;
4750
sf::Event ev_;
4851
sf::Clock dtClock_;
4952
float dt_;

include/State.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,29 @@ namespace path_finding_visualizer {
2222
class State {
2323
private:
2424
protected:
25-
std::stack<std::unique_ptr<State>> &states_;
26-
sf::RenderWindow *window_;
2725
std::shared_ptr<LoggerPanel> logger_panel_;
28-
sf::Vector2i mousePositionWindow_;
29-
bool quit_;
26+
sf::Vector2f mousePositionWindow_;
3027
bool is_reset_;
3128
bool is_running_;
3229

3330
public:
3431
// Constructor
35-
State(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states,
36-
std::shared_ptr<LoggerPanel> logger_panel);
32+
State(std::shared_ptr<LoggerPanel> logger_panel);
3733

3834
// Destructor
3935
virtual ~State();
4036

41-
// Accessors
42-
const bool getQuit() const;
43-
4437
void setReset(bool is_reset) { is_reset_ = is_reset; }
4538
void setRunning(bool is_running) { is_running_ = is_running; }
4639

4740
// Functions
48-
virtual void checkForQuit();
49-
virtual void updateMousePosition();
41+
void updateMousePosition(const ImVec2 &mousePos);
5042

5143
// virtual functions
5244
virtual void endState() = 0;
53-
virtual void updateKeybinds() = 0;
54-
virtual void update(const float &dt) = 0;
55-
virtual void render() = 0;
45+
virtual void update(const float &dt, const ImVec2 &mousePos) = 0;
46+
virtual void renderConfig() = 0;
47+
virtual void renderScene(sf::RenderTexture &render_texture) = 0;
5648
};
5749

5850
} // namespace path_finding_visualizer

include/States/Algorithms/GraphBased/ASTAR/ASTAR.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ struct MinimumDistanceASTAR {
2121
class ASTAR : public BFS {
2222
public:
2323
// Constructor
24-
ASTAR(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states,
25-
std::shared_ptr<LoggerPanel> logger_panel);
24+
ASTAR(std::shared_ptr<LoggerPanel> logger_panel);
2625

2726
// Destructor
2827
virtual ~ASTAR();
2928

3029
// Overriden functions
3130
virtual void initAlgorithm() override;
32-
virtual void solveConcurrently(
33-
std::shared_ptr<Node> nodeStart, std::shared_ptr<Node> nodeEnd,
34-
std::shared_ptr<MessageQueue<bool>> message_queue) override;
31+
32+
// override main update function
33+
virtual void updatePlanner(bool &solved, Node &start_node,
34+
Node &end_node) override;
3535

3636
protected:
3737
// ASTAR related

include/States/Algorithms/GraphBased/BFS/BFS.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace graph_based {
1111
class BFS : public GraphBased {
1212
public:
1313
// Constructor
14-
BFS(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states,
15-
std::shared_ptr<LoggerPanel> logger_panel);
14+
BFS(std::shared_ptr<LoggerPanel> logger_panel);
1615

1716
// Destructor
1817
virtual ~BFS();
@@ -24,13 +23,12 @@ class BFS : public GraphBased {
2423
virtual void updateNodes() override;
2524

2625
// override render functions
27-
virtual void renderNodes() override;
26+
virtual void renderNodes(sf::RenderTexture &render_texture) override;
2827
virtual void renderParametersGui() override;
2928

30-
// BFS algorithm function
31-
virtual void solveConcurrently(
32-
std::shared_ptr<Node> nodeStart, std::shared_ptr<Node> nodeEnd,
33-
std::shared_ptr<MessageQueue<bool>> message_queue) override;
29+
// override main update function
30+
virtual void updatePlanner(bool &solved, Node &start_node,
31+
Node &end_node) override;
3432

3533
private:
3634
// BFS related

include/States/Algorithms/GraphBased/DFS/DFS.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ namespace graph_based {
1010
class DFS : public BFS {
1111
public:
1212
// Constructor
13-
DFS(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states,
14-
std::shared_ptr<LoggerPanel> logger_panel);
13+
DFS(std::shared_ptr<LoggerPanel> logger_panel);
1514

1615
// Destructor
1716
virtual ~DFS();
1817

1918
// override initialization Functions
2019
void initAlgorithm() override;
2120

22-
// DFS algorithm function
23-
void solveConcurrently(
24-
std::shared_ptr<Node> nodeStart, std::shared_ptr<Node> nodeEnd,
25-
std::shared_ptr<MessageQueue<bool>> message_queue) override;
21+
// override main update function
22+
virtual void updatePlanner(bool &solved, Node &start_node,
23+
Node &end_node) override;
2624

2725
private:
2826
// DFS related

include/States/Algorithms/GraphBased/DIJKSTRA/DIJKSTRA.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ struct MinimumDistanceDIJKSTRA {
2121
class DIJKSTRA : public BFS {
2222
public:
2323
// Constructor
24-
DIJKSTRA(sf::RenderWindow *window, std::stack<std::unique_ptr<State>> &states,
25-
std::shared_ptr<LoggerPanel> logger_panel);
24+
DIJKSTRA(std::shared_ptr<LoggerPanel> logger_panel);
2625

2726
// Destructor
2827
virtual ~DIJKSTRA();
2928

3029
// Overriden functions
3130
virtual void initAlgorithm() override;
32-
void solveConcurrently(
33-
std::shared_ptr<Node> nodeStart, std::shared_ptr<Node> nodeEnd,
34-
std::shared_ptr<MessageQueue<bool>> message_queue) override;
31+
32+
// override main update function
33+
virtual void updatePlanner(bool &solved, Node &start_node,
34+
Node &end_node) override;
3535

3636
protected:
3737
// DIJKSTRA related

include/States/Algorithms/GraphBased/GraphBased.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,41 @@ namespace graph_based {
2222
class GraphBased : public State {
2323
public:
2424
// Constructor
25-
GraphBased(sf::RenderWindow* window,
26-
std::stack<std::unique_ptr<State>>& states,
27-
std::shared_ptr<LoggerPanel> logger_panel);
25+
GraphBased(std::shared_ptr<LoggerPanel> logger_panel);
2826

2927
// Destructor
3028
virtual ~GraphBased();
3129

3230
// Override Functions
3331
void endState() override;
34-
void updateKeybinds() override;
35-
void update(const float& dt) override;
36-
void render() override;
32+
void update(const float& dt, const ImVec2& mousePos) override;
33+
void renderConfig() override;
34+
void renderScene(sf::RenderTexture& render_texture) override;
3735

3836
// virtual functions
3937
virtual void clearObstacles();
4038
virtual void renderGui();
4139
// render planner specific parameters
4240
virtual void renderParametersGui() = 0;
43-
virtual void renderNodes() = 0;
41+
virtual void renderNodes(sf::RenderTexture& render_texture) = 0;
4442
virtual void updateNodes() = 0;
4543
virtual void initAlgorithm() = 0;
46-
virtual void solveConcurrently(
47-
std::shared_ptr<Node> nodeStart, std::shared_ptr<Node> nodeEnd,
48-
std::shared_ptr<MessageQueue<bool>> message_queue) = 0;
44+
// pure virtual function need to be implemented by graph-based planners
45+
virtual void updatePlanner(bool& solved, Node& node_start,
46+
Node& node_end) = 0;
47+
48+
void solveConcurrently(std::shared_ptr<Node> nodeStart,
49+
std::shared_ptr<Node> nodeEnd,
50+
std::shared_ptr<MessageQueue<bool>> message_queue);
51+
void updateKeyTime(const float& dt);
52+
const bool getKeyTime();
4953

5054
protected:
55+
// initialization Functions
56+
void initColors();
57+
void initVariables();
58+
void initNodes(bool reset = true, bool reset_neighbours_only = false);
59+
5160
// colors
5261
sf::Color BGN_COL, FONT_COL, IDLE_COL, HOVER_COL, ACTIVE_COL, START_COL,
5362
END_COL, VISITED_COL, FRONTIER_COL, OBST_COL, PATH_COL;
@@ -57,8 +66,11 @@ class GraphBased : public State {
5766
float keyTimeMax_;
5867

5968
// Map Variables
69+
int no_of_grid_rows_;
70+
int no_of_grid_cols_;
6071
int gridSize_;
6172
int slider_grid_size_;
73+
sf::Vector2f init_grid_xy_;
6274
// 0 = 4 connected grid, 1 = 8 connected grid
6375
int grid_connectivity_;
6476
unsigned int mapWidth_;
@@ -82,14 +94,6 @@ class GraphBased : public State {
8294
// threads
8395
std::thread t_;
8496
bool thread_joined_;
85-
86-
// initialization Functions
87-
void initColors();
88-
void initVariables();
89-
void initNodes(bool reset = true, bool reset_neighbours_only = false);
90-
91-
void updateKeyTime(const float& dt);
92-
const bool getKeyTime();
9397
};
9498

9599
} // namespace graph_based

include/States/Algorithms/GraphBased/Node.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ namespace path_finding_visualizer {
1010
namespace graph_based {
1111

1212
class Node {
13-
private:
14-
// Variables
15-
bool isObstacle_;
16-
bool isVisited_;
17-
bool isFrontier_;
18-
bool isPath_;
19-
sf::Vector2i pos_;
20-
std::vector<std::shared_ptr<Node>> vecNeighbours_;
21-
std::shared_ptr<Node> parent_;
22-
double gDist_;
23-
double fDist_;
24-
2513
public:
2614
// Constructor
2715
Node();
@@ -34,9 +22,11 @@ class Node {
3422
const bool isVisited() const;
3523
const bool isFrontier() const;
3624
const bool isPath() const;
25+
const bool isStart() const;
26+
const bool isGoal() const;
3727

3828
// Accessors
39-
sf::Vector2i getPos();
29+
sf::Vector2i getPos() const;
4030
std::shared_ptr<Node> getParentNode();
4131
const std::vector<std::shared_ptr<Node>>* getNeighbours() const;
4232
const double getGDistance() const;
@@ -47,12 +37,28 @@ class Node {
4737
void setVisited(bool b);
4838
void setFrontier(bool b);
4939
void setPath(bool b);
40+
void setStart(bool b);
41+
void setGoal(bool b);
5042
void setPosition(sf::Vector2i pos);
5143
void setNeighbours(std::shared_ptr<Node> node);
5244
void clearNeighbours();
5345
void setParentNode(std::shared_ptr<Node> node);
5446
void setGDistance(double dist);
5547
void setFDistance(double dist);
48+
49+
protected:
50+
// Variables
51+
bool isObstacle_;
52+
bool isVisited_;
53+
bool isFrontier_;
54+
bool isPath_;
55+
bool isStart_;
56+
bool isGoal_;
57+
sf::Vector2i pos_;
58+
std::vector<std::shared_ptr<Node>> vecNeighbours_;
59+
std::shared_ptr<Node> parent_;
60+
double gDist_;
61+
double fDist_;
5662
};
5763

5864
} // namespace graph_based

include/States/Algorithms/GraphBased/Utils.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ namespace path_finding_visualizer {
88
namespace graph_based {
99
namespace utils {
1010

11-
inline double distanceCost(const std::shared_ptr<Node> &n1,
12-
const std::shared_ptr<Node> &n2) {
11+
inline double distanceCost(const Node &n1, const Node &n2) {
1312
return std::sqrt(
14-
(n1->getPos().x - n2->getPos().x) * (n1->getPos().x - n2->getPos().x) +
15-
(n1->getPos().y - n2->getPos().y) * (n1->getPos().y - n2->getPos().y));
13+
(n1.getPos().x - n2.getPos().x) * (n1.getPos().x - n2.getPos().x) +
14+
(n1.getPos().y - n2.getPos().y) * (n1.getPos().y - n2.getPos().y));
1615
}
1716

18-
inline double costToGoHeuristics(const std::shared_ptr<Node> &n1,
19-
const std::shared_ptr<Node> &n2,
17+
inline double costToGoHeuristics(const Node &n1, const Node &n2,
2018
bool use_manhattan = false) {
2119
if (use_manhattan)
22-
return fabs(n1->getPos().x - n2->getPos().x) +
23-
fabs(n1->getPos().y - n2->getPos().y);
20+
return fabs(n1.getPos().x - n2.getPos().x) +
21+
fabs(n1.getPos().y - n2.getPos().y);
2422

2523
return std::sqrt(
26-
(n1->getPos().x - n2->getPos().x) * (n1->getPos().x - n2->getPos().x) +
27-
(n1->getPos().y - n2->getPos().y) * (n1->getPos().y - n2->getPos().y));
24+
(n1.getPos().x - n2.getPos().x) * (n1.getPos().x - n2.getPos().x) +
25+
(n1.getPos().y - n2.getPos().y) * (n1.getPos().y - n2.getPos().y));
2826
}
2927

3028
inline void addNeighbours(std::vector<std::shared_ptr<Node>> &nodes,

0 commit comments

Comments
 (0)