KSquare Utilities
KKB::BlobList Class Reference

Maintains a list of blobs. More...

#include <Blob.h>

+ Inheritance diagram for KKB::BlobList:

Public Member Functions

 BlobList (bool _owner)
 
 ~BlobList ()
 
void DeleteEntry (BlobPtr b)
 
BlobPtr LocateLargestBlob ()
 Will return Blob with largest pixel count. More...
 
BlobPtr LocateMostComplete ()
 Locates the blob that covers the greatest part of the raster; that is the one who has the largest (Height x Width) More...
 
BlobPtr LookUpByBlobId (kkint32 blobId)
 Will return pointer to blob with 'blobId'; if not found will return NULL. More...
 
void MergeBlobIds (BlobPtr blob, kkint32 blobId, kkint32 **blobIds)
 Used by the Connected component analysis to merge two blobs together. More...
 
BlobPtr MergeIntoSingleBlob (BlobPtr blob1, kkint32 blob2Id, kkint32 **blobIds)
 
BlobPtr NewBlob (kkuint32 rowTop, kkuint32 colLeft)
 
void PushOnBack (BlobPtr blob)
 
void PushOnFront (BlobPtr blob)
 

Detailed Description

Maintains a list of blobs.

Definition at line 77 of file Blob.h.

Constructor & Destructor Documentation

BlobList::BlobList ( bool  _owner)

Definition at line 64 of file Blob.cpp.

References BlobList().

Referenced by BlobList(), KKB::Raster::ConnectedComponent8Conected(), and KKB::Raster::ExtractBlobs().

64  :
65  availableBlobs (),
66  nextBlobId (0)
67 {
68 }
BlobList::~BlobList ( )

Definition at line 72 of file Blob.cpp.

73 {
74  while (availableBlobs.size () > 0)
75  {
76  BlobPtr b = availableBlobs.back ();
77  availableBlobs.pop_back ();
78 
79  delete b;
80  }
81 
82  iterator idx2;
83  iterator endIdx = end ();
84  for (idx2 = begin (); idx2 != endIdx; ++idx2)
85  {
86  BlobPtr b = idx2->second;
87  delete b;
88  }
89 }
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32

Member Function Documentation

void KKB::BlobList::DeleteEntry ( BlobPtr  b)
BlobPtr BlobList::LocateLargestBlob ( )

Will return Blob with largest pixel count.

Definition at line 230 of file Blob.cpp.

References KKB::Blob::pixelCount.

Referenced by KKB::Raster::ConnectedComponent(), and KKB::Raster::ConnectedComponent8Conected().

231 {
232  BlobPtr blob = NULL;
233  BlobPtr tempBlob = NULL;
234  kkint32 largestSize = 0;
235 
236  const_iterator idx;
237  const_iterator endIdx = end ();
238 
239  for (idx = begin (); idx != endIdx; ++idx)
240  {
241  tempBlob = idx->second;
242  if (tempBlob->pixelCount > largestSize)
243  {
244  largestSize = tempBlob->pixelCount;
245  blob = tempBlob;
246  }
247  }
248  return blob;
249 } /* LocateLargestBlob */
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 pixelCount
Definition: Blob.h:64
BlobPtr BlobList::LocateMostComplete ( )

Locates the blob that covers the greatest part of the raster; that is the one who has the largest (Height x Width)

Definition at line 253 of file Blob.cpp.

References KKB::Blob::Height(), and KKB::Blob::Width().

Referenced by KKB::Raster::ReduceToMostCompleteBlob().

254 {
255  BlobPtr blob = NULL;
256  BlobPtr tempBlob = NULL;
257  kkint32 largestSize = 0;
258 
259  const_iterator idx;
260  const_iterator endIdx = end ();
261 
262  for (idx = begin (); idx != endIdx; ++idx)
263  {
264  tempBlob = idx->second;
265  kkint32 size = tempBlob->Height () * tempBlob->Width ();
266  if (size > largestSize)
267  {
268  largestSize = size;
269  blob = tempBlob;
270  }
271  }
272  return blob;
273 } /* LocateMostComplete */
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 Width()
Number of columns that this blob occupies.
Definition: Blob.h:54
kkint32 Height()
Number of rows that the blob occupies.
Definition: Blob.h:49
BlobPtr BlobList::LookUpByBlobId ( kkint32  blobId)

Will return pointer to blob with 'blobId'; if not found will return NULL.

Definition at line 53 of file Blob.cpp.

Referenced by KKB::Raster::ConnectedComponent8Conected(), and KKB::Raster::ExtractBlobs().

54 {
55  const_iterator idx;
56  idx = find (blobId);
57  if (idx == end ())
58  return NULL;
59  return idx->second;
60 } /* LookUpByBlobId */
void BlobList::MergeBlobIds ( BlobPtr  blob,
kkint32  blobId,
kkint32 **  blobIds 
)

Used by the Connected component analysis to merge two blobs together.

When the connected component discovers that two separate blobs are actually connected if will call this method to merge them together into a single blob.

Definition at line 122 of file Blob.cpp.

References KKB::Blob::colLeft, KKB::Blob::colRight, KKB::Blob::Id(), KKB::Blob::pixelCount, KKB::Blob::rowBot, and KKB::Blob::rowTop.

Referenced by KKB::Raster::ConnectedComponent8Conected().

126 {
127  kkint32 newId = blob->Id ();
128 
129  iterator idx;
130  idx = find (blobId);
131  if (idx == end ())
132  return;
133  BlobPtr blobToMerge = idx->second;
134 
135  kkint32 col;
136  kkint32 row;
137 
138  kkint32 rowBot = blobToMerge->rowBot;
139  kkint32 colRight = blobToMerge->colRight;
140 
141  for (row = blobToMerge->rowTop; row <= rowBot; row++)
142  {
143  for (col = blobToMerge->colLeft; col <= colRight; col++)
144  {
145  if (blobIds[row][col] == blobId)
146  blobIds[row][col] = newId;
147  }
148  }
149 
150  blob->rowTop = Min (blob->rowTop, blobToMerge->rowTop);
151  blob->rowBot = Max (blob->rowBot, blobToMerge->rowBot);
152  blob->colLeft = Min (blob->colLeft, blobToMerge->colLeft);
153  blob->colRight = Max (blob->colRight, blobToMerge->colRight);
154  blob->pixelCount = blob->pixelCount + blobToMerge->pixelCount;
155 
156  erase (idx);
157  availableBlobs.push_back (blobToMerge);
158 } /* MergeBlobIds */
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 colLeft
Definition: Blob.h:61
kkint32 rowBot
Definition: Blob.h:65
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
kkint32 rowTop
Definition: Blob.h:66
kkint32 pixelCount
Definition: Blob.h:64
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
kkint32 Id()
The unique ID assigned to this blob.
Definition: Blob.h:44
kkint32 colRight
Definition: Blob.h:62
BlobPtr BlobList::MergeIntoSingleBlob ( BlobPtr  blob1,
kkint32  blob2Id,
kkint32 **  blobIds 
)

Definition at line 163 of file Blob.cpp.

References KKB::Blob::colLeft, KKB::Blob::colRight, KKB::Blob::Id(), KKB::Blob::PixelCount(), KKB::Blob::pixelCount, KKB::Blob::rowBot, and KKB::Blob::rowTop.

Referenced by KKB::Raster::ExtractBlobs().

167 {
168  kkint32 blob1Id = blob1->Id ();
169  iterator idx;
170  idx = find (blob2Id);
171  if (idx == end ())
172  return blob1;
173  BlobPtr blob2 = idx->second;
174 
175  if ((blob1Id == blob2Id) || (blob1 == blob2))
176  {
177  return blob1;
178  }
179 
180  BlobPtr srcBlob = NULL;
181  BlobPtr destBlob = NULL;
182 
183  if (blob1->PixelCount () > blob2->PixelCount ())
184  {
185  srcBlob = blob2;
186  destBlob = blob1;
187  }
188  else
189  {
190  srcBlob = blob1;
191  destBlob = blob2;
192  }
193 
194  kkint32 destBlobId = destBlob->Id ();
195  kkint32 srcBlobId = srcBlob->Id ();
196 
197  kkint32 col = 0;
198  kkint32 row = 0;
199 
200  kkint32 rowBot = srcBlob->rowBot;
201  kkint32 colRight = srcBlob->colRight;
202 
203  for (row = srcBlob->rowTop; row <= rowBot; ++row)
204  {
205  for (col = srcBlob->colLeft; col <= colRight; ++col)
206  {
207  if (blobIds[row][col] == srcBlobId)
208  blobIds[row][col] = destBlobId;
209  }
210  }
211 
212  destBlob->rowTop = Min (destBlob->rowTop, srcBlob->rowTop);
213  destBlob->rowBot = Max (destBlob->rowBot, srcBlob->rowBot);
214  destBlob->colLeft = Min (destBlob->colLeft, srcBlob->colLeft);
215  destBlob->colRight = Max (destBlob->colRight, srcBlob->colRight);
216  destBlob->pixelCount = destBlob->pixelCount + srcBlob->pixelCount;
217 
218  idx = find (srcBlobId);
219  if (idx != end ())
220  erase (idx);
221 
222  availableBlobs.push_back (srcBlob);
223  return destBlob;
224 } /* MergeIntoSingleBlob */
__int32 kkint32
Definition: KKBaseTypes.h:88
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 colLeft
Definition: Blob.h:61
kkint32 rowBot
Definition: Blob.h:65
T Min(T a, T b)
Generic Min function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:168
kkint32 rowTop
Definition: Blob.h:66
kkint32 pixelCount
Definition: Blob.h:64
kkint32 PixelCount()
Number of pixels that are part of this blob.
Definition: Blob.h:56
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
kkint32 Id()
The unique ID assigned to this blob.
Definition: Blob.h:44
kkint32 colRight
Definition: Blob.h:62
BlobPtr BlobList::NewBlob ( kkuint32  rowTop,
kkuint32  colLeft 
)

Definition at line 93 of file Blob.cpp.

References KKB::Blob::colLeft, KKB::Blob::colRight, PushOnBack(), KKB::Blob::rowBot, and KKB::Blob::rowTop.

Referenced by KKB::Raster::ConnectedComponent8Conected(), and KKB::Raster::ExtractBlobs().

96 {
97  BlobPtr blob = NULL;
98  if (availableBlobs.size () > 0)
99  {
100  blob = availableBlobs.back ();
101  blob->InitialzieAsNew (nextBlobId);
102  availableBlobs.pop_back ();
103  }
104  else
105  {
106  blob = new Blob (nextBlobId);
107  }
108 
109  blob->rowTop = rowTop;
110  blob->rowBot = rowTop;
111 
112  blob->colLeft = colLeft;
113  blob->colRight = colLeft;
114 
115  nextBlobId++;
116  PushOnBack (blob);
117  return blob;
118 }
Used by the Raster object to identify a distinct blob; where it is in the raster and its unique id...
Definition: Blob.h:32
kkint32 colLeft
Definition: Blob.h:61
kkint32 rowBot
Definition: Blob.h:65
kkint32 rowTop
Definition: Blob.h:66
void PushOnBack(BlobPtr blob)
Definition: Blob.cpp:280
kkint32 colRight
Definition: Blob.h:62
void InitialzieAsNew(kkint32 _id)
Definition: Blob.cpp:41
void BlobList::PushOnBack ( BlobPtr  blob)

Definition at line 280 of file Blob.cpp.

Referenced by NewBlob().

281 {
282  insert (BlobIndexPair (blob->Id (), blob));
283 } /* PushOnBack */
kkint32 Id()
The unique ID assigned to this blob.
Definition: Blob.h:44
void BlobList::PushOnFront ( BlobPtr  blob)

Definition at line 287 of file Blob.cpp.

288 {
289  insert (BlobIndexPair (blob->Id (), blob));
290 }
kkint32 Id()
The unique ID assigned to this blob.
Definition: Blob.h:44

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