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

phHoughData.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 <phHoughData.h>
00033 
00034 #include <phError.h>
00035 #include <phFile.h>
00036 #include <phMemory.h>
00037 #include <phPrint.h>
00038 
00039 /* ------------------------------------------------------------------------- */
00040 /* phHoughData */
00041 phHoughData::phHoughData()
00042 {
00043     this->init();
00044 }
00045 
00046 /* ------------------------------------------------------------------------- */
00047 phHoughData::~phHoughData()
00048 {
00049     phFUNCTION("phHoughData::~phHoughData")
00050 
00051     rc = this->lock();
00052     phPRINT_RC(rc,NULL,"lock");
00053 
00054     phFree(this->m_lines);
00055 
00056     this->m_lines_size = 0;
00057     this->m_line_count = 0;
00058     
00059     rc = this->unlock();
00060     phPRINT_RC(rc,NULL,"unlock");
00061 
00062 }
00063 
00064 /* ------------------------------------------------------------------------- */
00065 void phHoughData::init()
00066 {
00067     phFUNCTION("phHoughData::init()")
00068 
00069     rc = this->lock();
00070     phPRINT_RC(rc,NULL,"lock");
00071 
00072     this->setName("phHoughData");
00073 
00074     this->m_lines       = NULL;
00075     this->m_lines_size  = 0;
00076     this->m_line_count  = 0;
00077     
00078     rc = this->unlock();
00079     phPRINT_RC(rc,NULL,"unlock");
00080 }
00081 
00082 /* ------------------------------------------------------------------------- */
00083 phHoughData::phHoughData(const phHoughData &hough)
00084 {
00085     phFUNCTION("phHoughData::phHoughData")
00086     phHoughData *houghptr = (phHoughData *)&hough;
00087 
00088     rc = this->lock();
00089     phPRINT_RC(rc,NULL,"lock");
00090 
00091     this->init();
00092     
00093     rc = this->copy(houghptr);
00094     phPRINT_RC(rc,NULL,"this->copy(houghptr);");
00095     
00096     rc = this->unlock();
00097     phPRINT_RC(rc,NULL,"unlock");
00098 }
00099 
00100 /* ---------------------------------------------------------------------- */
00101 int phHoughData::copy( phObject *copyto_object )
00102 {
00103     phFUNCTION("phHoughData::copy")
00104     
00105     if (this->isNamed(((phObject *)copyto_object)->getName()))
00106     {
00107         phHoughData *hough = (phHoughData *)copyto_object;
00108         return hough->copy(*this);
00109     }
00110     /* Otherwise I'll assume they are incompatible */
00111     else
00112     {
00113         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00114                           "[ this:%s != target:%s ]",
00115                  this->getName(), ((phObject *)copyto_object)->getName());
00116         return phFAIL;
00117     }
00118 }
00119 
00120 /* ---------------------------------------------------------------------- */
00121 int phHoughData::swap( phObject *object )
00122 {
00123     phFUNCTION("phHoughData::swap")
00124 
00125     if (this->isNamed(((phObject *)object)->getName()))
00126     {
00127         phHoughData *hough = (phHoughData *)object;
00128 
00129         return hough->copy(*this);
00130     }
00131     /* Otherwise I'll assume they are incompatible */
00132     else
00133     {
00134         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00135                           "[ this:%s != target:%s ]",
00136                  this->getName(), ((phObject *)object)->getName());
00137         return phFAIL;
00138     }    
00139 }
00140 
00141 /* ------------------------------------------------------------------------- */
00142 int phHoughData::copy( phHoughData &copyfrom )
00143 {
00144     phFUNCTION("phHoughData::copy")
00145 
00146     rc = this->lock();
00147     phPRINT_RC(rc,NULL,"lock");
00148 
00149     rc = copyfrom.lock();
00150     phPRINT_RC(rc,NULL,"copyfrom.lock");
00151     rc = this->setData( copyfrom.m_lines,
00152                         copyfrom.m_line_count );
00153     phPRINT_RC(rc,NULL,"copyfrom.setData");
00154    
00155     rc = copyfrom.unlock();
00156     phPRINT_RC(rc,NULL,"copyfrom.unlock");
00157     
00158     rc = this->unlock();
00159     phPRINT_RC(rc,NULL,"unlock");
00160 
00161     return phSUCCESS;
00162 }
00163 
00164 /* ---------------------------------------------------------------------- */
00165 phHoughData &phHoughData::operator =( phHoughData &right )
00166 {
00167     phFUNCTION("phHoughData::operator =")
00168 
00169     if (&right != this)
00170     {
00171         rc = this->copy(right);
00172         phPRINT_RC(rc,NULL,"this->copy(right);");
00173     }
00174 
00175     return *this;
00176 }
00177 
00178 /* ------------------------------------------------------------------------- */
00179 int phHoughData::setData( phLine   *lines, uint32_t line_count )
00180 {
00181     phFUNCTION("phHoughData::setData")
00182 
00183     rc = this->lock();
00184     phPRINT_RC(rc,NULL,"lock");
00185    
00186     this->m_line_count = line_count;
00187     if (this->m_line_count > 0)
00188     {
00189         phDALLOC_RESIZE(this->m_lines,
00190                         this->m_lines_size,
00191                         this->m_line_count,
00192                         phLine);
00193 
00194         phMemmove(this->m_lines, lines, this->m_lines_size);
00195     }
00196     
00197     rc = this->notify();
00198     phPRINT_RC(rc,NULL,"notify() failed.");
00199 
00200     rc = this->unlock();
00201     phPRINT_RC(rc,NULL,"unlock");
00202 
00203     return phSUCCESS;
00204 error:
00205     rc = this->unlock();
00206     phPRINT_RC(rc,NULL,"unlock");
00207 
00208     return phFAIL;
00209 }
00210 
00211 /* ------------------------------------------------------------------------- */
00212 uint32_t phHoughData::getLineCount()
00213 {
00214     return this->m_line_count;
00215 }
00216 
00217 /* ------------------------------------------------------------------------- */
00218 phLine  phHoughData::getLine( uint32_t index )
00219 {
00220     if (index > this->m_line_count)
00221     {
00222         return phLine_new(0,0,0,0);
00223     }
00224     return this->m_lines[index];
00225 }
00226 
00227 /* ------------------------------------------------------------------------- */
00228 phLine *phHoughData::getLines()
00229 {
00230     return this->m_lines;
00231 }
00232 
00233 /* ---------------------------------------------------------------------- */
00234 void phHoughData::print_data()
00235 {
00236     phFUNCTION("phHoughData::print_data")
00237     uint32_t i = 0;
00238     uint32_t j = 0;
00239     int locked = 0;
00240 
00241     phTHIS_LOOSE_LOCK(locked);
00242  
00243     printf("\nphHoughData {\n");
00244     
00245     for (i = 0; i < this->m_line_count; i++ )
00246     {
00247         printf("\t[%6u] (%3d, %3d) -> (%3u, %3u)\n",
00248                 i,
00249                 this->m_lines[i].x1,
00250                 this->m_lines[i].y1,
00251                 this->m_lines[i].x2,
00252                 this->m_lines[i].y2);
00253     }
00254     
00255     printf("\n};\n");
00256  
00257     fflush(stdout);
00258     
00259     phTHIS_LOOSE_UNLOCK(locked);
00260 }




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