minor changes

This commit is contained in:
Nico Pietroni 2005-04-20 15:20:13 +00:00
parent 08f4270101
commit ab6ca78ee1
6 changed files with 174 additions and 96 deletions

View File

@ -30,10 +30,14 @@ int main( int argc, char ** argv )
#ifdef _TORUS #ifdef _TORUS
w.simpleGLWidget1->SetExtractionParameters(); //w.simpleGLWidget1->SetExtractionParameters();
s->BBox().min=Point3f(0.f,0.f,0.f); //s->SetSegmentParameters(10,0.5f,0.2f,0.8f,0.4f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15);
s->BBox().max=Point3f(300.f,300.f,300.f); s->SetSegmentParameters(10,0.5f,0.8f,0.65f,0.4f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15);
s->InitSegmentation(Point3f(0.f,100.f,0.f)); s->BBox().min=Point3f(-40.f,-40.f,-40.f);
s->BBox().max=Point3f(40.f,40.f,40.f);
s->InitSegmentation(Point3f(0.f,25.f,0.f));
w.simpleGLWidget1->CenterExtraction=vcg::Point3f(0.f,-25.f,0.f);
s->gray_init=100;
#endif #endif

View File

@ -16,7 +16,10 @@ SOURCES += D:/sf/wrap/gui/trackmode.cpp \
main.cpp main.cpp
FORMS = segmentform.ui \ FORMS = segmentform.ui \
d:\sf\apps\test\segmentation3d\segmentform.ui d:\sf\apps\test\segmentation3d\segmentform.ui
IMAGES = D:/sf/apps/test/segmentation3d/slider.jpg

View File

