13#include <opencv2/core.hpp>
54 using Pointer = std::shared_ptr<PointSet<T>>;
64 explicit PointSet(std::size_t initSize, T initVal)
66 data_.assign(initSize, initVal);
74 assert(idx <
data_.size() &&
"idx out of range");
81 assert(idx <
data_.size() &&
"idx out of range");
108 template <
class... Args>
111 data_.emplace_back(std::forward<Args>(args)...);
115 template <
class ContainerType>
118 std::copy(std::begin(c), std::end(c), std::back_inserter(
data_));
158 throw std::range_error(
"empty PointSet");
160 return *std::min_element(
162 [](
auto lhs,
auto rhs) {
return cv::norm(lhs) < cv::norm(rhs); });
172 throw std::range_error(
"empty PointSet");
174 return *std::max_element(
176 [](
auto lhs,
auto rhs) {
return cv::norm(lhs) < cv::norm(rhs); });
187 throw std::range_error(
"empty PointSet");
189 auto pair = std::minmax_element(
191 [](
auto lhs,
auto rhs) {
return cv::norm(lhs) < cv::norm(rhs); });
192 return {*pair.first, *pair.second};
Holds a collection of points.
static PointSet Fill(std::size_t initSize, T initVal)
Create a PointSet of a specific size, filled with an initial value.
PointSet()=default
Default constructor.
void append(const ContainerType &c)
Append a PointSet to the end of the current one.
static constexpr auto HEADER_TERMINATOR
typename Container::const_iterator ConstIterator
const T & back() const
Return a reference to the last element in the PointSet.
std::vector< Point > Container
T & back()
Return a reference to the last element in the PointSet.
PointSet(std::size_t initSize)
Construct and preallocate a number of Point elements.
std::pair< T, T > minMax() const
Return a pair of elements containing the points with the smallest and largest absolute norm (L2)
T min() const
Return the element with the smallest absolute norm (L2)
static constexpr auto HEADER_TERMINATOR_REGEX
ConstIterator begin() const
Return an iterator that points to the first element in the PointSet.
ConstIterator end() const
Return an iterator that points to the past-the-end element in the PointSet.
static constexpr int FORMAT_VERSION
Container as_vector()
Get the PointSet storage container.
const T & front() const
Return a reference to the first element in the PointSet.
Iterator begin()
Return an iterator that points to the first element in the PointSet.
void push_back(const T &val)
Add a Point to the PointSet.
void emplace_back(Args &&... args)
Emplace a Point at the back of the PointSet.
const T & operator[](std::size_t idx) const
Get a Point by index.
bool empty() const
Return whether the PointSet is empty.
std::size_t size() const
Get the size of the PointSet.
typename Container::iterator Iterator
Iterator end()
Return an iterator that points to the past-the-end element in the PointSet.
T & front()
Return a reference to the first element in the PointSet.
void clear()
Remove all elements from the PointSet.
PointSet(std::size_t initSize, T initVal)
Construct and fill a number of elements with an initial value.
T & operator[](std::size_t idx)
Get a Point by index.
std::shared_ptr< PointSet< T > > Pointer
T max() const
Return the element with the largest absolute norm (L2)
Volume Cartographer library