예제 #1
0
bool SToplex<C,PS,BT>::buildTopSimpMap (const vector<Simplex<C,PS,BT>*>& topsimps, bool makeverlist = true)
{
    verlist.clear();
	//cout<<" top simp size "<<topsimps.size(); cin.get();
	if (topsimps.size()==0 || topsimps.front()==NULL) return false;  // no simplices to add

	num topd;

	Simplex<C,PS,BT>* cursimp;

	set<Point<PS>*, ptcomplex<PS> > vertices; // store all vertices
	typename PT_SET::const_iterator viter; //

	// iterate over top simplices and extract vertices:
	typename vector<Simplex<C,PS,BT>*>::const_iterator curtop;
	for (curtop = topsimps.begin(); curtop != topsimps.end(); ++curtop)
	{
		cursimp = *curtop;
		topd = cursimp->getDim(); // get top simplex's dimension
		// update top dim of toplex!
		if (topd > topdim) topdim = topd;

		// now extract vertices!
		for (viter = cursimp->begin(); viter != cursimp->end(); ++viter)
		{
			vertices.insert(*viter);
		}
		if (makeverlist) verlist.insert(vertices.begin(),vertices.end());
	}

    if (SIMTOPTALK)
    {
        cout<<"\n built vertex list";
        if (MAKEBPS) cin.get();
    }

	// set number of distinct vertices:
	psize = vertices.size();

	typename SIMP_MAP::iterator mit;
	SIMP_RG* currg;
	num hmod = getHashMod();

	// now we can compute the hashes using topdim and psize, and hence
	// store the top simplices. sweep over them again...
	for (curtop = topsimps.begin(); curtop != topsimps.end(); ++curtop)
	{
		cursimp = *curtop;
		mit = mymap.find(cursimp->getDim()); // seek this hash
		if(mit == mymap.end()) // not found!
		{
			currg = new SIMP_RG; // define range, and...
			mymap.insert(mymap.end(),make_pair(cursimp->getDim(),currg));
		}
		else currg = mit->second;
		currg->insert(currg->end(),make_pair(cursimp->getHash(hmod),cursimp));
	}

    if (SIMTOPTALK)
    {
        cout<<"\n top map size: "<<mymap.size();
        if (MAKEBPS) cin.get();
    }
	//cout<<" top map size: "<<mymap.size(); cin.get();
	return true;
}
예제 #2
0
bool SToplex<C,PS,BT>::makeFacesOf(Simplex<C,PS,BT>* simp, bool inheritBirths = true)
{
	if (simp == NULL) return false; // can't handle null simplex
	if (simp->getDim()==0) return true; // no faces for 0 dimensional/already faced simplices!

	PT_SET verts = simp->getVerts(); // boundary vertex set
	typename PT_SET::iterator hat; // points to vertex which is being ignored when making face
	C coeff; // coefficient of this face
	num facect = 0;


	typename SIMP_MAP::iterator finddim;
	typename SIMP_RG::iterator findhash;
	SIMP_RG* currg;

	Simplex<C,PS,BT>* sloc; // face simplex possibly located in complex

	// iterate over vertices of this simplex.
	for (hat = simp->begin(); hat != simp->end(); ++hat)
	{
		verts.erase(*hat); // hat out this vertex
		coeff = (facect % 2 == 0) ? 1 : -1; // and its incidence coefficient

		// now check if current bdry simplex is in its anchor list
		//cout<<"isin call: "; cin.get();
		sloc = isIn(verts); // check if face is in corresponding list
		//cout<<" back with "<<sloc; cin.get();


		if (sloc == NULL) // no such face exists
		{
			// so add this new simplex to the map structure
			sloc = new Simplex<C,PS,BT>(verts);
			//cout<<"\n    attempting insertion of: "<<*sloc; cin.get();
			// it is possible that there  tDim());
			finddim = mymap.find(sloc->getDim());
			if (finddim == mymap.end())
			{
				currg = new SIMP_RG;
				mymap.insert(mymap.end(),make_pair(sloc->getDim(),currg));
				//cout<<"inserted!"; cin.get();
			}
			else
			{
				currg = finddim->second;
			}
			//cout<<"range insert!"; cin.get();

			currg->insert(make_pair(sloc->getHash(getHashMod()),sloc));
			//cout<<"\n     added: "<<*bdsimp<<" to "<<*firstbdvert<<" of dim "<<curd-1<<" at "<<bdsimp;
		}
		simp->addBDLink(sloc,coeff,true,inheritBirths);
		facect++; // update number of faces handled
		//cout<<"\n^^^^^^^^^^^^^^^^^added face: "<<*sloc; cin.get();
		// restore boundary for next face, idiot:
		verts.insert(*hat);
	}

//	// now make faces of faces etc...
//	typename list<Simplex<C,PS,BT>*>::const_iterator face;
//	for (face = facelist.begin(); face != facelist.end(); ++face)
//	{
//		makeFacesOf(*face); // recursive call
//	}
	return true;
}