TuttleOFX
1
|
00001 #include "bezier.hpp" 00002 00003 #include <boost/math/special_functions/pow.hpp> 00004 #include <boost/math/special_functions/math_fwd.hpp> 00005 00006 namespace tuttle { 00007 namespace plugin { 00008 namespace warp { 00009 namespace bezier { 00010 00011 double barycentre( const double a, const double b, const double c, const double d, const double t ) 00012 { 00013 using boost::math::pow; 00014 //B(t) = P0(1-t)^3 + 3 P1 t (1-t)^2 + 3 P2 t^2 (1-t) + P3 t^3; 00015 return ( a*pow<3>( 1 - t ) )+( 3 * b * t * pow<2>( 1 - t ) )+( 3 * c * pow<2>(t) * ( 1 - t ) )+( d * pow<3>(t) ); 00016 } 00017 00018 point2<double> barycentre( const std::vector< point2<double> >& pts, const double t ) 00019 { 00020 point2<double> p; 00021 p.x = barycentre( pts[0].x, pts[1].x, pts[2].x, pts[3].x, t ); 00022 p.y = barycentre( pts[0].y, pts[1].y, pts[2].y, pts[3].y, t ); 00023 return p; 00024 } 00025 00026 void tracerPoint( const point2<double>& p ) 00027 { 00028 //std::cout<<"--------------TracePoints--------------"<<std::endl; 00029 glVertex2f( p.x, p.y ); 00030 } 00031 00032 void drawBezier( const std::vector< point2<double> >& tabPts, const std::size_t nbBezier, const double r, const double v, const double b ) 00033 { 00034 //std::cout<<"--------------DessineRecur--------------"<<std::endl; 00035 for( std::size_t i = 0; i < nbBezier; ++i ) 00036 { 00037 double t = (double(nbBezier ) - i ) / double(nbBezier ); 00038 00039 point2<double> tab = barycentre( tabPts, t ); 00040 00041 //_tgtPointsBezier.push_back( tab ); 00042 00043 glPointSize( pointWidth ); 00044 glColor3f( r, v, b ); 00045 glBegin( GL_POINTS ); 00046 tracerPoint( tab ); 00047 glEnd( ); 00048 } 00049 } 00050 00051 void bezierSubdivide( const std::vector< point2<double> >& pts, const std::size_t subdivs, std::vector< point2<double> >& outputPts ) 00052 { 00053 const std::size_t fullSubdivs = subdivs + 1; 00054 for( std::size_t i = 1; i < fullSubdivs; ++i ) 00055 { 00056 const double t = i / double( fullSubdivs ); 00057 outputPts.push_back( barycentre( pts, t ) ); 00058 } 00059 } 00060 00061 00062 } 00063 } 00064 } 00065 } 00066 00067