@ -128,19 +128,24 @@ public:
((V(1)->blocked)||(V(1)->stopped))&& ((V(1)->blocked)||(V(1)->stopped))&&
((V(2)->blocked)||(V(2)->stopped))))&&(!intersected)); ((V(2)->blocked)||(V(2)->stopped))))&&(!intersected));
} }
bool HaveVertexActive()
{
return((V(0)->blocked==false)||(V(1)->blocked==false)||(V(2)->blocked==false));
}
bool IsBlocked() bool IsBlocked()
{ {
return((V(0)->blocked)&&(V(1)->blocked)&&(V(2)->blocked)); return((V(0)->blocked)&&(V(1)->blocked)&&(V(2)->blocked));
} }
double DiedralAngle(int edge) double DiedralAngle(int edge)
{ {
MyFace *fopp=FFp(edge); MyFace *fopp=FFp(edge);
CoordType norm1=NormalizedNormal(); CoordType norm1=NormalizedNormal();
CoordType norm2=fopp->NormalizedNormal(); CoordType norm2=fopp->NormalizedNormal();
return (NormalizedNormal()*fopp->NormalizedNormal()); return (norm1*norm2);
} }
///return the bounding box of the simplex ///return the bounding box of the simplex
@ -151,10 +156,15 @@ public:
return (bb); return (bb);
} }
ScalarType ForceValue(ScalarType l0,ScalarType l1)
{
return ((l0-l1)/(l0/l1) *_k);
}
///update of the internal forces using the dihedral angle ///update of the internal forces using the dihedral angle
bool Update ( void ) bool Update ( void )
{ {
if (!IsD())//if this face is not deleted if (!IsD()&&(!intersected))//if this face is not deleted
{ {
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
{ {
@ -166,28 +176,30 @@ public:
assert(!fopp->IsD()); assert(!fopp->IsD());
assert(fopp!=this); assert(fopp!=this);
if ((fopp<myAddr))//test do not duplicate updates per edge if ((fopp<myAddr)&&(!fopp->intersected))//test do not duplicate updates per edge
{ {
//normal and area based diadedral angle calcolus //normal and area based diadedral angle calcolus
CoordType DirEdge=(V(i)->P()-V((i+1)%3)->P()).Normalize(); CoordType DirEdge=(V(i)->P()-V((i+1)%3)->P()).Normalize();
fopp=FFp(i); fopp=FFp(i);
CoordType Ver=(NormalizedNormal()^fopp->NormalizedNormal()).Normalize(); CoordType Ver=(NormalizedNormal()^fopp->NormalizedNormal()).Normalize();
ScalarType diaedral=DiedralAngle(i); ScalarType diaedral=DiedralAngle(i);
ScalarType Force=(((-diaedral)+1.f)*kdihedral);
CoordType VectF=NormalizedNormal()*(Force);
if ((Ver*DirEdge)<=0)///convex if ((Ver*DirEdge)<=0)///convex
{ {
ScalarType Force=(((-diaedral)+1.f)*kdihedral); V((i+2)%3)->IntForce()+=VectF;
V((i+2)%3)->IntForce()+=NormalizedNormal()*(Force); fopp->V((FFi(i)+2)%3)->IntForce()+=VectF;///opposite vertex
V(i)->IntForce()-=NormalizedNormal()*(Force)/2.f; V(i)->IntForce()-=VectF;
V((i+1)%3)->IntForce()-=NormalizedNormal()*(Force)/2.f; V((i+1)%3)->IntForce()-=VectF;
} }
else ///non-convex else ///non-convex
{ {
ScalarType Force=(((-diaedral)+1.f)*kdihedral); V((i+2)%3)->IntForce()-=VectF;
V((i+2)%3)->IntForce()-=NormalizedNormal()*(Force); fopp->V((FFi(i)+2)%3)->IntForce()-=VectF;///opposite vertex
V(i)->IntForce()+=NormalizedNormal()*(Force)/2.f; V(i)->IntForce()+=VectF;
V((i+1)%3)->IntForce()+=NormalizedNormal()*(Force)/2.f; V((i+1)%3)->IntForce()+=VectF;
} }
} }
} }
} }
@ -253,6 +265,7 @@ public:
int gray_init; int gray_init;
float time_stamp; float time_stamp;
float edge_precision; float edge_precision;
float edge_init;
bool end_loop; bool end_loop;
bool refined; bool refined;
@ -307,18 +320,43 @@ private:
#ifdef _TORUS #ifdef _TORUS
///torus version ///torus version
/*float getColor(MyTriMesh::CoordType p)
{
static float ray=25.f;
static float diameter=4.f;
float dist=p.Norm();
float difference=abs(ray-dist);
float z=fabs(p.Z());
if((difference<diameter)&&(z<diameter))
return (100.f);
else
return (0.f);
}*/
bool InTorus(MyTriMesh::CoordType p)
{
static float ray=25.f;
static float diameter=4.f;
double fatt=(p.X()*p.X()+p.Y()*p.Y());
double fatt1=(ray-math::Sqrt(fatt));
double fatt2=fatt1*fatt1+p.Z()*p.Z();
double conf=diameter*diameter;
///now swap
return (fatt2<=conf);
}
float getColor(MyTriMesh::CoordType p) float getColor(MyTriMesh::CoordType p)
{ {
static float ray=100.f; MyTriMesh::CoordType p1=MyTriMesh::CoordType(p.X(),p.Z(),p.Y());
static float diameter=20.f; //MyTriMesh::CoordType p2=MyTriMesh::CoordType(p.Z(),p.Y(),p.X());
Point3f center=BBox().Center();
float dist=(p-center).Norm();
float difference=abs(ray-dist); if (InTorus(p)||InTorus(p1))//||InTorus(p2))
if(difference<diameter) return (100.f);
return 100.f;
else else
return (100.f+difference*5.f); return (0.f);
} }
#else #else
///return integer coordinete in volumetric dataset ///return integer coordinete in volumetric dataset
float getColor(MyTriMesh::CoordType p) float getColor(MyTriMesh::CoordType p)
@ -492,7 +530,6 @@ void InitMesh(MyTriMesh *m)
// 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);
} }
@ -531,7 +568,7 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
void AddExtForces() void AddExtForces()
{ {
Part_VertexContainer::iterator vi; Part_VertexContainer::iterator vi;
PartialUpdateNormals(); //PartialUpdateNormals();
end_loop=true; end_loop=true;
for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi) for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi)
{ {
@ -556,10 +593,9 @@ 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);
Containing0*=0.75;
if (Containing0.Norm()>1) if (Containing0.Norm()>1)
Containing0.Normalize(); Containing0.Normalize();
Containing0*=0.75;
(*vi).ExtForce()=Inflating+Containing0;/*+Containing1+Containing0*/; (*vi).ExtForce()=Inflating+Containing0;/*+Containing1+Containing0*/;
} }
} }
@ -682,6 +718,8 @@ bool TimeSelfIntersection()
void PartialUpdateNormals() void PartialUpdateNormals()
{ {
//vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
//vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);
Part_FaceContainer::iterator fi; Part_FaceContainer::iterator fi;
for (fi=P_Faces.begin();fi<P_Faces.end();++fi) for (fi=P_Faces.begin();fi<P_Faces.end();++fi)
if (!(*fi).IsD()) if (!(*fi).IsD())
@ -725,7 +763,7 @@ struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0;
nv.RPos()=(ep.f->V(ep.z)->RPos()+ep.f->V1(ep.z)->RPos())/2.0; nv.RPos()=(ep.f->V(ep.z)->RPos()+ep.f->V1(ep.z)->RPos())/2.0;
if( MESH_TYPE::HasPerVertexNormal()) if( MESH_TYPE::HasPerVertexNormal())
nv.N()= (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N()).Normalize(); nv.N()= (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N()).Normalize();
@ -768,6 +806,7 @@ void RefineStep(float _edge_size)
} }
/*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m); /*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/ vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/
PartialUpdateNormals(); PartialUpdateNormals();
//#ifdef _DEBUG //#ifdef _DEBUG
@ -783,15 +822,22 @@ void ReinitPhysicMesh()
{ {
Part_FaceContainer::iterator pfi; Part_FaceContainer::iterator pfi;
for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi) /*for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi)
if((!(*pfi).IsD())&&((!(*pfi).intersected))) if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral); (*pfi).Init(k_elanst,mass,k_dihedral);*/
Part_VertexContainer::iterator pvi; Part_VertexContainer::iterator pvi;
for (pvi=P_Vertex.begin();pvi<P_Vertex.end();++pvi) for (pvi=P_Vertex.begin();pvi<P_Vertex.end();++pvi)
if(!(*pvi).IsD()) if(!(*pvi).IsD())
(*pvi).SetRestPos(); (*pvi).SetRestPos();
for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi)
if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral);
//PartialUpdateNormals();
/*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++) /*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
ClearStopped(&*vi);*/ ClearStopped(&*vi);*/
} }
@ -851,7 +897,7 @@ void LoadFromDir(char *in, char *out)
///set parameters for segmentation ///set parameters for segmentation
void SetSegmentParameters(int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f, void SetSegmentParameters(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,Point3f ScaleFactor=Point3f(1.f,1.f,1.f),
clock_t _interval=1000,clock_t _interval2=250) clock_t _interval=2000,clock_t _interval2=250)
{ {
mass=Mass; mass=Mass;
k_elanst=K_elanst; k_elanst=K_elanst;
@ -861,6 +907,7 @@ void SetSegmentParameters(int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihe
interval_selfcollision=_interval2; interval_selfcollision=_interval2;
edge_size=16.f; edge_size=16.f;
edge_init=edge_size;
edge_precision=Edge_precision; edge_precision=Edge_precision;
time_stamp=Time_stamp; time_stamp=Time_stamp;
k_dihedral=Dihedral; k_dihedral=Dihedral;
@ -890,7 +937,7 @@ void InitSegmentation(MyTriMesh::CoordType b)
} }
///return the bounding box of the mesh ///return the bounding box of the mesh
vcg::Box3<float> BBox() vcg::Box3<float>& BBox()
{ {
return (bbox); return (bbox);
} }
@ -934,25 +981,40 @@ void AutoStep()
} }
} }
/////set as deleted intersected vertices ///set as deleted intersected vertices
//void ClearIntersectedFaces() void ClearIntersectedFaces()
//{ {
// MyTriMesh::FaceIterator fi; MyTriMesh::FaceIterator fi;
// for (fi=m->face.begin();fi<m->face.end();fi++) for (fi=m->face.begin();fi<m->face.end();fi++)
// if ((*fi).intersected==true) #ifdef _TORUS
// (*fi).SetD(); if (((*fi).intersected==true))///||((*fi).HaveVertexActive()))
// {
//} m->fn--;
(*fi).SetD();
}
#else
if (((*fi).intersected==true))//||((*fi).HaveVertexActive()))
{
m->fn--;
(*fi).SetD();
}
#endif
}
///first version ///first version
void Resample() void Resample()
{ {
//ClearIntersectedFaces(); ClearIntersectedFaces();
new_m=new MyTriMesh(); new_m=new MyTriMesh();
vcg::tri::UpdateBounding<MyTriMesh>::Box(*m); vcg::tri::UpdateBounding<MyTriMesh>::Box(*m);
#ifdef _TORUS
vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m, vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m,
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision)); Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision),edge_init);
#else
vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m,
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision),edge_size*2.f);
#endif
// delete(new_m0);
delete(m); delete(m);
m=new_m; m=new_m;

