From 0ff59ea1055f4e51f9935d5e48e40efb3cf39436 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 14 Sep 2016 09:55:18 +0200 Subject: [PATCH] Add missing files --- .../Surface_mesh/Parameterization_widget.ui | 48 ++++++ .../Plugins/Surface_mesh/UVProjector.h | 139 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_widget.ui create mode 100644 Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/UVProjector.h diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_widget.ui b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_widget.ui new file mode 100644 index 00000000000..7c705c323e0 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/Parameterization_widget.ui @@ -0,0 +1,48 @@ + + + Parameterization + + + + 0 + 0 + 400 + 300 + + + + UVMapping + + + + + + + true + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + false + + + QPainter::Antialiasing + + + QGraphicsView::NoDrag + + + QGraphicsView::NoAnchor + + + + + + + + + diff --git a/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/UVProjector.h b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/UVProjector.h new file mode 100644 index 00000000000..dd54dad556d --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Plugins/Surface_mesh/UVProjector.h @@ -0,0 +1,139 @@ +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +struct State{ + bool is_left_pressed; + bool is_right_pressed; +}; + +class UVProjector:public QWidget +{ +public: + UVProjector(QWidget* parent = 0, Qt::WindowFlags flags =0) + :QWidget(parent,flags) + { + setMouseTracking(true); + state = {false,false}; + translation = QVector3D(0,0,1); + rotation = 0; + prev_pos = QPoint(0,0); + rot_center = QPoint(width()/2, height()/2); + + } + void setPoints(const std::vector& p){points = p;} +protected: + void paintEvent(QPaintEvent*) + { + QPainter painter(this); + QFont font; + font.setPointSize(10); + painter.setFont(font); + painter.setBrush(QBrush(Qt::white)); + painter.setPen(Qt::white); + painter.drawRect(QRect(QPoint(0,0), QPoint(this->width(),this->height()))); + + painter.setPen(QPen(Qt::black)); + Q_FOREACH(QPointF p, points) + { + /*Translation(-w/2, -h/2) to recenter the scene, then + * Scaling then Rotation and finaly the Translation + * + Translation(w/2+h/2) to put it back. */ + //scaled values + qreal sx(translation.z()* (p.x()-width() /2.0)), sy(translation.z()* (p.y()-height()/2.0)) ; + + painter.drawPoint( + translation.x() + width() /2.0 + cos(rotation)*sx + sin(rotation)*sy, + translation.y() + height()/2.0 + -sin(rotation)*sx + cos(rotation)*sy + ); + } + painter.end(); + } + void mouseMoveEvent(QMouseEvent* me) + { + if(state.is_left_pressed) + { + QVector2D prev_dir(prev_pos.x() - width()/2, + prev_pos.y() - height()/2); + QVector2D dir(me->pos().x() - width()/2, + me->pos().y() - height()/2); + prev_dir.normalize(); + dir.normalize(); + qreal a = acos(QVector2D::dotProduct(dir,prev_dir)/(dir.length()*prev_dir.length())); + qreal det = dir.x()*prev_dir.y()-prev_dir.x()*dir.y(); + if(det > 0) + rotation += a; + else + rotation -= a; + update(); + } + else if(state.is_right_pressed) + { + QVector2D dir(me->pos().x() - prev_pos.x(), + me->pos().y() - prev_pos.y()); + + translation[0] += dir.x(); + translation[1] += dir.y(); + update(); + } + prev_pos = me->pos(); + } + + void mousePressEvent(QMouseEvent* me) + { + if(me->button() == Qt::LeftButton) + state.is_left_pressed = true; + else if (me->button() == Qt::RightButton) + state.is_right_pressed = true; + } + void mouseReleaseEvent(QMouseEvent* me) + { + if(me->button() == Qt::LeftButton) + state.is_left_pressed = false; + else if (me->button() == Qt::RightButton) + state.is_right_pressed = false; + } + void wheelEvent(QWheelEvent *event) + { + if(event->delta() >0) + translation[2] *= 1.2; + else + translation[2] /= 1.2; + update(); + } + + void mouseDoubleClickEvent(QMouseEvent * me) + { + if(state.is_right_pressed) + { + rot_center = me->pos(); + } + else{ + translation = QVector3D(0,0,1); + rotation = 0; + rot_center = QPoint(width()/2, height()/2); + } + update(); + } +private: + QPoint prev_pos; + QPoint rot_center; + std::vector points; + qreal rotation; + QVector3D translation; + State state; + +};