compiled with new version of spatial hashing

This commit is contained in:
Nico Pietroni 2005-11-07 14:12:42 +00:00
parent aca3eeec83
commit f8af64df99
2 changed files with 677 additions and 698 deletions

View File

@ -13,10 +13,11 @@ public:
typedef typename ContSimplex::value_type SimplexType; typedef typename ContSimplex::value_type SimplexType;
typedef typename ContSimplex::value_type* SimplexPointer; typedef typename ContSimplex::value_type* SimplexPointer;
typedef typename ContSimplex::iterator SimplexIterator; typedef typename ContSimplex::iterator SimplexIterator;
typedef typename SimplexType::CoordType Point3x; typedef typename SimplexType::CoordType CoordType;
typedef typename Point3x::ScalarType ScalarType; typedef typename CoordType::ScalarType ScalarType;
typedef typename vcg::Box3<ScalarType> Box3x;
typedef SpatialHashTable<SimplexType> HashingTable; typedef DynamicSpatialHashTable<SimplexType,float> HashingTable;
Collision_Detector(ContSimplex & r_):_simplex(r_){}; Collision_Detector(ContSimplex & r_):_simplex(r_){};
~Collision_Detector(){}; ~Collision_Detector(){};
@ -41,10 +42,14 @@ public:
} }
///initialize the box for collision detection and the dimension of a cell ///initialize the box for collision detection and the dimension of a cell
void Init(Point3x _min,Point3x _max,ScalarType _l) void Init(CoordType _min,CoordType _max,ScalarType _l)
{ {
HTable=new HashingTable(); HTable=new HashingTable();
HTable->Init(_min,_max,_l); Box3x bb(_min,_max);
CoordType d=((_max-_min)/_l);
vcg::Point3i dim;
dim.Import<ScalarType>(d);
HTable->InitEmpty(bb,dim);
} }
//control if two faces share a vertex //control if two faces share a vertex
@ -66,9 +71,14 @@ public:
if ((!f0->IsActive())&&(!f1->IsActive())) if ((!f0->IsActive())&&(!f1->IsActive()))
return false; return false;
//no adiacent faces //no adiacent faces
if ((f0!=f1)&& (!ShareEdge(f0,f1)) assert(f0!=f1);
&& (!ShareVertex(f0,f1))) if ((f0!=f1)&& (!ShareEdge(f0,f1))&&!ShareVertex(f0,f1))
return (vcg::Intersection<SimplexType>((*f0),(*f1))); {
//vcg::Segment3<ScalarType> segm;
//bool copl=false;
return (vcg::Intersection<SimplexType>((*f0),(*f1)));//,copl,segm))
//return ((copl)||(segm.Length()>0.001));
}
return false; return false;
} }
@ -76,44 +86,29 @@ public:
void RefreshElements() void RefreshElements()
{ {
HTable->Clear(); HTable->Clear();
vactive.clear();///new vactive.clear();
HTable->tempMark=0; HTable->tempMark=0;
for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si) for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si)
{ {
if (!(*si).IsD()) if (!(*si).IsD())
{ {
(*si).Mark()=0; (*si).HMark()=0;
if (!(*si).IsActive()) vcg::Box3i cells=HTable->Add(&*si);
if ((*si).IsActive())
HTable->AddElem(&*si);
///new now
else
{ {
std::vector<Point3i> cells=HTable->AddElem(&*si); vcg::Box3i cells=HTable->Add(&*si);
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++) for (int x=cells.min.X(); x<=cells.max.X();x++)
vactive.insert(*it); 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));
} }
///end new now
} }
//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
@ -126,35 +121,16 @@ public:
{ {
if ((!(*si).IsD())&&((*si).IsActive())) if ((!(*si).IsD())&&((*si).IsActive()))
{ {
std::vector<Point3i> cells=HTable->AddElem(&*si); vcg::Box3i cells=HTable->Add(&*si);
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++) for (int x=cells.min.X();x<=cells.max.X();x++)
vactive.insert(*it); 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));
} }
} }
} }
/////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()
@ -168,7 +144,8 @@ public:
if (HTable->numElemCell(p,I)>=2) if (HTable->numElemCell(p,I)>=2)
{ {
std::vector<SimplexType*> inCell; std::vector<SimplexType*> inCell;
HTable->getAtCell(p,inCell); inCell.clear();
HTable->getInCellUpdated(p,inCell);
int nelem=inCell.size(); int nelem=inCell.size();
if (nelem>=2) if (nelem>=2)
{ {
@ -181,6 +158,7 @@ public:
ret.push_back(inCell[j]); ret.push_back(inCell[j]);
} }
} }
} }
} }
return ret; return ret;

