示例#1
0
void Tetgen::removeSuperTetra()
{
	Node* pnd;

	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		getTetra(i)->setState(0);
		for(int j = 0; j < 4; j++)
		{
			pnd = getTetra(i)->getNode(j);
			if(pnd->getId() < 0)
			{
				getTetra(i)->setState(-1);
				break;
			}
		}
	}
	removeTetrahedra();

	for(int i = 0; i < 4; i++)
	{
		delete sptet_nd[i];
		sptet_nd[i] = NULL;
	}
}
示例#2
0
void Tetgen::setDomain(int dm)
{
	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		if(getTetra(i)->getState() == 1)
			getTetra(i)->setDomain(dm);
		getTetra(i)->setState(0);
	}
}
示例#3
0
void Tetgen::removeTetrahedra()
{
	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		if(getTetra(i)->getState() == -1)
		{
			n = erase(i + 1);
			i--;
			continue;
		}
		getTetra(i)->setState(0);
	}
}
示例#4
0
void Tetgen::cleanBadTetra(double min_value)
{
	Node* nd;
	Tetra* itet;
	double mindens,minvolm;

	mindens = cr_crowd->getCurrentMinDensity();
	minvolm = mindens * mindens * mindens * rate_minvolm;

	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		itet = getTetra(i);

		if(itet->getVolume() > minvolm &&
		   itet->getValue() > min_value)
			continue;

		for(int j = 0; j < 4; j++)
		{
			nd = itet->getNode(j);
			if(nd->getType() == 0 )
				continue;
			if(eraseNode(nd))
				break;
		}
		n = getSize();
	}
}
示例#5
0
void Tetgen::makeSuperTetra()
{
	double ix,iy,iz;

	sptet_nd[0] = new Node(-1);
	sptet_nd[1] = new Node(-2);
	sptet_nd[2] = new Node(-3);
	sptet_nd[3] = new Node(-4);

	ix =   86.60;
	iy =    0.00;
	iz =  -50.00;
	sptet_nd[0]->setCoordinates(ix,iy,iz);
	ix =  -43.30;
	iy =   75.00;
	iz =  -50.00;
	sptet_nd[1]->setCoordinates(ix,iy,iz);
	ix =  -43.30;
	iy =  -75.00;
	iz =  -50.00;
	sptet_nd[2]->setCoordinates(ix,iy,iz);
	ix =    0.00;
	iy =    0.00;
	iz =  100.00;
	sptet_nd[3]->setCoordinates(ix,iy,iz);

	makeNewTetra(sptet_nd[0],sptet_nd[1],sptet_nd[2],sptet_nd[3]);
	getTetra(0)->setVolume();
}
示例#6
0
int Tetgen::conectNewTetra(vector<int>&tet_id_buff,int nend)
{
	int i,j,k,l;
	int flg;
	Tetra* crtet;
	Node* cr_nd1,* cr_nd2,* nb_nd1,* nb_nd2;
	Adpt tmp_adpt;
	const int jj0[3] = {1,2,0};
	const int jj1[3] = {2,0,1};

	if(flg_tbl)
		for(i = 0; i < tbl_long; i++)
			tbl[i].clear();
	else
	{
		tbl.resize(tbl_long);
		flg_tbl = 1;
	}

	//conect each new tetrahedra
	//int np = tet_id_buff.size();
	for(i = 0; i < nend; i++)
	{
		crtet = getTetra(tet_id_buff[i] - 1);
		for(j = 0; j < 3; j++)
		{
			flg = 0;
			cr_nd1 = crtet->getNode(jj0[j]);
			cr_nd2 = crtet->getNode(jj1[j]);
			////////+10:for surertetra`s nodes
			l = (cr_nd1->getId() + cr_nd2->getId() + 10) % tbl_long;
			///////////
			int n = (int)tbl[l].size();
			for(k = 0; k < n; k++)
			{
				tmp_adpt = tbl[l][k];
				nb_nd1 = tmp_adpt.face[0];
				nb_nd2 = tmp_adpt.face[1];
				if(cr_nd1 == nb_nd1 && cr_nd2 == nb_nd2)
				{
					crtet->resetNeighborElement(j,tmp_adpt.neib);
					tmp_adpt.neib->resetNeighborElement(tmp_adpt.num,crtet);
					tbl[l][k] = tbl[l][n - 1];
					tbl[l].pop_back();
					flg = 1;
					break;
				}
			} //for k
			if(flg)
				continue;
			tmp_adpt.face[0] = cr_nd2;
			tmp_adpt.face[1] = cr_nd1;
			tmp_adpt.neib = crtet;
			tmp_adpt.num = j;
			tbl[l].push_back(tmp_adpt);
		} //for j
	} //for i

	return (int)tet_id_buff.size();
}
示例#7
0
void Tetgen::makeSuperTetra(double maxwidth,Point minpt)
{
	double ix,iy,iz;

	sptet_nd[0] = new Node(-1);
	sptet_nd[1] = new Node(-2);
	sptet_nd[2] = new Node(-3);
	sptet_nd[3] = new Node(-4);

	ix =   86.60 * maxwidth + minpt.getX();
	iy =    0.00 + minpt.getY();
	iz =  -50.00 * maxwidth + minpt.getZ();
	sptet_nd[0]->setCoordinates(ix,iy,iz);
	ix =  -43.30 * maxwidth + minpt.getX();
	iy =   75.00 * maxwidth + minpt.getY();
	iz =  -50.00 * maxwidth + minpt.getZ();
	sptet_nd[1]->setCoordinates(ix,iy,iz);
	ix =  -43.30 * maxwidth + minpt.getX();
	iy =  -75.00 * maxwidth + minpt.getY();
	iz =  -50.00 * maxwidth + minpt.getZ();
	sptet_nd[2]->setCoordinates(ix,iy,iz);
	ix =    0.00 + minpt.getX();
	iy =    0.00 + minpt.getY();
	iz =  100.00 * maxwidth + minpt.getZ();
	sptet_nd[3]->setCoordinates(ix,iy,iz);

	makeNewTetra(sptet_nd[0],sptet_nd[1],sptet_nd[2],sptet_nd[3]);
	getTetra(0)->setVolume();
}
示例#8
0
void Tetgen::view()
{
	cout << "TETGEN SIZE = " << getSize() << "\n";
	int n = getSize();
	for(int i = 0; i < n; i++)
		getTetra(i)->view();

}
示例#9
0
int Tetgen::correctPolyTetraAdd(vector<int>&tet_id_buff,
                                vector<Adpt>&adpt_buff,Node* cr_nd)
{
	int i,j;
	Tetra* crtet,* nbtet;
	Node* nd0,* nd1,* nd2;
	Adpt tmp_adpt;
	const int ij0[4] = {1,2,3,0};
	const int ij1[4] = {3,3,1,1};
	const int ij2[4] = {2,0,0,2};

	//pick up surface triangle(=adpt_buff) of poly tetrahedra(polygon)(=tet_id_buff)
	i = 0;
	int n = (int)tet_id_buff.size();
	while (i < n)
	{
		crtet = getTetra(tet_id_buff[i] - 1);
		for (j = 0; j < 4; j++)
		{
			nbtet = crtet->getNeighborElement(j);
			nd0 = crtet->getNode(ij0[j]);
			nd1 = crtet->getNode(ij1[j]);
			nd2 = crtet->getNode(ij2[j]);
			if (!nbtet)
			{
				tmp_adpt.face[0] = nd0;
				tmp_adpt.face[1] = nd1;
				tmp_adpt.face[2] = nd2;
				tmp_adpt.neib = NULL;
				tmp_adpt.num = 0;
				tmp_adpt.vol = getTetraVolume(nd0,nd1,nd2,cr_nd);
				adpt_buff.push_back(tmp_adpt);
			} //if !nbtet
			else if (nbtet->getState() != 1)
			{
				tmp_adpt.face[0] = nd0;
				tmp_adpt.face[1] = nd1;
				tmp_adpt.face[2] = nd2;
				tmp_adpt.neib = nbtet;
				tmp_adpt.num = nbtet->getConection(crtet);
				tmp_adpt.vol = getTetraVolume(nd0,nd1,nd2,cr_nd);
				adpt_buff.push_back(tmp_adpt);
				if (tmp_adpt.vol < LIMIT)
				{
					tet_id_buff.push_back(nbtet->getId());
					nbtet->setState(1);
					adpt_buff.clear();
					i = -1;
					n = (int)tet_id_buff.size();
					break;
				}
			} //else if nbtet->getState() != 1
		} //for j
		i++;
	} //while i < tet_id_buff.size()

	return (int)tet_id_buff.size();
}
示例#10
0
void Tetgen::setTetHanger()
{
	Tetra* crtet;
	Node* nd;

	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		crtet = getTetra(i);
		for(int j = 0; j < 4; j++)
		{
			nd = crtet->getNode(j);
			nd->insertHanger(crtet,FG_TYPE_TET);
		}
	}
}
示例#11
0
Tetra* Tetgen::locate(Point* ppt)
{
	Tetra* crtet;
	Node* p0,* p1,* p2;
	Plane plane;
	double ans;
	const int ij0[4] = {1,2,3,0};
	const int ij1[4] = {3,3,1,1};
	const int ij2[4] = {2,0,0,2};
	int counter = 0;

	int i = 0;
	crtet = getTetra(getSize() - 1);
	while (i < 4)
	{
		p0 = crtet->getNode(ij0[i]);
		p1 = crtet->getNode(ij1[i]);
		p2 = crtet->getNode(ij2[i]);
		plane.setVector(p0,p1,p2);
		ans = plane.getAnswer(ppt);
		if (ans < -LIMIT_10)
		{
			counter++;
			if(counter > LIMIT_NUMBER_OF_ELEMENTS)
			{
				Errors err(0,
				           "Tetra* Tetgen::locate(Point *ppt)",
				           "cannot find tetra");
				throw err;
			}
			crtet = crtet->getNeighborElement(i);
			if(!crtet)
			{
				Errors err(0,
				           "Tetra* Tetgen::locate(Point *ppt)",
				           "cannot find tetra");
				throw err;
			}
			i = 0;
			continue;
		}
		i++;
	} //while i<4

	return crtet;
}
示例#12
0
Tetra* Tetgen::optlocate(Point* ppt)
{
	Tetra* crtet = NULL;
	Node* p0,* p1,* p2;
	Plane plane;
	double ans;
	int flg;
	const int ij0[4] = {1,2,3,0};
	const int ij1[4] = {3,3,1,1};
	const int ij2[4] = {2,0,0,2};

	int n = getSize();
	for(int i = 0; i < n; i++)
	{
		crtet = getTetra(i);
		flg = 1;
		for(int j = 0; j < 4; j++)
		{
			p0 = crtet->getNode(ij0[j]);
			p1 = crtet->getNode(ij1[j]);
			p2 = crtet->getNode(ij2[j]);

			plane.setVector(p0,p1,p2);
			ans = plane.getAnswer(ppt);

			if (ans < -LIMIT)
			{
				flg = 0;
				break;
			}
		}
		if(flg)
			break;
	}

	return crtet;
}
示例#13
0
void Tetgen::fineTetra()
{
	int i;
	int n;
	Tetra* crtet;
	Node* nd0,* nd1,* nd2,* nd3;
	Node* new_nd;
	Point tmp_pt;
	double vol;
	double dist;
	double mindens,minvol;
	double nx,ny,nz,nden;
	int flg;
	vector<int> tet_id_buff;

	if(!cr_crowd)
		return;

	mindens = cr_crowd->getCurrentMinDensity();
	minvol = mindens * mindens * mindens * rate_minvolm;

	flg = 1;
	while(flg)
	{
		flg = 0;
		n = getSize();
		for(i = 0; i < n; i++)
		{
			crtet = getTetra(i);
			vol = crtet->getVolume();
			if(vol < minvol)
				continue;
			nd0 = crtet->getNode(0);
			nd1 = crtet->getNode(1);
			nd2 = crtet->getNode(2);
			nd3 = crtet->getNode(3);
			nx = (nd0->getX() + nd1->getX() + nd2->getX() + nd3->getX()) * 0.25;
			ny = (nd0->getY() + nd1->getY() + nd2->getY() + nd3->getY()) * 0.25;
			nz = (nd0->getZ() + nd1->getZ() + nd2->getZ() + nd3->getZ()) * 0.25;
			tmp_pt.setCoordinates(nx,ny,nz);

			dist = getDistance(&tmp_pt,nd0);
			if(nd0->getDensity() > dist * rate_density)
				continue;
			dist = getDistance(&tmp_pt,nd1);
			if(nd1->getDensity() > dist * rate_density)
				continue;
			dist = getDistance(&tmp_pt,nd2);
			if(nd2->getDensity() > dist * rate_density)
				continue;
			dist = getDistance(&tmp_pt,nd3);
			if(nd3->getDensity() > dist * rate_density)
				continue;

			flg = 1;
			nden = (nd0->getDensity() + nd1->getDensity() +
			        nd2->getDensity() + nd3->getDensity()) * 0.25;

			new_nd = cr_crowd->makeNewNode(nx,ny,nz,nden);
			new_nd->setType(3);

			//remeshing
			tet_id_buff.clear();
			addNode(tet_id_buff,crtet,new_nd);

			if(!tet_id_buff.size())
			{
				cr_crowd->erase(new_nd->getId());
				continue;
			}
			n = getSize();
		} //for i
	} //while flg

	/*
	   view();
	   getch();
	   setTetHanger();


	    Node *nnd = cr_crowd->getNode(202);

	    nnd->view();
	    getch();
	    eraseNode(nnd);

	    nnd = cr_crowd->getNode(203);

	    nnd->view();
	    getch();
	    eraseNode(nnd);
	    getch();

	   view();
	   getch();
	 */
}
示例#14
0
int Tetgen::reMeshTetra(vector<int>&tet_id_buff,vector<Adpt>&adpt_buff,Node* cr_nd)
{
	int i;
	Tetra* crtet;
	Node* nd0,* nd1,* nd2;
	int domain = 0;

	//refresh tetrahedra
	if(tet_id_buff.size() <= adpt_buff.size())
	{
		//recycle old tetrahedra
		int np = (int)tet_id_buff.size();
		for(i = 0; i < np; i++)
		{
			crtet = getTetra(tet_id_buff[i] - 1);
			domain = crtet->getDomain();
			nd0 = adpt_buff[i].face[0];
			nd1 = adpt_buff[i].face[1];
			nd2 = adpt_buff[i].face[2];
			crtet->resetNode(nd0,nd1,nd2,cr_nd);
			crtet->setVolume(adpt_buff[i].vol);
			crtet->resetNeighborElement(3,adpt_buff[i].neib);
			if(adpt_buff[i].neib)
				adpt_buff[i].neib->resetNeighborElement(adpt_buff[i].num,crtet);
			//crtet->setSphere();
			crtet->setState(0);
			crtet->setDomain(domain);
		} //for i
		  //if run out old one, make new tetrahedra
		int na = (int)adpt_buff.size();
		for(i = np; i < na; i++)
		{
			int ip = getSize() + 1;
			nd0 = adpt_buff[i].face[0];
			nd1 = adpt_buff[i].face[1];
			nd2 = adpt_buff[i].face[2];
			crtet = makeNewTetra(nd0,nd1,nd2,cr_nd);
			crtet->setVolume(adpt_buff[i].vol);
			crtet->resetNeighborElement(3,adpt_buff[i].neib);
			if(adpt_buff[i].neib)
				adpt_buff[i].neib->resetNeighborElement(adpt_buff[i].num,crtet);
			//crtet->setSphere();
			crtet->setState(0);
			crtet->setDomain(domain);
			tet_id_buff.push_back(ip);
		} //for i
	}
	else
	{
		//recycle old tetrahedra
		int na = (int)adpt_buff.size();
		for(i = 0; i < na; i++)
		{
			crtet = getTetra(tet_id_buff[i] - 1);
			domain = crtet->getDomain();
			nd0 = adpt_buff[i].face[0];
			nd1 = adpt_buff[i].face[1];
			nd2 = adpt_buff[i].face[2];
			crtet->resetNode(nd0,nd1,nd2,cr_nd);
			crtet->setVolume(adpt_buff[i].vol);
			crtet->resetNeighborElement(3,adpt_buff[i].neib);
			if(adpt_buff[i].neib)
				adpt_buff[i].neib->resetNeighborElement(adpt_buff[i].num,crtet);
			//crtet->setSphere();
			crtet->setState(0);
			crtet->setDomain(domain);
		}
		sort(tet_id_buff.begin() + i,tet_id_buff.end(),greater<int>());
	} //if tet_id_buff.size() <= adpt_buff.size() , else

	return (int)tet_id_buff.size();
}
示例#15
0
int Tetgen::correctPolyTetraCut(vector<int>&tet_id_buff,
                                vector<Adpt>&adpt_buff,Node* cr_nd)
{
	int i,j;
	Tetra* crtet,* nbtet;
	Adpt tmp_adpt;
	const int ij0[4] = {1,2,3,0};
	const int ij1[4] = {3,3,1,1};
	const int ij2[4] = {2,0,0,2};
	///adpt.reserve(tet_id_buff.size()*2);

	//pick up surface triangle(=adpt_buff) of poly tetrahedra(polygon)(=tet_id_buff)
	//this part is diffarent from function Poly (other parts are almost same)
	i = 0;
	int n = (int)tet_id_buff.size();
	while (i < n)
	{
		crtet = getTetra(tet_id_buff[i] - 1);
		for (j = 0; j < 4; j++)
		{
			nbtet = crtet->getNeighborElement(j);
			if (!nbtet)
			{
				tmp_adpt.face[0] = crtet->getNode(ij0[j]);
				tmp_adpt.face[1] = crtet->getNode(ij1[j]);
				tmp_adpt.face[2] = crtet->getNode(ij2[j]);
				tmp_adpt.neib = NULL;
				tmp_adpt.num = 0;
				tmp_adpt.vol = getTetraVolume(tmp_adpt.face[0],
				                              tmp_adpt.face[1],
				                              tmp_adpt.face[2],
				                              cr_nd);
				adpt_buff.push_back(tmp_adpt);
				if(tmp_adpt.vol < LIMIT)
				{
					crtet->setState(-1);
					tet_id_buff[i] = tet_id_buff[tet_id_buff.size() - 1];
					tet_id_buff.pop_back();
					adpt_buff.clear();
					i = -1;
					n = (int)tet_id_buff.size();
					break;
				}
			} //if !nbtet
			else if (nbtet->getState() != 1)
			{
				tmp_adpt.face[0] = crtet->getNode(ij0[j]);
				tmp_adpt.face[1] = crtet->getNode(ij1[j]);
				tmp_adpt.face[2] = crtet->getNode(ij2[j]);
				tmp_adpt.neib = nbtet;
				tmp_adpt.num = nbtet->getConection(crtet);
				tmp_adpt.vol = getTetraVolume(tmp_adpt.face[0],
				                              tmp_adpt.face[1],
				                              tmp_adpt.face[2],
				                              cr_nd);
				adpt_buff.push_back(tmp_adpt);
				if (tmp_adpt.vol < LIMIT)
				{
					crtet->setState(-1);
					tet_id_buff[i] = tet_id_buff[tet_id_buff.size() - 1];
					tet_id_buff.pop_back();
					adpt_buff.clear();
					n = (int)tet_id_buff.size();
					i = -1;
					break;
				}
			} //else if nbtet->getState() != 1
		} //for j
		i++;
	} //while i < tet_id_buff.size()

	return (int)tet_id_buff.size();
}
void VoronoiShatter::getVDFormDT(){

	//VD's vertex:  DT's tetra, center of the sphere
	//VD's edge:  2 VD's vertex with the same DT's face
	//VD's face:  tetra which share DT's edge
	//VD's poly:  share DT's vertex
	std::cerr<<"START!!!!!!!!!!!!!!11: "<< std::endl;	
	int counter = 0;
	int currentKey = 0;
	int flag = 0;
	int first_vertex_flag = 0;
			int previousTetraKey = 0;
			int nextTetraKey = 0;
			int firstTetraKey = 0;
			int nowVertexId = 0;
			bool still_has_edge=true;
	Tetrahedron t;
	//VoronoiShatter voronoiShatter;
	//TetraMap pool = voronoiShatter.getPool();
	TetraMap pool = tetraPool;
	TetraMapItr itr = pool.begin();

	for( ; itr!=pool.end(); itr++){
		// get tetrahedront
		t = itr->second;
	
		// put all verteces to set, not include big tetra's vertecies
		if( t.v1 != bigTetra .v1 && t.v1 != bigTetra .v2 && t.v1 !=bigTetra .v3 && t.v1 != bigTetra .v4)
			vertexSet.insert(t.v1);
		if( t.v2 != bigTetra .v1 && t.v2 != bigTetra .v2 && t.v2 !=bigTetra .v3 && t.v2 != bigTetra .v4)
			vertexSet.insert(t.v2);
		if( t.v3 != bigTetra .v1 && t.v3 != bigTetra .v2 && t.v3 !=bigTetra .v3 && t.v3 != bigTetra .v4)
			vertexSet.insert(t.v3);
		if( t.v4 != bigTetra .v1 && t.v4 != bigTetra .v2 && t.v4 !=bigTetra .v3 && t.v4 != bigTetra .v4)
			vertexSet.insert(t.v4);
	}


	Tetrahedron originalTetra;

	
	while( !vertexSet.empty() )
	{
		first_vertex_flag = 0;
		// not sure
		// choose one vertex p
		checkVertex = vertexSet.begin();	

		// if no tetra contains p
		if( getTetra(checkVertex->incidentTetra, originalTetra)  ==false){
			vertexSet.erase(checkVertex);
			continue;
		}
			
		// tetra contains p
		inSetEdge e1;
		inSetEdge e2;
		inSetEdge e3;

		// push the edge to stack
		if(*checkVertex == originalTetra.v1){
			std::cerr<<"AAA: "<< std::endl;	
			e1.startVertex = originalTetra.v1;
			e1.endVertex = originalTetra.v2;
			e1.key = originalTetra.key;

			e2.startVertex = originalTetra.v1;
			e2.endVertex = originalTetra.v3;
			e2.key = originalTetra.key;

			e3.startVertex = originalTetra.v1;
			e3.endVertex = originalTetra.v4;
			e3.key = originalTetra.key;

			edgeSet.insert(e1);
			edgeSet.insert(e2);
			edgeSet.insert(e3);
		}
		else if(*checkVertex == originalTetra.v2){
			std::cerr<<"BBB: "<< std::endl;	
			e1.startVertex = originalTetra.v2;
			e1.endVertex = originalTetra.v1;
			e1.key = originalTetra.key;

			e2.startVertex = originalTetra.v2;
			e2.endVertex = originalTetra.v3;
			e2.key = originalTetra.key;

			e3.startVertex = originalTetra.v2;
			e3.endVertex = originalTetra.v4;
			e3.key = originalTetra.key;

			edgeSet.insert(e1);
			edgeSet.insert(e2);
			edgeSet.insert(e3);
		}
		else if(*checkVertex == originalTetra.v3){
			std::cerr<<"CCC: "<< std::endl;	
			e1.startVertex = originalTetra.v3;
			e1.endVertex = originalTetra.v1;
			e1.key = originalTetra.key;

			e2.startVertex = originalTetra.v3;
			e2.endVertex = originalTetra.v2;
			e2.key = originalTetra.key;

			e3.startVertex = originalTetra.v3;
			e3.endVertex = originalTetra.v4;
			e3.key = originalTetra.key;

			edgeSet.insert(e1);
			edgeSet.insert(e2);
			edgeSet.insert(e3);
		}
		else if(*checkVertex == originalTetra.v4){
			std::cerr<<"DDD: "<< std::endl;	
			e1.startVertex = originalTetra.v4;
			e1.endVertex = originalTetra.v1;
			e1.key = originalTetra.key;
			std::cerr<<"DDD - e1.key: "<<e1.key<< std::endl;	

			e2.startVertex = originalTetra.v4;
			e2.endVertex = originalTetra.v2;
			e2.key = originalTetra.key;
			std::cerr<<"DDD - e2.key: "<<e2.key<< std::endl;	

			e3.startVertex = originalTetra.v4;
			e3.endVertex = originalTetra.v3;
			e3.key = originalTetra.key;
			std::cerr<<"DDD - e3.key: "<<e3.key<< std::endl;	

			edgeSet.insert(e1);
			edgeSet.insert(e2);
			edgeSet.insert(e3);
		}


		int vdEdgeTag = 0;
		int vdFaceTag = 0;
		VDfaceIndex.push_back(0);
		VDpolyIndex.push_back(0);

		// choose first edge
	//	currentEdgeItr = edgeSet.begin();
		bool hasNeighbor =true;


		still_has_edge = true;
		flag=0;
		inSetEdge usedEdge;
		int cou=0;
		while( still_has_edge==true  )
	//	for( currentEdgeItr; currentEdgeItr!=edgeSet.end(); currentEdgeItr++ )  //while haven't choosen the last edge
	//	for( ; currentEdgeItr!=edgeSet.end(); currentEdgeItr++ )  //while haven't choosen the last edge
		{


	//		if(still_has_edge==false)
	//			break;
			//choose one edge, from first to compare used set
	if(flag==0 || flag==3 ){
			currentEdgeItr = edgeSet.begin();			
			usedEdge.startVertex = currentEdgeItr->startVertex;
			usedEdge.endVertex = currentEdgeItr->endVertex;
			usedEdge.key = currentEdgeItr->key;
	
	}
	
	if(flag!=1 && flag!=4)
	{
		if(usedEdgeSet.size()!=edgeSet.size()-1)
		{

			while( usedEdgeSet.count(usedEdge)!=0   )
			{		
					currentEdgeItr++;
					usedEdge.startVertex = currentEdgeItr->startVertex;
					usedEdge.endVertex = currentEdgeItr->endVertex;
					usedEdge.key = currentEdgeItr->key;
			}
		}
		else
		{
					usedEdge.startVertex = currentEdgeItr->startVertex;
					usedEdge.endVertex = currentEdgeItr->endVertex;
					usedEdge.key = currentEdgeItr->key;
					flag=4;
					cou=0;
								previousTetraKey = 0;
			nextTetraKey = 0;
			firstTetraKey = 0;
			
			
			// find the edge from which tetra
			currentKey = currentEdgeItr->key; 
		first_vertex_flag = 0;
			firstTetraKey = currentEdgeItr->key;
		}
				
	}
		

			usedEdgeSet.insert(usedEdge);

			std::cerr<<"setEdgeSize: "<< edgeSet.size()<<std::endl;

			// choose one edge E
	//		inSetEdge currentEdge;
	//		currentEdge = edgeSet.top();
			hasNeighbor = true;
			
	
	

			if(flag!=1 && flag!=4){
			previousTetraKey = 0;
			nextTetraKey = 0;
			firstTetraKey = 0;
			
			
			// find the edge from which tetra
			currentKey = currentEdgeItr->key; 
	//		first_vertex_flag = 0;
			firstTetraKey = currentEdgeItr->key;
			}

			Tetrahedron currentTetra;
						
			while( hasNeighbor )
			{

						counter++;
				std::cerr<<"counter: "<< counter<<std::endl;	
				std::cerr<<"currentKey - StartAAA: "<< currentKey<<std::endl;	
				// get current tetra
				if( !getTetra( currentKey, currentTetra) ){
					//continue;
					break;
				}
				std::cerr<<"currentKey - StartBBB: "<< currentKey<<std::endl;	


						// tetra contains p
						inSetEdge ed1;
						inSetEdge ed2;
						inSetEdge ed3;
					// push the edge to stack
				if(*checkVertex == currentTetra.v1)
				{
					std::cerr<<"EEE: "<< std::endl;	
					ed1.startVertex = currentTetra.v1;
					ed1.endVertex = currentTetra.v2;
			//		findEdge  = edgeSet.find(ed1);
					
					if( edgeSet.count(ed1) == 0 )
					{
						ed1.key =currentTetra.key;
						edgeSet.insert(ed1);
					}

					ed2.startVertex = currentTetra.v1;
					ed2.endVertex = currentTetra.v3;
			//		findEdge  = edgeSet.find(ed2);
					
					if( edgeSet.count(ed2) == 0 )
					{
						ed2.key = currentTetra.key;
						edgeSet.insert(ed2);
					}

					ed3.startVertex = currentTetra.v1;
					ed3.endVertex = currentTetra.v4;
				//	findEdge  = edgeSet.find(ed3);
					
					if( edgeSet.count(ed3) == 0 )
					{
						ed3.key = currentTetra.key;
						edgeSet.insert(ed3);
					}
					
				}
				
				if(*checkVertex == currentTetra.v2)
				{
					std::cerr<<"FFF: "<< std::endl;	
					ed1.startVertex = currentTetra.v2;
					ed1.endVertex = currentTetra.v1;
	//				findEdge  = edgeSet.find(ed1);
					
					if( edgeSet.count(ed1) == 0 )
					{
						ed1.key =currentTetra.key;
						edgeSet.insert(ed1);
					}

					ed2.startVertex = currentTetra.v2;
					ed2.endVertex = currentTetra.v3;
		//			findEdge  = edgeSet.find(ed2);
					
					if( edgeSet.count(ed2) == 0 )
					{
						ed2.key = currentTetra.key;
						edgeSet.insert(ed2);
					}

					ed3.startVertex = currentTetra.v2;
					ed3.endVertex = currentTetra.v4;
				//	findEdge  = edgeSet.find(ed3);
					
					if( edgeSet.count(ed3) == 0 )
					{
						ed3.key = currentTetra.key;
						edgeSet.insert(ed3);
					}

	
				}
				
				if(*checkVertex == currentTetra.v3)
				{
					std::cerr<<"GGG: "<< std::endl;	
					ed1.startVertex = currentTetra.v3;
					ed1.endVertex = currentTetra.v1;
			//		findEdge  = edgeSet.find(ed1);
					
					if( edgeSet.count(ed1) == 0 )
					{
						ed1.key =currentTetra.key;
						edgeSet.insert(ed1);
					}

					ed2.startVertex = currentTetra.v3;
					ed2.endVertex = currentTetra.v2;
	//				findEdge  = edgeSet.find(ed2);
					
					if( edgeSet.count(ed2) == 0 )
					{
						ed2.key = currentTetra.key;
						edgeSet.insert(ed2);
					}

					ed3.startVertex = currentTetra.v3;
					ed3.endVertex = currentTetra.v4;
			//		findEdge  = edgeSet.find(ed3);
					
					if( edgeSet.count(ed3) == 0 )
					{
						ed3.key = currentTetra.key;
						edgeSet.insert(ed3);
					}

				}
				
				if(*checkVertex == currentTetra.v4)
				{
					std::cerr<<"HHH: "<< std::endl;	
					ed1.startVertex = currentTetra.v4;
					ed1.endVertex = currentTetra.v1;
		//			findEdge  = edgeSet.find(ed1);
					
					if( edgeSet.count(ed1) == 0 )
					{
						ed1.key =currentTetra.key;
						edgeSet.insert(ed1);
						std::cerr<<"HHH - ED1: "<<ed1.key<< std::endl;	
					}

					ed2.startVertex = currentTetra.v4;
					ed2.endVertex = currentTetra.v2;
	//				findEdge  = edgeSet.find(ed2);
					
					if( edgeSet.count(ed2) == 0 )
					{
						ed2.key = currentTetra.key;
						edgeSet.insert(ed2);
						std::cerr<<"HHH - ED2: "<<ed2.key<< std::endl;	
					}

					ed3.startVertex = currentTetra.v4;
					ed3.endVertex = currentTetra.v3;
			//		findEdge  = edgeSet.find(ed3);
					
					if( edgeSet.count(ed3) == 0 )
					{
						ed3.key = currentTetra.key;
						edgeSet.insert(ed3);
						std::cerr<<"HHH - ED3: "<<ed3.key<< std::endl;	
					}
	
				}

				


				// find VD's vertex vp of currentTetra
				Vertex vp;
				vp = findSphereCenter( currentTetra );
		
				// end of finding VD's vertex vp of currentTetra
				std::cerr<<"Vertex: "<<std::endl;	
				// put vp into VDvertex
				VDvertex.push_back(vp);
				// end of putting vp into VDvertex

				if(first_vertex_flag==0)
				{
					nowVertexId = VDvertex.size()-1;
					
				}
			

				if(flag==1 || (flag==4&&cou!=0)){
				// recode the VDedge
				if(VDvertex.size()>1)
				{
					Edge vdEdge;
					vdEdge.startVertexId = VDvertex.size() - 2;
					vdEdge.endVertexId = VDvertex.size() - 1;
					VDedge.push_back( vdEdge );
					std::cerr<<"Edge "<<std::endl;	
		
				// end record the VDedge
				}
				}
				// save now's tetra for preious
			

				// choose neighbor tetra which contain edge e
				Tetrahedron t1, t2, t3, t4;
				if( getTetra(currentTetra.neighbour1, t1) == false )
				{
			//		std::cerr<<"no neighborRRR"<<std::endl;
					
				}
				if( getTetra(currentTetra.neighbour2, t2) == false )
				{
	//				std::cerr<<"no neighbor2"<<std::endl;
					
				}
				if( getTetra(currentTetra.neighbour3, t3) == false )
				{
		//			std::cerr<<"no neighbor3"<<std::endl;
					
				}
				if( getTetra(currentTetra.neighbour4, t4) == false )
				{
		//			std::cerr<<"no neighbor4"<<std::endl;
					
				}

				
					// if tetra contains edge, and it is not the first tetra
					if ( checkEdge(t1, currentEdgeItr->startVertex, currentEdgeItr->endVertex)==true
						&& t1.key != previousTetraKey 
						&& t1.key != firstTetraKey
						){
								previousTetraKey = currentTetra.key;
						currentKey = t1.key;
						std::cerr<<"t1: "<<t1.key<<std::endl;
						std::cerr<<"currentKey - End - t1: "<< currentKey<<std::endl;	
								first_vertex_flag = 1;
						if(flag==4)
						{
							flag=4;
							cou=1;
						}
						else
							flag=1;
						break;
					}
					else if (checkEdge(t2, currentEdgeItr->startVertex, currentEdgeItr->endVertex) ==true
						&& t2.key != previousTetraKey
						&& t2.key != firstTetraKey
						){
								previousTetraKey = currentTetra.key;
						currentKey = t2.key;
						std::cerr<<"t2: "<<t2.key<<std::endl;	
						std::cerr<<"currentKey - End - t2: "<< currentKey<<std::endl;	
								first_vertex_flag = 1;
						if(flag==4)
						{
							flag=4;
							cou=1;
						}
						else
							flag=1;
						break;
					}
					else if (checkEdge(t3, currentEdgeItr->startVertex, currentEdgeItr->endVertex) ==true
						&& t3.key != previousTetraKey 
						&& t3.key != firstTetraKey
						){
								previousTetraKey = currentTetra.key;
						currentKey = t3.key;
						std::cerr<<"t3: "<<t3.key<<std::endl;	
						std::cerr<<"currentKey - End - t3: "<< currentKey<<std::endl;	
						std::cerr<<"previoueKey - End "<< previousTetraKey<<std::endl;	
								first_vertex_flag = 1;
						if(flag==4)
						{
							flag=4;
							cou=1;
						}
						else
							flag=1;
						break;
					}
					else if ( checkEdge(t4, currentEdgeItr->startVertex, currentEdgeItr->endVertex)  ==true
						&& t4.key != previousTetraKey 
						&& t4.key != firstTetraKey
						){
								previousTetraKey = currentTetra.key;
						currentKey = t4.key;
						std::cerr<<"t4: "<<t4.key<<std::endl;	
						std::cerr<<"currentKey - End - t4: "<< currentKey<<std::endl;	
								first_vertex_flag = 1;
						if(flag==4)
						{
							flag=4;
							cou=1;
						}
						else
							flag=1;
						break;
					}
					else{
						hasNeighbor = false;
						std::cerr<<"hereherehere"<<std::endl;
						if(flag==4)
							still_has_edge=false;

						flag = 2;
						//break;
					}
		
			}// end while of find neighbor
		if(flag==2  )
		{
	
				// first vertex and last vertex
				Edge vdEdge;
				vdEdge.startVertexId = VDvertex.size() - 1;
				vdEdge.endVertexId = nowVertexId;
				VDedge.push_back( vdEdge );
				first_vertex_flag = 0;
				std::cerr<<"First and Last Vertex"<<std::endl;	
		}
		if(flag==2 )
		{
				// this is a VDface
				for(int i=vdEdgeTag; i<VDedge.size(); i++)
				{
					VDface.push_back( i );
					std::cerr<<"Face: "<<VDedge.size()<<std::endl;	
				}

				vdEdgeTag = VDedge.size();
		//		if(vdEdgeTag!=0)
					VDfaceIndex.push_back( vdEdgeTag);
				// end of VDface
					flag = 3;
					
			}

		std::cerr<<"still_has_edge: "<<still_has_edge<<std::endl;	
		}//end while edge set
	


		//this is a VDpoly
	/*	for(int i=vdFaceTag; i<VDface.size(); i++)
		{
			VDpoly.push_back( i );
			std::cerr<<"Poly"<<std::endl;	
		}
		*/
		vdFaceTag = VDfaceIndex.size();
	//	if(vdFaceTag!=0)
			VDpolyIndex.push_back( vdFaceTag-1 );
		//end if VDpoly

		// erase the vertex
		vertexSet.erase( checkVertex );

		usedEdgeSet.clear();
		edgeSet.clear();
		flag=0;

	}//end while of vertex stk
		
	std::cerr<<"v1x: "<<VDvertex.at(0).point.x<<std::endl;
	std::cerr<<"v1x: "<<VDvertex.at(0).point.y<<std::endl;
	std::cerr<<"v1x: "<<VDvertex.at(0).point.z<<std::endl;

	std::cerr<<"v2x: "<<VDvertex.at(1).point.x<<std::endl;
	std::cerr<<"v2x: "<<VDvertex.at(1).point.y<<std::endl;
	std::cerr<<"v2x: "<<VDvertex.at(1).point.z<<std::endl;


	std::cerr<<"v3x: "<<VDvertex.at(2).point.x<<std::endl;
	std::cerr<<"v3x: "<<VDvertex.at(2).point.y<<std::endl;
	std::cerr<<"v3x: "<<VDvertex.at(2).point.z<<std::endl;


	std::cerr<<"v4x: "<<VDvertex.at(3).point.x<<std::endl;
	std::cerr<<"v4x: "<<VDvertex.at(3).point.y<<std::endl;
	std::cerr<<"v4x: "<<VDvertex.at(3).point.z<<std::endl;

	std::cerr<<"v5x: "<<VDvertex.at(4).point.x<<std::endl;
	std::cerr<<"v5x: "<<VDvertex.at(4).point.y<<std::endl;
	std::cerr<<"v5x: "<<VDvertex.at(4).point.z<<std::endl;

	std::cerr<<"v6x: "<<VDvertex.at(5).point.x<<std::endl;
	std::cerr<<"v6x: "<<VDvertex.at(5).point.y<<std::endl;
	std::cerr<<"v6x: "<<VDvertex.at(5).point.z<<std::endl;

	std::cerr<<"v7x: "<<VDvertex.at(6).point.x<<std::endl;
	std::cerr<<"v7x: "<<VDvertex.at(6).point.y<<std::endl;
	std::cerr<<"v7x: "<<VDvertex.at(6).point.z<<std::endl;

	std::cerr<<"v8x: "<<VDvertex.at(7).point.x<<std::endl;
	std::cerr<<"v8x: "<<VDvertex.at(7).point.y<<std::endl;
	std::cerr<<"v8x: "<<VDvertex.at(7).point.z<<std::endl;

	std::cerr<<"v9x: "<<VDvertex.at(8).point.x<<std::endl;
	std::cerr<<"v9x: "<<VDvertex.at(8).point.y<<std::endl;
	std::cerr<<"v9x: "<<VDvertex.at(8).point.z<<std::endl;

	std::cerr<<"v10x: "<<VDvertex.at(9).point.x<<std::endl;
	std::cerr<<"v10x: "<<VDvertex.at(9).point.y<<std::endl;
	std::cerr<<"v10x: "<<VDvertex.at(9).point.z<<std::endl;

	std::cerr<<"v11x: "<<VDvertex.at(10).point.x<<std::endl;
	std::cerr<<"v11x: "<<VDvertex.at(10).point.y<<std::endl;
	std::cerr<<"v11x: "<<VDvertex.at(10).point.z<<std::endl;

	std::cerr<<"v12x: "<<VDvertex.at(11).point.x<<std::endl;
	std::cerr<<"v12x: "<<VDvertex.at(11).point.y<<std::endl;
	std::cerr<<"v12x: "<<VDvertex.at(11).point.z<<std::endl;

	std::cerr<<"e1: "<<VDedge.at(0).startVertexId<<std::endl;
	std::cerr<<"e1: "<<VDedge.at(0).endVertexId<<std::endl;


		std::cerr<<"e2: "<<VDedge.at(1).startVertexId<<std::endl;
	std::cerr<<"e2: "<<VDedge.at(1).endVertexId<<std::endl;

		std::cerr<<"e3: "<<VDedge.at(2).startVertexId<<std::endl;
	std::cerr<<"e3: "<<VDedge.at(2).endVertexId<<std::endl;

		std::cerr<<"e4: "<<VDedge.at(3).startVertexId<<std::endl;
	std::cerr<<"e4: "<<VDedge.at(3).endVertexId<<std::endl;

		std::cerr<<"e5: "<<VDedge.at(4).startVertexId<<std::endl;
	std::cerr<<"e5: "<<VDedge.at(4).endVertexId<<std::endl;

		std::cerr<<"e6: "<<VDedge.at(5).startVertexId<<std::endl;
	std::cerr<<"e6: "<<VDedge.at(5).endVertexId<<std::endl;

	std::cerr<<"face1 "<<VDfaceIndex.at(0)<<std::endl;
	std::cerr<<"face2: "<<VDfaceIndex.at(1)<<std::endl;
	std::cerr<<"face3: "<<VDfaceIndex.at(2)<<std::endl;
	std::cerr<<"face4: "<<VDfaceIndex.at(3)<<std::endl;
		std::cerr<<"face5: "<<VDfaceIndex.at(4)<<std::endl;

	
			std::cerr<<"poly1 "<<VDpolyIndex.at(0)<<std::endl;
	std::cerr<<"poly2: "<<VDpolyIndex.at(1)<<std::endl;

	return;
}