#include <samplist.h>
Inheritance diagram for CDistanceSampler:
Public Member Functions | |
CDistanceSampler () | |
default constructor | |
~CDistanceSampler () | |
destructor | |
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. | |
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 |
Definition at line 266 of file samplist.h.
|
default constructor
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 }
|
|
destructor
Definition at line 1892 of file samplist.cpp.
|
|
This function is in charge of doing the actual sampling of data.
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 }
|
|
Retrieves the data between Start and End and puts it into the sampler provided.
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 }
|
|
Definition at line 296 of file samplist.h. 00296 { return ((double) m_DistanceSoFar); }
|
|
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:.
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 }
|
|
access fn.
Definition at line 1938 of file samplist.cpp. 01939 { 01940 return m_SampleDistance; 01941 }
|
|
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.
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 }
|
|
If we want to change the distance that we sampled over then we must resample the data to make it fit.
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 }
|
|
Definition at line 297 of file samplist.h. 00297 { m_DistanceSoFar = (MILLIPOINT) val; }
|
|
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.
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 }
|
|
Given the spacing between objects this works out the sample rate at which we want to retrieve objects Notes:.
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 }
|
|
Definition at line 310 of file samplist.h. |
|
Definition at line 304 of file samplist.h. |
|
Definition at line 305 of file samplist.h. |
|
Definition at line 307 of file samplist.h. |
|
Definition at line 294 of file samplist.h. |
|
Definition at line 303 of file samplist.h. |
|
Definition at line 302 of file samplist.h. |
|
Definition at line 301 of file samplist.h. |
|
Definition at line 299 of file samplist.h. |
|
Definition at line 309 of file samplist.h. |