minor changes

This commit is contained in:
Nico Pietroni 2005-02-08 17:47:50 +00:00
parent 71f78f7333
commit 5613d4c584
8 changed files with 1002 additions and 1044 deletions

View File

@ -32,6 +32,7 @@ public:
//control if two faces share an edge //control if two faces share an edge
bool ShareEdge(SimplexType *f0,SimplexType *f1) bool ShareEdge(SimplexType *f0,SimplexType *f1)
{ {
assert((!f0->IsD())&&(!f1->IsD()));
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
if (f0->FFp(i)==f1) if (f0->FFp(i)==f1)
return (true); return (true);
@ -49,6 +50,7 @@ public:
//control if two faces share a vertex //control if two faces share a vertex
bool ShareVertex(SimplexType *f0,SimplexType *f1) bool ShareVertex(SimplexType *f0,SimplexType *f1)
{ {
assert((!f0->IsD())&&(!f1->IsD()));
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
for (int j=0;j<3;j++) for (int j=0;j<3;j++)
if (f0->V(i)==f1->V(j)) if (f0->V(i)==f1->V(j))
@ -61,7 +63,7 @@ public:
bool TestRealIntersection(SimplexType *f0,SimplexType *f1) bool TestRealIntersection(SimplexType *f0,SimplexType *f1)
{ {
if (((!f0->IsActive())&&(!f1->IsActive()))||(f0->IsD())||(f1->IsD())) if ((f0->IsD())||(f1->IsD())||((!f0->IsActive())&&(!f1->IsActive())))
return false; return false;
//no adiacent faces //no adiacent faces
if ((f0!=f1)&& (!ShareEdge(f0,f1)) if ((f0!=f1)&& (!ShareEdge(f0,f1))
@ -71,26 +73,28 @@ public:
} }
///refresh all the elements 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 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())
HTable->addSimplex(&*si);
///new now
else
{ {
std::vector<Point3i> cells=HTable->addSimplex(&*si); if (!(*si).IsActive())
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++) HTable->addSimplex(&*si);
vactive.insert(*it); ///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 ///end new now
} }
//UpdateStep(); commented now //UpdateStep(); commented now
}
} }
/////put active cells on apposite structure /////put active cells on apposite structure
@ -116,7 +120,7 @@ public:
vactive.clear(); vactive.clear();
for (Container_Type::iterator 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()))
{ {
std::vector<Point3i> cells=HTable->addSimplex(&*si); std::vector<Point3i> cells=HTable->addSimplex(&*si);
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++) for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
@ -125,6 +129,28 @@ public:
} }
} }
///put active cells on apposite structure
void AddElements(typename ContSimplex::iterator newSimplex)
{
while (newSimplex!=_simplex.end())
{
if (!(*newSimplex).IsD())
{
if (!(*newSimplex).IsActive())
HTable->addSimplex(&*newSimplex);
///new now
else
{
std::vector<Point3i> cells=HTable->addSimplex(&*newSimplex);
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
vactive.insert(*it);
}
///end new now
}
newSimplex++;
}
}
///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,202 +0,0 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.6 2004/05/14 00:34:36 ganovelli
header added
****************************************************************************/
#ifndef __VCG_MINDISTPOINT
#define __VCG_MINDISTPOINT
#include <math.h>
#include <vcg/space/point3.h>
#include <vcg/space/box3.h>
#include <vcg/space/point4.h>
#include <vcg/math/base.h>
#include <vcg/space/index/grid_static_ptr.h>
using namespace vcg;
/*
aka MetroCore
data una mesh m e una ug sulle sue facce trova il punto di m piu' vicino ad
un punto dato.
*/
// input: mesh, punto, griglia, distanza limite
// output: normale alla faccia e punto piu' vicino su di essa
// Nota che il parametro template GRID non ci dovrebbe essere, visto che deve essere
// UGrid<MESH::FaceContainer >, ma non sono riuscito a definirlo implicitamente
template <class MESH, class GRID, class SCALAR>
void MinDistPoint( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::FaceType * &f, Point3<SCALAR> &ip)
{
typedef SCALAR scalar;
typedef Point3<scalar> Point3x;
typedef Box3<SCALAR> Box3x;
if(!gr.bbox.IsIn(p)) return;
typedef typename GridStaticPtr<typename MESH::FaceContainer>::Link A2UGridLink;
scalar ax = p[0] - gr.bbox.min[0]; // Real coodinate of point refer to
scalar ay = p[1] - gr.bbox.min[1];
scalar az = p[2] - gr.bbox.min[2];
int gx = int( ax/gr.voxel[0] ); // Integer coordinate of the point
int gy = int( ay/gr.voxel[1] ); // voxel
int gz = int( az/gr.voxel[2] );
scalar vx = gr.bbox.min[0]+gx*gr.voxel[0]; // Real world coordinate of the Voxel
scalar vy = gr.bbox.min[1]+gy*gr.voxel[1]; // origin
scalar vz = gr.bbox.min[2]+gz*gr.voxel[2];
scalar dx = math::Min(p[0] - vx, vx+gr.voxel[0]-p[0]); // Dist from the voxel
scalar dy = math::Min(p[1] - vy, vy+gr.voxel[1]-p[1]);
scalar dz = math::Min(p[2] - vz, vz+gr.voxel[2]-p[2]);
scalar vdist,vstep;
if(dx<dy && dx<dz)
{
vdist = dx;
vstep = gr.voxel[0];
}
else if(dy<dz)
{
vdist = dy;
vstep = gr.voxel[1];
}
else
{
vdist = dz;
vstep = gr.voxel[2];
}
//scalar error = gr.bbox.SquaredDiag();
//scalar error = gr.bbox.Diag();
scalar error = mdist;
Point3x q;
typename MESH::FaceIterator bestf = (typename MESH::FaceIterator)0;
mesh.UnMarkAll();
int mxsd = gr.siz[0];
if(mxsd<gr.siz[1]) mxsd = gr.siz[1];
if(mxsd<gr.siz[2]) mxsd = gr.siz[2];
for(int s=0;s<mxsd;++s)
{
if(s==0)
{
A2UGridLink *first, *last, *l;
gr.Grid( gx, gy, gz, first, last );
for(l=first;l!=last;++l)
if( ! mesh.IsMarked( &*(l->Elem())) )
{
if( Dist((*(l->Elem())), p, error, q) )
{
bestq = q;
bestf = l->Elem();
typename MESH::ScalarType alfa=1, beta=1, gamma=1;
//bestf->InterpolationParameters(q, alfa, beta);
//calcolo normale con interpolazione trilineare
/*normf = (1-(alfa+beta))*(bestf->V(0)->Normal())+
(alfa*(bestf->V(1)->Normal()))+
(beta*(bestf->V(2)->Normal()));*/
bool ret=bestf->InterpolationParameters(q, alfa, beta, gamma);
//assert(ret);
normf = (bestf->V(0)->cN())*alfa+
(bestf->V(1)->cN())*beta+
(bestf->V(2)->cN())*gamma;
normf.Normalize();
ip[0]=alfa;ip[1]=beta;ip[2]=gamma;
}
mesh.Mark( &*(l->Elem()) );
}
}
else
{
for(int ix=gx-s;ix<=gx+s;++ix)
if( ix>=0 && ix<gr.siz[0] )
{
for(int iy=gy-s;iy<=gy+s;++iy)
if( iy>=0 && iy<gr.siz[1] )
{
int sz = ( ix==gx-s || ix==gx+s ||
iy==gy-s || iy==gy+s )?1:2*s;
for(int iz=gz-s;iz<=gz+s;iz+=sz)
if( iz>=0 && iz<gr.siz[2] )
{
A2UGridLink *first, *last, *l;
gr.Grid( ix, iy, iz, first, last );
for(l=first;l!=last;++l)
if( ! mesh.IsMarked( &*(l->Elem())) )
{
if( Dist((*(l->Elem())), p, error, q) )
{
bestq = q;
bestf = l->Elem();
typename MESH::ScalarType alfa, beta, gamma;
//bestf->InterpolationParameters(q, alfa, beta);
//calcolo normale con interpolazione trilineare
bestf->InterpolationParameters(q, alfa, beta, gamma);
normf = (bestf->V(0)->cN())*alfa+
(bestf->V(1)->cN())*beta+
(bestf->V(2)->cN())*gamma ;
ip[0]=alfa;ip[1]=beta;ip[2]=gamma;
//normf.Normalize(); inutile si assume le normali ai vertici benfatte
}
mesh.Mark(&*l->Elem());
}
}
}
}
}
if( fabs(error)<vdist )
break;
vdist += vstep;
}
f=&*bestf;
mdist = scalar(fabs(error));
}
template <class MESH, class GRID, class SCALAR>
void MinDistPoint( MESH & mesh, const Point3<SCALAR> & p, GRID & gr, SCALAR & mdist,
Point3<SCALAR> & normf, Point3<SCALAR> & bestq, typename MESH::face_type * &f)
{
Point3<SCALAR> ip;
MinDistPoint(mesh,p,gr,mdist,normf,bestq,f,ip);
}
#endif

View File

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

View File

@ -26,20 +26,8 @@
#include <vcg/complex/trimesh/create/platonic.h> #include <vcg/complex/trimesh/create/platonic.h>
#include <volume_dataset.h> #include <volume_dataset.h>
//#include <vcg/simplex/face/pos.h>
///marching cubes
//#include <segmentation_wolker.h>
#include <vcg/complex/trimesh/create/resampler.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>
@ -51,9 +39,6 @@
#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{
@ -86,7 +71,6 @@ public:
void UpdateAcceleration() void UpdateAcceleration()
{ {
//if ((!IsBlocked(this))&&(!IsStopped(this)))
if ((!blocked)&&(!stopped)) if ((!blocked)&&(!stopped))
{ {
Acc()=(IntForce()+ExtForce())/Mass(); Acc()=(IntForce()+ExtForce())/Mass();
@ -127,9 +111,9 @@ public:
bool IsActive() bool IsActive()
{ {
return(!(((V(0)->blocked)||(V(0)->stopped))&& return((!(((V(0)->blocked)||(V(0)->stopped))&&
((V(1)->blocked)||(V(1)->stopped))&& ((V(1)->blocked)||(V(1)->stopped))&&
((V(2)->blocked)||(V(2)->stopped)))); ((V(2)->blocked)||(V(2)->stopped))))&&(!intersected));
} }
bool IsBlocked() bool IsBlocked()
@ -149,11 +133,16 @@ public:
///update of the internal forces using the dihedral angle ///update of the internal forces using the dihedral angle
bool Update ( void ) bool Update ( void )
{ {
if (!this->IsD())
{
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
{ {
MyFace *fopp=FFp(i); MyFace *fopp=FFp(i);
MyFace *myAddr=fopp->FFp(FFi(i)); MyFace *myAddr;
if ((fopp!=0)||(fopp<myAddr))//test do not duplicate updates per edge if (!fopp->IsD())
MyFace *myAddr=fopp->FFp(FFi(i));
if ((fopp->IsD())||(fopp!=0)||(fopp<myAddr))//test do not duplicate updates per edge
{ {
//normal and area based diadedral angle calcolus //normal and area based diadedral angle calcolus
CoordType DirEdge=(V(i)->P()-V((i+1)%3)->P()).Normalize(); CoordType DirEdge=(V(i)->P()-V((i+1)%3)->P()).Normalize();
@ -177,6 +166,7 @@ public:
} }
} }
} }
}
return(__super::Update()); return(__super::Update());
} }
}; };
@ -248,27 +238,6 @@ public:
{ {
m=new MyTriMesh(); m=new MyTriMesh();
CollDet=new Collision(m->face); 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()
@ -386,10 +355,8 @@ private:
bool OutOfLimits(MyTriMesh::CoordType p) bool OutOfLimits(MyTriMesh::CoordType p)
{ {
Point3f test=p; Point3f test=p;
/*Point3f max=UnScale(MapToSpace(V.Max())); Point3f max=BBox().max-Point3f(1.f,1.f,1.f);//last change
Point3f min=UnScale(MapToSpace(V.Min()));*/ Point3f min=BBox().min;//+Point3f(1.f,1.f,1.f);//last change
Point3f max=BBox().max;//last change
Point3f min=BBox().min;//last change
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
{ {
if(((test.V(i)>=max.V(i))||(test.V(i)<=min.V(i)))) if(((test.V(i)>=max.V(i))||(test.V(i)<=min.V(i))))
@ -422,6 +389,24 @@ private:
void SetIntersectedFace(MyFace *f) void SetIntersectedFace(MyFace *f)
{ {
f->intersected=true; f->intersected=true;
///detaching from ff topology
/*MyFace *f0=f->FFp(0);
MyFace *f1=f->FFp(1);
MyFace *f2=f->FFp(2);
int i0=f->FFi(0);
int i1=f->FFi(1);
int i2=f->FFi(2);
f0->FFp(i0)=f0;
f1->FFp(i1)=f1;
f2->FFp(i2)=f2;
f0->FFi(i0)=0;
f1->FFi(i1)=1;
f2->FFi(i2)=2;
f->SetD();*/
} }
bool IsStopped(MyVertex *v) bool IsStopped(MyVertex *v)
@ -443,20 +428,21 @@ private:
v->stopped=false; v->stopped=false;
} }
///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); // if (!m->face[i].IsD())
} // 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);
@ -468,7 +454,7 @@ void InitMesh(MyTriMesh *m)
{ {
m->vert[i].P()=UnScale(m->vert[i].P());///last change m->vert[i].P()=UnScale(m->vert[i].P());///last change
m->vert[i].P()+=InitialBarycenter; m->vert[i].P()+=InitialBarycenter;
// m.vert[i].P()=UnScale(m.vert[i].P()); // m.vert[i].P()=UnScale(m.vert[i].P());
// P_Vertex.push_back(&m.vert[i]); // P_Vertex.push_back(&m.vert[i]);
} }
@ -481,7 +467,7 @@ void InitMesh(MyTriMesh *m)
///return true if the gray level of the vertex v differ from graylevel less than tolerance ///return true if the gray level of the vertex v differ from graylevel less than tolerance
bool InTolerance(MyTriMesh::VertexType *v) bool InTolerance(MyTriMesh::VertexType *v)
{ {
return (abs(getColor(v->P())-gray_init)<tolerance); return (fabs(getColor(v->P())-(float)gray_init)<(float)tolerance);
} }
///add to the vertex v a containing force basing on diffence from tolerance ///add to the vertex v a containing force basing on diffence from tolerance
@ -511,7 +497,7 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
void AddExtForces() void AddExtForces()
{ {
Part_VertexContainer::iterator vi; Part_VertexContainer::iterator vi;
PartialUpdateNormals();
end_loop=true; end_loop=true;
for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi) for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi)
{ {
@ -519,8 +505,11 @@ void AddExtForces()
if (!(*vi).IsD()) if (!(*vi).IsD())
{ {
if (OutOfLimits((*vi).P())) if (OutOfLimits((*vi).P()))
//vi->blocked=true; {
SetBlocked(&*vi); SetBlocked(&*vi);
(*vi).ExtForce()=MyTriMesh::CoordType(0,0,0);
}
else
if ((!IsBlocked(&*vi))&&(!IsStopped(&*vi))) if ((!IsBlocked(&*vi))&&(!IsStopped(&*vi)))
{ {
end_loop=false; end_loop=false;
@ -565,7 +554,6 @@ void Reinit_PVectors()
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->IsD())&&(!fi->IsBlocked())) if ((!fi->IsD())&&(!fi->IsBlocked()))
P_Faces.push_back(&(*fi)); P_Faces.push_back(&(*fi));
} }
@ -582,13 +570,13 @@ void Refresh_PVectors()
unsigned 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]->IsD())&&(!P_Vertex[i]->blocked))
P_VertexAux.push_back(P_Vertex[i]); P_VertexAux.push_back(P_Vertex[i]);
} }
for (i=0;i<P_Faces.size();i++) for (i=0;i<P_Faces.size();i++)
{ {
if (!P_Faces[i]->IsBlocked()) if ((!P_Faces[i]->IsD())&&(!P_Faces[i]->IsBlocked()))
P_FacesAux.push_back(P_Faces[i]); P_FacesAux.push_back(P_Faces[i]);
} }
@ -604,13 +592,13 @@ void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
{ {
while (vi!=m->vert.end()) while (vi!=m->vert.end())
{ {
if (!(*vi).IsD()) if ((!(*vi).IsD())&&(!(*vi).blocked)&&(!(*vi).stopped))
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())&&((*fi).IsActive()))
P_Faces.push_back(&(*fi)); P_Faces.push_back(&(*fi));
fi++; fi++;
} }
@ -657,6 +645,35 @@ bool TimeSelfIntersection()
return false; return false;
} }
void PartialUpdateNormals()
{
Part_FaceContainer::iterator fi;
for (fi=P_Faces.begin();fi<P_Faces.end();++fi)
if (!(*fi).IsD())
(*fi).ComputeNormalizedNormal();
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=P_Faces.begin();fi!=P_Faces.end();++fi)
if( !(*fi).IsD() && (*fi).IsR() )
{
MyFace::NormalType t = (*fi).Normal();
for(int j=0; j<3; ++j)
if( !(*fi).V(j)->IsD() && (*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();
}
///refine the mesh and re-update eventually ///refine the mesh and re-update eventually
void RefineStep(float _edge_size) void RefineStep(float _edge_size)
{ {
@ -673,12 +690,19 @@ void RefineStep(float _edge_size)
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();
CollDet->RefreshElements();
}
else else
{
AddNewElements(vend,fend); AddNewElements(vend,fend);
CollDet->UpdateStep<Part_FaceContainer>(P_Faces);
}
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m); //vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);
CollDet->RefreshElements(); PartialUpdateNormals();
//CollDet->RefreshElements();
} }
} }
@ -688,7 +712,8 @@ void ReinitPhysicMesh()
Part_FaceContainer::iterator pfi; Part_FaceContainer::iterator pfi;
for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi) for (pfi=P_Faces.begin();pfi<P_Faces.end();++pfi)
(*pfi).Init(k_elanst,mass,k_dihedral); if((!(*pfi).IsD())&&((!(*pfi).intersected)))
(*pfi).Init(k_elanst,mass,k_dihedral);
/*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++) /*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
ClearStopped(&*vi);*/ ClearStopped(&*vi);*/
@ -711,13 +736,15 @@ 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<Part_FaceContainer>(P_Faces); 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++)
{ {
SetBlockedFace(*it); if (!(*it)->IsD())
SetIntersectedFace(*it); {
SetBlockedFace(*it);
SetIntersectedFace(*it);
}
} }
} }
@ -745,7 +772,7 @@ void LoadFromDir(char *in, char *out)
} }
///set parameters for segmentation ///set parameters for segmentation
void SetSegmentParameters(int color,int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f, void SetSegmentParameters(int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihedral=0.2f,float Time_stamp=0.2f,
float Edge_precision=4.f,Point3f ScaleFactor=Point3f(1.f,1.f,1.f), float Edge_precision=4.f,Point3f ScaleFactor=Point3f(1.f,1.f,1.f),
clock_t _interval=1000,clock_t _interval2=250) clock_t _interval=1000,clock_t _interval2=250)
{ {
@ -775,17 +802,11 @@ void InitSegmentation(MyTriMesh::CoordType b)
TrINT->SetPDESolver(PDESolvers::EULER_METHOD); TrINT->SetPDESolver(PDESolvers::EULER_METHOD);
////caso optimized
///*V.Resample(inDir,outDir);
//V.Init(1000,outDir);*/
//V.Load(inDir);
//
/*bbox=vcg::Box3<float>(MapToSpace(V.Min()),MapToSpace(V.Max()));*/
InitMesh(m); InitMesh(m);
//init the mesh with new //init the mesh with new
Reinit_PVectors(); Reinit_PVectors();
ReinitPhysicMesh(); ReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f); CollDet->Init(bbox.min,bbox.max,5.f);
@ -836,10 +857,22 @@ void AutoStep()
} }
} }
/////set as deleted intersected vertices
//void ClearIntersectedFaces()
//{
// MyTriMesh::FaceIterator fi;
// for (fi=m->face.begin();fi<m->face.end();fi++)
// if ((*fi).intersected==true)
// (*fi).SetD();
//
//}
///first version ///first version
void Resample() void Resample()
{ {
//ClearIntersectedFaces();
new_m=new MyTriMesh(); new_m=new MyTriMesh();
vcg::tri::UpdateBounding<MyTriMesh>::Box(*m);
vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m, vcg::trimesh::Resampler<MyTriMesh,MyTriMesh>::Resample<vcg::trimesh::RES::MMarchingCubes>(*m,*new_m,
Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision)); Point3i((int) edge_precision,(int) edge_precision,(int) edge_precision));

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
#include <qimage.h> #include <qimage.h>
#include <qdir.h> #include <qdir.h>
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qslider.h>
extern Segmentator *s; extern Segmentator *s;
@ -66,7 +67,7 @@ void SimpleGLWidget::LoadTexture(QString p,int level)
QString PathFile=Path; QString PathFile=Path;
PathFile.append(Qd[level]); PathFile.append(Qd[level]);
bool b=qI.load(PathFile,qformat); qI.load(PathFile,qformat);
QImage tx = QGLWidget::convertToGLFormat (qI); QImage tx = QGLWidget::convertToGLFormat (qI);
@ -155,7 +156,7 @@ void drawForces(Segmentator::Part_VertexContainer *pv,int typeForce)
{ {
Segmentator::Part_VertexContainer::iterator vi; Segmentator::Part_VertexContainer::iterator vi;
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
glLineWidth(0.3); glLineWidth(0.3f);
glDisable(GL_NORMALIZE); glDisable(GL_NORMALIZE);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
@ -169,7 +170,7 @@ else
if (typeForce==2) if (typeForce==2)
glColor3d(0,1,0); glColor3d(0,1,0);
for (vi=pv->begin();vi<pv->end();vi++) for (vi=pv->begin();vi<pv->end();++vi)
{ {
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
vcg::glVertex((*vi).P()); vcg::glVertex((*vi).P());
@ -262,8 +263,7 @@ void SimpleGLWidget::SmoothMesh()
} }
void SimpleGLWidget::glDraw(){ void SimpleGLWidget::glDraw(){
glClearColor(0.2f,0.2f,0.2f,1.f);
glClearColor(0.2,0.2,0.2,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -336,31 +336,42 @@ void SimpleGLWidget::glDraw(){
else else
glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_FRONT,GL_FILL);
int i=0;
if (s->m!=NULL) if (s->m!=NULL)
{ {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for (fi=s->m->face.begin();fi<s->m->face.end();fi++) for (fi=s->m->face.begin();fi<s->m->face.end();fi++)
{ {
glColor3d(0.4,0.8,0.8); if(!(*fi).IsD())
if (fi->intersected) {
glColor3d(1.f,0,0); glColor3d(0.4,0.8,0.8);
if (fi->intersected)
glColor3d(1.f,0,0);
if (((blocked)&&(!fi->IsBlocked()))||(!blocked)) if (((blocked)&&(!fi->IsBlocked()))||(!blocked))
{ {
if (!wire)
if (!wire) {
vcg::glNormal(fi->Normal()); 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());
}
vcg::glVertex(fi->V(0)->P()); }
vcg::glVertex(fi->V(1)->P()); }
vcg::glVertex(fi->V(2)->P());
} }
} }
glEnd(); glEnd();
} glPopMatrix();
glPopMatrix(); //WriteInfo();
//WriteInfo();
} }
QGLWidget::glDraw(); QGLWidget::glDraw();
@ -442,13 +453,11 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
//LoadMatrix(); //LoadMatrix();
glReadPixels(e->x(),_H-e->y(),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&winz); 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); gluUnProject(e->x(),_H-e->y(),winz,modelMatrix,projection,viewport,&x,&y,&z);
QString color="";
color.sprintf("%i",s->gray_init);
//w->Color->text()=color;
SetExtractionParameters(); SetExtractionParameters();
//s->SetInitialBarycenter(Point3f(x,y,_numslide));
//s->InitSegmentation(Point3f(x,y,_numslide));
s->InitSegmentation(Point3f(x,y,z)); s->InitSegmentation(Point3f(x,y,z));
w->slider1->setValue(s->gray_init);
UpdateBBMesh(); UpdateBBMesh();
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m)); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(*(s->m));
repaint(); repaint();
@ -456,6 +465,11 @@ void SimpleGLWidget::mousePressEvent ( QMouseEvent * e )
//vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m); //vcg::tri::UpdateBounding<Segmentator::MyTriMesh>::Box(s->m);
} }
void SimpleGLWidget::setColor()
{
s->gray_init=w->slider1->value();
}
void SimpleGLWidget::wheelEvent(QWheelEvent *e) void SimpleGLWidget::wheelEvent(QWheelEvent *e)
{ {
if (!_showslides) if (!_showslides)
@ -520,7 +534,7 @@ void SimpleGLWidget::SetExtractionParameters()
//int color =atoi(w->Color->text()); //int color =atoi(w->Color->text());
///to modify ///to modify
s->SetSegmentParameters(s->gray_init,tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance)); s->SetSegmentParameters(tolerance,mass,k_elanst,dihedral,timestep,edge,Point3f(1.f,1.f,dinstance));
} }
void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e ) void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )
@ -536,7 +550,7 @@ void SimpleGLWidget::mouseMoveEvent ( QMouseEvent * e )
void SimpleGLWidget::initializeGL(){ void SimpleGLWidget::initializeGL(){
GLfloat f[4]={0.2,0.2,0.2,1.f}; GLfloat f[4]={0.2f,0.2f,0.2f,1.f};
GLfloat p[4]={3,3,5,0}; GLfloat p[4]={3,3,5,0};
glLightfv(GL_LIGHT0, GL_AMBIENT,f); glLightfv(GL_LIGHT0, GL_AMBIENT,f);
glLightfv(GL_LIGHT1, GL_POSITION,p); glLightfv(GL_LIGHT1, GL_POSITION,p);

View File

@ -63,6 +63,7 @@ public:
void OpenDirectory(); void OpenDirectory();
void MarchingCube(); void MarchingCube();
void UpdateBBMesh(); void UpdateBBMesh();
void setColor();
//virtual void keyPressEvent(QKeyEvent *qk); //virtual void keyPressEvent(QKeyEvent *qk);
@ -163,5 +164,9 @@ public:
UpdateBBMesh(); UpdateBBMesh();
repaint(); repaint();
} }
void SetSegmentColor()
{
setColor();
}
}; };

View File

@ -1,3 +1,5 @@
#ifndef _SEG3D_VOLUMEDATASET
#define _SEG3D_VOLUMEDATASET
#include <qimage.h> #include <qimage.h>
#include <qdir.h> #include <qdir.h>
@ -481,3 +483,4 @@ public:
} }
}; };
#endif