1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library 2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra. 3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// 4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2010-2011 Hauke Heibel <heibel@gmail.com> 5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// 6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla 7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed 8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include "main.h" 11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include <unsupported/Eigen/Splines> 13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandeznamespace Eigen { 157faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// lets do some explicit instantiations and thus 17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// force the compilation of all spline functions... 18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 2, Dynamic>; 19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 3, Dynamic>; 20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 21c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 2, 2>; 22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 2, 3>; 23c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 2, 4>; 24c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<double, 2, 5>; 25c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 2, Dynamic>; 27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 3, Dynamic>; 28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 3, 2>; 30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 3, 3>; 31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 3, 4>; 32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate class Spline<float, 3, 5>; 33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 347faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez} 357faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez 36c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan KamathSpline<double, 2, Dynamic> closed_spline2d() 37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath RowVectorXd knots(12); 39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath knots << 0, 40c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0, 41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0, 42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0, 43c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.867193179093898, 44c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1.660330955342408, 45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 2.605084834823134, 46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 3.484154586374428, 47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.252699478956276, 48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.252699478956276, 49c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.252699478956276, 50c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.252699478956276; 51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath MatrixXd ctrls(8,2); 53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ctrls << -0.370967741935484, 0.236842105263158, 54c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.231401860693277, 0.442245185027632, 55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.344361228532831, 0.773369994120753, 56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.828990216203802, 0.106550882647595, 57c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.407270163678382, -1.043452922172848, 58c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.488467813584053, -0.390098582530090, 59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.494657189446427, 0.054804824897884, 60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.370967741935484, 0.236842105263158; 61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ctrls.transposeInPlace(); 62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath return Spline<double, 2, Dynamic>(knots, ctrls); 64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/* create a reference spline */ 67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan KamathSpline<double, 3, Dynamic> spline3d() 68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath RowVectorXd knots(11); 70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath knots << 0, 71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0, 72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0, 73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.118997681558377, 74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.162611735194631, 75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.498364051982143, 76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.655098003973841, 77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.679702676853675, 78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1.000000000000000, 79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1.000000000000000, 80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1.000000000000000; 81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath MatrixXd ctrls(8,3); 83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ctrls << 0.959743958516081, 0.340385726666133, 0.585267750979777, 84c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.223811939491137, 0.751267059305653, 0.255095115459269, 85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.505957051665142, 0.699076722656686, 0.890903252535799, 86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.959291425205444, 0.547215529963803, 0.138624442828679, 87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.149294005559057, 0.257508254123736, 0.840717255983663, 88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.254282178971531, 0.814284826068816, 0.243524968724989, 89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.929263623187228, 0.349983765984809, 0.196595250431208, 90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.251083857976031, 0.616044676146639, 0.473288848902729; 91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ctrls.transposeInPlace(); 92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath return Spline<double, 3, Dynamic>(knots, ctrls); 94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 95c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 96c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/* compares evaluations against known results */ 97c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid eval_spline3d() 98c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Spline3d spline = spline3d(); 100c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 101c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath RowVectorXd u(10); 102c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath u << 0.351659507062997, 103c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.830828627896291, 104c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.585264091152724, 105c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.549723608291140, 106c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.917193663829810, 107c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.285839018820374, 108c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.757200229110721, 109c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.753729094278495, 110c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.380445846975357, 111c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.567821640725221; 112c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 113c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath MatrixXd pts(10,3); 114c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts << 0.707620811535916, 0.510258911240815, 0.417485437023409, 115c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.603422256426978, 0.529498282727551, 0.270351549348981, 116c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.228364197569334, 0.423745615677815, 0.637687289287490, 117c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.275556796335168, 0.350856706427970, 0.684295784598905, 118c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.514519311047655, 0.525077224890754, 0.351628308305896, 119c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.724152914315666, 0.574461155457304, 0.469860285484058, 120c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.529365063753288, 0.613328702656816, 0.237837040141739, 121c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.522469395136878, 0.619099658652895, 0.237139665242069, 122c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.677357023849552, 0.480655768435853, 0.422227610314397, 123c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.247046593173758, 0.380604672404750, 0.670065791405019; 124c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts.transposeInPlace(); 125c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 126c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int i=0; i<u.size(); ++i) 127c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 128c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Vector3d pt = spline(u(i)); 129c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (pt - pts.col(i)).norm() < 1e-14 ); 130c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 131c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 132c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 133c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/* compares evaluations on corner cases */ 134c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid eval_spline3d_onbrks() 135c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 136c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Spline3d spline = spline3d(); 137c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 138c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath RowVectorXd u = spline.knots(); 139c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 140c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath MatrixXd pts(11,3); 141c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts << 0.959743958516081, 0.340385726666133, 0.585267750979777, 142c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.959743958516081, 0.340385726666133, 0.585267750979777, 143c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.959743958516081, 0.340385726666133, 0.585267750979777, 144c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.430282980289940, 0.713074680056118, 0.720373307943349, 145c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.558074875553060, 0.681617921034459, 0.804417124839942, 146c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.407076008291750, 0.349707710518163, 0.617275937419545, 147c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.240037008286602, 0.738739390398014, 0.324554153129411, 148c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.302434111480572, 0.781162443963899, 0.240177089094644, 149c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.251083857976031, 0.616044676146639, 0.473288848902729, 150c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.251083857976031, 0.616044676146639, 0.473288848902729, 151c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.251083857976031, 0.616044676146639, 0.473288848902729; 152c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts.transposeInPlace(); 153c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 154c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int i=0; i<u.size(); ++i) 155c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 156c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Vector3d pt = spline(u(i)); 157c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (pt - pts.col(i)).norm() < 1e-14 ); 158c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 159c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 160c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 161c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid eval_closed_spline2d() 162c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 163c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Spline2d spline = closed_spline2d(); 164c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 165c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath RowVectorXd u(12); 166c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath u << 0, 167c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.332457030395796, 168c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.356467130532952, 169c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.453562180176215, 170c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.648017921874804, 171c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.973770235555003, 172c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 1.882577647219307, 173c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 2.289408593930498, 174c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 3.511951429883045, 175c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 3.884149321369450, 176c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.236261590369414, 177c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 4.252699478956276; 178c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 179c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath MatrixXd pts(12,2); 180c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts << -0.370967741935484, 0.236842105263158, 181c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.152576775123250, 0.448975001279334, 182c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.133417538277668, 0.461615613865667, 183c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.053199060826740, 0.507630360006299, 184c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.114249591147281, 0.570414135097409, 185c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.377810316891987, 0.560497102875315, 186c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.665052120135908, -0.157557441109611, 187c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 0.516006487053228, -0.559763292174825, 188c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.379486035348887, -0.331959640488223, 189c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.462034726249078, -0.039105670080824, 190c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.378730600917982, 0.225127015099919, 191c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath -0.370967741935484, 0.236842105263158; 192c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath pts.transposeInPlace(); 193c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 194c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (int i=0; i<u.size(); ++i) 195c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 196c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Vector2d pt = spline(u(i)); 197c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (pt - pts.col(i)).norm() < 1e-14 ); 198c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 199c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 200c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 201c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid check_global_interpolation2d() 202c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 203c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef Spline2d::PointType PointType; 204c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef Spline2d::KnotVectorType KnotVectorType; 205c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath typedef Spline2d::ControlPointVectorType ControlPointVectorType; 206c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 207c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath ControlPointVectorType points = ControlPointVectorType::Random(2,100); 208c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 209c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath KnotVectorType chord_lengths; // knot parameters 210c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath Eigen::ChordLengths(points, chord_lengths); 211c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 212c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // interpolation without knot parameters 213c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 214c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath const Spline2d spline = SplineFitting<Spline2d>::Interpolate(points,3); 215c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 216c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (Eigen::DenseIndex i=0; i<points.cols(); ++i) 217c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 218c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath PointType pt = spline( chord_lengths(i) ); 219c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath PointType ref = points.col(i); 220c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (pt - ref).matrix().norm() < 1e-14 ); 221c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 222c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 223c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 224c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath // interpolation with given knot parameters 225c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 226c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath const Spline2d spline = SplineFitting<Spline2d>::Interpolate(points,3,chord_lengths); 227c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 228c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath for (Eigen::DenseIndex i=0; i<points.cols(); ++i) 229c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath { 230c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath PointType pt = spline( chord_lengths(i) ); 231c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath PointType ref = points.col(i); 232c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath VERIFY( (pt - ref).matrix().norm() < 1e-14 ); 233c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 234c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath } 235c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 236c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 237c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath 238c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_splines() 239c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{ 240c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( eval_spline3d() ); 241c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( eval_spline3d_onbrks() ); 242c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( eval_closed_spline2d() ); 243c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath CALL_SUBTEST( check_global_interpolation2d() ); 244c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} 245