CSampleData Class Reference

Base class to hold an array of CSampleItems. More...

#include <samplist.h>

Inheritance diagram for CSampleData:

CCObject SimpleCCObject CDistanceSampler List of all members.

Public Member Functions

 CSampleData ()
 default constructor
 ~CSampleData ()
 destructor, cleans out the list
CSampleDataMakeCopy ()
 Makes a copy of this sample data.
virtual BOOL InitialiseData (size_t Size=1000, UINT32 GrowBy=50)
 creates the list member variable
virtual BOOL CollectData (DocCoord Coord, UINT32 Pressure)
 This is the function you should override in you derived classes to do the sampling with. For an example see CDistanceSampler::CollectData.
void FinishSampling ()
 Tells the object that sampling has finished. As a security precaution we will add an extra 10 * m_RetrievalSampleRates worth of entries. The real reason for this hack is that once the path is entered it is then smoothed, which causes the path length to increase. Since we never sampled over this increased length we need to kind of pretend that we did.
BOOL SetCollectionSampleRate (double Rate)
 Sets the sample rate to use for collecting data. Note that for current purposes this is only allowed to be 1. So you probably won't be using this function very often.
double GetCollectionSampleRate ()
 as above
BOOL SetRetrievalSampleRate (double Rate)
 Sets the sample rate to use for retrieving data,.
double GetRetrievalSampleRate ()
 as above
void SetSampleArray (SampleArray *pArray)
 sets the given array to use as our sample data
SampleArrayGetSampleArray ()
size_t GetNumItems ()
UINT32 GetMaxPressure ()
 as above
void SetMaxPressure (UINT32 Max)
 To set our max pressure member. Do this by querying the WinTab device BEFORE you start collecting data.
BOOL ReverseData ()
 Reverses the items in the data array, or rather just copies them into a new one.
BOOL WriteNative (CXaraFileRecord *pRecord)
 Writes out the data contained in this SampleData to a record.
void SetNumItemsFromArraySize ()
 Sets the num items member from the size of the array. Note that you should never really use this unless you are certain that a) your current m_NumItems is incorrect and b)You are certain that your array contains nothing but valid data. An example of when you should use this is if you decide to set the array from out side, rather than collect it through sampling. And you really shouldn't be doing that either.
BOOL ClipArray (size_t Size)
 Clips the array to be the desired size, be careful with this as you will lose all data beyond the Size'th index.
void Add (CSampleItem &Item)
 adds a new item to the end of the array
BOOL SetAt (UINT32 Index, CSampleItem &Item)
 inserts Item at Index
BOOL InsertAt (UINT32 Index, CSampleItem &Item)
BOOL SetNext (CSampleItem &Item, BOOL Grow=FALSE)
 Increments our internal index and then inserts a new item at that position. If we hit the end of the array then we will add an element, so long as our flag is set Notes:.
BOOL SetPrev (CSampleItem &Item)
 Decrements our internal index and then inserts Item into the array.
BOOL RemoveAt (UINT32 Index)
 Removes item at Index.
BOOL GetAt (UINT32 Index, CSampleItem *pItem)
 Retrieves the item at Index.
BOOL GetAtPos (double Index, CSampleItem *pItem)
BOOL GetNext (CSampleItem *pItem)
 Increments the internal index, then retrieves the item at that index.
BOOL GetPrev (CSampleItem *pItem)
 Decrements our internal index and retrieves the item at that position.
INT32 GetCount ()
 To find the number of items in the array.
void FreeExtra ()
 Asks the array to free any unused memory above its current upper bound. Recommneded that you call this if you do a big SetSize and don't use it all.
BOOL InsertNewData (UINT32 Index, CSampleData *pData)
 To insert pData into our data array at Index. This function does the shuffling of existing array elements in order to insert the new data.
BOOL RemoveData (UINT32 StartIndex, UINT32 EndIndex, SampleArray *pArray=NULL)
 To remove all the items between StartIndex and EndIndex, and optionally record them in pArray.

Protected Member Functions

BOOL SetInternalCollectionIndex (UINT32 IndexRequested)
 Sets our collection internal array index to the position corresponding to the requested index.
BOOL SetInternalRetrievalIndex (UINT32 IndexRequested)
 Sets our Retrieval internal array index to the position corresponding to the requested index.
BOOL IncrementInternalIndex (double *CurrentIndex)
BOOL DecrementInternalIndex (double *CurrentIndex)
 Decrements our internal array pointer and index counter, unless we have reached the start of the array in which case we set it to -1.
BOOL GetItemAtInternalIndex (double Index, CSampleItem *pItem)
 Retrieves the item in the array indicated by the current internal index. Note that it is possible that this index may not be an integer in which case this function will generate a new CSampleItem by interpolation.
BOOL ReSampleArray (SampleArray **ppArray, UINT32 NewNumItems)
 Resamples the data in the sample array so that we end up with NewNumItems in the section required. We will do this by selecting some resampling points in the original array, maintain these points at the same proportional position and interpolate to get the new points.
BOOL InsertControlPoints (UINT32 Frequency, SampleArray *pOriginal, SampleArray *pNew)
 As part of the ReSampleArray process this function takes the case where we need to increase the number of control points. It therefore proceeds through the original array copying control points over at the same proportional position as they were in the original array.
BOOL RemoveControlPoints (UINT32 Frequency, SampleArray *pOriginal, SampleArray *pNew)
BOOL InterpolateItems (UINT32 StartIndex, UINT32 EndIndex, SampleArray *pArray)
 Interpolates between the two indexes in the array, creating intermediate items and inserting them.
BOOL GetArraySection (UINT32 StartIndex, UINT32 EndIndex, SampleArray *pArraySection)
 To copy the data from the section specified into a new array that we will create.

Protected Attributes

SampleArraym_pSampleData
double m_CollectionInternalIndex
double m_RetrievalInternalIndex
double m_CollectionSampleRate
double m_RetrievalSampleRate
UINT32 m_ElementSize
size_t m_NumItems
UINT32 m_MaxPressure
double m_ScalePressure

Detailed Description

Base class to hold an array of CSampleItems.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Notes:

Definition at line 163 of file samplist.h.


Constructor & Destructor Documentation

CSampleData::CSampleData  ) 
 

default constructor

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
this object
Notes:

Definition at line 318 of file samplist.cpp.

00319 {
00320     m_pSampleData = NULL;
00321     m_CollectionSampleRate = 1.0;
00322     m_RetrievalSampleRate  = 1.0;
00323     m_CollectionInternalIndex = 0;
00324     m_RetrievalInternalIndex  = 0;
00325     m_NumItems                = 0;
00326     m_MaxPressure             = 0;
00327     m_ElementSize = (UINT32)sizeof(CSampleItem);
00328 }

CSampleData::~CSampleData  ) 
 

destructor, cleans out the list

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
Notes:

Definition at line 345 of file samplist.cpp.

00346 {
00347     if (m_pSampleData != NULL)
00348     {
00349         m_pSampleData->clear();
00350         delete m_pSampleData;
00351         m_pSampleData = NULL;
00352     }
00353 }


