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

added button to choose input file

parent a0bebcd6
#include <QtGui> #include <QtGui>
#ifdef NEEDGLEE #ifdef NEEDGLEE
#include "GLee.h" #include "GLee.h"
#endif #endif
#include "openglcanvas.h" #include "openglcanvas.h"
#include <cmath> #include <cmath>
...@@ -34,7 +34,6 @@ OpenGLCanvas::OpenGLCanvas(QWidget *parent) : ...@@ -34,7 +34,6 @@ OpenGLCanvas::OpenGLCanvas(QWidget *parent) :
time_timer.setInterval(0); time_timer.setInterval(0);
connect(&time_timer, SIGNAL(timeout()), this, SLOT(slotTimer())); connect(&time_timer, SIGNAL(timeout()), this, SLOT(slotTimer()));
time_start = time_time.time(); time_start = time_time.time();
} }
void OpenGLCanvas::slotTimer(void) { void OpenGLCanvas::slotTimer(void) {
...@@ -104,14 +103,27 @@ void OpenGLCanvas::change_fov_scale_relation(QString name){ ...@@ -104,14 +103,27 @@ void OpenGLCanvas::change_fov_scale_relation(QString name){
void OpenGLCanvas::change_visualization(QString name){ void OpenGLCanvas::change_visualization(QString name){
visualization = 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(){ void OpenGLCanvas::change_input_image(){
QString path = QFileDialog::getExistingDirectory(this,tr("Choose directory"),directory.path()); load_image(QFileDialog::getOpenFileName(this,tr("Choose Panorama File")).toStdString().c_str());
if(path.isNull()==false)
directory.setPath(path);
updateGL(); updateGL();
} }
...@@ -137,27 +149,17 @@ void OpenGLCanvas::initializeGL(){ ...@@ -137,27 +149,17 @@ void OpenGLCanvas::initializeGL(){
#endif #endif
fprintf(stderr,"progname=%s\n",progname); fprintf(stderr,"progname=%s\n",progname);
fprintf(stderr,"image=%s\n",input_image); fprintf(stderr,"default image=%s\n",input_image);
// exit if the input file does not exist // what to do if the input file does not exist
struct stat testbuf; struct stat testbuf;
if(stat(input_image,&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); 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 // mesh resolution
int m,n; int m,n;
m = n = 100; m = n = 100;
......
...@@ -33,7 +33,7 @@ extern "C" { ...@@ -33,7 +33,7 @@ extern "C" {
#include <GL/glext.h> #include <GL/glext.h>
#endif #endif
#include <QDir> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
class OpenGLCanvas : public QGLWidget class OpenGLCanvas : public QGLWidget
...@@ -43,6 +43,7 @@ public: ...@@ -43,6 +43,7 @@ public:
explicit OpenGLCanvas(QWidget *parent = 0); explicit OpenGLCanvas(QWidget *parent = 0);
protected: protected:
void load_image(const char *new_image);
void initializeGL(); void initializeGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);
void paintGL(); void paintGL();
...@@ -76,7 +77,6 @@ private: ...@@ -76,7 +77,6 @@ private:
double center_phi; double center_phi;
QString fov_scale_relation; QString fov_scale_relation;
QString visualization; QString visualization;
QDir directory;
Chronos time_time; Chronos time_time;
QTimer time_timer; QTimer time_timer;
......
...@@ -18,5 +18,4 @@ public: ...@@ -18,5 +18,4 @@ public:
private: private:
Ui::PanoWindow1 *ui; Ui::PanoWindow1 *ui;
}; };
#endif // PANOWINDOW1_H #endif // PANOWINDOW1_H
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<string>PanoWindow1</string> <string>PanoWindow1</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <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"/> <widget class="OpenGLCanvas" name="GLCanvas" native="true"/>
</item> </item>
<item row="0" column="1" colspan="2"> <item row="0" column="1" colspan="2">
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_3"> <widget class="QDoubleSpinBox" name="doubleSpinBox_3">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="2"> <item row="8" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBox_4"> <widget class="QDoubleSpinBox" name="doubleSpinBox_4">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
...@@ -153,7 +153,14 @@ ...@@ -153,7 +153,14 @@
</property> </property>
</widget> </widget>
</item> </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"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -166,7 +173,7 @@ ...@@ -166,7 +173,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="9" column="1" colspan="2"> <item row="11" column="1" colspan="2">
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="pushButton">
<property name="text"> <property name="text">
<string>Close</string> <string>Close</string>
...@@ -180,7 +187,7 @@ ...@@ -180,7 +187,7 @@
<customwidget> <customwidget>
<class>OpenGLCanvas</class> <class>OpenGLCanvas</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>openglcanvas.h</header> <header location="global">openglcanvas.h</header>
<container>1</container> <container>1</container>
<slots> <slots>
<slot>change_fov(double)</slot> <slot>change_fov(double)</slot>
...@@ -290,5 +297,21 @@ ...@@ -290,5 +297,21 @@
</hint> </hint>
</hints> </hints>
</connection> </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> </connections>
</ui> </ui>
Markdown is supported
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