Changeset 538

Show
Ignore:
Timestamp:
03/05/08 17:28:58 (10 months ago)
Author:
phill
Message:

o Greedy split.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42make/modelbuilder-batch.cpp

    r537 r538  
    5656        void append_index( index src_idx ); 
    5757 
     58        size_t vertex_count() const { return dst_to_src_vert_map.size(); } 
     59 
    5860private: 
    5961        group_split_context *owner; 
     
    9294 
    9395        void split_by_weight_count(); 
     96        void greedy_split( size_t max_verts, size_t max_prims, size_t max_influences ); 
     97        void topological_split( size_t max_verts, size_t max_prims, size_t max_influences ); 
     98 
    9499        void cost_ordered_merge( size_t max_verts, float up_merge_limit_factor ); 
    95100 
     
    453458} 
    454459 
     460void group_split_context::greedy_split( size_t max_verts, 
     461        size_t max_prims, size_t max_influences ) 
     462{ 
     463        for( size_t i_prim = 0; i_prim < prim_count; i_prim++ ) 
     464        { 
     465                //find the best group to add this triangle to 
     466                 
     467                group_split_target_ptr target; 
     468                size_t target_vert_cost, target_inf_cost; 
     469 
     470                for( size_t j = 0; j < target_groups.size(); j++ ) 
     471                { 
     472                        group_split_target_ptr candidate = target_groups[j]; 
     473                         
     474                        //see if this candidate even has room for the insert 
     475                        if( candidate->prim_count + 1 > max_prims ) 
     476                                continue; 
     477 
     478                        size_t vert_cost, inf_cost; 
     479                        candidate->compute_append_prim_cost( i_prim, vert_cost, inf_cost ); 
     480 
     481                        if( candidate->vertex_count() + vert_cost > max_verts ) 
     482                                continue; 
     483                        if( candidate->influences.size() + inf_cost > max_influences ) 
     484                                continue; 
     485 
     486                        //it's OK to add to this group, see if it's the best one 
     487                        if( !target || inf_cost < target_inf_cost || 
     488                                (inf_cost == target_inf_cost && vert_cost < target_vert_cost ) ) 
     489                        { 
     490                                target = candidate; 
     491                                target_vert_cost = vert_cost; 
     492                                target_inf_cost = inf_cost; 
     493                        } 
     494                } 
     495 
     496                if( !target ) 
     497                        target = create_target(); 
     498 
     499                target->append_prim( i_prim ); 
     500        } 
     501} 
     502 
     503void group_split_context::topological_split( size_t max_verts, 
     504        size_t max_prims, size_t max_influences ) 
     505{ 
     506        if( elems_per_prim != 3 ) 
     507                throw error( "Topological split only works on triangles." ); 
     508 
     509 
     510} 
     511 
    455512group_split_target_ptr group_split_context::internal_merge_groups( 
    456513        group_split_target_ptr a, group_split_target_ptr b )