Skip to content

Commit

Permalink
clean code; compatible with both C++11 and C++17; resolve a few warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Dec 16, 2024
1 parent 9ea09c9 commit a2b9b93
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 30 deletions.
22 changes: 13 additions & 9 deletions code/3rd_QGLViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()

project(libQGLViewer LANGUAGES CXX VERSION 2.9.1)
cmake_minimum_required(VERSION 3.16)
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})

include(../cmake/UseQt.cmake)

Expand Down Expand Up @@ -37,6 +33,14 @@ set(QGLViewer_SRC
"${PROJECT_SOURCE_DIR}/QGLViewer/quaternion.cpp"
"${PROJECT_SOURCE_DIR}/QGLViewer/saveSnapshot.cpp"
"${PROJECT_SOURCE_DIR}/QGLViewer/vec.cpp")
add_library(3rd_QGLViewer SHARED ${QGLViewer_SRC})
target_include_directories(3rd_QGLViewer INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(3rd_QGLViewer PUBLIC ${QtLibs} OpenGL::GL OpenGL::GLU)

add_library(${PROJECT_NAME} STATIC ${QGLViewer_SRC})
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${QtLibs} OpenGL::GL OpenGL::GLU)

target_compile_definitions(${PROJECT_NAME} PUBLIC QGLVIEWER_STATIC)

# get a clean windows
if (WIN32 OR MSVC)
target_compile_definitions(${PROJECT_NAME} PUBLIC NOMINMAX)
endif()
3 changes: 0 additions & 3 deletions code/3rd_QGLViewer/QGLViewer/VRender/Vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include <math.h>
#include <algorithm>

#ifdef WIN32
# include <windows.h>
#endif

using namespace vrender;
using namespace std;
Expand Down
4 changes: 0 additions & 4 deletions code/3rd_QGLViewer/QGLViewer/VRender/Vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <math.h>
#include <algorithm>

#ifdef WIN32
# include <windows.h>
#endif

using namespace vrender;
using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion code/3rd_QGLViewer/QGLViewer/camera.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef QGLVIEWER_CAMERA_H
#define QGLVIEWER_CAMERA_H

