Changeset 4:e60e074ddd36 in rrlib_geometry
 Timestamp:
 11.01.2011 18:50:35 (9 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:2168a0365f5f446196ecbf27dc59b608/trunk@5
 Files:

 6 added
 3 edited
Legend:
 Unmodified
 Added
 Removed

make.xml
r1 r4 6 6 tBezierCurve.cpp 7 7 tBoundingBox.h 8 tCardinalSplineCurve.h 8 9 tLine.cpp 9 10 tLineSegment.cpp 11 tPoint.cpp 10 12 tShape.h 11 tPoint.cpp 13 tSplineCurve.h 14 tUniformBSplineCurve.h 12 15 </sources> 13 16 </rrlib> 
tBezierCurve.hpp
r1 r4 190 190 const tBezierCurve<Tdimension, TElement, Tother_degree> &other) const 191 191 { 192 intersection_points.clear();193 intersection_parameters.clear();194 192 return this>GetIntersections(intersection_points, intersection_parameters, other, 0.0, 1.0); 195 193 } … … 199 197 const tLine<Tdimension, TElement> &line) const 200 198 { 201 intersection_points.clear();202 intersection_parameters.clear();203 199 return this>GetIntersections(intersection_points, intersection_parameters, line, 0.0, 1.0); 204 200 } 
test/test_geometries.cpp
r1 r4 42 42 #include "rrlib/geometry/tLine.h" 43 43 #include "rrlib/geometry/tBezierCurve.h" 44 #include "rrlib/geometry/tUniformBSplineCurve.h" 45 #include "rrlib/geometry/tCardinalSplineCurve.h" 46 44 47 #include "rrlib/highgui_wrapper/tWindow.h" 45 48 … … 64 67 typedef rrlib::geometry::tLineSegment<2, tElement> tLineSegment; 65 68 typedef rrlib::geometry::tBezierCurve<2, tElement, 3> tBezierCurve; 69 typedef rrlib::geometry::tSplineCurve<2, tElement, 3> tSplineCurve; 70 //typedef rrlib::geometry::tUniformBSplineCurve<2, tElement> tConcreteSplineCurve; 71 typedef rrlib::geometry::tCardinalSplineCurve<2, tElement> tConcreteSplineCurve; 66 72 67 73 // … … 120 126 } 121 127 128 void 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 122 139 void DrawBezierCurve(tWindow &window, const tBezierCurve &bezier_curve, float epsilon = 1.0E6) 123 140 { … … 131 148 DrawBezierCurve(window, subdivision.first, epsilon); 132 149 DrawBezierCurve(window, subdivision.second, epsilon); 150 } 151 152 void DrawSplineCurve(tWindow &window, const tSplineCurve &spline_curve, float epsilon = 1.0E6) 153 { 154 for (size_t i = 0; i < spline_curve.GetNumberOfSegments(); ++i) 155 { 156 DrawBezierCurve(window, spline_curve.GetBezierCurveForSegment(i), epsilon); 157 } 133 158 } 134 159 … … 249 274 window.Render(); 250 275 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 251 382 252 383
Note: See TracChangeset
for help on using the changeset viewer.