Blender  V2.93
BLI_astar.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2014 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
27 #include "BLI_utildefines.h"
28 
29 #include "BLI_bitmap.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* -------------------------------------------------------------------- */
36 
37 typedef struct BLI_AStarGNLink {
38  int nodes[2];
39  float cost;
40 
41  void *custom_data;
43 
44 typedef struct BLI_AStarGNode {
45  struct ListBase neighbor_links;
46 
47  void *custom_data;
49 
50 typedef struct BLI_AStarSolution {
51  /* Final 'most useful' data. */
54  int steps;
56  int *prev_nodes;
59 
60  void *custom_data;
61 
62  /* Mostly runtime data. */
64  float *g_costs;
65  int *g_steps;
66 
67  struct MemArena *mem; /* Memory arena. */
69 
70 typedef struct BLI_AStarGraph {
71  int node_num;
73 
74  void *custom_data;
75 
76  struct MemArena *mem; /* Memory arena. */
78 
79 void BLI_astar_node_init(BLI_AStarGraph *as_graph, const int node_index, void *custom_data);
81  const int node1_index,
82  const int node2_index,
83  const float cost,
84  void *custom_data);
85 int BLI_astar_node_link_other_node(BLI_AStarGNLink *lnk, const int idx);
86 
88  BLI_AStarSolution *as_solution,
89  void *custom_data);
92 
104 typedef float (*astar_f_cost)(BLI_AStarGraph *as_graph,
105  BLI_AStarSolution *as_solution,
106  BLI_AStarGNLink *link,
107  const int node_idx_curr,
108  const int node_idx_next,
109  const int node_idx_dst);
110 
111 void BLI_astar_graph_init(BLI_AStarGraph *as_graph, const int node_num, void *custom_data);
112 void BLI_astar_graph_free(BLI_AStarGraph *as_graph);
114  const int node_index_src,
115  const int node_index_dst,
116  astar_f_cost f_cost_cb,
117  BLI_AStarSolution *r_solution,
118  const int max_steps);
119 
120 #ifdef __cplusplus
121 }
122 #endif
typedef float(TangentPoint)[2]
void BLI_astar_graph_init(BLI_AStarGraph *as_graph, const int node_num, void *custom_data)
Definition: astar.c:178
struct BLI_AStarGNode BLI_AStarGNode
struct BLI_AStarGNLink BLI_AStarGNLink
void BLI_astar_solution_clear(BLI_AStarSolution *as_solution)
Definition: astar.c:142
struct BLI_AStarGraph BLI_AStarGraph
float(* astar_f_cost)(BLI_AStarGraph *as_graph, BLI_AStarSolution *as_solution, BLI_AStarGNLink *link, const int node_idx_curr, const int node_idx_next, const int node_idx_dst)
Definition: BLI_astar.h:104
void BLI_astar_node_init(BLI_AStarGraph *as_graph, const int node_index, void *custom_data)
Definition: astar.c:62
void BLI_astar_solution_init(BLI_AStarGraph *as_graph, BLI_AStarSolution *as_solution, void *custom_data)
Definition: astar.c:112
void BLI_astar_node_link_add(BLI_AStarGraph *as_graph, const int node1_index, const int node2_index, const float cost, void *custom_data)
Definition: astar.c:75
bool BLI_astar_graph_solve(BLI_AStarGraph *as_graph, const int node_index_src, const int node_index_dst, astar_f_cost f_cost_cb, BLI_AStarSolution *r_solution, const int max_steps)
Definition: astar.c:210
void BLI_astar_solution_free(BLI_AStarSolution *as_solution)
Definition: astar.c:162
void BLI_astar_graph_free(BLI_AStarGraph *as_graph)
Definition: astar.c:194
int BLI_astar_node_link_other_node(BLI_AStarGNLink *lnk, const int idx)
Definition: astar.c:99
struct BLI_AStarSolution BLI_AStarSolution
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
void * custom_data
Definition: BLI_astar.h:47
struct ListBase neighbor_links
Definition: BLI_astar.h:45
BLI_AStarGNode * nodes
Definition: BLI_astar.h:72
void * custom_data
Definition: BLI_astar.h:74
struct MemArena * mem
Definition: BLI_astar.h:76
BLI_AStarGNLink ** prev_links
Definition: BLI_astar.h:58
struct MemArena * mem
Definition: BLI_astar.h:67
float * g_costs
Definition: BLI_astar.h:64
void * custom_data
Definition: BLI_astar.h:60
BLI_bitmap * done_nodes
Definition: BLI_astar.h:63