Volume Cartographer 2.27.0
ForceChain.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <vector>
7
8#include <opencv2/core.hpp>
9
11{
13using Force = cv::Vec3d;
24{
25public:
27 using Chain = std::vector<Force>;
28
30 ForceChain() = default;
31
33 explicit ForceChain(Chain c) : data_{std::move(c)} {}
34
42 auto operator+=(const ForceChain& rhs) -> ForceChain&;
43
45 auto operator*=(const double& rhs) -> ForceChain&;
46
48 auto operator[](std::size_t i) { return data_[i]; }
49
51 auto operator[](std::size_t i) const { return data_[i]; }
52
54 auto begin() { return data_.begin(); }
55
57 auto begin() const { return data_.begin(); }
58
60 auto end() { return data_.end(); }
61
63 auto end() const { return data_.end(); }
64
66 template <class... Args>
67 void emplace_back(Args&&... args)
68 {
69 data_.emplace_back(std::forward<Args>(args)...);
70 }
71
73 void push_back(const Force& val) { data_.push_back(val); }
74
76 auto size() -> std::size_t { return data_.size(); }
77
79 auto size() const -> std::size_t { return data_.size(); }
80
82 void clear() { data_.clear(); }
83
89 static void Normalize(ForceChain& c, double alpha = 1.0);
90
91private:
94};
95
97auto operator+(ForceChain lhs, const ForceChain& rhs) -> ForceChain;
99auto operator*(ForceChain lhs, const double& rhs) -> ForceChain;
101auto operator*(const double& rhs, ForceChain lhs) -> ForceChain;
102} // namespace volcart::segmentation
A simple class for tracking a list of offset vectors ("forces")
Definition: ForceChain.hpp:24
void clear()
Empties and resets the chain.
Definition: ForceChain.hpp:82
auto operator[](std::size_t i)
Element access operator.
Definition: ForceChain.hpp:48
void push_back(const Force &val)
Adds an element to the end of the chain.
Definition: ForceChain.hpp:73
static void Normalize(ForceChain &c, double alpha=1.0)
Normalize the magnitude of each Force in the chain.
ForceChain()=default
Default constructor.
auto begin()
Returns an iterator to the beginning of the chain.
Definition: ForceChain.hpp:54
auto end()
Returns an iterator to the end of the chain.
Definition: ForceChain.hpp:60
void emplace_back(Args &&... args)
Constructs an element at the end of the chain.
Definition: ForceChain.hpp:67
auto operator*=(const double &rhs) -> ForceChain &
Multiply each element of chain by a constant scale factor.
auto size() const -> std::size_t
Returns the number of elements in the chain.
Definition: ForceChain.hpp:79
auto size() -> std::size_t
Returns the number of elements in the chain.
Definition: ForceChain.hpp:76
auto operator+=(const ForceChain &rhs) -> ForceChain &
Add a list of offset vectors to each element in the chain.
auto operator[](std::size_t i) const
Element access operator.
Definition: ForceChain.hpp:51
auto begin() const
Returns an iterator to the beginning of the chain.
Definition: ForceChain.hpp:57
auto end() const
Returns an iterator to the end of the chain.
Definition: ForceChain.hpp:63
ForceChain(Chain c)
Constructor with chain initialization.
Definition: ForceChain.hpp:33
std::vector< Force > Chain
Definition: ForceChain.hpp:27
Segmentation algorithms and utilities library
auto operator+(ForceChain lhs, const ForceChain &rhs) -> ForceChain
auto operator*(ForceChain lhs, const double &rhs) -> ForceChain