KSquare Utilities
KKB::PointList Class Reference

Container object used to maintaining a list of pixel locations. More...

#include <Point.h>

+ Inheritance diagram for KKB::PointList:

Public Types

typedef PointListPointListPtr
 
- Public Types inherited from KKB::KKQueue< Point >
typedef std::vector< Point * >::const_iterator const_iterator
 
typedef std::vector< Point * >::iterator iterator
 

Public Member Functions

 PointList (const PointList &pointList)
 
 PointList (bool _owner)
 
void BoxCoordinites (kkint32 &minRow, kkint32 &minCol, kkint32 &maxRow, kkint32 &maxCol)
 
Point CalculateCenterPoint ()
 
float ComputeSegmentLens (float heightFactor, float widthFactor) const
 
KKStr ToDelStr (char del) const
 
- Public Member Functions inherited from KKB::KKQueue< Point >
 KKQueue (bool _owner=true)
 
 KKQueue (const KKQueue &q, bool _owner)
 Constructor, similar to the Copy Constructor except that you can control whether it duplicates the contents. More...
 
virtual ~KKQueue ()
 Virtual destructor; if owns its contents will also call the destructor on each one entry that it contains. More...
 
virtual void Add (EntryPtr _entry)
 
virtual void AddFirst (EntryPtr _entry)
 
virtual void AddQueue (const KKQueue &q)
 Add the contents of a separate KKQueue container to this container. More...
 
EntryPtr BackOfQueue () const
 
void DeleteContents ()
 
void DeleteEntry (EntryPtr _entry)
 
void DeleteEntry (kkuint32 _idx)
 
KKQueueDuplicateListAndContents () const
 Creates a new container including duplicating the contents, which also makes the new instance the owner of those contents. More...
 
kkuint32 FindTheKthElement (kkuint32 k, Functor pred)
 
EntryPtr FrontOfQueue () const
 
EntryPtr GetFirst () const
 
EntryPtr GetLast () const
 
EntryPtr IdxToPtr (kkuint32 idx) const
 
kkint32 LocateEntry (EntryConstPtr _entry) const
 
EntryPtr LookAtBack () const
 
EntryPtr LookAtFront () const
 
bool operator!= (const KKQueue< Point > &rightSide) const
 returns False if NOT every entry in both containers point to the same elements More...
 
KKQueueoperator= (const KKQueue &q)
 Assignment Operator. More...
 
bool operator== (const KKQueue< Point > &rightSide) const
 Returns True if every entry in both containers point to the same elements. More...
 
Pointoperator[] (kkuint32 i) const
 
bool Owner () const
 
void Owner (bool _owner)
 
virtual EntryPtr PopFromBack ()
 
virtual EntryPtr PopFromFront ()
 
kkint32 PtrToIdx (EntryConstPtr _entry) const
 
virtual void PushOnBack (EntryPtr _entry)
 
virtual void PushOnFront (EntryPtr _entry)
 
kkint32 QueueSize () const
 
void RandomizeOrder ()
 Randomizes the order of the vector. More...
 
void RandomizeOrder (kkint64 seed)
 
void RandomizeOrder (RandomNumGenerator &randomVariable)
 Randomizes the order of the vector. More...
 
virtual EntryPtr RemoveFirst ()
 
virtual EntryPtr RemoveLast ()
 
void SetIdxToPtr (kkuint32 _idx, Point *_ptr)
 
void SwapIndexes (size_t idx1, size_t idx2)
 

Static Public Member Functions

static PointListPtr FromDelStr (const KKStr &s)
 

Additional Inherited Members

- Protected Member Functions inherited from KKB::KKQueue< Point >
 KKQueue (const KKQueue &q)
 Copy Constructor creating new instance; including duplicating contents if owner set to true. More...
 

Detailed Description

Container object used to maintaining a list of pixel locations.

Definition at line 75 of file Point.h.

Member Typedef Documentation

Definition at line 78 of file Point.h.

Constructor & Destructor Documentation

PointList::PointList ( const PointList pointList)

Definition at line 93 of file Point.cpp.

References PointList().

Referenced by PointList().

93  :
94  KKQueue<Point> (true)
95 {
97  for (idx = pointList.begin (); idx != pointList.end (); idx++)
98  {
99  PushOnBack (new Point (*(*idx)));
100  }
101 }
std::vector< Point * >::const_iterator const_iterator
Definition: KKQueue.h:89
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
virtual void PushOnBack(EntryPtr _entry)

Member Function Documentation

void PointList::BoxCoordinites ( kkint32 minRow,
kkint32 minCol,
kkint32 maxRow,
kkint32 maxCol 
)

Definition at line 111 of file Point.cpp.

References KKB::Point::Col(), and KKB::Point::Row().

Referenced by KKB::ContourFollower::CreatePointListFromFourier().

116 {
117  minRow = minCol = 999999;
118  maxRow = maxCol = -1;
119 
120  for (iterator x = begin (); x != end (); x++)
121  {
122  PointPtr p = *x;
123  if (p->Row () < minRow)
124  minRow = p->Row ();
125 
126  if (p->Row () > maxRow)
127  maxRow = p->Row ();
128 
129  if (p->Col () < minCol)
130  minCol = p->Col ();
131 
132  if (p->Col () > maxCol)
133  maxCol = p->Col ();
134  }
135 }
std::vector< Point * >::iterator iterator
Definition: KKQueue.h:88
kkint32 Col() const
Definition: Point.h:40
kkint32 Row() const
Definition: Point.h:39
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
Point PointList::CalculateCenterPoint ( )

Definition at line 138 of file Point.cpp.

References KKB::Point::Col(), KKB::Point::Point(), and KKB::Point::Row().

