Exemplo n.º 1
0
////////////////////////////////////////////////////////////////////////////////////////
// RemoveSmallStrips()
//
// allStrips is the whole strip _vector_...all small strips will be deleted from this list, to avoid leaking mem
// allBigStrips is an out parameter which will contain all strips above minStripLength
// faceList is an out parameter which will contain all faces which were removed from the striplist
//
void NvStripifier::RemoveSmallStrips(NvStripInfoVec& allStrips, NvStripInfoVec& allBigStrips, NvFaceInfoVec& faceList)
{
	faceList.clear();
	allBigStrips.clear();  //make sure these are empty
	NvFaceInfoVec tempFaceList;
	
	for(int i = 0; i < allStrips.size(); i++)
	{
		if(allStrips[i]->m_faces.size() < minStripLength)
		{
			//strip is too small, add faces to faceList
			for(int j = 0; j < allStrips[i]->m_faces.size(); j++)
				tempFaceList.push_back(allStrips[i]->m_faces[j]);
			
			//and xr_free memory
			xr_delete(allStrips[i]);
		}
		else
		{
			allBigStrips.push_back(allStrips[i]);
		}
	}
	
	bool *bVisitedList	= xr_alloc<bool> (tempFaceList.size());
	ZeroMemory			(bVisitedList, tempFaceList.size()*sizeof(bool));
	
	VertexCache* vcache = xr_new<VertexCache> (cacheSize);
	
	int bestNumHits = -1;
	int numHits		= 0;
	int bestIndex	= 0;
	
	while(1)
	{
		bestNumHits = -1;
		
		//find best face to add next, given the current cache
		for(int i = 0; i < tempFaceList.size(); i++)
		{
			if(bVisitedList[i])
				continue;
			
			numHits = CalcNumHitsFace(vcache, tempFaceList[i]);
			if(numHits > bestNumHits)
			{
				bestNumHits = numHits;
				bestIndex = i;
			}
		}
		
		if(bestNumHits == -1.0f)
			break;
		bVisitedList[bestIndex] = true;
		UpdateCacheFace(vcache, tempFaceList[bestIndex]);
		faceList.push_back(tempFaceList[bestIndex]);
	}
	
	xr_delete	(vcache);
	xr_free		(bVisitedList);
}
////////////////////////////////////////////////////////////////////////////////////////
// RemoveSmallStrips()
//
// allStrips is the whole strip vector...all small strips will be deleted from this list, to avoid leaking mem
// allBigStrips is an out parameter which will contain all strips above minStripLength
// faceList is an out parameter which will contain all faces which were removed from the striplist
//
void NvStripifier::RemoveSmallStrips(NvStripInfoVec& allStrips, NvStripInfoVec& allBigStrips, NvFaceInfoVec& faceList)
{
	faceList.clear();
	allBigStrips.clear();  //make sure these are empty
	NvFaceInfoVec tempFaceList;
	
	for(size_t i = 0; i < allStrips.size(); i++)
	{
		if(allStrips[i]->m_faces.size() < (size_t)minStripLength)
		{
			//strip is too small, add faces to faceList
			for(size_t j = 0; j < allStrips[i]->m_faces.size(); j++)
				tempFaceList.push_back(allStrips[i]->m_faces[j]);
			
			//and free memory
			delete allStrips[i];
		}
		else
		{
			allBigStrips.push_back(allStrips[i]);
		}
	}
	
	if(tempFaceList.size())
	{
		bool *bVisitedList = new bool[tempFaceList.size()];
		memset(bVisitedList, 0, tempFaceList.size()*sizeof(bool));
		
		VertexCache* vcache = new VertexCache(cacheSize);
		
		int bestNumHits = -1;
		int numHits;
		int bestIndex;
		
		while(1)
		{
			bestNumHits = -1;
			
			//find best face to add next, given the current cache
			for(size_t i = 0; i < tempFaceList.size(); i++)
			{
				if(bVisitedList[i])
					continue;
				
				numHits = CalcNumHitsFace(vcache, tempFaceList[i]);
				if(numHits > bestNumHits)
				{
					bestNumHits = numHits;
					bestIndex = i;
				}
			}
			
			if(bestNumHits == -1.0f)
				break;
			bVisitedList[bestIndex] = true;
			UpdateCacheFace(vcache, tempFaceList[bestIndex]);
			faceList.push_back(tempFaceList[bestIndex]);
		}
		
		delete vcache;
		delete[] bVisitedList;
	}
}