2004-12-17 12:17:36 +01:00
|
|
|
#include <SimpleGLWidget.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qfiledialog.h>
|
2004-12-21 18:38:42 +01:00
|
|
|
#include <qimage.h>
|
2004-12-17 12:17:36 +01:00
|
|
|
#include <qdir.h>
|
|
|
|
#include <qmessagebox.h>
|
2005-02-08 18:47:50 +01:00
|
|
|
#include <qslider.h>
|
2004-12-17 12:17:36 +01:00
|
|
|
|
|
|
|
extern Segmentator *s;
|
|
|
|
|
|
|
|
SimpleGLWidget::SimpleGLWidget( QWidget * parent, const char * name, const QGLWidget * shareWidget, WFlags f ):
|
|
|
|
QGLWidget(parent, name)
|
|
|
|
{
|
|
|
|
|
2005-04-11 11:26:22 +02:00
|
|
|
//grabKeyboard();
|
2004-12-17 12:17:36 +01:00
|
|
|
_showslides=false;
|
|
|
|
blocked=false;
|
|
|
|
wire=true;
|
|
|
|
extForces=false;
|
|
|
|
intForces=false;
|
|
|
|
resultForces=false;
|
|
|
|
continue_int=false;
|
|
|
|
_numslide=0;
|
2005-02-01 19:07:14 +01:00
|
|
|
|
|
|
|
TrackM.center=Point3f(0,0,0);
|
|
|
|
TrackM.Reset();
|
|
|
|
TrackM.radius= 100.f;
|
|
|
|
|
|
|
|
TrackS.center=Point3f(0,0,0);
|
|
|
|
TrackS.Reset();
|
|
|
|
TrackS.radius= 100.f;
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
zoom=1;
|
2004-12-21 18:38:42 +01:00
|
|
|
path="";
|
2005-02-01 19:07:14 +01:00
|
|
|
/*s=new Segmentator();*/
|
|
|
|
//timer = new QTimer(this );
|
|
|
|
//QTimer::connect( timer, SIGNAL(timeout()), this, SLOT(Update()) );
|
|
|
|
// timer->start(0); // 2 seconds single-shot timer
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::SaveMatrix()
|
|
|
|
{
|
|
|
|
glGetDoublev(GL_PROJECTION_MATRIX ,projection);
|
|
|
|
glGetDoublev(GL_MODELVIEW_MATRIX ,modelMatrix);
|
|
|
|
glGetIntegerv(GL_VIEWPORT,viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::LoadMatrix()
|
|
|
|
{
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadMatrixd(projection);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadMatrixd(modelMatrix);
|
|
|
|
}
|
|
|
|
|
2004-12-21 18:38:42 +01:00
|
|
|
//load as texture the i jpg of the directory
|
2005-07-18 17:46:23 +02:00
|
|
|
void SimpleGLWidget::LoadTextureJpg(QString p,int level)
|
2004-12-21 18:38:42 +01:00
|
|
|
{
|
2005-07-18 17:46:23 +02:00
|
|
|
int e=glGetError();
|
|
|
|
|
2004-12-21 18:38:42 +01:00
|
|
|
QImage qI=QImage();
|
|
|
|
QDir Qd=QDir(p);
|
|
|
|
QString qformat;
|
|
|
|
QString Path=QString(p);
|
|
|
|
Qd.setNameFilter("*.jpg");
|
2005-07-18 17:46:23 +02:00
|
|
|
//Qd.setNameFilter("*.bmp");
|
2004-12-21 18:38:42 +01:00
|
|
|
|
|
|
|
Qd.setSorting(QDir::Name);
|
|
|
|
QString PathFile=Path;
|
|
|
|
PathFile.append(Qd[level]);
|
|
|
|
|
2005-02-08 18:47:50 +01:00
|
|
|
qI.load(PathFile,qformat);
|
2004-12-21 18:38:42 +01:00
|
|
|
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);
|
2005-07-18 17:46:23 +02:00
|
|
|
|
|
|
|
e=glGetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//load the texture corrisponding to a level
|
|
|
|
void SimpleGLWidget::LoadTextureRaw(int level)
|
|
|
|
{
|
|
|
|
//glGenTextures(1, &texName);
|
|
|
|
//glBindTexture(GL_TEXTURE_2D, texName);
|
|
|
|
//glTexImage2D( GL_TEXTURE_2D, 0,GL_LUMINANCE, 512, 512, 0,GL_LUMINANCE, GL_SHORT, &s->V.Data[level*512*512] );
|
|
|
|
//glEnable(GL_TEXTURE_2D);
|
|
|
|
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
|
|
|
|
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
|
|
|
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
2004-12-21 18:38:42 +01:00
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
|
|
|
|
void SimpleGLWidget::drawSlide()
|
|
|
|
{
|
2004-12-21 18:38:42 +01:00
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
glPolygonMode(GL_FRONT,GL_FILL);
|
|
|
|
glMatrixMode (GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2005-07-18 17:46:23 +02:00
|
|
|
/*glEnable(GL_NORMALIZE);
|
2004-12-21 18:38:42 +01:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
2005-07-18 17:46:23 +02:00
|
|
|
*/
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_LIGHT0);
|
2004-12-21 18:38:42 +01:00
|
|
|
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);
|
|
|
|
|
2005-07-18 17:46:23 +02:00
|
|
|
glColor3d(0.8,0.8,0.8);
|
2004-12-21 18:38:42 +01:00
|
|
|
|
|
|
|
///texture
|
|
|
|
//_numslide
|
|
|
|
glBegin(GL_QUADS);
|
2004-12-17 12:17:36 +01:00
|
|
|
glNormal(Point3d(0,0,1));
|
2004-12-21 18:38:42 +01:00
|
|
|
glTexCoord(Point3f(0,1,0));
|
2004-12-17 12:17:36 +01:00
|
|
|
glVertex(p0);
|
2004-12-21 18:38:42 +01:00
|
|
|
glTexCoord(Point3f(1,1,0));
|
2004-12-17 12:17:36 +01:00
|
|
|
glVertex(p1);
|
2004-12-21 18:38:42 +01:00
|
|
|
glTexCoord(Point3f(1,0,0));
|
2004-12-17 12:17:36 +01:00
|
|
|
glVertex(p2);
|
2004-12-21 18:38:42 +01:00
|
|
|
glTexCoord(Point3f(0,0,0));
|
2004-12-17 12:17:36 +01:00
|
|
|
glVertex(p3);
|
2004-12-21 18:38:42 +01:00
|
|
|
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<int> p0=Point3<int>(x,y,_numslide);
|
|
|
|
// double color=((double)s->V.getAt(p0))/256.f;
|
|
|
|
// glColor3d(color,color,color);
|
|
|
|
// glVertex(p0);
|
|
|
|
//
|
|
|
|
// Point3<int> p1=Point3<int>(x+1,y,_numslide);
|
|
|
|
// color=((double)s->V.getAt(p1))/256.f;
|
|
|
|
// glColor3d(color,color,color);
|
|
|
|
// glVertex(p1);
|
|
|
|
//
|
|
|
|
// Point3<int> p2=Point3<int>(x+1,y+1,_numslide);
|
|
|
|
// color=((double)s->V.getAt(p2))/256.f;
|
|
|
|
// glColor3d(color,color,color);
|
|
|
|
// glVertex(p2);
|
|
|
|
//
|
|
|
|
// Point3<int> p3=Point3<int>(x,y+1,_numslide);
|
|
|
|
// color=((double)s->V.getAt(p3))/256.f;
|
|
|
|
// glColor3d(color,color,color);
|
|
|
|
// glVertex(p3);
|
|
|
|
// }
|
|
|
|
//glEnd();
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawForces(Segmentator::Part_VertexContainer *pv,int typeForce)
|
|
|
|
{
|
|
|
|
Segmentator::Part_VertexContainer::iterator vi;
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
2005-02-08 18:47:50 +01:00
|
|
|
glLineWidth(0.3f);
|
2004-12-17 12:17:36 +01:00
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
|
|
|
|
|
|
|
if (typeForce==0)
|
|
|
|
glColor3d(1,0,0);
|
|
|
|
else
|
|
|
|
if (typeForce==1)
|
|
|
|
glColor3d(0,0,1);
|
|
|
|
else
|
|
|
|
if (typeForce==2)
|
|
|
|
glColor3d(0,1,0);
|
|
|
|
|
2005-02-08 18:47:50 +01:00
|
|
|
for (vi=pv->begin();vi<pv->end();++vi)
|
2004-12-17 12:17:36 +01:00
|
|
|
{
|
|
|
|
glBegin(GL_LINE_LOOP);
|
|
|
|
vcg::glVertex((*vi).P());
|
|
|
|
if (typeForce==0)
|
|
|
|
vcg::glVertex((*vi).P()+((*vi).IntForce()*4.f));
|
|
|
|
else
|
|
|
|
if (typeForce==1)
|
|
|
|
vcg::glVertex((*vi).P()+((*vi).ExtForce()*4.f));
|
|
|
|
else
|
|
|
|
if (typeForce==2)
|
|
|
|
vcg::glVertex((*vi).P()+(((*vi).ExtForce()+(*vi).IntForce())*4.f));
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::Save()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getSaveFileName("prova.ply",
|
|
|
|
"Ply files (*.ply)",
|
|
|
|
this,
|
|
|
|
"save file dialog",
|
|
|
|
"Choose a filename to save under" );
|
|
|
|
if (filename!=NULL)
|
|
|
|
{
|
2004-12-21 18:38:42 +01:00
|
|
|
const char *path_save=filename.ascii();
|
2005-02-01 19:07:14 +01:00
|
|
|
vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),path_save);
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TimeSelfIntersection()
|
|
|
|
{
|
|
|
|
static clock_t time=0;
|
|
|
|
clock_t elapsedsecs=abs(time-clock());
|
|
|
|
if (elapsedsecs>500)
|
|
|
|
{
|
|
|
|
time=clock();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//void SimpleGLWidget::WriteInfo()
|
|
|
|
//{
|
|
|
|
//
|
|
|
|
// if (s!=0)
|
|
|
|
// {
|
|
|
|
//
|
|
|
|
// glPushAttrib(0xffffffff);
|
|
|
|
//
|
|
|
|
// glEnable(GL_BLEND);
|
|
|
|
// glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
|
|
|
|
// glEnable(GL_LIGHTING);
|
|
|
|
// glEnable(GL_NORMALIZE);
|
|
|
|
// glEnable(GL_COLOR_MATERIAL);
|
|
|
|
// glDisable(GL_CLIP_PLANE0);
|
|
|
|
// glColor4d(0.7,0,0.7,0.6);
|
|
|
|
//
|
|
|
|
// glDepthRange(0.0,0.1);
|
|
|
|
//
|
|
|
|
// glBegin(GL_QUADS);
|
|
|
|
// glVertex3d(-0.5,-0.5,0);
|
|
|
|
// glVertex3d(-0.5,-0.3,0);
|
|
|
|
// glVertex3d(0.5,-0.3,0);
|
|
|
|
// glVertex3d(0.5,-0.5,0);
|
|
|
|
// glEnd();
|
|
|
|
//
|
|
|
|
// renderText( (width() - 10) / 2, 15, "a" );
|
|
|
|
//
|
|
|
|
// QFont f( "arial", 12 );
|
|
|
|
// QFontMetrics fmc( f );
|
|
|
|
// glColor3d(1,1,1);
|
|
|
|
//
|
|
|
|
// QString str="";
|
|
|
|
// int level=0;
|
|
|
|
//
|
|
|
|
// glDisable( GL_LIGHTING );
|
|
|
|
// glDisable( GL_TEXTURE_2D );
|
|
|
|
//
|
|
|
|
// level++;
|
|
|
|
// str.sprintf( "Triangles : %i Vertex: %i ",s->m.fn,s->m.vn);
|
|
|
|
// renderText( 20, height() - level*20, str, f );
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
void SimpleGLWidget::SmoothMesh()
|
|
|
|
{
|
|
|
|
s->Smooth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::glDraw(){
|
2005-07-18 17:46:23 +02:00
|
|
|
//glClearColor(0.2f,0.2f,0.2f,1.f);
|
|
|
|
glClearColor(1.f,1.f,1.f,1.f);
|
2004-12-17 12:17:36 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (s!=0){
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
if (_showslides)
|
|
|
|
{
|
|
|
|
vcg::Point3f p=Point3f((float)s->BBox().Center().V(0),(float)s->BBox().Center().V(1),(float)s->BBox().Center().V(2));
|
2005-02-01 19:07:14 +01:00
|
|
|
TrackS.radius=s->BBox().Diag();
|
|
|
|
TrackS.GetView();
|
|
|
|
TrackS.Apply();
|
|
|
|
TrackS.Draw();
|
2004-12-21 18:38:42 +01:00
|
|
|
glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag());
|
2005-02-01 19:07:14 +01:00
|
|
|
//glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom));
|
2004-12-17 12:17:36 +01:00
|
|
|
glTranslate(-p);
|
|
|
|
//save transformation matrixes
|
|
|
|
SaveMatrix();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
if (s->m!=NULL)
|
|
|
|
{
|
|
|
|
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
2005-04-20 17:20:13 +02:00
|
|
|
#ifndef _TORUS
|
2005-02-01 19:07:14 +01:00
|
|
|
vcg::Point3f p=s->m->bbox.Center();
|
2005-04-20 17:20:13 +02:00
|
|
|
#endif
|
2005-02-01 19:07:14 +01:00
|
|
|
TrackM.GetView();
|
|
|
|
TrackM.Apply();
|
|
|
|
TrackM.Draw();
|
2005-04-20 17:20:13 +02:00
|
|
|
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
|
|
|
|
#ifndef _TORUS
|
2005-02-01 19:07:14 +01:00
|
|
|
glTranslate(-p);
|
2005-04-20 17:20:13 +02:00
|
|
|
#endif
|
|
|
|
//glTranslate(-CenterExtraction);
|
2005-02-01 19:07:14 +01:00
|
|
|
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
|
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
if (_showslides)
|
|
|
|
drawSlide();
|
|
|
|
|
|
|
|
if (intForces)
|
|
|
|
drawForces(&s->P_Vertex,0);
|
|
|
|
if (extForces)
|
|
|
|
drawForces(&s->P_Vertex,1);
|
|
|
|
if (resultForces)
|
|
|
|
drawForces(&s->P_Vertex,2);
|
|
|
|
|
|
|
|
//draw faces
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
2004-12-21 18:38:42 +01:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2004-12-17 12:17:36 +01:00
|
|
|
|
|
|
|
Segmentator::MyTriMesh::FaceIterator fi;
|
|
|
|
|
|
|
|
|
|
|
|
if (wire)
|
|
|
|
{
|
|
|
|
glDisable(GL_NORMALIZE);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glPolygonMode(GL_FRONT,GL_FILL);
|
|
|
|
|
2005-02-01 19:07:14 +01:00
|
|
|
if (s->m!=NULL)
|
2004-12-17 12:17:36 +01:00
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for (fi=s->m->face.begin();fi<s->m->face.end();fi++)
|
|
|
|
{
|
2005-02-08 18:47:50 +01:00
|
|
|
if(!(*fi).IsD())
|
|
|
|
{
|
2005-04-11 11:26:22 +02:00
|
|
|
/*if ((!fi->V(0)->IsR())||(!fi->V(1)->IsR())||(!fi->V(2)->IsR()))
|
|
|
|
assert(0);
|
|
|
|
*/
|
|
|
|
|
2005-07-18 17:46:23 +02:00
|
|
|
//glColor3d(0.4,0.8,0.8);
|
|
|
|
if (wire)
|
|
|
|
{
|
|
|
|
glColor3d(0,0,0);
|
|
|
|
glLineWidth(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
glColor3d(0.4,0.8,0.8);
|
2005-04-20 17:20:13 +02:00
|
|
|
if ((fi->intersected)&&(wire))
|
2005-02-08 18:47:50 +01:00
|
|
|
glColor3d(1.f,0,0);
|
|
|
|
|
|
|
|
if (((blocked)&&(!fi->IsBlocked()))||(!blocked))
|
|
|
|
{
|
|
|
|
if (!wire)
|
|
|
|
{
|
|
|
|
vcg::glNormal(fi->V(0)->N());
|
|
|
|
vcg::glVertex(fi->V(0)->P());
|
|
|
|
vcg::glNormal(fi->V(1)->N());
|
|
|
|
vcg::glVertex(fi->V(1)->P());
|
|
|
|
vcg::glNormal(fi->V(2)->N());
|
|
|
|
vcg::glVertex(fi->V(2)->P());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vcg::glVertex(fi->V(0)->P());
|
|
|
|
vcg::glVertex(fi->V(1)->P());
|
|
|
|
vcg::glVertex(fi->V(2)->P());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
2005-02-08 18:47:50 +01:00
|
|
|
glPopMatrix();
|
|
|
|
//WriteInfo();
|
2004-12-17 12:17:36 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
QGLWidget::glDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
///open the directiry and initialize dataset
|
|
|
|
void SimpleGLWidget::OpenDirectory()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getExistingDirectory(
|
|
|
|
".",
|
|
|
|
this,
|
|
|
|
"open file dialog"
|
|
|
|
"Choose a Directory" );
|
|
|
|
if (filename!=NULL)
|
|
|
|
{
|
2005-07-18 17:46:23 +02:00
|
|
|
rawImage=false;
|
2004-12-20 18:56:01 +01:00
|
|
|
filename+="/";
|
2004-12-21 18:38:42 +01:00
|
|
|
path=filename;
|
|
|
|
const char *pa=filename.ascii();
|
|
|
|
char *p=(char*)pa;
|
2004-12-17 12:17:36 +01:00
|
|
|
s->LoadFromDir(p,"prova.txt");
|
2005-07-18 17:46:23 +02:00
|
|
|
LoadTextureJpg(p,0);
|
|
|
|
_showslides=true;
|
|
|
|
w->SlidesButton->setOn(true);
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///open the directiry and initialize dataset
|
|
|
|
void SimpleGLWidget::OpenRaw()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getOpenFileName(
|
|
|
|
"D:/Endocas/",
|
|
|
|
"Raw Files(*.raw)",
|
|
|
|
this,
|
|
|
|
"open file dialog"
|
|
|
|
"Choose a Raw file" );
|
|
|
|
|
|
|
|
if (filename!=NULL)
|
|
|
|
{
|
|
|
|
rawImage=true;
|
|
|
|
const char *pa=filename.ascii();
|
|
|
|
char *p=(char*)pa;
|
|
|
|
s->LoadFromRaw(p);
|
|
|
|
LoadTextureRaw(0);
|
2004-12-21 18:38:42 +01:00
|
|
|
_showslides=true;
|
|
|
|
w->SlidesButton->setOn(true);
|
|
|
|
repaint();
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::resizeGL( int w, int h )
|
|
|
|
{
|
|
|
|
// setup viewport, projection etc.:
|
|
|
|
glMatrixMode (GL_PROJECTION);
|
|
|
|
glLoadIdentity ();
|
|
|
|
float ratio=(float)w/(float)h;
|
|
|
|
gluPerspective(45,ratio,1,20);
|
|
|
|
_W=w;
|
|
|
|
_H=h;
|
|
|
|
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
|
|
|
glMatrixMode (GL_MODELVIEW);
|
|
|
|
repaint();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::ClearMesh()
|
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
s->m->Clear();
|
2004-12-17 12:17:36 +01:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
2005-02-01 19:07:14 +01:00
|
|
|
void SimpleGLWidget::UpdateBBMesh()
|
|
|
|
{
|
|
|
|
vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
|
|
|
|
void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
|
|
|
|
{
|
|
|
|
if (e->button()==Qt::LeftButton )
|
2005-02-01 19:07:14 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if ((!_showslides)&&(s->m!=NULL))
|
|
|
|
{
|
|
|
|
/*vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
|
|
|
TrackM.radius=s->m->bbox.Diag();
|
|
|
|
TrackM.center=s->m->bbox.Center();
|
|
|
|
*/
|
|
|
|
UpdateBBMesh();
|
|
|
|
TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
2005-04-20 17:20:13 +02:00
|
|
|
#ifndef _TORUS
|
|
|
|
CenterExtraction=s->m->bbox.Center();
|
|
|
|
#endif
|
2005-02-01 19:07:14 +01:00
|
|
|
}
|
|
|
|
else if (_showslides)
|
|
|
|
TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
else
|
|
|
|
//test mass spring model
|
|
|
|
if ((e->button()==Qt::RightButton)&&(_showslides))
|
|
|
|
{
|
|
|
|
float winz;
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double z;
|
|
|
|
//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);
|
2005-02-08 18:47:50 +01:00
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
SetExtractionParameters();
|
2004-12-21 18:38:42 +01:00
|
|
|
s->InitSegmentation(Point3f(x,y,z));
|
2005-02-08 18:47:50 +01:00
|
|
|
w->slider1->setValue(s->gray_init);
|
|
|
|
|
2005-02-01 19:07:14 +01:00
|
|
|
UpdateBBMesh();
|
|
|
|
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
|
2004-12-17 12:17:36 +01:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m);
|
|
|
|
}
|
|
|
|
|
2005-02-08 18:47:50 +01:00
|
|
|
void SimpleGLWidget::setColor()
|
|
|
|
{
|
|
|
|
s->gray_init=w->slider1->value();
|
|
|
|
}
|
|
|
|
|
2005-04-11 11:26:22 +02:00
|
|
|
///only for debugghing
|
|
|
|
void SimpleGLWidget::keyPressEvent(QKeyEvent *k)
|
|
|
|
{
|
|
|
|
s->AutoStep();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
void SimpleGLWidget::wheelEvent(QWheelEvent *e)
|
|
|
|
{
|
|
|
|
if (!_showslides)
|
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
/* zoom+=e->delta()/120.f;
|
|
|
|
repaint();*/
|
|
|
|
TrackM.MouseWheel(e->delta()/120.f);
|
2004-12-17 12:17:36 +01:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int oldnum=_numslide;
|
|
|
|
_numslide+=e->delta()/120.f;
|
|
|
|
if ((_numslide<0)||(_numslide>=s->V.dimZ()))
|
|
|
|
_numslide=oldnum;
|
2004-12-21 18:38:42 +01:00
|
|
|
if (s!=0)
|
|
|
|
{
|
2005-07-18 17:46:23 +02:00
|
|
|
if (!rawImage)
|
|
|
|
LoadTextureJpg(path,_numslide);
|
|
|
|
else
|
|
|
|
LoadTextureRaw(_numslide);
|
2004-12-21 18:38:42 +01:00
|
|
|
}
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::mouseReleaseEvent(QMouseEvent * e )
|
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
if (!_showslides)
|
|
|
|
TrackM.MouseUp(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
|
|
|
else
|
|
|
|
TrackS.MouseUp(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::Step()
|
|
|
|
{
|
|
|
|
if ((s!=0)&&(continue_int))
|
|
|
|
{
|
|
|
|
s->AutoStep();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-18 17:46:23 +02:00
|
|
|
//void SimpleGLWidget::MarchingCubesExtraction()
|
|
|
|
// {
|
|
|
|
// if (s!=0)
|
|
|
|
// {
|
|
|
|
// s->MarchingCubeExtraction();
|
|
|
|
// repaint();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2005-02-01 19:07:14 +01:00
|
|
|
void SimpleGLWidget::MarchingCube()
|
|
|
|
{
|
|
|
|
if (s->m->fn>0)
|
|
|
|
s->Resample();
|
|
|
|
|
|
|
|
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->new_m),"d:/march.ply");
|
|
|
|
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),"d:/march.ply");
|
|
|
|
}
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
void SimpleGLWidget::SetExtractionParameters()
|
|
|
|
{
|
|
|
|
float mass=atof(w->M_particles->text());
|
|
|
|
float k_elanst=atof(w->K_elanst->text());
|
|
|
|
float dihedral=atof(w->D_angle->text());
|
|
|
|
float timestep=atof(w->T_step->text());
|
|
|
|
float edge=atof(w->E_size->text());
|
|
|
|
float tolerance=atof(w->Tolerance->text());
|
2004-12-20 18:56:01 +01:00
|
|
|
float dinstance=atof(w->S_dist->text());
|
2004-12-17 12:17:36 +01:00
|
|
|
//int color =atoi(w->Color->text());
|
|
|
|
///to modify
|
2004-12-20 18:56:01 +01:00
|
|
|
|
2005-02-08 18:47:50 +01:00
|
|
|
s->SetSegmentParameters(tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance));
|
2004-12-17 12:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )
|
|
|
|
{
|
2005-02-01 19:07:14 +01:00
|
|
|
if (_showslides)
|
|
|
|
TrackS.MouseMove(e->x(),_H-e->y());
|
|
|
|
else
|
|
|
|
TrackM.MouseMove(e->x(),_H-e->y());
|
|
|
|
|
2004-12-17 12:17:36 +01:00
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleGLWidget::initializeGL(){
|
|
|
|
|
2005-02-08 18:47:50 +01:00
|
|
|
GLfloat f[4]={0.2f,0.2f,0.2f,1.f};
|
2004-12-17 12:17:36 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|