From 34cce21f3a8a443b3986275a46ac5a7dbe196a3f Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Tue, 3 Jan 2006 11:18:57 +0000 Subject: [PATCH] *** empty log message *** --- .../test/segmentation3d/collision_detection.h | 168 --- apps/test/segmentation3d/main.cpp | 58 - .../segmentation3d/moc_simpleglwidget.cpp | 137 -- apps/test/segmentation3d/partial_container.h | 53 - apps/test/segmentation3d/segmentation3d.pro | 292 ----- apps/test/segmentation3d/segmentator.h | 1106 ----------------- apps/test/segmentation3d/segmentform.ui | 1014 --------------- apps/test/segmentation3d/simpleglwidget.cpp | 652 ---------- apps/test/segmentation3d/simpleglwidget.h | 208 ---- apps/test/segmentation3d/volume_dataset.h | 519 -------- 10 files changed, 4207 deletions(-) delete mode 100644 apps/test/segmentation3d/collision_detection.h delete mode 100644 apps/test/segmentation3d/main.cpp delete mode 100644 apps/test/segmentation3d/moc_simpleglwidget.cpp delete mode 100644 apps/test/segmentation3d/partial_container.h delete mode 100644 apps/test/segmentation3d/segmentation3d.pro delete mode 100644 apps/test/segmentation3d/segmentator.h delete mode 100644 apps/test/segmentation3d/segmentform.ui delete mode 100644 apps/test/segmentation3d/simpleglwidget.cpp delete mode 100644 apps/test/segmentation3d/simpleglwidget.h delete mode 100644 apps/test/segmentation3d/volume_dataset.h diff --git a/apps/test/segmentation3d/collision_detection.h b/apps/test/segmentation3d/collision_detection.h deleted file mode 100644 index 16feb610..00000000 --- a/apps/test/segmentation3d/collision_detection.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef COLLISION_DETECTION -#define COLLISION_DETECTION - -#include -#include -#include - -template -class Collision_Detector{ - -public: - - typedef typename ContSimplex::value_type SimplexType; - typedef typename ContSimplex::value_type* SimplexPointer; - typedef typename ContSimplex::iterator SimplexIterator; - typedef typename SimplexType::CoordType CoordType; - typedef typename CoordType::ScalarType ScalarType; - typedef typename vcg::Box3 Box3x; - - typedef DynamicSpatialHashTable HashingTable; - - Collision_Detector(ContSimplex & r_):_simplex(r_){}; - ~Collision_Detector(){}; - - ContSimplex & _simplex; - - HashingTable *HTable; - - std::set vactive; - - int active; - - //control if two faces share an edge - bool ShareEdge(SimplexType *f0,SimplexType *f1) - { - assert((!f0->IsD())&&(!f1->IsD())); - for (int i=0;i<3;i++) - if (f0->FFp(i)==f1) - return (true); - - return(false); - } - - ///initialize the box for collision detection and the dimension of a cell - void Init(CoordType _min,CoordType _max,ScalarType _l) - { - HTable=new HashingTable(); - Box3x bb(_min,_max); - CoordType d=((_max-_min)/_l); - vcg::Point3i dim; - dim.Import(d); - HTable->InitEmpty(bb,dim); - } - - //control if two faces share a vertex - bool ShareVertex(SimplexType *f0,SimplexType *f1) - { - assert((!f0->IsD())&&(!f1->IsD())); - for (int i=0;i<3;i++) - for (int j=0;j<3;j++) - if (f0->V(i)==f1->V(j)) - return (true); - - return(false); - } - - //test real intersection between faces - bool TestRealIntersection(SimplexType *f0,SimplexType *f1) - { - assert((!f0->IsD())&&(!f1->IsD())); - if ((!f0->IsActive())&&(!f1->IsActive())) - return false; - //no adiacent faces - assert(f0!=f1); - if ((f0!=f1)&& (!ShareEdge(f0,f1))&&!ShareVertex(f0,f1)) - { - //vcg::Segment3 segm; - //bool copl=false; - return (vcg::Intersection((*f0),(*f1)));//,copl,segm)) - //return ((copl)||(segm.Length()>0.001)); - } - return false; - } - - ///refresh all the elements of spatial hashing table - void RefreshElements() - { - HTable->Clear(); - vactive.clear(); - - HTable->tempMark=0; - - for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si) - { - if (!(*si).IsD()) - { - (*si).HMark()=0; - vcg::Box3i cells=HTable->Add(&*si); - if ((*si).IsActive()) - { - vcg::Box3i cells=HTable->Add(&*si); - for (int x=cells.min.X(); x<=cells.max.X();x++) - for (int y=cells.min.Y(); y<=cells.max.Y();y++) - for (int z=cells.min.Z(); z<=cells.max.Z();z++) - vactive.insert(vcg::Point3i(x,y,z)); - } - } - } - } - - - - - ///put active cells on apposite structure - template - void UpdateStep(Container_Type &simplex) - { - vactive.clear(); - HTable->UpdateTmark(); - for (Container_Type::iterator si=simplex.begin();siAdd(&*si); - for (int x=cells.min.X();x<=cells.max.X();x++) - for (int y=cells.min.Y();y<=cells.max.Y();y++) - for (int z=cells.min.Z();z<=cells.max.Z();z++) - vactive.insert(vcg::Point3i(x,y,x)); - } - } - } - - - - ///control the real self intersection in the mesh and returns the elements that intersect with someone - std::vector computeSelfIntersection() - { - std::vector ret; - std::set::iterator act; - for (act=vactive.begin();act!=vactive.end();act++) - { - Point3i p=*act; - HashingTable::IteHtable I; - if (HTable->numElemCell(p,I)>=2) - { - std::vector inCell; - inCell.clear(); - HTable->getInCellUpdated(p,inCell); - int nelem=inCell.size(); - if (nelem>=2) - { - //test combinations of elements - for (int i=0;iIsD())&&(!inCell[j]->IsD())&&(TestRealIntersection(inCell[i],inCell[j]))) - { - ret.push_back(inCell[i]); - ret.push_back(inCell[j]); - } - } - - } - } - return ret; - } - -}; -#endif \ No newline at end of file diff --git a/apps/test/segmentation3d/main.cpp b/apps/test/segmentation3d/main.cpp deleted file mode 100644 index 8f037706..00000000 --- a/apps/test/segmentation3d/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include -//#include -#include -#include -#include -#include - - -Segmentator *s; -QTimer *timer; - - -int main( int argc, char ** argv ) -{ - s=new Segmentator(); - - //s->LoadFromDir("./venacava/","prova.txt");//to chANGE - - //s->InitSegmentation(0.5,0.2,20,10.f); - - QApplication a( argc, argv ); - - SegmentForm w; - w.show(); - - //assign pointer to pricipal form - w.simpleGLWidget1->w=&w; - - - #ifdef _TORUS - //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,30); - s->SetSegmentParameters(10,0.5f,0.6f,0.25f,0.2f,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(-25.f,0.f,0.f)); - w.simpleGLWidget1->CenterExtraction=vcg::Point3f(0.f,-25.f,0.f); - s->gray_init=100; - #endif - - - /*s=new Segmentator();*/ - - //s->LoadFromDir("./venacava/","prova.txt");//to chANGE - - ////s->InitSegmentation(0.5,0.2,20,10.f); - //w.simpleGLWidget1->path="./venacava/"; - - timer = new QTimer(w.simpleGLWidget1 ); - QTimer::connect( timer, SIGNAL(timeout()), w.simpleGLWidget1, SLOT(Update()) ); - timer->start(0); // - - - a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); - return a.exec(); -} diff --git a/apps/test/segmentation3d/moc_simpleglwidget.cpp b/apps/test/segmentation3d/moc_simpleglwidget.cpp deleted file mode 100644 index 0f3faded..00000000 --- a/apps/test/segmentation3d/moc_simpleglwidget.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** SimpleGLWidget meta object code from reading C++ file 'simpleglwidget.h' -** -** Created: Sat Dec 18 11:09:46 2004 -** 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! -*****************************************************************************/ - -#undef QT_NO_COMPAT -#include "simpleglwidget.h" -#include -#include - -#include -#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26) -#error "This file was generated using the moc from 3.3.2. It" -#error "cannot be used with the include files from this version of Qt." -#error "(The moc has changed too much.)" -#endif - -const char *SimpleGLWidget::className() const -{ - return "SimpleGLWidget"; -} - -QMetaObject *SimpleGLWidget::metaObj = 0; -static QMetaObjectCleanUp cleanUp_SimpleGLWidget( "SimpleGLWidget", &SimpleGLWidget::staticMetaObject ); - -#ifndef QT_NO_TRANSLATION -QString SimpleGLWidget::tr( const char *s, const char *c ) -{ - if ( qApp ) - return qApp->translate( "SimpleGLWidget", s, c, QApplication::DefaultCodec ); - else - return QString::fromLatin1( s ); -} -#ifndef QT_NO_TRANSLATION_UTF8 -QString SimpleGLWidget::trUtf8( const char *s, const char *c ) -{ - if ( qApp ) - return qApp->translate( "SimpleGLWidget", s, c, QApplication::UnicodeUTF8 ); - else - return QString::fromUtf8( s ); -} -#endif // QT_NO_TRANSLATION_UTF8 - -#endif // QT_NO_TRANSLATION - -QMetaObject* SimpleGLWidget::staticMetaObject() -{ - if ( metaObj ) - return metaObj; - QMetaObject* parentObject = QGLWidget::staticMetaObject(); - static const QUMethod slot_0 = {"Open", 0, 0 }; - static const QUMethod slot_1 = {"ShowSlides", 0, 0 }; - static const QUMethod slot_2 = {"SetWire", 0, 0 }; - static const QUMethod slot_3 = {"SetShowBlocked", 0, 0 }; - static const QUMethod slot_4 = {"ShowExternalForces", 0, 0 }; - static const QUMethod slot_5 = {"ShowInternalForces", 0, 0 }; - static const QUMethod slot_6 = {"ShowResultForces", 0, 0 }; - static const QUMethod slot_7 = {"Smooth", 0, 0 }; - static const QUMethod slot_8 = {"SavePly", 0, 0 }; - static const QUMethod slot_9 = {"Apply", 0, 0 }; - static const QUMethod slot_10 = {"Extract", 0, 0 }; - static const QUMethod slot_11 = {"Update", 0, 0 }; - static const QUMethod slot_12 = {"Clear", 0, 0 }; - static const QMetaData slot_tbl[] = { - { "Open()", &slot_0, QMetaData::Public }, - { "ShowSlides()", &slot_1, QMetaData::Public }, - { "SetWire()", &slot_2, QMetaData::Public }, - { "SetShowBlocked()", &slot_3, QMetaData::Public }, - { "ShowExternalForces()", &slot_4, QMetaData::Public }, - { "ShowInternalForces()", &slot_5, QMetaData::Public }, - { "ShowResultForces()", &slot_6, QMetaData::Public }, - { "Smooth()", &slot_7, QMetaData::Public }, - { "SavePly()", &slot_8, QMetaData::Public }, - { "Apply()", &slot_9, QMetaData::Public }, - { "Extract()", &slot_10, QMetaData::Public }, - { "Update()", &slot_11, QMetaData::Public }, - { "Clear()", &slot_12, QMetaData::Public } - }; - metaObj = QMetaObject::new_metaobject( - "SimpleGLWidget", parentObject, - slot_tbl, 13, - 0, 0, -#ifndef QT_NO_PROPERTIES - 0, 0, - 0, 0, -#endif // QT_NO_PROPERTIES - 0, 0 ); - cleanUp_SimpleGLWidget.setMetaObject( metaObj ); - return metaObj; -} - -void* SimpleGLWidget::qt_cast( const char* clname ) -{ - if ( !qstrcmp( clname, "SimpleGLWidget" ) ) - return this; - return QGLWidget::qt_cast( clname ); -} - -bool SimpleGLWidget::qt_invoke( int _id, QUObject* _o ) -{ - switch ( _id - staticMetaObject()->slotOffset() ) { - case 0: Open(); break; - case 1: ShowSlides(); break; - case 2: SetWire(); break; - case 3: SetShowBlocked(); break; - case 4: ShowExternalForces(); break; - case 5: ShowInternalForces(); break; - case 6: ShowResultForces(); break; - case 7: Smooth(); break; - case 8: SavePly(); break; - case 9: Apply(); break; - case 10: Extract(); break; - case 11: Update(); break; - case 12: Clear(); break; - default: - return QGLWidget::qt_invoke( _id, _o ); - } - return TRUE; -} - -bool SimpleGLWidget::qt_emit( int _id, QUObject* _o ) -{ - return QGLWidget::qt_emit(_id,_o); -} -#ifndef QT_NO_PROPERTIES - -bool SimpleGLWidget::qt_property( int id, int f, QVariant* v) -{ - return QGLWidget::qt_property( id, f, v); -} - -bool SimpleGLWidget::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; } -#endif // QT_NO_PROPERTIES diff --git a/apps/test/segmentation3d/partial_container.h b/apps/test/segmentation3d/partial_container.h deleted file mode 100644 index 93fd0651..00000000 --- a/apps/test/segmentation3d/partial_container.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __PARTIALCONT__ -#define __PARTIALCONT__ - -#include - -template -struct Partial_Container : STL_CONT -{ - - - typedef typename STL_CONT::iterator ite_father; - - typedef ELEM value_type; - -public: -struct iterator{ - - ite_father i; - iterator (){} - iterator (ite_father i_):i(i_){} - - ELEM &operator *(){return *(*i);} - - void operator ++() - { - ///((i!=(STL_CONT::end()))&& da controllare la fine - //while ((*i)->IsInvalid())++i; - ++i; - } - - iterator operator =(const iterator & oth){ - i=oth.i; - return *this; - } - - bool operator ==(const iterator & oth){ - return (i==oth.i); - } - bool operator !=(const iterator & oth){ - return (i!=oth.i); - } - - bool operator <(const iterator & oth){ - return (i -// #include -//#else - -#include -#include - -//#endif - -#include -#include - - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -//#include - -class Segmentator{ - -public: - - struct DummyEdge; - struct DummyTetra; - struct MyFace; - - //#ifdef _EXTENDED_MARCH - // struct MyVertex: public ParticleBasic > - //#else - struct MyVertex: public ParticleBasic > - //#endif - { - public: - - bool blocked;//optimize after with vertex flags - bool stopped; - - MyVertex() - { - blocked=false; - stopped=false; - Acc()=CoordType(0,0,0); - Vel()=CoordType(0,0,0); - ClearFlags(); - //__super:: - //neeed call of the super class - } - - void UpdateAcceleration() - { - if ((!blocked)&&(!stopped)) - { - Acc()=(IntForce()+ExtForce())/Mass(); - } - else - { - Acc()=CoordType(0,0,0); - Vel()=CoordType(0,0,0); - } - } - - void Reset() - { - IntForce()=CoordType(0.f,0.f,0.f); - } - - void SetRestPos() - { - RPos()=P(); - } - - }; - - ///this class implements the deformable triangle in a mass spring system - struct MyFace : public TriangleMassSpring< vcg::FaceAFAVFNFMRT > - { - public: - bool intersected; - float kdihedral; - ScalarType AreaRep; - int _HMark; - - CoordType old_N; - - MyFace() - { - intersected=false; - ClearFlags(); - } - - bool NormInversion() - { - return (((old_N*NormalizedNormal())<0)||(Normal().Norm()<0.01)); - } - - void Init ( double k, double mass,float k_dihedral ) - { - __super::Init(k,mass); - kdihedral=k_dihedral; - AreaRep=((V(1)->RPos() - V(0)->RPos()) ^ (V(2)->RPos() - V(0)->RPos())).Norm(); - SetS(); - ComputeNormal(); - old_N=Normal(); - old_N.Normalize(); - } - - bool IsActive() - { - return((!(((V(0)->blocked)||(V(0)->stopped))&& - ((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 (norm1*norm2); - } - - inline int &HMark() - {return (_HMark);} - - ///return the bounding box of the simplex - vcg::Box3 BBox() - { - vcg::Box3 bb; - GetBBox(bb); - return (bb); - } - - ScalarType ForceValue(ScalarType l0,ScalarType l1) - { - ScalarType diff=(l0-l1); - if (diff>0)//compression - return ((diff/(l1))*_k)+(diff *_k); - else - return (diff *_k); - } - - ///update of the internal forces using the dihedral angle - bool Update ( void ) - { - if (!IsD())//&&(!intersected))//if this face is not deleted - { - for (int i=0;i<3;i++) - { - if (!IsBorder(i)) - { - MyFace *fopp=FFp(i); - MyFace *myAddr=this; - - assert(!fopp->IsD()); - assert(fopp!=this); - - if ((foppintersected))//test do not duplicate updates per edge - { - /////updateing spring force - //ScalarType stretch; - //CoordType direction; - //stretch=ForceValue(L(i),(V(i)->P()-V((i+1)%3)->P()).Norm()); - //direction=(V(i)->P()-V((i+1)%3)->P()); - //direction.Normalize(); - //V(i)-> IntForce()+=direction*(stretch)/2.f-DampFactor(i); - //V((i+1)%3)-> IntForce()+=direction*(-stretch)/2.f-DampFactor(i); - - //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 - { - 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 - { - 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; - } - - } - } - } - return(__super::Update()); - } - return true; - ///new - } - }; - - struct MyTriMesh: public vcg::tri::TriMesh,std::vector >{}; - - typedef Partial_Container,MyVertex> Part_VertexContainer; - typedef Partial_Container,MyFace> Part_FaceContainer; - typedef PDEIntegrator myIntegrator; - typedef Collision_Detector > Collision; - - - ////typedef Walker MyWalk; - // - //#ifdef _EXTENDED_MARCH - // typedef vcg::tri::ExtendedMarchingCubes MarchingCubes; - //#else - // typedef vcg::tri::MarchingCubes MarchingCubes; - //#endif - - -public: - Point3f scale; - - //VolumetricDataset d; - /*MyTriMesh m; - MyTriMesh new_m;*/ - - MyTriMesh *m; - MyTriMesh *new_m; - - Part_FaceContainer P_Faces; - Part_VertexContainer P_Vertex; - Part_VertexContainer V_Stopped; - myIntegrator *TrINT; - - MyTriMesh::CoordType InitialBarycenter; - - float mass; - float k_elanst; - float k_dihedral; - float edge_size; - int tolerance; - int gray_init; - float time_stamp; - float edge_precision; - float edge_init; - - bool end_loop; - bool refined; - - clock_t interval_reinit; - clock_t interval_selfcollision; - - Collision *CollDet; - - //Volume_Dataset_Optimized V; - Volume_Dataset V; - - vcg::Box3 bbox; - - char *inDir; - char *outDir; - - //attention static members - /*int BlockFlag; - int StoppedFlag;*/ - - Segmentator() - { - m=new MyTriMesh(); - CollDet=new Collision(m->face); - } - - ~Segmentator() - { - } - -private: - - /////return integer coordinete in volumetric dataset - //Point3i MapToDataset(MyTriMesh::CoordType p) - //{ - // MyTriMesh::ScalarType x=((MyTriMesh::ScalarType)p.V(0)); - // MyTriMesh::ScalarType y=((MyTriMesh::ScalarType)p.V(1)); - // MyTriMesh::ScalarType z=((MyTriMesh::ScalarType)p.V(2)); - // return Point3i((int)p.V(0),(int)p.V(1),(int)p.V(2)); - //} - // - - ///map to space coordinate from dataset coordinates - MyTriMesh::CoordType MapToSpace(Point3i p) - { - MyTriMesh::ScalarType x=((MyTriMesh::ScalarType)p.V(0)); - MyTriMesh::ScalarType y=((MyTriMesh::ScalarType)p.V(1)); - MyTriMesh::ScalarType z=((MyTriMesh::ScalarType)p.V(2)); - return (MyTriMesh::CoordType(x,y,z)); - } - -#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((difference50)||(fabs(p.Y())>50)||(fabs(p.Z())>50))); - - } - - float getColor(MyTriMesh::CoordType p) - { - MyTriMesh::CoordType p1=MyTriMesh::CoordType(p.X(),p.Z(),p.Y()); - MyTriMesh::CoordType p2=MyTriMesh::CoordType(p.Z(),p.Y(),p.X()); - - if (InTorus(p))//||InTorus(p1)||InTorus(p2)) - return (100.f); - else - return (0.f); - } - - -#else - ///return integer coordinete in volumetric dataset - float getColor(MyTriMesh::CoordType p) - { - - - float lx=(p.V(0)-(int)p.V(0))*scale.V(0);//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)); - - float v[8]; - Point3i px; - for (int i=0;i<8;i++) - { - px=base+Point3i((i%2),(i/4),((i/2)%2)); - v[i]=(float)V.getAt(px); - } - - float color=lx*v[1]+v[0]+lz*v[0]*lx-v[0]*lx-ly*v[0]+ly*v[2]-lz*v[0]+ly*v[0]*lx-ly*lx*v[1]-ly*v[2]*lx - -lz*ly*v[0]*lx+lz*ly*lx*v[1]+lz*ly*v[2]*lx-lz*ly*lx*v[3]+lz*ly*lx*v[4]-lz*ly*lx*v[5]-lz*ly* - v[6]*lx+lz*ly*lx*v[7]+ly*lx*v[3]-lz*lx*v[1]+lz*ly*v[0]-lz*ly*v[2]-lz*lx*v[4]+lz*lx*v[5]-lz*ly* - v[4]+lz*ly*v[6]+lz*v[4]; - - return color; - } -#endif - - ///maximixe the gradient of the movement - MyTriMesh::CoordType Gradient(MyTriMesh::CoordType p,float h=0.01f) - { - float value=getColor(p); - MyTriMesh::CoordType h0=MyTriMesh::CoordType(h,0,0); - MyTriMesh::CoordType h1=MyTriMesh::CoordType(0,h,0); - MyTriMesh::CoordType h2=MyTriMesh::CoordType(0,0,h); - float dx=(getColor(p+h0)-value)/h; - - /*dx=v[1]+lz*v[0]-v[0]*lx+ly*v[0]-ly*v[1]-ly*v[2] - -lz*ly*v[0]+lz*ly*v[1]+lz*ly*v[2]-lz*ly*v[3]+lz*ly*v[4]-lz*ly*v[5]-lz*ly* - v[6]+lz*ly*v[7]+ly*v[3]-lz*v[1]-lz*v[4]+lz*v[5]-lz*ly*v[4]+lz*ly*v[6]+lz*v[4]; - - dy=-v[0]+v[2]+v[0]*lx-lx*v[1]-v[2]*lx - -lz*v[0]*lx+lz*lx*v[1]+lz*v[2]*lx-lz*lx*v[3]+lz*lx*v[4]-lz*lx*v[5]-lz*v[6]*lx+lz*ly*lx*v[7]+ly*lx*v[3]-lz*lx*v[1]+lz*ly*v[0]-lz*ly*v[2]-lz*lx*v[4]+lz*lx*v[5]-lz*ly* - v[4]+lz*ly*v[6]+lz*v[4];*/ - - float dy=(getColor(p+h1)-value)/h; - float dz=(getColor(p+h2)-value)/h; - MyTriMesh::CoordType ret=MyTriMesh::CoordType(dx,dy,dz); - 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 - MyTriMesh::CoordType Scale(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)); - } - - ///return true if a coordinate is out of limits - bool OutOfLimits(MyTriMesh::CoordType p) - { - MyTriMesh::CoordType test=p; - MyTriMesh::CoordType max=BBox().max-MyTriMesh::CoordType(1.f,1.f,1.f);//last change - MyTriMesh::CoordType min=BBox().min;//+Point3f(1.f,1.f,1.f);//last change - for (int i=0;i<3;i++) - { - if(((test.V(i)>=max.V(i))||(test.V(i)<=min.V(i)))) - return true; - } - return false; - } - - - bool IsBlocked(MyVertex *v) - { - //return ((v->Flags()& BlockFlag!=0)); - return (v->blocked); - } - - void SetBlocked(MyVertex *v) - { - //v->Flags()|= BlockFlag; - v->blocked=true; - //v->SetS();//for refine - } - - void SetBlockedFace(MyFace *f) - { - SetBlocked(f->V(0)); - SetBlocked(f->V(1)); - SetBlocked(f->V(2)); - } - - void SetIntersectedFace(MyFace *f) - { - f->intersected=true; - f->ClearS(); - SetBlockedFace(f); - - //if ((!f->intersected)&&(!f->IsD())) - //{ - // f->intersected=true; - // /////detach from Face-Face Topology - // for (int i=0;i<3;i++) - // if (!f->IsBorder(i)) - // vcg::face::FFDetach(*f,i); - // f->SetD(); - // m->fn--; - //} - } - - bool IsStopped(MyVertex *v) - { - //return ((v->Flags()& StoppedFlag!=0)); - return (v->stopped); - } - - void SetStopped(MyVertex *v) - { - //v->Flags()|= StoppedFlag; - v->stopped=true; - V_Stopped.push_back(v); - } - - void ClearStopped(MyVertex *v) - { - //v->Flags()&= ~StoppedFlag; - v->stopped=false; - } - - /////re-set physical pararmeters on the mesh - //void InitPhysParam(float k_elanst,float mass,float k_dihedral) - //{ - // for (unsigned int i=0;iface.size();i++) - // { - // if (!m->face[i].IsD()) - // m->face[i].Init(k_elanst,mass,k_dihedral); - // } - //} - - ///set the initial mesh of deformable object - void InitMesh(MyTriMesh *m) - { - m->Clear(); - - vcg::tri::Icosahedron(*m); - - vcg::tri::UpdateTopology::FaceFace(*m); - - /* P_Vertex.clear(); - P_Faces.clear();*/ - - for (unsigned int i=0;ivert.size();i++) - { - m->vert[i].P()=UnScale(m->vert[i].P());///last change - m->vert[i].P()+=InitialBarycenter; - m->vert[i].SetRestPos(); - // m.vert[i].P()=UnScale(m.vert[i].P()); - // P_Vertex.push_back(&m.vert[i]); - } - - vcg::tri::UpdateNormals::PerVertexNormalized(*m); - - } - - - ///return true if the gray level of the vertex v differ from graylevel less than tolerance - bool InTolerance(MyTriMesh::VertexType *v) - { - return (fabs(getColor(v->P())-(float)gray_init)<(float)tolerance); - } - - ///add to the vertex v a containing force basing on diffence from tolerance - MyTriMesh::CoordType ContainingForce(MyTriMesh::VertexType *v) - { - //float dinstance=fabs((FindGrayMedia(v))-gray_init); - float dinstance=fabs((getColor(v->P()))-(float)gray_init); - assert(dinstance<=tolerance); - MyTriMesh::CoordType ret=(-v->N()*((dinstance)/(float)tolerance)); - return (ret); - } - - ///find the gradient factor - MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v) - { - MyTriMesh::CoordType value=Gradient(v->P()); - /*float d0=getColor(v->P()+value); - float d1=getColor(v->P()-value); - if ((fabs(d0-(float)gray_init))>(fabs(d1-(float)gray_init))) - return (-value); - else */ - return (value*(gray_init-getColor(v->P()))); - } - - ///add the external forces to the deformable mesh - - void AddExtForces() - { - Part_VertexContainer::iterator vi; - /*PartialUpdateNormals();*/ - end_loop=true; - for (vi=P_Vertex.begin();vi1) - Containing0.Normalize(); - Containing0*=0.75; - (*vi).ExtForce()=Inflating+Containing0;/*+Containing1+Containing0*/; - } - } - else - (*vi).ExtForce()=MyTriMesh::CoordType(0,0,0); - } - } - } - - ///reinit the partial integration vectors that describe active vertices - void Reinit_PVectors() - { - V_Stopped.clear(); - P_Vertex.clear(); - MyTriMesh::VertexIterator vi; - - for (vi=m->vert.begin();vivert.end();vi++) - { - if ((!vi->IsD())&&(!vi->blocked)) - P_Vertex.push_back(&(*vi)); - if ((!vi->IsD())&&((*vi).stopped)&&(!vi->blocked))///to see - V_Stopped.push_back(&(*vi)); - } - - P_Faces.clear(); - MyTriMesh::FaceIterator fi; - for (fi=m->face.begin();fiface.end();fi++) - { - if ((!fi->IsD())&&(!fi->IsBlocked())&&(!fi->intersected)) - P_Faces.push_back(&(*fi)); - } - } - - ///erase the stopped entities from the partial containers - void Refresh_PVectors() - { - Part_FaceContainer P_FacesAux; - Part_VertexContainer P_VertexAux; - P_FacesAux.clear(); - P_VertexAux.clear(); - - unsigned int i=0; - ///as first control normal inversion - for (i=0;iNormInversion())//if one step inversion the block vertices - SetIntersectedFace(P_Faces[i]); - else - P_Faces[i]->old_N=NormalizedNormal(*P_Faces[i]); - - for (i=0;iIsD())&&(!P_Vertex[i]->blocked))//&&(!P_Vertex[i]->stopped)) - P_VertexAux.push_back(P_Vertex[i]); - - for (i=0;iIsD())&&(!P_Faces[i]->intersected)&&(!P_Faces[i]->IsBlocked()))//&&(!P_Faces[i]->IsActive()))//&&(!P_Faces[i]->IsBlocked())) - P_FacesAux.push_back(P_Faces[i]); - - P_Faces.clear(); - P_Vertex.clear(); - - P_Faces=P_FacesAux; - P_Vertex=P_VertexAux; - } - - ///add the new elements on partial vectors when allocate space for new vertices - void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi) - { - while (vi!=m->vert.end()) - { - if ((!(*vi).IsD())&&(!(*vi).blocked)&&(!(*vi).stopped)) - P_Vertex.push_back(&(*vi)); - vi++; - } - while (fi!=m->face.end()) - { - if ((!(*fi).IsD())&&((*fi).IsActive())) - P_Faces.push_back(&(*fi)); - fi++; - } - } - - ///verify and eventually stop the vertices of the mesh - void VerifyForces() - { - float proj; - Part_VertexContainer::iterator vi; - for (vi=P_Vertex.begin();viinterval_reinit) - { - time=clock(); - return true; - } - return false; - } - - bool TimeSelfIntersection() - { - static clock_t time=0; - clock_t elapsedsecs=abs(time-clock()); - if (elapsedsecs>interval_selfcollision) - { - time=clock(); - return true; - } - return false; - } - - - void PartialUpdateNormals() - { - /*vcg::tri::UpdateNormals::PerFaceNormalized(*m); - vcg::tri::UpdateNormals::PerVertexNormalized(*m);*/ - Part_FaceContainer::iterator fi; - for (fi=P_Faces.begin();fiIsD() && (*fi).V(j)->IsRW() ) - (*fi).V(j)->N() += t; - } - - for(vi=P_Vertex.begin();vi!=P_Vertex.end();++vi) - if( !(*vi).IsD() && (*vi).IsRW() ) - (*vi).N().Normalize(); - - //MyTriMesh::FaceIterator fi; - //for (fi=m->face.begin();fi!=m->face.end();++fi) - // if ((!(*fi).IsD())&&(!(*fi).intersected)) - // (*fi).ComputeNormalizedNormal(); - - /////update only on active vertices - //Part_VertexContainer::iterator vi; - //for (vi=P_Vertex.begin();viface.begin();fi!=m->face.end();++fi) - // if( !(*fi).IsD() && (*fi).IsR() &&(!(*fi).intersected))//(!(*fi).IsBlocked())&& - // { - // MyFace::NormalType t = (*fi).N(); - // for(int j=0; j<3; ++j) - // if( !(*fi).V(j)->IsD() && (*fi).V(j)->IsRW())//&& (!(*fi).V(j)->blocked)) - // (*fi).V(j)->N() += t; - // } - - //for(vi=P_Vertex.begin();vi!=P_Vertex.end();++vi) - // if( !(*vi).IsD() && (*vi).IsRW() ) - // (*vi).N().Normalize(); - - } - - //bool SelectToRefine() - //{ - // MyTriMesh::FaceIterator fi; - // for (fi=m->face.begin();pfiface.end();++pfi) - // { - // if (((*fi).QualityFace()<0.1f)) - // fi->ClearS(); - // } - //} - - template - struct MyMidPoint:vcg::MidPoint - { - void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ - - 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(); - - if( MESH_TYPE::HasPerVertexColor()) - nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); - } - }; - - ///refine the mesh and re-update eventually - void RefineStep(float _edge_size) - { - MyTriMesh::VertexIterator vinit=m->vert.begin(); - MyTriMesh::FaceIterator finit=m->face.begin(); - MyTriMesh::VertexIterator vend=m->vert.end(); - MyTriMesh::FaceIterator fend=m->face.end(); - - // bool to_refine=SelectToRefine(); - - /*if (to_refine)*/ - //refined=vcg::Refine(*m,MidPoint(),_edge_size,true); - refined=vcg::Refine(*m,MyMidPoint(),_edge_size,true); - /*else - refined=false;*/ - - if (refined) - { - - MyTriMesh::VertexIterator vinit2=m->vert.begin(); - MyTriMesh::FaceIterator finit2=m->face.begin(); - - if ((vinit2!=vinit)||(finit2!=finit)) - { - Reinit_PVectors(); - CollDet->RefreshElements(); - } - else - { - AddNewElements(vend,fend); - CollDet->UpdateStep(P_Faces); - } - /*vcg::tri::UpdateNormals::PerFaceNormalized(*m); - vcg::tri::UpdateNormals::PerVertexNormalized(*m);*/ - - PartialUpdateNormals(); - PartialReinitPhysicMesh(); - - //#ifdef _DEBUG - // vcg::tri::UpdateTopology::TestFaceFace(*m); - //#endif - - //CollDet->RefreshElements(); - } - } - - ///reset vertex position and unblock them - void PartialReinitPhysicMesh() - { - Part_FaceContainer::iterator pfi; - - Part_VertexContainer::iterator pvi; - for (pvi=P_Vertex.begin();pvivert.begin();pvivert.end();++pvi) - if(!(*pvi).IsD()) - (*pvi).SetRestPos(); - - for (pfi=m->face.begin();pfiface.end();++pfi) - if((!(*pfi).IsD())&&((!(*pfi).intersected))) - (*pfi).Init(k_elanst,mass,k_dihedral); - - PartialUpdateNormals();*/ - - /*for (MyTriMesh::VertexIterator vi=m.vert.begin();viUpdateStep(P_Faces); - std::vector coll=CollDet->computeSelfIntersection(); - for (std::vector::iterator it=coll.begin();itIsD()) - { - SetBlockedFace(*it); - SetIntersectedFace(*it); - } - } - } - -public: - - ///set the initial barycenter where the triangle mesh start to expand - //void SetInitialBarycenter(MyTriMesh::CoordType b) - //{ - // InitialBarycenter=b; - // gray_init=getColor(b); - // /*InitMesh(m);*/ - //} - - ///set the input output directory of images - void LoadFromDir(char *in, char *out) - { - inDir=in; - outDir=out; - - //caso optimized - /*V.LoadJpg(inDir,outDir); - - V.Init(1000,outDir);*/ - - V.LoadJpg(inDir); - bbox=vcg::Box3(MapToSpace((V.Min())),(MapToSpace(V.Max()))); - } - - ///set the input - void LoadFromRaw(char *inDir) - { - /*V.LoadRaw(inDir); - bbox=vcg::Box3(MapToSpace((V.Min())),(MapToSpace(V.Max())));*/ - } - - ///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, - float Edge_precision=4.f,Point3f ScaleFactor=Point3f(1.f,1.f,1.f), - clock_t _interval=2000,clock_t _interval2=250) - { - mass=Mass; - k_elanst=K_elanst; - tolerance=tol; - - interval_reinit=_interval; - interval_selfcollision=_interval2; - - edge_size=16.f; - edge_init=edge_size; - edge_precision=Edge_precision; - time_stamp=Time_stamp; - k_dihedral=Dihedral; - scale=ScaleFactor; - bbox=vcg::Box3(UnScale(MapToSpace(V.Min())),(UnScale(MapToSpace(V.Max()))));//last change! - } - - - ///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->SetPDESolver(PDESolvers::EULER_METHOD); - - InitMesh(m); - - //init the mesh with new - Reinit_PVectors(); - - PartialReinitPhysicMesh(); - - CollDet->Init(bbox.min,bbox.max,5.f); - } - - ///return the bounding box of the mesh - vcg::Box3& BBox() - { - return (bbox); - } - - ///one step of moving for the deformable object - void Step(float t,float _edge_size) - { - if (m->face.size()!=0) - { - AddExtForces(); - TrINT->Step(t); - PartialUpdateNormals(); - VerifyForces(); - Refresh_PVectors(); - if (end_loop) - { - ClearStopped(); - Reinit_PVectors(); - PartialReinitPhysicMesh(); - RefineStep(_edge_size); - /*ReinitPhysicMesh();*/ - } - if (TimeSelfIntersection()) - CollisionDetection(); - } - } - - void Smooth() - { - //ScaleLaplacianSmooth(*m,1,0.5); - vcg::tri::UpdateTopology::VertexFace(*m); - PasoDobleSmooth(*m,1); - } - - void AutoStep() - { - refined=false; - Step(time_stamp,edge_size); - //test on 80% of the vertex blocked - if ((((float)P_Vertex.size()/(float)m->vn)<0.2)&&(end_loop)&&(!refined)&&(edge_size>edge_precision)) - { - edge_size/=2.f; - if (edge_size mcE; - // mcE.Extract(gray_init,V,vcg::Point3i(256,256,100),*m,gray_init); - // //mcE.Extract(gray_init,V,vcg::Point3i(512,512,240),*m,gray_init); - // //mcE.Extract(gray_init,V,vcg::Point3i(128,128,60),*m,gray_init); - //} - - ///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(); - 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),edge_init); -#else - vcg::trimesh::Resampler::Resample(*m,*new_m, - Point3i((int) edge_precision/2.0,(int) edge_precision/2.0,(int) edge_precision/2.0),edge_size*2.f); -#endif - // delete(new_m0); - delete(m); - - m=new_m; - Reinit_PVectors(); - PartialReinitPhysicMesh(); - - CollDet->Init(bbox.min,bbox.max,5.f); - } - -}; -#endif \ No newline at end of file diff --git a/apps/test/segmentation3d/segmentform.ui b/apps/test/segmentation3d/segmentform.ui deleted file mode 100644 index 05a39fe7..00000000 --- a/apps/test/segmentation3d/segmentform.ui +++ /dev/null @@ -1,1014 +0,0 @@ - -SegmentForm - - - SegmentForm - - - - 0 - 0 - 1100 - 974 - - - - - 211 - 868 - - - - Segmentation - - - - unnamed - - - - layout1 - - - - unnamed - - - - buttonGroup1 - - - - 7 - 0 - 0 - 0 - - - - - - - - ResultButton - - - - 740 - 10 - 110 - 31 - - - - - 10 - - - - ResultForces - - - true - - - - - InternalButton - - - - 590 - 10 - 110 - 31 - - - - - 10 - - - - InternalForces - - - true - - - - - BlockedButton - - - - 270 - 10 - 110 - 31 - - - - - 10 - - - - BlockedFaces - - - true - - - - - SlidesButton - - - - 10 - 10 - 80 - 31 - - - - - 10 - - - - Slides - - - true - - - - - WireButton - - - - 130 - 10 - 100 - 31 - - - - - 10 - - - - Wire - - - true - - - true - - - true - - - - - ExternalButton - - - - 420 - 10 - 120 - 31 - - - - - 10 - - - - ExternalForces - - - true - - - - - - simpleGLWidget1 - - - - 5 - 5 - 0 - 0 - - - - - - - - buttonGroup2 - - - - 0 - 3 - 0 - 0 - - - - - - - - textLabel1_2 - - - - 30 - 190 - 90 - 21 - - - - - 10 - - - - initial time step - - - - - D_angle - - - - 30 - 150 - 70 - 31 - - - - - 10 - - - - LineEditPanel - - - Sunken - - - 0.2 - - - 3 - - - - - textLabel1_4 - - - - 30 - 130 - 150 - 21 - - - - - 10 - - - - dihedral angle constant - - - - - K_elanst - - - - 30 - 90 - 70 - 31 - - - - - 10 - - - - LineEditPanel - - - Sunken - - - 0.2 - - - 3 - - - - - textLabel1 - - - - 30 - 70 - 131 - 21 - - - - - 10 - - - - spring constant - - - - - M_particles - - - - 30 - 30 - 70 - 31 - - - - - 10 - - - - 2 - - - 0.5 - - - 3 - - - - - textLabel1_3 - - - - 30 - 10 - 131 - 21 - - - - - 10 - - - - mass of particles - - - - - textLabel1_2_2_2_3 - - - - 30 - 300 - 140 - 50 - - - - - 10 - - - - Slide dinstance (pixel) - - - - - textLabel1_2_2 - - - - 30 - 250 - 116 - 21 - - - - - 10 - - - - minimum edge size - - - - - S_dist - - - - 30 - 340 - 70 - 31 - - - - - 10 - - - - 1 - - - 1 - - - - - Tolerance - - - - 30 - 400 - 70 - 31 - - - - - 10 - - - - 10 - - - 2 - - - - - E_size - - - - 30 - 270 - 70 - 31 - - - - - 10 - - - - 4 - - - 1 - - - - - SmoothButton - - - - 30 - 660 - 140 - 30 - - - - - 10 - - - - 0 - - - Smooth - - - - - SaveButton - - - - 30 - 700 - 140 - 31 - - - - - 10 - - - - SavePly - - - - - ApplyButton - - - - 30 - 540 - 141 - 31 - - - - - 10 - - - - Apply - - - - - textLabel1_2_2_2 - - - - 30 - 380 - 116 - 21 - - - - - 10 - - - - tolerance - - - - - textLabel1_2_2_2_2 - - - - 30 - 440 - 116 - 21 - - - - - 10 - - - - color - - - - - slider1 - - - - 14 - 505 - 170 - 20 - - - - 255 - - - Horizontal - - - - - T_step - - - - 30 - 210 - 70 - 31 - - - - - 10 - - - - LineEditPanel - - - Sunken - - - 0.4 - - - 3 - - - - - GrayScale - - - - 14 - 460 - 170 - 31 - - - - true - - - - - Marching_Cubes - - - - 30 - 620 - 141 - 31 - - - - - 10 - - - - Resample mesh - - - Down, Down, Esc, Ctrl+Z - - - - - SegmentButton - - - - 30 - 580 - 141 - 31 - - - - - 10 - - - - Extract - - - true - - - - - ClearButton - - - - 30 - 740 - 140 - 30 - - - - - 10 - - - - 0 - - - ClearMesh - - - - - - - - MenuBar - - - - - - - - - - - - - - - - - - SimpleGLWidget -
D:/sf/apps/test/segmentation3d/simpleglwidget.h
- - -1 - -1 - - 0 - - 5 - 5 - 0 - 0 - - image0 - ShowSlides() - SetWire() - SetShowBlocked() - ShowExternalForces() - ShowInternalForces() - ShowResultForces() - Smooth() - SavePly() - Extract() - Apply() - Open() - CleanMesh() - Clear() - SetSegmentColor() - OpenRawFile() - slot() -
-
- - - - fileOpenAction - - - false - - - - - - &Open... - - - &Open... - - - Ctrl+O - - - - - fileSaveAction - - - - - - Save - - - &Save - - - Ctrl+S - - - - - Segmentation - - - Save As - - - Save &As... - - - - - - - - fileExitAction - - - Exit - - - E&xit - - - - - - - - fileOpennew_itemAction - - - new item - - - new item - - - - - fileOpenRawAction - - - OpenRaw - - - OpenRaw - - - - - - 89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000003b149444154789cad94514c5b5518c77fe7dc4b7b4b6150bb96324418ca32358bee6192609c51d883892ce083f1718b3ebb185f8dc91e972cf39d2d6a78d0b027b3cd07d9e68c81c625a6c139408a4384f416100aed6d4b7bdb7b8e0fc0921a70c6ed7b3ae7e43bbff3fffedfc927e2f138bbd1dbdbab7902118fc785d8058f8d8de9aeae2e72b91cb66de338ce7f82e47239666767492412b8aefbf0dcdc553a323242f4501d918e2d3a8f15a9784584100809a609526eafd1a0f54e6142e029c5c21f3ef41583bb77a805efbe1ce9d86279e32619678eaab7853fa0f02a16abb64166ad0cdac75307eb3874b84cb0a14aa5a24108cc0688c48c9a4a1e826ddbe6f0b12219678e8ace610502ccdfafe3f68d3c33bf6c01c59dcc209d472c4e0d35d2f3ba81d205d06005e4de60c77170bd2255af80150870f70e8c0eaf009260a349577714e913a4175d16925b5cbe50607931cc3b677c68ca28a5f7066f5b26f00760febec9e8f032a0e81b68a17fc0201415989647a9d8c4c498cbe8f05f5cff3a4d4bac8bfe210b290b35e01afd428257b1b875cd01aaf4bd1de5dd0fea688e1530ad1c1bab16b7af17393558cf997311c0e49bafd670d6258621f6576c9ab09a3248fe5ae6c08103f49f36517213d33070369bf8e2529ee9c90ceb2b2eef7f14617c2c48722a4b7226845143fa87622905ebeb6514253a9eb5084504a66950c88618bee0303d99217cb09e9ed71a09369538fa523d00e9a50a42eed3bc6d8f41281fa0903e8561796cac86f8f2b33c33930ea0f0fb4d5adbeb30ad22866ffbbad226d2a805d7ee0484220208925aaa50deaa67e27b97e9c90ccdcdf5c462cdd8a94d2e7e62f3603244ea410989a4ed191f52a8fd156b056d9d553a9e0bf0e7ef45c6bf7339fd5e90ec7a88575e6d20d6e6e7e2a755ec854dce7fb8885b2cd014f6f3c2714d3a550bae55ac35c1068fb7061b00b87a7995899b25ce9e0b73e24d8fae97b37c7cbe9370b499fce6066eb54adf6098f6ee2a9a7ff9c70841a5023d270deca510d746537c7e29cdf8ad20475fb4307c82d4fc324ec6859d66fdfc6381e44014b36e9fe6e572393ca54068aa22cfd0598b686b3737aeae90bc9725796f0350802414b6e81b7c9a9f7e70708a2e6e5991cfeee3f1ecec2c0b0b3e8c068142a2a8d23728397132c6dc6f2e2b8b0a8da4b5ddc7f3c735ed47146f0cb4502983693a4c25ca7b83138904fa8a412466e00f48b4271086c2901263676c4a6990b615b6ade15b85694af239984a94585bf6f606bbae5b334f1f37e4a3531e031c8fc7c5a312ff17f849c3e3f1b8f81b8be6900aca9b61c90000000049454e44ae426082 - - - - - SlidesButton - pressed() - simpleGLWidget1 - ShowSlides() - - - WireButton - pressed() - simpleGLWidget1 - SetWire() - - - BlockedButton - pressed() - simpleGLWidget1 - SetShowBlocked() - - - ExternalButton - pressed() - simpleGLWidget1 - ShowExternalForces() - - - InternalButton - pressed() - simpleGLWidget1 - ShowInternalForces() - - - ResultButton - pressed() - simpleGLWidget1 - ShowResultForces() - - - SaveButton - clicked() - simpleGLWidget1 - SavePly() - - - SmoothButton - pressed() - simpleGLWidget1 - Smooth() - - - SegmentButton - pressed() - simpleGLWidget1 - Extract() - - - ApplyButton - pressed() - simpleGLWidget1 - Apply() - - - fileOpenAction - activated() - simpleGLWidget1 - Open() - - - fileSaveAction - activated() - simpleGLWidget1 - SavePly() - - - Marching_Cubes - pressed() - simpleGLWidget1 - CleanMesh() - - - ClearButton - pressed() - simpleGLWidget1 - Clear() - - - slider1 - sliderMoved(int) - simpleGLWidget1 - SetSegmentColor() - - - fileOpenRawAction - activated() - simpleGLWidget1 - OpenRawFile() - - - - - - simpleglwidget.h - -
diff --git a/apps/test/segmentation3d/simpleglwidget.cpp b/apps/test/segmentation3d/simpleglwidget.cpp deleted file mode 100644 index 92b8b093..00000000 --- a/apps/test/segmentation3d/simpleglwidget.cpp +++ /dev/null @@ -1,652 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -extern Segmentator *s; - -SimpleGLWidget::SimpleGLWidget( QWidget * parent, const char * name, const QGLWidget * shareWidget, WFlags f ): -QGLWidget(parent, name) -{ - - //grabKeyboard(); - _showslides=false; - blocked=false; - wire=true; - extForces=false; - intForces=false; - resultForces=false; - continue_int=false; - _numslide=0; - - TrackM.center=Point3f(0,0,0); - TrackM.Reset(); - TrackM.radius= 100.f; - - TrackS.center=Point3f(0,0,0); - TrackS.Reset(); - TrackS.radius= 100.f; - - zoom=1; - path=""; - /*s=new Segmentator();*/ - //timer = new QTimer(this ); - //QTimer::connect( timer, SIGNAL(timeout()), this, SLOT(Update()) ); - // timer->start(0); // 2 seconds single-shot timer - -} - -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); -} - -//load as texture the i jpg of the directory -void SimpleGLWidget::LoadTextureJpg(QString p,int level) -{ - int e=glGetError(); - - QImage qI=QImage(); - QDir Qd=QDir(p); - QString qformat; - QString Path=QString(p); - Qd.setNameFilter("*.jpg"); - //Qd.setNameFilter("*.bmp"); - - Qd.setSorting(QDir::Name); - QString PathFile=Path; - PathFile.append(Qd[level]); - - qI.load(PathFile,qformat); - 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); - - 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); -} - -void SimpleGLWidget::drawSlide() -{ - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPolygonMode(GL_FRONT,GL_FILL); - glMatrixMode (GL_TEXTURE); - glLoadIdentity(); - glEnable(GL_TEXTURE_2D); - /*glEnable(GL_NORMALIZE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - */ - glDisable(GL_LIGHTING); - glDisable(GL_LIGHT0); - 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); - - glColor3d(0.8,0.8,0.8); - - ///texture - //_numslide - glBegin(GL_QUADS); - glNormal(Point3d(0,0,1)); - glTexCoord(Point3f(0,1,0)); - glVertex(p0); - glTexCoord(Point3f(1,1,0)); - glVertex(p1); - glTexCoord(Point3f(1,0,0)); - glVertex(p2); - glTexCoord(Point3f(0,0,0)); - glVertex(p3); - 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 p0=Point3(x,y,_numslide); -// double color=((double)s->V.getAt(p0))/256.f; -// glColor3d(color,color,color); -// glVertex(p0); -// -// Point3 p1=Point3(x+1,y,_numslide); -// color=((double)s->V.getAt(p1))/256.f; -// glColor3d(color,color,color); -// glVertex(p1); -// -// Point3 p2=Point3(x+1,y+1,_numslide); -// color=((double)s->V.getAt(p2))/256.f; -// glColor3d(color,color,color); -// glVertex(p2); -// -// Point3 p3=Point3(x,y+1,_numslide); -// color=((double)s->V.getAt(p3))/256.f; -// glColor3d(color,color,color); -// glVertex(p3); -// } -//glEnd(); -} - -void drawForces(Segmentator::Part_VertexContainer *pv,int typeForce) -{ -Segmentator::Part_VertexContainer::iterator vi; -glPushAttrib(GL_ALL_ATTRIB_BITS); -glLineWidth(0.3f); -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); - -for (vi=pv->begin();viend();++vi) -{ - 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) - { - const char *path_save=filename.ascii(); - vcg::tri::io::ExporterPLY::Save((*s->m),path_save); - } - -} - -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(){ - //glClearColor(0.2f,0.2f,0.2f,1.f); - glClearColor(1.f,1.f,1.f,1.f); - 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)); - TrackS.radius=s->BBox().Diag(); - TrackS.GetView(); - TrackS.Apply(); - TrackS.Draw(); - glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag()); - //glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom)); - glTranslate(-p); - //save transformation matrixes - SaveMatrix(); - } - else - { - 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()); -#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()); - } - } - - 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); - glDisable(GL_TEXTURE_2D); - - 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); - - if (s->m!=NULL) - { - glBegin(GL_TRIANGLES); - for (fi=s->m->face.begin();fim->face.end();fi++) - { - if(!(*fi).IsD()) - { - /*if ((!fi->V(0)->IsR())||(!fi->V(1)->IsR())||(!fi->V(2)->IsR())) - assert(0); - */ - - //glColor3d(0.4,0.8,0.8); - if (wire) - { - glColor3d(0,0,0); - glLineWidth(2); - } - else - glColor3d(0.4,0.8,0.8); - if ((fi->intersected)&&(wire)) - 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()); - } - - } - } - } - } - glEnd(); - glPopMatrix(); - //WriteInfo(); - - } - 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) - { - rawImage=false; - filename+="/"; - path=filename; - const char *pa=filename.ascii(); - char *p=(char*)pa; - s->LoadFromDir(p,"prova.txt"); - 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); - _showslides=true; - w->SlidesButton->setOn(true); - repaint(); - } -} - -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() -{ - s->m->Clear(); - repaint(); -} - -void SimpleGLWidget::UpdateBBMesh() -{ - vcg::tri::UpdateBounding::Box(*(s->m)); -} - -void SimpleGLWidget::mousePressEvent ( QMouseEvent * e ) -{ - if (e->button()==Qt::LeftButton ) - { - - if ((!_showslides)&&(s->m!=NULL)) - { - /*vcg::tri::UpdateBounding::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); -#ifndef _TORUS - CenterExtraction=s->m->bbox.Center(); -#endif - } - else if (_showslides) - TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); - } - 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); - - SetExtractionParameters(); - s->InitSegmentation(Point3f(x,y,z)); - w->slider1->setValue(s->gray_init); - - UpdateBBMesh(); - //vcg::tri::UpdateBounding::Box(*(s->m)); - repaint(); - } - //vcg::tri::UpdateBounding::Box(s->m); -} - -void SimpleGLWidget::setColor() -{ - s->gray_init=w->slider1->value(); -} - -///only for debugghing -void SimpleGLWidget::keyPressEvent(QKeyEvent *k) -{ - s->AutoStep(); - repaint(); -} - -void SimpleGLWidget::wheelEvent(QWheelEvent *e) -{ - if (!_showslides) - { - /* zoom+=e->delta()/120.f; - repaint();*/ - TrackM.MouseWheel(e->delta()/120.f); - repaint(); - } - else - { - int oldnum=_numslide; - _numslide+=e->delta()/120.f; - if ((_numslide<0)||(_numslide>=s->V.dimZ())) - _numslide=oldnum; - if (s!=0) - { - if (!rawImage) - LoadTextureJpg(path,_numslide); - else - LoadTextureRaw(_numslide); - } - } - - repaint(); -} - -void SimpleGLWidget::mouseReleaseEvent(QMouseEvent * e ) - { - 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); - - repaint(); - } - -void SimpleGLWidget::Step() - { - if ((s!=0)&&(continue_int)) - { - s->AutoStep(); - repaint(); - } - } - -//void SimpleGLWidget::MarchingCubesExtraction() -// { -// if (s!=0) -// { -// s->MarchingCubeExtraction(); -// repaint(); -// } -// } - -void SimpleGLWidget::MarchingCube() -{ - if (s->m->fn>0) - s->Resample(); - - //vcg::tri::io::ExporterPLY::Save((*s->new_m),"d:/march.ply"); - //vcg::tri::io::ExporterPLY::Save((*s->m),"d:/march.ply"); -} - -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()); - float dinstance=atof(w->S_dist->text()); - //int color =atoi(w->Color->text()); - ///to modify - - s->SetSegmentParameters(tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance)); - } - -void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e ) - { - if (_showslides) - TrackS.MouseMove(e->x(),_H-e->y()); - else - TrackM.MouseMove(e->x(),_H-e->y()); - - repaint(); - } - - -void SimpleGLWidget::initializeGL(){ - - GLfloat f[4]={0.2f,0.2f,0.2f,1.f}; - 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); - - } diff --git a/apps/test/segmentation3d/simpleglwidget.h b/apps/test/segmentation3d/simpleglwidget.h deleted file mode 100644 index a3b9b287..00000000 --- a/apps/test/segmentation3d/simpleglwidget.h +++ /dev/null @@ -1,208 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class SimpleGLWidget: public QGLWidget{ - -Q_OBJECT - -private : - int _H; - int _W; - vcg::Trackball TrackM; - vcg::Trackball TrackS; - double zoom; - GLdouble projection[16]; - GLdouble modelMatrix[16]; - GLint viewport[4]; - bool _showslides; - int _numslide; - bool wire; - bool blocked; - bool extForces; - bool intForces; - bool resultForces; - bool continue_int; - bool rawImage; - 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 ); - - virtual void glDraw(); - //virtual void paintEvent ( QPaintEvent * ) ; - void resizeGL( int w, int h ); - virtual void mousePressEvent ( QMouseEvent * e ); - virtual void mouseReleaseEvent(QMouseEvent * e ); - virtual void mouseMoveEvent ( QMouseEvent * e ); - virtual void wheelEvent ( QWheelEvent * e ); - virtual void keyPressEvent(QKeyEvent *k); - virtual void initializeGL(); - virtual void SaveMatrix(); - virtual void Save(); - void LoadMatrix(); - void LoadTextureJpg(QString path,int level); - void LoadTextureRaw(int level); - void drawSlide(); - void SmoothMesh(); - void Step(); - void SetExtractionParameters(); - void WriteInfo(); - void ClearMesh(); - void OpenDirectory(); - void OpenRaw(); - void MarchingCube(); - void UpdateBBMesh(); - void setColor(); - //void MarchingCubesExtraction(); - //virtual void keyPressEvent(QKeyEvent *qk); - - public slots: - - void Open() - { - OpenDirectory(); - } - - void OpenRawFile() - { - OpenRaw(); - } - - void ShowSlides() - { - _showslides=!_showslides; - UpdateBBMesh(); - repaint(); - } - - void SetWire() - { - wire=!wire; - repaint(); - } - - void SetShowBlocked() - { - blocked=!blocked; - repaint(); - } - - void ShowExternalForces() - { - extForces=!extForces; - repaint(); - } - - void ShowInternalForces() - { - intForces=!intForces; - repaint(); - } - - void ShowResultForces() - { - resultForces=!resultForces; - repaint(); - } - - void Smooth() - { - SmoothMesh(); - repaint(); - } - - void SavePly() - { - Save(); - } - - void Apply() - { - SetExtractionParameters(); - } - - void Extract() - { - //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); - //} - repaint(); - } - - //void Extract() - //{ - // //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); - // //} - // repaint(); - //} - - void Update() - { - Step(); - } - - - void Clear() - { - ClearMesh(); - repaint(); - } - - void CleanMesh() - { - MarchingCube(); -#ifndef _TORUS - UpdateBBMesh(); -#endif - repaint(); - } - /* - void MCExtraction() - { - MarchingCubesExtraction(); - }*/ - - void SetSegmentColor() - { - setColor(); - } -}; \ No newline at end of file diff --git a/apps/test/segmentation3d/volume_dataset.h b/apps/test/segmentation3d/volume_dataset.h deleted file mode 100644 index 12d6e58e..00000000 --- a/apps/test/segmentation3d/volume_dataset.h +++ /dev/null @@ -1,519 +0,0 @@ -#ifndef _SEG3D_VOLUMEDATASET -#define _SEG3D_VOLUMEDATASET - -#include -#include -#include -#include -#include -#include -#include - -#define LimX 512 -#define LimY 512 -#define LimZ 240 - -#define dimXCell 20 -#define dimYCell 20 -#define dimZCell 20 - -#define TLBx 30 -#define TLBy 30 -#define TLBz 30 - - -template -class Volume_Dataset_Optimized{ - -public: - - Volume_Dataset_Optimized(){pFile=0;}; - ~Volume_Dataset_Optimized(){}; - -private: - class Cell - { - public: - - void Clear() - { - for (int i=0;itimestamp); - } - - ///operatorn to perform sorting - inline bool operator ==(const Cell &c) - { - return (c.timestamp==timestamp); - } - Point3i index; - int timestamp; - }; - - - - typedef typename std::list StackType; - typedef typename StackType::iterator IteStack; - - ///the class of grid of iterator to stack structure (corrispondence grid - stack) - struct TLBelem - { - private: - IteStack StackPoint; - - public: - - inline IteStack & I() - { - return StackPoint; - } - - bool inMem; - }; - - FILE * pFile; - StackType CurrStack; - - TLBelem TLB[TLBx][TLBy][TLBz]; - Cell buffer[TLBx][TLBy] ; - - int n_element; - int max_element; - int timestamp; - - int lx; - int ly; - int lz; - int TLBdx; - int TLBdy; - int TLBdz; - - int timesort; - - void SortStack() - { - /*std::sort(CurrStack.begin(),CurrStack.end()); - timestamp=0; - for (IteStack i=CurrStack.begin();i!=CurrStack.end();i++) - (*i).timestamp=0;*/ - } - - ///allocate momory for the buffer - void InitBuffer(Cell _buffer[TLBx][TLBy]) - { - for (int j=0;j GetCoordinate(int x,int y, int z) - { - int xd=(int) x/dimXCell; - int yd=(int) y/dimYCell; - int zd=(int) z/dimZCell; - - int xx= x%dimXCell; - int yy= y%dimYCell; - int zz= z%dimZCell; - - return (std::pair (Point3i(xd,yd,zd),Point3i(xx,yy,zz))); - } - - ///add an element to the structure - void Add(Cell _buffer[TLBx][TLBy],int x, int y, int z, ScalarType value) - { - assert(value<256); - std::pair coords=GetCoordinate(x,y,z); - Point3i cell=coords.first; - Point3i inter=coords.second; - _buffer[cell.V(0)][cell.V(1)].Data[inter.V(0)][inter.V(1)][inter.V(2)]=value; - } - - ///store a cell in the file - void SaveCell(Cell &cell) - { - int size_unit=sizeof( ScalarType ); - int dim=dimXCell*dimYCell*dimZCell; - int numwritten = fwrite(cell.Data, size_unit,dim,pFile ); - } - - ///save to file the current buffer - void SwapBuffer(Cell _buffer[TLBx][TLBy]) - { - for (int x=0;x=256) - return true; - return false; - } - -public: - - ///build and save the strucure made fo blocks - void LoadJpg(char *path,char *_newFile) - { - pFile=fopen (_newFile,"w+b"); - - //std::vector buffer; - /*Cell buffer[TLBx][TLBy] ;*/ - - //load first one image to see dimensions - QImage qI=QImage(); - QDir Qd=QDir(path); - QString qformat; - QString Path=QString(path); - Qd.setNameFilter("*.jpg"); - int levels=Qd.count(); - - Qd.setSorting(QDir::Name); - QString PathFile=Path; - - PathFile.append(Qd[0]); - bool b=qI.load(PathFile,qformat); - - Resize(qI.width(),qI.height(),levels); - - InitBuffer(buffer); - - for (int z=0;ztimesort) - { - time=clock(); - return true; - } - return false; - } - - inline Point3i Min()//to change in case of difefrent space between sections - {return Point3i(0,0,0);} - - inline Point3i Max()//to change in case of difefrent space between sections - {return Point3i(lx,ly,lz);} - - ///return the x dimension of the dataset - inline int dimX() - {return lx;} - - ///return the y dimension of the dataset - inline int dimY() - {return ly;} - - ///return the z dimension of the dataset - inline int dimZ() - {return lz;} - - - ///return the lenght of the diagonal - inline float Diag() - { - Point3f diag=Point3f((float) _X,(float) _Y,(float) _Z); - return (diag.Norm()); - } - - /////erase the element not used for long time - //void EraseLastUsed() - //{ - // if (TimeSort()) - // SortStack(); - - // int mint=TLB[0][0][0].timestamp; - // Point3i minElem=Point3i(0,0,0); - - // for(int z=0;z=0)&&(p.V(1)>=0)&&(p.V(2)>=0)); - - std::pair co=GetCoordinate(p.V(0),p.V(1),p.V(2)); - Point3i cell=co.first; - Point3i inter=co.second; - TLBelem e=TLB[cell.V(0)][cell.V(1)][cell.V(2)]; - if (e.inMem)///the element is in the buffer - { - IteStack i=e.I(); - ScalarType ret=(*i).Data[inter.V(1)][inter.V(0)][inter.V(2)]; - timestamp++; - (*i).timestamp=timestamp; - return (ret); - } - else///element fault, must load from file /// - { - //insert new element in the TLB table - Cell c=loadFromFile(cell); - CurrStack.push_front(c); - TLB[cell.V(0)][cell.V(1)][cell.V(2)].I()=CurrStack.begin(); - TLB[cell.V(0)][cell.V(1)][cell.V(2)].inMem=true; - (*CurrStack.begin()).timestamp=timestamp; - n_element++; - ///if the number of element is the meximum , then erase one with second chanche algorithm - if (n_element>=max_element) - { - if (TimeSort()) - SortStack(); - CurrStack.pop_back(); - n_element--; - } - ScalarType ret=(*CurrStack.begin()).Data[inter.V(1)][inter.V(0)][inter.V(2)]; - return ret; - } - } - - - - -}; - - -template -class Volume_Dataset{ - -public: - - Volume_Dataset(){}; - ~Volume_Dataset(){}; - - ScalarType Data[LimX][LimY][LimZ] ; - - int lx; - int ly; - int lz; - - - ///set total size of the dataset - void Resize(int _lx,int _ly,int _lz) - { - lx=_lx; - ly=_ly; - lz=_lz; - } - -public: - - /*template - Type * Loadraw(char * filename){ - FILE * f = fopen(filename,"rb"); - fseek(f,0,SEEK_END); - int l= ftell(f); - fseek(f,0,SEEK_SET); - Type * res = (Type *) malloc(l); - int readed = fread(res,sizeof(Type),l/sizeof(Type),f); - fclose(f); - }*/ - - - void LoadRaw(char * filename){ - FILE * f = fopen(filename,"rb"); - fseek(f,0,SEEK_END); - int l= ftell(f); - fseek(f,0,SEEK_SET); - int n=l/sizeof(ScalarType); - int readed = fread(&Data,sizeof(ScalarType),l/sizeof(ScalarType),f); - for (int i=0;i=0)&&(p.V(1)>=0)&&(p.V(2)>=0)); - return (Data[p.V(0)][p.V(1)][p.V(2)]); - } - -}; -#endif \ No newline at end of file