fitcurve.h

Go to the documentation of this file.
00001 // $Id: fitcurve.h 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Header file for the functions
00099 
00100 
00101 #ifndef INC_FITCURVE
00102 #define INC_FITCURVE
00103 
00104 #include <math.h>
00105 
00106 /********************************************************************************************
00107 
00108 >   class FitPoint
00109 
00110     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00111     Created:    02/03/94
00112     Purpose:    This class is really a vector class that is used by the curve fitting
00113                 functions. It is also used as a coordinate class in the curve fitting
00114                 functions, but these are really regarded as vectors from the origin.
00115                 It has the following public member variables :-
00116                 MonoOn double x;        - The X coord of the vector MonoOff
00117                 MonoOn double y;        - The Y Coord of the vecotr MonoOff
00118 
00119 ********************************************************************************************/
00120 
00121 class FitPoint : public CC_CLASS_MEMDUMP
00122 {
00123     // Give my name in memory dumps
00124     CC_DECLARE_MEMDUMP(FitPoint);
00125 
00126 public:
00127     // Construction
00128     FitPoint() {}
00129     FitPoint(double cx, double cy) { x=cx; y=cy;}
00130     FitPoint(DocCoord coord) { x=coord.x; y=coord.y; }
00131     FitPoint(const FitPoint& Other) {x=Other.x; y=Other.y;}
00132 
00133     // destruction
00134     ~FitPoint() {}
00135 
00136     // operator =
00137     void operator = (const FitPoint& Other) { x=Other.x; y=Other.y; }
00138     void operator = (const DocCoord& Other) { x=Other.x; y=Other.y; }
00139 
00140     // Length Functions
00141     FitPoint SetLength( double NewLen );
00142 
00143     // Addition/Subtraction operators
00144     friend FitPoint operator + (const FitPoint& Point1, const FitPoint& Point2);
00145     friend FitPoint operator - (const FitPoint& Point1, const FitPoint& Point2);
00146 
00147     // Unary minus
00148     FitPoint operator - ();
00149 
00150     // Scale
00151     FitPoint operator * ( double Factor );
00152 
00153     // General geometry functions
00154     double SquaredLength()  { return (x*x + y*y); }
00155     double Length()         { return sqrt(x*x + y*y); }
00156     double Dot(const FitPoint& Other)   { return (Other.x*x + Other.y*y); }
00157 
00158     // Debug functions
00159     void Dump();
00160 
00161 public:
00162     double x;
00163     double y;
00164 };
00165 
00166 
00167 
00168 
00169 
00170 /********************************************************************************************
00171 
00172 >   class CurveFitObject : public CC_CLASS_MEMDUMP
00173 
00174     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00175     Created:    22/9/94
00176     Purpose:    Fits bezier curves to a serious of coordinates. Call the constructor,
00177                 Initialise and finally FitCurve to fit a bezier curve to the coords.
00178     SeeAlso:    FitPoint
00179 
00180 ********************************************************************************************/
00181 
00182 class CurveFitObject : public CC_CLASS_MEMDUMP
00183 {
00184     // Give my name in memory dumps
00185     CC_DECLARE_MEMDUMP(CurveFitObject);
00186 
00187 public:
00188     // Constructor that makes a note of things we will need to fit the curve
00189     CurveFitObject(Path* LongPath, double Error);
00190     ~CurveFitObject();
00191 
00192     // Strip useful points out of the path and puts them in the array
00193     BOOL Initialise(Path* CopyPath, INT32 NumPoints);
00194 
00195     // Fit the curve
00196     void FitCurve();
00197 
00198 // Private member functions to help out the above functions
00199 private:
00200     // The heart of the curve fitting code
00201     void FitCubic( INT32 FirstPoint, INT32 LastPoint, FitPoint Tangent1, FitPoint Tangent2,
00202                    BOOL IsStartCusp = TRUE, BOOL IsEndCusp = TRUE);
00203 
00204     // The function that does the actual maths
00205     void GenerateBezier( INT32 FirstPoint, INT32 LastPoint, FitPoint Tangent1, FitPoint Tangent2, FitPoint* Bezier );
00206 
00207     // Functions to determine how close a fit we have
00208     FitPoint BezierPoint( FitPoint* Bez, double u );
00209     double   CalcMaxError( INT32 FirstPoint, INT32 LastPoint, FitPoint* Bezier, INT32* SplitPoint );
00210 
00211     // Functions to find the tangents to the curve at various points
00212     FitPoint LeftTangent(INT32 Start);
00213     FitPoint RightTangent(INT32 End);
00214     FitPoint CentreTangent(INT32 Centre);
00215 
00216     // Functions to evaluate various components of the bezier function
00217     double Bezier0(double u) { double t=1.0-u; return (t*t*t); }
00218     double Bezier1(double u) { double t=1.0-u; return (3*u*t*t); }
00219     double Bezier2(double u) { double t=1.0-u; return (3*u*u*t); }
00220     double Bezier3(double u) { return (u*u*u); }
00221 
00222     // Functions to put curve elements into the path
00223     void InsertBezier( FitPoint* Bezier, BOOL, BOOL);
00224     void InsertLine( const DocCoord& Start, const DocCoord& End, FitPoint Tangent1, FitPoint Tangent2, BOOL, BOOL);
00225     void InsertStraightLine(const DocCoord& End);
00226 
00227 // Member vars
00228 private:
00229     // Pointers to the actual path object to get and store the points in and an array to
00230     // hold the coords that we will use in the smoothing process
00231     Path*       LongPath;
00232     DocCoord*   PathArray;
00233     INT32*      LineArray;
00234 
00235     // An array that holds the distance of each point from the start of the path
00236     INT32*      Distances;
00237 
00238     // The accuracy of the required fit. The larger this number, the smoother the fit.
00239     // Values of about 27,000,000 give smooth curves in millipoints at 100% zoom factor
00240     double      Error;
00241 
00242     // count of the total number of coordinates
00243     INT32       TotalCoords;
00244     INT32           TotalStraightLines;
00245 };
00246 
00247 /********************************************************************************************
00248 
00249 >   class FitCurveNoChangeGeometry : public CC_CLASS_MEMDUMP
00250 
00251     Author:     David_McClarnon (Xara Group Ltd) <camelotdev@xara.com>
00252     Created:    12/1/2000
00253     Purpose:    This class uses the fit curve functionality to reduce the number of points
00254                 in a path, whereas keeping the geometry as close to the original as possible
00255 
00256 ********************************************************************************************/
00257 class FitCurveNoChangeGeometry : public CC_CLASS_MEMDUMP
00258 {
00259     // Give my name in memory dumps
00260     CC_DECLARE_MEMDUMP(CurveFitObject);
00261 public:
00262     static void SmoothPath(Path * pPath, double Error);
00263 private:
00264     static void SmoothPathNoChangeGeometry(Path * pPath, double Error);
00265     static void EliminateColinearPointsFromPath(Path * pPath);
00266 } ;
00267 
00268 #endif
00269 
00270 

Generated on Sat Nov 10 03:45:20 2007 for Camelot by  doxygen 1.4.4