View File

@ -49,17 +49,17 @@ class Segmentator{
public: public:
struct DummyEdge; struct DummyEdge;
struct DummyTetra; struct DummyTetra;
struct MyFace; struct MyFace;
//#ifdef _EXTENDED_MARCH //#ifdef _EXTENDED_MARCH
// struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> > // struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
//#else //#else
struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> > struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
//#endif //#endif
{ {
public: public:
bool blocked;//optimize after with vertex flags bool blocked;//optimize after with vertex flags
bool stopped; bool stopped;
@ -68,8 +68,8 @@ public:
{ {
blocked=false; blocked=false;
stopped=false; stopped=false;
Acc()=Point3f(0,0,0); Acc()=CoordType(0,0,0);
Vel()=Point3f(0,0,0); Vel()=CoordType(0,0,0);
ClearFlags(); ClearFlags();
//__super:: //__super::
//neeed call of the super class //neeed call of the super class
@ -83,14 +83,14 @@ public:
} }
else else
{ {
Acc()=Point3f(0,0,0); Acc()=CoordType(0,0,0);
Vel()=Point3f(0,0,0); Vel()=CoordType(0,0,0);
} }
} }
void Reset() void Reset()
{ {
IntForce()=Point3f(0.f,0.f,0.f); IntForce()=CoordType(0.f,0.f,0.f);
} }
void SetRestPos() void SetRestPos()
@ -98,7 +98,7 @@ public:
RPos()=P(); RPos()=P();
} }
}; };
///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::FaceAFAVFNFMRT<MyVertex,DummyEdge,MyFace> > struct MyFace : public TriangleMassSpring< vcg::FaceAFAVFNFMRT<MyVertex,DummyEdge,MyFace> >
@ -107,7 +107,7 @@ public:
bool intersected; bool intersected;
float kdihedral; float kdihedral;
ScalarType AreaRep; ScalarType AreaRep;
int _Mark; int _HMark;
CoordType old_N; CoordType old_N;
@ -159,13 +159,13 @@ public:
return (norm1*norm2); return (norm1*norm2);
} }
int &Mark() inline int &HMark()
{return (_Mark);} {return (_HMark);}
///return the bounding box of the simplex ///return the bounding box of the simplex
vcg::Box3<float> BBox() vcg::Box3<ScalarType> BBox()
{ {
vcg::Box3<float> bb; vcg::Box3<ScalarType> bb;
GetBBox(bb); GetBBox(bb);
return (bb); return (bb);
} }
@ -235,23 +235,23 @@ public:
return true; return true;
///new ///new
} }
}; };
struct MyTriMesh: public vcg::tri::TriMesh<std::vector<MyVertex>,std::vector<MyFace> >{}; struct MyTriMesh: public vcg::tri::TriMesh<std::vector<MyVertex>,std::vector<MyFace> >{};
typedef Partial_Container<std::vector<MyVertex*>,MyVertex> Part_VertexContainer; typedef Partial_Container<std::vector<MyVertex*>,MyVertex> Part_VertexContainer;
typedef Partial_Container<std::vector<MyFace*>,MyFace> Part_FaceContainer; typedef Partial_Container<std::vector<MyFace*>,MyFace> Part_FaceContainer;
typedef PDEIntegrator<Part_FaceContainer,Part_VertexContainer,float> myIntegrator; typedef PDEIntegrator<Part_FaceContainer,Part_VertexContainer,MyVertex::ScalarType> myIntegrator;
typedef Collision_Detector<std::vector<MyFace> > Collision; typedef Collision_Detector<std::vector<MyFace> > Collision;
////typedef Walker<MyTriMesh,MyTriMesh> MyWalk; ////typedef Walker<MyTriMesh,MyTriMesh> MyWalk;
// //
//#ifdef _EXTENDED_MARCH //#ifdef _EXTENDED_MARCH
// typedef vcg::tri::ExtendedMarchingCubes<MyTriMesh, MyWalk> MarchingCubes; // typedef vcg::tri::ExtendedMarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
//#else //#else
// typedef vcg::tri::MarchingCubes<MyTriMesh, MyWalk> MarchingCubes; // typedef vcg::tri::MarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
//#endif //#endif
public: public:
@ -292,7 +292,7 @@ public:
//Volume_Dataset_Optimized<short> V; //Volume_Dataset_Optimized<short> V;
Volume_Dataset <short> V; Volume_Dataset <short> V;
vcg::Box3<float> bbox; vcg::Box3<MyTriMesh::ScalarType> bbox;
char *inDir; char *inDir;
char *outDir; char *outDir;
@ -357,6 +357,7 @@ private:
double conf=diameter*diameter; double conf=diameter*diameter;
///now swap ///now swap
return (fatt2<=conf); return (fatt2<=conf);
//return (!((fabs(p.X())>50)||(fabs(p.Y())>50)||(fabs(p.Z())>50)));
} }
@ -447,9 +448,9 @@ private:
///return true if a coordinate is out of limits ///return true if a coordinate is out of limits
bool OutOfLimits(MyTriMesh::CoordType p) bool OutOfLimits(MyTriMesh::CoordType p)
{ {
Point3f test=p; MyTriMesh::CoordType test=p;
Point3f max=BBox().max-Point3f(1.f,1.f,1.f);//last change MyTriMesh::CoordType max=BBox().max-MyTriMesh::CoordType(1.f,1.f,1.f);//last change
Point3f min=BBox().min;//+Point3f(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++) 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))))
@ -516,18 +517,18 @@ 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++)
// { // {
// if (!m->face[i].IsD()) // if (!m->face[i].IsD())
// 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();
@ -552,25 +553,25 @@ 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 (fabs(getColor(v->P())-(float)gray_init)<(float)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
MyTriMesh::CoordType ContainingForce(MyTriMesh::VertexType *v) MyTriMesh::CoordType ContainingForce(MyTriMesh::VertexType *v)
{ {
//float dinstance=fabs((FindGrayMedia(v))-gray_init); //float dinstance=fabs((FindGrayMedia(v))-gray_init);
float dinstance=fabs((getColor(v->P()))-(float)gray_init); float dinstance=fabs((getColor(v->P()))-(float)gray_init);
assert(dinstance<=tolerance); assert(dinstance<=tolerance);
MyTriMesh::CoordType ret=(-v->N()*((dinstance)/(float)tolerance)); MyTriMesh::CoordType ret=(-v->N()*((dinstance)/(float)tolerance));
return (ret); return (ret);
} }
///find the gradient factor ///find the gradient factor
MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v) MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
{ {
MyTriMesh::CoordType value=Gradient(v->P()); MyTriMesh::CoordType value=Gradient(v->P());
/*float d0=getColor(v->P()+value); /*float d0=getColor(v->P()+value);
float d1=getColor(v->P()-value); float d1=getColor(v->P()-value);
@ -578,12 +579,12 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
return (-value); return (-value);
else */ else */
return (value*(gray_init-getColor(v->P()))); return (value*(gray_init-getColor(v->P())));
} }
///add the external forces to the deformable mesh ///add the external forces to the deformable mesh
void AddExtForces() void AddExtForces()
{ {
Part_VertexContainer::iterator vi; Part_VertexContainer::iterator vi;
/*PartialUpdateNormals();*/ /*PartialUpdateNormals();*/
end_loop=true; end_loop=true;
@ -619,11 +620,11 @@ void AddExtForces()
(*vi).ExtForce()=MyTriMesh::CoordType(0,0,0); (*vi).ExtForce()=MyTriMesh::CoordType(0,0,0);
} }
} }
} }
///reinit the partial integration vectors that describe active vertices ///reinit the partial integration vectors that describe active vertices
void Reinit_PVectors() void Reinit_PVectors()
{ {
V_Stopped.clear(); V_Stopped.clear();
P_Vertex.clear(); P_Vertex.clear();
MyTriMesh::VertexIterator vi; MyTriMesh::VertexIterator vi;
@ -643,11 +644,11 @@ void Reinit_PVectors()
if ((!fi->IsD())&&(!fi->IsBlocked())&&(!fi->intersected)) if ((!fi->IsD())&&(!fi->IsBlocked())&&(!fi->intersected))
P_Faces.push_back(&(*fi)); P_Faces.push_back(&(*fi));
} }
} }
///erase the stopped entities from the partial containers ///erase the stopped entities from the partial containers
void Refresh_PVectors() void Refresh_PVectors()
{ {
Part_FaceContainer P_FacesAux; Part_FaceContainer P_FacesAux;
Part_VertexContainer P_VertexAux; Part_VertexContainer P_VertexAux;
P_FacesAux.clear(); P_FacesAux.clear();
@ -674,11 +675,11 @@ void Refresh_PVectors()
P_Faces=P_FacesAux; P_Faces=P_FacesAux;
P_Vertex=P_VertexAux; P_Vertex=P_VertexAux;
} }
///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())&&(!(*vi).blocked)&&(!(*vi).stopped)) if ((!(*vi).IsD())&&(!(*vi).blocked)&&(!(*vi).stopped))
@ -691,11 +692,11 @@ void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
P_Faces.push_back(&(*fi)); P_Faces.push_back(&(*fi));
fi++; fi++;
} }
} }
///verify and eventually stop the vertices of the mesh ///verify and eventually stop the vertices of the mesh
void VerifyForces() void VerifyForces()
{ {
float proj; float proj;
Part_VertexContainer::iterator vi; Part_VertexContainer::iterator vi;
for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi) for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi)
@ -708,10 +709,10 @@ void VerifyForces()
SetStopped(&*vi); SetStopped(&*vi);
} }
} }
} }
bool TimeReinit() bool TimeReinit()
{ {
static clock_t time=0; static clock_t time=0;
clock_t elapsedsecs=abs(time-clock()); clock_t elapsedsecs=abs(time-clock());
if (elapsedsecs>interval_reinit) if (elapsedsecs>interval_reinit)
@ -720,10 +721,10 @@ bool TimeReinit()
return true; return true;
} }
return false; return false;
} }
bool TimeSelfIntersection() bool TimeSelfIntersection()
{ {
static clock_t time=0; static clock_t time=0;
clock_t elapsedsecs=abs(time-clock()); clock_t elapsedsecs=abs(time-clock());
if (elapsedsecs>interval_selfcollision) if (elapsedsecs>interval_selfcollision)
@ -732,11 +733,11 @@ bool TimeSelfIntersection()
return true; return true;
} }
return false; return false;
} }
void PartialUpdateNormals() void PartialUpdateNormals()
{ {
/*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m); /*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/ vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/
Part_FaceContainer::iterator fi; Part_FaceContainer::iterator fi;
@ -787,21 +788,21 @@ void PartialUpdateNormals()
// if( !(*vi).IsD() && (*vi).IsRW() ) // if( !(*vi).IsD() && (*vi).IsRW() )
// (*vi).N().Normalize(); // (*vi).N().Normalize();
} }
//bool SelectToRefine() //bool SelectToRefine()
//{ //{
// MyTriMesh::FaceIterator fi; // MyTriMesh::FaceIterator fi;
// for (fi=m->face.begin();pfi<m->face.end();++pfi) // for (fi=m->face.begin();pfi<m->face.end();++pfi)
// { // {
// if (((*fi).QualityFace()<0.1f)) // if (((*fi).QualityFace()<0.1f))
// fi->ClearS(); // fi->ClearS();
// } // }
//} //}
template<class MESH_TYPE> template<class MESH_TYPE>
struct MyMidPoint:vcg::MidPoint<MESH_TYPE> struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
{ {
void operator()(typename MESH_TYPE::VertexType &nv, face::Pos<typename MESH_TYPE::FaceType> ep){ void operator()(typename MESH_TYPE::VertexType &nv, face::Pos<typename MESH_TYPE::FaceType> ep){
nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0;
@ -813,17 +814,17 @@ struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
if( MESH_TYPE::HasPerVertexColor()) if( MESH_TYPE::HasPerVertexColor())
nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f);
} }
}; };
///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();
// bool to_refine=SelectToRefine(); // bool to_refine=SelectToRefine();
/*if (to_refine)*/ /*if (to_refine)*/
//refined=vcg::Refine(*m,MidPoint<MyTriMesh>(),_edge_size,true); //refined=vcg::Refine(*m,MidPoint<MyTriMesh>(),_edge_size,true);
@ -853,17 +854,17 @@ void RefineStep(float _edge_size)
PartialUpdateNormals(); PartialUpdateNormals();
PartialReinitPhysicMesh(); PartialReinitPhysicMesh();
//#ifdef _DEBUG //#ifdef _DEBUG
// vcg::tri::UpdateTopology<MyTriMesh>::TestFaceFace(*m); // vcg::tri::UpdateTopology<MyTriMesh>::TestFaceFace(*m);
//#endif //#endif
//CollDet->RefreshElements(); //CollDet->RefreshElements();
} }
} }
///reset vertex position and unblock them ///reset vertex position and unblock them
void PartialReinitPhysicMesh() void PartialReinitPhysicMesh()
{ {
Part_FaceContainer::iterator pfi; Part_FaceContainer::iterator pfi;
Part_VertexContainer::iterator pvi; Part_VertexContainer::iterator pvi;
@ -891,13 +892,13 @@ void PartialReinitPhysicMesh()
/*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);*/
} }
///clear the stopped vertex ///clear the stopped vertex
void ClearStopped() void ClearStopped()
{ {
//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);
Part_VertexContainer::iterator vi; Part_VertexContainer::iterator vi;
for (vi=V_Stopped.begin();vi<V_Stopped.end();++vi) for (vi=V_Stopped.begin();vi<V_Stopped.end();++vi)
@ -905,11 +906,11 @@ void ClearStopped()
ClearStopped(&*vi); ClearStopped(&*vi);
} }
V_Stopped.clear(); V_Stopped.clear();
} }
///do one step of controls for self collision detetction ///do one step of controls for self collision detetction
void CollisionDetection() void CollisionDetection()
{ {
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++)
@ -920,21 +921,21 @@ void CollisionDetection()
SetIntersectedFace(*it); SetIntersectedFace(*it);
} }
} }
} }
public: public:
///set the initial barycenter where the triangle mesh start to expand ///set the initial barycenter where the triangle mesh start to expand
//void SetInitialBarycenter(MyTriMesh::CoordType b) //void SetInitialBarycenter(MyTriMesh::CoordType b)
//{ //{
// InitialBarycenter=b; // InitialBarycenter=b;
// gray_init=getColor(b); // gray_init=getColor(b);
// /*InitMesh(m);*/ // /*InitMesh(m);*/
//} //}
///set the input output directory of images ///set the input output directory of images
void LoadFromDir(char *in, char *out) void LoadFromDir(char *in, char *out)
{ {
inDir=in; inDir=in;
outDir=out; outDir=out;
@ -944,21 +945,21 @@ void LoadFromDir(char *in, char *out)
V.Init(1000,outDir);*/ V.Init(1000,outDir);*/
V.LoadJpg(inDir); V.LoadJpg(inDir);
bbox=vcg::Box3<float>(MapToSpace((V.Min())),(MapToSpace(V.Max()))); bbox=vcg::Box3<MyTriMesh::ScalarType>(MapToSpace((V.Min())),(MapToSpace(V.Max())));
} }
///set the input ///set the input
void LoadFromRaw(char *inDir) void LoadFromRaw(char *inDir)
{ {
/*V.LoadRaw(inDir); /*V.LoadRaw(inDir);
bbox=vcg::Box3<float>(MapToSpace((V.Min())),(MapToSpace(V.Max())));*/ bbox=vcg::Box3<float>(MapToSpace((V.Min())),(MapToSpace(V.Max())));*/
} }
///set parameters for segmentation ///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, 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=2000,clock_t _interval2=250) clock_t _interval=2000,clock_t _interval2=250)
{ {
mass=Mass; mass=Mass;
k_elanst=K_elanst; k_elanst=K_elanst;
tolerance=tol; tolerance=tol;
@ -972,13 +973,13 @@ void SetSegmentParameters(int tol,float Mass=0.5f,float K_elanst=0.2f,float Dihe
time_stamp=Time_stamp; time_stamp=Time_stamp;
k_dihedral=Dihedral; k_dihedral=Dihedral;
scale=ScaleFactor; scale=ScaleFactor;
bbox=vcg::Box3<float>(UnScale(MapToSpace(V.Min())),(UnScale(MapToSpace(V.Max()))));//last change! bbox=vcg::Box3<MyTriMesh::ScalarType>(UnScale(MapToSpace(V.Min())),(UnScale(MapToSpace(V.Max()))));//last change!
} }
///init the segmentation of the mesh ///init the segmentation of the mesh
void InitSegmentation(MyTriMesh::CoordType b) void InitSegmentation(MyTriMesh::CoordType b)
{ {
InitialBarycenter=b; InitialBarycenter=b;
gray_init=getColor(b); gray_init=getColor(b);
@ -994,17 +995,17 @@ void InitSegmentation(MyTriMesh::CoordType b)
PartialReinitPhysicMesh(); PartialReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f); CollDet->Init(bbox.min,bbox.max,5.f);
} }
///return the bounding box of the mesh ///return the bounding box of the mesh
vcg::Box3<float>& BBox() vcg::Box3<MyTriMesh::ScalarType>& BBox()
{ {
return (bbox); return (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();
@ -1023,17 +1024,17 @@ void Step(float t,float _edge_size)
if (TimeSelfIntersection()) if (TimeSelfIntersection())
CollisionDetection(); CollisionDetection();
} }
} }
void Smooth() void Smooth()
{ {
//ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5); //ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5);
vcg::tri::UpdateTopology<MyTriMesh>::VertexFace(*m); vcg::tri::UpdateTopology<MyTriMesh>::VertexFace(*m);
PasoDobleSmooth<MyTriMesh>(*m,1); PasoDobleSmooth<MyTriMesh>(*m,1);
} }
void AutoStep() 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
@ -1044,23 +1045,23 @@ void AutoStep()
edge_size=edge_precision; edge_size=edge_precision;
time_stamp/=2.f; time_stamp/=2.f;
} }
} }
//void MarchingCubeExtraction() //void MarchingCubeExtraction()
//{ //{
// /* // /*
// new_m = new MyTriMesh(); // new_m = new MyTriMesh();
// mcE.Extract(gray_init,&V,vcg::Point3i(2,2,2),*new_m);*/ // mcE.Extract(gray_init,&V,vcg::Point3i(2,2,2),*new_m);*/
// //
// MC_Extractor<MyTriMesh> mcE; // MC_Extractor<MyTriMesh> mcE;
// mcE.Extract(gray_init,V,vcg::Point3i(256,256,100),*m,gray_init); // 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(512,512,240),*m,gray_init);
// //mcE.Extract(gray_init,V,vcg::Point3i(128,128,60),*m,gray_init); // //mcE.Extract(gray_init,V,vcg::Point3i(128,128,60),*m,gray_init);
//} //}
///set as deleted intersected vertices ///set as deleted intersected vertices
void ClearIntersectedFaces() void ClearIntersectedFaces()
{ {
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++)
#ifdef _TORUS #ifdef _TORUS
@ -1076,11 +1077,11 @@ void ClearIntersectedFaces()
(*fi).SetD(); (*fi).SetD();
} }
#endif #endif
} }
///first version ///first version
void Resample() void Resample()
{ {
ClearIntersectedFaces(); ClearIntersectedFaces();
new_m=new MyTriMesh(); new_m=new MyTriMesh();
vcg::tri::UpdateBounding<MyTriMesh>::Box(*m); vcg::tri::UpdateBounding<MyTriMesh>::Box(*m);
@ -1091,7 +1092,7 @@ void Resample()
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/2.0,(int) edge_precision/2.0,(int) edge_precision/2.0),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 #endif
// delete(new_m0); // delete(new_m0);
delete(m); delete(m);
m=new_m; m=new_m;
@ -1099,7 +1100,7 @@ void Resample()
PartialReinitPhysicMesh(); PartialReinitPhysicMesh();
CollDet->Init(bbox.min,bbox.max,5.f); CollDet->Init(bbox.min,bbox.max,5.f);
} }
}; };
#endif #endif