tracergn.h

Go to the documentation of this file.
00001 // $Id: tracergn.h 1282 2006-06-09 09:46: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 // This is the header file for the bitmap effect atom class
00099 
00100 #ifndef INC_TRACERGN
00101 #define INC_TRACERGN
00102 
00103 //#include "coord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "doccoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 
00106 class UndoableOperation;
00107 class Path;
00108 class KernelBitmap;
00109 class DocCoord;
00110 class BfxPixelOp;
00111 
00112 /********************************************************************************************
00113 
00114 >   class TraceBoundaryPoint : public Coord
00115 
00116     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00117     Created:    21/11/1994
00118     Purpose:    Implements the TraceRegion class.
00119 
00120 This is an exceedingly simple class used to store the coordinates of boundary points on the
00121 trace
00122 
00123 ********************************************************************************************/
00124 
00125 
00126 class TraceBoundaryPoint : public /*Coord*/ SimpleCCObject
00127 {
00128     friend class TraceRegion;
00129     
00130     inline void translate( const TraceBoundaryPoint & that);
00131 
00132     inline TraceBoundaryPoint(double x1, double y1) { x=x1; y=y1; };
00133     inline TraceBoundaryPoint() {};
00134     inline TraceBoundaryPoint(const TraceBoundaryPoint & that) {x=that.x; y=that.y;};
00135     inline TraceBoundaryPoint& operator=(const TraceBoundaryPoint & that) {x=that.x; y=that.y; return *this;};
00136 
00137     inline void operator = (const DocCoord& Other) { x=Other.x; y=Other.y; };
00138     inline BOOL operator==(const TraceBoundaryPoint& input) const { return ((input.x == x) && (input.y == y)); };
00139     inline BOOL operator!=(const TraceBoundaryPoint& input) const { return ((input.x != x) || (input.y != y));};
00140 
00141     void RotateDirection(const TraceBoundaryPoint & rotation);
00142 
00143     void Init() {x=0; y=0;}
00144     void Init(INT32 x1, INT32 y1) { x=x1; y=y1; };
00145     inline double SquaredLength()   { return (x*x + y*y); }
00146     inline double Length()          { return sqrt(x*x + y*y); }
00147     inline double Dot(const TraceBoundaryPoint& Other)  { return (Other.x*x + Other.y*y); }
00148 
00149     TraceBoundaryPoint SetLength( double NewLen );
00150 
00151     // Addition/Subtraction operators
00152     inline friend TraceBoundaryPoint operator + (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2);
00153     inline friend TraceBoundaryPoint operator - (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2);
00154 
00155     // Unary minus
00156     inline TraceBoundaryPoint operator - ();
00157 
00158     // Scale
00159     inline TraceBoundaryPoint operator * ( double Factor );
00160     inline TraceBoundaryPoint operator / ( double Factor );
00161 
00162     double x;
00163     double y;
00164 
00165     private:
00166     
00167 };
00168 
00169 /********************************************************************************************
00170 
00171 >   TraceBoundaryPoint TraceBoundaryPoint::operator - ()
00172 
00173     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & Alex
00174     Created:    02/03/94
00175     Returns:    A TraceBoundaryPoint that is the negative of this
00176     Purpose:    Unary Minus for a TraceBoundaryPoint (Vector)
00177 
00178 ********************************************************************************************/
00179 
00180 TraceBoundaryPoint TraceBoundaryPoint::operator - ()
00181 {
00182     TraceBoundaryPoint Result;
00183 
00184     // negate the vector
00185     Result.x = -x;
00186     Result.y = -y;
00187 
00188     // and return it
00189     return Result;
00190 }
00191 
00192 
00193 
00194 /********************************************************************************************
00195 
00196 >   TraceBoundaryPoint TraceBoundaryPoint::operator * (double Factor)
00197 
00198     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & Alex
00199     Created:    02/03/94
00200     Inputs:     Factor - the amount to scale the vector by
00201     Returns:    TraceBoundaryPoint - this vector multiplied by the Factor
00202     Purpose:    TraceBoundaryPoint Multiply function. This will multiply the vector by a constant
00203                 Factor. The result is returned
00204 
00205 ********************************************************************************************/
00206 
00207 TraceBoundaryPoint TraceBoundaryPoint::operator * (double Factor)
00208 {
00209     TraceBoundaryPoint Result;
00210 
00211     // Scale the vector by the factor
00212     Result.x = (x*Factor);
00213     Result.y = (y*Factor);
00214 
00215     // and return it
00216     return Result;
00217 }
00218 
00219 
00220 /********************************************************************************************
00221 
00222 >   TraceBoundaryPoint TraceBoundaryPoint::operator / (double Factor)
00223 
00224     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & Alex
00225     Created:    02/03/94
00226     Inputs:     Factor - the amount to scale the vector by
00227     Returns:    TraceBoundaryPoint - this vector divided by the Factor
00228     Purpose:    TraceBoundaryPoint Multiply function. This will divide the vector by a constant
00229                 Factor. The result is returned
00230 
00231 ********************************************************************************************/
00232 
00233 TraceBoundaryPoint TraceBoundaryPoint::operator / (double Factor)
00234 {
00235     TraceBoundaryPoint Result;
00236 
00237     // Scale the vector by the factor
00238     Result.x = (x/Factor);
00239     Result.y = (y/Factor);
00240 
00241     // and return it
00242     return Result;
00243 }
00244 
00245 
00246 /********************************************************************************************
00247 
00248 >   TraceBoundaryPoint operator + (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2)
00249 
00250     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & Alex
00251     Created:    02/03/94
00252     Inputs:     Point1 - The first TraceBoundaryPoint Vector
00253                 Point2 - The Second TraceBoundaryPoint vector
00254     Returns:    TraceBoundaryPoint - the TraceBoundaryPoint vector that is a combination of Point1 and Point2
00255     Purpose:    Adds two TraceBoundaryPoint vectors together. This function is a Friend of the TraceBoundaryPoint
00256                 class
00257 
00258 ********************************************************************************************/
00259 
00260 TraceBoundaryPoint operator + (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2)
00261 {
00262     TraceBoundaryPoint Result;
00263 
00264     // Add the two vector together
00265     Result.x = Point1.x + Point2.x;
00266     Result.y = Point1.y + Point2.y;
00267 
00268     // return the result
00269     return Result;
00270 }
00271 
00272 
00273 /********************************************************************************************
00274 
00275 >   TraceBoundaryPoint operator - (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2)
00276 
00277     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> & Alex
00278     Created:    02/03/94
00279     Inputs:     Point1 - The first TraceBoundaryPoint Vector
00280                 Point2 - The Second TraceBoundaryPoint vector
00281     Returns:    TraceBoundaryPoint - the TraceBoundaryPoint vector that is the first vector minus the second
00282                 vector
00283     Purpose:    Subtracts the two TraceBoundaryPoint vectors. This function is a Friend of the TraceBoundaryPoint
00284                 class
00285 
00286 ********************************************************************************************/
00287 
00288 TraceBoundaryPoint operator - (const TraceBoundaryPoint& Point1, const TraceBoundaryPoint& Point2)
00289 {
00290     TraceBoundaryPoint Result;
00291 
00292     // Subtract the two vector from each other
00293     Result.x = Point1.x - Point2.x;
00294     Result.y = Point1.y - Point2.y;
00295 
00296     // return the result
00297     return Result;
00298 }
00299 
00300 inline void TraceBoundaryPoint::translate(const TraceBoundaryPoint & that) { x+=that.x; y+=that.y;}
00301 
00302 /********************************************************************************************
00303 
00304 >   class TraceRegion : public CCObject
00305 
00306     Author:     Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
00307     Created:    21/11/1994
00308     Purpose:    Implements the TraceRegion class.
00309 
00310 This class takes a given point on a bitmap and produces a boundary trace for it. The boundary
00311 criterion currently imposed is 'not white'.
00312 
00313 ********************************************************************************************/
00314 
00315 #define TR_NUMDIRECTIONMASK (0x7)
00316 #define FIT_STEPS   10
00317 
00318 class TraceRegion : public CCObject
00319 {
00320     CC_DECLARE_DYNCREATE(TraceRegion);
00321 
00322     //TraceRegion(); constructors and destructors are simple
00323     //~TraceRegion();
00324 
00325     public:
00326 
00327     // Constructor & Destructor
00328     TraceRegion();
00329     ~TraceRegion();
00330 
00331     // External object interface
00332     BOOL UseBitmap(KernelBitmap * pBitmap);
00333     BOOL UsePath(Path * pPath);
00334     BOOL Trace(INT32 InitialX, INT32 InitialY, BfxPixelOp * thepBfxPixelOp);
00335 
00336     BOOL SetParams(double * pPixelError = NULL);
00337     BOOL GetParams(double * pPixelError = NULL);
00338 
00339     // For testing porpoises
00340     static void Test(UndoableOperation * Op);
00341 
00342     protected:
00343 
00344     // For testing porpoises
00345     BOOL TraceBoundary(DocCoord Origin,DocCoord Point1,DocCoord Point2);
00346 
00347     // Trace buffer management  
00348     BOOL FillBoundaryBuffer(BOOL * End);
00349     BOOL ProcessBoundaryBuffer(BOOL Done = FALSE);
00350     BOOL FindInitialPoint(BOOL * End);
00351     
00352     // Curve smoothing  
00353     void FitCubic(INT32 FirstPoint, INT32 LastPoint, TraceBoundaryPoint Tangent1, TraceBoundaryPoint Tangent2,
00354                   BOOL IsStartCusp, BOOL IsEndCusp);
00355     void GenerateBezier(INT32 FirstPoint, INT32 LastPoint, TraceBoundaryPoint Tangent1, 
00356                         TraceBoundaryPoint Tangent2, TraceBoundaryPoint* Bezier);
00357     
00358     TraceBoundaryPoint BezierPoint( TraceBoundaryPoint* Bez, double u);
00359     BOOL CalcMaxError(INT32 LeftPoint, INT32 RightPoint, TraceBoundaryPoint* Bezier,
00360                                  INT32* SplitPoint, double * MaxDist, INT32 Level);
00361     void Parameterize(INT32 FirstPoint, INT32 LastPoint);
00362 
00363     TraceBoundaryPoint LeftTangent(INT32 Start, INT32 Points);
00364     TraceBoundaryPoint RightTangent(INT32 End, INT32 Points);
00365     TraceBoundaryPoint CentreTangent(INT32 Centre, INT32 Points);
00366 
00367     // Path management  
00368     void InsertBezier(TraceBoundaryPoint* Bezier, BOOL IsStartCusp, BOOL IsEndCusp);
00369     void InsertLine(const DocCoord& Start, const DocCoord& End,BOOL IsStartCusp, BOOL IsEndCusp);
00370     void InsertStraightLine(const DocCoord& End);
00371 
00372     // Functions to evaluate various components of the bezier function
00373     double Bezier0(double u) { double t=1.0-u; return (t*t*t); }
00374     double Bezier1(double u) { double t=1.0-u; return (3*u*t*t); }
00375     double Bezier2(double u) { double t=1.0-u; return (3*u*u*t); }
00376     double Bezier3(double u) { return (u*u*u); }
00377 
00378 
00379     // Miscellaneous
00380     inline BOOL IsCuspDirectionChange(INT32 dir1, INT32 dir2);
00381 
00382 
00383     TraceBoundaryPoint * BoundaryBuffer;
00384     BfxPixelOp * pBfxPixelOp;
00385 
00386     KernelBitmap * Bitmap;
00387     INT32 xsize;
00388     INT32 ysize;
00389 
00390     TraceBoundaryPoint InitialPoint;
00391     TraceBoundaryPoint HeadPoint;
00392     INT32   InitialDirection;
00393     INT32 TailDirection;
00394     INT32 HeadDirection;
00395 
00396     TraceBoundaryPoint FirstBufferPoint;
00397 
00398     INT32 BoundaryTail;
00399     INT32 BoundaryHead;
00400     INT32 BoundaryRingMask;
00401     INT32 BoundaryRingSize;
00402 
00403     double Error;           // Squared error
00404     double PixelError;      // user i/f to error above
00405 
00406     BOOL VirginBuffer;
00407     BOOL VirginPath;
00408     BOOL AtCusp;
00409     BOOL TailCusp;
00410 
00411     Path * ThePath;
00412 
00413     TraceBoundaryPoint Directions[TR_NUMDIRECTIONMASK+1];   
00414     TraceBoundaryPoint DirectionPoint[TR_NUMDIRECTIONMASK+1][TR_NUMDIRECTIONMASK+1][4];
00415 
00416     double TValues[FIT_STEPS+1];
00417     INT32 TPoints[FIT_STEPS+1];
00418     TraceBoundaryPoint Q1[3], Q2[2];    // Q' & Q''
00419     INT32   NumTPoints;
00420 
00421 };
00422 
00423 inline BOOL TraceRegion::IsCuspDirectionChange(INT32 dir1, INT32 dir2)
00424         { return (((dir1-dir2+TR_NUMDIRECTIONMASK+2) & TR_NUMDIRECTIONMASK)>2); }
00425         // Returns TRUE iff (dir1 - dir2) MOD numberofdirections is neither -1, 0, nor 1, i.e. 90 degree or greater
00426         // path change
00427 
00428 
00429 #endif  // INC_TRACERGN
00430 
00431 

Generated on Sat Nov 10 03:47:13 2007 for Camelot by  doxygen 1.4.4