Control Libraries 7.4.0
Loading...
Searching...
No Matches
Shape.cpp
1#include "state_representation/geometry/Shape.hpp"
2
3#include "state_representation/exceptions/EmptyStateException.hpp"
4#include "state_representation/exceptions/IncompatibleReferenceFramesException.hpp"
5
6namespace state_representation {
7
8Shape::Shape() : State(), center_state_(CartesianState::Identity("")) {
9 this->set_type(StateType::GEOMETRY_SHAPE);
10}
11
12Shape::Shape(const std::string& name, const std::string& reference_frame) :
13 State(name), center_state_(CartesianState::Identity(name, reference_frame)) {
14 this->set_type(StateType::GEOMETRY_SHAPE);
15}
16
17Shape::Shape(const Shape& shape) : Shape(shape.get_name()) {
18 if (shape) {
20 }
21}
22
23Shape Shape::Unit(const std::string& name, const std::string& reference_frame) {
24 Shape unit = Shape(name, reference_frame);
25 unit.set_empty(false);
26 return unit;
27}
28
30 Shape tmp(state);
31 swap(*this, tmp);
32 return *this;
33}
34
36 this->assert_not_empty();
37 return this->center_state_;
38}
39
41 this->assert_not_empty();
42 return static_cast<const CartesianPose&>(this->center_state_);
43}
44
45const Eigen::Vector3d Shape::get_center_position() const {
46 this->assert_not_empty();
47 return this->center_state_.get_position();
48}
49
50const Eigen::Quaterniond Shape::get_center_orientation() const {
51 this->assert_not_empty();
52 return this->center_state_.get_orientation();
53}
54
56 this->assert_not_empty();
57 return static_cast<const CartesianTwist&>(this->center_state_);
58}
59
61 if (state.is_empty()) {
62 throw exceptions::EmptyStateException(state.get_name() + " state is empty");
63 }
64 this->center_state_ = state;
65 this->set_empty(false);
66}
67
69 if (this->center_state_.get_reference_frame() != pose.get_reference_frame()) {
71 "The shape state and the given pose are not expressed in the same reference frame");
72 }
73 this->center_state_.set_pose(pose.get_position(), pose.get_orientation());
74 this->set_empty(false);
75}
76
77void Shape::set_center_position(const Eigen::Vector3d& position) {
78 this->center_state_.set_position(position);
79 this->set_empty(false);
80}
81
82void Shape::set_center_orientation(const Eigen::Quaterniond& orientation) {
83 this->center_state_.set_orientation(orientation);
84 this->set_empty(false);
85}
86
87std::string Shape::to_string() const {
88 std::stringstream s;
89 s << this->State::to_string();
90 if (this->is_empty()) {
91 return s.str();
92 }
93 s << std::endl << "state:" << std::endl;
94 s << this->get_center_state();
95 return s.str();
96}
97
98std::ostream& operator<<(std::ostream& os, const Shape& shape) {
99 os << shape.to_string();
100 return os;
101}
102}// namespace state_representation
Class to define Cartesian pose in Cartesian space as 3D position and quaternion based orientation.
Class to represent a state in Cartesian space.
void set_orientation(const Eigen::Quaterniond &orientation)
Setter of the orientation.
const Eigen::Vector3d & get_position() const
Getter of the position attribute.
void set_position(const Eigen::Vector3d &position)
Setter of the position.
const Eigen::Quaterniond & get_orientation() const
Getter of the orientation attribute.
void set_pose(const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
Setter of the pose from both position and orientation.
Class to define twist in Cartesian space as 3D linear and angular velocity vectors.
void set_center_orientation(const Eigen::Quaterniond &orientation)
Setter of the pose.
Definition Shape.cpp:82
void set_center_state(const CartesianState &state)
Setter of the state.
Definition Shape.cpp:60
friend void swap(Shape &state1, Shape &state2)
Swap the values of the two Shapes.
Definition Shape.hpp:125
Shape & operator=(const Shape &state)
Copy assignment operator that has to be defined to the custom assignment operator.
Definition Shape.cpp:29
static Shape Unit(const std::string &name, const std::string &reference_frame="world")
Constructor for a Shape with identity state.
Definition Shape.cpp:23
Shape()
Empty constructor.
Definition Shape.cpp:8
const Eigen::Vector3d get_center_position() const
Getter of the position from the state.
Definition Shape.cpp:45
std::string to_string() const override
Convert the state to its string representation.
Definition Shape.cpp:87
const CartesianState & get_center_state() const
Getter of the state.
Definition Shape.cpp:35
const CartesianPose & get_center_pose() const
Getter of the pose from the state.
Definition Shape.cpp:40
const Eigen::Quaterniond get_center_orientation() const
Getter of the orientation from the state.
Definition Shape.cpp:50
void set_center_pose(const CartesianPose &pose)
Setter of the pose.
Definition Shape.cpp:68
void set_center_position(const Eigen::Vector3d &position)
Setter of the position.
Definition Shape.cpp:77
const CartesianTwist & get_center_twist() const
Getter of the twist from the state.
Definition Shape.cpp:55
const std::string & get_reference_frame() const
Getter of the reference frame as const reference.
Abstract class to represent a state.
Definition State.hpp:25
void set_type(const StateType &type)
Setter of the state type attribute.
Definition State.cpp:41
virtual std::string to_string() const
Convert the state to its string representation.
Definition State.cpp:99
void assert_not_empty() const
Throw an exception if the state is empty.
Definition State.cpp:55
bool is_empty() const
Getter of the empty attribute.
Definition State.cpp:33
void set_empty(bool empty=true)
Setter of the empty attribute.
Definition State.cpp:50
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const AnalogIOState &state)