Commit 2d6af942 authored by Luis Peñaranda's avatar Luis Peñaranda
Browse files

added button to choose input file

parent a0bebcd6
#include <QtGui>
#ifdef NEEDGLEE
#include "GLee.h"
#include "GLee.h"
#endif
#include "openglcanvas.h"
#include <cmath>
......@@ -34,7 +34,6 @@ OpenGLCanvas::OpenGLCanvas(QWidget *parent) :
time_timer.setInterval(0);
connect(&time_timer, SIGNAL(timeout()), this, SLOT(slotTimer()));
time_start = time_time.time();
}
void OpenGLCanvas::slotTimer(void) {
......@@ -104,14 +103,27 @@ void OpenGLCanvas::change_fov_scale_relation(QString name){
void OpenGLCanvas::change_visualization(QString name){
visualization = name;
updateGL();
updateGL();
}
void OpenGLCanvas::load_image(const char *new_image){
const char * const progname=(char*)(PROGNAME);
int textureSize=getTextureSize(progname,new_image);
unsigned char * textureBytes=(unsigned char*)malloc(textureSize);
int width,height;
readTextureBytes(progname,new_image,textureBytes,&width,&height);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
GLuint tex;
glGenTextures(1,&tex);
glBindTexture(GL_TEXTURE_2D,tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,textureBytes);
}
void OpenGLCanvas::change_input_image(){
QString path = QFileDialog::getExistingDirectory(this,tr("Choose directory"),directory.path());
if(path.isNull()==false)
directory.setPath(path);
load_image(QFileDialog::getOpenFileName(this,tr("Choose Panorama File")).toStdString().c_str());
updateGL();
}
......@@ -137,27 +149,17 @@ void OpenGLCanvas::initializeGL(){
#endif
fprintf(stderr,"progname=%s\n",progname);
fprintf(stderr,"image=%s\n",input_image);
// exit if the input file does not exist
fprintf(stderr,"default image=%s\n",input_image);
// what to do if the input file does not exist
struct stat testbuf;
if(stat(input_image,&testbuf)){
fprintf(stderr,"the file does not exist!\n");
fprintf(stderr,"the default image file does not exist!\n");
free(input_image);
exit(-1);
load_image(QFileDialog::getOpenFileName(this,tr("Choose Panorama File")).toStdString().c_str());
}else{
load_image(input_image);
}
int textureSize = getTextureSize(progname,input_image);
unsigned char * textureBytes = (unsigned char*)malloc(textureSize);
int width, height;
readTextureBytes(progname, input_image, textureBytes, &width, &height);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
GLuint tex;
glGenTextures(1,&tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,textureBytes);
// mesh resolution
int m,n;
m = n = 100;
......
......@@ -33,7 +33,7 @@ extern "C" {
#include <GL/glext.h>
#endif
#include <QDir>
#include <QFile>
#include <QFileDialog>
class OpenGLCanvas : public QGLWidget
......@@ -43,6 +43,7 @@ public:
explicit OpenGLCanvas(QWidget *parent = 0);
protected:
void load_image(const char *new_image);
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
......@@ -76,7 +77,6 @@ private:
double center_phi;
QString fov_scale_relation;
QString visualization;
QDir directory;
Chronos time_time;
QTimer time_timer;
......
......@@ -18,5 +18,4 @@ public:
private:
Ui::PanoWindow1 *ui;
};
#endif // PANOWINDOW1_H
......@@ -14,7 +14,7 @@
<string>PanoWindow1</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="10">
<item row="0" column="0" rowspan="12">
<widget class="OpenGLCanvas" name="GLCanvas" native="true"/>
</item>
<item row="0" column="1" colspan="2">
......@@ -115,7 +115,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_3">
<property name="maximumSize">
<size>
......@@ -134,7 +134,7 @@
</property>
</widget>
</item>
<item row="7" column="2">
<item row="8" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBox_4">
<property name="maximumSize">
<size>
......@@ -153,7 +153,14 @@
</property>
</widget>
</item>
<item row="8" column="2">
<item row="9" column="1" colspan="2">
<widget class="QPushButton" name="chooseFile">
<property name="text">
<string>Input Image</string>
</property>
</widget>
</item>
<item row="10" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -166,7 +173,7 @@
</property>
</spacer>
</item>
<item row="9" column="1" colspan="2">
<item row="11" column="1" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Close</string>
......@@ -180,7 +187,7 @@
<customwidget>
<class>OpenGLCanvas</class>
<extends>QWidget</extends>
<header>openglcanvas.h</header>
<header location="global">openglcanvas.h</header>
<container>1</container>
<slots>
<slot>change_fov(double)</slot>
......@@ -290,5 +297,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>chooseFile</sender>
<signal>clicked()</signal>
<receiver>GLCanvas</receiver>
<slot>change_input_image()</slot>
<hints>
<hint type="sourcelabel">
<x>566</x>
<y>258</y>
</hint>
<hint type="destinationlabel">
<x>247</x>
<y>249</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment