00001 /*!@file NeovisionII/ChipValidator/ChipValidatorQt.qt.C Simple GUI to validate chips */ 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 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Apps/BorderWatch/ChipValidatorQt.qt.C $ 00035 // $Id: ChipValidatorQt.qt.C 13059 2010-03-26 08:14:32Z itti $ 00036 // 00037 00038 #include "NeovisionII/ChipValidator/ChipValidatorQt.qt.H" 00039 00040 #include <QtGui/QVBoxLayout> 00041 #include <QtGui/QHBoxLayout> 00042 #include <QtGui/QSlider> 00043 #include <QtGui/QGridLayout> 00044 #include <QtGui/QPushButton> 00045 #include <QtGui/QApplication> 00046 00047 #include "Image/DrawOps.H" 00048 #include "QtUtil/ImageConvert4.H" 00049 #include "Util/log.H" 00050 #include "Util/sformat.H" 00051 00052 // ###################################################################### 00053 ChipValidatorQt::ChipValidatorQt(QApplication *qapp, std::vector<ChipData>& chipvec, 00054 const Dims& griddims, QWidget* parent) : 00055 QWidget(parent), itsChipVec(chipvec), itsGridDims(griddims), itsChipLabels(), itsPage(0) 00056 { 00057 QVBoxLayout *main = new QVBoxLayout(this); 00058 main->setSpacing(4); 00059 main->setMargin(2); 00060 00061 QHBoxLayout *hgrid = new QHBoxLayout; 00062 hgrid->addStretch(1); 00063 00064 QGridLayout *grid = new QGridLayout; 00065 grid->setSpacing(3); uint idx = 0; 00066 for (int j = 0; j < itsGridDims.h(); ++j) 00067 for (int i = 0; i < itsGridDims.w(); ++i) { 00068 ChipQLabel *cl = new ChipQLabel(idx, this); 00069 grid->addWidget(cl, j, i); 00070 itsChipLabels.push_back(cl); 00071 setChipImage(idx); 00072 ++idx; 00073 } 00074 hgrid->addLayout(grid); 00075 00076 hgrid->addStretch(1); 00077 00078 main->addLayout(hgrid); 00079 00080 QHBoxLayout *hcontrol = new QHBoxLayout; 00081 00082 QSlider *slider = new QSlider(Qt::Horizontal , this); 00083 slider->setRange(0, itsChipVec.size() / itsGridDims.sz() + ( (itsChipVec.size() % itsGridDims.sz() ) ? 0 : -1)); 00084 slider->setValue(0); 00085 slider->setPageStep(1); 00086 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 00087 hcontrol->addWidget(slider); 00088 connect(slider, SIGNAL(valueChanged(int)), this, SLOT(pageChanged(int))); 00089 00090 QPushButton *button = new QPushButton("Save + Exit", this); 00091 hcontrol->addWidget(button); 00092 connect(button, SIGNAL(pressed()), qapp, SLOT(quit())); 00093 00094 main->addLayout(hcontrol); 00095 00096 itsStatusLabel = new QLabel("Status: Idle.", this); 00097 itsStatusLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 00098 main->addWidget(itsStatusLabel); 00099 00100 this->setLayout(main); 00101 } 00102 00103 // ###################################################################### 00104 ChipValidatorQt::~ChipValidatorQt() 00105 { } 00106 00107 // ###################################################################### 00108 void ChipValidatorQt::setChipImage(const uint idx) 00109 { 00110 if (itsChipVec.size() == 0) LFATAL("No chips loaded, I need at least one chip to work"); 00111 if (idx >= uint(itsGridDims.sz())) LFATAL("Trying to set chip image for out-of-grid chip"); 00112 00113 // get the image, if it exists 00114 const uint fullidx = itsPage * itsGridDims.sz() + idx; 00115 00116 if (fullidx < itsChipVec.size()) { 00117 Image< PixRGB<byte> > im = itsChipVec[fullidx].image; 00118 00119 // mark chip as negative? 00120 if (itsChipVec[fullidx].positive == false) { 00121 drawLine(im, Point2D<int>(0, 0), Point2D<int>(im.getWidth()-1, im.getHeight()-1), PixRGB<byte>(255, 0, 0), 2); 00122 drawLine(im, Point2D<int>(im.getWidth()-1, 0), Point2D<int>(0, im.getHeight()-1), PixRGB<byte>(255, 0, 0), 2); 00123 } 00124 00125 // draw the image: 00126 QPixmap pixmap = convertToQPixmap4(im); 00127 itsChipLabels[idx]->setPixmap(pixmap); 00128 } else { 00129 // set an empty pixmap: 00130 Image<PixRGB<byte> > im(itsChipVec[0].image.getDims(), NO_INIT); im.clear(PixRGB<byte>(192)); 00131 QPixmap pixmap = convertToQPixmap4(im); 00132 itsChipLabels[idx]->setPixmap(pixmap); 00133 } 00134 } 00135 00136 // ###################################################################### 00137 void ChipValidatorQt::chipClicked(const uint idx) 00138 { 00139 if (idx >= uint(itsGridDims.sz())) LFATAL("Clicked an out-of-grid chip"); 00140 00141 const uint fullidx = itsPage * itsGridDims.sz() + idx; 00142 if (fullidx < itsChipVec.size()) { 00143 itsChipVec[fullidx].positive = ! itsChipVec[fullidx].positive; 00144 itsStatusLabel->setText(sformat("Chip %u/%"ZU" marked as %s.", fullidx, itsChipVec.size()-1, 00145 itsChipVec[fullidx].positive ? "positive" : "negative").c_str()); 00146 setChipImage(idx); 00147 } 00148 } 00149 00150 // ###################################################################### 00151 void ChipValidatorQt::pageChanged(const int idx) 00152 { 00153 itsPage = idx; 00154 00155 const uint startidx = itsPage*itsGridDims.sz(); 00156 const uint stopidx = std::min(startidx + itsGridDims.sz() - 1, uint(itsChipVec.size() - 1)); 00157 itsStatusLabel->setText(sformat("Showing chips %u - %u", startidx, stopidx).c_str()); 00158 00159 for (uint i = 0; i < uint(itsGridDims.sz()); ++i) setChipImage(i); 00160 } 00161 00162 // ###################################################################### 00163 /* So things look consistent in everyone's emacs... */ 00164 /* Local Variables: */ 00165 /* mode: c++ */ 00166 /* indent-tabs-mode: nil */ 00167 /* End: */