From b88a447671c337c5c8030457185aff2dcb81edb9 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Sun, 10 Dec 2006 23:29:57 +0000 Subject: [PATCH] added VFIterator (Pos is disabled in this version) --- apps/sample/trimesh_pos_demo/glwidget.cpp | 147 ++++++++-------------- apps/sample/trimesh_pos_demo/glwidget.h | 11 +- apps/sample/trimesh_pos_demo/mesh_type.h | 7 +- apps/sample/trimesh_pos_demo/window.cpp | 12 +- apps/sample/trimesh_pos_demo/window.h | 5 +- 5 files changed, 81 insertions(+), 101 deletions(-) diff --git a/apps/sample/trimesh_pos_demo/glwidget.cpp b/apps/sample/trimesh_pos_demo/glwidget.cpp index 6e347adb..10f3e2a8 100644 --- a/apps/sample/trimesh_pos_demo/glwidget.cpp +++ b/apps/sample/trimesh_pos_demo/glwidget.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2006/12/10 22:17:18 ganovelli +cvs problem during frist committ. repeated + */ #include @@ -52,6 +55,9 @@ GLWidget::GLWidget(QWidget *parent) track.SetIdentity(); track.radius = 0.4; pos.f=NULL; + vfite.f = NULL; + doPickVfIte = false; + doPickPos = false; } GLWidget::~GLWidget() @@ -77,7 +83,9 @@ void GLWidget::LoadTriMesh(QString &namefile) vcg::tri::UpdateNormals::PerFace(mesh); vcg::tri::UpdateNormals::PerVertex(mesh); vcg::tri::UpdateTopology::FaceFace(mesh); + vcg::tri::UpdateTopology::VertexFace(mesh); pos.f=0; + vfite.f=NULL; } void GLWidget::OpenFile(){ @@ -108,16 +116,34 @@ void GLWidget::nextE( ){ if(pos.f) pos.NextE(); repaint(); } +void GLWidget::nextB( ){ + if(pos.f) pos.NextB(); + repaint(); +} + +void GLWidget::nextVfite( ){ + if(vfite.F()) ++vfite; + repaint(); +} void GLWidget::initializeGL() { qglClearColor(trolltechPurple.dark()); - object = makeObject(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); } +template +void drawVertex(VertexType & v){ + glPushAttrib(0xffffffff); + glPointSize(2.0); + glBegin(GL_POINTS); + glVertex(v.P()); + glEnd(); + glPopAttrib(); +} + void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -134,7 +160,8 @@ void GLWidget::paintGL() // to do some picking MyStraightMesh::FaceType* fp=NULL; - if(doPick) + MyStraightMesh::VertexType* vp=NULL; + if(doPickPos) { std::vector res; int yes = vcg::Pick(pic_x,ScreenH-pic_y+1,mesh.face,res,vcg::glTriangle3,1,1); @@ -142,8 +169,20 @@ void GLWidget::paintGL() {fp = res[0]; pos.Set(fp,0,fp->V(0)); } - doPick=false; - } + doPickPos=false; + }else + if(doPickVfIte) + { + std::vector res; + int yes = vcg::Pick(pic_x,ScreenH-pic_y+1,mesh.vert,res,drawVertex,3,3); + if(yes) + {vp = res[0]; +MyStraightMesh::FaceType* g = vp->VFp(); + vfite=vcg::face::VFIterator(vp); + } + + doPickVfIte = false; + } glWrap.Draw (); @@ -155,6 +194,15 @@ void GLWidget::paintGL() vcg::GlPos >::Draw(pos); glPopAttrib(); } + if(vfite.F()!=NULL) { + glPushAttrib(0xffffffff); + glDisable(GL_LIGHTING); + glColor3f(0.0,1.0,0.0); + glDepthRange(0.0,0.999); + vcg::GlVfIterator >::Draw(vfite); + glPopAttrib(); + } + } @@ -180,95 +228,6 @@ void GLWidget::mouseMoveEvent(QMouseEvent *e) keypress = e->key(); } -GLuint GLWidget::makeObject() -{ - GLuint list = glGenLists(1); - glNewList(list, GL_COMPILE); - - glBegin(GL_QUADS); - - GLdouble x1 = +0.06; - GLdouble y1 = -0.14; - GLdouble x2 = +0.14; - GLdouble y2 = -0.06; - GLdouble x3 = +0.08; - GLdouble y3 = +0.00; - GLdouble x4 = +0.30; - GLdouble y4 = +0.22; - - quad(x1, y1, x2, y2, y2, x2, y1, x1); - quad(x3, y3, x4, y4, y4, x4, y3, x3); - - extrude(x1, y1, x2, y2); - extrude(x2, y2, y2, x2); - extrude(y2, x2, y1, x1); - extrude(y1, x1, x1, y1); - extrude(x3, y3, x4, y4); - extrude(x4, y4, y4, x4); - extrude(y4, x4, y3, x3); - - const double Pi = 3.14159265358979323846; - const int NumSectors = 200; - - for (int i = 0; i < NumSectors; ++i) { - double angle1 = (i * 2 * Pi) / NumSectors; - GLdouble x5 = 0.30 * sin(angle1); - GLdouble y5 = 0.30 * cos(angle1); - GLdouble x6 = 0.20 * sin(angle1); - GLdouble y6 = 0.20 * cos(angle1); - - double angle2 = ((i + 1) * 2 * Pi) / NumSectors; - GLdouble x7 = 0.20 * sin(angle2); - GLdouble y7 = 0.20 * cos(angle2); - GLdouble x8 = 0.30 * sin(angle2); - GLdouble y8 = 0.30 * cos(angle2); - - quad(x5, y5, x6, y6, x7, y7, x8, y8); - - extrude(x6, y6, x7, y7); - extrude(x8, y8, x5, y5); - } - - glEnd(); - - glEndList(); - return list; -} - -void GLWidget::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2, - GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4) -{ - qglColor(trolltechGreen); - - glVertex3d(x1, y1, -0.05); - glVertex3d(x2, y2, -0.05); - glVertex3d(x3, y3, -0.05); - glVertex3d(x4, y4, -0.05); - - glVertex3d(x4, y4, +0.05); - glVertex3d(x3, y3, +0.05); - glVertex3d(x2, y2, +0.05); - glVertex3d(x1, y1, +0.05); -} - -void GLWidget::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) -{ - qglColor(trolltechGreen.dark(250 + int(100 * x1))); - - glVertex3d(x1, y1, +0.05); - glVertex3d(x2, y2, +0.05); - glVertex3d(x2, y2, -0.05); - glVertex3d(x1, y1, -0.05); -} - -void GLWidget::normalizeAngle(int *angle) -{ - while (*angle < 0) - *angle += 360 * 16; - while (*angle > 360 * 16) - *angle -= 360 * 16; -} - void GLWidget:: mousePressEvent(QMouseEvent *e) { if( (keypress==Qt::Key_Control) && (e->button() == Qt::LeftButton) ) @@ -279,7 +238,7 @@ void GLWidget::normalizeAngle(int *angle) else if(e->button() == Qt::RightButton) { - doPick=true; + doPickVfIte=true; pic_x = e->x(); pic_y = e->y(); } diff --git a/apps/sample/trimesh_pos_demo/glwidget.h b/apps/sample/trimesh_pos_demo/glwidget.h index c0630e79..0ce4007b 100644 --- a/apps/sample/trimesh_pos_demo/glwidget.h +++ b/apps/sample/trimesh_pos_demo/glwidget.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2006/12/10 22:17:18 ganovelli +cvs problem during frist committ. repeated + */ #ifndef GLWIDGET_H_POS_DEMO #define GLWIDGET_H_POS_DEMO @@ -34,6 +37,7 @@ $Log: not supported by cvs2svn $ #include #include #include +#include class GLWidget : public QGLWidget { @@ -50,13 +54,18 @@ public: vcg::GlTrimesh glWrap; vcg::Trackball track; int ScreenH,ScreenW,pic_x,pic_y,keypress; - bool doPick; + bool doPickPos,doPickVfIte; vcg::face::Pos pos; + vcg::face::VFIterator vfite; + public slots: void flipV( ); void flipE( ); void flipF( ); void nextE( ); + void nextB( ); + void nextVfite( ); + void LoadTriMesh(QString& namefile); void OpenFile(); diff --git a/apps/sample/trimesh_pos_demo/mesh_type.h b/apps/sample/trimesh_pos_demo/mesh_type.h index eedb6ffe..34ce8711 100644 --- a/apps/sample/trimesh_pos_demo/mesh_type.h +++ b/apps/sample/trimesh_pos_demo/mesh_type.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2006/12/10 19:55:09 ganovelli +first draft. Working but ugly interface. right mouse of the button to place a pos, then prss buttons. + */ #pragma once /** the definition of vertex */ @@ -44,10 +47,10 @@ class StraightFace; /* DEFINITION OF A VERY STRAIGHT MESH. No optional atributes, just normals in the vertices and flags in vertices and faces*/ /** definition of a very simple vertex type. Just coordinates and normal as attributes*/ -class StraightVertex: public vcg::VertexSimp2< StraightVertex, DummyEdge, StraightFace, vcg::vert::Coord3f,vcg::vert::Normal3f,vcg::vert::BitFlags>{}; +class StraightVertex: public vcg::VertexSimp2< StraightVertex, DummyEdge, StraightFace, vcg::vert::Coord3f,vcg::vert::VFAdj,vcg::vert::Normal3f,vcg::vert::BitFlags>{}; /** definition of a very simple face type. Just color and reference to vertices as attribute*/ -class StraightFace: public vcg::FaceSimp2< StraightVertex, DummyEdge, StraightFace, vcg:: face::VertexRef, vcg:: face::FFAdj,vcg:: face::Normal3f,vcg::face::BitFlags > {}; +class StraightFace: public vcg::FaceSimp2< StraightVertex, DummyEdge, StraightFace, vcg:: face::VertexRef, vcg:: face::FFAdj, vcg:: face::VFAdj,vcg:: face::Normal3f,vcg::face::BitFlags > {}; /** definition of a very simple mesh*/ class MyStraightMesh: public vcg::tri::TriMesh< std::vector,std::vector >{}; diff --git a/apps/sample/trimesh_pos_demo/window.cpp b/apps/sample/trimesh_pos_demo/window.cpp index 4c2e6799..a90146c9 100644 --- a/apps/sample/trimesh_pos_demo/window.cpp +++ b/apps/sample/trimesh_pos_demo/window.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2006/12/10 22:17:18 ganovelli +cvs problem during frist committ. repeated + */ #include @@ -39,8 +42,10 @@ Window::Window() fvButton = createButton("FlipV()",SLOT(flipV( ))); feButton = createButton("FlipE()",SLOT(flipE( ))); ffButton = createButton("FlipF()",SLOT(flipF( ))); - neButton = createButton("NextE()",SLOT(nextE( ))); - ldButton = createButton("Load",SLOT(OpenFile( ))); + neButton = createButton("NextE() {FlipE() + FlipF() }",SLOT(nextE( ))); + nbButton = createButton("NextB() ",SLOT(nextB( ))); + ldButton = createButton("Load TriMesh",SLOT(OpenFile( ))); + vfButton = createButton("++()",SLOT(nextVfite())); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(glWidget); @@ -48,7 +53,8 @@ Window::Window() mainLayout->addWidget(feButton); mainLayout->addWidget(ffButton); mainLayout->addWidget(neButton); - + mainLayout->addWidget(nbButton); + mainLayout->addWidget(vfButton); mainLayout->addWidget(ldButton); setLayout(mainLayout); diff --git a/apps/sample/trimesh_pos_demo/window.h b/apps/sample/trimesh_pos_demo/window.h index 2e60998b..9be6f8fb 100644 --- a/apps/sample/trimesh_pos_demo/window.h +++ b/apps/sample/trimesh_pos_demo/window.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2006/12/10 22:17:18 ganovelli +cvs problem during frist committ. repeated + */ #ifndef WINDOW_H_POS_DEMO #define WINDOW_H_POS_DEMO @@ -45,7 +48,7 @@ private: QPushButton *createButton(const char *changedSignal, const char *setterSlot); GLWidget *glWidget; - QPushButton * fvButton,*feButton,*ffButton,*neButton,*ldButton; + QPushButton * fvButton,*feButton,*ffButton,*neButton,*ldButton,*nbButton,*vfButton; }; #endif