samplist.h

Go to the documentation of this file.
00001 // $Id: samplist.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 
00099 // CSampleList and CSampleItem header file
00100 
00101 #ifndef INC_SAMPLIST
00102 #define INC_SAMPLIST
00103 
00104 class CCObject;
00105 class DocCoord;
00106 class CXaraFileRecord;
00107 
00108 /********************************************************************************************
00109 
00110 >   class CSampleItem : public CCObject
00111 
00112     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00113     Created:    31/5/2000
00114 
00115     Purpose:    Brush sample data item class, records position, distance along the path and 
00116                 pressure at the point when it is recorded.
00117                 
00118     Notes:      
00119 ********************************************************************************************/
00120 
00121 class CSampleItem : public CCObject
00122 {
00123     CC_DECLARE_DYNAMIC(CSampleItem)
00124 
00125 public:
00126     CSampleItem();
00127     CSampleItem(DocCoord Coord, MILLIPOINT Distance, UINT32 Pressure);
00128     CSampleItem(const CSampleItem& Other);
00129     ~CSampleItem() {};
00130 
00131 public: // operator overrides
00132     CSampleItem operator=(const CSampleItem& Other);
00133     BOOL        operator==(const CSampleItem& Other);
00134 
00135 public: // other
00136     CSampleItem InterpolateItems(CSampleItem& Other, double Proportion);
00137     
00138     BOOL WriteNative(CXaraFileRecord* pRecord);
00139 
00140 public: // data - bit naughty but I'm in a hurry
00141     DocCoord    m_Coord;
00142     MILLIPOINT  m_Distance;
00143     UINT32      m_Pressure;
00144 
00145     // Special note - we only ever actually use the pressure data, so ignore the distance and position
00146 };
00147 
00148 
00149 typedef std::vector< CSampleItem >  SampleArray;
00150 
00151 /********************************************************************************************
00152 
00153 >   class CSampleData : public CCObject
00154 
00155     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00156     Created:    31/5/2000
00157 
00158     Purpose:    Base class to hold an array of CSampleItems.  
00159                 
00160     Notes:      
00161 ********************************************************************************************/
00162 
00163 class CSampleData : public CCObject
00164 {
00165     CC_DECLARE_DYNAMIC(CSampleData)
00166 public:
00167     CSampleData();
00168     ~CSampleData();
00169 
00170 public:  // overridables
00171     CSampleData* MakeCopy();
00172     virtual BOOL InitialiseData(size_t Size = 1000, UINT32 GrowBy = 50);  // initialises the list member, you need to do this.
00173     virtual BOOL CollectData(DocCoord Coord, UINT32 Pressure); 
00174     void FinishSampling();
00175 public: // access fns.
00176     BOOL    SetCollectionSampleRate(double Rate);
00177     double  GetCollectionSampleRate();
00178     BOOL    SetRetrievalSampleRate(double Rate);
00179     double  GetRetrievalSampleRate();
00180 
00181     void    SetSampleArray(SampleArray* pArray);
00182     SampleArray* GetSampleArray() { return m_pSampleData;}
00183     size_t  GetNumItems() {return m_NumItems;}
00184 
00185     UINT32  GetMaxPressure();
00186     void    SetMaxPressure(UINT32 Max);
00187 public: // manipulation functions
00188     BOOL ReverseData();
00189 
00190 public: // writes this data object to a record
00191     BOOL WriteNative(CXaraFileRecord* pRecord);
00192 
00193     void SetNumItemsFromArraySize(); // sets the number of items member
00194     BOOL ClipArray(size_t Size);       // sets the size of the data array - use with care!
00195 
00196 public: // array access fns.
00197     void Add(CSampleItem& Item);
00198     BOOL SetAt(UINT32 Index, CSampleItem& Item);
00199     BOOL InsertAt(UINT32 Index, CSampleItem& Item);
00200     BOOL SetNext(CSampleItem& Item, BOOL Grow = FALSE);
00201     BOOL SetPrev(CSampleItem& Item);
00202     BOOL RemoveAt(UINT32 Index);
00203     
00204     BOOL GetAt(UINT32 Index, CSampleItem* pItem);
00205     BOOL GetAtPos(double Index, CSampleItem* pItem);
00206     BOOL GetNext(CSampleItem* pItem);
00207     BOOL GetPrev(CSampleItem* pItem);
00208     
00209     INT32 GetCount();
00210     void FreeExtra();
00211 
00212 public: // array manipulation functions
00213     BOOL InsertNewData(UINT32 Index, CSampleData* pData);
00214     BOOL RemoveData(UINT32 StartIndex, UINT32 EndIndex, SampleArray* pArray = NULL);
00215 
00216 protected: // helper functions
00217     BOOL    SetInternalCollectionIndex(UINT32 IndexRequested);
00218     BOOL    SetInternalRetrievalIndex(UINT32 IndexRequested);
00219     BOOL    IncrementInternalIndex(double* CurrentIndex);
00220     BOOL    DecrementInternalIndex(double* CurrentIndex);
00221 
00222     BOOL    GetItemAtInternalIndex(double Index, CSampleItem* pItem);
00223 
00224 protected:  // resampling helper functins
00225     BOOL    ReSampleArray(SampleArray** ppArray, UINT32 NewNumItems);
00226     BOOL    InsertControlPoints(UINT32 Frequency, SampleArray* pOriginal, SampleArray* pNew);
00227     BOOL    RemoveControlPoints(UINT32 Frequency, SampleArray* pOriginal, SampleArray* pNew);
00228     BOOL    InterpolateItems(UINT32 StartIndex, UINT32 EndIndex, SampleArray* pArray);
00229     BOOL    GetArraySection(UINT32 StartIndex, UINT32 EndIndex, SampleArray* pArraySection);
00230 
00231 protected: // data
00232     SampleArray* m_pSampleData;  // the actual array
00233 
00234     double       m_CollectionInternalIndex;  // index into the array that we use for collection
00235     double       m_RetrievalInternalIndex;   // index into the array that we use for retrieval
00236 
00237     double       m_CollectionSampleRate; // determines the rate at which we set data
00238     double       m_RetrievalSampleRate;  // the rate at which we retrieve data
00239 
00240     UINT32       m_ElementSize; // size of each item in the array
00241 
00242     size_t       m_NumItems;
00243 
00244     UINT32       m_MaxPressure; // the maximum possible value allowed by the pressure device
00245                                     // during collection
00246     double       m_ScalePressure; // the value that will scale the local pressure value to the
00247                                   // globally defined range
00248     
00249 };
00250 
00251 /********************************************************************************************
00252 
00253 >   class CDistanceSampler : public CSampleData
00254 
00255     Author:     Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
00256     Created:    31/5/2000
00257 
00258     Purpose:    Derived class which has a method to sample data over distances.  Basically
00259                 what you want to do is initialise the object, set the sample distances, then 
00260                 pass in data to the CollectData method and this object will sample at the
00261                 appropriate rate
00262                 
00263     Notes:      
00264 ********************************************************************************************/
00265 
00266 class CDistanceSampler : public CSampleData
00267 {
00268     CC_DECLARE_DYNAMIC(CDistanceSampler)
00269 
00270 public:
00271     CDistanceSampler();
00272     ~CDistanceSampler();
00273 
00274 public: // overridables
00275     CDistanceSampler* MakeCopy();
00276     virtual BOOL CollectData(DocCoord Coord, UINT32 Pressure);
00277 
00278 public: 
00279     BOOL SetSampleDistance(MILLIPOINT Distance);
00280     MILLIPOINT GetSampleDistance();
00281 
00282     BOOL SetSampleRateFromSpacing(MILLIPOINT Spacing);
00283                 // sets the retrieval sample rate from a given brush spacing            
00284 
00285     INT32 GetInternalIndexFromDistance(MILLIPOINT Distance);
00286                 // gets the internal index at the given distance            
00287 
00288     BOOL GetDataSection(MILLIPOINT Start, MILLIPOINT End, CDistanceSampler* pSection);
00289                 // retrieves a section of data and wraps it up for us           
00290 
00291     BOOL ReSample(MILLIPOINT NewLength);  
00292                 // stretches or shrinks our data to fit a new length
00293 
00294     UINT32 m_ItemsInserted;
00295 
00296     double  GetDistanceRep () { return ((double) m_DistanceSoFar); }
00297     void SetDistanceSoFar (double val) { m_DistanceSoFar = (MILLIPOINT) val; }
00298 protected: // data
00299     MILLIPOINT  m_SampleDistance;  // the distance at which we want to take each sample
00300     
00301     CSampleItem m_LastItemStored;        // the last item we inserted
00302     CSampleItem m_LastItem;              // the last item we receieved
00303     DocCoord    m_LastCoord;       // the last coordinate we received
00304     MILLIPOINT  m_DistanceSinceLastSample;  // pretty much what you might expect, given the name
00305     MILLIPOINT  m_DistanceSoFar;
00306 
00307     double      m_ItemRemainder;
00308 
00309     MILLIPOINT  m_TotalDistance;
00310     MILLIPOINT  m_DistanceSinceLastData;
00311 
00312 };
00313 
00314 #endif

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