spline.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*! ========================================================================
  2. ** Extended Template and Library Test Suite
  3. ** Spline Curve Test
  4. **
  5. ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
  6. ** Copyright (c) 2010 Nikita Kitaev
  7. **
  8. ** This package is free software; you can redistribute it and/or
  9. ** modify it under the terms of the GNU General Public License as
  10. ** published by the Free Software Foundation; either version 2 of
  11. ** the License, or (at your option) any later version.
  12. **
  13. ** This package is distributed in the hope that it will be useful,
  14. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. ** General Public License for more details.
  17. **
  18. ** === N O T E S ===========================================================
  19. **
  20. ** ========================================================================= */
  21. #include <ETL/spline>
  22. #include <ETL/angle>
  23. #include <ETL/clock>
  24. #include <ETL/calculus>
  25. #include <stdio.h>
  26. using namespace etl;
  27. int bspline_basic_test(void)
  28. {
  29. int ret = 0;
  30. float f;
  31. bspline<float> BSpline;
  32. etl::clock timer;
  33. double t;
  34. BSpline.cpoints().insert(BSpline.cpoints().end(), 0.0);
  35. BSpline.cpoints().insert(BSpline.cpoints().end(), -1.0);
  36. BSpline.cpoints().insert(BSpline.cpoints().end(), 0.0);
  37. BSpline.cpoints().insert(BSpline.cpoints().end(), 1.0);
  38. BSpline.cpoints().insert(BSpline.cpoints().end(), 0.0);
  39. BSpline.set_m(4);
  40. BSpline.reset_knots();
  41. integral<bspline<float> > inte(BSpline);
  42. /*
  43. for(f=0.0;f<1.001;f+=0.05)
  44. fprintf(stderr,"BSpline(%f)= %f\n",f,BSpline(f));
  45. */
  46. fprintf(stderr, "integral of BSpline() on [0,1] = %f\n", inte(0, 1.0));
  47. for (f = 0.0f, timer.reset(); f < 1.001f; f += 0.000005f) {
  48. t += BSpline(f) + BSpline(f + 0.1f);
  49. t += BSpline(f) + BSpline(f + 0.1f);
  50. t += BSpline(f) + BSpline(f + 0.1f);
  51. t += BSpline(f) + BSpline(f + 0.1f);
  52. t += BSpline(f) + BSpline(f + 0.1f);
  53. t += BSpline(f) + BSpline(f + 0.1f);
  54. t += BSpline(f) + BSpline(f + 0.1f);
  55. t += BSpline(f) + BSpline(f + 0.1f);
  56. t += BSpline(f) + BSpline(f + 0.1f);
  57. t += BSpline(f) + BSpline(f + 0.1f);
  58. t += BSpline(f) + BSpline(f + 0.1f);
  59. t += BSpline(f) + BSpline(f + 0.1f);
  60. }
  61. t = timer();
  62. fprintf(stderr, "BSpline time=%f milliseconds\n", t * 1000);
  63. return ret;
  64. }
  65. int main()
  66. {
  67. int error = 0;
  68. error += bspline_basic_test();
  69. return error;
  70. }