Member Function Documentation

void CSampleData::Add CSampleItem Item  ) 
 

adds a new item to the end of the array

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Item - the item to insert [INPUTS]
- [OUTPUTS]
Returns:
-
Notes:

Definition at line 488 of file samplist.cpp.

00489 {
00490     if (m_pSampleData != NULL)
00491         m_pSampleData->push_back(Item);
00492     m_NumItems++;
00493 
00494 }

BOOL CSampleData::ClipArray size_t  Size  ) 
 

Clips the array to be the desired size, be careful with this as you will lose all data beyond the Size'th index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
Size - the desired array size [INPUTS]
Returns:
TRUE unless Size is bigger than the array we have

Definition at line 1553 of file samplist.cpp.

01554 {
01555     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is NULL in CSampleData::ClipArray");
01556     ERROR2IF(Size > (UINT32)m_pSampleData->size(), FALSE, "Attempting to clip over the end of the array in CSampleData::ClipArray");
01557 
01558     m_pSampleData->resize( Size );
01559     if (m_NumItems > Size)
01560         m_NumItems = Size;
01561 
01562     return TRUE;
01563 }

BOOL CSampleData::CollectData DocCoord  Coord,
UINT32  Pressure
[virtual]
 

This is the function you should override in you derived classes to do the sampling with. For an example see CDistanceSampler::CollectData.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Coord - the coordinate data [INPUTS] Pressure - the pressure data
- [OUTPUTS]
Returns:
always TRUE in the base class
Notes:

Reimplemented in CDistanceSampler.

Definition at line 464 of file samplist.cpp.

00465 {
00466     return TRUE;
00467 }

BOOL CSampleData::DecrementInternalIndex double *  pCurrentIndex  )  [protected]
 

Decrements our internal array pointer and index counter, unless we have reached the start of the array in which case we set it to -1.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
pCurrentIndex - the index to be decremented, this should really only be either [INPUTS] the collection index or the retrieval index
- [OUTPUTS]
Returns:
TRUE, unless something went wrong

Definition at line 1161 of file samplist.cpp.

01162 {
01163     // not allowed to use indexes that aren't one of our members, also 
01164     // find out which sample rate to use here
01165     double SampleRate = 1.0;
01166     if (pCurrentIndex == &m_CollectionInternalIndex)
01167     {
01168         SampleRate = m_CollectionSampleRate;
01169     }
01170     else if (pCurrentIndex == &m_RetrievalInternalIndex)
01171     {
01172         SampleRate = m_RetrievalSampleRate;
01173     }
01174     else
01175     {
01176         ERROR3("Attempting to use non-member index in CSampleData::DecrementInternalIndex");
01177         return FALSE;
01178     }
01179 
01180     // we need to have valid sample data
01181     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is null in CSampleData::DecrementInternalIndex");
01182 
01183     double TestIndex = *pCurrentIndex - SampleRate;
01184     if (TestIndex > 0)
01185     {
01186         *pCurrentIndex -= SampleRate;
01187     }
01188     else
01189     {
01190         *pCurrentIndex = -1;
01191     }
01192     return TRUE;
01193 }

void CSampleData::FinishSampling  ) 
 

Tells the object that sampling has finished. As a security precaution we will add an extra 10 * m_RetrievalSampleRates worth of entries. The real reason for this hack is that once the path is entered it is then smoothed, which causes the path length to increase. Since we never sampled over this increased length we need to kind of pretend that we did.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
- [INPUTS]
Returns:
-

Definition at line 1487 of file samplist.cpp.

01488 {
01489     if (m_pSampleData != NULL)
01490     {
01491         // find out how many items to insert
01492         UINT32 NumExtraItems = (UINT32)(m_RetrievalSampleRate * 10);
01493         
01494         // get the last item we inserted
01495         UINT32 InsertIndex = (UINT32)m_CollectionInternalIndex;
01496         CSampleItem TheItem = (*m_pSampleData)[InsertIndex];
01497         
01498         // make sure the array is big enough
01499         UINT32 CurrentSize = (INT32)m_pSampleData->size();
01500         if (CurrentSize < InsertIndex+NumExtraItems)
01501         {
01502             m_pSampleData->resize( CurrentSize + NumExtraItems );
01503         }
01504 
01505     
01506 
01507         for (UINT32 i = 1; i <= NumExtraItems; i++)
01508         {
01509             (*m_pSampleData)[InsertIndex + i] = TheItem;
01510             m_NumItems++;
01511         }
01512     }
01513 }

void CSampleData::FreeExtra  ) 
 

Asks the array to free any unused memory above its current upper bound. Recommneded that you call this if you do a big SetSize and don't use it all.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 853 of file samplist.cpp.

00854 {
00855     if (m_pSampleData != NULL)
00856         m_pSampleData->resize( (INT32)m_NumItems );
00857 }

BOOL CSampleData::GetArraySection UINT32  StartIndex,
UINT32  EndIndex,
SampleArray pSection
[protected]
 

To copy the data from the section specified into a new array that we will create.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/2000
Parameters:
StartIndex - the internal index at which to start the resampling [INPUTS] EndIndex - the internal index to finish the resampling pSection - a to an allocated sample array
Allocatest the array and fills it with data from the section [OUTPUTS]
Returns:
TRUE if successful, FALSE if something went wrong

Errors: if StartIndex or EndIndex are invalid, or if we don't have a sample array

Definition at line 1713 of file samplist.cpp.

01714 {
01715     // check our input conditions
01716     ERROR2IF(pSection == NULL, FALSE, "Sample array is NULL in CSampleData::GetArraySection");
01717     if (EndIndex <= StartIndex || EndIndex > m_NumItems)
01718     {
01719         ERROR3("Invalid indexes in CSampleData::GetArraySection");
01720         return FALSE;
01721     }
01722     
01723     UINT32 NumItems = EndIndex - StartIndex;
01724     pSection->resize(NumItems);
01725 
01726     // we want to make sure we retrieve all the items
01727     m_RetrievalSampleRate = 1.0;
01728 
01729     // We have to do the first one manually, due to my rather clumsy implementation
01730     CSampleItem TheItem;
01731     BOOL ok = GetAt(StartIndex, &TheItem);
01732     if (ok) 
01733         (*pSection)[0] =  TheItem;
01734     else
01735         ERROR3("Failed to retrieve first item in CSampleData::GetArraySection");
01736     
01737     UINT32 Counter = 1;
01738     while (ok && (Counter < NumItems))
01739     {
01740         ok = GetNext(&TheItem);
01741         (*pSection)[Counter] = TheItem;
01742         Counter++;
01743     }
01744     
01745     // Did we copy the right number of items?
01746     if (Counter != NumItems)
01747     {
01748         ERROR3("Error copying data in CSampleData::GetArraySection");
01749         ok = FALSE;
01750     }
01751     else
01752         ok = TRUE;
01753     return ok;
01754 }

BOOL CSampleData::GetAt UINT32  Index,
CSampleItem pItem
 

Retrieves the item at Index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Index - the index to retrieve from [INPUTS]
pItem - the item at index [OUTPUTS]
Returns:
TRUE if successful, FALSE if Index is invalid or there is no array
Notes: All the access functions set the m_ListPosition member variable which records the last list positon accessed. This means that you can the use GetNext or GetPrev to retrieve subsequent elements, which is much quicker than using GetAt all the time.

Definition at line 695 of file samplist.cpp.

00696 {
00697     ERROR2IF(pItem == NULL, FALSE, "Item pointer is NULL in CSampleData::GetAt");
00698 
00699     if (m_pSampleData != NULL)
00700     {
00701         if (SetInternalRetrievalIndex(Index))
00702         {
00703             //TRACEUSER( "Diccon", _T("Get At: "));
00704             CSampleItem TheItem;
00705             if (GetItemAtInternalIndex(m_RetrievalInternalIndex, &TheItem))
00706                 *pItem = TheItem;
00707             return TRUE;
00708         }
00709         else
00710             ERROR3("Trying to access element over the end of the array in CSampleData::GetAt"); 
00711     }
00712     return FALSE;
00713 }

BOOL CSampleData::GetAtPos double  Index,
CSampleItem pItem
 

Definition at line 715 of file samplist.cpp.

00716 {
00717     ERROR2IF(pItem == NULL, FALSE, "Item pointer is NULL in CSampleData::GetAt");
00718 
00719     if (m_pSampleData != NULL)
00720     {
00721         //if (SetInternalRetrievalIndex(Index))
00722         {
00723             //TRACEUSER( "Diccon", _T("Get At: "));
00724 
00725             UINT32 rounded = (UINT32) Index;
00726 
00727             CSampleItem TheItem;
00728             if (GetItemAtInternalIndex((double) rounded, &TheItem))
00729                 *pItem = TheItem;
00730             return TRUE;
00731         }
00732         //else
00733         //  ERROR3("Trying to access element over the end of the array in CSampleData::GetAt"); 
00734     }
00735     return FALSE;
00736 }

double CSampleData::GetCollectionSampleRate  ) 
 

as above

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
the current collection sample rate

Definition at line 1302 of file samplist.cpp.

01303 {
01304     return m_CollectionSampleRate;
01305 }

INT32 CSampleData::GetCount void   ) 
 

To find the number of items in the array.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
the number of items in the array, or -1 if the array does not exist

Definition at line 831 of file samplist.cpp.

00832 {
00833     if (m_pSampleData != NULL)
00834         return (INT32)m_pSampleData->size();
00835 
00836     return -1;
00837 }

BOOL CSampleData::GetItemAtInternalIndex double  Index,
CSampleItem pItem
[protected]
 

Retrieves the item in the array indicated by the current internal index. Note that it is possible that this index may not be an integer in which case this function will generate a new CSampleItem by interpolation.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Index - the index to get the value from. Note that this does not have to be [INPUTS] an integer, should really be the collection or retrieval index only
pointer to item retrieved [OUTPUTS]
Returns:
TRUE if all went well, FALSE if we don't have an array or the index is invalid

Definition at line 1212 of file samplist.cpp.

01213 {
01214     // no reason why you shouldn't be using this function on values other than our member
01215     // indexes but that is not the intended purpose of this fn. hence the ERROR3
01216     //if (Index != m_CollectionInternalIndex && Index != m_RetrievalInternalIndex)
01217 //      ERROR3("Attempting to use non-member index in CSampleData::GetItemAtInternalIndex");
01218 
01219     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is null in CSampleData::GetItemAtInternalIndex");
01220 
01221     BOOL Retval = FALSE;
01222     //TRACEUSER( "Diccon", _T("Retrieving item at %f\n"), Index);
01223 
01224     double UpperBound = (double)m_pSampleData->size() - 1;
01225     
01226     // If our index is -1 then we have run off the end of the array, so return the last item
01227     if (Index == -1)
01228         Index = UpperBound;
01229 
01230     if (Index <= UpperBound)
01231     {
01232         size_t LowIndex = (UINT32)Index;
01233         if (LowIndex > m_NumItems)
01234             //ERROR3("Attempting to access data that has not been collected in CSampleData::GetItemAtInternalIndex");
01235             LowIndex = m_NumItems; //bodge alert!
01236 
01237         UINT32 HighIndex = (UINT32)Index+1;
01238         if (HighIndex < m_NumItems)
01239         {
01240             double Proportion = Index - (double)LowIndex;
01241             CSampleItem LowItem = (*m_pSampleData)[LowIndex];
01242             CSampleItem HighItem = (*m_pSampleData)[HighIndex];
01243             CSampleItem NewItem = LowItem.InterpolateItems(HighItem, (1-Proportion));
01244             //TRACEUSER( "Diccon", _T("Lo = %d, Hi = %d, Prop  =%f, Pressure = %d\n"), LowIndex, HighIndex, Proportion, NewItem.m_Pressure);
01245             *pItem = NewItem;
01246         }
01247         else
01248             *pItem = (*m_pSampleData)[LowIndex];
01249         
01250         Retval = TRUE;
01251     }
01252     else
01253         ERROR3("Internal index is over the end of the array in CSampleData::GetItemAtInternalIndex");
01254     
01255     return Retval;
01256 }

UINT32 CSampleData::GetMaxPressure  ) 
 

as above

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
the maximum pressure value allowed by the device sending the pressure data

Definition at line 1392 of file samplist.cpp.

01393 {
01394     return m_MaxPressure;
01395 }

BOOL CSampleData::GetNext CSampleItem pItem  ) 
 

Increments the internal index, then retrieves the item at that index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
pItem - the tail item [OUTPUTS]
Returns:
TRUE if successful, FALSE if we are at the end of the array or it doesn't exist
Notes: It is recommended that you do a GetAt before you start doing GetNexts, otherwise I won't vouch for the position of the value of the internal index

Definition at line 756 of file samplist.cpp.

00757 {
00758     BOOL Retval = FALSE;
00759     if (m_pSampleData != NULL)
00760     {
00761         //TRACEUSER( "Diccon", _T("Get Next: "));
00762         if (IncrementInternalIndex(&m_RetrievalInternalIndex))
00763         {
00764             // BODGE ALERT! if the retrieval index is -1 then this indicates that we
00765             // have reached the end of the array! However I am letting it pass on, 
00766             // and have inserted more bodge code at GetItemAtInternalIndex to return
00767             // the last item.
00768             
00769         //  if (m_RetrievalInternalIndex == -1.0)
00770         //      ERROR3("Invalid index in CSampleData::GetNext");
00771 
00772             {
00773                 if (GetItemAtInternalIndex(m_RetrievalInternalIndex, pItem))
00774                     Retval = TRUE;
00775             }
00776         }
00777         else
00778             ERROR3("Unable to increment index in CSampleData::GetNext");
00779     }
00780 
00781     return Retval;      
00782 }

size_t CSampleData::GetNumItems  )  [inline]
 

Definition at line 183 of file samplist.h.

00183 {return m_NumItems;}

BOOL CSampleData::GetPrev CSampleItem pItem  ) 
 

