Free Electron
GenerateNav.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __ai_GenerateNav_h__
8 #define __ai_GenerateNav_h__
9 
10 #include "signal/signal.h"
11 #include "math/math.h"
12 #include "datatool/datatool.h"
13 #include "shape/shape.h"
14 #include "mobility/mobilityAS.h"
15 #include "StepCostI.h"
16 #include "aiAS.h"
17 
18 namespace fe
19 {
20 
21 /** Generate a navigation field, which is a vector field of directions to
22  get to a target destination point.
23 
24  @copydoc GenerateNav_info
25  */
26 class FE_DL_EXPORT GenerateNav :
27  public Initialize<GenerateNav>,
28  virtual public HandlerI,
29  virtual public Config
30 {
31  public:
32  GenerateNav(void);
33 virtual ~GenerateNav(void);
34 
35  void initialize(void);
36 
37  // AS HandlerI
38 virtual void handle( Record &r_sig);
39 
40  private:
41  AsNav m_asNav;
42  AsNavDebug m_asNavDebug;
43 };
44 
45 template<typename P>
46 void wavefrontPotential( Continuum<P> &a_potential,
47  sp<StepCostI> a_costFn,
48  const SpatialVector &a_target,
49  const P &a_max, const P &a_min)
50 {
51  typedef typename Continuum<P>::t_index t_index;
52  t_index target_index;
53  a_potential.index(target_index, a_target);
54 
55  a_potential.unit().safe(target_index);
56 
57 fprintf(stderr, "target %f %f %f index %d %d %d\n", a_target[0], a_target[1], a_target[2], target_index[0], target_index[1], target_index[2]);
58 
59  std::list<t_index> checklist;
60  checklist.push_back(target_index);
61 
62  a_potential.accessUnit().set(a_max);
63  a_potential.accessUnit().set(target_index, a_min);
64 
65  while(checklist.begin() != checklist.end())
66  {
67  t_index i_current;
68  i_current = checklist.front();
69  checklist.pop_front();
70 
71  std::list<t_index> neighbors;
72 
73  a_potential.accessUnit().addNeighbors(neighbors, i_current);
74 
75  bool dup = false;
76  for(typename std::list<t_index>::iterator
77  i_neighbor = neighbors.begin();
78  i_neighbor != neighbors.end(); i_neighbor++)
79  {
80  typename std::list<t_index>::iterator i_other = i_neighbor;
81  i_other++;
82  while(i_other != neighbors.end())
83  {
84  if(*i_neighbor == *i_other)
85  {
86  dup = true;
87  }
88  i_other++;
89  }
90  P dp;
91  SpatialVector current_location;
92  a_potential.location(current_location, i_current);
93  SpatialVector neighbor_location;
94  a_potential.location(neighbor_location, *i_neighbor);
95  dp = a_costFn->cost(neighbor_location, current_location);
96  P new_value = a_potential.unit()[i_current] + dp;
97  if(new_value < a_potential.unit()[*i_neighbor])
98  {
99  a_potential.accessUnit().set(*i_neighbor, new_value);
100  checklist.push_back(*i_neighbor);
101  }
102  }
103  if(dup){ feX("duplicate\n");}
104  }
105 }
106 
107 
108 } /* namespace */
109 
110 #endif /* __ai_GenerateNav_h__ */
Generate a navigation field, which is a vector field of directions to get to a target destination poi...
Definition: GenerateNav.h:26
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53