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

@ -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()
@ -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);
} }
@ -241,7 +241,7 @@ struct MyTriMesh: public vcg::tri::TriMesh<std::vector<MyVertex>,std::vector<MyF
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;
@ -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))))
@ -944,7 +945,7 @@ 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
@ -972,7 +973,7 @@ 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!
} }
@ -997,7 +998,7 @@ void InitSegmentation(MyTriMesh::CoordType b)
} }
///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);
} }