Commit 2824f2ae authored by Sylvain Thery's avatar Sylvain Thery

add qtQGLV for qtQGLViewer

parent 6e4b84c4
......@@ -42,9 +42,24 @@ int main(int argc, char **argv)
// final show for redraw
sqt.show();
// and wait for the end
// QGLViewer* ptr = sqt.getQGLWidget();
return app.exec();
}
void MyQT::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
getQGLWidget()->camera()->centerScene();
updateGL();
break;
default:
break;
}
}
void MyQT::createMap()
{
// creation of a new attribute on vertices of type 3D vector for position.
......@@ -70,6 +85,7 @@ void MyQT::createMap()
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
show();
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
......
......@@ -27,7 +27,8 @@
//#define USE_GMAP
#include "Utils/Qt/qtSimple.h"
//#include "Utils/Qt/qtSimple.h"
#include "Utils/Qt/qtQGLV.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
......@@ -59,7 +60,7 @@ struct PFP: public PFP_STANDARD
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class MyQT : public Utils::QT::SimpleQT
class MyQT : public Utils::QT::SimpleQGLV
{
Q_OBJECT
public:
......@@ -67,6 +68,7 @@ public:
void cb_redraw();
void cb_initGL();
void cb_keyPress(int keycode);
protected:
// declaration of the map
......
......@@ -34,6 +34,7 @@ find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
find_package(SuiteSparse REQUIRED)
find_package(QGLViewer REQUIRED)
IF (DEFINED ASSERTON)
add_definitions(-DCGOGN_ASSERT_BOOL=${ASSERTON})
......@@ -73,7 +74,7 @@ SET (CGoGN_EXT_INCLUDES
${ZLIB_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${QGLVIEWER_INCLUDE_DIR}
)
# define libs for external libs
......@@ -87,6 +88,7 @@ SET (CGoGN_EXT_LIBS
${Boost_REGEX_LIBRARY}
${Boost_THREAD_LIBRARY}
${SUITESPARSE_LIBRARIES}
${QGLVIEWER_LIBRARIES}
)
#optionnal libs
......@@ -104,9 +106,11 @@ ENDIF (WITH_ZINRI)
IF (WITH_QT)
add_definitions(-DWITH_QT)
find_package(Qt4 REQUIRED)
SET(QT_USE_QTCORE TRUE)
SET(QT_USE_QTOPENGL TRUE)
SET(QT_USE_QTSVG TRUE)
find_package(Qt4 REQUIRED)
SET(QT_USE_QTXML TRUE )
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${QT_INCLUDE_DIR})
......
......@@ -92,7 +92,9 @@ IF(WITH_QT)
utils_qt_headers
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtgl.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtSimple.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV_glw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qthistodraw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtcolorschooser.h
)
......
......@@ -90,7 +90,9 @@ IF(WITH_QT)
utils_qt_headers
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtgl.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtSimple.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV_glw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qthistodraw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtcolorschooser.h
)
......
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __QTQGLVIEWER_GLW_H
#define __QTQGLVIEWER_GLW_H
#include <QApplication>
#include <QDesktopWidget>
#include <QMainWindow>
#include <QWidget>
#include <QtGui>
#include <GL/glew.h>
#include <QGLViewer/qglviewer.h>
#include <set>
#include <string>
#include "Geometry/vector_gen.h"
#include "Utils/gl_matrices.h"
namespace CGoGN { namespace Utils { class GLSLShader; } }
namespace CGoGN
{
namespace Utils
{
namespace QT
{
// forward definition
class SimpleQGLV;
class QGLView : public QGLViewer
{
Q_OBJECT
protected:
SimpleQGLV* m_sqgl;
int W;
int H;
int m_state_modifier;
public:
QGLView(SimpleQGLV* ptr, QWidget *parent = 0);
~QGLView();
void setParamObject(float width, float* pos);
void glMousePosition(int& x, int& y);
virtual void init();
virtual void preDraw();
virtual void draw();
virtual void postDraw() {}
virtual void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseClickEvent(QMouseEvent* event);
// void mouseDoubleClickEvent(QMouseEvent* event);
// void mouseMoveEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
// void wheelEvent(QWheelEvent* event);
bool Shift() { return m_state_modifier & Qt::ShiftModifier; }
bool Control() { return m_state_modifier & Qt::ControlModifier; }
bool Alt() { return m_state_modifier & Qt::AltModifier; }
int getHeight() const { return H; }
int getWidth() const { return W; }
QSize minimumSizeHint() const;
QSize sizeHint() const;
};
} // namespace QT
} // namespace Utils
} // namespace CGoGN
#endif
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Utils/GLSLShader.h"
#include "Utils/Qt/qtQGLV.h"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp"
#include <QtGui/QTextEdit>
#include <QImage>
namespace CGoGN
{
namespace Utils
{
namespace QT
{
QGLView::QGLView(SimpleQGLV* ptr, QWidget *parent):
QGLViewer(parent),
m_sqgl(ptr),m_state_modifier(0)
{
}
QGLView::~QGLView()
{
}
void QGLView::setParamObject(float width, float* pos)
{
qglviewer::Vec bbMin(pos[0]-width/2.0f, pos[1]-width/2.0f, pos[2]-width/2.0f);
qglviewer::Vec bbMax(pos[0]+width/2.0f, pos[1]+width/2.0f, pos[2]+width/2.0f);
camera()->setSceneBoundingBox(bbMin, bbMax);
camera()->showEntireScene();
std::cout << "w p = "<< width << " / "<< pos[0]<< " , "<< pos[1]<< " , "<< pos[2]<< std::endl;
}
QSize QGLView::minimumSizeHint() const
{
return QSize(200, 200);
}
QSize QGLView::sizeHint() const
{
return QSize(500, 500);
}
void QGLView::init()
{
glewInit();
if (m_sqgl)
m_sqgl->cb_initGL();
qglviewer::Vec bbMin(0.0,0.0,0.0);
qglviewer::Vec bbMax(2.0,2.0,2.0);
camera()->setSceneBoundingBox(bbMin, bbMax);
camera()->showEntireScene();
}
void QGLView::preDraw()
{
GLdouble gl_mvm[16];
camera()->getModelViewMatrix(gl_mvm);
glm::mat4& mvm = m_sqgl->modelViewMatrix();
for(unsigned int i = 0; i < 4; ++i)
{
for(unsigned int j = 0; j < 4; ++j)
mvm[i][j] = (float)gl_mvm[i*4+j];
}
GLdouble gl_pm[16];
camera()->getProjectionMatrix(gl_pm);
glm::mat4& pm = m_sqgl->projectionMatrix();
for(unsigned int i = 0; i < 4; ++i)
{
for(unsigned int j = 0; j < 4; ++j)
pm[i][j] = (float)gl_pm[i*4+j];
}
m_sqgl->cb_updateMatrix();
}
void QGLView::draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (m_sqgl)
{
Utils::GLSLShader::s_current_matrices = m_sqgl->matricesPtr();
m_sqgl->cb_redraw();
}
}
void QGLView::resizeGL(int w, int h)
{
W = w;
H = h;
QGLViewer::resizeGL(w,h);
}
void QGLView::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Escape)
{
close();
m_sqgl->close();
return;
}
m_state_modifier = event->modifiers();
QGLViewer::keyPressEvent(event);
if (m_sqgl)
{
int k = event->key();
if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) )
k += 32;
m_sqgl->cb_keyPress(k);
}
}
void QGLView::keyReleaseEvent(QKeyEvent* event)
{
m_state_modifier = event->modifiers();
QGLViewer::keyReleaseEvent(event);
if (m_sqgl)
{
int k = event->key();
if ( (k >= 65) && (k <= 91) && !(event->modifiers() & Qt::ShiftModifier) )
k += 32;
m_sqgl->cb_keyRelease(k);
}
}
void QGLView::mousePressEvent(QMouseEvent* event)
{
// beginx = event->x();
// beginy = event->y();
// clickPoint = event->pos();
// m_current_button = event->button();
if (m_sqgl)
m_sqgl->cb_mousePress(event->button(), event->x(), getHeight() - event->y());
QGLViewer::mousePressEvent(event);
}
void QGLView::mouseReleaseEvent(QMouseEvent* event)
{
if (m_sqgl)
m_sqgl->cb_mouseRelease(event->button(), event->x(), getHeight() - event->y());
QGLViewer::mouseReleaseEvent(event);
}
void QGLView::mouseClickEvent(QMouseEvent* event)
{
if (m_sqgl)
m_sqgl->cb_mouseClick(event->button(), event->x(), getHeight() - event->y());
}
void QGLView::glMousePosition(int& x, int& y)
{
QPoint xy = mapFromGlobal(QCursor::pos());
x = xy.x();
y = getHeight() - xy.y();
}
} // namespace QT
} // namespace Utils
} // namespace CGoGN
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