139 {
140  kkint32 totalRow = 0;
141  kkint32 totalCol = 0;
142  for (iterator x = begin (); x != end (); x++)
143  {
144  PointPtr p = *x;
145  totalRow += p->Row ();
146  totalCol += p->Col ();
147  }
148 
149  kkint32 centerRow = (kkint32)((double)totalRow / (double)size () + 0.5);
150  kkint32 centerCol = (kkint32)((double)totalCol / (double)size () + 0.5);
151  return Point (centerRow, centerCol);
152 }
std::vector< Point * >::iterator iterator
Definition: KKQueue.h:88
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 Col() const
Definition: Point.h:40
kkint32 Row() const
Definition: Point.h:39
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
float PointList::ComputeSegmentLens ( float  heightFactor,
float  widthFactor 
) const

Definition at line 233 of file Point.cpp.

236 {
237  if (QueueSize () < 1)
238  return 0.0f;
239 
240  float totalLen = 0.0f;
241 
242  const_iterator idx;
243  idx = begin ();
244  PointPtr lastPoint = *idx;
245  ++idx;
246 
247  while (idx != end ())
248  {
249  PointPtr nextPoint = *idx; ++idx;
250 
251  float deltaHeight = (float)(nextPoint->Row () - lastPoint->Row ()) * heightFactor;
252  float deltaWidth = (float)(nextPoint->Col () - lastPoint->Col ()) * widthFactor;
253 
254  float segmentLen = sqrt (deltaHeight * deltaHeight + deltaWidth * deltaWidth);
255 
256  totalLen += segmentLen;
257  lastPoint = nextPoint;
258  }
259 
260  return totalLen;
261 } /* ComputeSegmentLens */
kkint32 Col() const
Definition: Point.h:40
kkint32 Row() const
Definition: Point.h:39
std::vector< Point * >::const_iterator const_iterator
Definition: KKQueue.h:89
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
kkint32 QueueSize() const
PointListPtr PointList::FromDelStr ( const KKStr s)
static

Definition at line 176 of file Point.cpp.

References KKB::KKStr::ChopFirstChar(), KKB::KKStr::Concat(), KKB::KKStr::ExtractTokenInt(), KKB::KKStr::Find(), KKB::KKStr::FirstChar(), KKB::KKStr::KKStr(), KKB::KKStr::Len(), KKB::KKStr::operator=(), PointList(), KKB::KKStr::SubStrPart(), and KKB::KKStr::TrimLeft().

177 {
178  PointListPtr result = new PointList (true);
179 
180  KKStr s (_s);
181  s.TrimLeft ();
182 
183  while (s.Len () > 0)
184  {
185  char nextCh = s.FirstChar ();
186  char endPairChar = 0;
187  if (nextCh == '[')
188  endPairChar = ']';
189 
190  else if (nextCh == '(')
191  endPairChar = ')';
192 
193  else
194  {
195  // Not Bracketed.
196  endPairChar = 0;
197  kkint16 row = (kkint16)s.ExtractTokenInt (",\t\n\t");
198  kkint16 col = (kkint16)s.ExtractTokenInt (",\t\n\t");
199  result->PushOnBack (new Point (row, col));
200  }
201 
202  if (endPairChar != 0)
203  {
204  KKStr pairStr = "";
205  kkint32 idx = s.Find (endPairChar);
206  if (idx >= 0)
207  {
208  pairStr = s.SubStrPart (0, idx - 1);
209  s = s.SubStrPart (idx + 1);
210  }
211  else
212  {
213  pairStr = s;
214  s = "";
215  }
216 
217  kkint16 row = (kkint16)pairStr.ExtractTokenInt (",");
218  kkint16 col = (kkint16) pairStr.ExtractTokenInt (",");
219  result->PushOnBack (new Point (row, col));
220  nextCh = s.FirstChar ();
221  if ((nextCh == ',') || (nextCh == '\n') || (nextCh == '\r') || (nextCh == '\t'))
222  s.ChopFirstChar ();
223  }
224  s.TrimLeft ();
225  }
226 
227  return result;
228 } /* FromDelStr */
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
__int32 kkint32
Definition: KKBaseTypes.h:88
PointList(const PointList &pointList)
Definition: Point.cpp:93
char FirstChar() const
Definition: KKStr.cpp:1970
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1745
virtual void PushOnBack(EntryPtr _entry)
Definition: KKQueue.h:398
kkint32 ExtractTokenInt(const char *delStr)
Definition: KKStr.cpp:3129
kkint32 Find(const KKStr &str, kkint32 pos=0) const
Will return the position where the 1st instance of &#39;str&#39; after &#39;pos&#39; occurs or -1 if not found...
Definition: KKStr.cpp:3931
void ChopFirstChar()
Definition: KKStr.cpp:1649
Container object used to maintaining a list of pixel locations.
Definition: Point.h:75
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; until the end of the s...
Definition: KKStr.cpp:2780
KKStr PointList::ToDelStr ( char  del) const

Definition at line 156 of file Point.cpp.

References KKB::Point::Col(), KKB::KKStr::Concat(), and KKB::Point::Row().

157 {
158  if (QueueSize () < 1)
159  return "[]";
160 
161  KKStr result (QueueSize () * 10);
162 
163  int count = 0;
165  for (idx = begin (); idx != end (); ++idx, ++count)
166  {
167  PointPtr p = *idx;
168  if (count > 0)
169  result << del;
170  result << p->Row () << del << p->Col ();
171  }
172  return result;
173 } /* ToDelStr */
kkint32 Col() const
Definition: Point.h:40
kkint32 Row() const
Definition: Point.h:39
std::vector< Point * >::const_iterator const_iterator
Definition: KKQueue.h:89
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
kkint32 QueueSize() const

The documentation for this class was generated from the following files: