7_decomposition.py
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 import math
8 import fields2cover as f2c
9 
10 print("####### Tutorial 7.1 Why and when decompose ######")
11 
12 cells = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
13  f2c.Point( 0, 0),
14  f2c.Point( 90, 0),
15  f2c.Point( 90, 20),
16  f2c.Point( 20, 20),
17  f2c.Point( 20, 90),
18  f2c.Point( 0, 90),
19  f2c.Point( 0, 0)]))));
20 
22 f2c.Visualizer.plot(cells);
23 f2c.Visualizer.xlim(-5,95);
24 f2c.Visualizer.ylim(-5,95);
25 f2c.Visualizer.save("Tutorial_7_1_field.png");
26 
27 robot = f2c.Robot(1.0, 1.0);
28 r_w = robot.getCovWidth();
29 
30 const_hl = f2c.HG_Const_gen()
31 bf = f2c.SG_BruteForce();
32 obj = f2c.OBJ_NSwathModified();
33 
34 no_hl_wo_decomp = const_hl.generateHeadlands(cells, 3.0 * r_w);
35 swaths_wo_decomp = bf.generateBestSwaths(obj, r_w, no_hl_wo_decomp);
36 print("Without decomposition >> ", obj.computeCost(swaths_wo_decomp));
37 
38 decomp = f2c.DECOMP_TrapezoidalDecomp();
39 decomp.setSplitAngle(0.5*math.pi);
40 decomp_cell = decomp.decompose(cells);
41 
42 no_hl_decomp = const_hl.generateHeadlands(decomp_cell, 3.0 * r_w);
43 swaths_decomp = bf.generateBestSwaths(obj, r_w, no_hl_decomp);
44 print("With decomposition >> ", obj.computeCost(swaths_decomp));
45 
46 
48 f2c.Visualizer.plot(cells);
49 f2c.Visualizer.plot(no_hl_wo_decomp);
50 f2c.Visualizer.plot(swaths_wo_decomp);
51 f2c.Visualizer.xlim(-5,95);
52 f2c.Visualizer.ylim(-5,95);
53 f2c.Visualizer.save("Tutorial_7_1_without_decomposition.png");
54 
56 f2c.Visualizer.plot(decomp_cell);
57 f2c.Visualizer.plot(no_hl_decomp);
58 f2c.Visualizer.plot(swaths_decomp);
59 f2c.Visualizer.xlim(-5,95);
60 f2c.Visualizer.ylim(-5,95);
61 f2c.Visualizer.save("Tutorial_7_1_with_decomposition.png");
62 
63 print("####### Tutorial 7.2 Decomposition with route planner ######");
64 
65 mid_hl = const_hl.generateHeadlands(cells, 1.5 * r_w);
66 decomp_mid_hl = decomp.decompose(mid_hl);
67 no_hl = const_hl.generateHeadlands(decomp_mid_hl, 1.5 * r_w);
68 swaths = bf.generateBestSwaths(obj, r_w, no_hl);
69 
70 route_planner = f2c.RP_RoutePlannerBase();
71 route = route_planner.genRoute(mid_hl, swaths);
72 
74 f2c.Visualizer.plot(cells);
75 f2c.Visualizer.plot(no_hl);
76 f2c.Visualizer.plot(route);
77 f2c.Visualizer.xlim(-5,95);
78 f2c.Visualizer.ylim(-5,95);
79 f2c.Visualizer.save("Tutorial_7_2_route.png");
80 
81 
82 
f2c::Visualizer::plot
static void plot(double x, double y, const std::vector< double > &color={})
Definition: visualizer.cpp:23
f2c::Visualizer::xlim
static void xlim(double min, double max)
Definition: visualizer.cpp:280
f2c::Visualizer::figure
static void figure()
Create figure to plot on.
Definition: visualizer.cpp:254
f2c::Visualizer::save
static void save(const std::string &file)
Definition: visualizer.cpp:272
f2c::Visualizer::ylim
static void ylim(double min, double max)
Definition: visualizer.cpp:284


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