Changeset 90:8ecfdebbfe5b in rrlib_geometry


Ignore:
Timestamp:
29.07.2019 13:30:58 (4 months ago)
Author:
Tobias Föhst <foehst@…>
Branch:
14.08
Children:
91:c8f3f538e616, 92:bd5ec027bd3c, 93:a5e38d1d01b4
Phase:
public
Message:

Adapts to examples/tests structure, improves the curvature example and add a curvature example for splines

Files:
1 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • examples/geometries.cpp

    r68 r90  
    3737 
    3838#include "rrlib/highgui_wrapper/tWindow.h" 
     39#include "rrlib/math/utilities.h" 
    3940 
    4041//---------------------------------------------------------------------- 
     
    4647#include "rrlib/geometry/curves/tUniformBSplineCurve.h" 
    4748#include "rrlib/geometry/curves/tCardinalSplineCurve.h" 
     49#include "rrlib/geometry/curves/tBSplineCurve.h" 
    4850#include "rrlib/geometry/functions.h" 
    4951 
     
    6971typedef rrlib::geometry::tBezierCurve<2, tElement, 3> tBezierCurve; 
    7072typedef rrlib::geometry::tSplineCurve<2, tElement, 3> tSplineCurve; 
    71 typedef rrlib::geometry::tUniformBSplineCurve<2, tElement> tConcreteSplineCurve; 
    72 //typedef rrlib::geometry::tCardinalSplineCurve<2, tElement> tConcreteSplineCurve; 
     73// typedef rrlib::geometry::tUniformBSplineCurve<2, tElement> tConcreteSplineCurve; 
     74// typedef rrlib::geometry::tCardinalSplineCurve<2, tElement> tConcreteSplineCurve; 
     75typedef rrlib::geometry::tBSplineCurve<2, tElement> tConcreteSplineCurve; 
    7376 
    7477//---------------------------------------------------------------------- 
     
    213216  window.Render(); 
    214217 
    215  
    216218  for (int i = 0; i <= 100; ++i) 
    217219  { 
     
    227229      double radius = 1.0 / curvature; 
    228230 
    229       tBezierCurve::tDerivative first(bezier_curve.GetDerivative()); 
    230       tPoint m(p + (first(t).Normalized().Rotated(-rrlib::math::cPI_2) * radius)); 
     231      auto first(bezier_curve.GetDerivative()(t)); 
     232      auto direction = rrlib::math::Signum(first.Rotated(-rrlib::math::cPI_2) * bezier_curve.GetDerivative().GetDerivative()(t)); 
     233      tPoint m(p + (first.Normalized().Rotated(-rrlib::math::cPI_2) * direction * radius)); 
    231234 
    232235      window.SetColor(1); 
     
    442445  window.Render(); 
    443446 
     447  std::cout << std::endl << "=== Curvature on spline curve ===" << std::endl; 
     448 
     449  window.Clear(); 
     450  window.SetColor(0); 
     451  DrawSplineCurve(window, spline); 
     452  window.Render(); 
     453 
     454  for (int i = 0; i <= 100; ++i) 
     455  { 
     456    double t = i / 100.0 * spline.NumberOfSegments(); 
     457    tPoint p = spline(t); 
     458    window.Clear(); 
     459    window.SetColor(0); 
     460    DrawSplineCurve(window, spline); 
     461    DrawPoint(window, p); 
     462 
     463    window.SetColor(1); 
     464    double local_t; 
     465    auto bezier = spline.GetBezierCurveForParameter(t, local_t); 
     466    DrawBezierCurve(window, *bezier); 
     467 
     468    window.SetColor(2); 
     469    auto first = bezier->GetDerivative()(local_t); 
     470    DrawLineSegment(window, tLineSegment(p, p + first)); 
     471 
     472    double curvature = rrlib::geometry::GetCurvature(*bezier, local_t); 
     473    if (curvature > 0.0) 
     474    { 
     475      double radius = 1.0 / curvature; 
     476      auto direction = rrlib::math::Signum(first.Rotated(-rrlib::math::cPI_2) * bezier->GetDerivative().GetDerivative()(local_t)); 
     477      tPoint m(p + (first.Normalized().Rotated(-rrlib::math::cPI_2) * direction * radius)); 
     478 
     479      window.SetColor(3); 
     480      window.DrawCircleNormalized(m.X(), m.Y(), radius, false); 
     481    } 
     482 
     483    window.Render(); 
     484  } 
     485 
     486  window.Render(); 
     487 
    444488  tWindow::ReleaseAllInstances(); 
    445489 
  • examples/make.xml

    r81 r90  
    33<targets> 
    44 
    5   <rrlib name="basic_shapes"> 
    6     <sources> 
    7       functions.h 
    8       tBoundingBox.h 
    9       tLine.cpp 
    10       tLineSegment.cpp 
    11       tPlane.cpp 
    12       tPoint.cpp 
    13       tShape.h 
    14     </sources> 
    15   </rrlib> 
     5  <program name="geometries" sources="geometries.cpp" /> 
    166 
    17   <rrlib name="curves"> 
    18     <sources> 
    19       curves/* 
    20     </sources> 
    21   </rrlib> 
    22  
    23   <rrlib name="space_partitioning"> 
    24     <sources> 
    25       space_partitioning/* 
    26     </sources> 
    27   </rrlib> 
    28  
    29   <testprogram name="geometries"> 
    30     <sources> 
    31       test/test_geometries.cpp 
    32     </sources> 
    33   </testprogram> 
    34  
    35   <testprogram name="kd_tree"> 
    36     <sources> 
    37       test/test_kd_tree.cpp 
    38     </sources> 
    39   </testprogram> 
    40    
    41   <program name="geometry"> 
    42     <sources> 
    43       tests/geometry.cpp 
    44     </sources> 
    45   </program> 
     7  <program name="kd_tree" sources="kd_tree.cpp" /> 
    468 
    479</targets> 
  • make.xml

    r81 r90  
    33<targets> 
    44 
    5   <rrlib name="basic_shapes"> 
     5  <library name="basic_shapes"> 
    66    <sources> 
    77      functions.h 
     
    1313      tShape.h 
    1414    </sources> 
    15   </rrlib> 
     15  </library> 
    1616 
    17   <rrlib name="curves"> 
     17  <library name="curves"> 
    1818    <sources> 
    1919      curves/* 
    2020    </sources> 
    21   </rrlib> 
     21  </library> 
    2222 
    23   <rrlib name="space_partitioning"> 
     23  <library name="space_partitioning"> 
    2424    <sources> 
    2525      space_partitioning/* 
    2626    </sources> 
    27   </rrlib> 
    28  
    29   <testprogram name="geometries"> 
    30     <sources> 
    31       test/test_geometries.cpp 
    32     </sources> 
    33   </testprogram> 
    34  
    35   <testprogram name="kd_tree"> 
    36     <sources> 
    37       test/test_kd_tree.cpp 
    38     </sources> 
    39   </testprogram> 
    40    
    41   <program name="geometry"> 
    42     <sources> 
    43       tests/geometry.cpp 
    44     </sources> 
    45   </program> 
     27  </library> 
    4628 
    4729</targets> 
  • tests/make.xml

    r81 r90  
    33<targets> 
    44 
    5   <rrlib name="basic_shapes"> 
    6     <sources> 
    7       functions.h 
    8       tBoundingBox.h 
    9       tLine.cpp 
    10       tLineSegment.cpp 
    11       tPlane.cpp 
    12       tPoint.cpp 
    13       tShape.h 
    14     </sources> 
    15   </rrlib> 
    16  
    17   <rrlib name="curves"> 
    18     <sources> 
    19       curves/* 
    20     </sources> 
    21   </rrlib> 
    22  
    23   <rrlib name="space_partitioning"> 
    24     <sources> 
    25       space_partitioning/* 
    26     </sources> 
    27   </rrlib> 
    28  
    29   <testprogram name="geometries"> 
    30     <sources> 
    31       test/test_geometries.cpp 
    32     </sources> 
    33   </testprogram> 
    34  
    35   <testprogram name="kd_tree"> 
    36     <sources> 
    37       test/test_kd_tree.cpp 
    38     </sources> 
    39   </testprogram> 
    40    
    41   <program name="geometry"> 
    42     <sources> 
    43       tests/geometry.cpp 
    44     </sources> 
    45   </program> 
     5  <program name="geometry" sources="geometry.cpp" /> 
    466 
    477</targets> 
Note: See TracChangeset for help on using the changeset viewer.