From 1f646405e82b3e67b8d4e9371f45657d76d40d29 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 5 Jun 2018 14:22:26 +0200 Subject: [PATCH] Fix -Wconversion warnings (and a few others) in QGLViewer --- GraphicsView/include/CGAL/Qt/camera_impl.h | 12 +- GraphicsView/include/CGAL/Qt/frame_impl.h | 2 +- .../include/CGAL/Qt/image_interface.h | 4 +- GraphicsView/include/CGAL/Qt/qglviewer.h | 5 +- GraphicsView/include/CGAL/Qt/qglviewer_impl.h | 110 ++++++++++-------- 5 files changed, 72 insertions(+), 61 deletions(-) diff --git a/GraphicsView/include/CGAL/Qt/camera_impl.h b/GraphicsView/include/CGAL/Qt/camera_impl.h index eb5e939c774..249d80f20e1 100644 --- a/GraphicsView/include/CGAL/Qt/camera_impl.h +++ b/GraphicsView/include/CGAL/Qt/camera_impl.h @@ -1948,7 +1948,7 @@ int unProject(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble *modelview, CGAL_INLINE_FUNCTION Vec Camera::projectedCoordinatesOf(const Vec& src, const Frame* frame) const { - GLdouble x,y,z; + GLdouble x = 0.f, y = 0.f, z = 0.f; static GLint viewport[4]; getViewport(viewport); @@ -1990,7 +1990,7 @@ Vec Camera::projectedCoordinatesOf(const Vec& src, const Frame* frame) const CGAL_INLINE_FUNCTION Vec Camera::unprojectedCoordinatesOf(const Vec& src, const Frame* frame) const { - GLdouble x,y,z; + GLdouble x = 0.f, y = 0.f, z = 0.f; static GLint viewport[4]; getViewport(viewport); unProject(src.x,src.y,src.z, modelViewMatrix_, projectionMatrix_, viewport, &x,&y,&z); @@ -2480,8 +2480,8 @@ void Camera::setFrustum(double frustum[6]) double B = (r+l)/(r-l); double C = 2*n/(t-b); double D = (t+b)/(t-b); - float E = -(f+n)/(f-n); - float F = -2*(f*n)/(f-n); + double E = -(f+n)/(f-n); + double F = -2*(f*n)/(f-n); projectionMatrix_[0] = A; projectionMatrix_[4] = 0; projectionMatrix_[8] = B ; projectionMatrix_[12] = 0; projectionMatrix_[1] = 0; projectionMatrix_[5] = C; projectionMatrix_[9] = D ; projectionMatrix_[13] = 0; projectionMatrix_[2] = 0; projectionMatrix_[6] = 0; projectionMatrix_[10] = E ; projectionMatrix_[14] = F; @@ -2493,8 +2493,8 @@ void Camera::setFrustum(double frustum[6]) double B = -(r+l)/(r-l); double C = 2/(t-b); double D = -(t+b)/(t-b); - float E = -(f+n)/(f-n); - float F = -2/(f-n); + double E = -(f+n)/(f-n); + double F = -2/(f-n); projectionMatrix_[0] = A; projectionMatrix_[1] = 0; projectionMatrix_[2] = 0 ; projectionMatrix_[3] = 0; projectionMatrix_[4] = 0; projectionMatrix_[5] = C; projectionMatrix_[6] = 0 ; projectionMatrix_[7] = 0; projectionMatrix_[8] = 0; projectionMatrix_[9] = 0; projectionMatrix_[10] = F ; projectionMatrix_[11] = 0; diff --git a/GraphicsView/include/CGAL/Qt/frame_impl.h b/GraphicsView/include/CGAL/Qt/frame_impl.h index a8433867b5a..722170f9143 100644 --- a/GraphicsView/include/CGAL/Qt/frame_impl.h +++ b/GraphicsView/include/CGAL/Qt/frame_impl.h @@ -1137,7 +1137,7 @@ void Frame::alignWithFrame(const Frame *const frame, bool move, rotate(rotation().inverse() * Quaternion(axis, angle) * orientation()); // Try to align an other axis direction - unsigned short d = (index[1] + 1) % 3; + unsigned short d = (unsigned short)((index[1] + 1) % 3); Vec dir((d == 0) ? 1.0 : 0.0, (d == 1) ? 1.0 : 0.0, (d == 2) ? 1.0 : 0.0); dir = inverseTransformOf(dir); diff --git a/GraphicsView/include/CGAL/Qt/image_interface.h b/GraphicsView/include/CGAL/Qt/image_interface.h index d76fd993efe..90818ad827a 100644 --- a/GraphicsView/include/CGAL/Qt/image_interface.h +++ b/GraphicsView/include/CGAL/Qt/image_interface.h @@ -56,14 +56,14 @@ private Q_SLOTS: { if(currentlyFocused == imgHeight && ratioCheckBox->isChecked()) - {imgWidth->setValue(i*ratio);} + {imgWidth->setValue(int(i*ratio));} } void imgWidthValueChanged(int i) { if(currentlyFocused == imgWidth && ratioCheckBox->isChecked()) - {imgHeight->setValue(i/ratio);} + {imgHeight->setValue(int(i/ratio));} } void onFocusChanged(QWidget*, QWidget* now) diff --git a/GraphicsView/include/CGAL/Qt/qglviewer.h b/GraphicsView/include/CGAL/Qt/qglviewer.h index c076fcbb102..f5c28160c24 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer.h @@ -218,7 +218,10 @@ public Q_SLOTS: also setForegroundColor(). */ void setBackgroundColor(const QColor &color) { backgroundColor_ = color; - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + glClearColor(GLclampf(color.redF()), + GLclampf(color.greenF()), + GLclampf(color.blueF()), + GLclampf(color.alphaF())); } /*! Sets the foregroundColor() of the viewer, used to draw visual hints. See * also setBackgroundColor(). */ diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index 2d78bd719fb..4aa909c80fc 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -493,10 +493,10 @@ void CGAL::QGLViewer::postDraw() { } // Restore foregroundColor - float color[4]; - color[0] = foregroundColor().red() / 255.0f; - color[1] = foregroundColor().green() / 255.0f; - color[2] = foregroundColor().blue() / 255.0f; + GLfloat color[4]; + color[0] = GLfloat(foregroundColor().red()) / 255.0f; + color[1] = GLfloat(foregroundColor().green()) / 255.0f; + color[2] = GLfloat(foregroundColor().blue()) / 255.0f; color[3] = 1.0f; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); glDisable(GL_LIGHTING); @@ -818,7 +818,7 @@ CGAL_INLINE_FUNCTION void CGAL::QGLViewer::renderText(double x, double y, double z, const QString &str, const QFont &font) { const Vec proj = camera_->projectedCoordinatesOf(Vec(x, y, z)); - renderText(proj.x, proj.y, str, font); + renderText(int(proj.x), int(proj.y), str, font); } #endif @@ -2817,7 +2817,7 @@ void CGAL::QGLViewer::getWheelActionBinding(MouseHandler handler, MouseAction ac return; } - key = ::Qt::Key(-1); + key = ::Qt::Key_unknown; modifiers = ::Qt::NoModifier; } @@ -3094,7 +3094,7 @@ void CGAL::QGLViewer::drawVisualHints() { QMatrix4x4 mvMatrix; for(int i=0; i < 16; i++) { - mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i]; + mvMatrix.data()[i] = float(camera()->orientation().inverse().matrix()[i]); } rendering_program.setUniformValue("mvp_matrix", mvpMatrix); rendering_program.setUniformValue("color", QColor(::Qt::lightGray)); @@ -3117,7 +3117,7 @@ void CGAL::QGLViewer::drawVisualHints() { camera()->setType(CGAL::qglviewer::Camera::ORTHOGRAPHIC); for(int i=0; i < 16; i++) { - mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i]; + mvMatrix.data()[i] = float(camera()->orientation().inverse().matrix()[i]); } mvpMatrix.setToIdentity(); mvpMatrix.ortho(-1,1,-1,1,-1,1); @@ -3151,8 +3151,8 @@ void CGAL::QGLViewer::drawVisualHints() { std::vector vertices; for(int i=0; i< 4; ++i) { - float x = (pow(-1, i)*(1-i/2)); - float y = (pow(-1, i)*(i/2)); + float x = float(std::pow(-1, i)*(1-i/2)); + float y = float(std::pow(-1, i)*(i/2)); vertices.push_back(x); vertices.push_back(y); vertices.push_back(0); @@ -3167,9 +3167,11 @@ void CGAL::QGLViewer::drawVisualHints() { mvpMatrix.setToIdentity(); mvpMatrix.ortho(-1,1,-1,1,-1,1); size=30*devicePixelRatio(); - rendering_program.setUniformValue("mvp_matrix", mvpMatrix); - glViewport((camera()->projectedCoordinatesOf(camera()->pivotPoint()).x-size/2)*devicePixelRatio(), (height() - camera()->projectedCoordinatesOf(camera()->pivotPoint()).y-size/2)*devicePixelRatio(), size, size); - glScissor ((camera()->projectedCoordinatesOf(camera()->pivotPoint()).x-size/2)*devicePixelRatio(), (height() - camera()->projectedCoordinatesOf(camera()->pivotPoint()).y-size/2)*devicePixelRatio(), size, size); + rendering_program.setUniformValue("mvp_matrix", mvpMatrix); + glViewport(GLint((camera()->projectedCoordinatesOf(camera()->pivotPoint()).x-size/2)*devicePixelRatio()), + GLint((height() - camera()->projectedCoordinatesOf(camera()->pivotPoint()).y-size/2)*devicePixelRatio()), size, size); + glScissor (GLint((camera()->projectedCoordinatesOf(camera()->pivotPoint()).x-size/2)*devicePixelRatio()), + GLint((height() - camera()->projectedCoordinatesOf(camera()->pivotPoint()).y-size/2)*devicePixelRatio()), size, size); rendering_program.setUniformValue("color", QColor(::Qt::black)); glLineWidth(3.0); glDrawArrays(GL_LINES, 0, static_cast(4)); @@ -3214,18 +3216,21 @@ CGAL_INLINE_FUNCTION void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Vec from, CGAL::qglviewer::Vec to, CGAL::qglviewer::Vec color, std::vector &data) { + using std::cos; + using std::sin; + using std::acos; CGAL::qglviewer::Vec temp = to-from; - QVector3D dir = QVector3D(temp.x, temp.y, temp.z); + QVector3D dir = QVector3D(float(temp.x), float(temp.y), float(temp.z)); QMatrix4x4 mat; mat.setToIdentity(); - mat.translate(from.x, from.y, from.z); + mat.translate(float(from.x), float(from.y), float(from.z)); mat.scale(dir.length()); dir.normalize(); float angle = 0.0; if(std::sqrt((dir.x()*dir.x()+dir.y()*dir.y())) > 1) angle = 90.0f; else - angle =acos(dir.y()/std::sqrt(dir.x()*dir.x()+dir.y()*dir.y()+dir.z()*dir.z()))*180.0/CGAL_PI; + angle = float(acos(dir.y()/std::sqrt(dir.lengthSquared()))*180.0/CGAL_PI); QVector3D axis; axis = QVector3D(dir.z(), 0, -dir.x()); @@ -3268,7 +3273,7 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back((float)color.y); data.push_back((float)color.z); //point C1 - D = (d+360/prec)*CGAL_PI/180.0; + D = float((d+360/prec)*CGAL_PI/180.0); p = QVector4D(Rf* sin(D), 0.66f, Rf* cos(D), 1.f); n = QVector4D(sin(D), sin(a), cos(D), 1.0); pR = mat*p; @@ -3292,7 +3297,7 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve for(int d = 0; d<360; d+= 360/prec) { //point A1 - double D = d*CGAL_PI/180.0; + float D = float(d*CGAL_PI/180.0); QVector4D p(rf*sin(D), 0.66f, rf*cos(D), 1.f); QVector4D n(sin(D), 0.f, cos(D), 1.f); QVector4D pR = mat*p; @@ -3304,9 +3309,9 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back(color.x); - data.push_back(color.y); - data.push_back(color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); //point B1 p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0); n = QVector4D(sin(D), 0, cos(D), 1.0); @@ -3320,11 +3325,11 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back(color.x); - data.push_back(color.y); - data.push_back(color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); //point C1 - D = (d+360/prec)*CGAL_PI/180.0; + D = float((d+360/prec)*CGAL_PI/180.0); p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0); n = QVector4D(sin(D), 0, cos(D), 1.0); pR = mat*p; @@ -3335,11 +3340,11 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back(color.x); - data.push_back(color.y); - data.push_back(color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); //point A2 - D = (d+360/prec)*CGAL_PI/180.0; + D = float((d+360/prec)*CGAL_PI/180.0); p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0); n = QVector4D(sin(D), 0, cos(D), 1.0); @@ -3351,9 +3356,9 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back((float)color.x); - data.push_back((float)color.y); - data.push_back((float)color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); //point B2 p = QVector4D(rf * sin(D), 0.66f, rf*cos(D), 1.f); n = QVector4D(sin(D), 0, cos(D), 1.0); @@ -3365,11 +3370,11 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back((float)color.x); - data.push_back((float)color.y); - data.push_back((float)color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); //point C2 - D = d*CGAL_PI/180.0; + D = float(d*CGAL_PI/180.0); p = QVector4D(rf * sin(D), 0.66f, rf*cos(D), 1.f); n = QVector4D(sin(D), 0.f, cos(D), 1.f); pR = mat*p; @@ -3380,9 +3385,9 @@ void CGAL::QGLViewer::drawArrow(double r,double R, int prec, CGAL::qglviewer::Ve data.push_back(nR.x()); data.push_back(nR.y()); data.push_back(nR.z()); - data.push_back(color.x); - data.push_back(color.y); - data.push_back(color.z); + data.push_back(float(color.x)); + data.push_back(float(color.y)); + data.push_back(float(color.z)); } } @@ -3403,7 +3408,7 @@ void CGAL::QGLViewer::drawAxis(qreal length) { rendering_program_light.bind(); vaos[AXIS].bind(); vbos[Axis].bind(); - vbos[Axis].allocate(data.data(), static_cast(data.size()) * sizeof(float)); + vbos[Axis].allocate(data.data(), static_cast(data.size() * sizeof(float))); rendering_program_light.enableAttributeArray("vertex"); rendering_program_light.setAttributeBuffer("vertex",GL_FLOAT,0,3, static_cast(9*sizeof(float))); @@ -3432,22 +3437,22 @@ void CGAL::QGLViewer::drawGrid(qreal size, int nbSubdivisions) { std::vector v_Grid; for (int i=0; i<=nbSubdivisions; ++i) { - const float pos = size*(2.0*i/nbSubdivisions-1.0); + const float pos = float(size*(2.0*i/nbSubdivisions-1.0)); v_Grid.push_back(pos); - v_Grid.push_back(-size); - v_Grid.push_back(0.0); + v_Grid.push_back(float(-size)); + v_Grid.push_back(0.f); v_Grid.push_back(pos); - v_Grid.push_back(+size); - v_Grid.push_back(0.0); + v_Grid.push_back(float(+size)); + v_Grid.push_back(0.f); - v_Grid.push_back(-size); + v_Grid.push_back(float(-size)); v_Grid.push_back(pos); - v_Grid.push_back(0.0); + v_Grid.push_back(0.f); - v_Grid.push_back( size); + v_Grid.push_back( float(size)); v_Grid.push_back( pos); - v_Grid.push_back( 0.0); + v_Grid.push_back( 0.f); } rendering_program.bind(); vaos[GRID].bind(); @@ -3471,7 +3476,7 @@ void CGAL::QGLViewer::drawGrid(qreal size, int nbSubdivisions) { rendering_program_light.bind(); vaos[GRID_AXIS].bind(); vbos[Grid_axis].bind(); - vbos[Grid_axis].allocate(d_axis.data(), static_cast(d_axis.size()) * sizeof(float)); + vbos[Grid_axis].allocate(d_axis.data(), static_cast(d_axis.size() * sizeof(float))); rendering_program_light.enableAttributeArray("vertex"); rendering_program_light.setAttributeBuffer("vertex",GL_FLOAT,0,3, static_cast(9*sizeof(float))); @@ -4013,7 +4018,10 @@ QImage* CGAL::QGLViewer::takeSnapshot( CGAL::qglviewer::SnapShotBackground back for (int j=0; j