From 26716df9c1df2295cbeb2eb20e83c82cb103cc4a Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Sat, 19 May 2007 14:10:25 +0000 Subject: [PATCH] fix problem with drowing clean code --- src/meshlabplugins/editslice/editslice.cpp | 175 +++++++++++--------- src/meshlabplugins/editslice/editslice.h | 33 +++- src/meshlabplugins/editslice/slicedialog.h | 9 +- src/meshlabplugins/editslice/slicedialog.ui | 128 +++++++------- 4 files changed, 197 insertions(+), 148 deletions(-) diff --git a/src/meshlabplugins/editslice/editslice.cpp b/src/meshlabplugins/editslice/editslice.cpp index 4aecb631f..3d36db307 100644 --- a/src/meshlabplugins/editslice/editslice.cpp +++ b/src/meshlabplugins/editslice/editslice.cpp @@ -6,6 +6,7 @@ #include #include + #include #include #include @@ -14,18 +15,26 @@ #include #include #include +#include +#include +#include +#include +#include +#include using namespace vcg; + + + ExtraMeshSlidePlugin::ExtraMeshSlidePlugin() { first=false; isDragging=false; QAction* editslice = new QAction(QIcon(":/images/iconslice.png"),"Slice mesh geometry", this); editslice->setShortcut(Qt::Key_Escape); actionList << editslice; - - QAction *editAction; - trackball_slice.center=Point3f(0, 0, 0); - trackball_slice.radius= 50; + QAction *editAction; + trackball_slice.center=Point3f(0, 0, 0); + trackball_slice.radius= 50; foreach(editAction, actionList) editAction->setCheckable(true); @@ -34,7 +43,7 @@ ExtraMeshSlidePlugin::ExtraMeshSlidePlugin() { ExtraMeshSlidePlugin::~ExtraMeshSlidePlugin() { - //delete dialogsliceobj; + } QList ExtraMeshSlidePlugin::actions() const { return actionList; @@ -77,20 +86,21 @@ void ExtraMeshSlidePlugin::restoreDefault(){ disableTransision=true; //diable transition for main trackball e->accept(); - trackball_slice.ButtonUp(QT2VCG(Qt::NoButton, Qt::ControlModifier ) ); + trackball_slice.ButtonUp(QT2VCG(Qt::NoButton, Qt::ControlModifier ) ); trackball_slice.ButtonUp(QT2VCG(Qt::NoButton, Qt::ShiftModifier ) ); trackball_slice.ButtonUp(QT2VCG(Qt::NoButton, Qt::AltModifier ) ); - if (((e->modifiers() & Qt::ShiftModifier) && (e->modifiers() & Qt::ControlModifier) && + + /*if (((e->modifiers() & Qt::ShiftModifier) && (e->modifiers() & Qt::ControlModifier) && (e->button()==Qt::LeftButton))){ - } + }*/ if (((e->modifiers() & Qt::ControlModifier) && (e->button()==Qt::LeftButton)&& dialogsliceobj->getDefaultTrackball() )){ disableTransision=false; - //e->button()==0; + } if (((e->modifiers() & Qt::ShiftModifier) && @@ -121,17 +131,46 @@ void ExtraMeshSlidePlugin::restoreDefault(){ } gla->update(); } + void ExtraMeshSlidePlugin::RestoreDefault(){ + trackball_slice.Reset(); + gla->trackball.Reset(); + gla->update(); + } void ExtraMeshSlidePlugin::SlotExportButton(){ - QString fileName = QFileDialog::getSaveFileName(gla->window(), tr("Save polyline File"),"/",tr("Mesh (*.obj)")); - vcg::Plane3f* pl= new vcg::Plane3f(); - pl->SetDirection(vcg::Point3f(1,0,0)); - pl->SetOffset(100); - //vcg::tri::Grid* gr=new vcg::tri::Grid(); + fileName = QFileDialog::getSaveFileName(gla->window(), tr("Save polyline File"),"/",tr("Mesh (*.svg)")); + Matrix44f mat_trac_rotation ; + trackball_slice.track.rot.ToMatrix( mat_trac_rotation ); //Matrice di rotazione della trackball dei piani + Point3f* dir=new Point3f(0,1,0); + (*dir)= mat_trac_rotation * (*dir); + Point3f translation_plains=trackball_slice.track.tra; //vettore di translazione dei piani - + double avg_length; //lunghezza media edge + TriMeshGrid mesh_grid; + + /* Tentativo di rotazione della mesh + CMeshO* mes= new CMeshO(m.cm); + *mes=m.cm; + vcg::tri::UpdatePosition::Matrix(*mes,mat_trac_rotation ); + vcg::tri::UpdateNormals::PerVertexNormalizedPerFace(*mes); + mesh_grid.Set(mes->face.begin(), mes->face.end()); + */ + mesh_grid.Set(m.cm.face.begin() ,m.cm.face.end()); + std::vector intersected_cells; + n_EdgeMesh edge_mesh; + n_Mesh trimesh; + Plane3f p=*plains.begin(); + p.SetDirection(*dir); + p.Normalize(); + p.SetOffset(p.Offset()+ translation_plains[0]); + vcg::Intersection(p , edge_mesh, avg_length, &mesh_grid, intersected_cells); + vcg::edge::UpdateBounding::Box(edge_mesh); + + QByteArray fn = fileName.toLatin1(); + vcg::edge::io::ExporterSVG::Save(&edge_mesh, fn.data() ); + } void ExtraMeshSlidePlugin::mouseReleaseEvent (QAction *,QMouseEvent * e, MeshModel &/*m*/, GLArea * gla) @@ -139,13 +178,8 @@ void ExtraMeshSlidePlugin::restoreDefault(){ isDragging = true; if(dialogsliceobj->getDefaultTrackball()) gla->trackball.MouseUp(e->x(),gla->height()-e->y(),QT2VCG(e->button(), e->modifiers())); - - - else trackball_slice.MouseUp(e->x(),gla->height()-e->y(),QT2VCG(e->button(), e->modifiers())); - - - - } + else trackball_slice.MouseUp(e->x(),gla->height()-e->y(),QT2VCG(e->button(), e->modifiers())); +} void ExtraMeshSlidePlugin::Decorate(QAction * ac, MeshModel &m, GLArea * gla) { @@ -165,10 +199,10 @@ void ExtraMeshSlidePlugin::restoreDefault(){ if(!first){ dialogsliceobj=new dialogslice(gla->window()); - // gla->setParent(dialogsliceobj); + first=true;} dialogsliceobj->show(); - + this->m=m; QObject::connect(dialogsliceobj, SIGNAL(exportMesh()), this,SLOT(SlotExportButton())); @@ -179,89 +213,68 @@ void ExtraMeshSlidePlugin::restoreDefault(){ gla->update(); } + void ExtraMeshSlidePlugin::DrawPlane(GLArea * gla, MeshModel &m){ - Box3f b=m.cm.bbox; - + b=m.cm.bbox; //Boundig Box Point3f mi=b.min; Point3f ma=b.max; Point3f centre=b.Center(); - float Delta=0; + float edgeMax=0; float LX= ma[0]-mi[0]; float LY= ma[1]-mi[1]; float LZ= ma[2]-mi[2]; - Delta= max(LX, LY); - Delta=max(Delta, LZ); - dialogsliceobj->setDistanceRange(Delta); - + edgeMax= max(LX, LY); + edgeMax=max(edgeMax, LZ); //edgeMax è il lato maggiore della BBox + dialogsliceobj->setDistanceRange(edgeMax); glPushMatrix(); glPushAttrib(GL_COLOR_BUFFER_BIT|GL_LIGHTING_BIT); - - - - trackball_slice.GetView(); + trackball_slice.GetView(); trackball_slice.Apply(true); trackball_slice.center=centre; - trackball_slice.radius=Delta; - - - glColor4f(1.0,0.0,0.0,0.8); - if(dialogsliceobj->getRestoreDefalut()){ - trackball_slice.Reset(); - gla->trackball.Reset(); - gla->update(); - dialogsliceobj->setRestoreDefalut(false); - } - - - int plane=1; + trackball_slice.radius=edgeMax; + glColor4f(1.0,0.0,0.0,0.8); + int plane=1; //number of planis, defult=1 if(dialogsliceobj!=0) plane=dialogsliceobj->getPlaneNumber(); glEnable(GL_BLEND); glEnable(GL_COLOR_MATERIAL); float layer=(float)LX /(float)(plane+1); + dialogsliceobj->setDefaultDistance(layer); for(int i=1; i<=(plane); i++){ - if(dialogsliceobj->getdistanceDefault()){ + int in_ass; + if(dialogsliceobj->getdistanceDefault())in_ass=0; + else in_ass=2; + glEnable(GL_CULL_FACE); glColor4f(0,1,0,0.5); glBegin(GL_QUADS); - glNormal3f(1,0,0); - glVertex3f(mi[0]+(layer*i), centre[1]-Delta, centre[2]-Delta); - glVertex3f(mi[0]+(layer*i), centre[1]+Delta, centre[2]-Delta); - glVertex3f(mi[0]+(layer*i), centre[1]+Delta, centre[2]+Delta); - glVertex3f(mi[0]+(layer*i), centre[1]-Delta, centre[2]+Delta); + glNormal3f(1,0,0); + Plane3f* p=new Plane3f(); + float assi_x[4]; + assi_x[0]=mi[0]+(layer*i); + assi_x[1]=mi[0]+(layer*((plane+1)-i)); + assi_x[2]=centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i); + assi_x[3]=centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*((plane+1)-i)); + p->Init( Point3f (assi_x[0], centre[1]-edgeMax, centre[2]-edgeMax), + Point3f( assi_x[0], centre[1]+edgeMax, centre[2]-edgeMax), + Point3f( assi_x[0], centre[1]+edgeMax, centre[2]+edgeMax)); + + glVertex3f(assi_x[in_ass], centre[1]-edgeMax, centre[2]-edgeMax); + glVertex3f(assi_x[in_ass], centre[1]+edgeMax, centre[2]-edgeMax); + glVertex3f(assi_x[in_ass], centre[1]+edgeMax, centre[2]+edgeMax); + glVertex3f(assi_x[in_ass], centre[1]-edgeMax, centre[2]+edgeMax); glEnd(); + this->plains.insert(plains.begin()+(i-1) , *p); glColor4f(1,0,0,0.5); glBegin(GL_QUADS); glNormal3f(-1,0,0); - glVertex3f(mi[0]+(layer*i), centre[1]-Delta, centre[2]-Delta); - glVertex3f(mi[0]+(layer*i), centre[1]-Delta, centre[2]+Delta); - glVertex3f(mi[0]+(layer*i), centre[1]+Delta, centre[2]+Delta); - glVertex3f(mi[0]+(layer*i), centre[1]+Delta, centre[2]-Delta); + glVertex3f(assi_x[in_ass+1], centre[1]-edgeMax, centre[2]-edgeMax); + glVertex3f(assi_x[in_ass+1], centre[1]-edgeMax, centre[2]+edgeMax); + glVertex3f(assi_x[in_ass+1], centre[1]+edgeMax, centre[2]+edgeMax); + glVertex3f(assi_x[in_ass+1], centre[1]+edgeMax, centre[2]-edgeMax); glEnd(); - } - else{ - glEnable(GL_CULL_FACE); - glEnable(GL_BLEND); - glColor4f(0,1,0,0.5); - glBegin(GL_QUADS); - glNormal3f(1,0,0); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]-Delta, centre[2]-Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]+Delta, centre[2]-Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]+Delta, centre[2]+Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]-Delta, centre[2]+Delta); - glEnd(); - glColor4f(1,0,0,0.5); - glBegin(GL_QUADS); - glNormal3f(-1,0,0); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]-Delta, centre[2]-Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]-Delta, centre[2]+Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]+Delta, centre[2]+Delta); - glVertex3f(centre[0]-((dialogsliceobj->getDistance()*(plane+1))/2)+(dialogsliceobj->getDistance()*i), centre[1]+Delta, centre[2]-Delta); - glEnd(); - } - } - + } glPopAttrib(); glPopMatrix(); if(isDragging){ diff --git a/src/meshlabplugins/editslice/editslice.h b/src/meshlabplugins/editslice/editslice.h index 03836e1a3..90d7726d6 100644 --- a/src/meshlabplugins/editslice/editslice.h +++ b/src/meshlabplugins/editslice/editslice.h @@ -7,11 +7,35 @@ #include #include "slicedialog.h" - #include #include #include +#include +// VCG Vertex +#include +#include +#include +//#include +#include +#include +#include + + + +class n_Face; +class n_Edge; +class n_Vertex : public VertexAFVN {}; + +class n_Edge : public vcg::Edge {}; +class n_Mesh : public vcg::tri::TriMesh< vector, vector > {}; +class n_EdgeMesh: public vcg::edge::EdgeMesh< vector, vector > {}; + +typedef vcg::GridStaticPtr TriMeshGrid; +typedef vcg::edge::EdgeMesh,vector> Edge_Mesh; + +//class MyFace : public FaceAFAV< CVertexO, CEdge, CFaceO > {}; + class ExtraMeshSlidePlugin : public QObject, public MeshEditInterface { @@ -20,6 +44,7 @@ class ExtraMeshSlidePlugin : public QObject, public MeshEditInterface QList actionList; public: + ExtraMeshSlidePlugin(); vcg::Trackball trackball_slice; virtual ~ExtraMeshSlidePlugin(); @@ -35,16 +60,20 @@ public: void restoreDefault(); private: + + std::vector plains; + QString fileName; bool isDragging; GLArea * gla; MeshModel m; bool first; - + Box3f b; dialogslice *dialogsliceobj; void DrawPlane(GLArea * gla,MeshModel &m); bool activeDefaultTrackball; bool disableTransision; public Q_SLOTS: + void RestoreDefault(); void SlotExportButton(); void upGlA(); }; diff --git a/src/meshlabplugins/editslice/slicedialog.h b/src/meshlabplugins/editslice/slicedialog.h index 895f1bda0..b5e22ba9f 100644 --- a/src/meshlabplugins/editslice/slicedialog.h +++ b/src/meshlabplugins/editslice/slicedialog.h @@ -12,6 +12,7 @@ class dialogslice : public QDockWidget public: dialogslice(QWidget *parent = 0); ~dialogslice(); + inline int getPlaneNumber() {return numPlane;} inline float getDistance() {return (distance*distanceRange);} inline bool getDefaultTrackball(){return defaultTrackball;} @@ -19,6 +20,10 @@ public: inline bool getRestoreDefalut(){return restoreDefalut;} inline void setRestoreDefalut(bool in){ restoreDefalut=in;} + inline void setDefaultDistance(float f){ + defaultdistance=f; + } + inline void setDistanceRange(float dRange){ this->distanceRange=dRange/100; @@ -26,15 +31,17 @@ public: ui.labelDistanceRange->setText(QString("Distance range from 0 to "+ QString::number(distanceRange))); } + Q_SIGNALS: void exportMesh(); void Update_glArea(); - + void RestoreDefault(); private: Ui::dialogsliceClass ui; int numPlane; //numeber of plane float distance; //distance of plane float distanceRange; + float defaultdistance; QWidget* parent; bool distanceDefault; // enable/disable distance bool defaultTrackball; diff --git a/src/meshlabplugins/editslice/slicedialog.ui b/src/meshlabplugins/editslice/slicedialog.ui index bce801a7c..8400e191b 100644 --- a/src/meshlabplugins/editslice/slicedialog.ui +++ b/src/meshlabplugins/editslice/slicedialog.ui @@ -182,6 +182,60 @@ + + + + 10 + 200 + 100 + 61 + + + + + 0 + 60 + + + + + 100 + 16777215 + + + + Trackball mode + + + + + 10 + 40 + 83 + 18 + + + + Default + + + + + + 10 + 20 + 151 + 18 + + + + only Plane + + + true + + + @@ -249,6 +303,16 @@ + + + + 10 + 70 + 291 + 21 + + + false @@ -292,70 +356,6 @@ 1 - - - - 10 - 70 - 291 - 21 - - - - - - - - 10 - 200 - 100 - 61 - - - - - 0 - 60 - - - - - 100 - 16777215 - - - - Trackball mode - - - - - 10 - 40 - 83 - 18 - - - - Default - - - - - - 10 - 20 - 151 - 18 - - - - only Plane - - - true - -