Decrements our internal index and retrieves the item at that position.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
pItem - the previous item in the array [OUTPUTS]
Returns:
TRUE if successful, FALSE if we are at the start of the array or it doesn't exist
Notes: Really only works if the internal index has been set by a previous function such as GetAt, SetAt, etc.

Definition at line 799 of file samplist.cpp.

00800 {
00801     BOOL Retval = FALSE;
00802     if (m_pSampleData != NULL)
00803     {
00804         if (DecrementInternalIndex(&m_RetrievalInternalIndex))
00805         {
00806             if (m_RetrievalInternalIndex != -1.0)
00807             {
00808                 if (GetItemAtInternalIndex(m_RetrievalInternalIndex, pItem))
00809                     Retval = TRUE;
00810             }   
00811         }
00812         else
00813             ERROR3("Unable to decrement index in CSampleData::GetPrev");
00814     }
00815     return Retval;
00816 }

double CSampleData::GetRetrievalSampleRate  ) 
 

as above

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
the current Retrieval sample rate

Definition at line 1351 of file samplist.cpp.

01352 {
01353     return m_RetrievalSampleRate;
01354 }

SampleArray* CSampleData::GetSampleArray  )  [inline]
 

Definition at line 182 of file samplist.h.

00182 { return m_pSampleData;}

BOOL CSampleData::IncrementInternalIndex double *  CurrentIndex  )  [protected]
 

Definition at line 1102 of file samplist.cpp.

01103 {
01104     // if we've already overrun then don't go any further
01105     if (*pCurrentIndex == -1)
01106         return TRUE;
01107 
01108     // not allowed to use indexes that aren't one of our members, also 
01109     // find out which sample rate to use here
01110     double SampleRate = 1.0;
01111     if (pCurrentIndex == &m_CollectionInternalIndex)
01112     {
01113         SampleRate = m_CollectionSampleRate;
01114     }
01115     else if (pCurrentIndex == &m_RetrievalInternalIndex)
01116     {
01117         SampleRate = m_RetrievalSampleRate;
01118     }
01119     else
01120     {
01121         ERROR3("Attempting to use non-member index in CSampleData::IncrementInternalIndex");
01122         return FALSE;
01123     }
01124 
01125     // we need to have valid sample data
01126     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is null in CSampleData::IncrementInternalIndex");
01127 
01128     double TestIndex = *pCurrentIndex + SampleRate;
01129     //  TRACEUSER( "Diccon", _T("  Internal index = %f"), TestIndex);
01130     //  TRACEUSER( "Diccon", _T(", Upper bound = %f\n"), (double)(m_pSampleData->size() - 1));
01131     if (TestIndex <= (double)(m_pSampleData->size() - 1))
01132     {
01133         *pCurrentIndex += SampleRate;
01134     }
01135     else
01136     {
01137         
01138     //  TRACEUSER( "Diccon", _T("END OF ARRAY, Test index = %f, Num items = %d\n"), TestIndex, m_NumItems);
01139         *pCurrentIndex = -1;
01140         
01141     }
01142     
01143     
01144     return TRUE;
01145 }

BOOL CSampleData::InitialiseData size_t  Size = 1000,
UINT32  GrowBy = 50
[virtual]
 

creates the list member variable

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if we initialised ok, FALSE if we didn't get the memory
Notes:

Definition at line 425 of file samplist.cpp.

00426 {
00427     // if we've already got a list then delete it
00428     if (m_pSampleData != NULL)
00429     {
00430         m_pSampleData->clear();
00431         delete m_pSampleData;
00432         m_pSampleData = NULL;
00433     }
00434     m_pSampleData = new SampleArray;
00435 
00436     if (m_pSampleData == NULL)
00437         return FALSE;
00438 
00439     if( Size < m_pSampleData->size() + GrowBy )
00440         Size = m_pSampleData->size() + GrowBy;
00441 
00442     m_pSampleData->resize( Size );
00443 
00444     return TRUE;
00445 }

BOOL CSampleData::InsertAt UINT32  Index,
CSampleItem Item
 

BOOL CSampleData::InsertControlPoints UINT32  Frequency,
SampleArray pOriginal,
SampleArray pNew
[protected]
 

As part of the ReSampleArray process this function takes the case where we need to increase the number of control points. It therefore proceeds through the original array copying control points over at the same proportional position as they were in the original array.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/2000
Parameters:
Frequency - the number of indexes per control point. i.e. 4 = a control point [INPUTS] every 4th index. pOriginal - the original array pNew - the new array, this MUST be allocated AND sized
Returns:
TRUE if successful, FALSE if something went wrong

Definition at line 1666 of file samplist.cpp.

01667 {
01668     ERROR2IF(pOriginal == NULL, FALSE, "Original array is NULL in CSampleData::InsertControlPoints");
01669     ERROR2IF(pNew      == NULL, FALSE, "New array is NULL in CSampleData::InsertControlPoints");
01670 
01671     double NumOrigItems = (double)pOriginal->size();
01672     double NumNewItems  = (double)pNew->size();
01673 
01674     INT32    OrigIndex = 0;
01675     double dOrigIndex = 0;
01676     INT32 NewIndex  = 0;
01677 
01678     CSampleItem TheItem;
01679     double OrigProportion;
01680     while (OrigIndex < NumOrigItems)
01681     {
01682         TheItem = (*pOriginal)[OrigIndex];
01683         OrigProportion = dOrigIndex / NumOrigItems;
01684         NewIndex = (INT32)(OrigProportion * NumNewItems);
01685         if (NewIndex < NumNewItems)
01686             (*pNew)[NewIndex] = TheItem;
01687         else
01688             ERROR3("Attempting to set over the end of the new array in CSampleData::InsertControlPoints");
01689         OrigIndex += Frequency;
01690         dOrigIndex += Frequency;
01691     }
01692     return TRUE;
01693 }

BOOL CSampleData::InsertNewData UINT32  Index,
CSampleData pData
 

To insert pData into our data array at Index. This function does the shuffling of existing array elements in order to insert the new data.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Index - the index to insert at [INPUTS] pData - array of items to insert
- [OUTPUTS]
Returns:
TRUE if successful

Definition at line 874 of file samplist.cpp.

