first release version

This commit is contained in:
Nico Pietroni 2004-12-20 17:56:01 +00:00
parent 7c59d90735
commit c618354a24
5 changed files with 58 additions and 35 deletions

View File

@ -12,11 +12,11 @@ QTimer *timer;
int main( int argc, char ** argv ) int main( int argc, char ** argv )
{ {
//s=new Segmentator(); s=new Segmentator();
//s->LoadFromDir("./venacava/","prova.txt");//to chANGE //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 ); QApplication a( argc, argv );
@ -26,7 +26,7 @@ int main( int argc, char ** argv )
//assign pointer to pricipal form //assign pointer to pricipal form
w.simpleGLWidget1->w=&w; w.simpleGLWidget1->w=&w;
s=new Segmentator(); /*s=new Segmentator();*/
//s->LoadFromDir("./venacava/","prova.txt");//to chANGE //s->LoadFromDir("./venacava/","prova.txt");//to chANGE

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
** SimpleGLWidget meta object code from reading C++ file 'simpleglwidget.h' ** SimpleGLWidget meta object code from reading C++ file 'simpleglwidget.h'
** **
** Created: Fri Dec 17 12:16:05 2004 ** Created: Sat Dec 18 11:09:46 2004
** by: The Qt MOC ($Id: moc_simpleglwidget.cpp,v 1.1 2004-12-17 11:17:36 pietroni Exp $) ** 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! ** WARNING! All changes made in this file will be lost!
*****************************************************************************/ *****************************************************************************/

View File

@ -238,9 +238,12 @@ private:
float getColor(MyTriMesh::CoordType p) 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 lx=(p.V(0)-(int)p.V(0))*scale.V(0);//da rivedere bene per lo scale
float lz=p.V(2)-(int)p.V(2);//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)); Point3i base=Point3i((int)p.V(0),(int)p.V(1),(int)p.V(2));
@ -283,6 +286,15 @@ private:
return (ret); 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 ///scale the coordinates of a point
MyTriMesh::CoordType Scale(MyTriMesh::CoordType p) MyTriMesh::CoordType Scale(MyTriMesh::CoordType p)
{ {
@ -295,9 +307,12 @@ private:
///return true if a coordinate is out of limits ///return true if a coordinate is out of limits
bool OutOfLimits(MyTriMesh::CoordType p) bool OutOfLimits(MyTriMesh::CoordType p)
{ {
Point3f max=Scale(MapToSpace(V.Max())); /*Point3f max=Scale(MapToSpace(V.Max()));
Point3f min=Scale(MapToSpace(V.Min())); 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++) for (int i=0;i<3;i++)
{ {
@ -376,11 +391,13 @@ void InitMesh(MyTriMesh &m)
for (unsigned int i=0;i<m.vert.size();i++) for (unsigned int i=0;i<m.vert.size();i++)
{ {
m.vert[i].P()+=InitialBarycenter; m.vert[i].P()+=InitialBarycenter;
m.vert[i].P()=UnScale(m.vert[i].P());
// P_Vertex.push_back(&m.vert[i]); // P_Vertex.push_back(&m.vert[i]);
} }
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(m); vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(m);
} }
@ -439,7 +456,10 @@ void AddExtForces()
MyTriMesh::CoordType Inflating=(*vi).N(); MyTriMesh::CoordType Inflating=(*vi).N();
MyTriMesh::CoordType Containing0=ContainingForce(&*vi); MyTriMesh::CoordType Containing0=ContainingForce(&*vi);
//MyTriMesh::CoordType Containing1=GradientFactor(&*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 else
@ -625,12 +645,12 @@ void CollisionDetection()
public: public:
///set the initial barycenter where the triangle mesh start to expand ///set the initial barycenter where the triangle mesh start to expand
void SetInitialBarycenter(MyTriMesh::CoordType b) //void SetInitialBarycenter(MyTriMesh::CoordType b)
{ //{
InitialBarycenter=b; // InitialBarycenter=b;
gray_init=getColor(b); // gray_init=getColor(b);
InitMesh(m); // /*InitMesh(m);*/
} //}
///set the input output directory of images ///set the input output directory of images
void LoadFromDir(char *in, char *out) void LoadFromDir(char *in, char *out)
@ -642,14 +662,13 @@ void LoadFromDir(char *in, char *out)
V.Init(1000,outDir);*/ V.Init(1000,outDir);*/
V.Load(inDir); V.Load(inDir);
bbox=vcg::Box3<float>(MapToSpace(V.Min()),MapToSpace(V.Max())); bbox=vcg::Box3<float>(MapToSpace((V.Min())),(MapToSpace(V.Max())));
} }
///set parameters for segmentation
///init the segmentation of the mesh void SetSegmentParameters(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f,
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,Point3f ScaleFactor=Point3f(1.f,1.f,1.f),
float Edge_precision=4.f,clock_t _interval=1000,clock_t _interval2=250, clock_t _interval=1000,clock_t _interval2=250)
MyTriMesh::CoordType ScaleFactor=MyTriMesh::CoordType(1.f,1.f,1.f) )
{ {
mass=Mass; mass=Mass;
k_elanst=K_elanst; k_elanst=K_elanst;
@ -663,8 +682,13 @@ void InitSegmentation(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,floa
time_stamp=Time_stamp; time_stamp=Time_stamp;
k_dihedral=Dihedral; k_dihedral=Dihedral;
scale=ScaleFactor; 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= new myIntegrator(P_Faces,P_Vertex);
@ -678,6 +702,7 @@ void InitSegmentation(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,floa
// //
/*bbox=vcg::Box3<float>(MapToSpace(V.Min()),MapToSpace(V.Max()));*/ /*bbox=vcg::Box3<float>(MapToSpace(V.Min()),MapToSpace(V.Max()));*/
InitMesh(m);
//init the mesh with new //init the mesh with new
Reinit_PVectors(); Reinit_PVectors();
ReinitPhysicMesh(); ReinitPhysicMesh();

View File

@ -291,6 +291,7 @@ void SimpleGLWidget::OpenDirectory()
"Choose a Directory" ); "Choose a Directory" );
if (filename!=NULL) if (filename!=NULL)
{ {
filename+="/";
const char *path=filename.ascii(); const char *path=filename.ascii();
char *p=(char*)path; char *p=(char*)path;
s->LoadFromDir(p,"prova.txt"); s->LoadFromDir(p,"prova.txt");
@ -334,11 +335,12 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
//LoadMatrix(); //LoadMatrix();
glReadPixels(e->x(),_H-e->y(),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winz); 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); gluUnProject(e->x(),_H-e->y(),winz,modelMatrix,projection,viewport,&x,&y,&z);
s->SetInitialBarycenter(Point3f(x,y,_numslide));
QString color=""; QString color="";
color.sprintf("%i",s->gray_init); color.sprintf("%i",s->gray_init);
//w->Color->text()=color; //w->Color->text()=color;
SetExtractionParameters(); SetExtractionParameters();
//s->SetInitialBarycenter(Point3f(x,y,_numslide));
s->InitSegmentation(Point3f(x,y,_numslide));
repaint(); repaint();
} }
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m);
@ -385,9 +387,11 @@ void SimpleGLWidget::SetExtractionParameters()
float timestep=atof(w->T_step->text()); float timestep=atof(w->T_step->text());
float edge=atof(w->E_size->text()); float edge=atof(w->E_size->text());
float tolerance=atof(w->Tolerance->text()); float tolerance=atof(w->Tolerance->text());
float dinstance=atof(w->S_dist->text());
//int color =atoi(w->Color->text()); //int color =atoi(w->Color->text());
///to modify ///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 ) void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )

View File

@ -216,9 +216,6 @@ public:
Qd.setSorting(QDir::Name); Qd.setSorting(QDir::Name);
QString PathFile=Path; QString PathFile=Path;
if (PathFile.right(1)!="/")
PathFile.append("/");
PathFile.append(Qd[0]); PathFile.append(Qd[0]);
bool b=qI.load(PathFile,qformat); bool b=qI.load(PathFile,qformat);
@ -421,9 +418,6 @@ public:
Qd.setSorting(QDir::Name); Qd.setSorting(QDir::Name);
QString PathFile=Path; QString PathFile=Path;
if (PathFile.right(1)!="/")
PathFile.append("/");
PathFile.append(Qd[0]); PathFile.append(Qd[0]);
bool b=qI.load(PathFile,qformat); 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);} {return Point3i(0,0,0);}
inline Point3i Max()//to change in case of different space between sections inline Point3i Max()//to change in case of different space between sections