Changeset 539

Show
Ignore:
Timestamp:
03/05/08 18:00:56 (10 months ago)
Author:
phill
Message:

o Adjacency.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42make/libx42make.vcproj

    r523 r539  
    529529                </Filter> 
    530530                <Filter 
    531                         Name="batcher" 
    532                         > 
    533                         <File 
    534                                 RelativePath=".\adjacency.cpp" 
    535                                 > 
    536                         </File> 
    537                         <File 
    538                                 RelativePath=".\batcher.h" 
    539                                 > 
    540                         </File> 
    541                         <File 
    542                                 RelativePath=".\topology-split.cpp" 
    543                                 > 
    544                         </File> 
    545                         <File 
    546                                 RelativePath=".\topology.cpp" 
     531                        Name="modelbuilder" 
     532                        > 
     533                        <File 
     534                                RelativePath=".\modelbuilder-animation.cpp" 
     535                                > 
     536                        </File> 
     537                        <File 
     538                                RelativePath=".\modelbuilder-batch.cpp" 
     539                                > 
     540                        </File> 
     541                        <File 
     542                                RelativePath=".\modelbuilder-cull.cpp" 
     543                                > 
     544                        </File> 
     545                        <File 
     546                                RelativePath=".\modelbuilder-enumerators.cpp" 
     547                                > 
     548                        </File> 
     549                        <File 
     550                                RelativePath=".\modelbuilder-geometry.cpp" 
     551                                > 
     552                        </File> 
     553                        <File 
     554                                RelativePath=".\modelbuilder-influences.cpp" 
     555                                > 
     556                        </File> 
     557                        <File 
     558                                RelativePath=".\modelbuilder-skeleton.cpp" 
     559                                > 
     560                        </File> 
     561                        <File 
     562                                RelativePath=".\modelbuilder-write.cpp" 
     563                                > 
     564                        </File> 
     565                        <File 
     566                                RelativePath=".\modelbuilder.cpp" 
    547567                                > 
    548568                        </File> 
     
    579599                                > 
    580600                        </File> 
     601                        <Filter 
     602                                Name="batcher" 
     603                                > 
     604                                <File 
     605                                        RelativePath=".\adjacency.cpp" 
     606                                        > 
     607                                </File> 
     608                                <File 
     609                                        RelativePath=".\batcher.h" 
     610                                        > 
     611                                </File> 
     612                                <File 
     613                                        RelativePath=".\topology-split.cpp" 
     614                                        > 
     615                                </File> 
     616                                <File 
     617                                        RelativePath=".\topology.cpp" 
     618                                        > 
     619                                </File> 
     620                        </Filter> 
    581621                </Filter> 
    582622                <File 
     
    656696                        </FileConfiguration> 
    657697                </File> 
    658                 <File 
    659                         RelativePath=".\modelbuilder-animation.cpp" 
    660                         > 
    661                 </File> 
    662                 <File 
    663                         RelativePath=".\modelbuilder-batch.cpp" 
    664                         > 
    665                 </File> 
    666                 <File 
    667                         RelativePath=".\modelbuilder-cull.cpp" 
    668                         > 
    669                 </File> 
    670                 <File 
    671                         RelativePath=".\modelbuilder-enumerators.cpp" 
    672                         > 
    673                 </File> 
    674                 <File 
    675                         RelativePath=".\modelbuilder-geometry.cpp" 
    676                         > 
    677                 </File> 
    678                 <File 
    679                         RelativePath=".\modelbuilder-influences.cpp" 
    680                         > 
    681                 </File> 
    682                 <File 
    683                         RelativePath=".\modelbuilder-skeleton.cpp" 
    684                         > 
    685                 </File> 
    686                 <File 
    687                         RelativePath=".\modelbuilder-write.cpp" 
    688                         > 
    689                 </File> 
    690                 <File 
    691                         RelativePath=".\modelbuilder.cpp" 
    692                         > 
    693                 </File> 
    694698        </Files> 
    695699        <Globals> 
  • branches/morph-targets/libx42make/modelbuilder-batch.cpp

    r538 r539  
    9595        void split_by_weight_count(); 
    9696        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 ); 
     97        void topological_split_from_root( size_t max_verts, size_t max_prims, size_t max_influences ); 
     98        void topological_split_from_leaves( size_t max_verts, size_t max_prims, size_t max_influences ); 
    9899 
    99100        void cost_ordered_merge( size_t max_verts, float up_merge_limit_factor ); 
     
    101102private: 
    102103        group_split_target_ptr internal_merge_groups( group_split_target_ptr a, group_split_target_ptr b ); 
     104}; 
     105 
     106class adjacency 
     107{ 
     108public: 
     109        adjacency() 
     110        { 
     111        } 
     112 
     113        void initialize( const std::vector< index > &tris ); 
     114 
     115        size_t adj_len( size_t tri_idx ) const { return entries[tri_idx].len; } 
     116        size_t adj_idx( size_t tri_idx, size_t adj_idx ) const { return values[entries[tri_idx].beg + adj_idx]; } 
     117 
     118private: 
     119        struct adj_entry 
     120        { 
     121                size_t beg; 
     122                size_t len; 
     123        }; 
     124 
     125        std::vector< adj_entry > entries; 
     126        std::vector< size_t > values; 
    103127}; 
    104128 
     
    245269 
    246270        return ret; 
     271} 
     272 
     273/* 
     274        class adjacency 
     275*/ 
     276 
     277void adjacency::initialize( const std::vector< index > &tris ) 
     278{ 
     279        entries.resize( tris.size() / 3 ); 
     280 
     281        values.clear(); 
     282        values.reserve( tris.size() ); 
     283 
     284        //for each triangle 
     285        for( uint t = 0; t < entries.size(); t++ ) 
     286        { 
     287                entries[t].beg = (uint)values.size(); 
     288 
     289                //skip degenerates 
     290                if( tris[t * 3 + 0] == tris[t * 3 + 1] || 
     291                        tris[t * 3 + 1] == tris[t * 3 + 2] || 
     292                        tris[t * 3 + 2] == tris[t * 3 + 0] ) 
     293                        continue; 
     294 
     295                //for each edge 
     296                for( uint e = 0; e < 3; e++ ) 
     297                { 
     298                        uint es = tris[t * 3 + e]; 
     299                        uint ee = tris[t * 3 + ((e + 1) % 3)]; 
     300 
     301                        //for each other triangle 
     302                        for( uint ot = 0; ot < entries.size(); ot++ ) 
     303                        { 
     304                                if( ot == t ) 
     305                                        continue; 
     306 
     307                                //skip degenerates 
     308                                if( tris[ot * 3 + 0] == tris[ot * 3 + 1] || 
     309                                        tris[ot * 3 + 1] == tris[ot * 3 + 2] || 
     310                                        tris[ot * 3 + 2] == tris[ot * 3 + 0] ) 
     311                                        continue; 
     312 
     313                                //for each other edge 
     314                                for( uint oe = 0; oe < 3; oe++ ) 
     315                                { 
     316                                        uint oes = tris[ot * 3 + oe]; 
     317                                        uint oee = tris[ot * 3 + ((oe + 1) % 3)]; 
     318 
     319                                        if( es == oee && ee == oes ) 
     320                                                values.push_back( ot ); 
     321                                } 
     322                        } 
     323                } 
     324 
     325                entries[t].len = (uint)values.size() - entries[t].beg; 
     326        } 
    247327} 
    248328 
     
    429509void group_split_context::split_by_weight_count() 
    430510{ 
    431         if( target_groups.size() ) 
    432                 throw error(); 
     511        target_groups.clear(); 
    433512 
    434513        for( size_t i = 0; i < vertex_weights::max_weights; i++ ) 
     
    461540        size_t max_prims, size_t max_influences ) 
    462541{ 
     542        target_groups.clear(); 
     543 
    463544        for( size_t i_prim = 0; i_prim < prim_count; i_prim++ ) 
    464545        { 
     
    501582} 
    502583 
    503 void group_split_context::topological_split( size_t max_verts, 
     584void group_split_context::topological_split_from_leaves( size_t max_verts, 
     585        size_t max_prims, size_t max_influences ) 
     586
     587        if( elems_per_prim != 3 ) 
     588                throw error( "Topological split only works on triangles." ); 
     589 
     590 
     591
     592 
     593void group_split_context::topological_split_from_root( size_t max_verts, 
    504594        size_t max_prims, size_t max_influences ) 
    505595{