00875 {
00876     ERROR2IF(pData == NULL, FALSE, "Attempting to insert null array in CSampleData::InsertNewData");
00877     ERROR2IF(m_pSampleData == NULL, FALSE, "Member data array is NULL in CSampleData::InsertNewData");
00878 
00879     if (Index > m_pSampleData->size() - 1)
00880     {
00881         ERROR3("Attempting to insert beyond end of array in CSampleData::InsertNewData");
00882         return FALSE;
00883     }
00884 
00885     // find out how many elements we are inserting
00886     INT32 NumNewItems = (INT32)pData->GetNumItems();
00887     if (NumNewItems <= 0)
00888     {
00889         ERROR3("Attempting to insert zero or fewer elements in BOOL CSampleData::InsertNewData");
00890         return FALSE;
00891     }
00892 
00893     // Set our sample rates to 1.0 so that we don't skip any elements
00894     m_CollectionSampleRate = 1.0;
00895     m_RetrievalSampleRate  = 1.0;
00896     pData->SetRetrievalSampleRate(1.0);
00897     // work out how many elements we have to move
00898     size_t NumMoveItems = m_pSampleData->size() - 1 - Index;
00899 
00900         // this keeps track of where we're moving from
00901     UINT32 MoveIndex = (UINT32)m_pSampleData->size() - 1;
00902     m_NumItems = m_pSampleData->size() + NumNewItems;
00903     // extend our array so we have room for the new data
00904     m_pSampleData->resize((INT32)m_NumItems);
00905 
00906     // start at the tail and work down, shifting existing elements up to make room
00907     CSampleItem TheItem;
00908     BOOL KeepGoing = GetAt(MoveIndex, &TheItem);
00909 //  TRACEUSER( "Diccon", _T("SHIFTING %d ITEMS UP FROM %d TO %d\n"), NumMoveItems, MoveIndex-NumMoveItems, MoveIndex-NumMoveItems + NumNewItems);
00910     while (NumMoveItems && KeepGoing)
00911     {
00912         // copy the item to its place further up in the array
00913         (*m_pSampleData)[MoveIndex + NumNewItems] = TheItem;
00914         // get the next item
00915         KeepGoing = GetPrev(&TheItem);
00916         MoveIndex--;
00917         NumMoveItems--;
00918     }
00919 //  TRACEUSER( "Diccon", _T("FINISHED SHIFTING UP\n"));
00920     // now we can insert our new data at Index
00921 
00922     // get the first item and set it, so we can use GetNext for each array
00923     KeepGoing = pData->GetAt(0, &TheItem);
00924     if (KeepGoing)
00925         SetAt(Index, TheItem);
00926     UINT32 Counter = 0;
00927 //  TRACEUSER( "Diccon", _T("INSERTING NEW DATA\n"));
00928     while (NumNewItems && KeepGoing)
00929     {
00930         if (KeepGoing) KeepGoing = pData->GetNext(&TheItem);
00931         if (KeepGoing)  SetNext(TheItem);
00932         //TRACEUSER( "Diccon", _T("Inserting item %d\n"), TheItem.m_Pressure);
00933         NumNewItems--;
00934         Counter++;
00935     }
00936     
00937     //TRACEUSER( "Diccon", _T("Added %d items at index %d\n"), Counter, Index);
00938     // hopefully that should have done the trick!
00939 
00940     return TRUE;
00941 }

BOOL CSampleData::InterpolateItems UINT32  StartIndex,
UINT32  EndIndex,
SampleArray pArray
[protected]
 

Interpolates between the two indexes in the array, creating intermediate items and inserting them.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/6/2000
Parameters:
StartIndex,EndIndex - the indexes to interpolate between [INPUTS] pArray - the array to do the interpolatin' on
the interpolated array [OUTPUTS]
Returns:
TRUE unless the indexes are wack

Definition at line 1773 of file samplist.cpp.

01774 {
01775     ERROR2IF(pArray == NULL, FALSE, "Sample array is NULL in CSampleData::InterpolateItems");
01776     size_t              MaxIndex = pArray->size() - 1;
01777 
01778     if (EndIndex <= StartIndex  || EndIndex > MaxIndex)
01779     {
01780         ERROR3("Invalid indexes in CSampleData::InterpolateItems");
01781         return FALSE;
01782     }
01783     // get the two items to interpolate between
01784     CSampleItem FirstItem = (*pArray)[StartIndex];
01785     CSampleItem LastItem  = (*pArray)[EndIndex];
01786 
01787     // get the proportional changes for each step
01788     UINT32 NumItems = EndIndex - StartIndex;
01789     double ItemProportion = 1 / (double)NumItems;
01790 
01791     MILLIPOINT XVal = (INT32)((double)(LastItem.m_Coord.x - FirstItem.m_Coord.x) * ItemProportion);
01792     MILLIPOINT YVal = (INT32)((double)(LastItem.m_Coord.y - FirstItem.m_Coord.y) * ItemProportion);
01793     INT32 PressVal  = (INT32) (((double)(LastItem.m_Pressure - FirstItem.m_Pressure) * ItemProportion));
01794 
01795     UINT32 Index = StartIndex + 1;
01796     CSampleItem NewItem = FirstItem;
01797     while (Index < EndIndex)
01798     {
01799         NewItem.m_Coord.x += XVal;
01800         NewItem.m_Coord.y += YVal;
01801         NewItem.m_Pressure += PressVal;
01802         (*pArray)[Index] = NewItem;
01803         Index++;
01804     }
01805     return TRUE;
01806 }

CSampleData * CSampleData::MakeCopy  ) 
 

Makes a copy of this sample data.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
a copy of this object, unless something goes wrong (i.e memory) in which case NULL
Notes:

Reimplemented in CDistanceSampler.

Definition at line 370 of file samplist.cpp.

00371 {
00372     CSampleData* pNewData = new CSampleData;
00373 
00374     if (pNewData == NULL)
00375         return NULL;
00376 
00377     if (!pNewData->InitialiseData(m_NumItems))
00378     {
00379         delete pNewData;
00380         return NULL;
00381     }
00382 
00383     m_RetrievalSampleRate = 1; // make sure we get all the items
00384 
00385     CSampleItem TheItem;
00386 
00387     // unfortunately my implementation is a bit clumsy so we have to do the first item
00388     // by hand
00389     BOOL    Getok = GetAt(0, &TheItem);
00390     BOOL    Setok = pNewData->SetAt(0, TheItem);
00391     //TRACEUSER( "Diccon", _T("Copying pressure %d\n"), TheItem.m_Pressure);
00392     if (Getok == FALSE || Setok ==  FALSE)
00393         ERROR3("Failed to get or set first item in CSampleData::MakeCopy");
00394 
00395     UINT32 Counter = 1;
00396     // now we can loop through the rest
00397     while (Getok && Setok)
00398     {
00399         Getok = GetNext(&TheItem);
00400         Setok = pNewData->SetNext(TheItem);
00401         //TRACEUSER( "Diccon", _T("Copying pressure %d\n"), TheItem.m_Pressure);
00402         Counter++;
00403     }
00404 
00405     if (Counter != m_NumItems)
00406         TRACEUSER( "Diccon", _T("CSampleData::MakeCopy - Num items copied = %d, Actual num items = %d\n"), Counter, m_NumItems);
00407 
00408     return pNewData;
00409 }

BOOL CSampleData::RemoveAt UINT32  Index  ) 
 

Removes item at Index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Index - the position to remove from [INPUTS]
- [OUTPUTS]
Returns:
TRUE, unless we go over the end of the array
Notes:

Definition at line 651 of file samplist.cpp.