View File

@ -514,36 +514,6 @@
<number>1</number> <number>1</number>
</property> </property>
</widget> </widget>
<widget class="QLineEdit">
<property name="name">
<cstring>T_step</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>210</y>
<width>70</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="text">
<string>0.2</string>
</property>
<property name="cursorPosition">
<number>3</number>
</property>
</widget>
<widget class="QPushButton"> <widget class="QPushButton">
<property name="name"> <property name="name">
<cstring>SmoothButton</cstring> <cstring>SmoothButton</cstring>
@ -752,13 +722,40 @@
<height>31</height> <height>31</height>
</rect> </rect>
</property> </property>
<property name="pixmap">
<pixmap>slider.jpg</pixmap>
</property>
<property name="scaledContents"> <property name="scaledContents">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="QLineEdit">
<property name="name">
<cstring>T_step</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>210</y>
<width>70</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="text">
<string>0.4</string>
</property>
<property name="cursorPosition">
<number>3</number>
</property>
</widget>
</widget> </widget>
</hbox> </hbox>
</widget> </widget>

View File

@ -293,12 +293,17 @@ void SimpleGLWidget::glDraw(){
if (s->m!=NULL) if (s->m!=NULL)
{ {
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m)); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
#ifndef _TORUS
vcg::Point3f p=s->m->bbox.Center(); vcg::Point3f p=s->m->bbox.Center();
#endif
TrackM.GetView(); TrackM.GetView();
TrackM.Apply(); TrackM.Apply();
TrackM.Draw(); TrackM.Draw();
glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag()); //glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
#ifndef _TORUS
glTranslate(-p); glTranslate(-p);
#endif
//glTranslate(-CenterExtraction);
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag()); //glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
} }
} }
@ -348,7 +353,7 @@ void SimpleGLWidget::glDraw(){
*/ */
glColor3d(0.4,0.8,0.8); glColor3d(0.4,0.8,0.8);
if (fi->intersected) if ((fi->intersected)&&(wire))
glColor3d(1.f,0,0); glColor3d(1.f,0,0);
if (((blocked)&&(!fi->IsBlocked()))||(!blocked)) if (((blocked)&&(!fi->IsBlocked()))||(!blocked))
@ -442,6 +447,9 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
*/ */
UpdateBBMesh(); UpdateBBMesh();
TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
#ifndef _TORUS
CenterExtraction=s->m->bbox.Center();
#endif
} }
else if (_showslides) else if (_showslides)
TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);

