SwathsByCells.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 
8 #include <algorithm>
9 #include <numeric>
10 
11 namespace f2c::types {
12 
14 SwathsByCells::SwathsByCells(int i) : data_(i) {}
15 
16 SwathsByCells::SwathsByCells(const std::initializer_list<Swaths>& v_s) {
17  for (const auto& s : v_s) {
18  emplace_back(s);
19  }
20 }
21 
22 SwathsByCells::SwathsByCells(const std::vector<Swaths>& v_s) {
23  for (const auto& s : v_s) {
24  emplace_back(s);
25  }
26 }
27 
29 
31  this->data_.emplace_back(s);
32 }
33 
35  this->data_.push_back(s);
36 }
37 
38 std::vector<Swaths>::iterator SwathsByCells::begin() {
39  return this->data_.begin();
40 }
41 
42 std::vector<Swaths>::iterator SwathsByCells::end() {
43  return this->data_.end();
44 }
45 
46 std::vector<Swaths>::const_iterator SwathsByCells::begin() const {
47  return this->data_.begin();
48 }
49 
50 std::vector<Swaths>::const_iterator SwathsByCells::end() const {
51  return this->data_.end();
52 }
53 
55  std::reverse(this->data_.begin(), this->data_.end());
56 }
57 
59  return this->data_.back();
60 }
61 
62 const Swaths& SwathsByCells::back() const {
63  return this->data_.back();
64 }
65 
67  return this->data_.at(i);
68 }
69 
70 const Swaths& SwathsByCells::at(size_t i) const {
71  return this->data_.at(i);
72 }
73 
75  size_t j {0};
76  auto size_s = this->data_.at(j).size();
77  while (i >= size_s) {
78  i -= size_s;
79  ++j;
80  size_s = this->data_.at(j).size();
81  }
82  return this->data_.at(j).at(i);
83 }
84 
85 const Swath& SwathsByCells::getSwath(size_t i) const {
86  size_t j {0};
87  auto size_s = this->data_.at(j).size();
88  while (i >= size_s) {
89  i -= size_s;
90  ++j;
91  size_s = this->data_.at(j).size();
92  }
93  return this->data_.at(j).at(i);
94 }
95 
96 size_t SwathsByCells::size() const {
97  return this->data_.size();
98 }
99 
100 size_t SwathsByCells::sizeTotal() const {
101  return std::accumulate(
102  this->data_.begin(), this->data_.end(), 0,
103  [](size_t a, const Swaths& b) {return a + b.size();});
104 }
105 
107  return this->data_[i];
108 }
109 
110 const Swaths& SwathsByCells::operator[] (int i) const {
111  return this->data_[i];
112 }
113 
115  SwathsByCells sbc;
116  for (auto&& s : this->data_) {
117  sbc.emplace_back(s.clone());
118  }
119  return sbc;
120 }
121 
123  Swaths swaths;
124  for (auto&& s : *this) {
125  swaths.append(s);
126  }
127  return swaths;
128 }
129 
130 
131 } // namespace f2c::types
132 
f2c::types::SwathsByCells::begin
std::vector< Swaths >::iterator begin()
Definition: SwathsByCells.cpp:38
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::SwathsByCells::back
Swaths & back()
Definition: SwathsByCells.cpp:58
f2c::types::SwathsByCells::at
Swaths & at(size_t i)
Definition: SwathsByCells.cpp:66
f2c::types::SwathsByCells::flatten
Swaths flatten() const
Definition: SwathsByCells.cpp:122
f2c::types::SwathsByCells::push_back
void push_back(const Swaths &s)
Definition: SwathsByCells.cpp:34
f2c::types::Swath
Definition: Swath.h:23
f2c::types::SwathsByCells::sizeTotal
size_t sizeTotal() const
Definition: SwathsByCells.cpp:100
f2c::types::SwathsByCells::reverse
void reverse()
Definition: SwathsByCells.cpp:54
f2c::types::SwathsByCells::SwathsByCells
SwathsByCells()
SwathsByCells.h
f2c::types::SwathsByCells::getSwath
Swath & getSwath(size_t i)
Definition: SwathsByCells.cpp:74
f2c::types::SwathsByCells::~SwathsByCells
~SwathsByCells()
f2c::types::SwathsByCells::operator[]
Swaths & operator[](int i)
Definition: SwathsByCells.cpp:106
f2c::types::SwathsByCells::data_
std::vector< Swaths > data_
Definition: SwathsByCells.h:55
f2c::types::SwathsByCells::size
size_t size() const
Definition: SwathsByCells.cpp:96
f2c::types::SwathsByCells::end
std::vector< Swaths >::iterator end()
Definition: SwathsByCells.cpp:42
f2c::types::SwathsByCells
Definition: SwathsByCells.h:17
f2c::types::SwathsByCells::emplace_back
void emplace_back(const Swaths &s)
Definition: SwathsByCells.cpp:30
f2c::types::Swaths
Definition: Swaths.h:20
f2c::types::SwathsByCells::clone
SwathsByCells clone() const
Definition: SwathsByCells.cpp:114


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