00652 {
00653     BOOL Retval = FALSE;
00654     if (m_pSampleData != NULL)
00655     {
00656         // we are not allowed to be setting data when the sample rate is not 1.0
00657         if (m_CollectionSampleRate < MIN_COLLECTION_SAMPLE_RATE || 
00658             m_CollectionSampleRate > MAX_COLLECTION_SAMPLE_RATE)
00659         {
00660             ERROR3("Attempting to remove data when SampleRate != 1");
00661             return FALSE;
00662         }
00663         if (SetInternalRetrievalIndex(Index))
00664         {
00665             m_pSampleData->erase( m_pSampleData->begin() + size_t(m_RetrievalInternalIndex) );
00666             Retval = TRUE;
00667             m_NumItems--;
00668         }
00669         else
00670             ERROR3("Attempting to remove beyond the end of the array in CSampleData::RemoveAt");
00671     }
00672     return Retval;
00673 }

BOOL CSampleData::RemoveControlPoints UINT32  Frequency,
SampleArray pOriginal,
SampleArray pNew
[protected]
 

BOOL CSampleData::RemoveData UINT32  StartIndex,
UINT32  EndIndex,
SampleArray pArray = NULL
 

To remove all the items between StartIndex and EndIndex, and optionally record them in pArray.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
StartIndex - the index to start removing from [INPUTS] EndIndex - the index to stop removing at
pArray (optional) - an array to store the removed elements in [OUTPUTS]
Returns:
TRUE if successful

Definition at line 958 of file samplist.cpp.

00959 {
00960     // do some checks
00961     ERROR2IF(m_pSampleData == NULL, FALSE, "Attempting to remove from an array that doesn't exist in CSampleData::RemoveData");
00962     ERROR2IF(EndIndex <= StartIndex, FALSE, "Invalid indexes in CSampleData::RemoveData");
00963 
00964     UINT32 UpperBound = (UINT32)m_pSampleData->size() - 1;
00965     if (StartIndex > UpperBound || EndIndex > UpperBound)
00966     {
00967         ERROR3("Attempting to remove items beyond the bounds of the array in CSampleData::RemoveData");
00968         return FALSE;
00969     }
00970     // Set our samples rate to 1.0 so that we don't skip any elements
00971     m_CollectionSampleRate = 1.0;
00972     m_RetrievalSampleRate  = 1.0;
00973     
00974     // find out how many we're dealing with
00975     UINT32 NumRemoveItems = EndIndex - StartIndex;
00976     
00977 //  TRACEUSER( "Diccon", _T("COPYING ITEMS TO BE REMOVED\n"));
00978     // first copy the removed items to the new array (if relevant)
00979     if (pArray != NULL)
00980     {
00981         pArray->resize( NumRemoveItems );
00982         CSampleItem TheItem;
00983         for (UINT32 i = 0; i < NumRemoveItems; i++)
00984         {
00985             TheItem = (*m_pSampleData)[i + StartIndex];
00986             (*pArray)[i] = TheItem;
00987         //  TRACEUSER( "Diccon", _T("Removing data %d\n"), TheItem.m_Pressure);
00988         }
00989     }
00990     
00991     // now copy all elements beyond EndIndex back to StartIndex
00992     UINT32 NumMoveItems = UpperBound - EndIndex;
00993     UINT32 NumItemsMoved = 0;
00994     CSampleItem TheItem;
00995     // EndIndex +1 ??
00996 //  UINT32 Index = StartIndex;
00997 //  TRACEUSER( "Diccon", _T("SHIFTING ITEMS DOWN FROM %d TO %d\n"), EndIndex, Index);
00998 //  TRACEUSER( "Diccon", _T("Upper bound = %d\n"), UpperBound);
00999     BOOL ok = GetAt(EndIndex, &TheItem);
01000     INT32 RemoveCount = NumRemoveItems;
01001     while ((NumItemsMoved <= NumMoveItems) && ok)
01002     {
01003         (*m_pSampleData)[StartIndex++] = TheItem;
01004         ok = GetNext(&TheItem);
01005         NumItemsMoved++;
01006         if (RemoveCount > 0)
01007         {
01008             RemoveCount--;
01009             m_NumItems--; // decrement the number of items
01010         }
01011     }
01012     
01013 //  TRACEUSER( "Diccon", _T("Removed %d items\n"), EndIndex - Index);
01014 //  TRACEUSER( "Diccon", _T("Moved %d items from index %d to index %d\n"), NumItemsMoved, EndIndex, Index); 
01015     // shrink the array to the new size
01016     m_pSampleData->resize( m_NumItems );
01017 
01018     return TRUE;
01019 }

BOOL CSampleData::ReSampleArray SampleArray **  ppArray,
UINT32  NewNumItems
[protected]
 

Resamples the data in the sample array so that we end up with NewNumItems in the section required. We will do this by selecting some resampling points in the original array, maintain these points at the same proportional position and interpolate to get the new points.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/2000
Parameters:
pArray - the array to be resampled [INPUTS] NewNumItems - the number of items we want to end up with in the array
Returns:
TRUE if successful, FALSE if something went wrong
Notes: Because, in reality most of our 'sampled' points are actually interpolated from a smaller number of data points collected I feel that we don't actually lose much accuracy if we just take one in every four points as a control point.

Definition at line 1586 of file samplist.cpp.

01587 {
01588     SampleArray* pArray = *ppArray;
01589     // check our input conditions
01590     ERROR2IF(pArray == NULL, FALSE, "Sample array is NULL in CSampleData::ReSampleData");
01591 
01592     
01593     if (NewNumItems == 0)  // well this is easy
01594     {
01595         pArray->clear();
01596         return TRUE;
01597     }
01598     
01599     // allocate a new array to put the resampled data in
01600     SampleArray* pNewArray = new SampleArray;
01601     if (pNewArray == NULL)
01602         return FALSE;
01603     pNewArray->resize( NewNumItems );
01604 
01605     // how many items per control item
01606     UINT32 ItemsPerControl = 4;  // magic number alert!!
01607 
01608     // Insert the control points into the new array
01609     if (!InsertControlPoints(ItemsPerControl, pArray, pNewArray))
01610     {
01611         pNewArray->clear();
01612         delete pNewArray;
01613         return FALSE;
01614     }
01615 
01616     // proceed through the new array interpolating between the control points.
01617     // We will be able to tell the control points because their coordinates will be non-zero
01618 
01619     UINT32 ControlIndex1 = 0;  // first point is a control point
01620     UINT32 ControlIndex2 = 0;
01621     CSampleItem TheItem;
01622 
01623     UINT32 Index = 0;
01624 
01625     while (Index < NewNumItems)
01626     {
01627         TheItem = (*pNewArray)[Index];
01628         if (TheItem.m_Coord.x != 0 && TheItem.m_Coord.y != 0)  // got another control
01629         {
01630             ControlIndex2 = Index;
01631             if (Index != 0)
01632                 InterpolateItems(ControlIndex1, ControlIndex2, pNewArray);
01633             ControlIndex1 = ControlIndex2;  // current control becomes first control
01634         }
01635         Index++;
01636     }
01637     
01638     // now we have to destroy the original array and swap the pointers
01639     delete pArray;
01640     *ppArray = pNewArray;
01641 
01642     return TRUE;
01643 }

BOOL CSampleData::ReverseData  ) 
 

Reverses the items in the data array, or rather just copies them into a new one.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
- [INPUTS]
Returns:
TRUE if successful, FALSE if we didn't get the memory

