route_planner_base_test.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #include <gtest/gtest.h>
8 #include <random>
9 #include "fields2cover/types.h"
12 #include "fields2cover.h"
13 
14 TEST(fields2cover_rp_route_plan_base, simple_example) {
15  f2c::Random rand(4);
16  F2CCells cells {
18  F2CPoint(0,0), F2CPoint(2,0),F2CPoint(2,2),F2CPoint(0,2), F2CPoint(0,0)
19  }))
20  };
21  cells.addRing(0, F2CLinearRing({
22  F2CPoint(.4,.4), F2CPoint(.4,.6),F2CPoint(.6,.6),F2CPoint(.6,.4), F2CPoint(.4,.4)
23  }));
24  cells.addRing(0, F2CLinearRing({
25  F2CPoint(1.2,1.2), F2CPoint(1.2,1.6),F2CPoint(1.6,1.6),F2CPoint(1.6,1.2), F2CPoint(1.2,1.2)
26  }));
27 
28  cells *= 3e1;
29 
31  F2CCells no_hl = const_hl.generateHeadlandArea(cells, 1, 3);
32  auto hl_swaths = const_hl.generateHeadlandSwaths(cells, 1, 3, false);
33 
35  decomp.setSplitAngle(M_PI/2.0);
36  auto decomp_cells = decomp.decompose(no_hl);
37 
39  F2CSwathsByCells swaths = bf.generateSwaths(M_PI/2.0, 5, decomp_cells);
40 
42  F2CRoute route = route_planner.genRoute(hl_swaths[1], swaths);
43 
44  EXPECT_FALSE(route.isEmpty());
45  EXPECT_GT(route.sizeVectorSwaths(), 1);
46  EXPECT_EQ(route.sizeVectorSwaths(), route.sizeConnections());
47 
48  /*
49  f2c::Visualizer::figure();
50  f2c::Visualizer::plot(cells);
51  //f2c::Visualizer::plot(no_hl);
52  //f2c::Visualizer::plot(hl_swaths[1]);
53  //f2c::Visualizer::plot(decomp_cells);
54  //for (auto&& c : route.getConnections())
55  f2c::Visualizer::plot(route);
56  f2c::Visualizer::show();
57  */
58 }
59 
60 TEST(fields2cover_rp_route_plan_base, redirect_flag) {
61  f2c::Random rand(4);
62  F2CCells cells {
64  F2CPoint(0,0), F2CPoint(2,0),F2CPoint(2,2),F2CPoint(0,2), F2CPoint(0,0)
65  }))
66  };
67  cells.addRing(0, F2CLinearRing({
68  F2CPoint(.4,.4), F2CPoint(.4,.6),F2CPoint(.6,.6),F2CPoint(.6,.4), F2CPoint(.4,.4)
69  }));
70  cells.addRing(0, F2CLinearRing({
71  F2CPoint(1.2,1.2), F2CPoint(1.2,1.6),F2CPoint(1.6,1.6),F2CPoint(1.6,1.2), F2CPoint(1.2,1.2)
72  }));
73 
74  cells *= 3e1;
75 
77  F2CCells no_hl = const_hl.generateHeadlandArea(cells, 1, 3);
78  auto hl_swaths = const_hl.generateHeadlandSwaths(cells, 1, 3, false);
79 
81  decomp.setSplitAngle(M_PI/2.0);
82  auto decomp_cells = decomp.decompose(no_hl);
83 
85  F2CSwathsByCells swaths = bf.generateSwaths(M_PI/2.0, 5, decomp_cells);
86 
88  F2CRoute route = route_planner.genRoute(hl_swaths[1], swaths, false, 1e-4, false);
89 
90  F2CSwaths old_swaths = swaths.flatten();
91  F2CSwaths new_swaths;
92  for (size_t sbc = 0; sbc < route.sizeVectorSwaths(); ++sbc) {
93  new_swaths.append(route.getSwaths(sbc));
94  }
95 
96  EXPECT_EQ(new_swaths.size(), old_swaths.size());
97 
98  for (size_t s = 0; s < new_swaths.size(); ++s) {
99  F2CSwath old_swath = old_swaths.at(s);
100  F2CSwath new_swath = new_swaths.at(s);
101  EXPECT_TRUE(new_swath.hasSameDir(old_swath));
102  }
103 
104  EXPECT_FALSE(route.isEmpty());
105  EXPECT_GT(route.sizeVectorSwaths(), 1);
106  EXPECT_EQ(route.sizeVectorSwaths(), route.sizeConnections());
107 
108  /*
109  f2c::Visualizer::figure();
110  f2c::Visualizer::plot(cells);
111  //f2c::Visualizer::plot(no_hl);
112  //f2c::Visualizer::plot(hl_swaths[1]);
113  //f2c::Visualizer::plot(decomp_cells);
114  //for (auto&& c : route.getConnections())
115  f2c::Visualizer::plot(route);
116  f2c::Visualizer::show();
117  */
118 }
119 
120 
121 
122 
f2c::types::Swaths::size
size_t size() const
Definition: Swaths.cpp:78
f2c::types::Swath::hasSameDir
bool hasSameDir(const Swath &s) const
Check if the difference between swaths angles is less than pi.
Definition: Swath.cpp:123
f2c::hg::ConstHL
Class to generate headlands with equal width in each border.
Definition: constant_headland.h:18
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
1_basic_types.cells
cells
Definition: 1_basic_types.py:93
types.h
TEST
TEST(fields2cover_rp_route_plan_base, simple_example)
Definition: route_planner_base_test.cpp:14
F2CCell
f2c::types::Cell F2CCell
Definition: types.h:43
7_decomposition.decomp
decomp
Definition: 7_decomposition.py:38
3_headland_generator.rand
rand
Definition: 3_headland_generator.py:11
f2c::types::Swaths::at
Swath & at(size_t i)
Definition: Swaths.cpp:70
f2c::types::Swath
Definition: Swath.h:23
fields2cover.h
5_route_planning.route
route
Definition: 5_route_planning.py:29
3_headland_generator.const_hl
const_hl
Definition: 3_headland_generator.py:17
5_route_planning.route_planner
route_planner
Definition: 5_route_planning.py:28
F2CLinearRing
f2c::types::LinearRing F2CLinearRing
Definition: types.h:41
f2c::types::Swaths::append
void append(const LineString &line, double width=0, SwathType type=SwathType::MAINLAND)
Definition: Swaths.cpp:90
f2c::types::Cells
Definition: Cells.h:21
f2c::types::Route
Definition: Route.h:23
route_planner_base.h
f2c::Random
Definition: random.h:23
3_headland_generator.no_hl
no_hl
Definition: 3_headland_generator.py:18
f2c::decomp::BoustrophedonDecomp
Boustrophedon Cellular decomposition .
Definition: boustrophedon_decomp.h:23
f2c::types::SwathsByCells
Definition: SwathsByCells.h:17
direct_dist_path_obj.h
f2c::rp::RoutePlannerBase
Definition: route_planner_base.h:23
f2c::types::Swaths
Definition: Swaths.h:20
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
5_route_planning.bf
bf
Definition: 5_route_planning.py:25
f2c::sg::BruteForce
Definition: brute_force.h:20


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31