00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00032 #include <QtGui>
00033 #include <QtOpenGL>
00034 #include <QPixmap>
00035 #include "mainwidget.h"
00036
00044 MainWidget::MainWidget()
00045 {
00046
00047 setWindowTitle(tr("S3D Viewer"));
00048
00049
00050 QDesktopWidget *d = QApplication::desktop();
00051 int w = d->width();
00052 int h = d->height();
00053 setGeometry ( w/6 , h/8 , w*2/3 , h*3/4 );
00054
00055
00056 refWindow = new QMainWindow(this);
00057 refImgWidget = new RefImgWidget(refWindow);
00058 point3dWidget = new Point3dWidget(this);
00059 setWindow = new SettingWindow(this);
00060 setWindow->setPointWidget(point3dWidget);
00061 fileReader = new FileReader();
00062 setCentralWidget(point3dWidget);
00063 refWindow->setCentralWidget(refImgWidget);
00064 statusBar()->showMessage(tr("S3d Viewer Initialized"));
00065 refImgWidget->setPointWidget(point3dWidget);
00066
00067
00068 setupMenuBar();
00069
00070
00071
00072
00073 }
00074
00078 MainWidget::~MainWidget()
00079 {
00080 }
00081
00086 void MainWidget::setupMenuBar()
00087 {
00088 QMenu *menu = menuBar()->addMenu(tr("&File"));
00089 QAction *openAction = new QAction(tr("&Open File"), this);
00090 openAction->setShortcut(tr("Ctrl+O"));
00091 connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
00092
00093 QAction *saveAction = new QAction(tr("&Save Bitmap"), this);
00094 saveAction->setShortcut(tr("Ctrl+S"));
00095 connect(saveAction, SIGNAL(triggered()), this, SLOT(saveBMP()));
00096
00097 QAction *quitAction = new QAction(tr("&Quit"), this);
00098 quitAction->setShortcut(tr("Ctrl+Q"));
00099 connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
00100
00101 menu->addAction(openAction);
00102 menu->addAction(saveAction);
00103 menu->addSeparator();
00104 menu->addAction(quitAction);
00105
00106 menu = menuBar()->addMenu(tr("&View"));
00107
00108 toggleImg = new QAction(tr("&Reference Image"), this);
00109 connect(toggleImg, SIGNAL(triggered()), this, SLOT(changeToggle()));
00110
00111 showScene = new QAction(tr("Scene &Information"), this);
00112 connect(showScene, SIGNAL(triggered()), this, SLOT(sceneInfo()));
00113
00114 showSetting = new QAction(tr("S&ettings"), this);
00115 showSetting->setShortcut(tr("Ctrl+E"));
00116 connect(showSetting, SIGNAL(triggered()), this, SLOT(showSettings()));
00117
00118 menu->addAction(toggleImg);
00119 menu->addAction(showScene);
00120 menu->addAction(showSetting);
00121
00122 toggleImg->setEnabled(false);
00123 showScene->setEnabled(false);
00124
00125 menu = menuBar()->addMenu(tr("&About"));
00126
00127 QAction *helpAction = new QAction(tr("&Help"), this);
00128 helpAction->setShortcut(tr("Ctrl+H"));
00129 connect(helpAction, SIGNAL(triggered()), this, SLOT(help()));
00130
00131 QAction *aboutS3dAction = new QAction(tr("&About S3d Viewer"), this);
00132 aboutS3dAction->setShortcut(tr("Ctrl+A"));
00133 connect(aboutS3dAction, SIGNAL(triggered()), this, SLOT(aboutS3d()));
00134
00135 QAction *aboutQtAction = new QAction(tr("About Q&T"), this);
00136 aboutQtAction->setShortcut(tr("Ctrl+T"));
00137 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00138
00139 menu->addAction(helpAction);
00140 menu->addAction(aboutS3dAction);
00141 menu->addAction(aboutQtAction);
00142 }
00143
00148 void MainWidget::help(){
00149 QString helpText =
00150 tr("Open new S3d files by clicking on File->Open\n"
00151 "Save Bitmap of current S3d model by clicking on File->Save BMP\n"
00152 "Quit Program using File->Quit menu or click X on the top right\n\n"
00153 "Once S3d file is loaded, you can\n"
00154 "\tView->Reference Image to vew reference image of s3d file\n"
00155 "\tView->Scene Information to view information about s3d file\n"
00156 "\tView->Settings to edit settings\n\n"
00157 "Some useful tips in using this program\n"
00158 "\tUsing mouse to rotate model (press and drag)\n"
00159 "\tUsing mousewheel to zoom in and out\n"
00160 "\tUsing mousewheel to zoom in and out\n"
00161 "\tUsing Up and Down arrow to change zoom factor (like mousewheel)\n"
00162 "\tUsing Right and Left arrow to change Point Size (Cube option in Setting enabled)\n"
00163 "\tUsing shortcuts for quick command\n"
00164 "");
00165
00166 QMessageBox::about( this, tr("Help"), helpText);
00167 }
00168
00173 void MainWidget::aboutS3d(){
00174 QString aboutText =
00175 tr("S3dViewer for Unix-based Systems v1.0\n\n"
00176 "Authors: "
00177 "\tHue Tuan Thi\n"
00178 "\tJaime Valls Miro\n\n"
00179 "Centre of Autonomous System (CAS)\n"
00180 "University of Technoloty, Sydney (UTS)\n\n"
00181 "This program is used to view S3d files\n"
00182 "You can find out more about S3d files and a Windows version of this program at\n"
00183 "http://www.dccia.ua.es/~jmsaez/3D_Robot_Vision_Database\n"
00184 "");
00185
00186 QMessageBox::about( this, tr("About S3dViewer"), aboutText);
00187 }
00188
00194 void MainWidget::setVisible(QWidget *widget){
00195 if( widget->isVisible())
00196 widget->setVisible(false);
00197 else
00198 widget->setVisible(true);
00199 }
00200
00205 void MainWidget::showSettings(){
00206 setVisible(setWindow);
00207 }
00208
00213 void MainWidget::changeToggle(){
00214 setVisible(refWindow);
00215 }
00216
00221 void MainWidget::sceneInfo(){
00222 QMessageBox::about( this, "Scene Information", sceneInformation);
00223 }
00224
00229 void MainWidget::openFile(){
00230 fileName = QFileDialog::getOpenFileName(this, tr("Open S3D file ..."),
00231 "", tr("All Files (*);;S3D Files (*.s3d)"));
00232 if (!fileName.isEmpty()){
00233 fileReader->readFile(fileName);
00234 refImgWidget->updateFile(fileReader);
00235 point3dWidget->updateFile(fileReader);
00236
00237 sceneInformation = QString("File name: %1 \nInformation: %2 \nColor format: %3 \nImage resolution: %4 x %5 pixels \nNumber of 3D points: %6")
00238 .arg(fileName).arg(fileReader->getInfo()).arg(fileReader->getColorText())
00239 .arg(fileReader->getNRow()).arg(fileReader->getNCol()).arg(fileReader->getNp());
00240
00241 refWindow->resize(fileReader->getNCol(), fileReader->getNRow()+20);
00242
00243 if(fileReader->getEncoding() == 0)
00244 toggleImg->setEnabled(true);
00245 showScene->setEnabled(true);
00246 }
00247 }
00248
00253 void MainWidget::saveBMP(){
00254 QSize size = getSize();
00255 if (size.isValid()) {
00256 QPixmap pixmap = point3dWidget->renderPixmap(size.width(), size.height());
00257
00258 fileName = QFileDialog::getSaveFileName(this,
00259 tr("Save BMP file"), "S3DBMP",
00260 tr("All Files (*);;BMP Files (*.bmp)"));
00261
00262 pixmap.save(fileName, "BMP");
00263 qDebug("Saved");
00264 }
00265 }
00266
00271 QSize MainWidget::getSize()
00272 {
00273 bool ok;
00274 QString text = QInputDialog::getText(this, tr("S3dViewer"),
00275 tr("Enter pixmap size:"), QLineEdit::Normal,
00276 tr("%1 x %2").arg(point3dWidget->width()).arg(point3dWidget->height()), &ok);
00277 if (!ok)
00278 return QSize();
00279
00280 QRegExp regExp(tr("([0-9]+) *x *([0-9]+)"));
00281 if (regExp.exactMatch(text)) {
00282 int width = regExp.cap(1).toInt();
00283 int height = regExp.cap(2).toInt();
00284 if (width > 0 && width < 2048 && height > 0 && height < 2048)
00285 return QSize(width, height);
00286 }
00287
00288 return point3dWidget->size();
00289 }
00290
00295 void MainWidget::closeEvent(QCloseEvent *ce){
00296 refWindow->close();
00297 setWindow->close();
00298 }