compiled with new version of spatial hashing
This commit is contained in:
parent
aca3eeec83
commit
f8af64df99
|
|
@ -10,41 +10,46 @@ class Collision_Detector{
|
||||||
|
|
||||||
public:
|
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(){};
|
||||||
|
|
||||||
ContSimplex & _simplex;
|
ContSimplex & _simplex;
|
||||||
|
|
||||||
HashingTable *HTable;
|
HashingTable *HTable;
|
||||||
|
|
||||||
std::set<Point3i> vactive;
|
std::set<Point3i> vactive;
|
||||||
|
|
||||||
int active;
|
int active;
|
||||||
|
|
||||||
//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()));
|
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);
|
||||||
|
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
///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,49 +86,34 @@ 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
|
||||||
template <class Container_Type>
|
template <class Container_Type>
|
||||||
void UpdateStep(Container_Type &simplex)
|
void UpdateStep(Container_Type &simplex)
|
||||||
{
|
{
|
||||||
vactive.clear();
|
vactive.clear();
|
||||||
HTable->UpdateTmark();
|
HTable->UpdateTmark();
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -162,28 +138,30 @@ public:
|
||||||
std::vector<SimplexType*> ret;
|
std::vector<SimplexType*> ret;
|
||||||
std::set<Point3i>::iterator act;
|
std::set<Point3i>::iterator act;
|
||||||
for (act=vactive.begin();act!=vactive.end();act++)
|
for (act=vactive.begin();act!=vactive.end();act++)
|
||||||
|
{
|
||||||
|
Point3i p=*act;
|
||||||
|
HashingTable::IteHtable I;
|
||||||
|
if (HTable->numElemCell(p,I)>=2)
|
||||||
|
{
|
||||||
|
std::vector<SimplexType*> inCell;
|
||||||
|
inCell.clear();
|
||||||
|
HTable->getInCellUpdated(p,inCell);
|
||||||
|
int nelem=inCell.size();
|
||||||
|
if (nelem>=2)
|
||||||
{
|
{
|
||||||
Point3i p=*act;
|
//test combinations of elements
|
||||||
HashingTable::IteHtable I;
|
for (int i=0;i<nelem-1;i++)
|
||||||
if (HTable->numElemCell(p,I)>=2)
|
for (int j=i+1;j<nelem;j++)
|
||||||
{
|
if ((!inCell[i]->IsD())&&(!inCell[j]->IsD())&&(TestRealIntersection(inCell[i],inCell[j])))
|
||||||
std::vector<SimplexType*> inCell;
|
{
|
||||||
HTable->getAtCell(p,inCell);
|
ret.push_back(inCell[i]);
|
||||||
int nelem=inCell.size();
|
ret.push_back(inCell[j]);
|
||||||
if (nelem>=2)
|
}
|
||||||
{
|
|
||||||
//test combinations of elements
|
|
||||||
for (int i=0;i<nelem-1;i++)
|
|
||||||
for (int j=i+1;j<nelem;j++)
|
|
||||||
if ((!inCell[i]->IsD())&&(!inCell[j]->IsD())&&(TestRealIntersection(inCell[i],inCell[j])))
|
|
||||||
{
|
|
||||||
ret.push_back(inCell[i]);
|
|
||||||
ret.push_back(inCell[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue