Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phAutoBlobData.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003 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  ---------------------------------------------------------------------------*/
00012 #ifdef HAVE_CONFIG_H
00013     #include <phissionconfig.h>
00014 #endif
00015 #include <phAutoBlobData.h>
00016 #include <phbase.h>
00017 
00018 /* ---------------------------------------------------------------------- */
00019 /* phAutoBlobData : Thread safe structure for copying out blob data from
00020  * another thread. */
00021 /* ---------------------------------------------------------------------- */
00022 phAutoBlobData::phAutoBlobData()
00023 {
00024     this->init();
00025 }
00026 
00027 /* ---------------------------------------------------------------------- */
00028 phAutoBlobData::phAutoBlobData( const phAutoBlobData &blob )
00029 {
00030     phFUNCTION("phAutoBlobData::phAutoBlobData")
00031     phAutoBlobData *blobptr = (phAutoBlobData *)&blob;
00032 
00033     rc = this->writeLock();
00034     phPRINT_RC(rc,NULL,"lock");
00035 
00036     this->init();
00037     
00038     rc = this->copy(blobptr);
00039     phPRINT_RC(rc,NULL,"this->copy(blobptr)");
00040     
00041     rc = this->rwUnlock();
00042     phPRINT_RC(rc,NULL,"unlock");
00043 }
00044 
00045 /* ---------------------------------------------------------------------- */
00046 phAutoBlobData::~phAutoBlobData()
00047 {
00048     phFUNCTION("phAutoBlobData::phAutoBlobData")
00049 
00050     rc = this->writeLock();
00051     phPRINT_RC(rc,NULL,"lock");
00052 
00053     rc = phautoblob_data_free(&(this->m_data));
00054     phPRINT_RC(rc,NULL,"phautoblob_data_free");
00055    
00056     rc = this->rwUnlock();
00057     phPRINT_RC(rc,NULL,"unlock");
00058 }
00059 
00060 /* ---------------------------------------------------------------------- */
00061 void phAutoBlobData::init( )
00062 {
00063     phFUNCTION("phAutoBlobData::init")
00064 
00065     rc = this->writeLock();
00066     phPRINT_RC(rc,NULL,"lock");
00067 
00068     rc = phautoblob_data_new(&(this->m_data));
00069     phPRINT_RC(rc,NULL,"phautoblob_data_new");
00070    
00071     rc = this->rwUnlock();
00072     phPRINT_RC(rc,NULL,"unlock");
00073 }
00074 
00075 /* ---------------------------------------------------------------------- */
00076 int phAutoBlobData::reset()
00077 {
00078     phFUNCTION("phAutoBlobData::reset")
00079 
00080     rc = this->writeLock();
00081     phPRINT_RC(rc,NULL,"lock");
00082 
00083     rc = phautoblob_data_reset(this->m_data);
00084     phPRINT_RC(rc,NULL,"phautoblob_data_reset");
00085 
00086     this->init();
00087    
00088     rc = this->rwUnlock();
00089     phPRINT_RC(rc,NULL,"unlock");
00090 
00091     return phSUCCESS;
00092 }
00093 /* ---------------------------------------------------------------------- */
00094 int phAutoBlobData::copy( phObject *object )
00095 {
00096     phFUNCTION("phAutoBlobData::copy")
00097     
00098     if (this->isNamed(((phObject *)object)->getName()))
00099     {
00100         phAutoBlobData *blob = (phAutoBlobData *)object;
00101         return blob->copy(*this);
00102     }
00103     /* Otherwise I'll assume they are incompatible */
00104     else
00105     {
00106         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00107                           "[ this:%s != target:%s ]",
00108                  this->getName(), ((phObject *)object)->getName());
00109         return phFAIL;
00110     }
00111 }
00112 
00113 /* ---------------------------------------------------------------------- */
00114 int phAutoBlobData::swap( phObject *object )
00115 {
00116     phFUNCTION("phAutoBlobData::swap")
00117 
00118     if (this->isNamed(((phObject *)object)->getName()))
00119     {
00120         phAutoBlobData *blob = (phAutoBlobData *)object;
00121 
00122         return blob->copy(*this);
00123     }
00124     /* Otherwise I'll assume they are incompatible */
00125     else
00126     {
00127         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00128                           "[ this:%s != target:%s ]",
00129                  this->getName(), ((phObject *)object)->getName());
00130         return phFAIL;
00131     }    
00132 }
00133 
00134 /* ---------------------------------------------------------------------- */
00135 int phAutoBlobData::setData( phautoblob_data *data )
00136 {
00137     phFUNCTION("phAutoBlobData::setData")
00138 
00139     rc = this->writeLock();
00140     phPRINT_RC(rc,NULL,"writeLock");
00141 
00142     rc = phautoblob_data_copy( data,/* --> */ this->m_data );
00143     phCHECK_RC(rc,NULL,"phautoblob_data_copy");
00144 
00145     rc = this->notify();
00146     phPRINT_RC(rc,NULL,"notify() failed.");
00147     
00148     rc = this->rwUnlock();
00149     phPRINT_RC(rc,NULL,"rwUnlock");
00150 
00151     return phSUCCESS;
00152 error:
00153     rc = this->rwUnlock();
00154     phPRINT_RC(rc,NULL,"rwUnlock");
00155 
00156     return phFAIL;
00157 }
00158 
00159 /* ---------------------------------------------------------------------- */
00160 int phAutoBlobData::copy( phAutoBlobData &copyfrom )
00161 {
00162     phFUNCTION("phAutoBlobData::copy")
00163 
00164     rc = this->writeLock();
00165     phPRINT_RC(rc,NULL,"writeLock");
00166 
00167     rc = copyfrom.readLock();
00168     phPRINT_RC(rc,NULL,"copyfrom.readLock");
00169 
00170     rc = this->setData( copyfrom.m_data );
00171     phPRINT_RC(rc,NULL,"copyfrom.setData");
00172    
00173     rc = copyfrom.rwUnlock();
00174     phPRINT_RC(rc,NULL,"copyfrom.rwUnlock");
00175     
00176     rc = this->rwUnlock();
00177     phPRINT_RC(rc,NULL,"rwUnlock");
00178 
00179     return phSUCCESS;
00180 }
00181 
00182 /* ---------------------------------------------------------------------- */
00183 int32_t        phAutoBlobData::getTotalLines()
00184 {
00185     return this->m_data->nlines;
00186 }
00187 
00188 /* ---------------------------------------------------------------------- */
00189 auto_line_segment    *phAutoBlobData::getLines()
00190 {
00191     return this->m_data->lines;
00192 }
00193 
00194 /* ---------------------------------------------------------------------- */
00195 auto_line_segment    *phAutoBlobData::getLine(int32_t index)
00196 {
00197     if ((index < 0) || (((uint32_t)index) > this->m_data->nlines))
00198         return NULL;
00199     else
00200         return &(this->m_data->lines[index]);
00201 }
00202 
00203 /* ---------------------------------------------------------------------- */
00204 /* returns a copy of the auto_line_segment */
00205 auto_line_segment    phAutoBlobData::getLineData(int32_t index)
00206 {
00207     if ((index < 0) || (((uint32_t)index) > this->m_data->nlines))
00208         return this->m_data->lines[0];
00209     else
00210         return this->m_data->lines[index];
00211 }
00212 
00213 /* ---------------------------------------------------------------------- */
00214 int32_t        phAutoBlobData::getTotalRows()
00215 {
00216     return this->m_data->nrows;
00217 }
00218 
00219 /* ---------------------------------------------------------------------- */
00220 auto_line_segment    **phAutoBlobData::getRowPtrs()
00221 {
00222     return this->m_data->rows;
00223 }
00224 
00225 /* ---------------------------------------------------------------------- */
00226 int32_t        *phAutoBlobData::getRowIndexArray()
00227 {
00228     return this->m_data->rowindex;
00229 }
00230 
00231 /* ---------------------------------------------------------------------- */
00232 int32_t        phAutoBlobData::getTotalBlobs( uint32_t min_size )
00233 {
00234     phFUNCTION("phAutoBlobData::getTotalBlobs")
00235 
00236     uint32_t count = 0;
00237     uint32_t i = 0;
00238     
00239     rc = this->readLock();
00240     phPRINT_RC(rc,NULL,"this->readLock");
00241     
00242     for (i = 0; i < this->m_data->nblobs; i++)
00243     {
00244         if (this->m_data->blobs[i].mass >= min_size) count++;
00245     }
00246     
00247     rc = this->rwUnlock();
00248     phPRINT_RC(rc,NULL,"this->rwUnlock");
00249     
00250     return count;
00251 }
00252 
00253 /* ---------------------------------------------------------------------- */
00254 phautoblob          *phAutoBlobData::getBlobArray()
00255 {
00256     return this->m_data->blobs;
00257 }
00258 
00259 /* ---------------------------------------------------------------------- */
00260 phautoblob          phAutoBlobData::getBlob(uint32_t blob_index)
00261 {
00262     phFUNCTION("phAutoBlobData::getBlob")
00263     phautoblob blob;
00264     
00265     rc = this->readLock();
00266     phPRINT_RC(rc,NULL,"this->readLock");
00267     
00268     phMemset(&blob,0,sizeof(phautoblob));
00269     
00270     if ((uint32_t)this->m_data->nblobs > blob_index)
00271     {
00272         blob = this->m_data->blobs[blob_index];
00273     }
00274     
00275     rc = this->rwUnlock();
00276     phPRINT_RC(rc,NULL,"this->rwUnlock");
00277     
00278     return blob;
00279 }
00280 
00281 /* ---------------------------------------------------------------------- */
00282 phAutoBlobData &phAutoBlobData::operator =( phAutoBlobData &right )
00283 {
00284     phFUNCTION("phAutoBlobData &phAutoBlobData::operator = &right")
00285 
00286     if (&right != this)
00287     {
00288         rc = this->copy(right);
00289         phPRINT_RC(rc,NULL,"this->copy(right)");
00290     }
00291 
00292     return *this;
00293 }
00294 
00295 /* ---------------------------------------------------------------------- */
00296 void phAutoBlobData::print_data(uint32_t min_size, uint32_t verbose)
00297 {
00298     phFUNCTION("phAutoBlobData::print_data")
00299 
00300     uint32_t k = 0;
00301     uint32_t small_blobs = 0;
00302 
00303     rc = this->readLock();
00304     phPRINT_RC(rc,NULL,"this->readLock");
00305     
00306     /* Get the blob information */
00307     if (verbose == 1)
00308         printf("total_blobs: %lu\n",(long unsigned)this->m_data->nblobs);
00309             
00310     small_blobs = 0;
00311     printf("-------------------------------------------------------------------------------\n");
00312     for (k = 0; k < this->m_data->nblobs; k++ )
00313     {
00314         if (m_data->blobs[k].mass >= min_size)
00315         {
00316             printf("\tk:%4lu blob[%4lu](mass: %6lu, w:%4lu, h:%4lu,"
00317                    "c(%4lu, %4lu) ul(%4lu, %4lu) lr(%4lu, %4lu))\n",
00318                    (long unsigned)k, 
00319                    (long unsigned)m_data->blobs[k].index, 
00320                    (long unsigned)m_data->blobs[k].mass, 
00321                    (long unsigned)m_data->blobs[k].w, 
00322                    (long unsigned)m_data->blobs[k].h,
00323                    (long unsigned)m_data->blobs[k].cx, 
00324                    (long unsigned)m_data->blobs[k].cy,
00325                    (long unsigned)m_data->blobs[k].x1, 
00326                    (long unsigned)m_data->blobs[k].y1, 
00327                    (long unsigned)m_data->blobs[k].x2, 
00328                    (long unsigned)m_data->blobs[k].y2 );
00329         }
00330         else
00331         {
00332             small_blobs++;
00333         }
00334     }
00335     printf("-------------------------------------------------------------------------------\n");
00336     if (verbose == 1)
00337         printf("filtered blob count: %lu\n",(long unsigned)small_blobs);
00338 
00339     fflush(stdout);
00340     
00341     rc = this->rwUnlock();
00342     phPRINT_RC(rc,NULL,"this->rwUnlock");
00343 }
00344 
00345 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:06 2007 for phission by  doxygen 1.4.4