minor changes

This commit is contained in:
Nico Pietroni 2005-07-18 15:46:23 +00:00
parent d34f797d3f
commit a506fdf8c7
8 changed files with 399 additions and 168 deletions

View File

@ -82,6 +82,7 @@ public:
{
if (!(*si).IsD())
{
(*si).Mark()=0;
if (!(*si).IsActive())
HTable->AddElem(&*si);

View File

@ -31,8 +31,8 @@ int main( int argc, char ** argv )
#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,15);
s->SetSegmentParameters(10,0.5f,0.8f,0.8f,0.2f,3.f,vcg::Point3f(1.f,1.f,1.f),1000,15);
//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));
@ -50,7 +50,7 @@ int main( int argc, char ** argv )
timer = new QTimer(w.simpleGLWidget1 );
QTimer::connect( timer, SIGNAL(timeout()), w.simpleGLWidget1, SLOT(Update()) );
timer->start(0); // 2 seconds single-shot timer
timer->start(0); //
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

View File

@ -242,6 +242,26 @@ FORMS = segmentform.ui \

View File

@ -8,8 +8,8 @@
// #include <vcg/simplex/face/with/afavfnfmrt.h>
//#else
#include <vcg/simplex/vertex/with/vn.h>
#include <vcg/simplex/face/with/affnfmrt.h>
#include <vcg/simplex/vertex/with/afvn.h>
#include <vcg/simplex/face/with/afavfnfmrt.h>
//#endif
@ -43,6 +43,7 @@
#include <vcg/simplex/face/topology.h>
#include <vcg/complex/trimesh/update/topology.h>
//#include <mymarchingCubes.h>
class Segmentator{
@ -52,11 +53,11 @@ struct DummyEdge;
struct DummyTetra;
struct MyFace;
#ifdef _EXTENDED_MARCH
//#ifdef _EXTENDED_MARCH
// struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
//#else
struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
#else
struct MyVertex: public ParticleBasic<vcg::VertexVNf<DummyEdge,MyFace,DummyTetra> >
#endif
//#endif
{
public:
@ -100,7 +101,7 @@ public:
};
///this class implements the deformable triangle in a mass spring system
struct MyFace : public TriangleMassSpring< vcg::FaceAFFNFMRT<MyVertex,DummyEdge,MyFace> >
struct MyFace : public TriangleMassSpring< vcg::FaceAFAVFNFMRT<MyVertex,DummyEdge,MyFace> >
{
public:
bool intersected;
@ -108,18 +109,28 @@ public:
ScalarType AreaRep;
int _Mark;
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()
@ -171,7 +182,7 @@ public:
///update of the internal forces using the dihedral angle
bool Update ( void )
{
if (!IsD()&&(!intersected))//if this face is not deleted
if (!IsD())//&&(!intersected))//if this face is not deleted
{
for (int i=0;i<3;i++)
{
@ -185,6 +196,15 @@ public:
if ((fopp<myAddr)&&(!fopp->intersected))//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);
@ -210,33 +230,7 @@ public:
}
}
}
////area changing constrain penalize area goes to zero
//CoordType m0=(V(0)->P()+V(1)->P())/2.f;
//CoordType m1=(V(1)->P()+V(2)->P())/2.f;
//CoordType m2=(V(2)->P()+V(0)->P())/2.f;
//m0=(V(2)->P()-m0).Normalize();//directions
//m1=(V(0)->P()-m1).Normalize();
//m2=(V(1)->P()-m2).Normalize();
//ScalarType FArea=((ScalarType)1/AreaRep-Area())*_k;
//V(0)->IntForce()+=m0*FArea/3.f;
//V(1)->IntForce()+=m1*FArea/3.f;
//V(2)->IntForce()+=m2*FArea/3.f;
////end area constrain
return(__super::Update());
///new
//double stretch;
//CoordType direction;
/////for each vertex
//for (int i=0;i<3;i++)
//{
// //spring on the face
// direction=(V(i)->RPos()-V(i)->P());
// stretch=direction.Norm();
// direction.Normalize();
// V(i)-> IntForce()+=direction*(stretch * _k)/2.f;
//}
}
return true;
///new
@ -371,7 +365,7 @@ private:
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))
if (InTorus(p))//||InTorus(p1)||InTorus(p2))
return (100.f);
else
return (0.f);
@ -489,6 +483,8 @@ private:
{
f->intersected=true;
f->ClearS();
SetBlockedFace(f);
//if ((!f->intersected)&&(!f->IsD()))
//{
// f->intersected=true;
@ -589,11 +585,10 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
void AddExtForces()
{
Part_VertexContainer::iterator vi;
//PartialUpdateNormals();
/*PartialUpdateNormals();*/
end_loop=true;
for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi)
{
if (!(*vi).IsD())
{
if (OutOfLimits((*vi).P()))
@ -637,7 +632,7 @@ void Reinit_PVectors()
{
if ((!vi->IsD())&&(!vi->blocked))
P_Vertex.push_back(&(*vi));
if ((!vi->IsD())&&((*vi).stopped)&&(!vi->blocked))
if ((!vi->IsD())&&((*vi).stopped)&&(!vi->blocked))///to see
V_Stopped.push_back(&(*vi));
}
@ -645,7 +640,7 @@ void Reinit_PVectors()
MyTriMesh::FaceIterator fi;
for (fi=m->face.begin();fi<m->face.end();fi++)
{
if ((!fi->IsD())&&(!fi->IsBlocked()))
if ((!fi->IsD())&&(!fi->IsBlocked())&&(!fi->intersected))
P_Faces.push_back(&(*fi));
}
}
@ -659,17 +654,20 @@ void Refresh_PVectors()
P_VertexAux.clear();
unsigned int i=0;
///as first control normal inversion
for (i=0;i<P_Faces.size();i++)
if (P_Faces[i]->NormInversion())//if one step inversion the block vertices
SetIntersectedFace(P_Faces[i]);
else
P_Faces[i]->old_N=NormalizedNormal<MyFace>(*P_Faces[i]);
for (i=0;i<P_Vertex.size();i++)
{
if ((!P_Vertex[i]->IsD())&&(!P_Vertex[i]->blocked))
if ((!P_Vertex[i]->IsD())&&(!P_Vertex[i]->blocked))//&&(!P_Vertex[i]->stopped))
P_VertexAux.push_back(P_Vertex[i]);
}
for (i=0;i<P_Faces.size();i++)
{
if ((!P_Faces[i]->IsD())&&(!P_Faces[i]->IsBlocked()))
if ((!P_Faces[i]->IsD())&&(!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();
@ -739,8 +737,8 @@ bool TimeSelfIntersection()
void PartialUpdateNormals()
{
//vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
//vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);
/*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/
Part_FaceContainer::iterator fi;
for (fi=P_Faces.begin();fi<P_Faces.end();++fi)
if (!(*fi).IsD())
@ -755,7 +753,7 @@ void PartialUpdateNormals()
for(fi=P_Faces.begin();fi!=P_Faces.end();++fi)
if( !(*fi).IsD() && (*fi).IsR() )
{
MyFace::NormalType t = (*fi).Normal();
MyFace::NormalType t = (*fi).N();
for(int j=0; j<3; ++j)
if( !(*fi).V(j)->IsD() && (*fi).V(j)->IsRW() )
(*fi).V(j)->N() += t;
@ -765,6 +763,30 @@ void PartialUpdateNormals()
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();vi<P_Vertex.end();++vi)
// if( !(*vi).IsD() && (*vi).IsRW() )
// (*vi).N() = MyVertex::NormalType(0.f,0.f,0.f);
//for(fi=m->face.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()
@ -829,6 +851,7 @@ void RefineStep(float _edge_size)
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/
PartialUpdateNormals();
PartialReinitPhysicMesh();
//#ifdef _DEBUG
// vcg::tri::UpdateTopology<MyTriMesh>::TestFaceFace(*m);
@ -839,14 +862,10 @@ void RefineStep(float _edge_size)
}
///reset vertex position and unblock them
void ReinitPhysicMesh()
void PartialReinitPhysicMesh()
{
Part_FaceContainer::iterator pfi;
/*for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi)
if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral);*/
Part_VertexContainer::iterator pvi;
for (pvi=P_Vertex.begin();pvi<P_Vertex.end();++pvi)
if(!(*pvi).IsD())
@ -856,8 +875,19 @@ void ReinitPhysicMesh()
if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral);
/*MyTriMesh::VertexIterator pvi;
MyTriMesh::FaceIterator pfi;
//PartialUpdateNormals();
for (pvi=m->vert.begin();pvi<m->vert.end();++pvi)
if(!(*pvi).IsD())
(*pvi).SetRestPos();
for (pfi=m->face.begin();pfi<m->face.end();++pfi)
if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral);
PartialUpdateNormals();*/
/*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
ClearStopped(&*vi);*/
@ -907,14 +937,23 @@ void LoadFromDir(char *in, char *out)
{
inDir=in;
outDir=out;
//caso optimized
/*V.Resample(inDir,outDir);
/*V.LoadJpg(inDir,outDir);
V.Init(1000,outDir);*/
V.Load(inDir);
V.LoadJpg(inDir);
bbox=vcg::Box3<float>(MapToSpace((V.Min())),(MapToSpace(V.Max())));
}
///set the input
void LoadFromRaw(char *inDir)
{
/*V.LoadRaw(inDir);
bbox=vcg::Box3<float>(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),
@ -952,7 +991,7 @@ void InitSegmentation(MyTriMesh::CoordType b)
//init the mesh with new
Reinit_PVectors();
ReinitPhysicMesh();
PartialReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f);
}
@ -970,13 +1009,16 @@ void Step(float t,float _edge_size)
{
AddExtForces();
TrINT->Step(t);
PartialUpdateNormals();
VerifyForces();
Refresh_PVectors();
if (end_loop)
{
RefineStep(_edge_size);
ReinitPhysicMesh();
ClearStopped();
Reinit_PVectors();
PartialReinitPhysicMesh();
RefineStep(_edge_size);
/*ReinitPhysicMesh();*/
}
if (TimeSelfIntersection())
CollisionDetection();
@ -985,7 +1027,9 @@ void Step(float t,float _edge_size)
void Smooth()
{
ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5);
//ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5);
vcg::tri::UpdateTopology<MyTriMesh>::VertexFace(*m);
PasoDobleSmooth<MyTriMesh>(*m,1);
}
void AutoStep()
@ -1002,6 +1046,18 @@ void AutoStep()
}
}
//void MarchingCubeExtraction()
//{
// /*
// new_m = new MyTriMesh();
// mcE.Extract(gray_init,&V,vcg::Point3i(2,2,2),*new_m);*/
//
// MC_Extractor<MyTriMesh> 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()
{
@ -1033,14 +1089,14 @@ void Resample()
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision),edge_init);
#else
vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m,
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision),edge_size*2.f);
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();
ReinitPhysicMesh();
PartialReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f);
}

View File

@ -15,7 +15,7 @@
<property name="minimumSize">
<size>
<width>211</width>
<height>839</height>
<height>868</height>
</size>
</property>
<property name="caption">
@ -559,75 +559,6 @@
<string>SavePly</string>
</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>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>
@ -710,22 +641,6 @@
<enum>Horizontal</enum>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>GrayScale</cstring>
</property>
<property name="geometry">
<rect>
<x>14</x>
<y>460</y>
<width>170</width>
<height>31</height>
</rect>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
<cstring>T_step</cstring>
@ -756,6 +671,94 @@
<number>3</number>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>GrayScale</cstring>
</property>
<property name="geometry">
<rect>
<x>14</x>
<y>460</y>
<width>170</width>
<height>31</height>
</rect>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Marching_Cubes</cstring>
</property>
<property name="geometry">
<rect>
<x>30</x>
<y>620</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Resample mesh</string>
</property>
<property name="accel">
<string>Down, Down, Esc, Ctrl+Z</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>
</hbox>
</widget>
@ -769,6 +772,10 @@
<separator/>
<separator/>
<action name="fileExitAction"/>
<action name="fileOpenRawAction"/>
</item>
<separator/>
<item text="new menu" name="new_menu">
</item>
</menubar>
<toolbars>
@ -802,8 +809,9 @@
<slot access="public" specifier="">Open()</slot>
<slot access="public" specifier="">CleanMesh()</slot>
<slot access="public" specifier="">Clear()</slot>
<slot access="public" specifier="">slot()</slot>
<slot access="public" specifier="">SetSegmentColor()</slot>
<slot access="public" specifier="">OpenRawFile()</slot>
<slot access="public" specifier="">slot()</slot>
</customwidget>
</customwidgets>
<actions>
@ -883,6 +891,17 @@
<string>new item</string>
</property>
</action>
<action>
<property name="name">
<cstring>fileOpenRawAction</cstring>
</property>
<property name="text">
<string>OpenRaw</string>
</property>
<property name="menuText">
<string>OpenRaw</string>
</property>
</action>
</actions>
<images>
<image name="image0">
@ -980,6 +999,12 @@
<receiver>simpleGLWidget1</receiver>
<slot>SetSegmentColor()</slot>
</connection>
<connection>
<sender>fileOpenRawAction</sender>
<signal>activated()</signal>
<receiver>simpleGLWidget1</receiver>
<slot>OpenRawFile()</slot>
</connection>
</connections>
<pixmapinproject/>
<layoutdefaults spacing="2" margin="4"/>

View File

@ -55,13 +55,16 @@ void SimpleGLWidget::LoadMatrix()
}
//load as texture the i jpg of the directory
void SimpleGLWidget::LoadTexture(QString p,int level)
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;
@ -78,7 +81,21 @@ void SimpleGLWidget::LoadTexture(QString p,int level)
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()
@ -88,9 +105,12 @@ void SimpleGLWidget::drawSlide()
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glEnable(GL_NORMALIZE);
/*glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
*/
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
float dx=s->BBox().DimX();
@ -107,7 +127,7 @@ void SimpleGLWidget::drawSlide()
Point3f p2=p0+Point3f(dx,dy,0.f);
Point3f p3=p0+Point3f(0.f,dy,0.f);
glColor3d(1,1,1);
glColor3d(0.8,0.8,0.8);
///texture
//_numslide
@ -263,7 +283,8 @@ void SimpleGLWidget::SmoothMesh()
}
void SimpleGLWidget::glDraw(){
glClearColor(0.2f,0.2f,0.2f,1.f);
//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();
@ -352,7 +373,14 @@ void SimpleGLWidget::glDraw(){
assert(0);
*/
glColor3d(0.4,0.8,0.8);
//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);
@ -396,12 +424,36 @@ void SimpleGLWidget::OpenDirectory()
"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");
LoadTexture(p,0);
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();
@ -506,7 +558,10 @@ void SimpleGLWidget::wheelEvent(QWheelEvent *e)
_numslide=oldnum;
if (s!=0)
{
LoadTexture(path,_numslide);
if (!rawImage)
LoadTextureJpg(path,_numslide);
else
LoadTextureRaw(_numslide);
}
}
@ -532,6 +587,15 @@ void SimpleGLWidget::Step()
}
}
//void SimpleGLWidget::MarchingCubesExtraction()
// {
// if (s!=0)
// {
// s->MarchingCubeExtraction();
// repaint();
// }
// }
void SimpleGLWidget::MarchingCube()
{
if (s->m->fn>0)

View File

@ -31,6 +31,7 @@ private :
bool intForces;
bool resultForces;
bool continue_int;
bool rawImage;
GLuint texName;
//Segmentator *s;
@ -55,7 +56,8 @@ public:
virtual void SaveMatrix();
virtual void Save();
void LoadMatrix();
void LoadTexture(QString path,int level);
void LoadTextureJpg(QString path,int level);
void LoadTextureRaw(int level);
void drawSlide();
void SmoothMesh();
void Step();
@ -63,10 +65,11 @@ public:
void WriteInfo();
void ClearMesh();
void OpenDirectory();
void OpenRaw();
void MarchingCube();
void UpdateBBMesh();
void setColor();
//void MarchingCubesExtraction();
//virtual void keyPressEvent(QKeyEvent *qk);
public slots:
@ -75,6 +78,11 @@ public:
{
OpenDirectory();
}
void OpenRawFile()
{
OpenRaw();
}
void ShowSlides()
{
@ -147,6 +155,25 @@ public:
//}
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()
{
@ -168,7 +195,12 @@ public:
#endif
repaint();
}
/*
void MCExtraction()
{
MarchingCubesExtraction();
}*/
void SetSegmentColor()
{
setColor();

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <list>
#include <algorithm>
#include <stdlib.h>
#define LimX 512
#define LimY 512
@ -200,7 +201,7 @@ private:
public:
///build and save the strucure made fo blocks
void Resample(char *path,char *_newFile)
void LoadJpg(char *path,char *_newFile)
{
pFile=fopen (_newFile,"w+b");
@ -256,7 +257,7 @@ public:
}
///set initial size of buffer in terms of cell
void Init(int size,char* archive,int timeSort=3000)
void Init(int size,char* archive,int _timeSort=3000)
{
timestamp=0;
n_element=0;
@ -264,6 +265,7 @@ public:
CurrStack.clear();
pFile=fopen (archive,"r+b");
timestamp=0;
timesort=_timeSort;
for(int z=0;z<TLBz;z++)
for(int x=0;x<TLBx;x++)
for(int y=0;y<TLBy;y++)
@ -405,9 +407,39 @@ public:
}
public:
/*template <class Type, int N=1>
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<readed;i++){
//((unsigned short*)&Data[0][0][0])[i]/=((float)(1<<12))*(float)255;
((short*)&Data[0][0][0])[i]+=3024;
float a=(float)((short*)&Data[0][0][0])[i]/5324;
((short*)&Data[0][0][0])[i]=a*255;
}
int levels=n/(512*512);
Resize(512,512,levels);
fclose(f);
}
///build and save the strucure made fo blocks
void Load(char *path)
void LoadJpg(char *path)
{
//load first one image to see dimensions
QImage qI=QImage();
@ -415,6 +447,7 @@ public:
QString qformat;
QString Path=QString(path);
Qd.setNameFilter("*.jpg");
//Qd.setNameFilter("*.bmp");
int levels=Qd.count();
Qd.setSorting(QDir::Name);
@ -477,7 +510,7 @@ public:
///return the value of the element in position point3i(i0,i1,i2)
ScalarType getAt(Point3i p)
{
assert ((p.V(0)<dimX())&&(p.V(1)<dimY())&&(p.V(2)<dimZ()));
assert ((p.V(0)<=dimX())&&(p.V(1)<=dimY())&&(p.V(2)<=dimZ()));
assert ((p.V(0)>=0)&&(p.V(1)>=0)&&(p.V(2)>=0));
return (Data[p.V(0)][p.V(1)][p.V(2)]);
}