From 2e29544645333ef5657c2e98f155e763b1f17d98 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Sun, 27 Apr 2008 10:09:22 +0000 Subject: [PATCH] Added collapse vertex function, improved interface --- src/fgt/edit_texture/edittexture.cpp | 3 +- src/fgt/edit_texture/images/sel_move.png | Bin 250 -> 0 bytes src/fgt/edit_texture/meshlab.qrc | 1 - src/fgt/edit_texture/renderarea.cpp | 109 ++++++++++++----------- src/fgt/edit_texture/renderarea.h | 7 ++ src/fgt/edit_texture/textureeditor.cpp | 8 +- src/fgt/edit_texture/textureeditor.h | 3 + src/fgt/edit_texture/textureeditor.ui | 4 +- 8 files changed, 78 insertions(+), 57 deletions(-) delete mode 100644 src/fgt/edit_texture/images/sel_move.png diff --git a/src/fgt/edit_texture/edittexture.cpp b/src/fgt/edit_texture/edittexture.cpp index d1c62513f..165e19917 100644 --- a/src/fgt/edit_texture/edittexture.cpp +++ b/src/fgt/edit_texture/edittexture.cpp @@ -173,7 +173,7 @@ void EditTexturePlugin::Decorate(QAction *, MeshModel &m, GLArea *gla) void EditTexturePlugin::StartEdit(QAction * /*mode*/, MeshModel &m, GLArea *gla ) { // Set up the model - m.cm.face.EnableFFAdjacency(); + if (!m.cm.face.IsFFAdjacencyEnabled()) m.cm.face.EnableFFAdjacency(); vcg::tri::UpdateTopology::FaceFaceFromTexCoord(m.cm); FaceSel.clear(); @@ -215,6 +215,7 @@ void EditTexturePlugin::StartEdit(QAction * /*mode*/, MeshModel &m, GLArea *gla void EditTexturePlugin::EndEdit(QAction * , MeshModel &m , GLArea * ) { // Delete the widget + for (unsigned i = 0; i < m.cm.face.size(); i++) m.cm.face[i].ClearS(); if (widget != 0) { delete widget; diff --git a/src/fgt/edit_texture/images/sel_move.png b/src/fgt/edit_texture/images/sel_move.png deleted file mode 100644 index 7036334c8486ee08c017021eec2d19809493e233..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPSixel1jQ5e@B265oaPaom-7*>KH{uYaQ2kq4W^gtE7F#}Ox9Ez0A0c0>FVdQ&MBb@0M@QrF#rGn diff --git a/src/fgt/edit_texture/meshlab.qrc b/src/fgt/edit_texture/meshlab.qrc index 18c75ccd5..226b681dc 100644 --- a/src/fgt/edit_texture/meshlab.qrc +++ b/src/fgt/edit_texture/meshlab.qrc @@ -7,7 +7,6 @@ images/invertsel.png images/rotate.png images/scale.png - images/sel_move.png images/sel_rect.png images/sel_rect_minus.png images/sel_rect_plus.png diff --git a/src/fgt/edit_texture/renderarea.cpp b/src/fgt/edit_texture/renderarea.cpp index fa77dec4d..b8751d1a2 100644 --- a/src/fgt/edit_texture/renderarea.cpp +++ b/src/fgt/edit_texture/renderarea.cpp @@ -11,6 +11,8 @@ #define NOSEL -1 #define AREADIM 400 #define HRECT 6 +#define MINZOOM 0.1 +#define MAXZOOM 7 RenderArea::RenderArea(QWidget *parent, QString textureName, MeshModel *m, unsigned tnum) : QGLWidget(parent) { @@ -71,6 +73,8 @@ RenderArea::RenderArea(QWidget *parent, QString textureName, MeshModel *m, unsig this->setMouseTracking(true); this->setCursor(Qt::PointingHandCursor); this->setAttribute(Qt::WA_NoSystemBackground); + this->setAttribute(Qt::WA_KeyCompression, true); + this->setFocusPolicy(Qt::ClickFocus); } RenderArea::~RenderArea() @@ -468,9 +472,7 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *e) case Vertex: if (selectedV) { - //CountVertexes(); - // <-------- - VCount = 2; + CountVertexes(); selection = QRect(QPoint(selStart.x() - RADIUS/2, selStart.y() - RADIUS/2), QPoint(selEnd.x() + RADIUS/2, selEnd.y() + RADIUS/2)); if (VCount > 1) { @@ -646,9 +648,9 @@ void RenderArea::wheelEvent(QWheelEvent*e) bool scale = false; if (e->delta() > 0) { - if (zoom/0.75 < 6) { zoom /= 0.75; scale = true; } + if (zoom/0.75 < MAXZOOM) { zoom /= 0.75; scale = true; } } - else if (zoom*0.75 > 0.1) { zoom *= 0.75; scale = true; } + else if (zoom*0.75 > MINZOOM) { zoom *= 0.75; scale = true; } if (scale) { // Change the viewport, putting the center of the screen on the mouseposition @@ -675,15 +677,8 @@ void RenderArea::wheelEvent(QWheelEvent*e) void RenderArea::keyPressEvent(QKeyEvent *e) { - // <----- - if(e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_H) - { - zoom = 1; - ResetTrack(true); - if (selected) RecalculateSelectionArea(); - else if (selectedV) UpdateVertexSelection(); - this->update(); - } + if (e->key() == Qt::Key_H) ResetPosition(); + else e->ignore(); } void RenderArea::RemapClamp() @@ -752,7 +747,7 @@ void RenderArea::ChangeMode(int index) if (mode != Edit) { mode = Edit; - this->setCursor(QCursor(QBitmap(":/images/sel_move.png"))); + this->setCursor(Qt::SizeAllCursor); } break; case 2: @@ -772,7 +767,7 @@ void RenderArea::ChangeMode(int index) selected = true; selVertBit = CVertexO::NewBitFlag(); } - this->setCursor(QCursor(QBitmap(":/images/sel_move.png"))); + this->setCursor(Qt::SizeAllCursor); } else { @@ -840,6 +835,8 @@ void RenderArea::ChangeSelectMode(int index) { selected = false; selBit = CFaceO::NewBitFlag(); + for (unsigned i = 0; i < model->cm.face.size(); i++) model->cm.face[i].ClearS(); + emit UpdateModel(); } } @@ -1127,39 +1124,23 @@ void RenderArea::Flip(bool mode) void RenderArea::UnifyCouple() { - // <------ + // Calculate the average coordinates and unify a couple of vertexes if (VCount == 2) { - int i1 = -1, j1, i2 = -1, j2; - for (unsigned i = 0; i < model->cm.face.size(); i++) - { - if (i2 != -1) break; - for (unsigned j = 0; j < 3; j++) - { - if (areaUV.contains(QPointF(model->cm.face[i].WT(j).u(),model->cm.face[i].WT(j).v())) - && model->cm.face[i].V(j)->IsUserBit(selVertBit)) - { - if (i1 == -1) {i1 = i; j1 = j;} - else {i2 = i; j2 = j; break;} - } - } - } - float tu = (model->cm.face[i1].WT(j1).u() + model->cm.face[i2].WT(j2).u())/2.0; - float tv = (model->cm.face[i1].WT(j1).v() + model->cm.face[i2].WT(j2).v())/2.0; + float tu = (vc1.u() + vc2.u())/2.0; + float tv = (vc1.v() + vc2.v())/2.0; for (unsigned i = 0; i < model->cm.face.size(); i++) { for (unsigned j = 0; j < 3; j++) { - if (areaUV.contains(QPointF(model->cm.face[i].WT(j).u(),model->cm.face[i].WT(j).v())) - && model->cm.face[i].V(j)->IsUserBit(selVertBit)) + if (model->cm.face[i].V(j) == collapse1 || model->cm.face[i].V(j) == collapse2) { model->cm.face[i].WT(j).u() = tu; model->cm.face[i].WT(j).v() = tv; } } } - selectedV = false; selVertBit = CVertexO::NewBitFlag(); areaUV = QRectF(); @@ -1170,6 +1151,13 @@ void RenderArea::UnifyCouple() } } +void RenderArea::UnifySet() +{ + // Unify a set of vertexes + // <------ + +} + void RenderArea::HandleScale(QPoint e) { // Move the rectangle of scaling and resize the selction area @@ -1388,7 +1376,7 @@ void RenderArea::ImportSelection() { if (!selected) selected = true; (*fi).SetUserBit(selBit); - QVector t = QVector(); + QVector t = QVector(); t.push_back(ToScreenSpace((*fi).WT(0).u(), (*fi).WT(0).v())); t.push_back(ToScreenSpace((*fi).WT(1).u(), (*fi).WT(1).v())); t.push_back(ToScreenSpace((*fi).WT(2).u(), (*fi).WT(2).v())); @@ -1409,34 +1397,41 @@ void RenderArea::ImportSelection() void RenderArea::CountVertexes() { - model->cm.face.EnableVFAdjacency(); - vcg::tri::UpdateTopology::VertexFace(model->cm); - - - // Count the number of selected UV vertexes + // Count the number of selected UV vertexes (not so easy) VCount = 0; - + collapse1 = 0; + collapse2 = 0; CMeshO::FaceIterator fi; + vector< TexCoord2 > tmpCoord = vector< TexCoord2 >(); for(fi = model->cm.face.begin(); fi != model->cm.face.end(); ++fi) { if ((*fi).WT(0).n() == textNum) { for (int j = 0; j < 3; j++) { - if ((*fi).V(j)->IsUserBit(selBit) && !(*fi).V(j)->IsV()) + if ((*fi).V(j)->IsUserBit(selVertBit)) { - (*fi).V(j)->SetV(); - VCount++; - TexCoord2 tc = (*fi).WT(j); - - - //vcg::face::VFIterator vfi((*fi).V(j)); + if (!isInside(tmpCoord, (*fi).WT(j)) && areaUV.contains(QPointF((*fi).WT(j).u(), (*fi).WT(j).v()))) + { + VCount++; + if (collapse1 == 0) {collapse1 = (*fi).V(j); vc1 = (*fi).WT(j); } + else if (collapse2 == 0) {collapse2 = (*fi).V(j); vc2 = (*fi).WT(j); } + tmpCoord.push_back((*fi).WT(j)); + } } } - } } - for (unsigned i = 0; i < model->cm.vert.size(); i++) model->cm.vert[i].ClearV(); +} + +bool RenderArea::isInside(vector > tmpCoord, TexCoord2 act) +{ + // Support function for search in a vector + for (unsigned i = 0; i < tmpCoord.size(); i++) + { + if (tmpCoord[i] == act) return true; + } + return false; } void RenderArea::ShowFaces() @@ -1448,3 +1443,13 @@ void RenderArea::ShowFaces() else model->cm.face[i].ClearS(); } } + +void RenderArea::ResetPosition() +{ + // Reset the position of the viewport + zoom = 1; + ResetTrack(true); + if (selected) RecalculateSelectionArea(); + else if (selectedV) UpdateVertexSelection(); + this->update(); +} \ No newline at end of file diff --git a/src/fgt/edit_texture/renderarea.h b/src/fgt/edit_texture/renderarea.h index 1061ef2e8..d2cf45f04 100644 --- a/src/fgt/edit_texture/renderarea.h +++ b/src/fgt/edit_texture/renderarea.h @@ -8,6 +8,7 @@ #include #include #include +#include #define TEXTX 175 #define TEXTY 200 @@ -45,6 +46,8 @@ public: void Flip(bool mode); void ImportSelection(); void UnifyCouple(); + void UnifySet(); + void ResetPosition(); protected: void paintEvent(QPaintEvent *event); @@ -106,6 +109,9 @@ private: float zoom; // Actual value of zoom int VCount; // Vertex counter + CVertexO *collapse1; // Pointer to vertex for collapse + CVertexO *collapse2; + TexCoord2 vc1, vc2; void UpdateUV(); void UpdateVertex(); @@ -126,6 +132,7 @@ private: void DrawCircle(QPoint origin); void UpdateBoundingArea(QPoint topLeft, QPoint topRight); void CountVertexes(); + bool isInside(vector>, TexCoord2); void ShowFaces(); signals: diff --git a/src/fgt/edit_texture/textureeditor.cpp b/src/fgt/edit_texture/textureeditor.cpp index 6602a36e2..6aaa3a399 100644 --- a/src/fgt/edit_texture/textureeditor.cpp +++ b/src/fgt/edit_texture/textureeditor.cpp @@ -168,7 +168,7 @@ void TextureEditor::on_unify2Button_clicked() void TextureEditor::on_unifySetButton_clicked() { - //((RenderArea*)ui.tabWidget->currentWidget()->childAt(MARGIN,MARGIN))->UnifySet(); + ((RenderArea*)ui.tabWidget->currentWidget()->childAt(MARGIN,MARGIN))->UnifySet(); } void TextureEditor::on_smoothButton_clicked() @@ -177,6 +177,12 @@ void TextureEditor::on_smoothButton_clicked() SmoothTextureCoordinates(); } +void TextureEditor::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_H) ((RenderArea*)ui.tabWidget->currentWidget()->childAt(MARGIN,MARGIN))->ResetPosition(); + else e->ignore(); +} + void TextureEditor::on_tabWidget_currentChanged(int index) { int button = 0, mode = -1; diff --git a/src/fgt/edit_texture/textureeditor.h b/src/fgt/edit_texture/textureeditor.h index 5d12f355f..f34620f94 100644 --- a/src/fgt/edit_texture/textureeditor.h +++ b/src/fgt/edit_texture/textureeditor.h @@ -56,6 +56,9 @@ private slots: public slots: void UpdateModel(); +protected: + void keyPressEvent(QKeyEvent *event); + }; #endif // TEXTUREEDITOR_H diff --git a/src/fgt/edit_texture/textureeditor.ui b/src/fgt/edit_texture/textureeditor.ui index c37c9e87d..f4bcf9949 100644 --- a/src/fgt/edit_texture/textureeditor.ui +++ b/src/fgt/edit_texture/textureeditor.ui @@ -54,7 +54,7 @@ - Unify a set of vertexes + Choose and unify a set of vertexes @@ -177,7 +177,7 @@ - Unselect any selected faces/vertexes + Clear selected faces/vertexes