00001 /*!@file Image/NamedImage.H An Image with a name */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@pollux.usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/NamedImage.H $ 00035 // $Id: NamedImage.H 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #ifndef IMAGE_NAMEDIMAGE_H_DEFINED 00039 #define IMAGE_NAMEDIMAGE_H_DEFINED 00040 00041 #include "Image/Image.H" 00042 #include "rutz/shared_ptr.h" 00043 #include <string> 00044 //! NamedImage is an Image with a name. It inherits all functionality of Image. 00045 /*! A copy of the name string is made at construction, and is held in 00046 a shared_ptr, so that further copying NamedImage objects arround 00047 will not copy again the name string. */ 00048 template <class T> class NamedImage : public Image<T> { 00049 public: 00050 //! Construct from an existing Image, possibly converting along the way 00051 template <class T2> inline NamedImage(const Image<T2>& img, const std::string& name); 00052 00053 //! Construct from an existing Image, possibly converting along the way 00054 template <class T2> inline NamedImage(const Image<T2>& img, const char *name); 00055 00056 //! Construct an empty (0-by-0) image (useful for arrays of Images) 00057 inline NamedImage(const std::string& name); 00058 00059 //! Construct an empty (0-by-0) image (useful for arrays of Images) 00060 inline NamedImage(const char *name = ""); 00061 00062 //! Conversion and copy constructor 00063 template <class T2> inline NamedImage(const NamedImage<T2>& A); 00064 00065 //! Conversion and assigment operator 00066 template <class T2> inline NamedImage<T>& operator=(const NamedImage<T2>& A); 00067 00068 //! Assign from an image, preserving our name and doing a clamped convert 00069 /*! This is potentially dangerous, and mostly provided so that we 00070 can inherit all of the Image free functions that return images 00071 (e.g., those of Image/MathOps.H). */ 00072 template <class TT> inline NamedImage<T>& operator=(const Image<TT>& img); 00073 00074 //! Destructor 00075 virtual inline ~NamedImage(); 00076 00077 //! Get the name 00078 inline const std::string& name() const; 00079 00080 //! Set the name post hoc 00081 inline void setName(const std::string& name); 00082 00083 //! Set the name post hoc 00084 inline void setName(const char *name); 00085 00086 //! Access our pointer to our name 00087 inline const rutz::shared_ptr<std::string>& namePtr() const; 00088 00089 private: 00090 rutz::shared_ptr<std::string> itsName; 00091 }; 00092 00093 // ###################################################################### 00094 // Inline function implementation 00095 // ###################################################################### 00096 00097 template <class T> template <class T2> inline 00098 NamedImage<T>::NamedImage(const Image<T2>& img, const std::string& name) : 00099 Image<T>(img), itsName(new std::string(name)) 00100 { } 00101 00102 template <class T> template <class T2> inline 00103 NamedImage<T>::NamedImage(const Image<T2>& img, const char *name) : 00104 Image<T>(img), itsName(new std::string(name)) 00105 { } 00106 00107 template <class T> inline 00108 NamedImage<T>::NamedImage(const std::string& name) : 00109 Image<T>(), itsName(new std::string(name)) 00110 { } 00111 00112 template <class T> inline 00113 NamedImage<T>::NamedImage(const char *name) : 00114 Image<T>(), itsName(new std::string(name)) 00115 { } 00116 00117 template <class T> template <class T2> inline 00118 NamedImage<T>::NamedImage(const NamedImage<T2>& A) : 00119 Image<T>(A), itsName(A.namePtr()) 00120 { } 00121 00122 template <class T> template <class T2> inline 00123 NamedImage<T>& NamedImage<T>::operator=(const NamedImage<T2>& A) 00124 { 00125 Image<T>::operator=(A); // copy the image data 00126 itsName = A.namePtr(); // get a handle to the name 00127 return *this; 00128 } 00129 00130 template <class T> template <class TT> inline 00131 NamedImage<T>& NamedImage<T>::operator=(const Image<TT>& img) 00132 { 00133 // our name does not change 00134 Image<T>::operator=(img); return *this; 00135 } 00136 00137 template <class T> inline 00138 NamedImage<T>::~NamedImage() 00139 { } 00140 00141 template <class T> inline 00142 const std::string& NamedImage<T>::name() const 00143 { return *(itsName.get()); } 00144 00145 template <class T> inline 00146 void NamedImage<T>::setName(const std::string& name) 00147 { itsName.reset(new std::string(name)); } 00148 00149 template <class T> inline 00150 void NamedImage<T>::setName(const char *name) 00151 { itsName.reset(new std::string(name)); } 00152 00153 template <class T> inline 00154 const rutz::shared_ptr<std::string>& NamedImage<T>::namePtr() const 00155 { return itsName; } 00156 00157 // ###################################################################### 00158 /* So things look consistent in everyone's emacs... */ 00159 /* Local Variables: */ 00160 /* mode: c++ */ 00161 /* indent-tabs-mode: nil */ 00162 /* End: */ 00163 00164 #endif // IMAGE_NAMEDIMAGE_H_DEFINED