21 VIPRA_MODULE_NAME(
"PotentialField")
22 VIPRA_MODULE_TYPE(Goals)
24 VIPRA_REGISTER_PARAMS(VIPRA_PARAM(
"endGoalType", _endGoalType),
25 VIPRA_PARAM(
"cellSize", _cellSize),
26 VIPRA_PARAM(
"densityUpdateFrequency", _densityUpdateFrequency),
27 VIPRA_PARAM(
"densityCellSize", _densityCellSize),
28 VIPRA_PARAM(
"densityWeight", _densityWeight))
35 _field.intialize(map, _cellSize);
36 _densityMap.intialize(map, _densityCellSize);
39 for ( VIPRA::idx pedIdx = 0; pedIdx < pedset.num_pedestrians(); ++pedIdx ) {
41 auto const& grid = _field.get_grid(pos);
43 if ( grid.end == _emptyf3d_ )
45 "No path found for pedestrian {}, Start: ({}, {}), End: ({}, {})", pedIdx,
46 pos.x, pos.y, end_goal(pedIdx).x, end_goal(pedIdx).y);
48 set_current_goal(pedIdx, pos + grid.direction);
49 set_end_goal(pedIdx, grid.end);
54 VIPRA_GOALS_UPDATE_STEP
56 _densityCheckCounter++;
60 if ( _densityCheckCounter >= _densityUpdateFrequency ) {
63 for ( VIPRA::idx pedIdx = 0; pedIdx < pedset.num_pedestrians(); ++pedIdx ) {
65 VIPRA::f3d direction = _field.get_grid(pos).direction;
67 set_current_goal(pedIdx, pos + direction);
68 update_ped_density(pos);
71 _densityMap.clear_grid();
73 _densityCheckCounter = 0;
77 for ( VIPRA::idx pedIdx = 0; pedIdx < pedset.num_pedestrians(); ++pedIdx ) {
79 VIPRA::f3d direction = _field.get_grid(pos).direction;
81 set_current_goal(pedIdx, pos + direction);
86 VIPRA_GOALS_NEXT_GOAL {
return false; }
89 VIPRA_GOALS_CHANGE_GOAL
91 throw std::runtime_error(
"Potential Field Goals is unable to change goals");
99 int _densityCheckCounter;
101 VIPRA::f_pnt _cellSize{};
102 VIPRA::f_pnt _densityCellSize{};
103 VIPRA::f_pnt _densityWeight{};
105 std::string _endGoalType;
106 int _densityUpdateFrequency;
110 auto const& objectives = map.get_objectives(_endGoalType);
111 if ( objectives.empty() ) {
112 throw std::runtime_error(
"No objectives of type " + _endGoalType +
" found in map");
115 for (
auto const& objective : objectives ) {
116 _field.flood_fill(objective.center(), map, _densityMap);