Changeset 4:e60e074ddd36 in rrlib_geometry


Ignore:
Timestamp:
11.01.2011 18:50:35 (9 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Convert:
svn:2168a036-5f5f-4461-96ec-bf27dc59b608/trunk@5
Message:
  • Added base class for splines that define their segments as Bezier curves
  • Added cubic uniform b-splines for smooth approximation
  • Added cubic cardinal splines for interpolation
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • make.xml

    r1 r4  
    66      tBezierCurve.cpp 
    77      tBoundingBox.h 
     8      tCardinalSplineCurve.h 
    89      tLine.cpp 
    910      tLineSegment.cpp 
     11      tPoint.cpp 
    1012      tShape.h 
    11       tPoint.cpp 
     13      tSplineCurve.h 
     14      tUniformBSplineCurve.h 
    1215    </sources> 
    1316  </rrlib> 
  • tBezierCurve.hpp

    r1 r4  
    190190    const tBezierCurve<Tdimension, TElement, Tother_degree> &other) const 
    191191{ 
    192   intersection_points.clear(); 
    193   intersection_parameters.clear(); 
    194192  return this->GetIntersections(intersection_points, intersection_parameters, other, 0.0, 1.0); 
    195193} 
     
    199197    const tLine<Tdimension, TElement> &line) const 
    200198{ 
    201   intersection_points.clear(); 
    202   intersection_parameters.clear(); 
    203199  return this->GetIntersections(intersection_points, intersection_parameters, line, 0.0, 1.0); 
    204200} 
  • test/test_geometries.cpp

    r1 r4  
    4242#include "rrlib/geometry/tLine.h" 
    4343#include "rrlib/geometry/tBezierCurve.h" 
     44#include "rrlib/geometry/tUniformBSplineCurve.h" 
     45#include "rrlib/geometry/tCardinalSplineCurve.h" 
     46 
    4447#include "rrlib/highgui_wrapper/tWindow.h" 
    4548 
     
    6467typedef rrlib::geometry::tLineSegment<2, tElement> tLineSegment; 
    6568typedef rrlib::geometry::tBezierCurve<2, tElement, 3> tBezierCurve; 
     69typedef rrlib::geometry::tSplineCurve<2, tElement, 3> tSplineCurve; 
     70//typedef rrlib::geometry::tUniformBSplineCurve<2, tElement> tConcreteSplineCurve; 
     71typedef rrlib::geometry::tCardinalSplineCurve<2, tElement> tConcreteSplineCurve; 
    6672 
    6773//---------------------------------------------------------------------- 
     
    120126} 
    121127 
     128void DrawControlPolygon(tWindow &window, const tSplineCurve &spline_curve) 
     129{ 
     130  for (size_t i = 1; i < spline_curve.GetNumberOfControlPoints(); ++i) 
     131  { 
     132    const tPoint &start(spline_curve.GetControlPoint(i - 1)); 
     133    const tPoint &stop(spline_curve.GetControlPoint(i)); 
     134 
     135    window.DrawLineNormalized(start.X(), start.Y(), stop.X(), stop.Y()); 
     136  } 
     137} 
     138 
    122139void DrawBezierCurve(tWindow &window, const tBezierCurve &bezier_curve, float epsilon = 1.0E-6) 
    123140{ 
     
    131148  DrawBezierCurve(window, subdivision.first, epsilon); 
    132149  DrawBezierCurve(window, subdivision.second, epsilon); 
     150} 
     151 
     152void DrawSplineCurve(tWindow &window, const tSplineCurve &spline_curve, float epsilon = 1.0E-6) 
     153{ 
     154  for (size_t i = 0; i < spline_curve.GetNumberOfSegments(); ++i) 
     155  { 
     156    DrawBezierCurve(window, spline_curve.GetBezierCurveForSegment(i), epsilon); 
     157  } 
    133158} 
    134159 
     
    249274  window.Render(); 
    250275 
     276  std::cout << std::endl << "=== Spline with bounding box ===" << std::endl; 
     277 
     278  control_points.clear(); 
     279  control_points.push_back(tPoint(0.1, 0.2)); 
     280  control_points.push_back(tPoint(0.1, 0.2)); 
     281  control_points.push_back(tPoint(0.1, 0.2)); 
     282  control_points.push_back(tPoint(0.3, 0.5)); 
     283  control_points.push_back(tPoint(0.7, 0.6)); 
     284  control_points.push_back(tPoint(0.9, 0.4)); 
     285 
     286 
     287  tConcreteSplineCurve spline(control_points); 
     288 
     289  window.Clear(); 
     290  window.SetColor(1); 
     291  DrawControlPolygon(window, spline); 
     292  window.SetColor(2); 
     293  DrawBoundingBox(window, spline); 
     294  window.SetColor(3); 
     295  DrawSplineCurve(window, spline); 
     296  window.Render(); 
     297 
     298  std::cout << std::endl << "=== Adding point ===" << std::endl; 
     299 
     300  spline.AppendControlPoint(tPoint(0.75, 0.7)); 
     301  window.Clear(); 
     302  window.SetColor(1); 
     303  DrawControlPolygon(window, spline); 
     304  window.SetColor(2); 
     305  DrawBoundingBox(window, spline); 
     306  window.SetColor(3); 
     307  DrawSplineCurve(window, spline); 
     308  window.Render(); 
     309 
     310  std::cout << std::endl << "=== Adding point ===" << std::endl; 
     311 
     312  spline.AppendControlPoint(tPoint(0.5, 0.8)); 
     313  window.Clear(); 
     314  window.SetColor(1); 
     315  DrawControlPolygon(window, spline); 
     316  window.SetColor(2); 
     317  DrawBoundingBox(window, spline); 
     318  window.SetColor(3); 
     319  DrawSplineCurve(window, spline); 
     320  window.Render(); 
     321 
     322  std::cout << std::endl << "=== Adding point ===" << std::endl; 
     323 
     324  spline.AppendControlPoint(tPoint(0.2, 0.4)); 
     325  window.Clear(); 
     326  window.SetColor(1); 
     327  DrawControlPolygon(window, spline); 
     328  window.SetColor(2); 
     329  DrawBoundingBox(window, spline); 
     330  window.SetColor(3); 
     331  DrawSplineCurve(window, spline); 
     332  window.Render(); 
     333 
     334  std::cout << std::endl << "=== Adding point ===" << std::endl; 
     335 
     336  spline.AppendControlPoint(tPoint(0.2, 0.4)); 
     337  window.Clear(); 
     338  window.SetColor(1); 
     339  DrawControlPolygon(window, spline); 
     340  window.SetColor(2); 
     341  DrawBoundingBox(window, spline); 
     342  window.SetColor(3); 
     343  DrawSplineCurve(window, spline); 
     344  window.Render(); 
     345 
     346  std::cout << std::endl << "=== Adding point ===" << std::endl; 
     347 
     348  spline.AppendControlPoint(tPoint(0.2, 0.4)); 
     349  window.Clear(); 
     350  window.SetColor(1); 
     351  DrawControlPolygon(window, spline); 
     352  window.SetColor(2); 
     353  DrawBoundingBox(window, spline); 
     354  window.SetColor(3); 
     355  DrawSplineCurve(window, spline); 
     356  window.Render(); 
     357 
     358  std::cout << std::endl << "=== Spline intersects line ===" << std::endl; 
     359 
     360  window.Clear(); 
     361  window.SetColor(0); 
     362  line.Translate(tVector(0, 0.1)); 
     363  DrawLine(window, line); 
     364  window.SetColor(1); 
     365  DrawSplineCurve(window, spline); 
     366 
     367  window.Render(); 
     368 
     369  intersection_points.clear(); 
     370  intersection_parameters.clear(); 
     371  spline.GetIntersections(intersection_points, intersection_parameters, line); 
     372  std::cout << "number of intersections: " << intersection_points.size() << std::endl; 
     373 
     374  window.SetColor(2); 
     375  for (std::vector<tPoint>::iterator it = intersection_points.begin(); it != intersection_points.end(); ++it) 
     376  { 
     377    std::cout << *it << std::endl; 
     378    DrawPoint(window, *it); 
     379  } 
     380  window.Render(); 
     381 
    251382 
    252383 
Note: See TracChangeset for help on using the changeset viewer.