CDistanceSampler Class Reference

Derived class which has a method to sample data over distances. Basically what you want to do is initialise the object, set the sample distances, then pass in data to the CollectData method and this object will sample at the appropriate rate. More...

#include <samplist.h>

Inheritance diagram for CDistanceSampler:

CSampleData CCObject SimpleCCObject List of all members.

Public Member Functions

 CDistanceSampler ()
 default constructor
 ~CDistanceSampler ()
 destructor
CDistanceSamplerMakeCopy ()
 Makes a copy of this sample data. Most of the work is done in the base class but we need to also copy a few members over.
virtual BOOL CollectData (DocCoord Coord, UINT32 Pressure)
 This function is in charge of doing the actual sampling of data.
BOOL SetSampleDistance (MILLIPOINT Distance)
 Sets the sample distance, I can't see why you would wish to sample at anything other than MIN_BRUSH_SPACING, but each to their own.
MILLIPOINT GetSampleDistance ()
 access fn.
BOOL SetSampleRateFromSpacing (MILLIPOINT Spacing)
 Given the spacing between objects this works out the sample rate at which we want to retrieve objects Notes:.
INT32 GetInternalIndexFromDistance (MILLIPOINT Distance)
 If you want to find out what index corresponds to Distance then call this, actually all it does is divide by the minimum spacing. Note that it will always round down. ERRORS: Negative distance being passed in, Distance resulting in index which is off the end of the array. Notes:.
BOOL GetDataSection (MILLIPOINT Start, MILLIPOINT End, CDistanceSampler *pSection)
 Retrieves the data between Start and End and puts it into the sampler provided.
BOOL ReSample (MILLIPOINT NewLength)
 If we want to change the distance that we sampled over then we must resample the data to make it fit.
double GetDistanceRep ()
void SetDistanceSoFar (double val)

Public Attributes

UINT32 m_ItemsInserted

Protected Attributes

MILLIPOINT m_SampleDistance
CSampleItem m_LastItemStored
CSampleItem m_LastItem
DocCoord m_LastCoord
MILLIPOINT m_DistanceSinceLastSample
MILLIPOINT m_DistanceSoFar
double m_ItemRemainder
MILLIPOINT m_TotalDistance
MILLIPOINT m_DistanceSinceLastData

Detailed Description

Derived class which has a method to sample data over distances. Basically what you want to do is initialise the object, set the sample distances, then pass in data to the CollectData method and this object will sample at the appropriate rate.

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

Definition at line 266 of file samplist.h.


Constructor & Destructor Documentation

CDistanceSampler::CDistanceSampler  ) 
 

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 1867 of file samplist.cpp.

01868 {
01869     m_SampleDistance = MIN_BRUSH_SPACING;
01870     m_DistanceSinceLastSample = -1;
01871     m_DistanceSoFar = 0;
01872     m_TotalDistance = 0;
01873     m_ItemsInserted = 0;
01874     m_DistanceSinceLastData = 0;
01875     m_ItemRemainder = 0.0;
01876 }

CDistanceSampler::~CDistanceSampler  ) 
 

destructor

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

Definition at line 1892 of file samplist.cpp.

01893 {
01894 
01895 }


Member Function Documentation

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

This function is in charge of doing the actual sampling of data.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Coord - the current coordinate [INPUTS] Pressure - the current pressure
- [OUTPUTS]
Returns:
TRUE if successful, FALSE if something went wrong
Notes:

Reimplemented from CSampleData.

Definition at line 1958 of file samplist.cpp.

01959 {
01960     // first up check that we have set the max pressure value
01961     ERROR2IF(m_MaxPressure == 0, FALSE, "You're supposed to set the Max Pressure value BEFORE you collect data");
01962     ERROR2IF(Pressure > m_MaxPressure, FALSE, "Pressure is greater than maximum value in CDistanceSampler::CollectData");
01963 
01964     BOOL ok = FALSE;
01965     // first up, if we are initialised to -1 then this is the first point, which we want
01966     if (m_DistanceSinceLastSample == -1)
01967     {
01968         if (m_ScalePressure != 1.0)
01969             Pressure = (UINT32)(m_ScalePressure * Pressure);
01970         CSampleItem TheItem(Coord, 0, Pressure);
01971         ok = SetAt(0, TheItem);
01972         m_DistanceSinceLastSample = 0;
01973 //      TRACEUSER( "Diccon", _T("Recording pressure %d at 0\n"), Pressure);
01974         m_LastItemStored = TheItem;
01975         m_LastItem = TheItem;
01976         m_LastCoord = Coord;
01977 
01978     }
01979     else
01980     {
01981         // find out how far we've gone
01982         MILLIPOINT Dist = (MILLIPOINT)Coord.Distance(m_LastItem.m_Coord);
01983         m_DistanceSinceLastData      = Dist;
01984         m_DistanceSinceLastSample   += Dist;
01985         m_TotalDistance             += Dist;
01986     //  TRACEUSER( "Diccon", _T("Received Pressure %d at Distance %d\n"), Pressure ,m_TotalDistance);
01987         // work out how many new items we need to make, and the proportional values to give to each
01988         double NumInsertItems = (double)m_DistanceSinceLastSample / (double)m_SampleDistance;
01989         if (NumInsertItems > 1)
01990         {
01991             if (m_ItemRemainder > 1) // if our remainder total adds up to >1 then add one more
01992             {
01993                 NumInsertItems++;
01994                 m_ItemRemainder--;
01995             }
01996             double ItemProportion = 1 / NumInsertItems;
01997         
01998             // work out the values that we need to add on for each step
01999             MILLIPOINT XVal = (INT32)((double)(Coord.x - m_LastItem.m_Coord.x) * ItemProportion);
02000             MILLIPOINT YVal = (INT32)((double)(Coord.y - m_LastItem.m_Coord.y) * ItemProportion);
02001             double dPressure = (double)Pressure * m_ScalePressure;
02002             INT32 PressVal  = (INT32)((dPressure - (double)m_LastItemStored.m_Pressure) * ItemProportion);
02003             m_ItemsInserted += (UINT32)NumInsertItems;
02004             //TRACEUSER( "Diccon", _T("INSERTED %d ITEMS\n"), m_ItemsInserted); 
02005             CSampleItem TheItem = m_LastItemStored;
02006             while (NumInsertItems > 1)
02007             {
02008                 m_DistanceSoFar += m_SampleDistance;
02009                 TheItem.m_Pressure += PressVal;
02010                 TheItem.m_Coord.x += XVal;
02011                 TheItem.m_Coord.y += YVal;
02012                 TheItem.m_Distance = m_DistanceSoFar;
02013                 ok = SetNext(TheItem, TRUE);
02014                 NumInsertItems--;
02015                 m_DistanceSinceLastSample -= m_SampleDistance;
02016                 //TRACEUSER( "Diccon", _T("Recording pressure %d at %d\n"), TheItem.m_Pressure, m_DistanceSoFar);
02017             }
02018             // add the remainder to our remainder counter
02019             m_ItemRemainder += NumInsertItems;
02020 
02021             m_LastItemStored = TheItem;
02022 
02023         }
02024         else
02025             ok = TRUE;
02026     }
02027     m_LastItem.m_Pressure = Pressure;
02028     m_LastItem.m_Coord    = Coord;
02029     return ok;
02030 }

BOOL CDistanceSampler::GetDataSection MILLIPOINT  Start,
MILLIPOINT  End,
CDistanceSampler pSection
 

Retrieves the data between Start and End and puts it into the sampler provided.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/2000
Parameters:
Start,End - the distances between which we want to get the data from [INPUTS] pSection - pointer to an allocated CDistanceSampler
Initialises pSection with data between the two distances [OUTPUTS]
Returns:
TRUE if successful, FALSE if something went wrong

Errors: if Start or End are invalid, or if we don't have a sample array See Also: CSampleData::GetArraySection

Notes: If this fn. goes wrong you are responsible for deleting the CDistanceSampler

Definition at line 2176 of file samplist.cpp.

02177 {   
02178     ERROR2IF(pSection == NULL, FALSE, "Sampler is NULL in CDistanceSampler::GetDataSection");
02179 
02180     if (Start < 0 || End < 0 || (End <= Start))
02181     {
02182         ERROR3("Invalid distances in CSampleData::ReSample");
02183         return FALSE;
02184     }
02185     // I guess if the caller hasn't allocated the sampler then we can do it, under duress..
02186     if (pSection == NULL)
02187     {
02188         ERROR3("You haven't initialised the distance sampler.  Well I suppose I can do it for you...");
02189         pSection = new CDistanceSampler;
02190         if (pSection == NULL)
02191         {
02192             ERROR3("Well actually I can't, sorry must bail");
02193             return FALSE;
02194         }
02195     }
02196     // get the indexes of the start and end points
02197     INT32 StartIndex = GetInternalIndexFromDistance(Start);
02198     INT32 EndIndex   = GetInternalIndexFromDistance(End);
02199 
02200     if (StartIndex == -1 || EndIndex == -1)
02201     {
02202         ERROR3("Error getting indexes in CDistanceSampler::ReSample");
02203         return FALSE;
02204     }
02205 
02206     // figure out how many items in the new length
02207     INT32 NewNumItems = (EndIndex - StartIndex) / MIN_BRUSH_SPACING;
02208 
02209     // initialise the data
02210     if (!pSection->InitialiseData(NewNumItems))
02211         return FALSE;
02212 
02213     // call the helper function to do the work
02214     BOOL ok = GetArraySection((UINT32)StartIndex, (UINT32)EndIndex, pSection->GetSampleArray());
02215     if (ok)
02216         pSection->SetNumItemsFromArraySize();
02217 
02218     return ok;
02219 }

double CDistanceSampler::GetDistanceRep  )  [inline]
 

Definition at line 296 of file samplist.h.

00296 { return ((double) m_DistanceSoFar); }

INT32 CDistanceSampler::GetInternalIndexFromDistance MILLIPOINT  Distance  ) 
 

If you want to find out what index corresponds to Distance then call this, actually all it does is divide by the minimum spacing. Note that it will always round down. ERRORS: Negative distance being passed in, Distance resulting in index which is off the end of the array. Notes:.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Distance - the distance along the path [INPUTS]
- [OUTPUTS]
Returns:
the internal index into the distance array at that distance, or -1 if something goes wrong

Definition at line 2082 of file samplist.cpp.

02083 {
02084     if (Distance < 0)
02085     {
02086         ERROR3("Negative distance in CDistanceSampler::GetInternalIndexFromDistance");
02087         return -1;
02088     }
02089 
02090     INT32 Index = Distance / MIN_BRUSH_SPACING;
02091 
02092     if (Index > (INT32)m_NumItems)
02093         Index = -1;
02094     return Index;
02095 }

MILLIPOINT CDistanceSampler::GetSampleDistance  ) 
 

access fn.

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

Definition at line 1938 of file samplist.cpp.

01939 {
01940     return m_SampleDistance;
01941 }

CDistanceSampler * CDistanceSampler::MakeCopy  ) 
 

Makes a copy of this sample data. Most of the work is done in the base class but we need to also copy a few members over.

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 from CSampleData.

Definition at line 2113 of file samplist.cpp.

02114 {
02115     CDistanceSampler* pNewData = new CDistanceSampler;
02116 
02117     if (pNewData == NULL)
02118         return NULL;
02119 
02120     if (!pNewData->InitialiseData(m_NumItems))
02121     {
02122         delete pNewData;
02123         return NULL;
02124     }
02125 
02126     m_RetrievalSampleRate = 1; // make sure we get all the items
02127 
02128     CSampleItem TheItem;
02129 
02130     // unfortunately my implementation is a bit clumsy so we have to do the first item
02131     // by hand
02132     BOOL    Getok = GetAt(0, &TheItem);
02133     BOOL    Setok = pNewData->SetAt(0, TheItem);
02134     //TRACEUSER( "Diccon", _T("Copying pressure %d\n"), TheItem.m_Pressure);
02135     if (Getok == FALSE || Setok ==  FALSE)
02136         ERROR3("Failed to get or set first item in CSampleData::MakeCopy");
02137 
02138     UINT32 Counter = 1;
02139     // now we can loop through the rest
02140     while (Getok && Setok)
02141     {
02142         Getok = GetNext(&TheItem);
02143         Setok = pNewData->SetNext(TheItem);
02144         //TRACEUSER( "Diccon", _T("Copying pressure %d\n"), TheItem.m_Pressure);
02145         Counter++;
02146     }
02147 
02148     pNewData->m_DistanceSoFar = TheItem.m_Distance;
02149 
02150     if (Counter != m_NumItems)
02151         TRACEUSER( "Diccon", _T("CSampleData::MakeCopy - Num items copied = %d, Actual num items = %d\n"), Counter, m_NumItems);
02152 
02153 //  pNewData->SetSampleDistance(m_SampleDistance);
02154     return pNewData;
02155 }

