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

phImageWindow.cpp

Go to the documentation of this file.
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 <phObject.h>
00033 #include <phMutex.h>
00034 #include <phSemaphore.h>
00035 #include <phCondition.h>
00036 #include <phRWLock.h>
00037 #include <phThread.h>
00038 #include <phList.h>
00039 #include <phTimeStamp.h>
00040 #include <phTimeInterval.h>
00041 #include <phLiveObject.h>
00042 #include <phDataObject.h>
00043 #include <phImage.h>
00044 
00045 #include <phImageWindow.h>
00046 
00047 #include <phError.h>
00048 #include <phMemory.h>
00049 #include <phPrint.h>
00050 
00051 /* ---------------------------------------------------------------------- */
00052 phImageWindow::phImageWindow( int32_t   x,  int32_t     y,
00053                               uint32_t  w,  uint32_t    h,
00054                               char     *title,
00055                               uint32_t  flags )
00056 {
00057     phFUNCTION("phImageWindow::phImageWindow")
00058     
00059     rc = this->lock();
00060     phPRINT_RC(rc,NULL,"this->lock()");
00061 
00062     this->setName("phImageWindow");
00063 
00064     this->m_min_width       = (w > 0) ? w : 1;
00065     this->m_min_height      = (h > 0) ? h : 1;
00066     
00067     this->m_x = x;
00068     this->m_y = y;
00069     this->m_w = (w > 0) ? w : 1;
00070     this->m_h = (h > 0) ? h : 1;
00071 
00072     this->m_formats = phImageRGB24;
00073     
00074     this->m_title = NULL;
00075     this->m_title_size = 0;
00076     rc = this->setTitle(title);
00077     phPRINT_RC(rc,NULL,"this->setTitle");
00078      
00079     this->m_timer.clear();
00080     this->m_fps = 0.0;
00081     this->m_frames = 0;
00082 
00083 /* error: */
00084     rc = this->unlock();
00085     phPRINT_RC(rc,NULL,"this->unlock() failed.");
00086     
00087     return;
00088 }
00089 
00090 /* ---------------------------------------------------------------------- */
00091 phImageWindow::~phImageWindow()
00092 {
00093     phFUNCTION("phImageWindow::~phImageWindow")
00094     
00095     rc = this->lock();
00096     phPRINT_RC(rc,NULL,"this->lock()");
00097     
00098     phFree(this->m_title);
00099 }
00100 
00101 /* ---------------------------------------------------------------------- */
00102 const char *phImageWindow::getTitle()
00103 {
00104     phFUNCTION("phImageWindow::getTitle")
00105     char *ret_title = NULL;
00106     
00107     rc = this->lock();
00108     phPRINT_RC(rc,NULL,"this->lock()");
00109 
00110     ret_title = this->m_title;
00111     
00112     rc = this->lock();
00113     phPRINT_RC(rc,NULL,"this->lock()");
00114 
00115     return ret_title;
00116 }
00117 
00118 /* ---------------------------------------------------------------------- */
00119 int phImageWindow::setTitle(const char *title)
00120 {
00121     phFUNCTION("phImageWindow::setTitle")
00122     int locked = 0;
00123     
00124     uint32_t title_len = (title != NULL) ? strlen(title) : 50;
00125 
00126     rc = this->lock();
00127     phCHECK_RC(rc,NULL,"this->lock()");
00128     locked = 1;    
00129 
00130     if (title != NULL)
00131     {
00132         phDALLOC_RESIZE(this->m_title,
00133                         this->m_title_size,
00134                         (title_len+1),
00135                         char);
00136 #ifdef HAVE_SNPRINTF
00137         snprintf(this->m_title,title_len+1,"%s",title);
00138 #else
00139         sprintf(this->m_title,"%s",title);
00140 #endif
00141     }
00142     /*
00143     else
00144     {
00145         if (this->m_title != NULL)
00146         {
00147             phFree(this->m_title);
00148         }
00149     }
00150     */
00151 
00152     rc = this->unlock();
00153     locked = 0;
00154     phCHECK_RC(rc,NULL,"this->unlock()");
00155 
00156     return phSUCCESS;
00157 error:
00158     if (locked)
00159     {
00160         rc = this->unlock();
00161         locked = 0;
00162         phPRINT_RC(rc,NULL,"this->unlock()");
00163     }
00164     return phFAIL;
00165 }
00166 
00167 /* ---------------------------------------------------------------------- */
00168 int phImageWindow::setMinSize( const phUSize &s )
00169 {
00170     return this->setMinSize(s.w,s.h);
00171 }
00172 
00173 /* ---------------------------------------------------------------------- */
00174 int phImageWindow::setMinSize( uint32_t w, uint32_t h )
00175 {
00176     phFUNCTION("phImageWindow::setMinSize")
00177     int resized = phSUCCESS;
00178     
00179     if ((w > 0) && (h > 0))
00180     {
00181         rc = this->lock();
00182         phPRINT_RC(rc,NULL,"this->lock()");
00183     
00184         if (((this->m_w == this->m_min_width) && 
00185              (this->m_h == this->m_min_height)) && 
00186             ((this->m_w < w) || (this->m_h < h)))
00187         {
00188             resized = 1;
00189         }               
00190         
00191         if (resized != phSUCCESS)
00192         {
00193             rc = this->resize(w,h);
00194             phPRINT_RC(rc,NULL,"this->resize(w:%u,h:%u)",w,h);
00195         }
00196         
00197         this->m_min_width = w;
00198         this->m_min_height = h;
00199 
00200         rc = this->private_minsize(this->m_min_width,this->m_min_height);
00201         phPRINT_RC(rc,NULL,"private_minsize");
00202     
00203         rc = this->unlock();
00204         phPRINT_RC(rc,NULL,"this->unlock()");
00205     }
00206     
00207     return resized;
00208 }
00209 
00210 /* ---------------------------------------------------------------------- */
00211 phUSize phImageWindow::getMinSize( )
00212 { 
00213     phFUNCTION("phImageWindow::getMinSize")
00214     
00215     phUSize retval;
00216     
00217     rc = this->lock();
00218     phPRINT_RC(rc,NULL,"this->lock()");
00219     
00220     retval.w = this->m_min_width;
00221     retval.h = this->m_min_height;
00222     
00223     rc = this->unlock();
00224     phPRINT_RC(rc,NULL,"this->unlock()");
00225     
00226     return retval;
00227 }
00228 
00229 /* ---------------------------------------------------------------------- */
00230 uint32_t phImageWindow::getWidth()
00231 { 
00232     return this->m_w;
00233 }
00234 /* ---------------------------------------------------------------------- */
00235 uint32_t phImageWindow::getHeight()
00236 { 
00237     return this->m_h;
00238 }
00239 
00240 /* ---------------------------------------------------------------------- */
00241 phUSize phImageWindow::getSize()
00242 { 
00243     phFUNCTION("phImageWindow::getLocation")
00244     
00245     phUSize retval;
00246     
00247     rc = this->lock();
00248     phPRINT_RC(rc,NULL,"this->lock()");
00249     
00250     retval.w = this->m_w;
00251     retval.h = this->m_h;
00252     
00253     rc = this->unlock();
00254     phPRINT_RC(rc,NULL,"this->unlock()");
00255     
00256     return retval;
00257 }
00258 
00259 /* ---------------------------------------------------------------------- */
00260 int32_t phImageWindow::getX()
00261 { 
00262     return this->m_x;
00263 }
00264 /* ---------------------------------------------------------------------- */
00265 int32_t phImageWindow::getY()
00266 { 
00267     return this->m_y;
00268 }
00269 /* ---------------------------------------------------------------------- */
00270 phPoint phImageWindow::getLocation()
00271 { 
00272     phFUNCTION("phImageWindow::getLocation")
00273     
00274     phPoint retval;
00275     
00276     rc = this->lock();
00277     phPRINT_RC(rc,NULL,"this->lock()");
00278     
00279     retval.x = this->m_x;
00280     retval.y = this->m_y;
00281     
00282     rc = this->unlock();
00283     phPRINT_RC(rc,NULL,"this->unlock()");
00284     
00285     return retval;
00286 }
00287 
00288 /* ---------------------------------------------------------------------- */
00289 phImage *phImageWindow::getImage()
00290 { 
00291     return &(this->m_image);
00292 }
00293 
00294 /* ---------------------------------------------------------------------- */
00295 int phImageWindow::setFormats( uint32_t formats )
00296 {
00297     return phFAIL;
00298 }
00299 
00300 /* ---------------------------------------------------------------------- */
00301 uint32_t phImageWindow::getFormats()
00302 { 
00303     return this->m_formats;
00304 }
00305 
00306 /* ---------------------------------------------------------------------- */
00307 void phImageWindow::show()
00308 {
00309     phFUNCTION("phImageWindow::show")
00310     int locked = 0;
00311 
00312     phTHIS_LOCK(locked);
00313 
00314     this->private_show();
00315     
00316     phTHIS_UNLOCK(locked);
00317 
00318     return;
00319 error:
00320     phTHIS_ERROR_UNLOCK(locked);
00321     
00322     return;
00323 }
00324 
00325 /* ---------------------------------------------------------------------- */
00326 void phImageWindow::hide()
00327 {
00328     phFUNCTION("phImageWindow::hide")
00329     int locked = 0;
00330     
00331     phTHIS_LOCK(locked);
00332 
00333     this->private_hide();
00334     
00335     phTHIS_UNLOCK(locked);
00336 
00337     return;
00338 error:
00339     phTHIS_ERROR_UNLOCK(locked);
00340     
00341     return;
00342 }
00343 
00344 /* ---------------------------------------------------------------------- */
00345 int phImageWindow::redraw()
00346 {
00347     phFUNCTION("phImageWindow::redraw")
00348     int locked = 0;
00349     int retrc  = phSUCCESS;
00350     
00351     phTHIS_LOCK(locked);
00352 
00353     retrc = this->private_redraw();
00354     
00355     phTHIS_UNLOCK(locked);
00356 
00357     return retrc;
00358 error:
00359     phTHIS_ERROR_UNLOCK(locked);
00360     
00361     return phFAIL;
00362 }
00363 
00364 /* ---------------------------------------------------------------------- */
00365 int phImageWindow::update()
00366 {
00367     phFUNCTION("phImageWindow::update")
00368     int locked = 0;
00369     int retrc  = phSUCCESS;
00370     
00371     phTHIS_LOCK(locked);
00372 
00373     retrc = this->private_update();
00374     
00375     phTHIS_UNLOCK(locked);
00376 
00377     return retrc;
00378 error:
00379     phTHIS_ERROR_UNLOCK(locked);
00380     
00381     return phFAIL;
00382 }
00383 
00384 /* ---------------------------------------------------------------------- */
00385 int phImageWindow::resize( uint32_t w, uint32_t h)
00386 {
00387     phFUNCTION("phImageWindow::resize")
00388     int locked = 0;
00389     int retrc  = phSUCCESS;
00390     
00391     phTHIS_LOCK(locked);
00392 
00393     retrc = this->private_resize(w,h);
00394     
00395     phTHIS_UNLOCK(locked);
00396 
00397     return retrc;
00398 error:
00399     phTHIS_ERROR_UNLOCK(locked);
00400     
00401     return phFAIL;
00402 }
00403 
00404 /* ---------------------------------------------------------------------- */
00405 int phImageWindow::move( int32_t x, int32_t y)
00406 {
00407     phFUNCTION("phImageWindow::move")
00408     int locked = 0;
00409     int retrc  = phSUCCESS;
00410     
00411     phTHIS_LOCK(locked);
00412 
00413     retrc = this->private_move(x,y);
00414     
00415     phTHIS_UNLOCK(locked);
00416 
00417     return retrc;
00418 error:
00419     phTHIS_ERROR_UNLOCK(locked);
00420     
00421     return phFAIL;
00422 }
00423 
00424 /* ---------------------------------------------------------------------- */
00425 int phImageWindow::tickFrame()
00426 {
00427     phFUNCTION("phImageWindow::tickFrame")
00428     int locked = 0;
00429 
00430     phTHIS_LOCK(locked);
00431     
00432     if (this->m_frames > 15)
00433     {
00434         phTimeStamp elapsed;
00435         float usec = 0.0;
00436         float f = 0.0;
00437         
00438         this->m_timer.stop();
00439         elapsed = this->m_timer.elapsed();
00440 
00441         f       = (float)this->m_frames;
00442         usec    = (float)elapsed.getMicroseconds();
00443         
00444         this->m_fps = (float)(f / (usec / 1000000.0));
00445         
00446         //phPRINT("%0.1f:%0.1f:%0.5f\n",f,usec,fps);
00447         this->m_frames = 0;
00448     }
00449     if (this->m_frames == 0)
00450     {
00451         this->m_timer.start();
00452     }
00453     this->m_frames++;
00454     
00455 #if 0
00456     /* Compare the current time to the start time to figure 
00457      * out how fast things are being displayed */
00458     if (this->m_frames > 30)
00459     {
00460         this->m_time.stop();
00461         if (this->m_time.elapsed().getNanoSeconds() > 0)
00462         {
00463             this->m_fps = ((float)this->m_frames) / 
00464                           ((float)this->m_time.elapsed().getSeconds());
00465 #if TIMESTUFF()
00466             this->m_time.report(this->getName());
00467             phPROGRESS("%0.5fps\n",this->m_fps);
00468 #endif   
00469         }
00470         this->m_frames = 0;
00471         this->m_time.clear();
00472         this->m_time.start();
00473     }
00474     this->m_frames++;
00475 #endif
00476     phTHIS_UNLOCK(locked);
00477     return phSUCCESS;
00478 error:
00479     phTHIS_ERROR_UNLOCK(locked);
00480     return phFAIL;
00481 }
00482 
00483 /* ---------------------------------------------------------------------- */
00484 float phImageWindow::getFps()
00485 {
00486     phFUNCTION("phImageWindow::getFps")
00487     int     locked  = 0;
00488     float   retval  = 0.0;
00489     
00490     phTHIS_LOCK(locked);
00491     retval = this->m_fps; 
00492     phTHIS_UNLOCK(locked);
00493     
00494     return retval;
00495 error:
00496     phTHIS_ERROR_UNLOCK(locked);
00497     return 0.0;
00498 }
00499 




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:02 2007 for phission by  doxygen 1.4.4