#include "../basic/canvas.h"
#include "../../basic/canvas.h"
#include <QMap>
#include "keyFrameInterpolator.h"
class QGLViewer;
Expand Down
2 changes: 1 addition & 1 deletion code/3rd_QGLViewer/QGLViewer/manipulatedCameraFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
case QGLViewer::MOVE_BACKWARD:
//#CONNECTION# mouseMoveEvent() MOVE_FORWARD case
translate(
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->delta())));
#else
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y())));
Expand Down
2 changes: 1 addition & 1 deletion code/3rd_QGLViewer/QGLViewer/manipulatedFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ qreal ManipulatedFrame::deltaWithPrevPos(QMouseEvent *const event,

qreal ManipulatedFrame::wheelDelta(const QWheelEvent *event) const {
static const qreal WHEEL_SENSITIVITY_COEF = 8E-4;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
return event->delta() * wheelSensitivity() * WHEEL_SENSITIVITY_COEF;
#else
return event->angleDelta().y() * wheelSensitivity() * WHEEL_SENSITIVITY_COEF;
Expand Down
32 changes: 32 additions & 0 deletions code/3rd_QGLViewer/QGLViewer/qglviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ void QGLViewer::setDefaultMouseBindings() {
(mh == FRAME) ? frameKeyboardModifiers : cameraKeyboardModifiers;

setMouseBinding(modifiers, Qt::LeftButton, mh, ROTATE);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(modifiers, Qt::MidButton, mh, ZOOM);
#else
setMouseBinding(modifiers, Qt::MiddleButton, mh, ZOOM);
#endif
setMouseBinding(modifiers, Qt::RightButton, mh, TRANSLATE);

setMouseBinding(Qt::Key_R, modifiers, Qt::LeftButton, mh, SCREEN_ROTATE);
Expand All @@ -594,15 +598,23 @@ void QGLViewer::setDefaultMouseBindings() {
}

// Z o o m o n r e g i o n
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(Qt::ShiftModifier, Qt::MidButton, CAMERA, ZOOM_ON_REGION);
#else
setMouseBinding(Qt::ShiftModifier, Qt::MiddleButton, CAMERA, ZOOM_ON_REGION);
#endif

// S e l e c t
setMouseBinding(Qt::ShiftModifier, Qt::LeftButton, SELECT);

setMouseBinding(Qt::ShiftModifier, Qt::RightButton, RAP_FROM_PIXEL);
// D o u b l e c l i c k
setMouseBinding(Qt::NoModifier, Qt::LeftButton, ALIGN_CAMERA, true);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(Qt::NoModifier, Qt::MidButton, SHOW_ENTIRE_SCENE, true);
#else
setMouseBinding(Qt::NoModifier, Qt::MiddleButton, SHOW_ENTIRE_SCENE, true);
#endif
setMouseBinding(Qt::NoModifier, Qt::RightButton, CENTER_SCENE, true);

setMouseBinding(frameKeyboardModifiers, Qt::LeftButton, ALIGN_FRAME, true);
Expand Down Expand Up @@ -1228,7 +1240,11 @@ static QString mouseButtonsString(Qt::MouseButtons b) {
result += QGLViewer::tr("Left", "left mouse button");
addAmpersand = true;
}
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
if (b & Qt::MidButton) {
#else
if (b & Qt::MiddleButton) {
#endif
if (addAmpersand)
result += " & ";
result += QGLViewer::tr("Middle", "middle mouse button");
Expand Down Expand Up @@ -3336,27 +3352,43 @@ void QGLViewer::toggleCameraMode() {
camera()->frame()->stopSpinning();

setMouseBinding(modifiers, Qt::LeftButton, CAMERA, MOVE_FORWARD);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(modifiers, Qt::MidButton, CAMERA, LOOK_AROUND);
#else
setMouseBinding(modifiers, Qt::MiddleButton, CAMERA, LOOK_AROUND);
#endif
setMouseBinding(modifiers, Qt::RightButton, CAMERA, MOVE_BACKWARD);

setMouseBinding(Qt::Key_R, modifiers, Qt::LeftButton, CAMERA, ROLL);

setMouseBinding(Qt::NoModifier, Qt::LeftButton, NO_CLICK_ACTION, true);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(Qt::NoModifier, Qt::MidButton, NO_CLICK_ACTION, true);
#else
setMouseBinding(Qt::NoModifier, Qt::MiddleButton, NO_CLICK_ACTION, true);
#endif
setMouseBinding(Qt::NoModifier, Qt::RightButton, NO_CLICK_ACTION, true);

setWheelBinding(modifiers, CAMERA, MOVE_FORWARD);
} else {
// Should stop flyTimer. But unlikely and not easy.
setMouseBinding(modifiers, Qt::LeftButton, CAMERA, ROTATE);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(modifiers, Qt::MidButton, CAMERA, ZOOM);
#else
setMouseBinding(modifiers, Qt::MiddleButton, CAMERA, ZOOM);
#endif
setMouseBinding(modifiers, Qt::RightButton, CAMERA, TRANSLATE);

setMouseBinding(Qt::Key_R, modifiers, Qt::LeftButton, CAMERA,
SCREEN_ROTATE);

setMouseBinding(Qt::NoModifier, Qt::LeftButton, ALIGN_CAMERA, true);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
setMouseBinding(Qt::NoModifier, Qt::MidButton, SHOW_ENTIRE_SCENE, true);
#else
setMouseBinding(Qt::NoModifier, Qt::MiddleButton, SHOW_ENTIRE_SCENE, true);
#endif
setMouseBinding(Qt::NoModifier, Qt::RightButton, CENTER_SCENE, true);

setWheelBinding(modifiers, CAMERA, ZOOM);
Expand Down
2 changes: 1 addition & 1 deletion code/3rd_QGLViewer/QGLViewer/qglviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define QGLVIEWER_QGLVIEWER_H

#include "camera.h"
#include "../basic/canvas.h"
#include "../../basic/canvas.h"

#include <QClipboard>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand Down
4 changes: 2 additions & 2 deletions code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Then calls setSnapshotFormat() with the selected one (unless the user cancels).
Returns \c false if the user presses the Cancel button and \c true otherwise. */
bool QGLViewer::openSnapshotFormatDialog() {
bool ok = false;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList list = formats.split(";;", QString::SkipEmptyParts);
#else
QStringList list = formats.split(";;", Qt::SkipEmptyParts);
Expand Down Expand Up @@ -543,7 +543,7 @@ void QGLViewer::saveSnapshot(bool automatic, bool overwrite) {
this, "Choose a file name to save under", snapshotFileName(), formats,
&selectedFormat,
overwrite ? QFileDialog::DontConfirmOverwrite
: QFlags<QFileDialog::Option>(0));
: QFlags<QFileDialog::Option>());
setSnapshotFormat(Qtformat[selectedFormat]);

if (checkFileName(fileName, this, snapshotFormat()))
Expand Down
14 changes: 8 additions & 6 deletions code/PolyFit/paint_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void PaintCanvas::draw() {
mesh_render_->draw(optimized_mesh_, interacting);
}

const static QFont font("Helvetica", 12/*, QFont::Bold*/); // "Times", "Helvetica", "Bradley Hand ITC"
const static QFont font("Times", 12/*, QFont::Bold*/); // "Times", "Helvetica", "Bradley Hand ITC"
if (show_hint_text_) {
if (!hint_text_.isEmpty()) {
glColor3f(0, 0, 0.7f);
Expand All @@ -245,10 +245,13 @@ void PaintCanvas::draw() {

if (show_mouse_hint_) {
glColor3f(0, 0, 0);
drawText(30, 120, "Mouse Operations:", font);
drawText(30, 150, " - Orbit: left button", font);
drawText(30, 180, " - Pan: right button", font);
drawText(30, 210, " - Zoom: wheel", font);
drawText(30, 100, "Mouse Operations:", font);
glColor3f(0, 0, 0);
drawText(30, 130, " - Orbit: left button", font);
glColor3f(0, 0, 0);
drawText(30, 160, " - Pan: right button", font);
glColor3f(0, 0, 0);
drawText(30, 190, " - Zoom: wheel", font);
}

// Liangliang: It seems the renderText() func disables multi-sample and depth test
Expand Down Expand Up @@ -606,7 +609,6 @@ void PaintCanvas::optimization() {
FaceSelection selector(point_set_, mesh);
selector.optimize(adjacency, main_window_->active_solver());


// to have consistent orientation for the final model
adjacency = hypothesis_->extract_adjacency(mesh);
selector.re_orient(adjacency, main_window_->active_solver());
Expand Down
4 changes: 2 additions & 2 deletions code/method/alpha_shape_CGAL4.11_and_later.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class Alpha_shape_2 : public Dt
typedef Type_of_alpha FT;

//check simplices are correctly instantiated
static_assert( (boost::is_same<NT, typename Dt::Face::NT>::value) );
static_assert( (boost::is_same<NT, typename Dt::Vertex::NT>::value) );
static_assert( (boost::is_same<NT, typename Dt::Face::NT>::value), "NT type in Dt::Face does not match NT" );
static_assert( (boost::is_same<NT, typename Dt::Vertex::NT>::value), "NT type in Dt::Vertex does not match NT");

typedef typename Dt::Point Point;

Expand Down

0 comments on commit a2b9b93

Please sign in to comment.