From ac5354fb660329c5d57e2aaaa1fabad47210a0c7 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Wed, 4 Aug 2004 20:59:13 +0000 Subject: [PATCH] first release compiled but not tested --- apps/test/lem/bardrawer.h | 128 +++++++++++++++++++++++ apps/test/lem/form1.cpp | 50 +++++++++ apps/test/lem/form1.h | 37 +++++++ apps/test/lem/form1.ui | 20 ++++ apps/test/lem/insert_vertex.h | 98 ++++++++++++++++++ apps/test/lem/main.cpp | 186 ++++++++++++++++++++++++++++++++++ apps/test/lem/moc_form1.cpp | 101 ++++++++++++++++++ 7 files changed, 620 insertions(+) create mode 100644 apps/test/lem/bardrawer.h create mode 100644 apps/test/lem/form1.cpp create mode 100644 apps/test/lem/form1.h create mode 100644 apps/test/lem/form1.ui create mode 100644 apps/test/lem/insert_vertex.h create mode 100644 apps/test/lem/main.cpp create mode 100644 apps/test/lem/moc_form1.cpp diff --git a/apps/test/lem/bardrawer.h b/apps/test/lem/bardrawer.h new file mode 100644 index 00000000..ec5e79d0 --- /dev/null +++ b/apps/test/lem/bardrawer.h @@ -0,0 +1,128 @@ +#ifndef __GLWRAPBAR__ +#define __GLWRAPBAR__ + +#include +#include +#include +#include + +namespace vcg { + +template < class STL_BAR_CONT > +class GLWrapBar{ +public: + /// The bar container + typedef STL_BAR_CONT BarContainer; + /// The bar type + typedef typename STL_BAR_CONT::value_type BarType; + /// The type of bar iterator + typedef typename STL_BAR_CONT::iterator BarIterator; + ///the type of coordinates + typedef typename BarType::CoordType CoordType; + ///the type of scalar + typedef typename CoordType::ScalarType ScalarType; + + /* typedef typename MESH_TYPE MeshType; + typedef typename MeshType::FaceType FaceType; + typedef typename MeshType::VertexType VertexType; + typedef typename MeshType::CoordType CoordType; + typedef typename MeshType::ScalarType ScalarType; + typedef typename vcg::LemSolver LemSolver; + typedef typename LemSolver::BarType BarType;*/ + + GLWrapBar(BarContainer & _b):Bars(_b){} + + BarContainer & Bars; + + public: + + + void Draw() + { + + BarIterator Bi; + glLineWidth(3.f); + glPushAttrib(GL_CURRENT_BIT|GL_ENABLE_BIT ); + glDisable(GL_NORMALIZE); + glDisable(GL_LIGHTING); + + + for (Bi=Bars.begin();BiD>2) + verse=-1.f; + + direction.V(Bi->D%3)=verse; + + if (Bi->D==0) + glColor3d(1,1,1); + else + if (Bi->D==1) + glColor3d(1,0,0); + else + if (Bi->D==2) + glColor3d(0,1,0); + else + if (Bi->D==3) + glColor3d(0,0,1); + else + if (Bi->D==4) + glColor3d(0,1,1); + else + glColor3d(1,0,1); + + if (Bi->IsTouched()) + glColor3d(0,0,0); + + glBegin(GL_LINE_STRIP); + vcg::glVertex(Bi->P); + vcg::glVertex(Bi->P+(direction*Bi->L)); + // vcg::glVertex(Bi->P+direction); + glEnd(); + /*glBegin(GL_LINE_STRIP); + vcg::glVertex(Bi->V0->P()); + vcg::glVertex(Bi->V1->P()); + glEnd();*/ + } + glPopAttrib(); + } + + template + void DrawMesh(MESH_TYPE *m) + { + MESH_TYPE::FaceIterator Fi; + glPushAttrib(GL_COLOR_BUFFER_BIT); + + glColor4d(0.8,0.8,0.8,0.9); + for (Fi=m->face.begin();Fiface.end();Fi++) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); + glEnable(GL_LIGHTING); + glEnable(GL_NORMALIZE); + glBegin(GL_TRIANGLES); + glNormal(Fi->NormalizedNormal()); + glVertex(Fi->V(0)->P()); + glVertex(Fi->V(1)->P()); + glVertex(Fi->V(2)->P()); + glEnd(); + + glDisable(GL_BLEND); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glColor3d(0,0,0); + glBegin(GL_LINE_LOOP); + glVertex(Fi->V(0)->P()); + glVertex(Fi->V(1)->P()); + glVertex(Fi->V(2)->P()); + glEnd(); + } + glPopAttrib(); + } +}; + +} +#endif \ No newline at end of file diff --git a/apps/test/lem/form1.cpp b/apps/test/lem/form1.cpp new file mode 100644 index 00000000..db1bff2c --- /dev/null +++ b/apps/test/lem/form1.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** Form implementation generated from reading ui file 'form1.ui' +** +** Created: Mon Aug 2 16:35:19 2004 +** by: The User Interface Compiler ($Id: form1.cpp,v 1.1 2004-08-04 20:59:13 pietroni Exp $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "form1.h" + +#include +#include +#include +#include + +/* + * Constructs a Form1 as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "Form1" ); + languageChange(); + resize( QSize(909, 714).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); +} + +/* + * Destroys the object and frees any allocated resources + */ +Form1::~Form1() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void Form1::languageChange() +{ + setCaption( tr( "TetraWraP" ) ); +} + diff --git a/apps/test/lem/form1.h b/apps/test/lem/form1.h new file mode 100644 index 00000000..101ede37 --- /dev/null +++ b/apps/test/lem/form1.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'form1.ui' +** +** Created: Mon Aug 2 16:35:19 2004 +** by: The User Interface Compiler ($Id: form1.h,v 1.1 2004-08-04 20:59:13 pietroni Exp $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#ifndef FORM1_H +#define FORM1_H + +#include +#include + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QSpacerItem; + +class Form1 : public QDialog +{ + Q_OBJECT + +public: + Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~Form1(); + + +protected: + +protected slots: + virtual void languageChange(); + +}; + +#endif // FORM1_H diff --git a/apps/test/lem/form1.ui b/apps/test/lem/form1.ui new file mode 100644 index 00000000..c7301f82 --- /dev/null +++ b/apps/test/lem/form1.ui @@ -0,0 +1,20 @@ + +Form1 + + + Form1 + + + + 0 + 0 + 909 + 714 + + + + TetraWraP + + + + diff --git a/apps/test/lem/insert_vertex.h b/apps/test/lem/insert_vertex.h new file mode 100644 index 00000000..7592a43a --- /dev/null +++ b/apps/test/lem/insert_vertex.h @@ -0,0 +1,98 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History +****************************************************************************/ + +#ifndef __VCG_TRI_INSERT_VERTEX +#define __VCG_TRI_INSERT_VERTEX + + +#include +#include +#include + +/// This Class is used for insertiong a vertex in a face +namespace vcg{ + namespace tri{ + + + template + ///insert a vertex iside a face and re-triangolarize v will be pointer to inserted vertex + void InsertVert(MESH_TYPE &m,typename MESH_TYPE::FaceType *f,typename MESH_TYPE::VertexType* &v) + { + MESH_TYPE::FaceIterator Finit=vcg::tri::Allocator::AddFaces(m,3); + MESH_TYPE::VertexIterator Vi=vcg::tri::Allocator::AddVertices(m,1); + MESH_TYPE::FaceIterator Fi=Finit; + MESH_TYPE::FaceType *F; + //set vertex pointer of new face + for (int i=0;i<3;i++) + { + Fi->V(0)=f->V(i); + Fi->V(1)=f->V((i+1)%3); + Fi->V(2)=&(*Vi); + + F=&(*Fi); + + //assign topology in substitution of the old one + if (MESH_TYPE::HasFFTopology()) + vcg::face::Attach(F,0,f->FFp(i),f->FFi(i)); + if (MESH_TYPE::HasVFTopology()) + { + vcg::face::VFDetach(f,i); + + //put new faces on list of the old vertex and new one + vcg::face::VFAppend(F,0); + vcg::face::VFAppend(F,1); + vcg::face::VFAppend(F,2); + } + Fi++; + } + //then attach the faces between themselfes + Fi=Finit; + MESH_TYPE::FaceIterator Fsucc=Fi; + Fsucc++; + + MESH_TYPE::FaceType *F0=&(*Fi); + MESH_TYPE::FaceType *F1=&(*Fsucc); + + /*vcg::face::Attach(F0,1,F1,2);*/ + Fi++; + Fsucc++; + F0=&(*Fi); + F1=&(*Fsucc); + /*vcg::face::Attach(F0,1,F1,2);*/ + Fsucc=Finit; + Fi++; + F0=&(*Fi); + F1=&(*Fsucc); + /*vcg::face::Attach(F0,1,F1,2);*/ + //at the end set as deleted the old face that was substituted + f->SetD(); + v=&(*Vi); + } + + +} +} +#endif \ No newline at end of file diff --git a/apps/test/lem/main.cpp b/apps/test/lem/main.cpp new file mode 100644 index 00000000..b1a01ce4 --- /dev/null +++ b/apps/test/lem/main.cpp @@ -0,0 +1,186 @@ +//#include +#include +//#include +#include +//#include +//#include + +//#include + +#include + +#include +#include +#include +#include +#include + + + +//#include "form1.h" + + +class MyFace; + +class MyVertex: public vcg::VertexAFVNd +{ + public: + ///we suppose at maximum 4 bars for each direction + vcg::Bar* B[6]; + double Delta[6]; + double Num[6]; + //int Num; +}; + +class MyFace:public vcg::FaceAFAV +{ + public: + ///we suppose at maximum 4 bars for each direction + vcg::Bar* B[6]; +}; + +typedef vcg::tri::TriMesh< std::vector ,std::vector > MyTriMesh; + +//typedef vcg::Lem_Face LemType; +typedef vcg::Lem_Vertex LemType; +typedef vcg::Lem_Remesher LemRemesherType; +LemType LS; +LemRemesherType LR; +vcg::tri::UpdateTopology UT; +MyTriMesh *tm; +vcg::tri::UpdateBounding UB; + +//vcg::GLWrapBar *WB; +//vcg::GlTrimesh *glT; + +//struct MyGl: public QGLWidget{ +// MyGl( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 ) +// :QGLWidget(parent,name){} +// //void QGLWidget::paintEvent ( QPaintEvent * ) [virtual protected] +// double lr,ud,tz; +// int cx,cy,z; +// +// virtual void glDraw(){ +// +// glClearColor(0.2,0.2,0.2,1); +// glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); +// glMatrixMode(GL_PROJECTION); +// glLoadIdentity(); +// gluPerspective(45,1,0.01,20); +// glMatrixMode(GL_MODELVIEW); +// glLoadIdentity(); +// gluLookAt(0,0,1,0,0,0,0,10,0); +// +// +// glTranslatef(0,0,tz); +// glRotatef(lr,0,1,0); +// glRotatef(ud,1,0,0); +// +// glScalef(1/tm->bbox.Diag(),1/tm->bbox.Diag(),1/tm->bbox.Diag()); +// vcg::Point3d p=tm->bbox.Center(); +// glTranslate(-p); +// +// WB->Draw(); +// WB->DrawMesh(tm); +// +// /*glT->Draw ();*/ +// QGLWidget::glDraw(); +// } +// +// void resizeGL( int w, int h ) +// { +// //// setup viewport, projection etc.: +// glViewport( 0, 0, (GLint)w, (GLint)h ); +// } +// +// virtual void mousePressEvent ( QMouseEvent * e ){ +// cx = e->x(); +// cy = e->y(); +// +// //tr.MouseDown(e->x(),e->y(),(Trackball::Button)(int)(e->button())); +// //QWidget::mousePressEvent(e); +// } +// +// virtual void mouseMoveEvent ( QMouseEvent * e ){ +// //tr.MouseMove(e->x(),e->y()); +// //QWidget::mouseMoveEvent(e); +// lr+=e->x()-cx; +// ud-=e->y()-cy; +// cx = e->x(); +// cy = e->y(); +// repaint(); +// } +// +// virtual void wheelEvent ( QWheelEvent * e ){ +// tz +=e->delta()/360.f; +// repaint(); +// QWidget::wheelEvent(e); +// } +// +// virtual void initializeGL(){ +// +// +// GLfloat f[4]={0.2,0.2,0.2,1.f}; +// GLfloat p[4]={3,3,5,0}; +// glLightfv(GL_LIGHT0, GL_AMBIENT,f); +// glLightfv(GL_LIGHT1, GL_POSITION,p); +// glLightfv(GL_LIGHT1, GL_DIFFUSE,f); +// glLightfv(GL_LIGHT1, GL_SPECULAR,f); +// +// glEnable(GL_LIGHT0); +// glEnable(GL_LIGHT1); +// glEnable(GL_LIGHTING); +// glEnable(GL_DEPTH_TEST); +// glDepthFunc(GL_LESS); +// glPolygonMode(GL_FRONT,GL_FILL); +// glEnable(GL_BACK); +// glCullFace(GL_BACK); +// } +// +//}; + + +int main( int argc, char ** argv ) +{ LS=LemType(0.01,0.1,0.01); + + //LS=LemType(0.01,200,0.01); + LS._SetDir(0); + LS._SetDir(1); + LS._SetDir(2); + LS._SetDir(3); + LS._SetDir(4); + LS._SetDir(5); + + tm=new MyTriMesh(); + vcg::tri::io::ImporterPLY Imp=vcg::tri::io::ImporterPLY(); + char *name="cube.ply"; + Imp.Open((*tm),name); + + UT.FaceFace(*tm); + UT.VertexFace(*tm); + UB.Box(*tm); + + LR._SetDir(0); + LR._SetDir(1); + LR._SetDir(2); + LR._SetDir(3); + LR._SetDir(4); + LR._SetDir(5); + LR.Remesh((*tm),0.5,0.2); + LS.Init(tm,0.5); + + /*WB=new vcg::GLWrapBar >(LS.LEM.Bars);*/ + + LS.SetTouchedBar(&LS.LEM.Bars[9],1); + LS.ComputeStep(tm); + + /* glT=new vcg::GlTrimesh(); + glT->m=tm;*/ + /*QApplication a( argc, argv );*/ + /* Form1 w;*/ + /*MyGl *gl = new MyGl(&w); + gl->setMinimumSize(800,800); + w.show(); + a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); + return a.exec();*/ +} diff --git a/apps/test/lem/moc_form1.cpp b/apps/test/lem/moc_form1.cpp new file mode 100644 index 00000000..a2b3cc63 --- /dev/null +++ b/apps/test/lem/moc_form1.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** Form1 meta object code from reading C++ file 'form1.h' +** +** Created: Mon Aug 2 16:35:19 2004 +** by: The Qt MOC ($Id: moc_form1.cpp,v 1.1 2004-08-04 20:59:13 pietroni Exp $) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#undef QT_NO_COMPAT +#include "form1.h" +#include +#include + +#include +#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26) +#error "This file was generated using the moc from 3.3.2. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +const char *Form1::className() const +{ + return "Form1"; +} + +QMetaObject *Form1::metaObj = 0; +static QMetaObjectCleanUp cleanUp_Form1( "Form1", &Form1::staticMetaObject ); + +#ifndef QT_NO_TRANSLATION +QString Form1::tr( const char *s, const char *c ) +{ + if ( qApp ) + return qApp->translate( "Form1", s, c, QApplication::DefaultCodec ); + else + return QString::fromLatin1( s ); +} +#ifndef QT_NO_TRANSLATION_UTF8 +QString Form1::trUtf8( const char *s, const char *c ) +{ + if ( qApp ) + return qApp->translate( "Form1", s, c, QApplication::UnicodeUTF8 ); + else + return QString::fromUtf8( s ); +} +#endif // QT_NO_TRANSLATION_UTF8 + +#endif // QT_NO_TRANSLATION + +QMetaObject* Form1::staticMetaObject() +{ + if ( metaObj ) + return metaObj; + QMetaObject* parentObject = QDialog::staticMetaObject(); + static const QUMethod slot_0 = {"languageChange", 0, 0 }; + static const QMetaData slot_tbl[] = { + { "languageChange()", &slot_0, QMetaData::Protected } + }; + metaObj = QMetaObject::new_metaobject( + "Form1", parentObject, + slot_tbl, 1, + 0, 0, +#ifndef QT_NO_PROPERTIES + 0, 0, + 0, 0, +#endif // QT_NO_PROPERTIES + 0, 0 ); + cleanUp_Form1.setMetaObject( metaObj ); + return metaObj; +} + +void* Form1::qt_cast( const char* clname ) +{ + if ( !qstrcmp( clname, "Form1" ) ) + return this; + return QDialog::qt_cast( clname ); +} + +bool Form1::qt_invoke( int _id, QUObject* _o ) +{ + switch ( _id - staticMetaObject()->slotOffset() ) { + case 0: languageChange(); break; + default: + return QDialog::qt_invoke( _id, _o ); + } + return TRUE; +} + +bool Form1::qt_emit( int _id, QUObject* _o ) +{ + return QDialog::qt_emit(_id,_o); +} +#ifndef QT_NO_PROPERTIES + +bool Form1::qt_property( int id, int f, QVariant* v) +{ + return QDialog::qt_property( id, f, v); +} + +bool Form1::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; } +#endif // QT_NO_PROPERTIES