00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "main.h"
00011
00012 #include <unsupported/Eigen/Splines>
00013
00014 namespace Eigen {
00015
00016
00017
00018 template class Spline<double, 2, Dynamic>;
00019 template class Spline<double, 3, Dynamic>;
00020
00021 template class Spline<double, 2, 2>;
00022 template class Spline<double, 2, 3>;
00023 template class Spline<double, 2, 4>;
00024 template class Spline<double, 2, 5>;
00025
00026 template class Spline<float, 2, Dynamic>;
00027 template class Spline<float, 3, Dynamic>;
00028
00029 template class Spline<float, 3, 2>;
00030 template class Spline<float, 3, 3>;
00031 template class Spline<float, 3, 4>;
00032 template class Spline<float, 3, 5>;
00033
00034 }
00035
00036 Spline<double, 2, Dynamic> closed_spline2d()
00037 {
00038 RowVectorXd knots(12);
00039 knots << 0,
00040 0,
00041 0,
00042 0,
00043 0.867193179093898,
00044 1.660330955342408,
00045 2.605084834823134,
00046 3.484154586374428,
00047 4.252699478956276,
00048 4.252699478956276,
00049 4.252699478956276,
00050 4.252699478956276;
00051
00052 MatrixXd ctrls(8,2);
00053 ctrls << -0.370967741935484, 0.236842105263158,
00054 -0.231401860693277, 0.442245185027632,
00055 0.344361228532831, 0.773369994120753,
00056 0.828990216203802, 0.106550882647595,
00057 0.407270163678382, -1.043452922172848,
00058 -0.488467813584053, -0.390098582530090,
00059 -0.494657189446427, 0.054804824897884,
00060 -0.370967741935484, 0.236842105263158;
00061 ctrls.transposeInPlace();
00062
00063 return Spline<double, 2, Dynamic>(knots, ctrls);
00064 }
00065
00066
00067 Spline<double, 3, Dynamic> spline3d()
00068 {
00069 RowVectorXd knots(11);
00070 knots << 0,
00071 0,
00072 0,
00073 0.118997681558377,
00074 0.162611735194631,
00075 0.498364051982143,
00076 0.655098003973841,
00077 0.679702676853675,
00078 1.000000000000000,
00079 1.000000000000000,
00080 1.000000000000000;
00081
00082 MatrixXd ctrls(8,3);
00083 ctrls << 0.959743958516081, 0.340385726666133, 0.585267750979777,
00084 0.223811939491137, 0.751267059305653, 0.255095115459269,
00085 0.505957051665142, 0.699076722656686, 0.890903252535799,
00086 0.959291425205444, 0.547215529963803, 0.138624442828679,
00087 0.149294005559057, 0.257508254123736, 0.840717255983663,
00088 0.254282178971531, 0.814284826068816, 0.243524968724989,
00089 0.929263623187228, 0.349983765984809, 0.196595250431208,
00090 0.251083857976031, 0.616044676146639, 0.473288848902729;
00091 ctrls.transposeInPlace();
00092
00093 return Spline<double, 3, Dynamic>(knots, ctrls);
00094 }
00095
00096
00097 void eval_spline3d()
00098 {
00099 Spline3d spline = spline3d();
00100
00101 RowVectorXd u(10);
00102 u << 0.351659507062997,
00103 0.830828627896291,
00104 0.585264091152724,
00105 0.549723608291140,
00106 0.917193663829810,
00107 0.285839018820374,
00108 0.757200229110721,
00109 0.753729094278495,
00110 0.380445846975357,
00111 0.567821640725221;
00112
00113 MatrixXd pts(10,3);
00114 pts << 0.707620811535916, 0.510258911240815, 0.417485437023409,
00115 0.603422256426978, 0.529498282727551, 0.270351549348981,
00116 0.228364197569334, 0.423745615677815, 0.637687289287490,
00117 0.275556796335168, 0.350856706427970, 0.684295784598905,
00118 0.514519311047655, 0.525077224890754, 0.351628308305896,
00119 0.724152914315666, 0.574461155457304, 0.469860285484058,
00120 0.529365063753288, 0.613328702656816, 0.237837040141739,
00121 0.522469395136878, 0.619099658652895, 0.237139665242069,
00122 0.677357023849552, 0.480655768435853, 0.422227610314397,
00123 0.247046593173758, 0.380604672404750, 0.670065791405019;
00124 pts.transposeInPlace();
00125
00126 for (int i=0; i<u.size(); ++i)
00127 {
00128 Vector3d pt = spline(u(i));
00129 VERIFY( (pt - pts.col(i)).norm() < 1e-14 );
00130 }
00131 }
00132
00133
00134 void eval_spline3d_onbrks()
00135 {
00136 Spline3d spline = spline3d();
00137
00138 RowVectorXd u = spline.knots();
00139
00140 MatrixXd pts(11,3);
00141 pts << 0.959743958516081, 0.340385726666133, 0.585267750979777,
00142 0.959743958516081, 0.340385726666133, 0.585267750979777,
00143 0.959743958516081, 0.340385726666133, 0.585267750979777,
00144 0.430282980289940, 0.713074680056118, 0.720373307943349,
00145 0.558074875553060, 0.681617921034459, 0.804417124839942,
00146 0.407076008291750, 0.349707710518163, 0.617275937419545,
00147 0.240037008286602, 0.738739390398014, 0.324554153129411,
00148 0.302434111480572, 0.781162443963899, 0.240177089094644,
00149 0.251083857976031, 0.616044676146639, 0.473288848902729,
00150 0.251083857976031, 0.616044676146639, 0.473288848902729,
00151 0.251083857976031, 0.616044676146639, 0.473288848902729;
00152 pts.transposeInPlace();
00153
00154 for (int i=0; i<u.size(); ++i)
00155 {
00156 Vector3d pt = spline(u(i));
00157 VERIFY( (pt - pts.col(i)).norm() < 1e-14 );
00158 }
00159 }
00160
00161 void eval_closed_spline2d()
00162 {
00163 Spline2d spline = closed_spline2d();
00164
00165 RowVectorXd u(12);
00166 u << 0,
00167 0.332457030395796,
00168 0.356467130532952,
00169 0.453562180176215,
00170 0.648017921874804,
00171 0.973770235555003,
00172 1.882577647219307,
00173 2.289408593930498,
00174 3.511951429883045,
00175 3.884149321369450,
00176 4.236261590369414,
00177 4.252699478956276;
00178
00179 MatrixXd pts(12,2);
00180 pts << -0.370967741935484, 0.236842105263158,
00181 -0.152576775123250, 0.448975001279334,
00182 -0.133417538277668, 0.461615613865667,
00183 -0.053199060826740, 0.507630360006299,
00184 0.114249591147281, 0.570414135097409,
00185 0.377810316891987, 0.560497102875315,
00186 0.665052120135908, -0.157557441109611,
00187 0.516006487053228, -0.559763292174825,
00188 -0.379486035348887, -0.331959640488223,
00189 -0.462034726249078, -0.039105670080824,
00190 -0.378730600917982, 0.225127015099919,
00191 -0.370967741935484, 0.236842105263158;
00192 pts.transposeInPlace();
00193
00194 for (int i=0; i<u.size(); ++i)
00195 {
00196 Vector2d pt = spline(u(i));
00197 VERIFY( (pt - pts.col(i)).norm() < 1e-14 );
00198 }
00199 }
00200
00201 void check_global_interpolation2d()
00202 {
00203 typedef Spline2d::PointType PointType;
00204 typedef Spline2d::KnotVectorType KnotVectorType;
00205 typedef Spline2d::ControlPointVectorType ControlPointVectorType;
00206
00207 ControlPointVectorType points = ControlPointVectorType::Random(2,100);
00208
00209 KnotVectorType chord_lengths;
00210 Eigen::ChordLengths(points, chord_lengths);
00211
00212
00213 {
00214 const Spline2d spline = SplineFitting<Spline2d>::Interpolate(points,3);
00215
00216 for (Eigen::DenseIndex i=0; i<points.cols(); ++i)
00217 {
00218 PointType pt = spline( chord_lengths(i) );
00219 PointType ref = points.col(i);
00220 VERIFY( (pt - ref).matrix().norm() < 1e-14 );
00221 }
00222 }
00223
00224
00225 {
00226 const Spline2d spline = SplineFitting<Spline2d>::Interpolate(points,3,chord_lengths);
00227
00228 for (Eigen::DenseIndex i=0; i<points.cols(); ++i)
00229 {
00230 PointType pt = spline( chord_lengths(i) );
00231 PointType ref = points.col(i);
00232 VERIFY( (pt - ref).matrix().norm() < 1e-14 );
00233 }
00234 }
00235 }
00236
00237
00238 void test_splines()
00239 {
00240 CALL_SUBTEST( eval_spline3d() );
00241 CALL_SUBTEST( eval_spline3d_onbrks() );
00242 CALL_SUBTEST( eval_closed_spline2d() );
00243 CALL_SUBTEST( check_global_interpolation2d() );
00244 }