diff --git a/apps/test/segmentation3d/main.cpp b/apps/test/segmentation3d/main.cpp index d89370b0..d3c45747 100644 --- a/apps/test/segmentation3d/main.cpp +++ b/apps/test/segmentation3d/main.cpp @@ -12,11 +12,11 @@ QTimer *timer; int main( int argc, char ** argv ) { - //s=new Segmentator(); + 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); // QApplication a( argc, argv ); @@ -26,7 +26,7 @@ int main( int argc, char ** argv ) //assign pointer to pricipal form w.simpleGLWidget1->w=&w; - s=new Segmentator(); + /*s=new Segmentator();*/ //s->LoadFromDir("./venacava/","prova.txt");//to chANGE diff --git a/apps/test/segmentation3d/moc_simpleglwidget.cpp b/apps/test/segmentation3d/moc_simpleglwidget.cpp index a7369cca..0f3faded 100644 --- a/apps/test/segmentation3d/moc_simpleglwidget.cpp +++ b/apps/test/segmentation3d/moc_simpleglwidget.cpp @@ -1,8 +1,8 @@ /**************************************************************************** ** SimpleGLWidget meta object code from reading C++ file 'simpleglwidget.h' ** -** Created: Fri Dec 17 12:16:05 2004 -** by: The Qt MOC ($Id: moc_simpleglwidget.cpp,v 1.1 2004-12-17 11:17:36 pietroni Exp $) +** Created: Sat Dec 18 11:09:46 2004 +** by: The Qt MOC ($Id: moc_simpleglwidget.cpp,v 1.2 2004-12-20 17:56:01 pietroni Exp $) ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/ diff --git a/apps/test/segmentation3d/segmentator.h b/apps/test/segmentation3d/segmentator.h index 4f710dd6..7ae1c5b4 100644 --- a/apps/test/segmentation3d/segmentator.h +++ b/apps/test/segmentation3d/segmentator.h @@ -238,9 +238,12 @@ private: float getColor(MyTriMesh::CoordType p) { - float lx=p.V(0)-(int)p.V(0);//da rivedere bene per lo scale - float ly=p.V(1)-(int)p.V(1);//da rivedere bene per lo scale - float lz=p.V(2)-(int)p.V(2);//da rivedere bene per lo scale + + float lx=(p.V(0)-(int)p.V(0))*scale.V(0);//da rivedere bene per lo scale + float ly=(p.V(1)-(int)p.V(1))*scale.V(1);//da rivedere bene per lo scale + float lz=(p.V(2)-(int)p.V(2))*scale.V(2);//da rivedere bene per lo scale + + p=Scale(p); Point3i base=Point3i((int)p.V(0),(int)p.V(1),(int)p.V(2)); @@ -283,6 +286,15 @@ private: return (ret); } + ///scale the coordinates of a point + MyTriMesh::CoordType UnScale(MyTriMesh::CoordType p) + { + MyTriMesh::ScalarType x=(p.V(0))*scale.V(0); + MyTriMesh::ScalarType y=(p.V(1))*scale.V(1); + MyTriMesh::ScalarType z=(p.V(2))*scale.V(2); + return (MyTriMesh::CoordType(x,y,z)); + } + ///scale the coordinates of a point MyTriMesh::CoordType Scale(MyTriMesh::CoordType p) { @@ -295,9 +307,12 @@ private: ///return true if a coordinate is out of limits bool OutOfLimits(MyTriMesh::CoordType p) { - Point3f max=Scale(MapToSpace(V.Max())); + /*Point3f max=Scale(MapToSpace(V.Max())); Point3f min=Scale(MapToSpace(V.Min())); - Point3f test=(Scale(p)); + Point3f test=(Scale(p));*/ + Point3f test=p; + Point3f max=UnScale(MapToSpace(V.Max())); + Point3f min=UnScale(MapToSpace(V.Min())); for (int i=0;i<3;i++) { @@ -376,11 +391,13 @@ void InitMesh(MyTriMesh &m) for (unsigned int i=0;i::PerVertexNormalized(m); + } @@ -439,7 +456,10 @@ void AddExtForces() MyTriMesh::CoordType Inflating=(*vi).N(); MyTriMesh::CoordType Containing0=ContainingForce(&*vi); //MyTriMesh::CoordType Containing1=GradientFactor(&*vi); - (*vi).ExtForce()=Inflating+Containing0*0.75;/*+Containing1+Containing0*/; + Containing0*=0.75; + if (Containing0.Norm()>1) + Containing0.Normalize(); + (*vi).ExtForce()=Inflating+Containing0;/*+Containing1+Containing0*/; } } else @@ -625,12 +645,12 @@ void CollisionDetection() public: ///set the initial barycenter where the triangle mesh start to expand -void SetInitialBarycenter(MyTriMesh::CoordType b) -{ - InitialBarycenter=b; - gray_init=getColor(b); - InitMesh(m); -} +//void SetInitialBarycenter(MyTriMesh::CoordType b) +//{ +// InitialBarycenter=b; +// gray_init=getColor(b); +// /*InitMesh(m);*/ +//} ///set the input output directory of images void LoadFromDir(char *in, char *out) @@ -642,14 +662,13 @@ void LoadFromDir(char *in, char *out) V.Init(1000,outDir);*/ V.Load(inDir); - bbox=vcg::Box3(MapToSpace(V.Min()),MapToSpace(V.Max())); + bbox=vcg::Box3(MapToSpace((V.Min())),(MapToSpace(V.Max()))); } - -///init the segmentation of the mesh -void InitSegmentation(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f, - float Edge_precision=4.f,clock_t _interval=1000,clock_t _interval2=250, - MyTriMesh::CoordType ScaleFactor=MyTriMesh::CoordType(1.f,1.f,1.f) ) +///set parameters for segmentation +void SetSegmentParameters(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f, + float Edge_precision=4.f,Point3f ScaleFactor=Point3f(1.f,1.f,1.f), + clock_t _interval=1000,clock_t _interval2=250) { mass=Mass; k_elanst=K_elanst; @@ -663,9 +682,14 @@ void InitSegmentation(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,floa time_stamp=Time_stamp; k_dihedral=Dihedral; scale=ScaleFactor; +} + +///init the segmentation of the mesh +void InitSegmentation(MyTriMesh::CoordType b) +{ + InitialBarycenter=b; + gray_init=getColor(b); - - TrINT= new myIntegrator(P_Faces,P_Vertex); TrINT->SetPDESolver(PDESolvers::EULER_METHOD); @@ -677,7 +701,8 @@ void InitSegmentation(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,floa //V.Load(inDir); // /*bbox=vcg::Box3(MapToSpace(V.Min()),MapToSpace(V.Max()));*/ - + + InitMesh(m); //init the mesh with new Reinit_PVectors(); ReinitPhysicMesh(); diff --git a/apps/test/segmentation3d/simpleglwidget.cpp b/apps/test/segmentation3d/simpleglwidget.cpp index 4a2983fd..2299f56a 100644 --- a/apps/test/segmentation3d/simpleglwidget.cpp +++ b/apps/test/segmentation3d/simpleglwidget.cpp @@ -291,6 +291,7 @@ void SimpleGLWidget::OpenDirectory() "Choose a Directory" ); if (filename!=NULL) { + filename+="/"; const char *path=filename.ascii(); char *p=(char*)path; s->LoadFromDir(p,"prova.txt"); @@ -334,11 +335,12 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e ) //LoadMatrix(); glReadPixels(e->x(),_H-e->y(),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winz); gluUnProject(e->x(),_H-e->y(),winz,modelMatrix,projection,viewport,&x,&y,&z); - s->SetInitialBarycenter(Point3f(x,y,_numslide)); QString color=""; color.sprintf("%i",s->gray_init); //w->Color->text()=color; SetExtractionParameters(); + //s->SetInitialBarycenter(Point3f(x,y,_numslide)); + s->InitSegmentation(Point3f(x,y,_numslide)); repaint(); } //vcg::tri::UpdateBounding::Box(s->m); @@ -385,9 +387,11 @@ void SimpleGLWidget::SetExtractionParameters() float timestep=atof(w->T_step->text()); float edge=atof(w->E_size->text()); float tolerance=atof(w->Tolerance->text()); + float dinstance=atof(w->S_dist->text()); //int color =atoi(w->Color->text()); ///to modify - s->InitSegmentation(s->gray_init,tolerance,mass,k_elanst,dihedral,timestep,edge); + + s->SetSegmentParameters(s->gray_init,tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance)); } void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e ) diff --git a/apps/test/segmentation3d/volume_dataset.h b/apps/test/segmentation3d/volume_dataset.h index 76f219d7..2c575f67 100644 --- a/apps/test/segmentation3d/volume_dataset.h +++ b/apps/test/segmentation3d/volume_dataset.h @@ -216,9 +216,6 @@ public: Qd.setSorting(QDir::Name); QString PathFile=Path; - if (PathFile.right(1)!="/") - PathFile.append("/"); - PathFile.append(Qd[0]); bool b=qI.load(PathFile,qformat); @@ -421,9 +418,6 @@ public: Qd.setSorting(QDir::Name); QString PathFile=Path; - if (PathFile.right(1)!="/") - PathFile.append("/"); - PathFile.append(Qd[0]); bool b=qI.load(PathFile,qformat); @@ -453,7 +447,7 @@ public: } - inline Point3i Min()//to change in case of difefrent space between sections + inline Point3i Min()//to change in case of different space between sections {return Point3i(0,0,0);} inline Point3i Max()//to change in case of different space between sections