Definition at line 1434 of file samplist.cpp.

01435 {
01436     if (m_pSampleData == NULL)
01437         return TRUE;  //EASY
01438 
01439     size_t ArraySize = m_NumItems;  
01440 
01441     if (ArraySize == 0)
01442         return TRUE;  // also easy
01443 
01444     // make a new array
01445     SampleArray* pNewArray = new SampleArray;
01446     if (pNewArray == NULL)
01447         return FALSE;
01448 
01449     pNewArray->resize( ArraySize );
01450 
01451     size_t UpperBound = ArraySize-1;
01452     CSampleItem TheItem;
01453 //  BOOL ok = TRUE;
01454     // take the item at the start of our member array and set it at the end of the new array
01455     for (UINT32 Counter = 0; Counter < (UINT32)ArraySize ; Counter++)
01456     {
01457         TheItem = (*m_pSampleData)[Counter];
01458         (*pNewArray)[UpperBound - Counter] = TheItem;
01459     }
01460     // swap the pointers
01461     SampleArray* pTemp = m_pSampleData;
01462     m_pSampleData = pNewArray;
01463     
01464     // clear out the original
01465     pTemp->clear();
01466     delete pTemp;
01467 
01468     return TRUE;
01469 }

BOOL CSampleData::SetAt UINT32  Index,
CSampleItem Item
 

inserts Item at Index

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Index - the position to set Item at [INPUTS] Item - the item to insert
- [OUTPUTS]
Returns:
TRUE if successful, FALSE otherwise
Notes: Currently it is not permitted to Set, Remove or Insert items if the sample rate is not 1. This is because a) I really don't want people changing data in the array once it has been collected (we're sampling remember) and b) Its a pain in the ass

Definition at line 513 of file samplist.cpp.

00514 {
00515     BOOL Retval = FALSE;
00516     if (m_pSampleData != NULL)
00517     {
00518         // we are not allowed to be setting data when the sample rate is not 1.0
00519         if (m_CollectionSampleRate < MIN_COLLECTION_SAMPLE_RATE || 
00520             m_CollectionSampleRate > MAX_COLLECTION_SAMPLE_RATE)
00521         {
00522             ERROR3("Attempting to set data when SampleRate != 1");
00523             return FALSE;
00524         }
00525         if (SetInternalCollectionIndex(Index))
00526         {
00527             (*m_pSampleData)[size_t(m_CollectionInternalIndex)] = Item; 
00528             Retval = TRUE;
00529             if ((UINT32)m_CollectionInternalIndex > m_NumItems)
00530                 m_NumItems = (UINT32)m_CollectionInternalIndex;
00531         }
00532         else
00533             ERROR3("Attempting to set over the end of the array in CSampleData::SetAt");
00534     }
00535     return Retval;
00536 }

BOOL CSampleData::SetCollectionSampleRate double  Rate  ) 
 

Sets the sample rate to use for collecting data. Note that for current purposes this is only allowed to be 1. So you probably won't be using this function very often.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Rate - the sample rate to use [INPUTS]
- [OUTPUTS]
Returns:
TRUE if Rate is within the set bounds

Definition at line 1276 of file samplist.cpp.

01277 {
01278     if (Rate < MIN_COLLECTION_SAMPLE_RATE || Rate > MAX_COLLECTION_SAMPLE_RATE)
01279     {
01280         ERROR3("Attempting to set invalid sample rate in CSampleData::SetCollectionSampleRate");
01281         return FALSE;
01282     }
01283 
01284     m_CollectionSampleRate = Rate;
01285 
01286     return TRUE;
01287 }

BOOL CSampleData::SetInternalCollectionIndex UINT32  Index  )  [protected]
 

Sets our collection internal array index to the position corresponding to the requested index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
IndexRequested - the requested index to set the array pointer to [INPUTS]
- [OUTPUTS]
Returns:
TRUE, unless index converts to an internal index that is out of bounds

Definition at line 1036 of file samplist.cpp.

01037 {
01038     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is null in CSampleData::SetInternalIndex");
01039 
01040     BOOL Retval = FALSE;
01041 
01042     double TempIndex = m_CollectionSampleRate * Index;
01043     if (TempIndex <= (double)m_pSampleData->size() - 1 && TempIndex >= 0)
01044     {
01045         m_CollectionInternalIndex = TempIndex;
01046         Retval = TRUE;
01047     }
01048     else
01049         ERROR3("Attempting to set internal index beyond the end of the array in CSampleData::SetInternalIndex"); 
01050 
01051     return Retval;
01052 }

BOOL CSampleData::SetInternalRetrievalIndex UINT32  Index  )  [protected]
 

Sets our Retrieval internal array index to the position corresponding to the requested index.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
IndexRequested - the requested index to set the array pointer to [INPUTS]
- [OUTPUTS]
Returns:
TRUE, unless index converts to an internal index that is out of bounds

Definition at line 1069 of file samplist.cpp.

01070 {
01071     ERROR2IF(m_pSampleData == NULL, FALSE, "Sample data is null in CSampleData::SetInternalIndex");
01072 
01073     BOOL Retval = FALSE;
01074 
01075     double TempIndex = m_RetrievalSampleRate * Index;
01076     if (TempIndex <= (double)m_pSampleData->size() - 1)
01077     {
01078         m_RetrievalInternalIndex = TempIndex;
01079         Retval = TRUE;
01080     }
01081     else
01082         ERROR3("Attempting to set internal index beyond the end of the array in CSampleData::SetInternalIndex"); 
01083 
01084     return Retval;
01085 }

void CSampleData::SetMaxPressure UINT32  Max  ) 
 

To set our max pressure member. Do this by querying the WinTab device BEFORE you start collecting data.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Max - the maximum pressure value allowed by the current pressure device [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 1370 of file samplist.cpp.

01371 {
01372     m_MaxPressure = Max;
01373     
01374     // +1 because values go from 0 -> MaxVal whereas we really want the number of values
01375     m_ScalePressure = (double)(MAXPRESSURE+1) / (Max+1); 
01376     
01377 }

BOOL CSampleData::SetNext CSampleItem Item,
BOOL  Grow = FALSE
 

Increments our internal index and then inserts a new item at that position. If we hit the end of the array then we will add an element, so long as our flag is set Notes:.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Item - the item to insert [INPUTS] Grow - do we wish to grow the array if we hit the end (defaults to FALSE)
- [OUTPUTS]
Returns:
TRUE, unless we hit the end of the array and do not widh to grow

Definition at line 554 of file samplist.cpp.

00555 {
00556     BOOL Retval = FALSE;
00557     if (m_pSampleData != NULL)
00558     {
00559         // we are not allowed to be setting data when the sample rate is not 1.0
00560         if (m_CollectionSampleRate < MIN_COLLECTION_SAMPLE_RATE || 
00561             m_CollectionSampleRate > MAX_COLLECTION_SAMPLE_RATE)
00562         {
00563             ERROR3("Attempting to set data when SampleRate != 1");
00564             return FALSE;
00565         }
00566         if (IncrementInternalIndex(&m_CollectionInternalIndex))
00567         {
00568             // if internal index == -1 after incrementing it means we hit the end of the array
00569             if (m_CollectionInternalIndex != -1.0)
00570             {
00571                 //TRACEUSER( "Diccon", _T("Setting at %f\n"), m_CollectionInternalIndex);
00572                 (*m_pSampleData)[size_t(m_CollectionInternalIndex)] = Item;
00573                 Retval = TRUE;
00574                 if ((UINT32)m_CollectionInternalIndex > m_NumItems)
00575                     m_NumItems = (UINT32)m_CollectionInternalIndex;
00576             }
00577             else
00578             {
00579                 // we must have hit the end of the array, so we need to add
00580                 if (Grow == TRUE)
00581                 {
00582                     m_pSampleData->push_back( Item );
00583                     Retval = TRUE;
00584                     m_NumItems++;
00585                     m_CollectionInternalIndex = m_NumItems;
00586                 }
00587             }
00588         }
00589         else
00590             ERROR3("Failed to increment index in CSampleData::SetNext");
00591     }   
00592 
00593     return Retval;
00594 }

void CSampleData::SetNumItemsFromArraySize  ) 
 

