Directory: | ./ |
---|---|
File: | include/parametric-curves/spatial/force-curve.hpp |
Date: | 2025-04-07 13:04:42 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 2 | 56 | 3.6% |
Branches: | 3 | 66 | 4.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * \file exact_cubic.h | ||
3 | * \brief class allowing to create an Exact cubic spline. | ||
4 | * \author Rohan Budhiraja | ||
5 | * \version 0.1 | ||
6 | * \date 09/11/2017 | ||
7 | * | ||
8 | * This file contains representation of spatial vectors as splines | ||
9 | */ | ||
10 | |||
11 | #ifndef _parameteric_curves_force_curve_hpp | ||
12 | #define _parameteric_curves_force_curve_hpp | ||
13 | |||
14 | #include <boost/archive/text_iarchive.hpp> | ||
15 | #include <boost/archive/text_oarchive.hpp> | ||
16 | #include <boost/serialization/split_member.hpp> | ||
17 | #include <boost/serialization/vector.hpp> | ||
18 | #include <fstream> | ||
19 | #include <parametric-curves/abstract-curve.hpp> | ||
20 | #include <parametric-curves/spline.hpp> | ||
21 | #include <vector> | ||
22 | namespace parametriccurves { | ||
23 | namespace spatial { | ||
24 | |||
25 | using parametriccurves::Spline; | ||
26 | /// \class ForceCurve | ||
27 | /// \brief Representation of a spatial vector curve in the form of splines | ||
28 | /// Returns Plucker coordinates in the form of (Linear(3), Angular(3)) | ||
29 | /// | ||
30 | template <typename Numeric = double> | ||
31 | struct ForceCurve | ||
32 | : public AbstractCurve<Numeric, Eigen::Matrix<Numeric, 6, 1> > { | ||
33 | static const std::size_t Dim = 3; | ||
34 | typedef Eigen::Matrix<Numeric, 2 * Dim, 1> force_t; | ||
35 | typedef Eigen::Matrix<Numeric, 2 * Dim, 1> motion_t; | ||
36 | typedef Spline<Numeric, Dim, Eigen::Matrix<Numeric, Dim, 1> > spline_lin_t; | ||
37 | typedef Spline<Numeric, Dim, Eigen::Matrix<Numeric, Dim, 1> > spline_ang_t; | ||
38 | typedef Numeric time_t; | ||
39 | typedef Numeric num_t; | ||
40 | typedef AbstractCurve<num_t, force_t> curve_abc_t; | ||
41 | |||
42 | public: | ||
43 | ///\brief Constructor | ||
44 | |||
45 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
1 | ForceCurve() : curve_abc_t() {} |
46 | |||
47 | ///\brief Constructor | ||
48 | ///\param subSplines: vector of subsplines | ||
49 | ✗ | ForceCurve(const spline_lin_t& linPart_, const spline_ang_t& angPart_) | |
50 | ✗ | : curve_abc_t(linPart_.tmin(), linPart_.tmax()), | |
51 | ✗ | linPart(linPart_), | |
52 | ✗ | angPart(angPart_), | |
53 | ✗ | motionVector(motion_t::Zero()) {} | |
54 | |||
55 | ///\brief Copy Constructor | ||
56 | ✗ | ForceCurve(const ForceCurve& other) | |
57 | : curve_abc_t(other.linPart.tmin(), other.linPart.tmax()), | ||
58 | ✗ | linPart(other.linPart), | |
59 | ✗ | angPart(other.angPart), | |
60 | ✗ | motionVector(motion_t::Zero()) {} | |
61 | |||
62 | ///\brief Destructor | ||
63 | 4 | ~ForceCurve() {} | |
64 | |||
65 | public: | ||
66 | ✗ | virtual const force_t operator()(const time_t& t) const { | |
67 | ✗ | force_t s = force_t::Zero(); | |
68 | ✗ | s << linPart(t), angPart(t); | |
69 | ✗ | return s; | |
70 | } | ||
71 | |||
72 | ✗ | virtual const force_t derivate(const time_t&, const std::size_t&) const { | |
73 | // TODO: Implement derivative | ||
74 | ✗ | return force_t::Zero(Dim); | |
75 | } | ||
76 | |||
77 | ✗ | virtual const std::size_t& size() const { return linPart.size(); } | |
78 | |||
79 | ✗ | void setMotionVector(const motion_t& motionVector_) { | |
80 | ✗ | motionVector = motionVector_; | |
81 | ✗ | return; | |
82 | } | ||
83 | |||
84 | ✗ | virtual bool setInitialPoint(const force_t& /*x_init*/) { return false; } | |
85 | ✗ | virtual bool setInitialPoint(const num_t& /*x_init*/) { return false; } | |
86 | |||
87 | protected: | ||
88 | /*Attributes*/ | ||
89 | spline_lin_t linPart; // const | ||
90 | spline_ang_t angPart; // const | ||
91 | motion_t motionVector; // const | ||
92 | |||
93 | private: | ||
94 | // Serialization of the class | ||
95 | friend class boost::serialization::access; | ||
96 | template <class Archive> | ||
97 | ✗ | void save(Archive& ar, const unsigned int /*version*/) const { | |
98 | ✗ | ar& linPart; | |
99 | ✗ | ar& angPart; | |
100 | |||
101 | ✗ | return; | |
102 | } | ||
103 | |||
104 | template <class Archive> | ||
105 | ✗ | void load(Archive& ar, const unsigned int /*version*/) { | |
106 | ✗ | ar& linPart; | |
107 | ✗ | ar& angPart; | |
108 | |||
109 | ✗ | motionVector = motion_t::Zero(); | |
110 | ✗ | this->t_min = linPart.tmin(); | |
111 | ✗ | this->t_max = linPart.tmax(); | |
112 | |||
113 | ✗ | assert(this->t_min == angPart.tmin()); | |
114 | ✗ | assert(this->t_max == angPart.tmax()); | |
115 | ✗ | return; | |
116 | } | ||
117 | |||
118 | ✗ | BOOST_SERIALIZATION_SPLIT_MEMBER() | |
119 | |||
120 | public: | ||
121 | ✗ | bool loadFromFile(const std::string& filename) { | |
122 | ✗ | std::ifstream ifs(filename.c_str()); | |
123 | ✗ | if (ifs) { | |
124 | ✗ | boost::archive::text_iarchive ia(ifs); | |
125 | ✗ | ForceCurve& force_curve = *static_cast<ForceCurve*>(this); | |
126 | ✗ | ia >> force_curve; | |
127 | ✗ | } else { | |
128 | ✗ | const std::string exception_message(filename + | |
129 | " does not seem to be a valid file."); | ||
130 | ✗ | throw std::invalid_argument(exception_message); | |
131 | return false; | ||
132 | } | ||
133 | ✗ | return true; | |
134 | } | ||
135 | |||
136 | /// \brief Saved a Derived object as a text file. | ||
137 | ✗ | bool saveToFile(const std::string& filename) const { | |
138 | ✗ | std::ofstream ofs(filename.c_str()); | |
139 | ✗ | if (ofs) { | |
140 | ✗ | boost::archive::text_oarchive oa(ofs); | |
141 | ✗ | oa << *static_cast<const ForceCurve*>(this); | |
142 | ✗ | } else { | |
143 | ✗ | const std::string exception_message(filename + | |
144 | " does not seem to be a valid file."); | ||
145 | ✗ | throw std::invalid_argument(exception_message); | |
146 | return false; | ||
147 | } | ||
148 | ✗ | return true; | |
149 | } | ||
150 | |||
151 | // BOOST_SERIALIZATION_SPLIT_MEMBER() | ||
152 | }; | ||
153 | } // namespace spatial | ||
154 | } // namespace parametriccurves | ||
155 | #endif //_CLASS_EXACTCUBIC | ||
156 |