00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 This file is part of Phission. 00010 00011 Phission is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Phission is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with Phission; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 ---------------------------------------------------------------------------*/ 00026 #ifdef HAVE_CONFIG_H 00027 #include <phissionconfig.h> 00028 #endif 00029 00030 #include <phStandard.h> 00031 00032 #include <phBlobData.h> 00033 00034 #include <phError.h> 00035 #include <phMemory.h> 00036 #include <phPrint.h> 00037 00038 /* ---------------------------------------------------------------------- */ 00039 /* phBlobData : Thread safe structure for copying out blob data from 00040 * another thread. */ 00041 /* ---------------------------------------------------------------------- */ 00042 phBlobData::phBlobData() 00043 { 00044 this->init(); 00045 } 00046 00047 /* ---------------------------------------------------------------------- */ 00048 phBlobData::phBlobData( const phBlobData &blob ) 00049 { 00050 phFUNCTION("phBlobData::phBlobData") 00051 phBlobData *blobptr = (phBlobData *)&blob; 00052 00053 rc = this->writeLock(); 00054 phPRINT_RC(rc,NULL,"lock"); 00055 00056 this->init(); 00057 00058 rc = this->copy(blobptr); 00059 phPRINT_RC(rc,NULL,"this->copy(blobptr)"); 00060 00061 rc = this->rwUnlock(); 00062 phPRINT_RC(rc,NULL,"unlock"); 00063 } 00064 00065 /* ---------------------------------------------------------------------- */ 00066 phBlobData::~phBlobData() 00067 { 00068 phFUNCTION("phBlobData::phBlobData") 00069 00070 rc = this->writeLock(); 00071 phPRINT_RC(rc,NULL,"lock"); 00072 00073 rc = phblob_data_free(&(this->m_data)); 00074 phPRINT_RC(rc,NULL,"phblob_data_free"); 00075 00076 rc = this->rwUnlock(); 00077 phPRINT_RC(rc,NULL,"unlock"); 00078 } 00079 00080 /* ---------------------------------------------------------------------- */ 00081 void phBlobData::init( ) 00082 { 00083 phFUNCTION("phBlobData::init") 00084 00085 rc = this->writeLock(); 00086 phPRINT_RC(rc,NULL,"lock"); 00087 00088 rc = phblob_data_new(&(this->m_data)); 00089 phPRINT_RC(rc,NULL,"phblob_data_new"); 00090 00091 rc = this->rwUnlock(); 00092 phPRINT_RC(rc,NULL,"unlock"); 00093 } 00094 00095 /* ---------------------------------------------------------------------- */ 00096 int phBlobData::reset() 00097 { 00098 phFUNCTION("phBlobData::reset") 00099 00100 rc = this->writeLock(); 00101 phPRINT_RC(rc,NULL,"lock"); 00102 00103 rc = phblob_data_reset(this->m_data); 00104 phPRINT_RC(rc,NULL,"phblob_data_reset"); 00105 00106 this->init(); 00107 00108 rc = this->rwUnlock(); 00109 phPRINT_RC(rc,NULL,"unlock"); 00110 00111 return phSUCCESS; 00112 } 00113 /* ---------------------------------------------------------------------- */ 00114 int phBlobData::copy( phObject *copyto_object ) 00115 { 00116 phFUNCTION("phBlobData::copy") 00117 00118 if (this->isNamed(((phObject *)copyto_object)->getName())) 00119 { 00120 phBlobData *blob = (phBlobData *)copyto_object; 00121 return blob->copy(*this); 00122 } 00123 /* Otherwise I'll assume they are incompatible */ 00124 else 00125 { 00126 phPRINT_RC(-1,NULL, "Invalid object pairing in update." 00127 "[ this:%s != target:%s ]", 00128 this->getName(), ((phObject *)copyto_object)->getName()); 00129 return phFAIL; 00130 } 00131 } 00132 00133 /* ---------------------------------------------------------------------- */ 00134 int phBlobData::swap( phObject *object ) 00135 { 00136 phFUNCTION("phBlobData::swap") 00137 00138 if (this->isNamed(((phObject *)object)->getName())) 00139 { 00140 phBlobData *blob = (phBlobData *)object; 00141 00142 return blob->copy(*this); 00143 } 00144 /* Otherwise I'll assume they are incompatible */ 00145 else 00146 { 00147 phPRINT_RC(-1,NULL, "Invalid object pairing in update." 00148 "[ this:%s != target:%s ]", 00149 this->getName(), ((phObject *)object)->getName()); 00150 return phFAIL; 00151 } 00152 } 00153 00154 /* ---------------------------------------------------------------------- */ 00155 int phBlobData::setData( phblob_data *data ) 00156 { 00157 phFUNCTION("phBlobData::setData") 00158 00159 rc = this->writeLock(); 00160 phPRINT_RC(rc,NULL,"writeLock"); 00161 00162 rc = phblob_data_copy( data,/* --> */ this->m_data ); 00163 phCHECK_RC(rc,NULL,"phblob_data_copy"); 00164 00165 rc = this->notify(); 00166 phPRINT_RC(rc,NULL,"notify() failed."); 00167 00168 rc = this->rwUnlock(); 00169 phPRINT_RC(rc,NULL,"rwUnlock"); 00170 00171 return phSUCCESS; 00172 error: 00173 rc = this->rwUnlock(); 00174 phPRINT_RC(rc,NULL,"rwUnlock"); 00175 00176 return phFAIL; 00177 } 00178 00179 /* ---------------------------------------------------------------------- */ 00180 int phBlobData::copy( phBlobData ©from ) 00181 { 00182 phFUNCTION("phBlobData::copy") 00183 00184 rc = this->writeLock(); 00185 phPRINT_RC(rc,NULL,"writeLock"); 00186 00187 rc = copyfrom.readLock(); 00188 phPRINT_RC(rc,NULL,"copyfrom.readLock"); 00189 00190 rc = this->setData( copyfrom.m_data ); 00191 phPRINT_RC(rc,NULL,"copyfrom.setData"); 00192 00193 rc = copyfrom.rwUnlock(); 00194 phPRINT_RC(rc,NULL,"copyfrom.rwUnlock"); 00195 00196 rc = this->rwUnlock(); 00197 phPRINT_RC(rc,NULL,"rwUnlock"); 00198 00199 return phSUCCESS; 00200 } 00201 00202 #if 0 00203 /* ---------------------------------------------------------------------- */ 00204 int32_t phBlobData::getTotalLines() 00205 { 00206 return this->m_data->nlines; 00207 } 00208 00209 /* ---------------------------------------------------------------------- */ 00210 phblob_line_segment *phBlobData::getLines() 00211 { 00212 return this->m_data->lines; 00213 } 00214 00215 /* ---------------------------------------------------------------------- */ 00216 phblob_line_segment *phBlobData::getLine(int32_t index) 00217 { 00218 if ((index < 0) || (((uint32_t)index) > this->m_data->nlines)) 00219 return NULL; 00220 else 00221 return &(this->m_data->lines[index]); 00222 } 00223 00224 /* ---------------------------------------------------------------------- */ 00225 /* returns a copy of the line_segment */ 00226 phblob_line_segment phBlobData::getLineData(int32_t index) 00227 { 00228 if ((index < 0) || (((uint32_t)index) > this->m_data->nlines)) 00229 return this->m_data->lines[0]; 00230 else 00231 return this->m_data->lines[index]; 00232 } 00233 00234 /* ---------------------------------------------------------------------- */ 00235 int32_t phBlobData::getTotalRows() 00236 { 00237 return this->m_data->nrows; 00238 } 00239 00240 /* ---------------------------------------------------------------------- */ 00241 phblob_line_segment **phBlobData::getRowPtrs() 00242 { 00243 return this->m_data->rows; 00244 } 00245 00246 /* ---------------------------------------------------------------------- */ 00247 int32_t *phBlobData::getRowIndexArray() 00248 { 00249 return this->m_data->rowindex; 00250 } 00251 #endif 00252 /* ---------------------------------------------------------------------- */ 00253 int32_t phBlobData::getTotalBlobs( uint32_t min_size ) 00254 { 00255 phFUNCTION("phBlobData::getTotalBlobs") 00256 00257 uint32_t count = 0; 00258 uint32_t i = 0; 00259 00260 rc = this->readLock(); 00261 phPRINT_RC(rc,NULL,"this->readLock"); 00262 00263 for (i = 0; i < this->m_data->nblobs; i++) 00264 { 00265 if (this->m_data->blobs[i].mass >= min_size) count++; 00266 } 00267 00268 rc = this->rwUnlock(); 00269 phPRINT_RC(rc,NULL,"this->rwUnlock"); 00270 00271 return count; 00272 } 00273 00274 /* ---------------------------------------------------------------------- */ 00275 phblob *phBlobData::getBlobArray() 00276 { 00277 return this->m_data->blobs; 00278 } 00279 00280 /* ---------------------------------------------------------------------- */ 00281 phblob phBlobData::getBlob(uint32_t blob_index) 00282 { 00283 phFUNCTION("phBlobData::getBlob") 00284 phblob blob; 00285 00286 rc = this->readLock(); 00287 phPRINT_RC(rc,NULL,"this->readLock"); 00288 00289 phMemset(&blob,0,sizeof(phblob)); 00290 00291 if ((uint32_t)this->m_data->nblobs > blob_index) 00292 { 00293 blob = this->m_data->blobs[blob_index]; 00294 } 00295 00296 rc = this->rwUnlock(); 00297 phPRINT_RC(rc,NULL,"this->rwUnlock"); 00298 00299 return blob; 00300 } 00301 00302 /* ---------------------------------------------------------------------- */ 00303 phBlobData &phBlobData::operator =( phBlobData &right ) 00304 { 00305 phFUNCTION("phBlobData &phBlobData::operator = &right") 00306 00307 if (&right != this) 00308 { 00309 rc = this->copy(right); 00310 phPRINT_RC(rc,NULL,"this->copy(right)"); 00311 } 00312 00313 return *this; 00314 } 00315 00316 /* ---------------------------------------------------------------------- */ 00317 void phBlobData::print_data(uint32_t min_size, uint32_t verbose) 00318 { 00319 phFUNCTION("phBlobData::print_data") 00320 00321 uint32_t k = 0; 00322 uint32_t small_blobs = 0; 00323 00324 rc = this->readLock(); 00325 phPRINT_RC(rc,NULL,"this->readLock"); 00326 00327 /* Get the blob information */ 00328 if (verbose == 1) 00329 printf("total_blobs: %lu\n",(long unsigned)this->m_data->nblobs); 00330 00331 small_blobs = 0; 00332 printf("-------------------------------------------------------------------------------\n"); 00333 for (k = 0; k < this->m_data->nblobs; k++ ) 00334 { 00335 if (m_data->blobs[k].mass >= min_size) 00336 { 00337 printf("\tk:%4lu blob[%4lu](mass: %6lu, w:%4lu, h:%4lu," 00338 "c(%4lu, %4lu) ul(%4lu, %4lu) lr(%4lu, %4lu))\n", 00339 (long unsigned)k, 00340 (long unsigned)m_data->blobs[k].index, 00341 (long unsigned)m_data->blobs[k].mass, 00342 (long unsigned)m_data->blobs[k].w, 00343 (long unsigned)m_data->blobs[k].h, 00344 (long unsigned)m_data->blobs[k].cx, 00345 (long unsigned)m_data->blobs[k].cy, 00346 (long unsigned)m_data->blobs[k].x1, 00347 (long unsigned)m_data->blobs[k].y1, 00348 (long unsigned)m_data->blobs[k].x2, 00349 (long unsigned)m_data->blobs[k].y2 ); 00350 } 00351 else 00352 { 00353 small_blobs++; 00354 } 00355 } 00356 printf("-------------------------------------------------------------------------------\n"); 00357 if (verbose == 1) 00358 printf("filtered blob count: %lu\n",(long unsigned)small_blobs); 00359 00360 fflush(stdout); 00361 00362 rc = this->rwUnlock(); 00363 phPRINT_RC(rc,NULL,"this->rwUnlock"); 00364 } 00365 00366
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |