bezier.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * bezier.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: 6c3a9b422ce3cf896983fbfb13174b4df1a6f4dd $
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef BEZIER_HPP
00026 #define BEZIER_HPP
00027 
00028 #include "../src/skin_common.hpp"
00029 #include "pointer.hpp"
00030 #include <vector>
00031 
00032 #define MAX_BEZIER_POINT 1023
00033 
00034 
00035 /// Class for Bezier curves
00036 class Bezier: public SkinObject
00037 {
00038 public:
00039     /// Values to indicate which coordinate(s) must be checked to consider
00040     /// that two points are distinct
00041     enum Flag_t
00042     {
00043         kCoordsBoth,    // x or y must be different (default)
00044         kCoordsX,       // only x is different
00045         kCoordsY        // only y is different
00046     };
00047 
00048     Bezier( intf_thread_t *p_intf,
00049             const vector<float> &pAbscissas,
00050             const vector<float> &pOrdinates,
00051             Flag_t flag = kCoordsBoth );
00052     ~Bezier() { }
00053 
00054     /// Get the number of control points used to define the curve
00055     int getNbCtrlPoints() const { return m_nbCtrlPt; }
00056 
00057     /// Return the percentage (between 0 and 1) of the curve point nearest
00058     /// from (x, y)
00059     float getNearestPercent( int x, int y ) const;
00060 
00061     /// Return the distance of (x, y) to the curve, corrected
00062     /// by the (optional) given scale factors
00063     float getMinDist( int x, int y, float xScale = 1.0f,
00064                       float yScale = 1.0f ) const;
00065 
00066     /// Get the coordinates of the point at t percent of
00067     /// the curve (t must be between 0 and 1)
00068     void getPoint( float t, int &x, int &y ) const;
00069 
00070     /// Get the width (maximum abscissa) of the curve
00071     int getWidth() const;
00072 
00073     /// Get the height (maximum ordinate) of the curve
00074     int getHeight() const;
00075 
00076 private:
00077     /// Number of control points
00078     int m_nbCtrlPt;
00079     /// vectors containing the coordinates of the control points
00080     vector<float> m_ptx;
00081     vector<float> m_pty;
00082     /// Vector containing precalculated factoriels
00083     vector<float> m_ft;
00084 
00085     /// Number of points (=pixels) used by the curve
00086     int m_nbPoints;
00087     /// Vectors with the coordinates of the different points of the curve
00088     vector<int> m_leftVect;
00089     vector<int> m_topVect;
00090     /// Vector with the percentages associated with the points of the curve
00091     vector<float> m_percVect;
00092 
00093     /// Return the index of the curve point that is the nearest from (x, y)
00094     int findNearestPoint( int x, int y ) const;
00095     /// Compute the coordinates of a point corresponding to a given
00096     /// percentage
00097     void computePoint( float t, int &x, int &y ) const;
00098     /// Helper function to compute a coefficient of the curve
00099     inline float computeCoeff( int i, int n, float t ) const;
00100     /// x^n
00101     static inline float power( float x, int n );
00102 };
00103 
00104 
00105 typedef CountedPtr<Bezier> BezierPtr;
00106 
00107 #endif

Generated on Tue May 25 08:04:58 2010 for VLC by  doxygen 1.5.6