minor changes

This commit is contained in:
Nico Pietroni 2004-10-07 13:14:37 +00:00
parent 4dc937e514
commit 8c83d3d4d0
3 changed files with 73 additions and 65 deletions

View File

@ -122,22 +122,6 @@ void MyGLWidget::DrawTextInfo()
renderText(x,y,z,str,f); renderText(x,y,z,str,f);
} }
Stats.TCurrent()->SetS(); Stats.TCurrent()->SetS();
////show the tetrahedron
//glBegin(GL_LINE_LOOP);
//for (int i=0;i<4;i++)
//{
// glVertex(Stats.TCurrent()->V(i)->P());
//}
//glEnd();
//glBegin(GL_LINE_LOOP);
// glVertex(Stats.TCurrent()->V(0)->P());
// glVertex(Stats.TCurrent()->V(2)->P());
//glEnd();
//glBegin(GL_LINE_LOOP);
// glVertex(Stats.TCurrent()->V(1)->P());
// glVertex(Stats.TCurrent()->V(3)->P());
//glEnd();
////end drawing
} }
glPopAttrib(); glPopAttrib();
} }
@ -324,7 +308,7 @@ else if (e->button()==Qt::RightButton)
vcg::GLPickTetra<MyTetraMesh>::PickNearestTetra(e->x(),_H-e->y(),*tm,ti); vcg::GLPickTetra<MyTetraMesh>::PickNearestTetra(e->x(),_H-e->y(),*tm,ti);
if (ti!=0) if (ti!=0)
{ {
Stats.TetraInfo(&*ti); Stats.SetTetraInfo(&*ti);
} }
} }
@ -382,12 +366,10 @@ void MyGLWidget::wheelEvent ( QWheelEvent * e ){
void MyGLWidget::keyPressEvent(QKeyEvent *k) void MyGLWidget::keyPressEvent(QKeyEvent *k)
{ {
mouse_modality=MMTrackball; if (k->key()==Qt::Key_Escape)//&&((mouse_modality==MMNavigateSection)||(mouse_modality==MMSection)))
if ((k->key()==Qt::Key_Escape)&&((mouse_modality==MMNavigateSection)||(mouse_modality==MMSection)))
{ {
mouse_modality=MMTrackball; mouse_modality=MMTrackball;
/*wp->SectionButton->setOn(false); WT->ClearClipSection();
QString p=wp->TrackButton->text();*/
} }
} }

View File

@ -11,7 +11,7 @@ public:
double volume; double volume;
double ratio; double ratio;
TetraStats(){} TetraStats(){T=0;}
~TetraStats(){} ~TetraStats(){}
@ -55,11 +55,18 @@ void Update()
volume=ComputeVolume(Tetra); volume=ComputeVolume(Tetra);
} }
void TetraInfo(TetraType *Te) void SetTetraInfo(TetraType *Te)
{ {
if (T!=0)
T->ClearS();
T=Te; T=Te;
} }
void ClearTetraInfo(TetraType *Te)
{
T=0;
}
TetraType * TCurrent() TetraType * TCurrent()
{ {
return T; return T;

View File

@ -34,7 +34,6 @@ public:
class ClipPlane class ClipPlane
{ {
private: private:
Point3x D; Point3x D;
Point3x D0; Point3x D0;
GLdouble eqn[4]; GLdouble eqn[4];
@ -46,10 +45,12 @@ public:
Point3x pp3; Point3x pp3;
public: public:
bool active;
Point3x P; Point3x P;
ClipPlane (){} ClipPlane (){active=false;}
~ClipPlane (){} ~ClipPlane (){}
@ -90,13 +91,15 @@ public:
void GlClip() void GlClip()
{ {
GLdouble d=-(D.V(0)*P.V(0)+D.V(1)*P.V(1)+D.V(2)*P.V(2)); if (active){
eqn[0]=-D.V(0); GLdouble d=-(D.V(0)*P.V(0)+D.V(1)*P.V(1)+D.V(2)*P.V(2));
eqn[1]=-D.V(1); eqn[0]=-D.V(0);
eqn[2]=-D.V(2); eqn[1]=-D.V(1);
eqn[3]=-d; eqn[2]=-D.V(2);
glClipPlane(GL_CLIP_PLANE0, eqn); eqn[3]=-d;
glEnable(GL_CLIP_PLANE0); glClipPlane(GL_CLIP_PLANE0, eqn);
glEnable(GL_CLIP_PLANE0);
}
} }
void GlDraw() void GlDraw()
@ -143,14 +146,14 @@ public:
}; };
GLWrapTetra(CONT_TETRA & _t):tetra(_t){nsection=0;} GLWrapTetra(CONT_TETRA & _t):tetra(_t){}
CONT_TETRA & tetra; CONT_TETRA & tetra;
ClipPlane section; ClipPlane section;
private: private:
double shrink_factor; double shrink_factor;
int nsection;
public: public:
@ -163,7 +166,12 @@ public:
void AddClipSection(Point3x p0,Point3x p1,Point3x p2) void AddClipSection(Point3x p0,Point3x p1,Point3x p2)
{ {
section=ClipPlane(p0,p1,p2); section=ClipPlane(p0,p1,p2);
nsection++; section.active=true;
}
void ClearClipSection()
{
section.active=false;
} }
typedef Color4b (*color_func_vertex)(VertexType&v); typedef Color4b (*color_func_vertex)(VertexType&v);
@ -198,23 +206,23 @@ template <ColorMode cm >
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_FRONT,GL_FILL);
if (nsection!=0) if (section.active)
{ {
section.GlClip(); section.GlClip();
section.GlDraw(); section.GlDraw();
} }
glBegin(GL_TRIANGLES); /*glBegin(GL_TRIANGLES);*/
for( it = tetra.begin(); it != tetra.end(); ++it) for( it = tetra.begin(); it != tetra.end(); ++it)
if((!it->IsD())&&(!(it->IsS()))) //draw as normal if((!it->IsD())&&(!(it->IsS()))) //draw as normal
{ {
_DrawSmallTetra<cm>(*it); _DrawSmallTetra<cm>(*it);
} }
else else
if((!it->IsD())&&(!(it->IsS())))//draw in selection mode if((!it->IsD())&&((it->IsS())))//draw in selection mode
{ {
_DrawSelectedTetra(*it); _DrawSelectedTetra(*it);
} }
glEnd(); //glEnd();
glPopAttrib(); glPopAttrib();
} }
@ -251,10 +259,10 @@ void _DrawSurface(){
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_FRONT,GL_FILL);
} }
glBegin(GL_TRIANGLES); //glBegin(GL_TRIANGLES);
for( it = tetra.begin(); it != tetra.end(); ++it) for( it = tetra.begin(); it != tetra.end(); ++it)
_DrawTetra<dm,nm,cm>((*it)); _DrawTetra<dm,nm,cm>((*it));
glEnd(); //glEnd();
glPopAttrib(); glPopAttrib();
} }
@ -263,21 +271,24 @@ void _DrawSelectedTetra(TetraType &t)
{ {
glPushMatrix(); glPushMatrix();
glPushAttrib(0xffff); glPushAttrib(0xffff);
glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE0);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE); glDisable(GL_NORMALIZE);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glBegin(GL_LINE_LOOP); glColor3d(1,0,0);
glColor3d(1,0,0);
for (int face=0;face<4;face++) glBegin(GL_TRIANGLES);
{ for (int face=0;face<4;face++)
glVertex(t.V(Tetra::VofF(face,0))->P()); {
glVertex(t.V(Tetra::VofF(face,1))->P()); glVertex(t.V(Tetra::VofF(face,0))->P());
glVertex(t.V(Tetra::VofF(face,2))->P()); glVertex(t.V(Tetra::VofF(face,1))->P());
} glVertex(t.V(Tetra::VofF(face,2))->P());
//end drawing }
glEnd();
//end drawing
glPopAttrib(); glPopAttrib();
glPopMatrix(); glPopMatrix();
} }
@ -355,20 +366,24 @@ void _DrawFaceSmooth(TetraType &t,int face)
VertexType *v0=t.V(Tetra::VofF(face,0)); VertexType *v0=t.V(Tetra::VofF(face,0));
VertexType *v1=t.V(Tetra::VofF(face,1)); VertexType *v1=t.V(Tetra::VofF(face,1));
VertexType *v2=t.V(Tetra::VofF(face,2)); VertexType *v2=t.V(Tetra::VofF(face,2));
_ChooseColorVertex<cm>(*v0);
glNormal(v0->N()); glBegin(GL_TRIANGLES);
glVertex(v0->P()); _ChooseColorVertex<cm>(*v0);
_ChooseColorVertex<cm>(*v1); glNormal(v0->N());
glNormal(v1->N()); glVertex(v0->P());
glVertex(v1->P()); _ChooseColorVertex<cm>(*v1);
_ChooseColorVertex<cm>(*v2); glNormal(v1->N());
glNormal(v2->N()); glVertex(v1->P());
glVertex(v2->P()); _ChooseColorVertex<cm>(*v2);
glNormal(v2->N());
glVertex(v2->P());
glEnd();
} }
template <ColorMode cm > template <ColorMode cm >
void _DrawFace(TetraType &t,int face) void _DrawFace(TetraType &t,int face)
{ {
glBegin(GL_TRIANGLES);
glNormal(t.N(face)); glNormal(t.N(face));
VertexType *v0=t.V(Tetra::VofF(face,0)); VertexType *v0=t.V(Tetra::VofF(face,0));
VertexType *v1=t.V(Tetra::VofF(face,1)); VertexType *v1=t.V(Tetra::VofF(face,1));
@ -379,6 +394,7 @@ void _DrawFace(TetraType &t,int face)
glVertex(v1->P()); glVertex(v1->P());
_ChooseColorVertex<cm>(*v2); _ChooseColorVertex<cm>(*v2);
glVertex(v2->P()); glVertex(v2->P());
glEnd();
} }
template <ColorMode cm > template <ColorMode cm >
@ -394,6 +410,8 @@ void _DrawSmallTetra(TetraType &t)
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
p[i] = t.V(i)->P()* shrink_factor + br *(1- shrink_factor); p[i] = t.V(i)->P()* shrink_factor + br *(1- shrink_factor);
_ChooseColorTetra<cm>(t); _ChooseColorTetra<cm>(t);
glBegin(GL_TRIANGLES);
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
glNormal(t.N(i)); glNormal(t.N(i));
@ -407,6 +425,7 @@ void _DrawSmallTetra(TetraType &t)
_ChooseColorVertex<cm>(*v2); _ChooseColorVertex<cm>(*v2);
glVertex(p[Tetra::VofF(i,2)]); glVertex(p[Tetra::VofF(i,2)]);
} }
glEnd();
} }