Ejemplo n.º 1
0
void ConvexHull::CConvexHull::_remove_upper_tets()
{
	ConvexHull::CVertex v(-1);
	v.point() = ConvexHull::CPoint4(0,0,0, 1e+20);
	_visibility( &v );

	//remove visible tets
	std::vector<ConvexHull::CTet*> visible_tets;
	for( std::set<ConvexHull::CTet*>::iterator iter = m_tets.begin(); iter != m_tets.end(); iter ++ )
	{	
		ConvexHull::CTet * pT = *iter;
		if( pT->visible() ) visible_tets.push_back( pT );
	}

	std::vector<ConvexHull::CFace*> visible_faces;

	for( std::set<ConvexHull::CFace*>::iterator iter = m_faces.begin(); iter != m_faces.end(); iter ++ )
	{
		CFace * pF = *iter;
		
		CTet  * pT = pF->tets(0);
		CTet  * pW = pF->tets(1);
		
		if(   pT->visible() &&  pW->visible() )  visible_faces.push_back( pF );
	}



	for( size_t i = 0; i < visible_tets.size(); i ++ )
	{
		ConvexHull::CTet * pT = visible_tets[i];
		std::set<ConvexHull::CTet*>::iterator iter = std::find( m_tets.begin(), m_tets.end(), pT );
		assert( iter != m_tets.end() );
		m_tets.erase( iter );
		m_tet_pool.delocate( pT );
	}

	//remove visible faces
	for( size_t i = 0; i < visible_faces.size(); i ++ )
	{
		ConvexHull::CFace * pF = visible_faces[i];
		std::set<ConvexHull::CFace*>::iterator iter = std::find( m_faces.begin(), m_faces.end(), pF );
		m_faces.erase( iter );
		ConvexHull::CVertex * pV = pF->min_vert();
		pV->remove( pF );
		m_face_pool.delocate( pF );
	}
}
Ejemplo n.º 2
0
void ConvexHull::CConvexHull::_insert_one_vertex( CVertex * pV )
{

	//test the visibility of each tetrahedron
	_visibility( pV );


	std::vector<ConvexHull::CFace*> visible_faces;
	std::vector<ConvexHull::CFace*> silhoutte_faces;
	std::set<ConvexHull::CFace*>   invisible_faces;

	for( std::set<CFace*>::iterator iter = m_faces.begin(); iter != m_faces.end(); iter ++ )
	{
		CFace * pF = *iter;
		
		CTet  * pT = pF->tets(0);
		CTet  * pW = pF->tets(1);
		
		if(   pT->visible() &&  pW->visible() )  visible_faces.push_back( pF );
		else
		{
			invisible_faces.insert( pF );
		}
		if( ( pT->visible() && !pW->visible() ) || (!pT->visible() &&  pW->visible()) )  silhoutte_faces.push_back( pF );
	}

	m_faces.clear();
	m_faces = invisible_faces;

	//generate new tets
	std::vector<ConvexHull::CTet*> new_tets;

	//Silhoutte face
	for( size_t i = 0; i < silhoutte_faces.size(); i ++ )
	{
		CFace * pF = silhoutte_faces[i];

		if( pF->tets(0)->visible() )
		{
			CTet * pTet = m_tet_pool.allocate();

			(*pTet)[0] = pV;
			(*pTet)[1] = (*pF)[0];
			(*pTet)[2] = (*pF)[1];
			(*pTet)[3] = (*pF)[2];
				
			pF->tets(0) = pTet;
			m_tets.insert( pTet );
			new_tets.push_back( pTet );
		}
		else //pF->tets()[1]->visible()
		{
			CTet * pTet = m_tet_pool.allocate();

			(*pTet)[0] = pV;
			(*pTet)[1] = (*pF)[1];
			(*pTet)[2] = (*pF)[0];
			(*pTet)[3] = (*pF)[2];

			pF->tets(1) = pTet;
			m_tets.insert( pTet );
			new_tets.push_back( pTet );
		}
	}

	//generate new faces

	for( size_t i = 0; i < new_tets.size(); i ++ )
	{
		ConvexHull::CTet * pT = new_tets[i];
		std::set<ConvexHull::CFace*> fs;
		boundary( *pT, fs );

		for( std::set<ConvexHull::CFace*>::iterator iter=fs.begin(); iter != fs.end(); iter ++ )
		{
			ConvexHull::CFace   * pF = *iter;
			ConvexHull::CVertex * pV = pF->min_vert();
			ConvexHull::CFace   * pD = pV->find( pF );

			if( pD != NULL )
			{
				int id = consistent( pD,pF );
				switch( id )
				{
				case +1:
					pD->tets(0) = pT;
					break;
				case -1:
					pD->tets(1) = pT;
					break;
				}
				m_face_pool.delocate( pF );
			}
			else
			{
				pF->tets(0) = pT;
				pV->faces().push_back( pF );
				m_faces.insert( pF );
			}
		}
	}



	//remove visible faces
	for( size_t i = 0; i < visible_faces.size(); i ++ )
	{
		ConvexHull::CFace   * pF = visible_faces[i];
		ConvexHull::CVertex * pV = pF->min_vert();
		pV->remove( pF );
		m_face_pool.delocate( pF );
	}

};