From 9adc490b872415d72e2fc2fb2e84ab71d4b78a84 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Wed, 20 Mar 2013 08:56:50 +0000 Subject: [PATCH] small changes to update to the recent changes of the vcg library --- .../decorate_background/cubemap.cpp | 117 ++-- .../edit_measure/edit_measure.cpp | 12 +- src/meshlabplugins/edit_paint/edit_paint.cpp | 554 +++++++++--------- .../edit_texture/edittexture.cpp | 204 +++---- .../edit_texture/renderarea.cpp | 174 +++--- .../filter_sdfgpu/filter_sdfgpu.cpp | 8 +- 6 files changed, 534 insertions(+), 535 deletions(-) diff --git a/src/meshlabplugins/decorate_background/cubemap.cpp b/src/meshlabplugins/decorate_background/cubemap.cpp index 5f2c85a3b..aaca32234 100755 --- a/src/meshlabplugins/decorate_background/cubemap.cpp +++ b/src/meshlabplugins/decorate_background/cubemap.cpp @@ -63,12 +63,12 @@ static int cube_faces[6][4] = { static float tex_vert[4][2] = { - {1,1},{1,0},{0,0},{0,1}, + {1,1},{1,0},{0,0},{0,1}, }; void CICubeMap::DrawEnvCube(Matrix44f &tr) { - if(!GLEW_ARB_texture_cube_map) + if(!GLEW_ARB_texture_cube_map) DrawEnvCubeOld(tr); else DrawEnvCubeExt(tr); } @@ -80,13 +80,13 @@ void CICubeMap::DrawEnvCubeOld(Matrix44f &tr) { checkGLError::qDebug("DrawEnvCubeOld: start"); glMatrixMode(GL_MODELVIEW); - glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT | GL_TEXTURE_BIT); - + glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT | GL_TEXTURE_BIT); + glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_1D); glEnable(GL_TEXTURE_2D); glDepthMask(false); - + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -96,19 +96,19 @@ void CICubeMap::DrawEnvCubeOld(Matrix44f &tr) glMultMatrix(tr); glScalef(radius,radius,radius); - for (int i=0; i<6; ++i) - { - glBindTexture(GL_TEXTURE_2D,oti[i]); - - glBegin(GL_QUADS); + for (int i=0; i<6; ++i) + { + glBindTexture(GL_TEXTURE_2D,oti[i]); + + glBegin(GL_QUADS); for (int j=0; j<4; ++j) { glTexCoord2f(tex_vert[j][0],tex_vert[j][1]); - glVertex(cube_vertices[cube_faces[i][j]]); - } - glEnd(); - + glVertex(cube_vertices[cube_faces[i][j]]); + } + glEnd(); + } - + glDepthMask(true); glPopMatrix(); glPopAttrib(); @@ -118,11 +118,10 @@ void CICubeMap::DrawEnvCubeOld(Matrix44f &tr) void CICubeMap::DrawEnvCubeExt(Matrix44f &tr) { - Matrix44f ii=tr; - ii=Invert(ii); - + Matrix44f ii=Inverse(tr); + glMatrixMode(GL_MODELVIEW); - glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT | GL_TEXTURE_BIT ); // saves the current state of opengl + glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT | GL_TEXTURE_BIT ); // saves the current state of opengl glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); @@ -132,11 +131,11 @@ void CICubeMap::DrawEnvCubeExt(Matrix44f &tr) glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_CUBE_MAP_ARB); - //CIMsg::checkGLError("glEnable(GL_TEXTURE_CUBE_MAP_ARB);"); - glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,ti); - //CIMsg::checkGLError("glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,ti);"); - glDepthMask(false); - + //CIMsg::checkGLError("glEnable(GL_TEXTURE_CUBE_MAP_ARB);"); + glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,ti); + //CIMsg::checkGLError("glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,ti);"); + glDepthMask(false); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); @@ -144,7 +143,7 @@ void CICubeMap::DrawEnvCubeExt(Matrix44f &tr) glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); - + glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -157,22 +156,22 @@ void CICubeMap::DrawEnvCubeExt(Matrix44f &tr) glPushMatrix();// Texture glLoadIdentity(); glMultMatrix(ii); - + // LQ.track.inverse().applyGL(); - for (int i=0; i<6; ++i) - { + for (int i=0; i<6; ++i) + { glBegin(GL_QUADS); - for (int j=0; j<4; ++j) { - glNormal(-cube_vertices[cube_faces[i][j]]); + for (int j=0; j<4; ++j) { + glNormal(-cube_vertices[cube_faces[i][j]]); glVertex(cube_vertices[cube_faces[i][j]]); } glEnd(); - + } - glMatrixMode(GL_TEXTURE); - glPopMatrix();// Texture - glMatrixMode(GL_MODELVIEW); + glMatrixMode(GL_TEXTURE); + glPopMatrix();// Texture + glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); @@ -186,7 +185,7 @@ glPopAttrib(); bool CICubeMap::GetName(int i, QString basename, QString &filename) { QString exts[6]; - + exts[0]="_negx"; exts[1]="_posx"; exts[2]="_negy"; @@ -195,23 +194,23 @@ bool CICubeMap::GetName(int i, QString basename, QString &filename) exts[5]="_posz"; // qDebug("filename = %s basename = %s", qPrintable(filename), qPrintable(basename)); filename=basename; - QString ext= basename.right(4); - filename=filename.left(filename.length()-4); - filename.append(exts[i]); - filename.append(ext); + QString ext= basename.right(4); + filename=filename.left(filename.length()-4); + filename.append(exts[i]); + filename.append(ext); // qDebug("filename = %s basename = %s", qPrintable(filename), qPrintable(basename)); - return true; + return true; } bool CICubeMap::Load(const char *basename) { if(basename==0) return false; - bool ret; - if(!GLEW_ARB_texture_cube_map) - ret= LoadOld(basename); - else ret =LoadExt(basename); - if(!ret) SetInvalid(); - return ret; + bool ret; + if(!GLEW_ARB_texture_cube_map) + ret= LoadOld(basename); + else ret =LoadExt(basename); + if(!ret) SetInvalid(); + return ret; } bool CICubeMap::LoadOld(const char *basename) @@ -219,9 +218,9 @@ bool CICubeMap::LoadOld(const char *basename) glPushAttrib(GL_ENABLE_BIT); glDisable(GL_TEXTURE_1D); glEnable(GL_TEXTURE_2D); - if(oti[0]==0) glGenTextures(6,&(oti[0])); - QString filename; - + if(oti[0]==0) glGenTextures(6,&(oti[0])); + QString filename; + for(int i=0;i<6;++i) { glBindTexture(GL_TEXTURE_2D,oti[i]); @@ -229,9 +228,9 @@ bool CICubeMap::LoadOld(const char *basename) //CIMsg::checkGLError("glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER)"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //CIMsg::checkGLError("glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER)"); - - QImage tt; - + + QImage tt; + if(!GetName(i,basename,filename)) { glPopAttrib(); return false; @@ -248,10 +247,10 @@ bool CICubeMap::LoadOld(const char *basename) GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() ); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, tx.width(), tx.height(), GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() ); - //CIMsg::checkGLError("glTexImage2D"); + //CIMsg::checkGLError("glTexImage2D"); } - glPopAttrib(); + glPopAttrib(); return true; } bool CICubeMap::LoadExt(const char *basename) @@ -260,7 +259,7 @@ bool CICubeMap::LoadExt(const char *basename) glEnable(GL_TEXTURE_CUBE_MAP_ARB); glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); - if(ti==0) glGenTextures(1,&ti); + if(ti==0) glGenTextures(1,&ti); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,ti); GLenum targets[6]; @@ -276,7 +275,7 @@ bool CICubeMap::LoadExt(const char *basename) glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //CIMsg::checkGLError("glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER)"); - + for(int i=0;i<6;++i) { QString filename; @@ -288,7 +287,7 @@ bool CICubeMap::LoadExt(const char *basename) if(!tt.load(filename)) { glPopAttrib(); - //QMessageBox::warning(0,"Cubemapped background decoration","Warning unable to load cube map images: " + filename ); + //QMessageBox::warning(0,"Cubemapped background decoration","Warning unable to load cube map images: " + filename ); return false; } @@ -298,11 +297,11 @@ bool CICubeMap::LoadExt(const char *basename) gluBuild2DMipmaps(targets[i], 4, tx.width(), tx.height(), GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() ); //CIMsg::checkGLError("glTexImage2D"); - + } glDisable(GL_TEXTURE_CUBE_MAP_ARB); - + glPopAttrib(); return true; } diff --git a/src/meshlabplugins/edit_measure/edit_measure.cpp b/src/meshlabplugins/edit_measure/edit_measure.cpp index 910079522..4dca7cb34 100644 --- a/src/meshlabplugins/edit_measure/edit_measure.cpp +++ b/src/meshlabplugins/edit_measure/edit_measure.cpp @@ -36,9 +36,9 @@ EditMeasurePlugin::EditMeasurePlugin() :rubberband(Color4b(255,170,85,255)),was_ready(false) {} -const QString EditMeasurePlugin::Info() +const QString EditMeasurePlugin::Info() { - return tr("Allow to measure distances between points of a model"); + return tr("Allow to measure distances between points of a model"); } void EditMeasurePlugin::mousePressEvent(QMouseEvent *, MeshModel &, GLArea * gla) @@ -69,12 +69,12 @@ void EditMeasurePlugin::Decorate(MeshModel &, GLArea * gla,QPainter* p) { Point3f a,b; rubberband.GetPoints(a,b); - vcg::glLabel::render(p,b,QString("%1").arg(Distance(a,b))); + vcg::glLabel::render(p,b,QString("%1").arg(Distance(a,b))); if(!was_ready) { suspendEditToggle(); - gla->log->Logf(GLLogStream::FILTER, "Distance: %f",Distance(a,b)); + this->Log(GLLogStream::FILTER, "Distance: %f",Distance(a,b)); } was_ready=true; } @@ -83,11 +83,11 @@ void EditMeasurePlugin::Decorate(MeshModel &, GLArea * gla,QPainter* p) bool EditMeasurePlugin::StartEdit(MeshModel &, GLArea *gla ) { - gla->setCursor(QCursor(QPixmap(":/images/cur_measure.png"),15,15)); + gla->setCursor(QCursor(QPixmap(":/images/cur_measure.png"),15,15)); connect(this, SIGNAL(suspendEditToggle()),gla,SLOT(suspendEditToggle()) ); was_ready = false; rubberband.Reset(); - return true; + return true; } void EditMeasurePlugin::EndEdit(MeshModel &, GLArea *) diff --git a/src/meshlabplugins/edit_paint/edit_paint.cpp b/src/meshlabplugins/edit_paint/edit_paint.cpp index 00a84b4ad..7c0a114ca 100644 --- a/src/meshlabplugins/edit_paint/edit_paint.cpp +++ b/src/meshlabplugins/edit_paint/edit_paint.cpp @@ -28,7 +28,7 @@ using namespace std; using namespace vcg; -EditPaintPlugin::EditPaintPlugin() +EditPaintPlugin::EditPaintPlugin() { zbuffer = NULL; color_buffer = NULL; @@ -45,7 +45,7 @@ const QString EditPaintPlugin::Info() { return tr("Improved Painting"); } -bool EditPaintPlugin::StartEdit(MeshModel& m, GLArea * parent) +bool EditPaintPlugin::StartEdit(MeshModel& m, GLArea * parent) { dock = new QDockWidget(parent->window()); paintbox = new Paintbox(dock); @@ -53,24 +53,24 @@ bool EditPaintPlugin::StartEdit(MeshModel& m, GLArea * parent) dock->setWidget(paintbox); QPoint p=parent->mapToGlobal(QPoint(0,0)); dock->setGeometry(5 + p.x(), p.y() + 5 , paintbox->width(), parent->height() - 10); - dock->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Minimum); + dock->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Minimum); dock->setFloating(true); dock->setVisible(true); tri::UpdateBounding::Box(m.cm); - + m.updateDataMask(MeshModel::MM_VERTFACETOPO | MeshModel::MM_FACEMARK|MeshModel::MM_VERTMARK); if (!m.hasDataMask(MeshModel::MM_VERTCOLOR)) { m.updateDataMask(MeshModel::MM_VERTCOLOR); - tri::UpdateColor::PerVertexConstant(m.cm,Color4b(150, 150, 150, 255)); + tri::UpdateColor::PerVertexConstant(m.cm,Color4b(150, 150, 150, 255)); } tri::InitFaceIMark(m.cm); tri::InitVertexIMark(m.cm); - + parent->getCurrentRenderMode().colorMode=vcg::GLW::CMPerVert; - + QObject::connect(paintbox, SIGNAL(undo()), this, SLOT(update())); QObject::connect(paintbox, SIGNAL(redo()), this, SLOT(update())); QObject::connect(paintbox, SIGNAL(typeChange(ToolType)), this, SLOT(setToolType(ToolType))); @@ -79,25 +79,25 @@ bool EditPaintPlugin::StartEdit(MeshModel& m, GLArea * parent) selection = new vector(); latest_event.pressure = 0.0; - + setToolType(COLOR_PAINT); - + glarea = parent; buffer_width = glarea->width(); buffer_height = glarea->height(); glarea->setMouseTracking(true); connect(this, SIGNAL(setSelectionRendering(bool)),glarea,SLOT(setSelectFaceRendering(bool)) ); - + parent->setCursor(QCursor(QPixmap(":/images/cursor_paint.png"),1,1)); // initialize once and for all the radius (will remain the same all the time) current_brush.radius = (paintbox->getRadius() * m.cm.bbox.Diag() * 0.5); - return true; + return true; } -void EditPaintPlugin::EndEdit(MeshModel &/*m*/, GLArea * /*parent*/) +void EditPaintPlugin::EndEdit(MeshModel &/*m*/, GLArea * /*parent*/) { QObject::disconnect(paintbox, SIGNAL(undo()), this, SLOT(update())); QObject::disconnect(paintbox, SIGNAL(redo()), this, SLOT(update())); @@ -108,26 +108,26 @@ void EditPaintPlugin::EndEdit(MeshModel &/*m*/, GLArea * /*parent*/) delete dock; } -void EditPaintPlugin::mousePressEvent(QMouseEvent * event, MeshModel &, GLArea * gla) +void EditPaintPlugin::mousePressEvent(QMouseEvent * event, MeshModel &, GLArea * gla) { // start a new stroke: init zbuffer and update brush - if (zbuffer != NULL) delete zbuffer; zbuffer = NULL; + if (zbuffer != NULL) delete zbuffer; zbuffer = NULL; current_brush.size = paintbox->getSize(); - current_brush.opacity = paintbox->getOpacity(); - current_brush.hardness = paintbox->getHardness(); + current_brush.opacity = paintbox->getOpacity(); + current_brush.hardness = paintbox->getHardness(); - pushInputEvent(event->type(), event->pos(), event->modifiers(), 1, event->button(), gla); + pushInputEvent(event->type(), event->pos(), event->modifiers(), 1, event->button(), gla); gla->update(); } -void EditPaintPlugin::mouseMoveEvent(QMouseEvent* event, MeshModel & , GLArea * gla) +void EditPaintPlugin::mouseMoveEvent(QMouseEvent* event, MeshModel & , GLArea * gla) { pushInputEvent(event->type(), event->pos(), event->modifiers(), latest_event.pressure, latest_event.button, gla); gla->update(); } -void EditPaintPlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &, GLArea * gla) +void EditPaintPlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &, GLArea * gla) { pushInputEvent(event->type(), event->pos(), event->modifiers(), 0, event->button(), gla); gla->update(); @@ -138,32 +138,32 @@ void EditPaintPlugin::tabletEvent(QTabletEvent * event, MeshModel & , GLArea * g if(!(paintbox->getPressureFrameEnabled())) paintbox->enablePressureFrame(); - event->accept(); + event->accept(); // if event is down, start a new stroke: clean zbuff if(event->type() == QEvent::TabletPress) { - if (zbuffer != NULL) delete zbuffer; zbuffer = NULL; + if (zbuffer != NULL) delete zbuffer; zbuffer = NULL; current_brush.size = paintbox->getSize(); - current_brush.opacity = paintbox->getOpacity(); - current_brush.hardness = paintbox->getHardness(); + current_brush.opacity = paintbox->getOpacity(); + current_brush.hardness = paintbox->getHardness(); } pushInputEvent(event->type(), event->pos(), event->modifiers(), event->pressure(), (event->pointerType() == QTabletEvent::Eraser)? Qt::RightButton : Qt::LeftButton, gla); - gla->update(); -} + gla->update(); +} void EditPaintPlugin::setToolType(ToolType t) { current_type = t; - + switch(current_type) { case MESH_SELECT : current_options = EPP_PICK_FACES | EPP_DRAW_CURSOR; emit setSelectionRendering(true); break; - + case COLOR_PAINT: case COLOR_NOISE: case COLOR_CLONE: @@ -171,12 +171,12 @@ void EditPaintPlugin::setToolType(ToolType t) case MESH_SMOOTH : current_options = EPP_PICK_VERTICES | EPP_DRAW_CURSOR; break; - + case MESH_PULL: case MESH_PUSH: current_options = EPP_PICK_VERTICES | EPP_AVG_NORMAL | EPP_DRAW_CURSOR; break; - + case COLOR_FILL: case COLOR_GRADIENT: case COLOR_PICK : @@ -198,10 +198,10 @@ void EditPaintPlugin::setBrushSettings(int size, int opacity, int hardness) * method and not where mouse events are processed. * */ -void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) -{ +void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) +{ glarea = gla; - + if (!latest_event.valid || latest_event.processed) return; latest_event.processed = true; @@ -213,16 +213,16 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) glPopMatrix(); glPopAttrib(); glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix); - + viewport[0] = viewport[1] = 0; viewport[2] = gla->width(); viewport[3] = gla->height(); if (zbuffer == NULL) { zbuffer = new GLfloat[gla->width()*gla->height()]; - glReadPixels(0,0,gla->width(), gla->height(), GL_DEPTH_COMPONENT, GL_FLOAT, zbuffer); + glReadPixels(0,0,gla->width(), gla->height(), GL_DEPTH_COMPONENT, GL_FLOAT, zbuffer); } - + if (current_options & EPP_DRAW_CURSOR) { @@ -230,71 +230,71 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) if((paintbox->getPressureFrameEnabled())) { if(paintbox->getPressureSize()) - current_brush.size = paintbox->getSize() * latest_event.pressure; + current_brush.size = paintbox->getSize() * latest_event.pressure; - if(paintbox->getPressureOpacity()) - current_brush.opacity = paintbox->getOpacity() * latest_event.pressure; + if(paintbox->getPressureOpacity()) + current_brush.opacity = paintbox->getOpacity() * latest_event.pressure; - if(paintbox->getPressureHardness()) - current_brush.hardness = paintbox->getHardness() * latest_event.pressure; - } - - if (paintbox->getSizeUnit() == 0) - drawSimplePolyLine(gla, latest_event.position, paintbox->getSize(), + if(paintbox->getPressureHardness()) + current_brush.hardness = paintbox->getHardness() * latest_event.pressure; + } + + if (paintbox->getSizeUnit() == 0) + drawSimplePolyLine(gla, latest_event.position, paintbox->getSize(), (paintbox->getBrush() == CIRCLE) ? & circle : & square); else - drawPercentualPolyLine(glarea, latest_event.gl_position, m, zbuffer, modelview_matrix, projection_matrix, viewport, current_brush.radius, + drawPercentualPolyLine(glarea, latest_event.gl_position, m, zbuffer, modelview_matrix, projection_matrix, viewport, current_brush.radius, (paintbox->getBrush() == CIRCLE) ? & dense_circle : & dense_square ); } - + if (latest_event.pressure > 0) - { - if (current_options & EPP_PICK_VERTICES) - { - vertices.clear(); - updateSelection(m, & vertices); + { + if (current_options & EPP_PICK_VERTICES) + { + vertices.clear(); + updateSelection(m, & vertices); }else if (current_options & EPP_PICK_FACES) updateSelection(m); - + if (previous_event.pressure == 0) { /************************* * ON BRUSH DOWN * *************************/ - + paintbox->setUndoStack(glarea); - + switch (current_type) { case COLOR_PAINT: - { + { painted_vertices.clear(); QColor newcol; - + if(latest_event.button == Qt::LeftButton) - newcol = paintbox->getForegroundColor(); + newcol = paintbox->getForegroundColor(); else - newcol = paintbox->getBackgroundColor(); - color[0] = newcol.red(); color[1] = newcol.green(); - color[2] = newcol.blue(); color[3] = newcol.alpha(); - paintbox->getUndoStack()->beginMacro("Color Paint"); - paint(& vertices); - } - break; - + newcol = paintbox->getBackgroundColor(); + color[0] = newcol.red(); color[1] = newcol.green(); + color[2] = newcol.blue(); color[3] = newcol.alpha(); + paintbox->getUndoStack()->beginMacro("Color Paint"); + paint(& vertices); + } + break; + case COLOR_CLONE : - + //Clone Source Acquisition - if (latest_event.modifiers & Qt::ControlModifier || + if (latest_event.modifiers & Qt::ControlModifier || latest_event.button == Qt::RightButton) { if (color_buffer != NULL) delete color_buffer; if (clone_zbuffer != NULL) delete clone_zbuffer; color_buffer = NULL, clone_zbuffer = NULL; glarea->getCurrentRenderMode().lighting = false; - current_options &= ~EPP_DRAW_CURSOR; + current_options &= ~EPP_DRAW_CURSOR; glarea->update(); } - + //Clone Painting else { //There's a new image to get @@ -308,7 +308,7 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) apply_start = latest_event.position; painted_vertices.clear(); paintbox->getUndoStack()->beginMacro("Color Clone"); - + paint( & vertices); }else if (color_buffer != NULL) //There's still something in the buffer @@ -322,35 +322,35 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) } } break; - + case COLOR_NOISE : painted_vertices.clear(); noise_scale = paintbox->getNoiseSize() * 10 / m.cm.bbox.Diag(); paintbox->getUndoStack()->beginMacro("Color Noise"); break; - + case COLOR_GRADIENT: gradient_start = latest_event.position; break; - + case MESH_PULL: case MESH_PUSH : displaced_vertices.clear(); paintbox->getUndoStack()->beginMacro("Mesh Sculpting"); sculpt(m, & vertices); break; - + case COLOR_SMOOTH: paintbox->getUndoStack()->beginMacro("Color Smooth"); smoothed_vertices.clear(); - tri::UnMarkAll(m.cm); + tri::UnMarkAll(m.cm); break; case MESH_SMOOTH: paintbox->getUndoStack()->beginMacro("Mesh Smooth"); smoothed_vertices.clear(); - tri::UnMarkAll(m.cm); + tri::UnMarkAll(m.cm); break; - + default : break; } @@ -359,47 +359,47 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) /************************* * ON BRUSH MOVE * *************************/ - + switch (current_type) { - + case COLOR_CLONE : paintbox->setPixmapOffset(latest_event.position.x() - apply_start.x(), latest_event.position.y() - apply_start.y()); if (color_buffer != NULL) paint( & vertices); break; - + case COLOR_PAINT: case COLOR_NOISE : paint(& vertices); break; - + case COLOR_GRADIENT: drawLine(glarea, gradient_start, latest_event.position); break; - + case MESH_SELECT: - for(vector::iterator fpi = selection->begin(); fpi != selection->end(); ++fpi) + for(vector::iterator fpi = selection->begin(); fpi != selection->end(); ++fpi) { if (latest_event.button == Qt::LeftButton)(*fpi)->SetS(); else (*fpi)->ClearS(); } break; - + case MESH_PUSH: case MESH_PULL: sculpt(m, & vertices); break; - + case COLOR_SMOOTH: case MESH_SMOOTH: smooth(& vertices); break; - + default : break; } } - + }else { if (previous_event.pressure > 0) @@ -407,7 +407,7 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) /************************* * ON BRUSH UP * *************************/ - + switch (current_type) { case COLOR_FILL: @@ -419,18 +419,18 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) } break; - + case COLOR_PICK : { QColor color; CVertexO * temp_vert = NULL; if (paintbox->getPickMode() == 0) { - if (getVertexAtMouse(m,temp_vert, latest_event.gl_position, modelview_matrix, projection_matrix, viewport)) - { + if (getVertexAtMouse(m,temp_vert, latest_event.gl_position, modelview_matrix, projection_matrix, viewport)) + { color.setRgb(temp_vert->C()[0], temp_vert->C()[1], temp_vert->C()[2], 255); (latest_event.button == Qt::LeftButton) ? paintbox->setForegroundColor(color) : paintbox->setBackgroundColor(color); - } - } else + } + } else { GLubyte pixel[3]; glReadPixels( latest_event.gl_position.x(), latest_event.gl_position.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE,(void *)pixel); @@ -440,14 +440,14 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) paintbox->restorePreviousType(); } break; - + case COLOR_GRADIENT: gradient(m, gla); gla->update(); break; - + case COLOR_CLONE: - if (latest_event.modifiers & Qt::ControlModifier || + if (latest_event.modifiers & Qt::ControlModifier || latest_event.button == Qt::RightButton) {capture(); break;} else paintbox->movePixmapDelta(-latest_event.position.x() + apply_start.x(), -latest_event.position.y() + apply_start.y()); @@ -459,7 +459,7 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) case MESH_PULL: paintbox->getUndoStack()->endMacro(); default : - break; + break; } } } @@ -469,13 +469,13 @@ void EditPaintPlugin::Decorate(MeshModel &m, GLArea * gla) inline void EditPaintPlugin::smooth(vector< pair > * vertices) { QHash > originals; - + Color4b newcol, destCol; int opac = paintbox->getOpacity(); int decrease_pos = paintbox->getSmoothPercentual(); int c_r, c_g, c_b; float p_x, p_y, p_z; - float newpos[3]; + float newpos[3]; if(paintbox->getPressureDisplacement()) decrease_pos *= latest_event.pressure; @@ -483,12 +483,12 @@ inline void EditPaintPlugin::smooth(vector< pair > * ve for (unsigned int k = 0; k < vertices->size(); k++) //forach selected vertices { pair data = vertices->at(k); - + CVertexO * v = data.first; PickingData * vd = & data.second; pair pc_data; //save its color and position - + for (int k = 0; k < 4; k++) pc_data.second[k] = v->C()[k]; for (int k = 0; k < 3; k++) pc_data.first[k] = v->P()[k]; @@ -497,78 +497,78 @@ inline void EditPaintPlugin::smooth(vector< pair > * ve if (paintbox->getCurrentType() == COLOR_SMOOTH) paintbox->getUndoStack()->push(new SingleColorUndo(v, v->C())); else paintbox->getUndoStack()->push(new SinglePositionUndo(v, v->P(), v->N())); smoothed_vertices.insert(v,v); - } - + } + if (!originals.contains(v)) originals.insert(v, pc_data); //save original color/position data - + CFaceO * one_face = v->VFp(); //one of the faces adjacent to the vertex int pos = v->VFi(); //index of vertex v on face one_face c_r = c_g = c_b = 0; p_x = p_y = p_z = 0; int count_me = 0; CFaceO * f = one_face; - - do + + do { /// calc the sum of the surrounding vertexes pos or and vertexes color CFaceO * temp = one_face->VFp(pos); //next face in VF list - if (one_face != 0 && !one_face->IsD()) + if (one_face != 0 && !one_face->IsD()) { - for (int k = 0; k < 3; k++) + for (int k = 0; k < 3; k++) { - if (pos != k) - { + if (pos != k) + { CVertexO * v = one_face->V(k); Color4b tco = v->C(); - if (originals.contains(v)) + if (originals.contains(v)) { pair pc_data_k = originals[v]; - + tco = pc_data_k.second; - + p_x += pc_data_k.first[0]; p_y += pc_data_k.first[1]; p_z += pc_data_k.first[2]; }else if (paintbox->getCurrentType() == MESH_SMOOTH) { - p_x += v->P()[0]; p_y += v->P()[1]; p_z += v->P()[2]; + p_x += v->P()[0]; p_y += v->P()[1]; p_z += v->P()[2]; } - c_r += tco[0]; c_g += tco[1]; c_b += tco[2]; + c_r += tco[0]; c_g += tco[1]; c_b += tco[2]; } } - + pos=one_face->VFi(pos); count_me+=2; } one_face = temp; } while (one_face != f && one_face != 0); - - if (count_me > 0) /// calc the new color or pos - { + + if (count_me > 0) /// calc the new color or pos + { float op = brush(paintbox->getBrush(), vd->distance, vd->rel_position.x(), vd->rel_position.y(), decrease_pos); - + if (paintbox->getCurrentType() == COLOR_SMOOTH) - { + { newcol[0] = c_r/count_me; newcol[1] = c_g/count_me; newcol[2] = c_b/count_me; - + mergeColors((float)(op*opac)/100.0, newcol, v->C(), &destCol); - + v->C()[0] = destCol[0]; v->C()[1] = destCol[1]; v->C()[2] = destCol[2]; - } else - { + } else + { newpos[0] = p_x/(float)count_me; newpos[1] = p_y/(float)count_me; newpos[2] = p_z/(float)count_me; float po[3]; for (int lauf=0; lauf<3; lauf++) po[lauf]=v->P()[lauf]; mergePositions((float)(op*opac)/100.0,newpos,po,newpos); - + for (int lauf=0; lauf<3; lauf++) v->P()[lauf]=newpos[lauf]; } } - + if (paintbox->getCurrentType() == MESH_SMOOTH) - { + { updateNormal(v); } } @@ -582,42 +582,42 @@ inline void EditPaintPlugin::sculpt(MeshModel & m, vector< pairgetPressureDisplacement()) strength *= latest_event.pressure; - + if (latest_event.button == Qt::RightButton) strength = - strength; - + if (normal[0] == normal[1] && normal[1] == normal[2] && normal[2] == 0) { return; } - + for (unsigned int k = 0; k < vertices->size(); k++) { pair data = vertices->at(k); - + float op = brush(paintbox->getBrush(), data.second.distance, data.second.rel_position.x(), data.second.rel_position.y(), decrease_pos * 100); - + //TODO Precalculate this monster! float gauss = (strength * exp(-(op - 1.0)*(op - 1.0) * 8.0 )); - - if (!displaced_vertices.contains(data.first)) + + if (!displaced_vertices.contains(data.first)) { displaced_vertices.insert(data.first, pair( Point3f(data.first->P()[0], data.first->P()[1], data.first->P()[2]), gauss) ); paintbox->getUndoStack()->push(new SinglePositionUndo(data.first, data.first->P(), data.first->N())); - displaceAlongVector(data.first, normal, gauss); + displaceAlongVector(data.first, normal, gauss); updateNormal(data.first); - } else if ((latest_event.button == Qt::RightButton) - ? displaced_vertices[data.first].second > gauss - : displaced_vertices[data.first].second < gauss) + } else if ((latest_event.button == Qt::RightButton) + ? displaced_vertices[data.first].second > gauss + : displaced_vertices[data.first].second < gauss) { displaced_vertices[data.first].second = gauss; Point3f temp = displaced_vertices[data.first].first; data.first->P()[0]=temp[0]; data.first->P()[1]=temp[1]; data.first->P()[2]=temp[2]; - displaceAlongVector(data.first, normal, gauss); + displaceAlongVector(data.first, normal, gauss); updateNormal(data.first); - + } delete zbuffer; zbuffer = NULL; @@ -632,10 +632,10 @@ inline void EditPaintPlugin::capture() glReadPixels(0,0,glarea->width(), glarea->height(), GL_DEPTH_COMPONENT, GL_FLOAT, clone_zbuffer); buffer_height = glarea->height(); buffer_width = glarea->width(); - + source_delta = latest_event.position; - - QImage image(glarea->width(), glarea->height(), QImage::Format_ARGB32); + + QImage image(glarea->width(), glarea->height(), QImage::Format_ARGB32); for (int x = 0; x < glarea->width(); x++){ for (int y = 0; y < glarea->height(); y++){ int index = (y * glarea->width() + x)*4; @@ -646,7 +646,7 @@ inline void EditPaintPlugin::capture() current_options |= EPP_DRAW_CURSOR; paintbox->setClonePixmap(image); paintbox->setPixmapDelta(source_delta.x(), source_delta.y()); - + // paintbox->setPixmapCenter(-source_delta.x(), -source_delta.y()); glarea->update(); } @@ -655,9 +655,9 @@ inline bool EditPaintPlugin::accessCloneBuffer(int vertex_x, int vertex_y, vcg:: { int y = buffer_height - source_delta.y() + (vertex_y + apply_start.y() - glarea->height()); int x = source_delta.x() + (vertex_x - apply_start.x()); - + int index = y * buffer_width + x; - + if (x < buffer_width && y < buffer_height && x >= 0 && y >= 0) { if (clone_zbuffer[index] < 1.0) @@ -681,40 +681,40 @@ inline void EditPaintPlugin::paint(vector< pair > * ver for (unsigned int k = 0; k < vertices->size(); k++) { pair data = vertices->at(k); - + float op = brush(paintbox->getBrush(), data.second.distance, data.second.rel_position.x(), data.second.rel_position.y(), decrease_pos); - - if (!painted_vertices.contains(data.first)) + + if (!painted_vertices.contains(data.first)) { - if (paintbox->getCurrentType() == COLOR_CLONE) + if (paintbox->getCurrentType() == COLOR_CLONE) if (!accessCloneBuffer(data.second.position.x(), data.second.position.y(), color)) return; - + if (paintbox->getCurrentType() == COLOR_NOISE) computeNoiseColor(data.first, color); - + painted_vertices.insert(data.first, pair( Color4b(data.first->C()[0], data.first->C()[1], data.first->C()[2], data.first->C()[3]), (int)(op*opac)) ); - + paintbox->getUndoStack()->push(new SingleColorUndo(data.first, data.first->C())); - + applyColor(data.first, color, (int)(op * opac )); - - } else if (painted_vertices[data.first].second < (int)(op * opac)) + + } else if (painted_vertices[data.first].second < (int)(op * opac)) { painted_vertices[data.first].second = (int)(op * opac); Color4b temp = painted_vertices[data.first].first; data.first->C()[0]=temp[0]; data.first->C()[1]=temp[1]; data.first->C()[2]=temp[2]; - - if (paintbox->getCurrentType() == COLOR_CLONE) + + if (paintbox->getCurrentType() == COLOR_CLONE) if (!accessCloneBuffer(data.second.position.x(), data.second.position.y(), color)) return; - + if (paintbox->getCurrentType() == COLOR_NOISE) computeNoiseColor(data.first, color); paintbox->getUndoStack()->push(new SingleColorUndo(data.first, data.first->C())); - - applyColor(data.first, color, (int)(op * opac) ); + + applyColor(data.first, color, (int)(op * opac) ); } } } @@ -722,7 +722,7 @@ inline void EditPaintPlugin::paint(vector< pair > * ver inline void EditPaintPlugin::computeNoiseColor(CVertexO * vert, vcg::Color4b & col) { float scaler = noise_scale; //parameter TODO to be cahced - + double noise; //if "veins on" // noise = vcg::math::Abs(vcg::math::Perlin::Noise(vert->P()[0] * scaler, vert->P()[1] * scaler, vert->P()[2] * scaler)); @@ -731,25 +731,25 @@ inline void EditPaintPlugin::computeNoiseColor(CVertexO * vert, vcg::Color4b & c Color4b forecolor(paintbox->getForegroundColor().red(), paintbox->getForegroundColor().green(), paintbox->getForegroundColor().blue(), paintbox->getForegroundColor().alpha()); - //TODO test code to be refactored + //TODO test code to be refactored if (paintbox->getGradientType() == 0) { Color4b backcolor(paintbox->getBackgroundColor().red(), paintbox->getBackgroundColor().green(), paintbox->getBackgroundColor().blue(), paintbox->getBackgroundColor().alpha()); for (int i = 0; i < 4; i ++) col[i] = forecolor[i] * noise + backcolor[i] * (1.0 - noise); - }else + }else { for (int i = 0; i < 4; i ++) col[i] = forecolor[i] * noise + vert->C()[i] * (1.0 - noise); } } -/** +/** * fills the mesh starting from face. - * If face is selected, it will fill only the selected area, - * otherwise only the non selected area + * If face is selected, it will fill only the selected area, + * otherwise only the non selected area */ -inline void EditPaintPlugin::fill(MeshModel & ,CFaceO * face) +inline void EditPaintPlugin::fill(MeshModel & ,CFaceO * face) { QHash visited; QHash temp; @@ -763,14 +763,14 @@ inline void EditPaintPlugin::fill(MeshModel & ,CFaceO * face) Color4b color(newcol.red(), newcol.green(), newcol.blue(), newcol.alpha()); paintbox->getUndoStack()->beginMacro("Fill Color"); - + for (unsigned int lauf2 = 0; lauf2 < temp_po.size(); lauf2++) { CFaceO * fac=temp_po.at(lauf2); if (who == fac->IsS()) { for (int lauf=0; lauf<3; lauf++) { if (!temp.contains(fac->V(lauf))) { temp.insert(fac->V(lauf),fac->V(lauf)); - + paintbox->getUndoStack()->push(new SingleColorUndo(fac->V(lauf), fac->V(lauf)->C())); applyColor(fac->V(lauf), color , opac); @@ -784,16 +784,16 @@ inline void EditPaintPlugin::fill(MeshModel & ,CFaceO * face) if (!visited.contains(surround[lauf3])) { temp_po.push_back(surround[lauf3]); visited.insert(surround[lauf3],surround[lauf3]); - } + } } } } - + paintbox->getUndoStack()->endMacro(); } inline void EditPaintPlugin::gradient(MeshModel & m,GLArea * gla) { - + QPoint p = gradient_start - latest_event.position; QHash temp; @@ -804,13 +804,13 @@ inline void EditPaintPlugin::gradient(MeshModel & m,GLArea * gla) { Color4b c1(qc1.red(), qc1.green(), qc1.blue(), qc1.alpha()); Color4b c2(qc2.red(), qc2.green(), qc2.blue(), qc2.alpha()); - + QPointF p1(gradient_start.x(),gla->height() - gradient_start.y()); QPointF p0(latest_event.gl_position); - + float x2=(p1.x()-p0.x()); float y2=(p1.y()-p0.y()); - + float l_square=x2*x2+y2*y2; CVertexO * vertex; @@ -819,33 +819,33 @@ inline void EditPaintPlugin::gradient(MeshModel & m,GLArea * gla) { Color4b merger; bool tutti = !hasSelected(m); float radius=sqrt((float)(p.x()*p.x()+p.y()*p.y())); - + paintbox->getUndoStack()->beginMacro("Gradient"); - + int gradient_type=paintbox->getGradientType(); int gradient_form=paintbox->getGradientForm(); - for(fi=m.cm.face.begin();fi!=m.cm.face.end();++fi) + for(fi=m.cm.face.begin();fi!=m.cm.face.end();++fi) if (!(*fi).IsD() && (tutti || (*fi).IsS())) for (int lauf=0; lauf<3; lauf++) { if (!temp.contains((*fi).V(lauf))) { vertex=(*fi).V(lauf); temp.insert(vertex,vertex); gluProject(vertex->P()[0],vertex->P()[1],vertex->P()[2],modelview_matrix, projection_matrix, viewport,&dx,&dy,&dz); - + paintbox->getUndoStack()->push(new SingleColorUndo(vertex, vertex->C())); - + if (gradient_form==0) { double r=(dx-p0.x())*(p1.x()-p0.x())+(dy-p0.y())*(p1.y()-p0.y()); r=r/l_square; - + float px=p0.x()+r*(p1.x()-p0.x()); float py=p0.y()+r*(p1.y()-p0.y()); - + px=px-dx; py=py-dy; - + if (gradient_type==0) { - if (r>=0 && r<=1) { + if (r>=0 && r<=1) { mergeColors(r,c1,c2,&merger); applyColor(vertex,merger,opac); } else if (r>1) { @@ -854,7 +854,7 @@ inline void EditPaintPlugin::gradient(MeshModel & m,GLArea * gla) { applyColor(vertex,c2,opac); } } else { - if (r>=0 && r<=1) { + if (r>=0 && r<=1) { applyColor(vertex,c1,(int)((opac * 0.01) * r * 100.0)); } else if (r>1) { applyColor(vertex,c1,opac); @@ -883,40 +883,40 @@ inline void EditPaintPlugin::gradient(MeshModel & m,GLArea * gla) { /** * Updates currently selected faces by using one of the * two methods. Just a new version of computeBrushedFaces - * + * * It's inlined because it's only called once, inside Decorate. * Should it be called in other places, the inlining must be removed! - */ + */ inline void EditPaintPlugin::updateSelection(MeshModel &m, vector< pair > * vertex_result) { vector::iterator fpi; vector temp; //TODO maybe temp can be placed inside the class for better performance - + vector surround; /*< surrounding faces of a given face*/ surround.reserve(6); - + if (current_options & EPP_AVG_NORMAL ) normal = Point3f(0.0, 0.0, 0.0); - + tri::UnMarkAll(m.cm); - + if (selection->size() == 0) { CMeshO::FaceIterator fi; temp.reserve(m.cm.fn); //avoid unnecessary expansions - for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi){ - if(!(*fi).IsD()) { - temp.push_back((&*fi)); - } - } - } else + for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi){ + if(!(*fi).IsD()) { + temp.push_back((&*fi)); + } + } + } else { temp.reserve(selection->size()); //avoid unnecessary expansions vertex_result->reserve(selection->size()); - for(fpi = selection->begin();fpi != selection->end(); ++fpi) + for(fpi = selection->begin();fpi != selection->end(); ++fpi) { temp.push_back(*fpi); } } - + selection->clear(); QPointF gl_cursorf = QPointF(latest_event.gl_position); @@ -928,53 +928,53 @@ inline void EditPaintPlugin::updateSelection(MeshModel &m, vector< pairgetPaintBackFace(); bool invisible = paintbox->getPaintInvisible(); bool percentual = paintbox->getSizeUnit() == 1; - + double EPSILON = 0.003; - + double scale_fac = 1.0; float fov = 1.0; double distance[3]; - + if (percentual) { double dX, dY, dZ; fastMultiply(0,0,0,modelview_matrix,&dX,&dY,&dZ); fastMultiply(0,1,0,modelview_matrix,&tx,&ty,&tz); - + scale_fac=sqrt((ty-dY)*(ty-dY)+(tx-dX)*(tx-dX)+(tz-dZ)*(tz-dZ)); /** to get the correct radius depending on distance but on fov too */ float fo = glarea->getFov()*0.5; fov = 1.0/tan(fo*M_PI/180.0)*0.5; } - - for (unsigned int k = 0; k < temp.size(); k++) //for each face + + for (unsigned int k = 0; k < temp.size(); k++) //for each face { CFaceO * fac = temp.at(k); bool intern = false; int checkable = 0; /*< counts how many valid vertices there are in this face*/ - + for (int i = 0; i < 3; i++) //for each vertex defining the face - { + { if (gluProject((fac)->V(i)->P()[0], (fac)->V(i)->P()[1], (fac)->V(i)->P()[2], modelview_matrix, projection_matrix, viewport, &tx, &ty, &tz) == GL_TRUE) checkable++; //if gluProjection works - + if (tz < 0 || tz > 1) checkable--; //but if outside depth bounds - + p[i].setX(tx); p[i].setY(ty); //store the position of the vertex on the screen - + //if the vertex is projected within the screen (i.e. it's visible) if (tx>=0 && tx=0 && tyV(i)->P()[0],(fac)->V(i)->P()[1],(fac)->V(i)->P()[2], modelview_matrix, &dx, &dy, &dz); @@ -987,74 +987,74 @@ inline void EditPaintPlugin::updateSelection(MeshModel &m, vector< pairV(j))) + else if (!tri::IsMarked(m.cm,fac->V(j))) { vd.position.setX((int)p[j].x()); vd.position.setY((int)p[j].y()); pair data(fac->V(j), vd); vertex_result->push_back(data); - + if (current_options & EPP_AVG_NORMAL ) normal += fac->V(j)->N(); - - tri::Mark(m.cm,fac->V(j)); + + tri::Mark(m.cm,fac->V(j)); } } - - if (vertex_result == NULL && !intern && lineHitsCircle(p[j],p[(j+1)%3], gl_cursorf, radius)) + + if (vertex_result == NULL && !intern && lineHitsCircle(p[j],p[(j+1)%3], gl_cursorf, radius)) { - intern = true; + intern = true; continue; } } - - if (checkable==3 && !intern && (pointInTriangle(gl_cursorf,p[0],p[1],p[2]) || pointInTriangle(gl_prev_cursorf,p[0],p[1],p[2]))) + + if (checkable==3 && !intern && (pointInTriangle(gl_cursorf,p[0],p[1],p[2]) || pointInTriangle(gl_prev_cursorf,p[0],p[1],p[2]))) { intern = true; - } + } } - - if (intern && !tri::IsMarked(m.cm,fac)) + + if (intern && !tri::IsMarked(m.cm,fac)) { - tri::Mark(m.cm,fac); + tri::Mark(m.cm,fac); selection->push_back(fac); surround.clear(); for (int lauf=0; lauf<3; lauf++) getSurroundingFacesVF(fac,lauf,&surround); for (unsigned int lauf3=0; lauf3size(); } /** * Request an async repainting of the glarea - * + * * This slot is connected to undo and redo */ void EditPaintPlugin::update() { - glarea->update(); + glarea->update(); } /*********OpenGL Drawing Routines************/ -/** - * draws the xor-line +/** + * draws the xor-line */ void drawLine(GLArea * gla, QPoint & start, QPoint & cur) { glMatrixMode(GL_PROJECTION); @@ -1102,14 +1102,14 @@ void drawSimplePolyLine(GLArea * gla, QPoint & cur, float scale, vector glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); glColor3f(1,1,1); - + glBegin(GL_LINE_LOOP); - + for (unsigned int k = 0; k < points->size(); k++) { glVertex2f(cur.x() + ( points->at(k).x() * scale ), cur.y() + ( points->at(k).y() * scale )); } - + glEnd(); glDisable(GL_LOGIC_OP); @@ -1125,51 +1125,51 @@ void drawPercentualPolyLine(GLArea * gla, QPoint &mid, MeshModel &m, GLfloat* pi { double dX, dY, dZ; //near double dX2, dY2, dZ2; //far - + gluUnProject ((double) mid.x(), mid.y(), 0.0, modelview_matrix, projection_matrix, viewport, &dX, &dY, &dZ); gluUnProject ((double) mid.x(), mid.y(), 1.0, modelview_matrix, projection_matrix, viewport, &dX2, &dY2, &dZ2); glPushMatrix(); glLoadIdentity(); gluLookAt(dX,dY,dZ, dX2,dY2,dZ2, 1,0,0); - + double mvmatrix2[16]; glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix2); glPopMatrix(); - + double tx,ty,tz; double tx2,ty2,tz2; - + double inv_mvmatrix[16]; - + Matrix44d temp(mvmatrix2); - Invert(temp); - - for (int k=0; k<16; k++) + temp=Inverse(temp); + + for (int k=0; k<16; k++) inv_mvmatrix[k]=temp[k/4][k%4]; - + double a,b,c; double a2,b2,c2; int STEPS = 30; int DSCALER = -7; - + float diag = m.cm.bbox.Diag() * DSCALER; float radius = scale; //TODO leftover - + QVector proj_points(points->size()); - + for (unsigned int i = 0; i < points->size(); i++) { /** calcs the far point of the line */ fastMultiply(points->at(i).x() * radius, points->at(i).y() * radius, diag, inv_mvmatrix, &tx, &ty, &tz); - + gluProject(tx,ty,tz,modelview_matrix, projection_matrix, viewport, &a,&b,&c); - + /** calcs the near point of the line */ fastMultiply(points->at(i).x() * radius, points->at(i).y() * radius, 0, inv_mvmatrix, &tx2, &ty2, &tz2); - + gluProject(tx2,ty2,tz2,modelview_matrix, projection_matrix, viewport, &a2,&b2,&c2); double da=(a-a2);// /(double)STEPS; double db=(b-b2);// /(double)STEPS; @@ -1177,23 +1177,23 @@ void drawPercentualPolyLine(GLArea * gla, QPoint &mid, MeshModel &m, GLfloat* pi double pix_x=a2; double pix_y=b2; double pix_z=c2; - + /** to search with quicksearch the nearset zbuffer value in the line */ for (int k = 0; k < STEPS; k++) { double inv_yy = gla->height()-pix_y; double zz=999; - - if ((int)pix_x>=0 && (int)pix_xwidth() && (int)pix_y>=0 && (int)pix_yheight()) + + if ((int)pix_x>=0 && (int)pix_xwidth() && (int)pix_y>=0 && (int)pix_yheight()) zz=(GLfloat)pixels[(int)(((int)pix_y)*gla->width()+(int)pix_x)]; da=da/2.0; db=db/2.0; dc=dc/2.0; - if (fabsf(zz-pix_z)<0.001) + if (fabsf(zz-pix_z)<0.001) { proj_points[i] = QPointF(pix_x, inv_yy); break; - } else if (zz>pix_z) + } else if (zz>pix_z) { pix_x+=da; pix_y+=db; @@ -1204,15 +1204,15 @@ void drawPercentualPolyLine(GLArea * gla, QPoint &mid, MeshModel &m, GLfloat* pi pix_y-=db; pix_z-=dc; } - - if (k == STEPS-1) - { + + if (k == STEPS-1) + { proj_points[i] = QPointF(pix_x,inv_yy); - break; + break; } } } - + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); @@ -1227,17 +1227,17 @@ void drawPercentualPolyLine(GLArea * gla, QPoint &mid, MeshModel &m, GLfloat* pi glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); glColor3f(1,1,1); - + /** draws the circle */ glBegin(GL_LINE_LOOP); - + for (unsigned int i = 0; i < points->size(); i++) { glVertex2f(proj_points[i].x(), proj_points[i].y()); } - + glEnd(); - + glDisable(GL_COLOR_LOGIC_OP); glPopAttrib(); glPopMatrix(); // restore modelview @@ -1249,16 +1249,16 @@ void drawPercentualPolyLine(GLArea * gla, QPoint &mid, MeshModel &m, GLfloat* pi //each side is divided in given segments void generatePolygon(std::vector & vertices, int sides, int segments) -{ +{ float step = sides / 2.0; - + float start_angle = M_PI / sides; - + for (int k = 0; k < sides; k++) { vertices.push_back(QPointF(sin((M_PI * (float)k / step) + start_angle), cos((M_PI * (float)k / step) + start_angle))); } - + if (segments > 1) { int sk; @@ -1282,14 +1282,14 @@ void generatePolygon(std::vector & vertices, int sides, int segments) /** * Generates the same circle points that Gfrei's algorithm does - */ + */ void generateCircle(std::vector & vertices, int segments) { - return generatePolygon(vertices, segments, 1); + return generatePolygon(vertices, segments, 1); } void generateSquare(std::vector & vertices, int segments) { - return generatePolygon(vertices, 4, segments); + return generatePolygon(vertices, 4, segments); } diff --git a/src/meshlabplugins/edit_texture/edittexture.cpp b/src/meshlabplugins/edit_texture/edittexture.cpp index 97490d68f..6f729aa7d 100644 --- a/src/meshlabplugins/edit_texture/edittexture.cpp +++ b/src/meshlabplugins/edit_texture/edittexture.cpp @@ -32,7 +32,7 @@ using namespace vcg; -EditTexturePlugin::EditTexturePlugin() +EditTexturePlugin::EditTexturePlugin() { isDragging = false; widget = 0; @@ -40,17 +40,17 @@ EditTexturePlugin::EditTexturePlugin() qFont.setPixelSize(14); } -EditTexturePlugin::~EditTexturePlugin() +EditTexturePlugin::~EditTexturePlugin() { // Delete the tool widget - if (widget != 0) + if (widget != 0) { delete widget; widget = 0; } } -const QString EditTexturePlugin::Info() +const QString EditTexturePlugin::Info() { return tr("Edit texture coordinates of the selected area"); } @@ -59,87 +59,87 @@ void EditTexturePlugin::mousePressEvent(QMouseEvent * event, MeshModel &m, GLAre { isDragging = true; - if(event->modifiers() == Qt::ControlModifier) selMode = SMAdd; + if(event->modifiers() == Qt::ControlModifier) selMode = SMAdd; else if(event->modifiers() == Qt::ShiftModifier) selMode = SMSub; - else selMode = SMClear; - // Change the appearance of the cursor - switch(selMode) - { - case SMAdd: // CTRL + Mouse - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"),1,1)); - break; - case SMSub: // SHIFT + Mouse - gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"),1,1)); - break; - case SMClear: // Mouse - gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"),1,1)); - for (unsigned i = 0; i < FaceSel.size(); i++) FaceSel[i]->ClearS(); - FaceSel.clear(); - break; - } + else selMode = SMClear; + // Change the appearance of the cursor + switch(selMode) + { + case SMAdd: // CTRL + Mouse + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_plus.png"),1,1)); + break; + case SMSub: // SHIFT + Mouse + gla->setCursor(QCursor(QPixmap(":/images/sel_rect_minus.png"),1,1)); + break; + case SMClear: // Mouse + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"),1,1)); + for (unsigned i = 0; i < FaceSel.size(); i++) FaceSel[i]->ClearS(); + FaceSel.clear(); + break; + } if(event->modifiers() == Qt::ControlModifier || event->modifiers() == Qt::ShiftModifier ) - { - CMeshO::FaceIterator fi; - for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) - if(!(*fi).IsD() && (*fi).IsS()) FaceSel.push_back(&*fi); - } + { + CMeshO::FaceIterator fi; + for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) + if(!(*fi).IsD() && (*fi).IsS()) FaceSel.push_back(&*fi); + } - start = event->pos(); + start = event->pos(); cur = start; - gla->update(); - return; + gla->update(); + return; } - + void EditTexturePlugin::mouseMoveEvent(QMouseEvent * event, MeshModel &/*m*/, GLArea * gla) { prev = cur; cur = event->pos(); - /*int curT; - static int lastRendering; - if (isDragging) - { - // The user is selecting an area: management of the update - lastRendering = clock(); - curT = clock(); - if(gla->lastRenderingTime() < 50 || (curT - lastRendering) > 1000 ) - { - lastRendering = curT; - gla->update(); - } - else - { - gla->makeCurrent(); - glDrawBuffer(GL_FRONT); - DrawXORRect(gla); - glDrawBuffer(GL_BACK); - glFlush(); - } - }*/ - if(gla->lastRenderingTime() < 200 ) + /*int curT; + static int lastRendering; + if (isDragging) { - gla->update(); + // The user is selecting an area: management of the update + lastRendering = clock(); + curT = clock(); + if(gla->lastRenderingTime() < 50 || (curT - lastRendering) > 1000 ) + { + lastRendering = curT; + gla->update(); + } + else + { + gla->makeCurrent(); + glDrawBuffer(GL_FRONT); + DrawXORRect(gla); + glDrawBuffer(GL_BACK); + glFlush(); + } + }*/ + if(gla->lastRenderingTime() < 200 ) + { + gla->update(); } else - { - gla->makeCurrent(); - glDrawBuffer(GL_FRONT); - DrawXORRect(gla); - glDrawBuffer(GL_BACK); - glFlush(); + { + gla->makeCurrent(); + glDrawBuffer(GL_FRONT); + DrawXORRect(gla); + glDrawBuffer(GL_BACK); + glFlush(); } } - + void EditTexturePlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &/*m*/, GLArea * gla) { prev = cur; cur = event->pos(); - gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"),1,1)); - if (isDragging) - { - widget->SelectFromModel(); - isDragging = false; - } - gla->update(); + gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"),1,1)); + if (isDragging) + { + widget->SelectFromModel(); + isDragging = false; + } + gla->update(); } void EditTexturePlugin::Decorate(MeshModel &m, GLArea *gla) @@ -153,12 +153,12 @@ void EditTexturePlugin::Decorate(MeshModel &m, GLArea *gla) DrawXORRect(gla); mid = (start + cur)/2; - mid.setY(gla->height() - mid.y()); + mid.setY(gla->height() - mid.y()); wid = (start - cur); - if(wid.x()<0) wid.setX(-wid.x()); + if(wid.x()<0) wid.setX(-wid.x()); if(wid.y()<0) wid.setY(-wid.y()); - for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) + for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) if(!(*fi).IsD()) (*fi).ClearS(); glPushMatrix(); @@ -190,7 +190,7 @@ bool EditTexturePlugin::StartEdit(MeshModel &m, GLArea *gla ) // Set up the model //m.cm.face.EnableFFAdjacency(); m.updateDataMask(MeshModel::MM_FACEFACETOPO); - + if (m.cm.textures.size() == 0) { QMessageBox::warning(gla->window(), "Texture Parametrization Tool", @@ -199,13 +199,13 @@ bool EditTexturePlugin::StartEdit(MeshModel &m, GLArea *gla ) return false; } - if (vcg::tri::HasPerWedgeTexCoord(m.cm)) + if (vcg::tri::HasPerWedgeTexCoord(m.cm)) { vcg::tri::UpdateTopology::FaceFaceFromTexCoord(m.cm); if(vcg::tri::Clean::HasConsistentPerWedgeTexCoord(m.cm) && !HasCollapsedTextCoords(m)) degenerate = false; - else + else { - gla->log->Logf(GLLogStream::WARNING,"This mesh has a degenerated texture parametrization!"); + this->Log(GLLogStream::WARNING,"This mesh has a degenerated texture parametrization!"); degenerate = true; } } @@ -219,23 +219,23 @@ bool EditTexturePlugin::StartEdit(MeshModel &m, GLArea *gla ) for(fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) (*fi).ClearS(); gla->setCursor(QCursor(QPixmap(":/images/sel_rect.png"),1,1)); - + connect(this, SIGNAL(setSelectionRendering(bool)),gla,SLOT(setSelectionRendering(bool))); setSelectionRendering(true); // Create an istance of the interface - if (widget == 0) - { + if (widget == 0) + { widget = new TextureEditor(gla->window(), &m, gla, degenerate); dock = new QDockWidget(gla->window()); dock->setAllowedAreas(Qt::NoDockWidgetArea); dock->setWidget(widget); QPoint p = gla->window()->mapToGlobal(QPoint(0,0)); dock->setGeometry(-5+p.x()+gla->window()->width()-widget->width(),p.y(),widget->width(),widget->height()); - dock->setFloating(true); + dock->setFloating(true); } dock->setVisible(true); - dock->layout()->update(); + dock->layout()->update(); // Initialize the texture using the intere model InitTexture(m); @@ -248,29 +248,29 @@ void EditTexturePlugin::EndEdit(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; - delete dock; + if (widget != 0) + { + delete widget; + delete dock; widget = 0; dock = 0; } } void EditTexturePlugin::DrawXORRect(GLArea *gla) -{ - // Draw the rectangle of the selection area +{ + // Draw the rectangle of the selection area glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, gla->width(), gla->height(),0,-1,1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, gla->width(), gla->height(),0,-1,1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); glColor3f(1,1,1); @@ -283,11 +283,11 @@ void EditTexturePlugin::DrawXORRect(GLArea *gla) glEnd(); glDisable(GL_LOGIC_OP); - glPopAttrib(); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); + glPopAttrib(); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); } void EditTexturePlugin::InitTexture(MeshModel &m) @@ -311,9 +311,9 @@ bool EditTexturePlugin::HasCollapsedTextCoords(MeshModel &m) if(!HasPerWedgeTexCoord(m.cm)) return true; for (CMeshO::FaceIterator fi = m.cm.face.begin(); fi != m.cm.face.end(); ++fi) { - if(!(*fi).IsD()) + if(!(*fi).IsD()) { - if( (*fi).WT(0).P() == (*fi).WT(1).P() || (*fi).WT(0).P() == (*fi).WT(2).P() || (*fi).WT(1).P() == (*fi).WT(2).P()) + if( (*fi).WT(0).P() == (*fi).WT(1).P() || (*fi).WT(0).P() == (*fi).WT(2).P() || (*fi).WT(1).P() == (*fi).WT(2).P()) return true; } } diff --git a/src/meshlabplugins/edit_texture/renderarea.cpp b/src/meshlabplugins/edit_texture/renderarea.cpp index 808050b80..a2a422ada 100644 --- a/src/meshlabplugins/edit_texture/renderarea.cpp +++ b/src/meshlabplugins/edit_texture/renderarea.cpp @@ -38,29 +38,29 @@ RenderArea::RenderArea(QWidget *parent, QString textureName, MeshModel *m, unsigned tnum) : QGLWidget(parent) { - // Parameters + // Parameters antialiased = true; setBackgroundRole(QPalette::Base); setAutoFillBackground(true); - textNum = tnum; - model = m; - image = QImage(); - fileName = textureName; - if(textureName != QString()) - { - if (QFile(textureName).exists()) - { - image = QImage(textureName); - int bestW = pow(2.0,floor(::log(double(image.width()))/::log(2.0))); - int bestH = pow(2.0,floor(::log(double(image.height()))/::log(2.0))); - QImage imgGL = image.scaled(bestW,bestH,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); - QImage tmpGL = QGLWidget::convertToGLFormat(imgGL); - glGenTextures(1, &id); - image = QImage(tmpGL).mirrored(false, true); - } - else textureName = QString(); - } - + textNum = tnum; + model = m; + image = QImage(); + fileName = textureName; + if(textureName != QString()) + { + if (QFile(textureName).exists()) + { + image = QImage(textureName); + int bestW = pow(2.0,floor(::log(double(image.width()))/::log(2.0))); + int bestH = pow(2.0,floor(::log(double(image.height()))/::log(2.0))); + QImage imgGL = image.scaled(bestW,bestH,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); + QImage tmpGL = QGLWidget::convertToGLFormat(imgGL); + glGenTextures(1, &id); + image = QImage(tmpGL).mirrored(false, true); + } + else textureName = QString(); + } + // Initialization oldX = 0; oldY = 0; viewport = vcg::Point2f(0,0); @@ -169,19 +169,19 @@ void RenderArea::SetDegenerate(bool deg) void RenderArea::paintEvent(QPaintEvent *) { - // Init + // Init QPainter painter(this); painter.setPen(QPen(brush,2)); painter.setBrush(brush); painter.setRenderHint(QPainter::Antialiasing, antialiased); - painter.setRenderHint(QPainter::SmoothPixmapTransform, true); - tb->GetView(); - tb->Apply(true); - maxX = 0; maxY = 0; minX = 0; minY = 0; - + painter.setRenderHint(QPainter::SmoothPixmapTransform, true); + tb->GetView(); + tb->Apply(); + maxX = 0; maxY = 0; minX = 0; minY = 0; + if (model != NULL && HasPerWedgeTexCoord(model->cm) && image != QImage()) { - glEnable(GL_COLOR_LOGIC_OP); + glEnable(GL_COLOR_LOGIC_OP); glEnable(GL_DEPTH_TEST); glLineWidth(1); for (unsigned i = 0; i < model->cm.face.size(); i++) @@ -207,7 +207,7 @@ void RenderArea::paintEvent(QPaintEvent *) } } if (mode == UnifyVert) drawUnifyVertexes(); - + glDisable(GL_LOGIC_OP); glDisable(GL_COLOR_LOGIC_OP); if (minX != 0 || minY != 0 || maxX != 0 || maxY != 0) drawBackground(); // Draw the background behind the model @@ -229,16 +229,16 @@ void RenderArea::paintEvent(QPaintEvent *) if (mode != UnifyVert) drawEditRectangle(&painter); else drawUnifyRectangles(&painter); // Draw the rectangles for unify glDisable(GL_LOGIC_OP); - glPopAttrib(); + glPopAttrib(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); - + // Draw blend object glDepthMask(GL_FALSE); glLogicOp(GL_AND); - glEnable(GL_BLEND); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 0.0f, 0.0f, 0.7f); for (unsigned i = 0; i < model->cm.face.size(); i++) @@ -260,7 +260,7 @@ void RenderArea::drawSelectedVertexes(int i) if (!isInside(&model->cm.face[i])) { for (int 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)) DrawCircle(QPoint((origin.x() + (cos(degree) * (model->cm.face[i].WT(j).u() - origin.x()) - sin(degree) * (model->cm.face[i].WT(j).v() - origin.y()))) * AREADIM - posVX/zoom, (AREADIM - ((origin.y() + (sin(degree) * (model->cm.face[i].WT(j).u() - origin.x()) + cos(degree) * (model->cm.face[i].WT(j).v() - origin.y())))) * AREADIM) - posVY/zoom)); @@ -276,8 +276,8 @@ void RenderArea::drawSelectedFaces(int i) for (int j = 0; j < 3; j++) { if (editMode == Scale) - glVertex3f((oScale.x() + (model->cm.face[i].WT(j).u() - oScale.x()) * scaleX) * AREADIM - panX/zoom, - AREADIM - ((oScale.y() + (model->cm.face[i].WT(j).v() - oScale.y()) * scaleY) * AREADIM) - panY/zoom, 1); + glVertex3f((oScale.x() + (model->cm.face[i].WT(j).u() - oScale.x()) * scaleX) * AREADIM - panX/zoom, + AREADIM - ((oScale.y() + (model->cm.face[i].WT(j).v() - oScale.y()) * scaleY) * AREADIM) - panY/zoom, 1); else glVertex3f((origin.x() + (cos(degree) * (model->cm.face[i].WT(j).u() - origin.x()) - sin(degree) * (model->cm.face[i].WT(j).v() - origin.y()))) * AREADIM - panX/zoom, AREADIM - ((origin.y() + (sin(degree) * (model->cm.face[i].WT(j).u() - origin.x()) + cos(degree) * (model->cm.face[i].WT(j).v() - origin.y()))) * AREADIM) - panY/zoom, 1); } @@ -292,9 +292,9 @@ void RenderArea::drawEdge(int i) if (mode != EditVert) { if (!model->cm.face[i].IsUserBit(selBit)) - glVertex3f(model->cm.face[i].WT(j).u() * AREADIM , AREADIM - (model->cm.face[i].WT(j).v() * AREADIM), 1); - else if (editMode == Scale) glVertex3f((oScale.x() + (model->cm.face[i].WT(j).u() - oScale.x()) * scaleX) * AREADIM - panX/zoom, - AREADIM - ((oScale.y() + (model->cm.face[i].WT(j).v() - oScale.y()) * scaleY) * AREADIM) - panY/zoom, 1); + glVertex3f(model->cm.face[i].WT(j).u() * AREADIM , AREADIM - (model->cm.face[i].WT(j).v() * AREADIM), 1); + else if (editMode == Scale) glVertex3f((oScale.x() + (model->cm.face[i].WT(j).u() - oScale.x()) * scaleX) * AREADIM - panX/zoom, + AREADIM - ((oScale.y() + (model->cm.face[i].WT(j).v() - oScale.y()) * scaleY) * AREADIM) - panY/zoom, 1); else glVertex3f((origin.x() + (cos(degree) * (model->cm.face[i].WT(j).u() - origin.x()) - sin(degree) * (model->cm.face[i].WT(j).v() - origin.y()))) * AREADIM - panX/zoom, AREADIM - ((origin.y() + (sin(degree) * (model->cm.face[i].WT(j).u() - origin.x()) + cos(degree) * (model->cm.face[i].WT(j).v() - origin.y()))) * AREADIM) - panY/zoom, 1); } @@ -332,21 +332,21 @@ void RenderArea::drawBackground() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image.width(), image.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); for (int x = minX; x < maxX; x++) { - for (int y = minY; y < maxY; y++) + for (int y = minY; y < maxY; y++) { - glBegin(GL_QUADS); - glTexCoord2f(0.0,0.0); + glBegin(GL_QUADS); + glTexCoord2f(0.0,0.0); glVertex3f(0.0 + x*AREADIM,0.0 - y*AREADIM,0.0); - glTexCoord2f(1.0,0.0); + glTexCoord2f(1.0,0.0); glVertex3f(1.0*AREADIM + x*AREADIM,0.0 - y*AREADIM,0.0); - glTexCoord2f(1.0,1.0); + glTexCoord2f(1.0,1.0); glVertex3f(1.0*AREADIM + x*AREADIM,1.0*AREADIM - y*AREADIM,0.0); - glTexCoord2f(0.0,1.0); + glTexCoord2f(0.0,1.0); glVertex3f(0.0 + x*AREADIM,1.0*AREADIM - y*AREADIM,0.0); glEnd(); } @@ -400,7 +400,7 @@ void RenderArea::drawEditRectangle(QPainter *painter) painter->drawRect(selRect[l]); if (editMode == Scale && mode == Edit) painter->drawImage(selRect[l],scal,QRect(0,0,scal.width(),scal.height())); else painter->drawImage(selRect[l],rot,QRect(0,0,rot.width(),rot.height())); - } + } // and the origin of the rotation if ((editMode == Rotate && mode == Edit) || mode == EditVert) { @@ -444,7 +444,7 @@ void RenderArea::drawUnifyRectangles(QPainter *painter) { painter->setPen(QPen(QBrush(Qt::red),2)); for (unsigned k = 0; k < drawnPath.size()-1; k++) - painter->drawLine(ToScreenSpace(drawnPath[k].X(), drawnPath[k].Y()), ToScreenSpace(drawnPath[k+1].X(),drawnPath[k+1].Y())); + painter->drawLine(ToScreenSpace(drawnPath[k].X(), drawnPath[k].Y()), ToScreenSpace(drawnPath[k+1].X(),drawnPath[k+1].Y())); } if (drawP1) { @@ -457,7 +457,7 @@ void RenderArea::mousePressEvent(QMouseEvent *e) { if((e->buttons() & Qt::LeftButton)) { - if ((mode == Edit || mode == EditVert) && highlighted == NOSEL) + if ((mode == Edit || mode == EditVert) && highlighted == NOSEL) { this->ChangeMode(SPECIALMODE); pressed = NOSEL; @@ -565,7 +565,7 @@ void RenderArea::mouseReleaseEvent(QMouseEvent *e) void RenderArea::handleReleaseView(QMouseEvent *e) { - if (selection != QRect()) + if (selection != QRect()) { UpdateSelectionArea((viewport.X() - initVX)*zoom, (viewport.Y() - initVY)*zoom); originR.moveCenter(QPoint(originR.x() + (viewport.X() - initVX)*zoom, originR.y() + (viewport.Y() - initVY)*zoom)); @@ -615,11 +615,11 @@ void RenderArea::handleReleaseEdit(QMouseEvent *e) RecalculateSelectionArea(); degree = 0; } - else if (scaleX != 1 && scaleY != 1 && mode == Edit) + else if (scaleX != 1 && scaleY != 1 && mode == Edit) { ScaleComponent(scaleX, scaleY); RecalculateSelectionArea(); - scaleX = 1; + scaleX = 1; scaleY = 1; oScale = QPointF(0,0); } @@ -781,7 +781,7 @@ void RenderArea::handleMoveEdit(QMouseEvent *e) orY = tY; this->update(originR); } - else if (pressed > NOSEL && pressed < selRect.size()) + else if (pressed > NOSEL && pressed < selRect.size()) { if (editMode == Scale && mode == Edit) HandleScale(e->pos()); else HandleRotate(e->pos()); @@ -838,15 +838,15 @@ void RenderArea::wheelEvent(QWheelEvent*e) // Handle the zoom for any mode int cwx = viewport.X() - (this->visibleRegion().boundingRect().width()/zoom)/2; int cwy = viewport.Y() - (this->visibleRegion().boundingRect().height()/zoom)/2; - if (e->delta() > 0) zoom /= 0.75; - else zoom *= 0.75; + if (e->delta() > 0) zoom /= 0.75; + else zoom *= 0.75; // Change the viewport, putting the center of the screen on the mouseposition cwx += (this->visibleRegion().boundingRect().width()/zoom)/2; cwy += (this->visibleRegion().boundingRect().height()/zoom)/2; viewport = Point2f(cwx, cwy); ResetTrack(false); tb->Scale(zoom); - if (selectedV) + if (selectedV) { if (mode == UnifyVert) UpdateUnify(); else UpdateVertexSelection(); @@ -903,7 +903,7 @@ void RenderArea::RemapMod() float v = model->cm.face[i].WT(j).v(); if (u < 0) u = u + (int)u + 1; else if (u > 1) u = u - (int)u; - if (v < 0) v = v + (int)v + 1; + if (v < 0) v = v + (int)v + 1; else if (v > 1) v = v - (int)v; model->cm.face[i].WT(j).u() = u; model->cm.face[i].WT(j).v() = v; @@ -949,13 +949,13 @@ void RenderArea::ChangeMode(int modenumber) { if (selection != QRect()) { - if (selectMode == Vertex) + if (selectMode == Vertex) { mode = EditVert; selectedV = true; UpdateSelectionAreaV(0,0); for (unsigned i = 0; i < model->cm.face.size(); i++) model->cm.face[i].ClearUserBit(selBit); } - else + else { mode = Edit; selected = true; for (unsigned i = 0; i < model->cm.vert.size(); i++) model->cm.vert[i].ClearUserBit(selVertBit); @@ -965,7 +965,7 @@ void RenderArea::ChangeMode(int modenumber) else { mode = Select; - for (unsigned i = 0; i < model->cm.face.size(); i++) + for (unsigned i = 0; i < model->cm.face.size(); i++) { model->cm.face[i].ClearUserBit(selBit); model->cm.face[i].ClearS(); } @@ -977,7 +977,7 @@ void RenderArea::ChangeMode(int modenumber) break; case SPECIALMODE: // For internal use... reset the selection mode = Select; - for (unsigned i = 0; i < model->cm.face.size(); i++) + for (unsigned i = 0; i < model->cm.face.size(); i++) { model->cm.face[i].ClearUserBit(selBit); model->cm.face[i].ClearS(); } @@ -1054,13 +1054,13 @@ void RenderArea::ChangeSelectMode(int selectindex) selectMode = Area; break; } - if (selectedV && selectMode != Vertex) + if (selectedV && selectMode != Vertex) { areaUV = QRectF(); selVertBit = CVertexO::NewBitFlag(); selectedV = false; } - if (selected && selectMode == Vertex) + if (selected && selectMode == Vertex) { selected = false; //selBit = CFaceO::NewBitFlag(); @@ -1199,8 +1199,8 @@ void RenderArea::SelectFaces() { if ((*fi).WT(0).n() == textNum && !(*fi).IsD()) { - (*fi).ClearUserBit(selBit); - QVector t = QVector(); + (*fi).ClearUserBit(selBit); + 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())); @@ -1268,7 +1268,7 @@ void RenderArea::CheckVertex() if (!areaUV.contains(QPointF((*fi).WT(j).u(), (*fi).WT(j).v()))) go = true; else {go = false; break;} } - } + } if (go) banList.push_back(&(*fi)); } } @@ -1277,7 +1277,7 @@ void RenderArea::CheckVertex() void RenderArea::handleUnifySelection(CMeshO::FaceIterator fi, int j) { if (unifyRA == QRect()) - { + { unifyRA = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); unifyA = (*fi).V(j); firstface = &(*fi); @@ -1286,8 +1286,8 @@ void RenderArea::handleUnifySelection(CMeshO::FaceIterator fi, int j) drawnPath.clear(); drawnPath.push_back(Point2f(tua,tva)); } - else if (unifyRB == QRect()) - { + else if (unifyRB == QRect()) + { unifyRB = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); unifyB = (*fi).V(j); uvertB = ToScreenSpace((*fi).WT(j).u(), (*fi).WT(j).v()); @@ -1300,19 +1300,19 @@ void RenderArea::handleUnifySelection(CMeshO::FaceIterator fi, int j) } this->update(); } - else if (unifyRA1 == QRect()) - { + else if (unifyRA1 == QRect()) + { firstface1 = &(*fi); - unifyRA1 = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); + unifyRA1 = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); unifyA1 = (*fi).V(j); uvertA1 = ToScreenSpace((*fi).WT(j).u(), (*fi).WT(j).v()); tua1 = (*fi).WT(j).u(); tva1 = (*fi).WT(j).v(); drawnPath1.clear(); drawnPath1.push_back(Point2f(tua1,tva1)); } - else if (unifyRB1 == QRect()) - { - unifyRB1 = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); + else if (unifyRB1 == QRect()) + { + unifyRB1 = QRect(QPoint(selStart.x() - VRADIUS, selStart.y() - VRADIUS), QPoint(selEnd.x() + VRADIUS, selEnd.y() + VRADIUS)); unifyB1 = (*fi).V(j); uvertB1 = ToScreenSpace((*fi).WT(j).u(), (*fi).WT(j).v()); tub1 = (*fi).WT(j).u(); tvb1 = (*fi).WT(j).v(); @@ -1328,7 +1328,7 @@ void RenderArea::handleUnifySelection(CMeshO::FaceIterator fi, int j) void RenderArea::SelectConnectedComponent(QPoint e) { - // Select a series of faces with the same UV coord on the edge + // Select a series of faces with the same UV coord on the edge selStart = QPoint(MAX,MAX); selEnd = QPoint(-MAX,-MAX); selected = false; @@ -1336,13 +1336,13 @@ void RenderArea::SelectConnectedComponent(QPoint e) for (unsigned i = 0; i < model->cm.face.size(); i++) model->cm.face[i].ClearUserBit(selBit); unsigned index = 0; vector Q = vector(); - + // Search the clicked face for(unsigned i = 0; i < model->cm.face.size(); i++) { if (model->cm.face[i].WT(0).n() == textNum) { - QVector t = QVector(); + QVector t = QVector(); t.push_back(ToScreenSpace(model->cm.face[i].WT(0).u(), model->cm.face[i].WT(0).v())); t.push_back(ToScreenSpace(model->cm.face[i].WT(1).u(), model->cm.face[i].WT(1).v())); t.push_back(ToScreenSpace(model->cm.face[i].WT(2).u(), model->cm.face[i].WT(2).v())); @@ -1379,8 +1379,8 @@ void RenderArea::SelectConnectedComponent(QPoint e) void RenderArea::ClearSelection() { //selBit = CFaceO::NewBitFlag(); - for (unsigned i = 0; i < model->cm.face.size(); i++) - { + for (unsigned i = 0; i < model->cm.face.size(); i++) + { model->cm.face[i].ClearUserBit(selBit); model->cm.face[i].ClearS(); } @@ -1438,7 +1438,7 @@ void RenderArea::Flip(bool mode) if (mode) model->cm.face[i].WT(j).u() = 2.0f * mid.x() - model->cm.face[i].WT(j).u(); else model->cm.face[i].WT(j).v() = 2.0f * mid.y() - model->cm.face[i].WT(j).v(); } - } + } } } RecalculateSelectionArea(); @@ -1543,9 +1543,9 @@ vector RenderArea::FindPath(CVertexO* begin, CVertexO* end, CFaceO* f int notcontrol = -1; int lastadd = 0, lastex = -1; /* Add all the adjacent faces to the vertex. - For each face in Stack Q - if the edge is a border one and contains the last added vertex and is on the right - enqueue all adjacent faces to the other vertex + For each face in Stack Q + if the edge is a border one and contains the last added vertex and is on the right + enqueue all adjacent faces to the other vertex add the other vertex to the path */ float tu, tv; @@ -1563,7 +1563,7 @@ vector RenderArea::FindPath(CVertexO* begin, CVertexO* end, CFaceO* f if (nextb == 0) break; } bool verso; - if (pathN == 0) + if (pathN == 0) { if (tua < tub) verso = true; else verso = false; @@ -1626,7 +1626,7 @@ vector RenderArea::FindPath(CVertexO* begin, CVertexO* end, CFaceO* f tu = p->WT(oldn).u(); tv = p->WT(oldn).v(); while (n != -1) { - if (tu == next->WT(n).u() && tv == next->WT(n).v() && next != p && !next->IsV()) + if (tu == next->WT(n).u() && tv == next->WT(n).v() && next != p && !next->IsV()) Q.push_back(next); previus = next; oldn = n; @@ -1650,9 +1650,9 @@ vector RenderArea::FindPath(CVertexO* begin, CVertexO* end, CFaceO* f } else notcontrol = -1; index++; - if (index == Q.size() && end != path[path.size()-1]) + if (index == Q.size() && end != path[path.size()-1]) { - index = lastadd; + index = lastadd; notcontrol = lastex; Q[index]->ClearV(); } @@ -1738,7 +1738,7 @@ void RenderArea::HandleRotate(QPoint e) if (ny > e.y()) degree = -degree; break; case 1: - if (ny < e.y()) + if (ny < e.y()) degree = -degree; break; case 2: diff --git a/src/meshlabplugins/filter_sdfgpu/filter_sdfgpu.cpp b/src/meshlabplugins/filter_sdfgpu/filter_sdfgpu.cpp index 477e25412..17d64bbc1 100644 --- a/src/meshlabplugins/filter_sdfgpu/filter_sdfgpu.cpp +++ b/src/meshlabplugins/filter_sdfgpu/filter_sdfgpu.cpp @@ -575,7 +575,7 @@ void SdfGpuPlugin::setupMesh(MeshDocument& md, ONPRIMITIVE onPrimitive ) vcg::tri::Allocator::CompactVertexVector(m); vcg::tri::Allocator::CompactFaceVector(m); vcg::tri::UpdateNormal::PerVertexAngleWeighted(m); - tri::UpdateBounding::Box(m); + tri::UpdateBounding::Box(m); //Enable & Reset the necessary attributes switch(onPrimitive) @@ -705,7 +705,7 @@ void SdfGpuPlugin::calculateSdfHW(FramebufferObject* fboFront, FramebufferObject vcg::Matrix44f mvprINV(mv_pr_Matrix_f); mvprINV.transposeInPlace(); - vcg::Invert(mvprINV); + mvprINV=vcg::Inverse(mvprINV); mSDFProgram->setUniformMatrix4fv( "mvprMatrixINV", mvprINV.V(), 1, GL_TRUE ); @@ -1010,8 +1010,8 @@ bool SdfGpuPlugin::postRender(unsigned int peelingIteration) return true; } else return false; - } - + } + return true; }