コード例 #1
0
ファイル: printer.cpp プロジェクト: IshwarKulkarni/ToyTracer
// Recursively print the hierarchy starting from the root.
// If there is only one aggregate object, the hierarchy will
// only be one level deep (i.e. the children of the one
// aggregate).  However, if there are other aggregates nested 
// within the top one, the printer will print each nested
// aggregate with further indentation.
void printer::print_it( std::ostream &out, Object *root )
    {
    if( root == NULL ) return;
    if( root->PluginType() == aggregate_plugin )
        {
        Aggregate *agg = (Aggregate *)root;
        out << indent() << "begin " << root->MyName() << endl;
        indent_n += 4;
        agg->Begin();
        for( int n = 0;  ; n++ )
            {
            Object *obj = agg->GetChild();
            if( obj == NULL ) break;
            if( limit > 0 && n == limit )
                {
                // Indicate that the list has been truncated.
                out << indent() << "..." << endl;
                break;
                }
            else print_it( out, obj );
            }
        indent_n -= 4;
        out << indent() << "end" << endl;
        }
    else if( root->PluginType() == primitive_plugin )
        {
        out << indent() << root->MyName() << endl;
        }
    }
コード例 #2
0
ファイル: util.cpp プロジェクト: IshwarKulkarni/ToyTracer
// Count the number of objects (either just primitives, or both primitives
// and aggregates) contained in a scene graph.
int CountObjects( const Object *root, bool just_primitives )
    {
    if( root == NULL ) return 0;
    if( root->PluginType() != aggregate_plugin ) return 1;
    Aggregate *agg = (Aggregate *)root;
    agg->Begin();
    int count = ( just_primitives ? 0 : 1 );
    for(;;)
        {
        Object *obj = agg->GetChild();
        if( obj == NULL ) break;
        count += CountObjects( obj, just_primitives );
        }
    return count;
    }