compiled with new version of spatial hashing
This commit is contained in:
parent
aca3eeec83
commit
f8af64df99
|
|
@ -13,10 +13,11 @@ public:
|
|||
typedef typename ContSimplex::value_type SimplexType;
|
||||
typedef typename ContSimplex::value_type* SimplexPointer;
|
||||
typedef typename ContSimplex::iterator SimplexIterator;
|
||||
typedef typename SimplexType::CoordType Point3x;
|
||||
typedef typename Point3x::ScalarType ScalarType;
|
||||
typedef typename SimplexType::CoordType CoordType;
|
||||
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(){};
|
||||
|
|
@ -41,10 +42,14 @@ public:
|
|||
}
|
||||
|
||||
///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->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
|
||||
|
|
@ -66,9 +71,14 @@ public:
|
|||
if ((!f0->IsActive())&&(!f1->IsActive()))
|
||||
return false;
|
||||
//no adiacent faces
|
||||
if ((f0!=f1)&& (!ShareEdge(f0,f1))
|
||||
&& (!ShareVertex(f0,f1)))
|
||||
return (vcg::Intersection<SimplexType>((*f0),(*f1)));
|
||||
assert(f0!=f1);
|
||||
if ((f0!=f1)&& (!ShareEdge(f0,f1))&&!ShareVertex(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;
|
||||
}
|
||||
|
||||
|
|
@ -76,44 +86,29 @@ public:
|
|||
void RefreshElements()
|
||||
{
|
||||
HTable->Clear();
|
||||
vactive.clear();///new
|
||||
vactive.clear();
|
||||
|
||||
HTable->tempMark=0;
|
||||
|
||||
for (SimplexIterator si=_simplex.begin();si<_simplex.end();++si)
|
||||
{
|
||||
if (!(*si).IsD())
|
||||
{
|
||||
(*si).Mark()=0;
|
||||
if (!(*si).IsActive())
|
||||
|
||||
HTable->AddElem(&*si);
|
||||
///new now
|
||||
else
|
||||
(*si).HMark()=0;
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
if ((*si).IsActive())
|
||||
{
|
||||
std::vector<Point3i> cells=HTable->AddElem(&*si);
|
||||
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
|
||||
vactive.insert(*it);
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
for (int x=cells.min.X(); x<=cells.max.X();x++)
|
||||
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
|
||||
|
|
@ -126,35 +121,16 @@ public:
|
|||
{
|
||||
if ((!(*si).IsD())&&((*si).IsActive()))
|
||||
{
|
||||
std::vector<Point3i> cells=HTable->AddElem(&*si);
|
||||
for(std::vector<Point3i>::iterator it=cells.begin();it<cells.end();it++)
|
||||
vactive.insert(*it);
|
||||
vcg::Box3i cells=HTable->Add(&*si);
|
||||
for (int x=cells.min.X();x<=cells.max.X();x++)
|
||||
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
|
||||
std::vector<SimplexType*> computeSelfIntersection()
|
||||
|
|
@ -168,7 +144,8 @@ public:
|
|||
if (HTable->numElemCell(p,I)>=2)
|
||||
{
|
||||
std::vector<SimplexType*> inCell;
|
||||
HTable->getAtCell(p,inCell);
|
||||
inCell.clear();
|
||||
HTable->getInCellUpdated(p,inCell);
|
||||
int nelem=inCell.size();
|
||||
if (nelem>=2)
|
||||
{
|
||||
|
|
@ -181,6 +158,7 @@ public:
|
|||
ret.push_back(inCell[j]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -49,17 +49,17 @@ class Segmentator{
|
|||
|
||||
public:
|
||||
|
||||
struct DummyEdge;
|
||||
struct DummyTetra;
|
||||
struct MyFace;
|
||||
struct DummyEdge;
|
||||
struct DummyTetra;
|
||||
struct MyFace;
|
||||
|
||||
//#ifdef _EXTENDED_MARCH
|
||||
// struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
|
||||
//#else
|
||||
//#ifdef _EXTENDED_MARCH
|
||||
// struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
|
||||
//#else
|
||||
struct MyVertex: public ParticleBasic<vcg::VertexAFVNf<DummyEdge,MyFace,DummyTetra> >
|
||||
//#endif
|
||||
{
|
||||
public:
|
||||
//#endif
|
||||
{
|
||||
public:
|
||||
|
||||
bool blocked;//optimize after with vertex flags
|
||||
bool stopped;
|
||||
|
|
@ -68,8 +68,8 @@ public:
|
|||
{
|
||||
blocked=false;
|
||||
stopped=false;
|
||||
Acc()=Point3f(0,0,0);
|
||||
Vel()=Point3f(0,0,0);
|
||||
Acc()=CoordType(0,0,0);
|
||||
Vel()=CoordType(0,0,0);
|
||||
ClearFlags();
|
||||
//__super::
|
||||
//neeed call of the super class
|
||||
|
|
@ -83,14 +83,14 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
Acc()=Point3f(0,0,0);
|
||||
Vel()=Point3f(0,0,0);
|
||||
Acc()=CoordType(0,0,0);
|
||||
Vel()=CoordType(0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
IntForce()=Point3f(0.f,0.f,0.f);
|
||||
IntForce()=CoordType(0.f,0.f,0.f);
|
||||
}
|
||||
|
||||
void SetRestPos()
|
||||
|
|
@ -98,7 +98,7 @@ public:
|
|||
RPos()=P();
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
///this class implements the deformable triangle in a mass spring system
|
||||
struct MyFace : public TriangleMassSpring< vcg::FaceAFAVFNFMRT<MyVertex,DummyEdge,MyFace> >
|
||||
|
|
@ -107,7 +107,7 @@ public:
|
|||
bool intersected;
|
||||
float kdihedral;
|
||||
ScalarType AreaRep;
|
||||
int _Mark;
|
||||
int _HMark;
|
||||
|
||||
CoordType old_N;
|
||||
|
||||
|
|
@ -159,13 +159,13 @@ public:
|
|||
return (norm1*norm2);
|
||||
}
|
||||
|
||||
int &Mark()
|
||||
{return (_Mark);}
|
||||
inline int &HMark()
|
||||
{return (_HMark);}
|
||||
|
||||
///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);
|
||||
return (bb);
|
||||
}
|
||||
|
|
@ -235,23 +235,23 @@ public:
|
|||
return true;
|
||||
///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<MyFace*>,MyFace> Part_FaceContainer;
|
||||
typedef PDEIntegrator<Part_FaceContainer,Part_VertexContainer,float> myIntegrator;
|
||||
typedef Collision_Detector<std::vector<MyFace> > Collision;
|
||||
typedef Partial_Container<std::vector<MyVertex*>,MyVertex> Part_VertexContainer;
|
||||
typedef Partial_Container<std::vector<MyFace*>,MyFace> Part_FaceContainer;
|
||||
typedef PDEIntegrator<Part_FaceContainer,Part_VertexContainer,MyVertex::ScalarType> myIntegrator;
|
||||
typedef Collision_Detector<std::vector<MyFace> > Collision;
|
||||
|
||||
|
||||
////typedef Walker<MyTriMesh,MyTriMesh> MyWalk;
|
||||
//
|
||||
//#ifdef _EXTENDED_MARCH
|
||||
// typedef vcg::tri::ExtendedMarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
|
||||
//#else
|
||||
// typedef vcg::tri::MarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
|
||||
//#endif
|
||||
////typedef Walker<MyTriMesh,MyTriMesh> MyWalk;
|
||||
//
|
||||
//#ifdef _EXTENDED_MARCH
|
||||
// typedef vcg::tri::ExtendedMarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
|
||||
//#else
|
||||
// typedef vcg::tri::MarchingCubes<MyTriMesh, MyWalk> MarchingCubes;
|
||||
//#endif
|
||||
|
||||
|
||||
public:
|
||||
|
|
@ -292,7 +292,7 @@ public:
|
|||
//Volume_Dataset_Optimized<short> V;
|
||||
Volume_Dataset <short> V;
|
||||
|
||||
vcg::Box3<float> bbox;
|
||||
vcg::Box3<MyTriMesh::ScalarType> bbox;
|
||||
|
||||
char *inDir;
|
||||
char *outDir;
|
||||
|
|
@ -357,6 +357,7 @@ private:
|
|||
double conf=diameter*diameter;
|
||||
///now swap
|
||||
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
|
||||
bool OutOfLimits(MyTriMesh::CoordType p)
|
||||
{
|
||||
Point3f test=p;
|
||||
Point3f max=BBox().max-Point3f(1.f,1.f,1.f);//last change
|
||||
Point3f min=BBox().min;//+Point3f(1.f,1.f,1.f);//last change
|
||||
MyTriMesh::CoordType test=p;
|
||||
MyTriMesh::CoordType max=BBox().max-MyTriMesh::CoordType(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++)
|
||||
{
|
||||
if(((test.V(i)>=max.V(i))||(test.V(i)<=min.V(i))))
|
||||
|
|
@ -516,18 +517,18 @@ private:
|
|||
v->stopped=false;
|
||||
}
|
||||
|
||||
/////re-set physical pararmeters on the mesh
|
||||
//void InitPhysParam(float k_elanst,float mass,float k_dihedral)
|
||||
//{
|
||||
// for (unsigned int i=0;i<m->face.size();i++)
|
||||
// {
|
||||
// if (!m->face[i].IsD())
|
||||
// m->face[i].Init(k_elanst,mass,k_dihedral);
|
||||
// }
|
||||
//}
|
||||
/////re-set physical pararmeters on the mesh
|
||||
//void InitPhysParam(float k_elanst,float mass,float k_dihedral)
|
||||
//{
|
||||
// for (unsigned int i=0;i<m->face.size();i++)
|
||||
// {
|
||||
// if (!m->face[i].IsD())
|
||||
// m->face[i].Init(k_elanst,mass,k_dihedral);
|
||||
// }
|
||||
//}
|
||||
|
||||
///set the initial mesh of deformable object
|
||||
void InitMesh(MyTriMesh *m)
|
||||
///set the initial mesh of deformable object
|
||||
void InitMesh(MyTriMesh *m)
|
||||
{
|
||||
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
|
||||
bool InTolerance(MyTriMesh::VertexType *v)
|
||||
{
|
||||
///return true if the gray level of the vertex v differ from graylevel less than tolerance
|
||||
bool InTolerance(MyTriMesh::VertexType *v)
|
||||
{
|
||||
return (fabs(getColor(v->P())-(float)gray_init)<(float)tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
///add to the vertex v a containing force basing on diffence from tolerance
|
||||
MyTriMesh::CoordType ContainingForce(MyTriMesh::VertexType *v)
|
||||
{
|
||||
///add to the vertex v a containing force basing on diffence from tolerance
|
||||
MyTriMesh::CoordType ContainingForce(MyTriMesh::VertexType *v)
|
||||
{
|
||||
//float dinstance=fabs((FindGrayMedia(v))-gray_init);
|
||||
float dinstance=fabs((getColor(v->P()))-(float)gray_init);
|
||||
assert(dinstance<=tolerance);
|
||||
MyTriMesh::CoordType ret=(-v->N()*((dinstance)/(float)tolerance));
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
///find the gradient factor
|
||||
MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
|
||||
{
|
||||
///find the gradient factor
|
||||
MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
|
||||
{
|
||||
MyTriMesh::CoordType value=Gradient(v->P());
|
||||
/*float d0=getColor(v->P()+value);
|
||||
float d1=getColor(v->P()-value);
|
||||
|
|
@ -578,12 +579,12 @@ MyTriMesh::CoordType GradientFactor(MyTriMesh::VertexType *v)
|
|||
return (-value);
|
||||
else */
|
||||
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;
|
||||
/*PartialUpdateNormals();*/
|
||||
end_loop=true;
|
||||
|
|
@ -619,11 +620,11 @@ void AddExtForces()
|
|||
(*vi).ExtForce()=MyTriMesh::CoordType(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///reinit the partial integration vectors that describe active vertices
|
||||
void Reinit_PVectors()
|
||||
{
|
||||
///reinit the partial integration vectors that describe active vertices
|
||||
void Reinit_PVectors()
|
||||
{
|
||||
V_Stopped.clear();
|
||||
P_Vertex.clear();
|
||||
MyTriMesh::VertexIterator vi;
|
||||
|
|
@ -643,11 +644,11 @@ void Reinit_PVectors()
|
|||
if ((!fi->IsD())&&(!fi->IsBlocked())&&(!fi->intersected))
|
||||
P_Faces.push_back(&(*fi));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///erase the stopped entities from the partial containers
|
||||
void Refresh_PVectors()
|
||||
{
|
||||
///erase the stopped entities from the partial containers
|
||||
void Refresh_PVectors()
|
||||
{
|
||||
Part_FaceContainer P_FacesAux;
|
||||
Part_VertexContainer P_VertexAux;
|
||||
P_FacesAux.clear();
|
||||
|
|
@ -674,11 +675,11 @@ void Refresh_PVectors()
|
|||
|
||||
P_Faces=P_FacesAux;
|
||||
P_Vertex=P_VertexAux;
|
||||
}
|
||||
}
|
||||
|
||||
///add the new elements on partial vectors when allocate space for new vertices
|
||||
void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
|
||||
{
|
||||
///add the new elements on partial vectors when allocate space for new vertices
|
||||
void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
|
||||
{
|
||||
while (vi!=m->vert.end())
|
||||
{
|
||||
if ((!(*vi).IsD())&&(!(*vi).blocked)&&(!(*vi).stopped))
|
||||
|
|
@ -691,11 +692,11 @@ void AddNewElements(MyTriMesh::VertexIterator vi,MyTriMesh::FaceIterator fi)
|
|||
P_Faces.push_back(&(*fi));
|
||||
fi++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///verify and eventually stop the vertices of the mesh
|
||||
void VerifyForces()
|
||||
{
|
||||
///verify and eventually stop the vertices of the mesh
|
||||
void VerifyForces()
|
||||
{
|
||||
float proj;
|
||||
Part_VertexContainer::iterator vi;
|
||||
for (vi=P_Vertex.begin();vi<P_Vertex.end();++vi)
|
||||
|
|
@ -708,10 +709,10 @@ void VerifyForces()
|
|||
SetStopped(&*vi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimeReinit()
|
||||
{
|
||||
bool TimeReinit()
|
||||
{
|
||||
static clock_t time=0;
|
||||
clock_t elapsedsecs=abs(time-clock());
|
||||
if (elapsedsecs>interval_reinit)
|
||||
|
|
@ -720,10 +721,10 @@ bool TimeReinit()
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TimeSelfIntersection()
|
||||
{
|
||||
bool TimeSelfIntersection()
|
||||
{
|
||||
static clock_t time=0;
|
||||
clock_t elapsedsecs=abs(time-clock());
|
||||
if (elapsedsecs>interval_selfcollision)
|
||||
|
|
@ -732,11 +733,11 @@ bool TimeSelfIntersection()
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PartialUpdateNormals()
|
||||
{
|
||||
void PartialUpdateNormals()
|
||||
{
|
||||
/*vcg::tri::UpdateNormals<MyTriMesh>::PerFaceNormalized(*m);
|
||||
vcg::tri::UpdateNormals<MyTriMesh>::PerVertexNormalized(*m);*/
|
||||
Part_FaceContainer::iterator fi;
|
||||
|
|
@ -787,21 +788,21 @@ void PartialUpdateNormals()
|
|||
// if( !(*vi).IsD() && (*vi).IsRW() )
|
||||
// (*vi).N().Normalize();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//bool SelectToRefine()
|
||||
//{
|
||||
// MyTriMesh::FaceIterator fi;
|
||||
// for (fi=m->face.begin();pfi<m->face.end();++pfi)
|
||||
// {
|
||||
// if (((*fi).QualityFace()<0.1f))
|
||||
// fi->ClearS();
|
||||
// }
|
||||
//}
|
||||
//bool SelectToRefine()
|
||||
//{
|
||||
// MyTriMesh::FaceIterator fi;
|
||||
// for (fi=m->face.begin();pfi<m->face.end();++pfi)
|
||||
// {
|
||||
// if (((*fi).QualityFace()<0.1f))
|
||||
// fi->ClearS();
|
||||
// }
|
||||
//}
|
||||
|
||||
template<class MESH_TYPE>
|
||||
struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
|
||||
{
|
||||
template<class MESH_TYPE>
|
||||
struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
|
||||
{
|
||||
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;
|
||||
|
|
@ -813,17 +814,17 @@ struct MyMidPoint:vcg::MidPoint<MESH_TYPE>
|
|||
if( MESH_TYPE::HasPerVertexColor())
|
||||
nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///refine the mesh and re-update eventually
|
||||
void RefineStep(float _edge_size)
|
||||
{
|
||||
///refine the mesh and re-update eventually
|
||||
void RefineStep(float _edge_size)
|
||||
{
|
||||
MyTriMesh::VertexIterator vinit=m->vert.begin();
|
||||
MyTriMesh::FaceIterator finit=m->face.begin();
|
||||
MyTriMesh::VertexIterator vend=m->vert.end();
|
||||
MyTriMesh::FaceIterator fend=m->face.end();
|
||||
|
||||
// bool to_refine=SelectToRefine();
|
||||
// bool to_refine=SelectToRefine();
|
||||
|
||||
/*if (to_refine)*/
|
||||
//refined=vcg::Refine(*m,MidPoint<MyTriMesh>(),_edge_size,true);
|
||||
|
|
@ -853,17 +854,17 @@ void RefineStep(float _edge_size)
|
|||
PartialUpdateNormals();
|
||||
PartialReinitPhysicMesh();
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// vcg::tri::UpdateTopology<MyTriMesh>::TestFaceFace(*m);
|
||||
//#endif
|
||||
//#ifdef _DEBUG
|
||||
// vcg::tri::UpdateTopology<MyTriMesh>::TestFaceFace(*m);
|
||||
//#endif
|
||||
|
||||
//CollDet->RefreshElements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///reset vertex position and unblock them
|
||||
void PartialReinitPhysicMesh()
|
||||
{
|
||||
///reset vertex position and unblock them
|
||||
void PartialReinitPhysicMesh()
|
||||
{
|
||||
Part_FaceContainer::iterator pfi;
|
||||
|
||||
Part_VertexContainer::iterator pvi;
|
||||
|
|
@ -891,13 +892,13 @@ void PartialReinitPhysicMesh()
|
|||
|
||||
/*for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
|
||||
ClearStopped(&*vi);*/
|
||||
}
|
||||
}
|
||||
|
||||
///clear the stopped vertex
|
||||
void ClearStopped()
|
||||
{
|
||||
//for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
|
||||
// ClearStopped(&*vi);
|
||||
///clear the stopped vertex
|
||||
void ClearStopped()
|
||||
{
|
||||
//for (MyTriMesh::VertexIterator vi=m.vert.begin();vi<m.vert.end();vi++)
|
||||
// ClearStopped(&*vi);
|
||||
|
||||
Part_VertexContainer::iterator vi;
|
||||
for (vi=V_Stopped.begin();vi<V_Stopped.end();++vi)
|
||||
|
|
@ -905,11 +906,11 @@ void ClearStopped()
|
|||
ClearStopped(&*vi);
|
||||
}
|
||||
V_Stopped.clear();
|
||||
}
|
||||
}
|
||||
|
||||
///do one step of controls for self collision detetction
|
||||
void CollisionDetection()
|
||||
{
|
||||
///do one step of controls for self collision detetction
|
||||
void CollisionDetection()
|
||||
{
|
||||
CollDet->UpdateStep<Part_FaceContainer>(P_Faces);
|
||||
std::vector<MyFace*> coll=CollDet->computeSelfIntersection();
|
||||
for (std::vector<MyFace*>::iterator it=coll.begin();it<coll.end();it++)
|
||||
|
|
@ -920,21 +921,21 @@ void CollisionDetection()
|
|||
SetIntersectedFace(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
///set the initial barycenter where the triangle mesh start to expand
|
||||
//void SetInitialBarycenter(MyTriMesh::CoordType b)
|
||||
//{
|
||||
// InitialBarycenter=b;
|
||||
// gray_init=getColor(b);
|
||||
// /*InitMesh(m);*/
|
||||
//}
|
||||
///set the initial barycenter where the triangle mesh start to expand
|
||||
//void SetInitialBarycenter(MyTriMesh::CoordType b)
|
||||
//{
|
||||
// InitialBarycenter=b;
|
||||
// gray_init=getColor(b);
|
||||
// /*InitMesh(m);*/
|
||||
//}
|
||||
|
||||
///set the input output directory of images
|
||||
void LoadFromDir(char *in, char *out)
|
||||
{
|
||||
///set the input output directory of images
|
||||
void LoadFromDir(char *in, char *out)
|
||||
{
|
||||
inDir=in;
|
||||
outDir=out;
|
||||
|
||||
|
|
@ -944,21 +945,21 @@ void LoadFromDir(char *in, char *out)
|
|||
V.Init(1000,outDir);*/
|
||||
|
||||
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
|
||||
void LoadFromRaw(char *inDir)
|
||||
{
|
||||
///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,
|
||||
///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),
|
||||
clock_t _interval=2000,clock_t _interval2=250)
|
||||
{
|
||||
{
|
||||
mass=Mass;
|
||||
k_elanst=K_elanst;
|
||||
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;
|
||||
k_dihedral=Dihedral;
|
||||
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
|
||||
void InitSegmentation(MyTriMesh::CoordType b)
|
||||
{
|
||||
///init the segmentation of the mesh
|
||||
void InitSegmentation(MyTriMesh::CoordType b)
|
||||
{
|
||||
InitialBarycenter=b;
|
||||
gray_init=getColor(b);
|
||||
|
||||
|
|
@ -994,17 +995,17 @@ void InitSegmentation(MyTriMesh::CoordType b)
|
|||
PartialReinitPhysicMesh();
|
||||
|
||||
CollDet->Init(bbox.min,bbox.max,5.f);
|
||||
}
|
||||
}
|
||||
|
||||
///return the bounding box of the mesh
|
||||
vcg::Box3<float>& BBox()
|
||||
{
|
||||
///return the bounding box of the mesh
|
||||
vcg::Box3<MyTriMesh::ScalarType>& BBox()
|
||||
{
|
||||
return (bbox);
|
||||
}
|
||||
}
|
||||
|
||||
///one step of moving for the deformable object
|
||||
void Step(float t,float _edge_size)
|
||||
{
|
||||
///one step of moving for the deformable object
|
||||
void Step(float t,float _edge_size)
|
||||
{
|
||||
if (m->face.size()!=0)
|
||||
{
|
||||
AddExtForces();
|
||||
|
|
@ -1023,17 +1024,17 @@ void Step(float t,float _edge_size)
|
|||
if (TimeSelfIntersection())
|
||||
CollisionDetection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Smooth()
|
||||
{
|
||||
void Smooth()
|
||||
{
|
||||
//ScaleLaplacianSmooth<MyTriMesh>(*m,1,0.5);
|
||||
vcg::tri::UpdateTopology<MyTriMesh>::VertexFace(*m);
|
||||
PasoDobleSmooth<MyTriMesh>(*m,1);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoStep()
|
||||
{
|
||||
void AutoStep()
|
||||
{
|
||||
refined=false;
|
||||
Step(time_stamp,edge_size);
|
||||
//test on 80% of the vertex blocked
|
||||
|
|
@ -1044,23 +1045,23 @@ void AutoStep()
|
|||
edge_size=edge_precision;
|
||||
time_stamp/=2.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
//}
|
||||
//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()
|
||||
{
|
||||
///set as deleted intersected vertices
|
||||
void ClearIntersectedFaces()
|
||||
{
|
||||
MyTriMesh::FaceIterator fi;
|
||||
for (fi=m->face.begin();fi<m->face.end();fi++)
|
||||
#ifdef _TORUS
|
||||
|
|
@ -1076,11 +1077,11 @@ void ClearIntersectedFaces()
|
|||
(*fi).SetD();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
///first version
|
||||
void Resample()
|
||||
{
|
||||
///first version
|
||||
void Resample()
|
||||
{
|
||||
ClearIntersectedFaces();
|
||||
new_m=new MyTriMesh();
|
||||
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,
|
||||
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(new_m0);
|
||||
delete(m);
|
||||
|
||||
m=new_m;
|
||||
|
|
@ -1099,7 +1100,7 @@ void Resample()
|
|||
PartialReinitPhysicMesh();
|
||||
|
||||
CollDet->Init(bbox.min,bbox.max,5.f);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
Loading…
Reference in New Issue