Ejemplo n.º 1
0
void intersect( SurfPatch& bp1, SurfPatch& bp2, int depth )
{
    int MAX_SUB = 3;
    if ( !Compare( *bp1.get_bbox(), *bp2.get_bbox() ) )
    {
        return;
    }

    SurfPatch bps1[4];
    SurfPatch bps2[4];

    //if ( bp1.bnd_box.diag_dist() < 0.1 )
    //  bp1.SetSubDepth( MAX_SUB + 1 );

    //if ( bp2.bnd_box.diag_dist() < 0.1 )
    //  bp2.SetSubDepth( MAX_SUB + 1 );

    if ( bp1.GetSubDepth() > MAX_SUB && bp2.GetSubDepth() > MAX_SUB )
    {
        intersect_quads( bp1, bp2 );          // Plane - Plane Intersection
    }
    else
    {
        if ( bp1.GetSubDepth() < bp2.GetSubDepth() )
        {
            bp1.split_patch( bps1[0], bps1[1], bps1[2], bps1[3] );      // Split Patch1 and Keep Subdividing
            for ( int i = 0 ; i < 4 ; i++ )
            {
                bps1[i].SetSubDepth( bp1.GetSubDepth() + 1 );
            }

            intersect( bps1[0], bp2, depth );
            intersect( bps1[1], bp2, depth );
            intersect( bps1[2], bp2, depth );
            intersect( bps1[3], bp2, depth );
        }
        else
        {
            bp2.split_patch( bps2[0], bps2[1], bps2[2], bps2[3] );      // Split Patch2 and Keep Subdividing
            for ( int i = 0 ; i < 4 ; i++ )
            {
                bps2[i].SetSubDepth( bp2.GetSubDepth() + 1 );
            }

            intersect( bp1, bps2[0], depth );
            intersect( bp1, bps2[1], depth );
            intersect( bp1, bps2[2], depth );
            intersect( bp1, bps2[3], depth );
        }
    }
}
Ejemplo n.º 2
0
void Surf::LoadControlPnts( vector< vector< vec3d > > & control_pnts )
{
	int i, j;
	assert( control_pnts.size() >= 4 );
	assert( control_pnts[0].size() >= 4);
	m_Pnts = control_pnts;

	m_NumU = m_Pnts.size();
	m_NumW = m_Pnts[0].size();
	m_MaxU = (m_NumU-1)/3;
	m_MaxW = (m_NumW-1)/3;

	//==== Load Patch Vec ====//
	m_BBox.init();
	for ( i = 0 ; i < (int)m_PatchVec.size() ; i++ )
		delete m_PatchVec[i];
	m_PatchVec.clear();

	for ( i = 0 ; i < m_NumU-1 ; i+=3 )
	{
		for ( j = 0 ; j < m_NumW-1 ; j+=3 )
		{
			SurfPatch* patch = new SurfPatch();
			for ( int pi = 0 ; pi < 4 ; pi++ )
				for ( int pj = 0 ; pj < 4 ; pj++ )
				{
					m_BBox.update( m_Pnts[pi+i][pj+j] );
					patch->put_pnt( pi, pj, m_Pnts[pi+i][pj+j] );

					patch->set_u_min_max( i/3, i/3 + 1.0 );
					patch->set_w_min_max( j/3, j/3 + 1.0 );
				}
			patch->set_surf_ptr( this );
			patch->compute_bnd_box();
			m_PatchVec.push_back( patch );
		}
	}
}
Ejemplo n.º 3
0
void SurfCore::BuildPatches( Surf* srf ) const
{
    vector< SurfPatch* > patchVec = srf->GetPatchVec();

    for ( int i = 0 ; i < ( int )patchVec.size() ; i++ )
    {
        delete patchVec[i];
    }
    patchVec.clear();

    for ( int ip = 0; ip < m_Surface.number_u_patches(); ip++ )
    {
        for ( int jp = 0; jp < m_Surface.number_v_patches(); jp++ )
        {
            double umin, du, vmin, dv;
            const surface_patch_type *epatch = m_Surface.get_patch( ip, jp, umin, du, vmin, dv );

            SurfPatch* patch = new SurfPatch();

            patch->setPatch( *epatch );

            patch->set_u_min_max( umin, umin + du );
            patch->set_w_min_max( vmin, vmin + dv );

            patch->set_surf_ptr( srf );
            patch->compute_bnd_box();

            patchVec.push_back( patch );
        }
    }

    surface_bounding_box_type bbox;
    m_Surface.get_bounding_box( bbox );
    srf->SetBBox( bbox.get_max(), bbox.get_min() );
    srf->SetPatchVec( patchVec );
}