/****************************************************************************
Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
This file is part of the QGLViewer library version 2.7.2.
http://www.libqglviewer.com -
[email protected]
This file may be used under the terms of the GNU General Public License
versions 2.0 or 3.0 as published by the Free Software Foundation and
appearing in the LICENSE file included in the packaging of this file.
In addition, as a special exception, Gilles Debunne gives you certain
additional rights, described in the file GPL_EXCEPTION in this package.
libQGLViewer uses dual licensing. Commercial/proprietary software must
purchase a libQGLViewer Commercial License.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/
#include "qglviewer.h"
#include "camera.h"
#include "domUtils.h"
#include "keyFrameInterpolator.h"
#include "manipulatedCameraFrame.h"
#include <QApplication>
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
#include <QGLContext>
#include <QImage>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPushButton>
#include <QTabWidget>
#include <QTextEdit>
#include <QTextStream>
#include <QTimer>
#include <QUrl>
#include <QtAlgorithms>
using namespace std;
using namespace qglviewer;
// Static private variable
QList<QGLViewer *> QGLViewer::QGLViewerPool_;
/*! \mainpage
libQGLViewer is a free C++ library based on Qt that enables the quick creation
of OpenGL 3D viewers. It features a powerful camera trackball and simple
applications simply require an implementation of the <code>draw()</code> method.
This makes it a tool of choice for OpenGL beginners and assignments. It provides
screenshot saving, mouse manipulated frames, stereo display, interpolated
keyFrames, object selection, and much more. It is fully
customizable and easy to extend to create complex applications, with a possible
Qt GUI.
libQGLViewer is <i>not</i> a 3D viewer that can be used directly to view 3D
scenes in various formats. It is more likely to be the starting point for the
coding of such a viewer.
libQGLViewer is based on the Qt toolkit and hence compiles on any architecture
(Unix-Linux, Mac, Windows, ...). Full reference documentation and many examples
are provided.
See the project main page for details on the project and installation steps. */
void QGLViewer::defaultConstructor() {
// Test OpenGL context
// if (glGetString(GL_VERSION) == 0)
// qWarning("Unable to get OpenGL version, context may not be available -
// Check your configuration");
int poolIndex = QGLViewer::QGLViewerPool_.indexOf(nullptr);
setFocusPolicy(Qt::StrongFocus);
if (poolIndex >= 0)
QGLViewer::QGLViewerPool_.replace(poolIndex, this);
else
QGLViewer::QGLViewerPool_.append(this);
camera_ = new Camera();
setCamera(camera());
setDefaultShortcuts();
setDefaultMouseBindings();
setSnapshotFileName(tr("snapshot", "Default snapshot file name"));
initializeSnapshotFormats();
setSnapshotCounter(0);
setSnapshotQuality(95);
fpsTime_.start();
fpsCounter_ = 0;
f_p_s_ = 0.0;
fpsString_ = tr("%1Hz", "Frames per seconds, in Hertz").arg("?");
visualHint_ = 0;
previousPathId_ = 0;
// prevPos_ is not initialized since pos() is not meaningful here.
// It will be set when setFullScreen(false) is called after
// setFullScreen(true)
// #CONNECTION# default values in initFromDOMElement()
manipulatedFrame_ = nullptr;
manipulatedFrameIsACamera_ = false;
mouseGrabberIsAManipulatedFrame_ = false;
mouseGrabberIsAManipulatedCameraFrame_ = false;
displayMessage_ = false;
connect(&messageTimer_, SIGNAL(timeout()), SLOT(hideMessage()));
messageTimer_.setSingleShot(true);
helpWidget_ = nullptr;
setMouseGrabber(nullptr);
setSceneRadius(1.0);
showEntireScene();
setStateFileName(".qglviewer.xml");
// #CONNECTION# default values in initFromDOMElement()
setAxisIsDrawn(false);
setGridIsDrawn(false);
setFPSIsDisplayed(false);
setCameraIsEdited(false);
setTextIsEnabled(true);
setStereoDisplay(false);
// Make sure move() is not called, which would call initializeGL()
fullScreen_ = false;
setFullScreen(false);
animationTimerId_ = 0;
stopAnimation();
setAnimationPeriod(40); // 25Hz
selectBuffer_ = nullptr;
setSelectBufferSize(4 * 1000);
setSelectRegionWidth(3);
setSelectRegionHeight(3);
setSelectedName(-1);
bufferTextureId_ = 0;
bufferTextureMaxU_ = 0.0;
bufferTextureMaxV_ = 0.0;
bufferTextureWidth_ = 0;
bufferTextureHeight_ = 0;
previousBufferTextureFormat_ = 0;
previousBufferTextureInternalFormat_ = 0;
currentlyPressedKey_ = Qt::Key(0);
setAttribute(Qt::WA_NoSystemBackground);
tileRegion_ = nullptr;
}
/*! Constructor. See \c QGLWidget documentation for details.
All viewer parameters (display flags, scene parameters, associated objects...)
are set to their default values. See the associated documentation. */
QGLViewer::QGLViewer(QWidget *parent, Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags) {
defaultConstructor();
}
#ifndef DOXYGEN
/*! These contructors are deprecated since version 2.7.0, since they are not
* supported by QOpenGlWidget */
/*! Constructor. See \c QGLWidget documentation for details.
All viewer parameters (display flags, scene parameters, associated objects...)
are set to their default values. See the associated documentation.
If the \p shareWidget parameter points to a valid \c QGLWidget, the QGLViewer
will share the OpenGL context with \p shareWidget (see isSharing()). */
QGLViewer::QGLViewer(QWidget *parent, const QGLWidget *shareWidget,
Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags) {
Q_UNUSED(shareWidget)
qWarning("The constructor with a shareWidget is deprecated, use the regular "
"contructor instead.");
defaultConstructor();
}
/*! Same as QGLViewer(), but a \c QGLContext can be provided so that viewers
share GL contexts, even with \c QGLContext sub-classes (use \p shareWidget
otherwise). */
QGLViewer::QGLViewer(QGLContext *context, QWidget *parent,
const QGLWidget *shareWidget, Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags) {
Q_UNUSED(context)
Q_UNUSED(shareWidget)
qWarning("The constructor with a QGLContext is deprecated, use the regular "
"contructor instead.");
defaultConstructor();
}
/*! Same as QGLViewer(), but a specific \c QGLFormat can be provided.
This is for instance needed to ask for a stencil buffer or for stereo display
(as is illustrated in the <a href="../examples/stereoViewer.html">stereoViewer
example</a>). */
QGLViewer::QGLViewer(const QGLFormat &format, QWidget *parent,
const QGLWidget *shareWidget, Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags) {
Q_UNUSED(format)
Q_UNUSED(shareWidget)
qWarning("The constructor with a QGLFormat is deprecated, use the regular "
"contructor instead.");
defaultConstructor();
}
#endif // DOXYGEN
/*! Virtual destructor.
The viewer is replaced by \c nullptr in the QGLViewerPool() (in order to preserve
other viewer's indexes) and allocated memory is released. The camera() is
deleted and should be copied before if it is shared by an other viewer. */
QGLViewer::~QGLViewer() {
// See closeEvent comment. Destructor is called (and not closeEvent) only when
// the widget is embedded. Hence we saveToFile here. It is however a bad idea
// if virtual domElement() has been overloaded ! if (parent())
// saveStateToFileForAllViewers();
QGLViewer::QGLViewerPool_.replace(QGLViewer::QGLViewerPool_.indexOf(this),
nullptr);
delete camera();
delete[] selectBuffer_;
if (helpWidget()) {
// Needed for Qt 4 which has no main widget.
helpWidget()->close();
评论1