//-*****************************************************************************
void accumXform( M44d &xf, IObject obj )
{
    if ( ISimpleXform::matches( obj.getMetaData() ) )
    {
        ISimpleXform x( obj, kWrapExisting );
        xf *= x.getSchema().getValue().getMatrix();
    }
    else if ( IXform::matches( obj.getMetaData() ) )
    {
        IXform x( obj, kWrapExisting );
        XformSample xs;
        x.getSchema().get( xs );
        xf *= xs.getMatrix();
    }
}
//-*****************************************************************************
Box3d getBounds( IObject iObj )
{
    Box3d bnds;
    bnds.makeEmpty();

    M44d xf = getFinalMatrix( iObj );

    if ( IPolyMesh::matches( iObj.getMetaData() ) )
    {
        IPolyMesh mesh( iObj, kWrapExisting );
        IPolyMeshSchema ms = mesh.getSchema();
        V3fArraySamplePtr positions = ms.getValue().getPositions();
        size_t numPoints = positions->size();

        for ( size_t i = 0 ; i < numPoints ; ++i )
        {
            bnds.extendBy( (*positions)[i] );
        }
    }
    else if ( ISubD::matches( iObj.getMetaData() ) )
    {
        ISubD mesh( iObj, kWrapExisting );
        ISubDSchema ms = mesh.getSchema();
        V3fArraySamplePtr positions = ms.getValue().getPositions();
        size_t numPoints = positions->size();

        for ( size_t i = 0 ; i < numPoints ; ++i )
        {
            bnds.extendBy( (*positions)[i] );
        }
    }

    bnds.extendBy( Imath::transform( bnds, xf ) );

    g_bounds.extendBy( bnds );

    return bnds;
}
//-*****************************************************************************
void visitObject( IObject iObj )
{
    std::string path = iObj.getFullName();

    const MetaData &md = iObj.getMetaData();

    if ( IPolyMeshSchema::matches( md ) || ISubDSchema::matches( md ) )
    {
        Box3d bnds = getBounds( iObj );
        std::cout << path << " " << bnds.min << " " << bnds.max << std::endl;
    }

    // now the child objects
    for ( size_t i = 0 ; i < iObj.getNumChildren() ; i++ )
    {
        visitObject( IObject( iObj, iObj.getChildHeader( i ).getName() ) );
    }
}
bool getNamedCamera( IObject iObjTop, const std::string &iName, ICamera &iCam )
{
	// Return true if found

	const Alembic::AbcGeom::MetaData &md = iObjTop.getMetaData();
	if ( (iObjTop.getName() == iName) && (ICamera::matches( md )) )
	{
		iCam = ICamera(iObjTop, kWrapExisting );
		return true;
	}

	// now the child objects
	for ( size_t i = 0 ; i < iObjTop.getNumChildren() ; i++ )
	{
		if (getNamedCamera(IObject( iObjTop, iObjTop.getChildHeader( i ).getName() ), iName, iCam ))
			return true;
	}

	return false;

}
//-*****************************************************************************
int pushName( IObject &iObj )
{
    Abc::MetaData md = iObj.getMetaData();
    if ( IPolyMesh::matches( md ) ||
         IPoints::matches( md ) ||
         ICurves::matches( md ) ||
         INuPatch::matches( md ) ||
         ISubD::matches( md )
       )
    {
        OBJECT_MAP.push_back( iObj.getFullName() );
        glPushName( OBJECT_MAP.size() );
        //std::cout << OBJECT_MAP.size()
        //          << "\t"
        //          << iObj.getFullName()
        //          << std::endl;
        return OBJECT_MAP.size();
    } else {
        return -1;
    }
}