00001 /** @file Psycho/SearchArray.H jittered array of search elements */ 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: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Psycho/SearchArray.H $ 00035 // $Id: SearchArray.H 14200 2010-11-04 03:10:43Z jshen $ 00036 // 00037 00038 // Code herein is derived from GroovX, also licensed under the GPL 00039 // Copyright (c) 2002-2004 California Institute of Technology 00040 // Copyright (c) 2004-2007 University of Southern California 00041 // [http://ilab.usc.edu/rjpeters/groovx/] 00042 00043 #ifndef PSYCHO_SEARCHARRAY_H_DEFINED 00044 #define PSYCHO_SEARCHARRAY_H_DEFINED 00045 00046 #include "Image/Image.H" 00047 #include "Image/Pixels.H" 00048 #include "Image/vec2.h" 00049 #include "Psycho/SearchItem.H" 00050 #include "rutz/arrays.h" 00051 #include "rutz/shared_ptr.h" 00052 00053 #include <string> 00054 #include <vector> 00055 00056 namespace rutz 00057 { 00058 class urand; 00059 } 00060 00061 /// SearchArray represents an 2-D spatial array of search items 00062 /** The array has manipulable spacing properties. */ 00063 class SearchArray 00064 { 00065 public: 00066 SearchArray(const Dims& dims = Dims(512, 512), 00067 double gridSpacing = 48.0, 00068 double minSpacing = 36.0, 00069 double margin = 0.0); 00070 00071 virtual ~SearchArray() throw(); 00072 00073 void addElement(const rutz::shared_ptr<SearchItem>& e, bool displace = false) const; 00074 size_t numElements() const { return itsArray.size(); } 00075 00076 void replaceElementAtSamePos(size_t i, const rutz::shared_ptr<SearchItem>& e); 00077 00078 void generateBackground(SearchItemFactory& factory, 00079 const int diffusionCycles = 10, 00080 const bool doFinalFill = true, 00081 const int jitterIters = 1000, 00082 const bool doJitterForeground = false, 00083 const int backgSeed = 0) const; 00084 00085 Image<byte> getImage(const double lo = -1.0, const double hi = 1.0, 00086 const double bg = 0.0, 00087 bool doTagLast = false) const; 00088 00089 void pareBackground(const uint shrunkSize) const; 00090 void clear() const; 00091 void saveCoords(const std::string& filename) const; 00092 Rectangle itemBounds() const; 00093 private: 00094 SearchArray(const SearchArray&); 00095 SearchArray& operator=(const SearchArray&); 00096 00097 void doAddElement(const rutz::shared_ptr<SearchItem>& e, const bool toFront = false) const; 00098 bool tooClose(const geom::vec2<double>& v, int except) const; 00099 void backgHexGrid(SearchItemFactory& factory) const; 00100 void backgFill(SearchItemFactory& factory) const; 00101 void backgJitter(rutz::urand& urand, const int niter, 00102 const bool doJitterForeground) const; 00103 void doRemoveElement(const rutz::shared_ptr<SearchItem>& e) const; 00104 Dims itsDims; 00105 double itsGridSpacing; 00106 double itsMinSpacing; 00107 double itsFillResolution; 00108 double itsMargin; 00109 00110 mutable std::vector<rutz::shared_ptr<SearchItem> > itsArray; 00111 00112 bool itsDumpingFrames; 00113 unsigned int itsFrameDumpPeriod; 00114 }; 00115 00116 // ###################################################################### 00117 /* So things look consistent in everyone's emacs... */ 00118 /* Local Variables: */ 00119 /* mode: c++ */ 00120 /* indent-tabs-mode: nil */ 00121 /* End: */ 00122 00123 #endif // PSYCHO_SEARCHARRAY_H_DEFINED