From ab6ca78ee1b9ad2911092dc382e62bd131796e3f Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Wed, 20 Apr 2005 15:20:13 +0000 Subject: [PATCH] minor changes --- apps/test/segmentation3d/main.cpp | 12 +- apps/test/segmentation3d/segmentation3d.pro | 5 +- apps/test/segmentation3d/segmentator.h | 148 ++++++++++++++------ apps/test/segmentation3d/segmentform.ui | 63 ++++----- apps/test/segmentation3d/simpleglwidget.cpp | 12 +- apps/test/segmentation3d/simpleglwidget.h | 30 ++-- 6 files changed, 174 insertions(+), 96 deletions(-) diff --git a/apps/test/segmentation3d/main.cpp b/apps/test/segmentation3d/main.cpp index 94645878..3020fab4 100644 --- a/apps/test/segmentation3d/main.cpp +++ b/apps/test/segmentation3d/main.cpp @@ -30,10 +30,14 @@ int main( int argc, char ** argv ) #ifdef _TORUS - w.simpleGLWidget1->SetExtractionParameters(); - s->BBox().min=Point3f(0.f,0.f,0.f); - s->BBox().max=Point3f(300.f,300.f,300.f); - s->InitSegmentation(Point3f(0.f,100.f,0.f)); + //w.simpleGLWidget1->SetExtractionParameters(); + //s->SetSegmentParameters(10,0.5f,0.2f,0.8f,0.4f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15); + s->SetSegmentParameters(10,0.5f,0.8f,0.65f,0.4f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15); + 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 diff --git a/apps/test/segmentation3d/segmentation3d.pro b/apps/test/segmentation3d/segmentation3d.pro index 821701da..6965ca4e 100644 --- a/apps/test/segmentation3d/segmentation3d.pro +++ b/apps/test/segmentation3d/segmentation3d.pro @@ -16,7 +16,10 @@ SOURCES += D:/sf/wrap/gui/trackmode.cpp \ main.cpp FORMS = segmentform.ui \ d:\sf\apps\test\segmentation3d\segmentform.ui -IMAGES = D:/sf/apps/test/segmentation3d/slider.jpg + + + + diff --git a/apps/test/segmentation3d/segmentator.h b/apps/test/segmentation3d/segmentator.h index 8ac9d305..0ffed032 100644 --- a/apps/test/segmentation3d/segmentator.h +++ b/apps/test/segmentation3d/segmentator.h @@ -128,19 +128,24 @@ public: ((V(1)->blocked)||(V(1)->stopped))&& ((V(2)->blocked)||(V(2)->stopped))))&&(!intersected)); } + + bool HaveVertexActive() + { + return((V(0)->blocked==false)||(V(1)->blocked==false)||(V(2)->blocked==false)); + } bool IsBlocked() { return((V(0)->blocked)&&(V(1)->blocked)&&(V(2)->blocked)); } - + double DiedralAngle(int edge) { MyFace *fopp=FFp(edge); CoordType norm1=NormalizedNormal(); CoordType norm2=fopp->NormalizedNormal(); - return (NormalizedNormal()*fopp->NormalizedNormal()); + return (norm1*norm2); } ///return the bounding box of the simplex @@ -151,10 +156,15 @@ public: return (bb); } + ScalarType ForceValue(ScalarType l0,ScalarType l1) + { + return ((l0-l1)/(l0/l1) *_k); + } + ///update of the internal forces using the dihedral angle 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++) { @@ -166,28 +176,30 @@ public: assert(!fopp->IsD()); assert(fopp!=this); - if ((foppintersected))//test do not duplicate updates per edge { //normal and area based diadedral angle calcolus CoordType DirEdge=(V(i)->P()-V((i+1)%3)->P()).Normalize(); fopp=FFp(i); CoordType Ver=(NormalizedNormal()^fopp->NormalizedNormal()).Normalize(); ScalarType diaedral=DiedralAngle(i); - + ScalarType Force=(((-diaedral)+1.f)*kdihedral); + CoordType VectF=NormalizedNormal()*(Force); if ((Ver*DirEdge)<=0)///convex - { - ScalarType Force=(((-diaedral)+1.f)*kdihedral); - V((i+2)%3)->IntForce()+=NormalizedNormal()*(Force); - V(i)->IntForce()-=NormalizedNormal()*(Force)/2.f; - V((i+1)%3)->IntForce()-=NormalizedNormal()*(Force)/2.f; + { + V((i+2)%3)->IntForce()+=VectF; + fopp->V((FFi(i)+2)%3)->IntForce()+=VectF;///opposite vertex + V(i)->IntForce()-=VectF; + V((i+1)%3)->IntForce()-=VectF; } else ///non-convex { - ScalarType Force=(((-diaedral)+1.f)*kdihedral); - V((i+2)%3)->IntForce()-=NormalizedNormal()*(Force); - V(i)->IntForce()+=NormalizedNormal()*(Force)/2.f; - V((i+1)%3)->IntForce()+=NormalizedNormal()*(Force)/2.f; + V((i+2)%3)->IntForce()-=VectF; + fopp->V((FFi(i)+2)%3)->IntForce()-=VectF;///opposite vertex + V(i)->IntForce()+=VectF; + V((i+1)%3)->IntForce()+=VectF; } + } } } @@ -253,6 +265,7 @@ public: int gray_init; float time_stamp; float edge_precision; + float edge_init; bool end_loop; bool refined; @@ -307,18 +320,43 @@ private: #ifdef _TORUS ///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::PerVertexNormalized(*m); } @@ -531,7 +568,7 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v) void AddExtForces() { Part_VertexContainer::iterator vi; - PartialUpdateNormals(); + //PartialUpdateNormals(); end_loop=true; for (vi=P_Vertex.begin();vi1) Containing0.Normalize(); + Containing0*=0.75; (*vi).ExtForce()=Inflating+Containing0;/*+Containing1+Containing0*/; } } @@ -682,6 +718,8 @@ bool TimeSelfIntersection() void PartialUpdateNormals() { + //vcg::tri::UpdateNormals::PerFaceNormalized(*m); + //vcg::tri::UpdateNormals::PerVertexNormalized(*m); Part_FaceContainer::iterator fi; for (fi=P_Faces.begin();fi 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; - + if( MESH_TYPE::HasPerVertexNormal()) 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::PerFaceNormalized(*m); vcg::tri::UpdateNormals::PerVertexNormalized(*m);*/ + PartialUpdateNormals(); //#ifdef _DEBUG @@ -783,15 +822,22 @@ void ReinitPhysicMesh() { Part_FaceContainer::iterator pfi; - for (pfi=P_Faces.begin();pfi BBox() +vcg::Box3& BBox() { return (bbox); } @@ -934,25 +981,40 @@ void AutoStep() } } -/////set as deleted intersected vertices -//void ClearIntersectedFaces() -//{ -// MyTriMesh::FaceIterator fi; -// for (fi=m->face.begin();fiface.end();fi++) -// if ((*fi).intersected==true) -// (*fi).SetD(); -// -//} +///set as deleted intersected vertices +void ClearIntersectedFaces() +{ + MyTriMesh::FaceIterator fi; + for (fi=m->face.begin();fiface.end();fi++) +#ifdef _TORUS + if (((*fi).intersected==true))///||((*fi).HaveVertexActive())) + { + m->fn--; + (*fi).SetD(); + } +#else + if (((*fi).intersected==true))//||((*fi).HaveVertexActive())) + { + m->fn--; + (*fi).SetD(); + } +#endif +} ///first version void Resample() { - //ClearIntersectedFaces(); + ClearIntersectedFaces(); new_m=new MyTriMesh(); vcg::tri::UpdateBounding::Box(*m); +#ifdef _TORUS vcg::trimesh::Resampler::Resample(*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::Resample(*m,*new_m, + Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision),edge_size*2.f); +#endif +// delete(new_m0); delete(m); m=new_m; diff --git a/apps/test/segmentation3d/segmentform.ui b/apps/test/segmentation3d/segmentform.ui index 370a3ac1..b1d395cb 100644 --- a/apps/test/segmentation3d/segmentform.ui +++ b/apps/test/segmentation3d/segmentform.ui @@ -514,36 +514,6 @@ 1 - - - T_step - - - - 30 - 210 - 70 - 31 - - - - - 10 - - - - LineEditPanel - - - Sunken - - - 0.2 - - - 3 - - SmoothButton @@ -752,13 +722,40 @@ 31 - - slider.jpg - true + + + T_step + + + + 30 + 210 + 70 + 31 + + + + + 10 + + + + LineEditPanel + + + Sunken + + + 0.4 + + + 3 + + diff --git a/apps/test/segmentation3d/simpleglwidget.cpp b/apps/test/segmentation3d/simpleglwidget.cpp index 2a956114..f9c8b101 100644 --- a/apps/test/segmentation3d/simpleglwidget.cpp +++ b/apps/test/segmentation3d/simpleglwidget.cpp @@ -293,12 +293,17 @@ void SimpleGLWidget::glDraw(){ if (s->m!=NULL) { //vcg::tri::UpdateBounding::Box(*(s->m)); +#ifndef _TORUS vcg::Point3f p=s->m->bbox.Center(); +#endif TrackM.GetView(); TrackM.Apply(); 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); +#endif + //glTranslate(-CenterExtraction); //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); - if (fi->intersected) + if ((fi->intersected)&&(wire)) glColor3d(1.f,0,0); if (((blocked)&&(!fi->IsBlocked()))||(!blocked)) @@ -442,6 +447,9 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e ) */ UpdateBBMesh(); TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); +#ifndef _TORUS + CenterExtraction=s->m->bbox.Center(); +#endif } else if (_showslides) TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); diff --git a/apps/test/segmentation3d/simpleglwidget.h b/apps/test/segmentation3d/simpleglwidget.h index da4a1cf2..da0cfed2 100644 --- a/apps/test/segmentation3d/simpleglwidget.h +++ b/apps/test/segmentation3d/simpleglwidget.h @@ -32,11 +32,13 @@ private : bool resultForces; bool continue_int; GLuint texName; + //Segmentator *s; //QTimer *timer; //vcg::GlTrimesh *Wrap; public: + vcg::Point3f CenterExtraction; QString path; SegmentForm *w; SimpleGLWidget( QWidget * parent = 0, const char * name = 0, const QGLWidget * shareWidget = 0, WFlags f = 0 ); @@ -129,20 +131,20 @@ public: void Extract() { - UpdateBBMesh(); + //UpdateBBMesh(); continue_int=!continue_int; - if (continue_int) - { - _showslides=false; - w->SlidesButton->setOn(false); - //((SegmentForm *)this->parent())->SlidesButton->setOn(false); - } - else - { - _showslides=true; - w->SlidesButton->setOn(true); - //((SegmentForm *)this->parent())->SlidesButton->setOn(true); - } + //if (continue_int) + //{ + // _showslides=false; + // w->SlidesButton->setOn(false); + // //((SegmentForm *)this->parent())->SlidesButton->setOn(false); + //} + //else + //{ + // _showslides=true; + // w->SlidesButton->setOn(true); + // //((SegmentForm *)this->parent())->SlidesButton->setOn(true); + //} repaint(); } @@ -161,7 +163,9 @@ public: void CleanMesh() { MarchingCube(); +#ifndef _TORUS UpdateBBMesh(); +#endif repaint(); }