BOOL CDistanceSampler::ReSample MILLIPOINT  NewLength  ) 
 

If we want to change the distance that we sampled over then we must resample the data to make it fit.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
NewLength - the new length to sample over [INPUTS]
- [OUTPUTS]
Returns:
TRUE if all went well, FALSE if not
Notes: In truth most of the work is done in the base class. Here we simply calculate the new number of items that we need and pass it along

Definition at line 2239 of file samplist.cpp.

02240 {
02241     //checks
02242     if (NewLength <= 0 || m_pSampleData == NULL)
02243     {
02244         ERROR3("Invalid entry conditions in CDistanceSampler::ReSample");
02245         return FALSE;
02246     }
02247 
02248     // find out the new number of items
02249     INT32 NewNumItems = NewLength / MIN_BRUSH_SPACING;
02250 
02251     m_DistanceSoFar = NewLength;
02252 
02253     BOOL ok = ReSampleArray(&m_pSampleData, NewNumItems);
02254     if (ok)
02255         SetNumItemsFromArraySize();  // make sure our number of items is up to date
02256 
02257     return ok;
02258 
02259 }

void CDistanceSampler::SetDistanceSoFar double  val  )  [inline]
 

Definition at line 297 of file samplist.h.

00297 { m_DistanceSoFar = (MILLIPOINT) val; }

BOOL CDistanceSampler::SetSampleDistance MILLIPOINT  Distance  ) 
 

Sets the sample distance, I can't see why you would wish to sample at anything other than MIN_BRUSH_SPACING, but each to their own.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Distance - the distance to sample at [INPUTS]
- [OUTPUTS]
Returns:
TRUE, unless Distance is out of bounds
Notes:

Definition at line 1912 of file samplist.cpp.

01913 {
01914     if (Distance < MIN_BRUSH_SPACING || Distance > MAX_BRUSH_SPACING)
01915     {
01916         ERROR3("Invalid distaance in CDistanceSampler::SetSampleDistance");
01917         return FALSE;
01918     }
01919     m_SampleDistance = Distance;
01920 
01921     return TRUE;
01922 }

BOOL CDistanceSampler::SetSampleRateFromSpacing MILLIPOINT  Spacing  ) 
 

Given the spacing between objects this works out the sample rate at which we want to retrieve objects Notes:.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/2000
Parameters:
Spacing - the spacing between brush objects [INPUTS]
- [OUTPUTS]
Returns:
TRUE so long as spacing is between bounds

Definition at line 2047 of file samplist.cpp.

02048 {
02049     if (/*Spacing < MIN_BRUSH_SPACING ||*/ Spacing > MAX_BRUSH_SPACING)
02050     {
02051         ERROR3("Attempting to set invalid spacing value");
02052         return FALSE;
02053     }
02054 
02055     /* recall that sample rate 1 : Spacing = MIN_BRUSH_SPACING
02056                    sample rate 2 : Spacing = 2 * MIN_BRUSH_SPACING
02057                    sample rate 3 : Spacing = 3 * .. etc. */
02058 
02059     m_RetrievalSampleRate = ((double)Spacing / (double)MIN_BRUSH_SPACING) ;
02060 
02061     return TRUE;
02062 }


Member Data Documentation

MILLIPOINT CDistanceSampler::m_DistanceSinceLastData [protected]
 

Definition at line 310 of file samplist.h.

MILLIPOINT CDistanceSampler::m_DistanceSinceLastSample [protected]
 

Definition at line 304 of file samplist.h.

MILLIPOINT CDistanceSampler::m_DistanceSoFar [protected]
 

Definition at line 305 of file samplist.h.

double CDistanceSampler::m_ItemRemainder [protected]
 

Definition at line 307 of file samplist.h.

UINT32 CDistanceSampler::m_ItemsInserted
 

Definition at line 294 of file samplist.h.

DocCoord CDistanceSampler::m_LastCoord [protected]
 

Definition at line 303 of file samplist.h.

CSampleItem CDistanceSampler::m_LastItem [protected]
 

Definition at line 302 of file samplist.h.

CSampleItem CDistanceSampler::m_LastItemStored [protected]
 

Definition at line 301 of file samplist.h.

MILLIPOINT CDistanceSampler::m_SampleDistance [protected]
 

Definition at line 299 of file samplist.h.

MILLIPOINT CDistanceSampler::m_TotalDistance [protected]
 

Definition at line 309 of file samplist.h.


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