fix problem with drowing

clean code
This commit is contained in:
Paolo Cignoni cignoni 2007-05-19 14:10:25 +00:00
parent 5023bbe6aa
commit 26716df9c1
4 changed files with 197 additions and 148 deletions

View File

@ -6,6 +6,7 @@
#include <wrap/gl/pick.h>
#include <vcg/complex/trimesh/create/platonic.h>
#include <vcg/space/point3.h>
#include <vcg/space/box3.h>
#include <vcg/space/index/grid_closest.h>
@ -14,18 +15,26 @@
#include <wrap/gui/trackball.h>
#include <qfiledialog.h>
#include<limits>
#include <vcg/complex/edgemesh/update/bounding.h>
#include <wrap/io_trimesh/import.h>
#include <wrap/io_edgemesh/export_svg.h>
#include <vcg/complex/trimesh/update/position.h>
#include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/update/normal.h>
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<QAction *> 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<CMeshO>::Matrix(*mes,mat_trac_rotation );
vcg::tri::UpdateNormals<CMeshO>::PerVertexNormalizedPerFace(*mes);
mesh_grid.Set(mes->face.begin(), mes->face.end());
*/
mesh_grid.Set(m.cm.face.begin() ,m.cm.face.end());
std::vector<TriMeshGrid::Cell *> 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<n_Mesh, n_EdgeMesh, n_Mesh::ScalarType, TriMeshGrid>(p , edge_mesh, avg_length, &mesh_grid, intersected_cells);
vcg::edge::UpdateBounding<n_EdgeMesh>::Box(edge_mesh);
QByteArray fn = fileName.toLatin1();
vcg::edge::io::ExporterSVG<n_EdgeMesh>::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){

View File

@ -7,11 +7,35 @@
#include <QList>
#include "slicedialog.h"
#include <meshlab/meshmodel.h>
#include <meshlab/interfaces.h>
#include <wrap/gui/trackball.h>
#include <vcg/space/index/grid_static_ptr.h>
// VCG Vertex
#include <vcg/simplex/vertex/vertex.h>
#include <vcg/simplex/vertex/with/afvn.h>
#include <vcg/simplex/face/base.h>
//#include <vcg/simplex/face/with/afav.h>
#include <vcg/complex/edgemesh/base.h>
#include <vcg/complex/trimesh/base.h>
#include <vcg/simplex/edge/with/ae.h>
class n_Face;
class n_Edge;
class n_Vertex : public VertexAFVN<float, n_Edge, n_Face> {};
class n_Edge : public vcg::Edge<n_Edge, n_Vertex> {};
class n_Mesh : public vcg::tri::TriMesh< vector<n_Vertex>, vector<CFaceO> > {};
class n_EdgeMesh: public vcg::edge::EdgeMesh< vector<n_Vertex>, vector<n_Edge> > {};
typedef vcg::GridStaticPtr<n_Mesh::FaceType, n_Mesh::ScalarType> TriMeshGrid;
typedef vcg::edge::EdgeMesh<vector<n_Vertex>,vector<n_Edge>> 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 <QAction *> actionList;
public:
ExtraMeshSlidePlugin();
vcg::Trackball trackball_slice;
virtual ~ExtraMeshSlidePlugin();
@ -35,16 +60,20 @@ public:
void restoreDefault();
private:
std::vector<Plane3f> 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();
};

View File

@ -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;

View File

@ -182,6 +182,60 @@
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_3" >
<property name="geometry" >
<rect>
<x>10</x>
<y>200</y>
<width>100</width>
<height>61</height>
</rect>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="title" >
<string>Trackball mode</string>
</property>
<widget class="QRadioButton" name="DefaultTrackball" >
<property name="geometry" >
<rect>
<x>10</x>
<y>40</y>
<width>83</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>Default</string>
</property>
</widget>
<widget class="QRadioButton" name="on_slideTrackBall" >
<property name="geometry" >
<rect>
<x>10</x>
<y>20</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>only Plane</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2" >
<property name="geometry" >
<rect>
@ -249,6 +303,16 @@
</rect>
</property>
</widget>
<widget class="QLabel" name="labelDistanceRange" >
<property name="geometry" >
<rect>
<x>10</x>
<y>70</y>
<width>291</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QSlider" name="SliderPlaneDistance" >
<property name="enabled" >
<bool>false</bool>
@ -292,70 +356,6 @@
<number>1</number>
</property>
</widget>
<widget class="QLabel" name="labelDistanceRange" >
<property name="geometry" >
<rect>
<x>10</x>
<y>70</y>
<width>291</width>
<height>21</height>
</rect>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_3" >
<property name="geometry" >
<rect>
<x>10</x>
<y>200</y>
<width>100</width>
<height>61</height>
</rect>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="title" >
<string>Trackball mode</string>
</property>
<widget class="QRadioButton" name="DefaultTrackball" >
<property name="geometry" >
<rect>
<x>10</x>
<y>40</y>
<width>83</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>Default</string>
</property>
</widget>
<widget class="QRadioButton" name="on_slideTrackBall" >
<property name="geometry" >
<rect>
<x>10</x>
<y>20</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>only Plane</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
</widget>