Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArPixelDevice.h

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #ifndef ARPIXELDEVICE_H
00027 #define ARPIXELDEVICE_H
00028 
00029 #include <stdio.h>
00030 #include "Aria.h"
00059 template<class DataObject>
00060 class ArPixelDevice
00061 {
00062  public:
00064   AREXPORT ArPixelDevice(int x_size, int y_size, double x_fov, double y_fov,
00065               const char *name)
00066   {
00067     myXSize = x_size;
00068     myYSize = y_size;
00069     myXFOV = x_fov;
00070     myYFOV = y_fov;
00071     myName = name;
00072 
00073     mySensorData = NULL;
00074     
00075     if (!allocateSensorDataMemory()) 
00076     {
00077       ArLog::log(ArLog::Terse, "Failed to allocate memory for ArPixelDevice %s", getName());
00078     }
00079     else
00080     {
00081       ArLog::log(ArLog::Verbose, "Allocated memory for ArPixelDevice %s", getName());
00082     }
00083   }
00085   AREXPORT virtual ~ArPixelDevice()
00086   {
00087     if (mySensorData != NULL)
00088     {
00089       for (int i=0; i < myXSize; i++)
00090       {
00091     for (int j=0; j < myYSize; j++)
00092     {
00093       delete mySensorData[i][j];
00094     }
00095     delete [] (mySensorData[i]);
00096       }
00097       delete [] (mySensorData);
00098     }
00099   }
00101   DataObject *getSensorData(int x, int y)
00102   {
00103     if ((x >= 0) && (x < myXSize) && (y >= 0) && (y < myYSize)) 
00104     {
00105       return mySensorData[x][y];
00106     }
00107     else 
00108     {
00109       return NULL;
00110     }
00111   }
00113   int getXDimension(void) { return myXSize; }
00115   int getYDimension(void) { return myYSize; }
00117   double getXFOV(void) { return myXFOV; }
00119   double getYFOV(void) { return myYFOV; }
00121   const char *getName(void) { return myName.c_str(); }
00123   DataObject ***getRawSensorData(void) { return mySensorData; }
00125   AREXPORT virtual int lockDevice() { return(myDeviceMutex.lock()); }
00127   AREXPORT virtual int tryLockDevice() { return(myDeviceMutex.tryLock()); }
00129   AREXPORT virtual int unlockDevice() { return(myDeviceMutex.unlock()); }
00130 protected:
00131   std::string myName;
00132   int myXSize;
00133   int myYSize;
00134   double myXFOV;
00135   double myYFOV;
00136   DataObject ***mySensorData;
00137   ArMutex myDeviceMutex;
00138 
00139   bool allocateSensorDataMemory()
00140   {    
00141     if ((myXSize < 1) || (myYSize < 1)) 
00142     {
00143       ArLog::log(ArLog::Normal, "Bad array size for ArPixelDevice %s", getName());
00144       return false;
00145     }
00146     mySensorData = new DataObject**[myXSize];
00147     if (mySensorData == NULL)
00148     {
00149       ArLog::log(ArLog::Normal, "Cannot allocate memory for ArPixelDevice %s", getName());
00150       return false;
00151     }
00152     for (int i=0; i < myXSize; i++)
00153     {
00154       if ((mySensorData[i] = new DataObject*[myYSize]) == NULL)
00155       {
00156     ArLog::log(ArLog::Normal, "Cannot allocate memory for ArPixelDevice %s", getName());
00157     return false;
00158       }
00159       for (int j=0; j < myYSize; j++) 
00160       {
00161     mySensorData[i][j] = new DataObject;
00162       }      
00163     }
00164     return true;
00165   }
00166 };
00167 
00168 #endif // ARPIXELDEVICE_H

Generated on Tue Feb 20 10:51:40 2007 for Aria by  doxygen 1.4.0