Control Libraries 6.3.4
Loading...
Searching...
No Matches
Ellipsoid.hpp
1#pragma once
2
3#include <list>
4#include <eigen3/Eigen/Core>
5#include <eigen3/Eigen/Dense>
6#include <eigen3/Eigen/Sparse>
7#include <random>
8#include "state_representation/geometry/Shape.hpp"
9#include "state_representation/space/cartesian/CartesianPose.hpp"
10
11namespace state_representation {
15class Ellipsoid : public Shape {
16private:
17 std::vector<double> axis_lengths_;
18 double rotation_angle_;
19
20public:
24 Ellipsoid();
30 explicit Ellipsoid(const std::string& name, const std::string& reference_frame = "world");
31
36 Ellipsoid(const Ellipsoid& ellipsoid);
37
43 Ellipsoid& operator=(const Ellipsoid& state);
44
49 const std::vector<double>& get_axis_lengths() const;
50
56 double get_axis_length(unsigned int index) const;
57
62 void set_axis_lengths(const std::vector<double>& axis_lengths);
63
69 void set_axis_lengths(unsigned int index, double axis_length);
70
75 double get_rotation_angle() const;
76
81 void set_rotation_angle(double rotation_angle);
82
83 const CartesianPose get_rotation() const;
84
90 const std::list<CartesianPose> sample_from_parameterization(unsigned int nb_samples) const;
91
97 const std::string& name, const std::vector<double>& coefficients, const std::string& reference_frame = "world"
98 );
99
106 static const Ellipsoid fit(
107 const std::string& name, const std::list<CartesianPose>& points, const std::string& reference_frame = "world",
108 double noise_level = 0.01
109 );
110
115 const std::vector<double> to_std_vector() const;
116
121 virtual void set_data(const Eigen::VectorXd& data) override;
122
127 virtual void set_data(const std::vector<double>& data) override;
128
135 friend std::ostream& operator<<(std::ostream& os, const Ellipsoid& ellipsoid);
136};
137
139 Shape::operator=(state);
140 this->set_axis_lengths(state.get_axis_lengths());
142 return (*this);
143}
144
145inline const std::vector<double>& Ellipsoid::get_axis_lengths() const {
146 return this->axis_lengths_;
147}
148
149inline double Ellipsoid::get_axis_length(unsigned int index) const {
150 return this->axis_lengths_[index];
151}
152
153inline void Ellipsoid::set_axis_lengths(const std::vector<double>& axis_lengths) {
154 this->axis_lengths_ = axis_lengths;
155 this->set_filled();
156}
157
158inline void Ellipsoid::set_axis_lengths(unsigned int index, double axis_length) {
159 this->axis_lengths_[index] = axis_length;
160 this->set_filled();
161}
162
163inline double Ellipsoid::get_rotation_angle() const {
164 return this->rotation_angle_;
165}
166
167inline void Ellipsoid::set_rotation_angle(double rotation_angle) {
168 this->rotation_angle_ = rotation_angle;
169 this->set_filled();
170}
171
172inline const std::vector<double> Ellipsoid::to_std_vector() const {
173 if (this->get_center_state().is_empty()) {
174 throw exceptions::EmptyStateException("The center state of the Ellipsoid is not set yet.");
175 }
176 std::vector<double> representation(6);
177 // position
178 representation[0] = this->get_center_position()(0);
179 representation[1] = this->get_center_position()(1);
180 representation[2] = this->get_center_position()(2);
181 // rotation angle
182 representation[3] = this->get_rotation_angle();
183 // axis lengths
184 representation[4] = this->get_axis_length(0);
185 representation[5] = this->get_axis_length(1);
186 return representation;
187}
188
189inline const CartesianPose Ellipsoid::get_rotation() const {
190 if (this->get_center_state().is_empty()) {
191 throw exceptions::EmptyStateException("The center state of the Ellipsoid is not set yet.");
192 }
193 Eigen::Quaterniond rotation(Eigen::AngleAxisd(this->rotation_angle_, Eigen::Vector3d::UnitZ()));
194 return CartesianPose(
195 this->get_center_pose().get_name() + "_rotated", Eigen::Vector3d::Zero(), rotation,
196 this->get_center_pose().get_name());
197}
198}
Class to define CartesianPose in cartesian space as 3D position and quaternion based orientation.
virtual void set_data(const Eigen::VectorXd &data) override
Set the ellipsoid data from an Eigen vector.
Definition: Ellipsoid.cpp:168
Ellipsoid & operator=(const Ellipsoid &state)
Copy assignment operator that have to be defined to the custom assignment operator.
Definition: Ellipsoid.hpp:138
void set_rotation_angle(double rotation_angle)
Setter of the rotation angle.
Definition: Ellipsoid.hpp:167
double get_axis_length(unsigned int index) const
Getter of the axis length in one direction.
Definition: Ellipsoid.hpp:149
static const Ellipsoid from_algebraic_equation(const std::string &name, const std::vector< double > &coefficients, const std::string &reference_frame="world")
Compute an ellipsoid from its algebraic equation ax2 + bxy + cy2 + cx + ey + f.
Definition: Ellipsoid.cpp:39
const std::list< CartesianPose > sample_from_parameterization(unsigned int nb_samples) const
Function to sample an obstacle from its parameterization.
Definition: Ellipsoid.cpp:18
void set_axis_lengths(const std::vector< double > &axis_lengths)
Setter of the axis lengths.
Definition: Ellipsoid.hpp:153
double get_rotation_angle() const
Getter of the rotation angle.
Definition: Ellipsoid.hpp:163
const std::vector< double > to_std_vector() const
Convert the ellipse to an std vector representation of its parameter.
Definition: Ellipsoid.hpp:172
Ellipsoid()
Empty constructor.
Definition: Ellipsoid.cpp:8
const std::vector< double > & get_axis_lengths() const
Getter of the axis lengths.
Definition: Ellipsoid.hpp:145
friend std::ostream & operator<<(std::ostream &os, const Ellipsoid &ellipsoid)
Overload the ostream operator for printing.
Definition: Ellipsoid.cpp:185
static const Ellipsoid fit(const std::string &name, const std::list< CartesianPose > &points, const std::string &reference_frame="world", double noise_level=0.01)
Fit an ellipsoid on a set of points This method uses direct least square fitting from Fitzgibbon,...
Definition: Ellipsoid.cpp:85
Shape & operator=(const Shape &state)
Copy assignment operator that have to be defined to the custom assignment operator.
Definition: Shape.hpp:111
const Eigen::Vector3d get_center_position() const
Getter of the position from the state.
Definition: Shape.hpp:125
const CartesianState & get_center_state() const
Getter of the state.
Definition: Shape.hpp:117
const CartesianPose & get_center_pose() const
Getter of the pose from the state.
Definition: Shape.hpp:121
const std::string & get_name() const
Getter of the name as const reference.
Definition: State.cpp:48
void set_filled()
Setter of the empty attribute to false and also reset the timestamp.
Definition: State.cpp:31
bool is_empty() const
Getter of the empty attribute.
Definition: State.cpp:23
Core state variables and objects.