00001 /*!@file Qt4/ImageDisplayLayout.qt.C */ 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: Pezhman Firoozfam (pezhman.firoozfam@usc.edu) 00034 // $HeadURL$ svn://isvn.usc.edu/software/invt/trunk/saliency/src/Qt4/ImageDisplayLayout.qt.C $ 00035 // 00036 00037 #include <QtGui/QtGui> 00038 #include "Qt4/ImageDisplayLayout.qt.H" 00039 #include "Qt4/ImageView.qt.H" 00040 00041 using namespace std; 00042 00043 // ###################################################################### 00044 ImageDisplayLayout::ImageDisplayLayout(QWidget *parent, const std::string& layout) : 00045 QWidget(parent) 00046 { 00047 // erase the white spaces first 00048 string layoutString; 00049 const string delimiter(" \t\r\n"); 00050 for (string::const_iterator itr = layout.begin(); itr != layout.end(); ++itr) 00051 { 00052 if (delimiter.find(*itr) == string::npos) 00053 layoutString += *itr; 00054 } 00055 QGridLayout *grid = CreateLayout(layoutString.begin(), layoutString.end()); 00056 if (grid != NULL) 00057 { 00058 setLayout(grid); 00059 } 00060 } 00061 00062 // ###################################################################### 00063 ImageDisplayLayout::~ImageDisplayLayout() 00064 { 00065 } 00066 00067 // ###################################################################### 00068 QGridLayout *ImageDisplayLayout::CreateLayout(string::const_iterator begin, string::const_iterator end) 00069 { 00070 if (begin == end) return NULL; 00071 00072 int row = 0; 00073 int col = 0; 00074 QGridLayout *grid = new QGridLayout; 00075 00076 for (string::const_iterator itr = begin; itr != end;) 00077 { 00078 if (*itr == '(') 00079 { 00080 int parenthese_count = 1; 00081 for (string::const_iterator itr2 = itr + 1; itr2 != end; ++itr2) 00082 { 00083 if (*itr2 == '(') 00084 { 00085 parenthese_count++; 00086 } 00087 else if (*itr2 == ')') 00088 { 00089 parenthese_count--; 00090 if (parenthese_count == 0) 00091 { 00092 QGridLayout *grid2 = CreateLayout(itr + 1, itr2); 00093 if (grid2 != NULL) 00094 { 00095 grid->addLayout(grid2, row, col); 00096 } 00097 itr = itr2 + 1; 00098 break; 00099 } 00100 } 00101 } 00102 if (parenthese_count != 0) LFATAL("Unbalanced parentheses detected in layout string"); 00103 if (itr == end) break; 00104 } 00105 if (*itr == ',') 00106 { 00107 col++; 00108 ++itr; 00109 } 00110 else if(*itr == ';') 00111 { 00112 col = 0; 00113 row++; 00114 ++itr; 00115 } 00116 else 00117 { 00118 string::const_iterator itr2 = itr; 00119 string name; 00120 for (; itr2 != end && *itr2 != ',' && *itr2 != ';' && *itr2 != '(' && *itr2 != ')'; ++itr2) 00121 { 00122 name += *itr2; 00123 } 00124 ImageView *view = new ImageView(0, name.c_str()); 00125 grid->addWidget(view, row, col); 00126 itsViews.insert(pair<string,ImageView*>(name, view)); 00127 itr = itr2; 00128 } 00129 } 00130 return grid; 00131 } 00132 00133 // ###################################################################### 00134 ImageView* ImageDisplayLayout::view(const char* name) 00135 { 00136 map<std::string, ImageView*>::iterator item = itsViews.find(string(name)); 00137 return (item == itsViews.end()) ? NULL : item->second; 00138 } 00139 00140 // ###################################################################### 00141 void ImageDisplayLayout::setImage(const char* name, Image< PixRGB<byte> > img) 00142 { 00143 ImageView* v = view(name); 00144 if (v == NULL) LFATAL("Accessing a NULL or not existing view '%s'", name); 00145 v->setImage(img); 00146 } 00147 00148 // ###################################################################### 00149 /* So things look consistent in everyone's emacs... */ 00150 /* Local Variables: */ 00151 /* mode: c++ */ 00152 /* indent-tabs-mode: nil */ 00153 /* End: */ 00154