View File

@ -32,11 +32,13 @@ private :
bool resultForces; bool resultForces;
bool continue_int; bool continue_int;
GLuint texName; GLuint texName;
//Segmentator *s; //Segmentator *s;
//QTimer *timer; //QTimer *timer;
//vcg::GlTrimesh<Segmentator::MyTriMesh> *Wrap; //vcg::GlTrimesh<Segmentator::MyTriMesh> *Wrap;
public: public:
vcg::Point3f CenterExtraction;
QString path; QString path;
SegmentForm *w; SegmentForm *w;
SimpleGLWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 ); SimpleGLWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 );
@ -129,20 +131,20 @@ public:
void Extract() void Extract()
{ {
UpdateBBMesh(); //UpdateBBMesh();
continue_int=!continue_int; continue_int=!continue_int;
if (continue_int) //if (continue_int)
{ //{
_showslides=false; // _showslides=false;
w->SlidesButton->setOn(false); // w->SlidesButton->setOn(false);
//((SegmentForm *)this->parent())->SlidesButton->setOn(false); // //((SegmentForm *)this->parent())->SlidesButton->setOn(false);
} //}
else //else
{ //{
_showslides=true; // _showslides=true;
w->SlidesButton->setOn(true); // w->SlidesButton->setOn(true);
//((SegmentForm *)this->parent())->SlidesButton->setOn(true); // //((SegmentForm *)this->parent())->SlidesButton->setOn(true);
} //}
repaint(); repaint();
} }
@ -161,7 +163,9 @@ public:
void CleanMesh() void CleanMesh()
{ {
MarchingCube(); MarchingCube();
#ifndef _TORUS
UpdateBBMesh(); UpdateBBMesh();
#endif
repaint(); repaint();
} }