diff --git a/apps/test/segmentation3d/main.cpp b/apps/test/segmentation3d/main.cpp index d3c45747..e10ef473 100644 --- a/apps/test/segmentation3d/main.cpp +++ b/apps/test/segmentation3d/main.cpp @@ -15,9 +15,9 @@ int main( int argc, char ** argv ) s=new Segmentator(); //s->LoadFromDir("./venacava/","prova.txt");//to chANGE - + //s->InitSegmentation(0.5,0.2,20,10.f); - // + QApplication a( argc, argv ); SegmentForm w; @@ -26,12 +26,19 @@ int main( int argc, char ** argv ) //assign pointer to pricipal form w.simpleGLWidget1->w=&w; + #ifdef _TORUS + w.simpleGLWidget1->SetExtractionParameters(); + s->BBox().min=Point3f(0.f,0.f,0.f); + s->BBox().max=Point3f(300.f,300.f,300.f); + s->InitSegmentation(Point3f(0.f,100.f,0.f)); + #endif + /*s=new Segmentator();*/ //s->LoadFromDir("./venacava/","prova.txt");//to chANGE - //s->InitSegmentation(0.5,0.2,20,10.f); - + ////s->InitSegmentation(0.5,0.2,20,10.f); + //w.simpleGLWidget1->path="./venacava/"; timer = new QTimer(w.simpleGLWidget1 ); QTimer::connect( timer, SIGNAL(timeout()), w.simpleGLWidget1, SLOT(Update()) ); diff --git a/apps/test/segmentation3d/min_dist_point.h b/apps/test/segmentation3d/min_dist_point.h new file mode 100644 index 00000000..6cd4722b --- /dev/null +++ b/apps/test/segmentation3d/min_dist_point.h @@ -0,0 +1,202 @@ +/**************************************************************************** +* 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 + +$Log: not supported by cvs2svn $ +Revision 1.6 2004/05/14 00:34:36 ganovelli +header added + +****************************************************************************/ + +#ifndef __VCG_MINDISTPOINT +#define __VCG_MINDISTPOINT +#include + +#include +#include +#include +#include +#include + + +using namespace vcg; + + +/* +aka MetroCore +data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad +un punto dato. +*/ + +// input: mesh, punto, griglia, distanza limite +// output: normale alla faccia e punto piu' vicino su di essa + +// Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere +// UGrid, ma non sono riuscito a definirlo implicitamente + +template +void MinDistPoint( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, + Point3 & normf, Point3 & bestq, typename MESH::FaceType * &f, Point3 &ip) +{ + typedef SCALAR scalar; + typedef Point3 Point3x; + typedef Box3 Box3x; + + if(!gr.bbox.IsIn(p)) return; + typedef typename GridStaticPtr::Link A2UGridLink; + scalar ax = p[0] - gr.bbox.min[0]; // Real coodinate of point refer to + scalar ay = p[1] - gr.bbox.min[1]; + scalar az = p[2] - gr.bbox.min[2]; + + int gx = int( ax/gr.voxel[0] ); // Integer coordinate of the point + int gy = int( ay/gr.voxel[1] ); // voxel + int gz = int( az/gr.voxel[2] ); + + scalar vx = gr.bbox.min[0]+gx*gr.voxel[0]; // Real world coordinate of the Voxel + scalar vy = gr.bbox.min[1]+gy*gr.voxel[1]; // origin + scalar vz = gr.bbox.min[2]+gz*gr.voxel[2]; + + scalar dx = math::Min(p[0] - vx, vx+gr.voxel[0]-p[0]); // Dist from the voxel + scalar dy = math::Min(p[1] - vy, vy+gr.voxel[1]-p[1]); + scalar dz = math::Min(p[2] - vz, vz+gr.voxel[2]-p[2]); + + scalar vdist,vstep; + + if(dxElem())) ) + { + if( Dist((*(l->Elem())), p, error, q) ) + { + bestq = q; + bestf = l->Elem(); + typename MESH::ScalarType alfa=1, beta=1, gamma=1; + + //bestf->InterpolationParameters(q, alfa, beta); + //calcolo normale con interpolazione trilineare + /*normf = (1-(alfa+beta))*(bestf->V(0)->Normal())+ + (alfa*(bestf->V(1)->Normal()))+ + (beta*(bestf->V(2)->Normal()));*/ + bool ret=bestf->InterpolationParameters(q, alfa, beta, gamma); + //assert(ret); + normf = (bestf->V(0)->cN())*alfa+ + (bestf->V(1)->cN())*beta+ + (bestf->V(2)->cN())*gamma; + normf.Normalize(); + ip[0]=alfa;ip[1]=beta;ip[2]=gamma; + + } + + mesh.Mark( &*(l->Elem()) ); + } + } + else + { + for(int ix=gx-s;ix<=gx+s;++ix) + if( ix>=0 && ix=0 && iy=0 && izElem())) ) + { + if( Dist((*(l->Elem())), p, error, q) ) + { + bestq = q; + bestf = l->Elem(); + typename MESH::ScalarType alfa, beta, gamma; + //bestf->InterpolationParameters(q, alfa, beta); + //calcolo normale con interpolazione trilineare + bestf->InterpolationParameters(q, alfa, beta, gamma); + normf = (bestf->V(0)->cN())*alfa+ + (bestf->V(1)->cN())*beta+ + (bestf->V(2)->cN())*gamma ; + ip[0]=alfa;ip[1]=beta;ip[2]=gamma; + //normf.Normalize(); inutile si assume le normali ai vertici benfatte + } + mesh.Mark(&*l->Elem()); + } + } + } + } + } + + if( fabs(error) +void MinDistPoint( MESH & mesh, const Point3 & p, GRID & gr, SCALAR & mdist, + Point3 & normf, Point3 & bestq, typename MESH::face_type * &f) +{ + Point3 ip; + MinDistPoint(mesh,p,gr,mdist,normf,bestq,f,ip); +} +#endif diff --git a/apps/test/segmentation3d/segmentation3d.pro b/apps/test/segmentation3d/segmentation3d.pro new file mode 100644 index 00000000..79c3d097 --- /dev/null +++ b/apps/test/segmentation3d/segmentation3d.pro @@ -0,0 +1,29 @@ +TEMPLATE = app +LANGUAGE = C++ + +CONFIG += qt warn_on release + + +FORMS = segmentform.ui + + + + + + + + + + + + + + + +unix { + UI_DIR = .ui + MOC_DIR = .moc + OBJECTS_DIR = .obj +} + + diff --git a/apps/test/segmentation3d/segmentator.h b/apps/test/segmentation3d/segmentator.h index 7ae1c5b4..504b9820 100644 --- a/apps/test/segmentation3d/segmentator.h +++ b/apps/test/segmentation3d/segmentator.h @@ -234,6 +234,21 @@ private: return (MyTriMesh::CoordType(x,y,z)); } +#ifdef _TORUS + ///torus version + float getColor(MyTriMesh::CoordType p) + { + static float ray=100.f; + static float diameter=20.f; + Point3f center=BBox().Center(); + float dist=(p-center).Norm(); + float difference=abs(ray-dist); + if(difference=max.V(i))||(test.V(i)<=min.V(i)))) @@ -430,6 +444,7 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v) } ///add the external forces to the deformable mesh + void AddExtForces() { Part_VertexContainer::iterator vi; @@ -682,8 +697,10 @@ void SetSegmentParameters(int color,int tol,float Mass=0.5f,float K_elanst=0.2f, time_stamp=Time_stamp; k_dihedral=Dihedral; scale=ScaleFactor; + bbox=vcg::Box3(UnScale(MapToSpace(V.Min())),(UnScale(MapToSpace(V.Max()))));//last change! } + ///init the segmentation of the mesh void InitSegmentation(MyTriMesh::CoordType b) { @@ -708,8 +725,6 @@ void InitSegmentation(MyTriMesh::CoordType b) ReinitPhysicMesh(); CollDet->Init(bbox.min,bbox.max,5.f); - - } ///return the bounding box of the mesh @@ -740,7 +755,7 @@ void Step(float t,float _edge_size) void Smooth() { - ScaleLaplacianSmooth(m,2,0.5); + ScaleLaplacianSmooth(m,1,0.5); } void AutoStep() diff --git a/apps/test/segmentation3d/segmentform.ui b/apps/test/segmentation3d/segmentform.ui index 42b0c545..296cb3c2 100644 --- a/apps/test/segmentation3d/segmentform.ui +++ b/apps/test/segmentation3d/segmentform.ui @@ -30,30 +30,6 @@ - - - SlidesButton - - - - 10 - 10 - 80 - 31 - - - - - 10 - - - - Slides - - - true - - ResultButton @@ -150,6 +126,30 @@ true + + + SlidesButton + + + + 10 + 10 + 80 + 31 + + + + + 10 + + + + Slides + + + true + + WireButton @@ -196,243 +196,6 @@ - - - SaveButton - - - - 30 - 560 - 140 - 31 - - - - - 10 - - - - SavePly - - - - - SmoothButton - - - - 30 - 520 - 140 - 30 - - - - - 10 - - - - 1 - - - Smooth - - - - - SegmentButton - - - - 30 - 480 - 141 - 31 - - - - - 10 - - - - Extract - - - true - - - - - Color - - - false - - - - 30 - 390 - 70 - 30 - - - - - 10 - - - - LineEditPanel - - - Sunken - - - - - - 0 - - - - - textLabel1_2_2_2_2 - - - - 30 - 370 - 116 - 21 - - - - - 10 - - - - color - - - - - Tolerance - - - - 30 - 330 - 70 - 31 - - - - - 10 - - - - 10 - - - 2 - - - - - textLabel1_2_2_2 - - - - 30 - 310 - 116 - 21 - - - - - 10 - - - - tolerance - - - - - E_size - - - - 30 - 270 - 70 - 31 - - - - - 10 - - - - 4 - - - 1 - - - - - textLabel1_2_2 - - - - 30 - 250 - 116 - 21 - - - - - 10 - - - - minimum edge size - - - - - T_step - - - - 30 - 210 - 70 - 31 - - - - - 10 - - - - 0.2 - - - 3 - - textLabel1_2 @@ -598,27 +361,6 @@ mass of particles - - - ApplyButton - - - - 30 - 440 - 141 - 31 - - - - - 10 - - - - Apply - - ClearButton @@ -626,7 +368,7 @@ 30 - 600 + 700 141 31 @@ -640,6 +382,315 @@ Clear + + + SaveButton + + + + 30 + 660 + 140 + 31 + + + + + 10 + + + + SavePly + + + + + SmoothButton + + + + 30 + 620 + 140 + 30 + + + + + 10 + + + + 1 + + + Smooth + + + + + SegmentButton + + + + 30 + 580 + 141 + 31 + + + + + 10 + + + + Extract + + + true + + + + + ApplyButton + + + + 30 + 540 + 141 + 31 + + + + + 10 + + + + Apply + + + + + textLabel1_2_2_2_3 + + + + 30 + 300 + 140 + 50 + + + + + 10 + + + + Slide dinstance (pixel) + + + + + textLabel1_2_2 + + + + 30 + 250 + 116 + 21 + + + + + 10 + + + + minimum edge size + + + + + S_dist + + + + 30 + 340 + 70 + 31 + + + + + 10 + + + + 1 + + + 1 + + + + + textLabel1_2_2_2 + + + + 30 + 380 + 116 + 21 + + + + + 10 + + + + tolerance + + + + + Tolerance + + + + 30 + 400 + 70 + 31 + + + + + 10 + + + + 10 + + + 2 + + + + + textLabel1_2_2_2_2 + + + + 30 + 440 + 116 + 21 + + + + + 10 + + + + color + + + + + Color + + + false + + + + 30 + 460 + 70 + 30 + + + + + 10 + + + + LineEditPanel + + + Sunken + + + + + + 0 + + + + + E_size + + + + 30 + 270 + 70 + 31 + + + + + 10 + + + + 4 + + + 1 + + + + + T_step + + + + 30 + 210 + 70 + 31 + + + + + 10 + + + + LineEditPanel + + + Sunken + + + 0.2 + + + 3 + + @@ -648,7 +699,7 @@ 10 - 70 + 50 1030 880 diff --git a/apps/test/segmentation3d/simpleglwidget.cpp b/apps/test/segmentation3d/simpleglwidget.cpp index 2299f56a..09a17e54 100644 --- a/apps/test/segmentation3d/simpleglwidget.cpp +++ b/apps/test/segmentation3d/simpleglwidget.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ QGLWidget(parent, name) Track.Reset(); Track.radius= 100; zoom=1; + path=""; } void SimpleGLWidget::SaveMatrix() @@ -40,35 +42,102 @@ void SimpleGLWidget::LoadMatrix() glLoadMatrixd(modelMatrix); } +//load as texture the i jpg of the directory +void SimpleGLWidget::LoadTexture(QString p,int level) +{ + QImage qI=QImage(); + QDir Qd=QDir(p); + QString qformat; + QString Path=QString(p); + Qd.setNameFilter("*.jpg"); + + Qd.setSorting(QDir::Name); + QString PathFile=Path; + PathFile.append(Qd[level]); + + bool b=qI.load(PathFile,qformat); + QImage tx = QGLWidget::convertToGLFormat (qI); + + + glGenTextures(1, &texName); + glBindTexture(GL_TEXTURE_2D, texName); + glTexImage2D( GL_TEXTURE_2D, 0, 3, tx.width(), tx.height(), 0,GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() ); + glEnable(GL_TEXTURE_2D); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + +} void SimpleGLWidget::drawSlide() { -glBegin(GL_QUADS); -for (int x=0;x<((s->V.dimX())-1);x++) - for (int y=0;y<((s->V.dimY())-1);y++) - { + glPushAttrib(GL_ALL_ATTRIB_BITS); + glPolygonMode(GL_FRONT,GL_FILL); + glMatrixMode (GL_TEXTURE); + glLoadIdentity(); + glEnable(GL_TEXTURE_2D); + glEnable(GL_NORMALIZE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_COLOR_MATERIAL); + + float dx=s->BBox().DimX(); + float dy=s->BBox().DimY(); + + //to change take scale from segmentator.. better! + float n=atof(w->S_dist->text()); + float level=((float)_numslide)*n; + + Point3f p0=s->BBox().min; + p0+=Point3f(0.f,0.f,level); + + Point3f p1=p0+Point3f(dx,0.f,0.f); + Point3f p2=p0+Point3f(dx,dy,0.f); + Point3f p3=p0+Point3f(0.f,dy,0.f); + + glColor3d(1,1,1); + + ///texture + //_numslide + glBegin(GL_QUADS); glNormal(Point3d(0,0,1)); - Point3 p0=Point3(x,y,_numslide); - double color=((double)s->V.getAt(p0))/256.f; - glColor3d(color,color,color); + glTexCoord(Point3f(0,1,0)); glVertex(p0); - - Point3 p1=Point3(x+1,y,_numslide); - color=((double)s->V.getAt(p1))/256.f; - glColor3d(color,color,color); + glTexCoord(Point3f(1,1,0)); glVertex(p1); - - Point3 p2=Point3(x+1,y+1,_numslide); - color=((double)s->V.getAt(p2))/256.f; - glColor3d(color,color,color); + glTexCoord(Point3f(1,0,0)); glVertex(p2); - - Point3 p3=Point3(x,y+1,_numslide); - color=((double)s->V.getAt(p3))/256.f; - glColor3d(color,color,color); + glTexCoord(Point3f(0,0,0)); glVertex(p3); - } -glEnd(); + glEnd(); + glPopAttrib(); + +//glBegin(GL_QUADS); +//for (int x=0;x<((s->V.dimX())-1);x++) +// for (int y=0;y<((s->V.dimY())-1);y++) +// { +// glNormal(Point3d(0,0,1)); +// Point3 p0=Point3(x,y,_numslide); +// double color=((double)s->V.getAt(p0))/256.f; +// glColor3d(color,color,color); +// glVertex(p0); +// +// Point3 p1=Point3(x+1,y,_numslide); +// color=((double)s->V.getAt(p1))/256.f; +// glColor3d(color,color,color); +// glVertex(p1); +// +// Point3 p2=Point3(x+1,y+1,_numslide); +// color=((double)s->V.getAt(p2))/256.f; +// glColor3d(color,color,color); +// glVertex(p2); +// +// Point3 p3=Point3(x,y+1,_numslide); +// color=((double)s->V.getAt(p3))/256.f; +// glColor3d(color,color,color); +// glVertex(p3); +// } +//glEnd(); } void drawForces(Segmentator::Part_VertexContainer *pv,int typeForce) @@ -115,8 +184,8 @@ void SimpleGLWidget::Save() "Choose a filename to save under" ); if (filename!=NULL) { - const char *path=filename.ascii(); - vcg::tri::io::ExporterPLY::Save(s->m,path); + const char *path_save=filename.ascii(); + vcg::tri::io::ExporterPLY::Save(s->m,path_save); } } @@ -202,7 +271,7 @@ void SimpleGLWidget::glDraw(){ Track.GetView(); Track.Apply(); Track.Draw(); - glScalef(1/s->BBox().Diag(),1/s->BBox().Diag(),1/s->BBox().Diag()); + glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag()); glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom)); glTranslate(-p); //save transformation matrixes @@ -240,6 +309,7 @@ void SimpleGLWidget::glDraw(){ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); + glDisable(GL_TEXTURE_2D); Segmentator::MyTriMesh::FaceIterator fi; @@ -292,9 +362,14 @@ void SimpleGLWidget::OpenDirectory() if (filename!=NULL) { filename+="/"; - const char *path=filename.ascii(); - char *p=(char*)path; + path=filename; + const char *pa=filename.ascii(); + char *p=(char*)pa; s->LoadFromDir(p,"prova.txt"); + LoadTexture(p,0); + _showslides=true; + w->SlidesButton->setOn(true); + repaint(); } } @@ -340,7 +415,8 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e ) //w->Color->text()=color; SetExtractionParameters(); //s->SetInitialBarycenter(Point3f(x,y,_numslide)); - s->InitSegmentation(Point3f(x,y,_numslide)); + //s->InitSegmentation(Point3f(x,y,_numslide)); + s->InitSegmentation(Point3f(x,y,z)); repaint(); } //vcg::tri::UpdateBounding::Box(s->m); @@ -359,6 +435,10 @@ void SimpleGLWidget::wheelEvent(QWheelEvent *e) _numslide+=e->delta()/120.f; if ((_numslide<0)||(_numslide>=s->V.dimZ())) _numslide=oldnum; + if (s!=0) + { + LoadTexture(path,_numslide); + } } repaint(); diff --git a/apps/test/segmentation3d/simpleglwidget.h b/apps/test/segmentation3d/simpleglwidget.h index 59603e8e..09b2a156 100644 --- a/apps/test/segmentation3d/simpleglwidget.h +++ b/apps/test/segmentation3d/simpleglwidget.h @@ -8,6 +8,7 @@ #include #include #include +#include class SimpleGLWidget: public QGLWidget{ @@ -29,10 +30,12 @@ private : bool intForces; bool resultForces; bool continue_int; + GLuint texName; //vcg::GlTrimesh *Wrap; public: + QString path; SegmentForm *w; SimpleGLWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 ); @@ -48,6 +51,7 @@ public: virtual void SaveMatrix(); virtual void Save(); void LoadMatrix(); + void LoadTexture(QString path,int level); void drawSlide(); void SmoothMesh(); void Step(); @@ -121,6 +125,16 @@ public: void Extract() { continue_int=!continue_int; + if (continue_int) + { + _showslides=false; + w->SlidesButton->setOn(false); + } + else + { + _showslides=true; + w->SlidesButton->setOn(true); + } } void Update()