Sets the num items member from the size of the array. Note that you should never really use this unless you are certain that a) your current m_NumItems is incorrect and b)You are certain that your array contains nothing but valid data. An example of when you should use this is if you decide to set the array from out side, rather than collect it through sampling. And you really shouldn't be doing that either.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
- [INPUTS]
Returns:
-

Definition at line 1532 of file samplist.cpp.

01533 {
01534     if (m_pSampleData != NULL)
01535         m_NumItems = (UINT32)m_pSampleData->size();
01536     else
01537         m_NumItems = 0;
01538 }

BOOL CSampleData::SetPrev CSampleItem Item  ) 
 

Decrements our internal index and then inserts Item into the array.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Item - the item to insert [INPUTS]
- [OUTPUTS]
Returns:
TRUE if successful, FALSE if we're already at the head of the array
Notes:

Definition at line 610 of file samplist.cpp.

00611 {
00612     BOOL Retval = FALSE;
00613     if (m_pSampleData != NULL)
00614     {
00615         // we are not allowed to be setting data when the sample rate is not 1.0
00616         if (m_CollectionSampleRate < MIN_COLLECTION_SAMPLE_RATE || 
00617             m_CollectionSampleRate > MAX_COLLECTION_SAMPLE_RATE)
00618         {
00619             ERROR3("Attempting to set data when SampleRate != 1");
00620             return Retval;
00621         }
00622         if (DecrementInternalIndex(&m_CollectionInternalIndex))
00623         {
00624             if (m_CollectionInternalIndex != -1.0)
00625             {
00626                 (*m_pSampleData)[size_t(m_CollectionInternalIndex)] = Item;
00627                 Retval = TRUE;
00628             }
00629             else
00630                 ERROR3("Attempting to SetPrev over the start of the array in CSampleData::SetPrev");
00631         }
00632             ERROR3("Unable to decrement index in CSampleData::SetPrev");
00633     }   
00634     return Retval;
00635 }

BOOL CSampleData::SetRetrievalSampleRate double  Rate  ) 
 

Sets the sample rate to use for retrieving data,.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Rate - the sample rate to use [INPUTS]
- [OUTPUTS]
Returns:
TRUE if Rate is within the set bounds

Definition at line 1319 of file samplist.cpp.

01320 {
01321     // CGS:  because of the way that I now use this function, its NOT fair to do the following ....
01322     
01323     if (Rate < MIN_RETRIEVAL_SAMPLE_RATE || Rate > MAX_RETRIEVAL_SAMPLE_RATE)
01324     {
01325         TRACE( _T("Sample rate passed to CSampleData::SetRetrievalSampleRate was oustide of range!") );
01326         //ERROR3("Attempting to set invalid sample rate in CSampleData::SetRetrievalSampleRate");
01327         //return FALSE;
01328     }
01329 
01330     if (Rate < MIN_RETRIEVAL_SAMPLE_RATE) Rate = MIN_RETRIEVAL_SAMPLE_RATE;
01331     if (Rate > MAX_RETRIEVAL_SAMPLE_RATE) Rate = MAX_RETRIEVAL_SAMPLE_RATE;
01332 
01333     m_RetrievalSampleRate = Rate;
01334 
01335     return TRUE;
01336 }

void CSampleData::SetSampleArray SampleArray pArray  ) 
 

sets the given array to use as our sample data

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
pArray - the array to set as a data member [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 1410 of file samplist.cpp.

01411 {
01412     // if we've already got one then delete it
01413     if (m_pSampleData != NULL)
01414     {
01415         m_pSampleData->clear();
01416         delete m_pSampleData;
01417         m_pSampleData = NULL;
01418     }
01419     m_pSampleData = pArray;
01420 }

BOOL CSampleData::WriteNative CXaraFileRecord pRecord  ) 
 

Writes out the data contained in this SampleData to a record.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/12/99
Parameters:
pRecord - the record to write to [INPUTS]
Returns:
TRUE if the Node has written out a record to the filter

Definition at line 1821 of file samplist.cpp.

01822 {
01823     ERROR2IF(pRecord == NULL, FALSE, "Record is NULL in CSampleData::WriteNative");
01824 
01825     BOOL ok = TRUE;
01826     ok = pRecord->WriteINT32((INT32)m_NumItems);
01827 
01828     if (m_pSampleData != NULL)
01829     {
01830         CSampleItem TheItem;
01831         
01832         SetRetrievalSampleRate(1.0); // as we want 
01833         BOOL KeepWriting  = GetAt(0, &TheItem);  // get the first itemto save out every item
01834         
01835 
01836         UINT32 Counter = 0;
01837         // note that GetNext returns FALSE it just means we've reached the end, not an error
01838         while (ok && Counter <= m_NumItems && KeepWriting)
01839         {
01840             if (ok) ok = TheItem.WriteNative(pRecord);
01841             KeepWriting = GetNext(&TheItem);
01842             Counter++;
01843         }
01844     }
01845     return ok;
01846 }


Member Data Documentation

double CSampleData::m_CollectionInternalIndex [protected]
 

Definition at line 234 of file samplist.h.

double CSampleData::m_CollectionSampleRate [protected]
 

Definition at line 237 of file samplist.h.

UINT32 CSampleData::m_ElementSize [protected]
 

Definition at line 240 of file samplist.h.

UINT32 CSampleData::m_MaxPressure [protected]
 

Definition at line 244 of file samplist.h.

size_t CSampleData::m_NumItems [protected]
 

Definition at line 242 of file samplist.h.

SampleArray* CSampleData::m_pSampleData [protected]
 

Definition at line 232 of file samplist.h.

double CSampleData::m_RetrievalInternalIndex [protected]
 

Definition at line 235 of file samplist.h.

double CSampleData::m_RetrievalSampleRate [protected]
 

Definition at line 238 of file samplist.h.

double CSampleData::m_ScalePressure [protected]
 

Definition at line 246 of file samplist.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:16 2007 for Camelot by  doxygen 1.4.4