minor changes

This commit is contained in:
Nico Pietroni 2005-02-01 18:07:14 +00:00
parent 8722c1dbc2
commit 28da494fe3
7 changed files with 576 additions and 198 deletions

View File

@ -61,7 +61,7 @@ public:
bool TestRealIntersection(SimplexType *f0,SimplexType *f1) bool TestRealIntersection(SimplexType *f0,SimplexType *f1)
{ {
if ((!f0->IsActive())&&(!f1->IsActive())) if (((!f0->IsActive())&&(!f1->IsActive()))||(f0->IsD())||(f1->IsD()))
return false; return false;
//no adiacent faces //no adiacent faces
if ((f0!=f1)&& (!ShareEdge(f0,f1)) if ((f0!=f1)&& (!ShareEdge(f0,f1))
@ -70,25 +70,51 @@ public:
return false; return false;
} }
///refresh the elemnt of spatial hashing table ///refresh all the elements of spatial hashing table
///this function must called sometimes
void RefreshElements() void RefreshElements()
{ {
HTable->Clear(); HTable->Clear();
vactive.clear();///new
for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si) for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si)
{ {
if ((!(*si).IsD())&&(!(*si).IsActive())) if ((!(*si).IsD())&&(!(*si).IsActive()))
HTable->addSimplex(&*si); HTable->addSimplex(&*si);
///new now
else
{
std::vector<Point3i> cells=HTable->addSimplex(&*si);
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
vactive.insert(*it);
}
///end new now
} }
UpdateStep(); //UpdateStep(); commented now
} }
/////put active cells on apposite structure
//void UpdateStep()
//{
// vactive.clear();
// for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si)
// {
// if ((((!(*si).IsD()))&&(*si).IsActive()))
// {
// std::vector<Point3i> cells=HTable->addSimplex(&*si);
// for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
// vactive.insert(*it);
// }
// }
//}
///put active cells on apposite structure ///put active cells on apposite structure
void UpdateStep() template <class Container_Type>
void UpdateStep(Container_Type &simplex)
{ {
vactive.clear(); vactive.clear();
for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si) for (Container_Type::iterator si=simplex.begin();si<simplex.end();++si)
{ {
if ((((!(*si).IsD()))&&(*si).IsActive())) if ((((!(*si).IsD()))&&(*si).IsActive()))
{ {
@ -99,6 +125,7 @@ public:
} }
} }
///control the real self intersection in the mesh and returns the elements that intersect with someone ///control the real self intersection in the mesh and returns the elements that intersect with someone
std::vector<SimplexType*> computeSelfIntersection() std::vector<SimplexType*> computeSelfIntersection()
{ {

View File

@ -1,15 +1,17 @@
#include <qapplication.h> #include <qapplication.h>
#include <qimage.h> #include <qimage.h>
#include <segmentform.h> #include <segmentform.h>
#include <segmentator.h> //#include <segmentator.h>
#include <qdir.h> #include <qdir.h>
#include <qcolor.h> #include <qcolor.h>
#include <SimpleGLWidget.h> #include <SimpleGLWidget.h>
#include <qtimer.h> #include <qtimer.h>
Segmentator *s; Segmentator *s;
QTimer *timer; QTimer *timer;
int main( int argc, char ** argv ) int main( int argc, char ** argv )
{ {
s=new Segmentator(); s=new Segmentator();
@ -25,6 +27,7 @@ int main( int argc, char ** argv )
//assign pointer to pricipal form //assign pointer to pricipal form
w.simpleGLWidget1->w=&w; w.simpleGLWidget1->w=&w;
#ifdef _TORUS #ifdef _TORUS
w.simpleGLWidget1->SetExtractionParameters(); w.simpleGLWidget1->SetExtractionParameters();
@ -32,7 +35,8 @@ int main( int argc, char ** argv )
s->BBox().max=Point3f(300.f,300.f,300.f); s->BBox().max=Point3f(300.f,300.f,300.f);
s->InitSegmentation(Point3f(0.f,100.f,0.f)); s->InitSegmentation(Point3f(0.f,100.f,0.f));
#endif #endif
/*s=new Segmentator();*/ /*s=new Segmentator();*/
//s->LoadFromDir("./venacava/","prova.txt");//to chANGE //s->LoadFromDir("./venacava/","prova.txt");//to chANGE

View File

@ -3,7 +3,16 @@ LANGUAGE = C++
CONFIG += qt warn_on release CONFIG += qt warn_on release
win32:LIBS += qt-mt332.lib qtmain.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib imm32.lib winmm.lib wsock32.lib winspool.lib delayimp.lib opengl32.lib glu32.lib glew32.lib
DEFINES += QT_NO_DEBUG _WINDOWS UNICODE WIN32 QT_DLL QT_THREAD_SUPPORT _TORUS01 _EXTENDED_MARCH1
win32:DEFINES += QT_NO_DEBUG _WINDOWS UNICODE WIN32 QT_DLL QT_THREAD_SUPPORT _TORUS01 _EXTENDED_MARCH1
win32:INCLUDEPATH += "$(QTDIR)\include" . "C:\Qt\3.3.2\mkspecs\win32-msvc.net" D:\sf\apps\test\segmentation3d D:\sf
SOURCES += D:/sf/wrap/gui/trackmode.cpp \
D:/sf/wrap/gui/trackball.cpp \
D:/sf/wrap/ply/plylib.cpp \
simpleglwidget.cpp \
main.cpp
FORMS = segmentform.ui FORMS = segmentform.ui
@ -20,6 +29,154 @@ FORMS = segmentform.ui
unix { unix {
UI_DIR = .ui UI_DIR = .ui
MOC_DIR = .moc MOC_DIR = .moc

View File

@ -1,11 +1,15 @@
#ifndef SEGMENTATOR #ifndef __SEGMENTATOR
#define SEGMENTATOR #define __SEGMENTATOR
//#include <vcg/simplex/vertex/with/afvn.h>
//#include <vcg/simplex/face/with/afav.h>
#include <vcg/simplex/vertex/with/vn.h> ///need vertex-face topology in case of extended marching cubes
#include <vcg/simplex/face/with/af.h> #ifdef _EXTENDED_MARCH
#include <vcg/simplex/vertex/with/afvn.h>
#include <vcg/simplex/face/with/afavfnfmrt.h>
#else
#include <vcg/simplex/vertex/with/vn.h>
#include <vcg/simplex/face/with/afavfnfmrt.h>
#endif
#include <sim/particle/with/basic_physics.h> #include <sim/particle/with/basic_physics.h>
#include <sim/methods/mass_spring/triangle.h> #include <sim/methods/mass_spring/triangle.h>
@ -15,13 +19,26 @@
#include <vcg/complex/trimesh/allocate.h> #include <vcg/complex/trimesh/allocate.h>
#include <vcg/complex/trimesh/update/topology.h> #include <vcg/complex/trimesh/update/topology.h>
#include <vcg/complex/trimesh/update/normal.h> #include <vcg/complex/trimesh/update/normal.h>
#include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/update/edges.h>
#include <vcg/complex/trimesh/refine.h> #include <vcg/complex/trimesh/refine.h>
#include <vcg/complex/trimesh/platonic.h> #include <vcg/complex/trimesh/create/platonic.h>
#include <volume_dataset.h> #include <volume_dataset.h>
//#include <vcg/simplex/face/pos.h> //#include <vcg/simplex/face/pos.h>
///marching cubes
//#include <segmentation_wolker.h>
#include <vcg/complex/trimesh/create/resampler.h>
//#ifdef _EXTENDED_MARCH
// #include <vcg/complex/trimesh/create/extended_marching_cubes.h>
//#else
// #include <vcg/complex/trimesh/create/marching_cubes.h>
//#endif
#include <vcg/space/point3.h> #include <vcg/space/point3.h>
#include <vcg/space/box3.h> #include <vcg/space/box3.h>
@ -34,6 +51,10 @@
#include <collision_detection.h> #include <collision_detection.h>
#include <vcg/complex/trimesh/smooth.h> #include <vcg/complex/trimesh/smooth.h>
///debugghe
#include <wrap/io_trimesh/export_ply.h>
///debugghe
class Segmentator{ class Segmentator{
public: public:
@ -42,7 +63,11 @@ struct DummyEdge;
struct DummyTetra; struct DummyTetra;
struct MyFace; struct MyFace;
struct MyVertex: public ParticleBasic<vcg::VertexVNf<DummyEdge,MyFace,DummyTetra> > #ifdef _EXTENDED_MARCH
struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
#else
struct MyVertex: public ParticleBasic<vcg::VertexVNf<DummyEdge,MyFace,DummyTetra> >
#endif
{ {
public: public:
@ -55,6 +80,7 @@ public:
stopped=false; stopped=false;
Acc()=Point3f(0,0,0); Acc()=Point3f(0,0,0);
Vel()=Point3f(0,0,0); Vel()=Point3f(0,0,0);
ClearFlags();
//neeed call of the super class //neeed call of the super class
} }
@ -82,7 +108,7 @@ public:
}; };
///this class implements the deformable triangle in a mass spring system ///this class implements the deformable triangle in a mass spring system
struct MyFace : public TriangleMassSpring< vcg::FaceAF<MyVertex,DummyEdge,MyFace> > struct MyFace : public TriangleMassSpring< vcg::FaceAFAVFNFMRT<MyVertex,DummyEdge,MyFace> >
{ {
public: public:
bool intersected; bool intersected;
@ -163,11 +189,25 @@ typedef PDEIntegrator<Part_FaceContainer,Part_VertexContainer,float> myIntegrat
typedef Collision_Detector<std::vector<MyFace> > Collision; typedef Collision_Detector<std::vector<MyFace> > Collision;
////typedef Walker<MyTriMesh,MyTriMesh> MyWalk;
//
//#ifdef _EXTENDED_MARCH
// typedef vcg::tri::ExtendedMarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
//#else
// typedef vcg::tri::MarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
//#endif
public: public:
Point3f scale; Point3f scale;
//VolumetricDataset<int> d; //VolumetricDataset<int> d;
MyTriMesh m; /*MyTriMesh m;
MyTriMesh new_m;*/
MyTriMesh *m;
MyTriMesh *new_m;
Part_FaceContainer P_Faces; Part_FaceContainer P_Faces;
Part_VertexContainer P_Vertex; Part_VertexContainer P_Vertex;
Part_VertexContainer V_Stopped; Part_VertexContainer V_Stopped;
@ -206,7 +246,29 @@ public:
Segmentator() Segmentator()
{ {
CollDet=new Collision(m.face); m=new MyTriMesh();
CollDet=new Collision(m->face);
//m=NULL;
//scale=Point3f(5.f,5.f,5.f);
//InitialBarycenter=Point3f(20.f,20.f,20.f);
//InitMesh(m);
//vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(m);
//vcg::tri::UpdateBounding<MyTriMesh>::Box(m);
//vcg::tri::UpdateEdges<MyTriMesh>::Set(m);
///////debugghe
//edge_precision=4.f;
////edge_precision=1.f;
//float rx=this->m.bbox.DimX()/edge_precision;
//float ry=this->m.bbox.DimY()/edge_precision;
//float rz=this->m.bbox.DimZ()/edge_precision;
//Point3i res=Point3i((int)ceil(rx),(int)ceil(ry),(int)ceil(rz));
//// EXTENDED MARCHING CUBES
//MyWalk walker(m.bbox,res);
//MarchingCubes emc(new_m, walker);
//walker.BuildMesh<MarchingCubes>(m,new_m,emc);
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save(new_m,"D:/lillo.ply");
} }
~Segmentator() ~Segmentator()
@ -384,33 +446,34 @@ private:
///re-set physical pararmeters on the mesh ///re-set physical pararmeters on the mesh
void InitPhysParam(float k_elanst,float mass,float k_dihedral) void InitPhysParam(float k_elanst,float mass,float k_dihedral)
{ {
for (unsigned int i=0;i<m.face.size();i++) for (unsigned int i=0;i<m->face.size();i++)
{ {
m.face[i].Init(k_elanst,mass,k_dihedral); m->face[i].Init(k_elanst,mass,k_dihedral);
} }
} }
///set the initial mesh of deformable object ///set the initial mesh of deformable object
void InitMesh(MyTriMesh &m) void InitMesh(MyTriMesh *m)
{ {
m.Clear(); m->Clear();
vcg::tri::Icosahedron<MyTriMesh>(m); vcg::tri::Icosahedron<MyTriMesh>(*m);
vcg::tri::UpdateTopology<MyTriMesh>::FaceFace(m); vcg::tri::UpdateTopology<MyTriMesh>::FaceFace(*m);
/* P_Vertex.clear(); /* P_Vertex.clear();
P_Faces.clear();*/ P_Faces.clear();*/
for (unsigned int i=0;i<m.vert.size();i++) for (unsigned int i=0;i<m->vert.size();i++)
{ {
m.vert[i].P()+=InitialBarycenter; m->vert[i].P()=UnScale(m->vert[i].P());///last change
m.vert[i].P()=UnScale(m.vert[i].P()); m->vert[i].P()+=InitialBarycenter;
// m.vert[i].P()=UnScale(m.vert[i].P());
// 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);
} }
@ -490,7 +553,7 @@ void Reinit_PVectors()
P_Vertex.clear(); P_Vertex.clear();
MyTriMesh::VertexIterator vi; MyTriMesh::VertexIterator vi;
for (vi=m.vert.begin();vi<m.vert.end();vi++) for (vi=m->vert.begin();vi<m->vert.end();vi++)
{ {
if ((!vi->IsD())&&(!vi->blocked)) if ((!vi->IsD())&&(!vi->blocked))
P_Vertex.push_back(&(*vi)); P_Vertex.push_back(&(*vi));
@ -500,7 +563,7 @@ void Reinit_PVectors()
P_Faces.clear(); P_Faces.clear();
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->IsBlocked())) //if ((!fi->IsBlocked()))
if ((!fi->IsD())&&(!fi->IsBlocked())) if ((!fi->IsD())&&(!fi->IsBlocked()))
@ -516,7 +579,7 @@ void Refresh_PVectors()
P_FacesAux.clear(); P_FacesAux.clear();
P_VertexAux.clear(); P_VertexAux.clear();
int i=0; unsigned int i=0;
for (i=0;i<P_Vertex.size();i++) for (i=0;i<P_Vertex.size();i++)
{ {
if (!P_Vertex[i]->blocked) if (!P_Vertex[i]->blocked)
@ -539,13 +602,13 @@ void Refresh_PVectors()
///add the new elements on partial vectors when allocate space for new vertices ///add the new elements on partial vectors when allocate space for new vertices
void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi) void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
{ {
while (vi!=m.vert.end()) while (vi!=m->vert.end())
{ {
if (!(*vi).IsD()) if (!(*vi).IsD())
P_Vertex.push_back(&(*vi)); P_Vertex.push_back(&(*vi));
vi++; vi++;
} }
while (fi!=m.face.end()) while (fi!=m->face.end())
{ {
if (!(*fi).IsD()) if (!(*fi).IsD())
P_Faces.push_back(&(*fi)); P_Faces.push_back(&(*fi));
@ -597,24 +660,24 @@ bool TimeSelfIntersection()
///refine the mesh and re-update eventually ///refine the mesh and re-update eventually
void RefineStep(float _edge_size) void RefineStep(float _edge_size)
{ {
MyTriMesh::VertexIterator vinit=m.vert.begin(); MyTriMesh::VertexIterator vinit=m->vert.begin();
MyTriMesh::FaceIterator finit=m.face.begin(); MyTriMesh::FaceIterator finit=m->face.begin();
MyTriMesh::VertexIterator vend=m.vert.end(); MyTriMesh::VertexIterator vend=m->vert.end();
MyTriMesh::FaceIterator fend=m.face.end(); MyTriMesh::FaceIterator fend=m->face.end();
refined=vcg::Refine(m,MidPoint<MyTriMesh>(),_edge_size); refined=vcg::Refine(*m,MidPoint<MyTriMesh>(),_edge_size);
if (refined) if (refined)
{ {
MyTriMesh::VertexIterator vinit2=m.vert.begin(); MyTriMesh::VertexIterator vinit2=m->vert.begin();
MyTriMesh::FaceIterator finit2=m.face.begin(); MyTriMesh::FaceIterator finit2=m->face.begin();
if ((vinit2!=vinit)||(finit2!=finit)) if ((vinit2!=vinit)||(finit2!=finit))
Reinit_PVectors(); Reinit_PVectors();
else else
AddNewElements(vend,fend); AddNewElements(vend,fend);
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(m); vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);
CollDet->RefreshElements(); CollDet->RefreshElements();
} }
} }
@ -648,7 +711,8 @@ void ClearStopped()
///do one step of controls for self collision detetction ///do one step of controls for self collision detetction
void CollisionDetection() void CollisionDetection()
{ {
CollDet->UpdateStep(); //CollDet->UpdateStep();
CollDet->UpdateStep<Part_FaceContainer>(P_Faces);
std::vector<MyFace*> coll=CollDet->computeSelfIntersection(); std::vector<MyFace*> coll=CollDet->computeSelfIntersection();
for (std::vector<MyFace*>::iterator it=coll.begin();it<coll.end();it++) for (std::vector<MyFace*>::iterator it=coll.begin();it<coll.end();it++)
{ {
@ -736,7 +800,7 @@ vcg::Box3<float> BBox()
///one step of moving for the deformable object ///one step of moving for the deformable object
void Step(float t,float _edge_size) void Step(float t,float _edge_size)
{ {
if (m.face.size()!=0) if (m->face.size()!=0)
{ {
AddExtForces(); AddExtForces();
TrINT->Step(t); TrINT->Step(t);
@ -755,7 +819,7 @@ void Step(float t,float _edge_size)
void Smooth() void Smooth()
{ {
ScaleLaplacianSmooth<MyTriMesh>(m,1,0.5); ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5);
} }
void AutoStep() void AutoStep()
@ -763,7 +827,7 @@ void AutoStep()
refined=false; refined=false;
Step(time_stamp,edge_size); Step(time_stamp,edge_size);
//test on 80% of the vertex blocked //test on 80% of the vertex blocked
if ((((float)P_Vertex.size()/(float)m.vn)<0.2)&&(end_loop)&&(!refined)&&(edge_size>edge_precision)) if ((((float)P_Vertex.size()/(float)m->vn)<0.2)&&(end_loop)&&(!refined)&&(edge_size>edge_precision))
{ {
edge_size/=2.f; edge_size/=2.f;
if (edge_size<edge_precision) if (edge_size<edge_precision)
@ -772,5 +836,21 @@ void AutoStep()
} }
} }
///first version
void Resample()
{
new_m=new MyTriMesh();
vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m,
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision));
delete(m);
m=new_m;
Reinit_PVectors();
ReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f);
}
}; };
#endif #endif

View File

@ -234,6 +234,12 @@
<pointsize>10</pointsize> <pointsize>10</pointsize>
</font> </font>
</property> </property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="text"> <property name="text">
<string>0.2</string> <string>0.2</string>
</property> </property>
@ -361,117 +367,6 @@
<string>mass of particles</string> <string>mass of particles</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton">
<property name="name">
<cstring>ClearButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>700</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>SaveButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>660</y>
<width>140</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>SavePly</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>SmoothButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>620</y>
<width>140</width>
<height>30</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="cursor">
<cursor>1</cursor>
</property>
<property name="text">
<string>Smooth</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>SegmentButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>580</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Extract</string>
</property>
<property name="toggleButton">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>ApplyButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>540</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QLabel"> <widget class="QLabel">
<property name="name"> <property name="name">
<cstring>textLabel1_2_2_2_3</cstring> <cstring>textLabel1_2_2_2_3</cstring>
@ -691,6 +586,141 @@
<number>3</number> <number>3</number>
</property> </property>
</widget> </widget>
<widget class="QPushButton">
<property name="name">
<cstring>SmoothButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>660</y>
<width>140</width>
<height>30</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="cursor">
<cursor>0</cursor>
</property>
<property name="text">
<string>Smooth</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>SaveButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>700</y>
<width>140</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>SavePly</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>SegmentButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>580</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Extract</string>
</property>
<property name="toggleButton">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>ClearButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>740</y>
<width>140</width>
<height>30</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="cursor">
<cursor>0</cursor>
</property>
<property name="text">
<string>ClearMesh</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Marching_Cubes</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>619</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Marching Cube</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>ApplyButton</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>540</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</widget> </widget>
<widget class="SimpleGLWidget"> <widget class="SimpleGLWidget">
<property name="name"> <property name="name">
@ -746,9 +776,9 @@
<slot access="public" specifier="">SavePly()</slot> <slot access="public" specifier="">SavePly()</slot>
<slot access="public" specifier="">Extract()</slot> <slot access="public" specifier="">Extract()</slot>
<slot access="public" specifier="">Apply()</slot> <slot access="public" specifier="">Apply()</slot>
<slot access="public" specifier="">Clear()</slot>
<slot access="public" specifier="">slot()</slot>
<slot access="public" specifier="">Open()</slot> <slot access="public" specifier="">Open()</slot>
<slot access="public" specifier="">CleanMesh()</slot>
<slot access="public" specifier="">Clear()</slot>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<actions> <actions>
@ -895,12 +925,6 @@
<receiver>simpleGLWidget1</receiver> <receiver>simpleGLWidget1</receiver>
<slot>Apply()</slot> <slot>Apply()</slot>
</connection> </connection>
<connection>
<sender>ClearButton</sender>
<signal>pressed()</signal>
<receiver>simpleGLWidget1</receiver>
<slot>Clear()</slot>
</connection>
<connection> <connection>
<sender>fileOpenAction</sender> <sender>fileOpenAction</sender>
<signal>activated()</signal> <signal>activated()</signal>
@ -913,7 +937,22 @@
<receiver>simpleGLWidget1</receiver> <receiver>simpleGLWidget1</receiver>
<slot>SavePly()</slot> <slot>SavePly()</slot>
</connection> </connection>
<connection>
<sender>Marching_Cubes</sender>
<signal>pressed()</signal>
<receiver>simpleGLWidget1</receiver>
<slot>CleanMesh()</slot>
</connection>
<connection>
<sender>ClearButton</sender>
<signal>pressed()</signal>
<receiver>simpleGLWidget1</receiver>
<slot>Clear()</slot>
</connection>
</connections> </connections>
<includes>
<include location="local" impldecl="in declaration">simpleglwidget.h</include>
</includes>
<pixmapinproject/> <pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/> <layoutdefaults spacing="6" margin="11"/>
<includehints> <includehints>

View File

@ -20,11 +20,22 @@ QGLWidget(parent, name)
resultForces=false; resultForces=false;
continue_int=false; continue_int=false;
_numslide=0; _numslide=0;
Track.center=Point3f(0,0,0);
Track.Reset(); TrackM.center=Point3f(0,0,0);
Track.radius= 100; TrackM.Reset();
TrackM.radius= 100.f;
TrackS.center=Point3f(0,0,0);
TrackS.Reset();
TrackS.radius= 100.f;
zoom=1; zoom=1;
path=""; 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() void SimpleGLWidget::SaveMatrix()
@ -185,7 +196,7 @@ void SimpleGLWidget::Save()
if (filename!=NULL) if (filename!=NULL)
{ {
const char *path_save=filename.ascii(); const char *path_save=filename.ascii();
vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save(s->m,path_save); vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),path_save);
} }
} }
@ -267,27 +278,29 @@ void SimpleGLWidget::glDraw(){
if (_showslides) if (_showslides)
{ {
vcg::Point3f p=Point3f((float)s->BBox().Center().V(0),(float)s->BBox().Center().V(1),(float)s->BBox().Center().V(2)); vcg::Point3f p=Point3f((float)s->BBox().Center().V(0),(float)s->BBox().Center().V(1),(float)s->BBox().Center().V(2));
Track.radius=s->BBox().Diag(); TrackS.radius=s->BBox().Diag();
Track.GetView(); TrackS.GetView();
Track.Apply(); TrackS.Apply();
Track.Draw(); TrackS.Draw();
glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag()); glScalef(1.f/s->BBox().Diag(),1.f/s->BBox().Diag(),1.f/s->BBox().Diag());
glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom)); //glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom));
glTranslate(-p); glTranslate(-p);
//save transformation matrixes //save transformation matrixes
SaveMatrix(); SaveMatrix();
} }
else else
{ {
vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m); if (s->m!=NULL)
vcg::Point3f p=s->m.bbox.Center(); {
Track.radius=s->m.bbox.Diag(); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
Track.GetView(); vcg::Point3f p=s->m->bbox.Center();
Track.Apply(); TrackM.GetView();
Track.Draw(); TrackM.Apply();
glScalef(1/s->m.bbox.Diag(),1/s->m.bbox.Diag(),1/s->m.bbox.Diag()); TrackM.Draw();
glScalef(GLfloat(zoom),GLfloat(zoom),GLfloat(zoom)); glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
glTranslate(-p); glTranslate(-p);
//glScalef(1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag(),1.f/s->m->bbox.Diag());
}
} }
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
@ -324,9 +337,11 @@ void SimpleGLWidget::glDraw(){
glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_FRONT,GL_FILL);
int i=0; int i=0;
glBegin(GL_TRIANGLES); if (s->m!=NULL)
for (fi=s->m.face.begin();fi<s->m.face.end();fi++)
{ {
glBegin(GL_TRIANGLES);
for (fi=s->m->face.begin();fi<s->m->face.end();fi++)
{
glColor3d(0.4,0.8,0.8); glColor3d(0.4,0.8,0.8);
if (fi->intersected) if (fi->intersected)
glColor3d(1.f,0,0); glColor3d(1.f,0,0);
@ -343,7 +358,7 @@ void SimpleGLWidget::glDraw(){
} }
} }
glEnd(); glEnd();
}
glPopMatrix(); glPopMatrix();
//WriteInfo(); //WriteInfo();
@ -390,15 +405,32 @@ void SimpleGLWidget::resizeGL( int w, int h )
void SimpleGLWidget::ClearMesh() void SimpleGLWidget::ClearMesh()
{ {
s->m.Clear(); s->m->Clear();
repaint(); repaint();
} }
void SimpleGLWidget::UpdateBBMesh()
{
vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
}
void SimpleGLWidget::mousePressEvent ( QMouseEvent * e ) void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
{ {
if (e->button()==Qt::LeftButton ) if (e->button()==Qt::LeftButton )
Track.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); {
if ((!_showslides)&&(s->m!=NULL))
{
/*vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
TrackM.radius=s->m->bbox.Diag();
TrackM.center=s->m->bbox.Center();
*/
UpdateBBMesh();
TrackM.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
}
else if (_showslides)
TrackS.MouseDown(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT);
}
else else
//test mass spring model //test mass spring model
if ((e->button()==Qt::RightButton)&&(_showslides)) if ((e->button()==Qt::RightButton)&&(_showslides))
@ -417,6 +449,8 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
//s->SetInitialBarycenter(Point3f(x,y,_numslide)); //s->SetInitialBarycenter(Point3f(x,y,_numslide));
//s->InitSegmentation(Point3f(x,y,_numslide)); //s->InitSegmentation(Point3f(x,y,_numslide));
s->InitSegmentation(Point3f(x,y,z)); s->InitSegmentation(Point3f(x,y,z));
UpdateBBMesh();
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
repaint(); repaint();
} }
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m);
@ -426,7 +460,9 @@ void SimpleGLWidget::wheelEvent(QWheelEvent *e)
{ {
if (!_showslides) if (!_showslides)
{ {
zoom+=e->delta()/120.f; /* zoom+=e->delta()/120.f;
repaint();*/
TrackM.MouseWheel(e->delta()/120.f);
repaint(); repaint();
} }
else else
@ -446,7 +482,11 @@ void SimpleGLWidget::wheelEvent(QWheelEvent *e)
void SimpleGLWidget::mouseReleaseEvent(QMouseEvent * e ) void SimpleGLWidget::mouseReleaseEvent(QMouseEvent * e )
{ {
Track.MouseUp(e->x(),_H-e->y(),vcg::Trackball::BUTTON_LEFT); 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(); repaint();
} }
@ -459,6 +499,15 @@ void SimpleGLWidget::Step()
} }
} }
void SimpleGLWidget::MarchingCube()
{
if (s->m->fn>0)
s->Resample();
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->new_m),"d:/march.ply");
//vcg::tri::io::ExporterPLY<Segmentator::MyTriMesh>::Save((*s->m),"d:/march.ply");
}
void SimpleGLWidget::SetExtractionParameters() void SimpleGLWidget::SetExtractionParameters()
{ {
float mass=atof(w->M_particles->text()); float mass=atof(w->M_particles->text());
@ -476,7 +525,11 @@ void SimpleGLWidget::SetExtractionParameters()
void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e ) void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )
{ {
Track.MouseMove(e->x(),_H-e->y()); if (_showslides)
TrackS.MouseMove(e->x(),_H-e->y());
else
TrackM.MouseMove(e->x(),_H-e->y());
repaint(); repaint();
} }

View File

@ -1,14 +1,14 @@
#include <GL\glew.h> #include <GL/glew.h>
#include <qgl.h> #include <qgl.h>
#include <wrap\gl\trimesh.h> #include <wrap/gl/trimesh.h>
#include <wrap\gui\trackball.h> #include <wrap/gui/trackball.h>
#include <segmentator.h> #include <segmentator.h>
#include <sim/tri_pde_integrator.h> #include <sim/tri_pde_integrator.h>
#include <vcg/complex/trimesh/update/bounding.h> #include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/update/bounding.h>
#include <wrap/io_trimesh/export_ply.h> #include <wrap/io_trimesh/export_ply.h>
#include <segmentform.h> #include <segmentform.h>
#include <qpushbutton.h> #include <qpushbutton.h>
#include <qtimer.h>
class SimpleGLWidget: public QGLWidget{ class SimpleGLWidget: public QGLWidget{
@ -17,7 +17,8 @@ Q_OBJECT
private : private :
int _H; int _H;
int _W; int _W;
vcg::Trackball Track; vcg::Trackball TrackM;
vcg::Trackball TrackS;
double zoom; double zoom;
GLdouble projection[16]; GLdouble projection[16];
GLdouble modelMatrix[16]; GLdouble modelMatrix[16];
@ -31,7 +32,8 @@ private :
bool resultForces; bool resultForces;
bool continue_int; bool continue_int;
GLuint texName; GLuint texName;
//Segmentator *s;
//QTimer *timer;
//vcg::GlTrimesh<Segmentator::MyTriMesh> *Wrap; //vcg::GlTrimesh<Segmentator::MyTriMesh> *Wrap;
public: public:
@ -59,7 +61,8 @@ public:
void WriteInfo(); void WriteInfo();
void ClearMesh(); void ClearMesh();
void OpenDirectory(); void OpenDirectory();
void MarchingCube();
void UpdateBBMesh();
//virtual void keyPressEvent(QKeyEvent *qk); //virtual void keyPressEvent(QKeyEvent *qk);
@ -73,6 +76,7 @@ public:
void ShowSlides() void ShowSlides()
{ {
_showslides=!_showslides; _showslides=!_showslides;
UpdateBBMesh();
repaint(); repaint();
} }
@ -124,17 +128,21 @@ public:
void Extract() void Extract()
{ {
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);
} }
else else
{ {
_showslides=true; _showslides=true;
w->SlidesButton->setOn(true); w->SlidesButton->setOn(true);
//((SegmentForm *)this->parent())->SlidesButton->setOn(true);
} }
repaint();
} }
void Update() void Update()
@ -142,8 +150,18 @@ public:
Step(); Step();
} }
void Clear() void Clear()
{ {
ClearMesh(); ClearMesh();
repaint();
} }
void CleanMesh()
{
MarchingCube();
UpdateBBMesh();
repaint();
}
}; };