Exemple #1
0
PrimitiveVariableMap Primitive::loadPrimitiveVariables( const IndexedIO *ioInterface, const IndexedIO::EntryID &name, const IndexedIO::EntryIDList &primVarNames )
{
    IECore::Object::LoadContextPtr context = new Object::LoadContext( ioInterface->subdirectory( name )->subdirectory( g_dataEntry ) );

    unsigned int v = m_ioVersion;
    ConstIndexedIOPtr container = context->container( Primitive::staticTypeName(), v );
    if ( !container )
    {
        throw Exception( "Could not find Primitive entry in the file!" );
    }
    ConstIndexedIOPtr ioVariables = container->subdirectory( g_variablesEntry );

    PrimitiveVariableMap variables;
    IndexedIO::EntryIDList::const_iterator it;
    for( it=primVarNames.begin(); it!=primVarNames.end(); it++ )
    {
        ConstIndexedIOPtr ioPrimVar = ioVariables->subdirectory( *it, IndexedIO::NullIfMissing );
        if ( !ioPrimVar )
        {
            continue;
        }
        int i;
        ioPrimVar->read( g_interpolationEntry, i );
        variables.insert(
            PrimitiveVariableMap::value_type( *it, PrimitiveVariable( (PrimitiveVariable::Interpolation)i, context->load<Data>( ioPrimVar.get(), g_dataEntry ) ) )
        );
    }

    return variables;
}
void CompoundDataBase::load( LoadContextPtr context )
{
	Data::load( context );
	unsigned int v = 0;
	ConstIndexedIOPtr container = nullptr;

	try
	{
		container = context->container( staticTypeName(), v );
	}
	catch( const IOException &e )
	{
		// probably a file with CORTEX_MAJOR_VERSION < 5, get the
		// data from CompoundData container instead.
		container = context->container( "CompoundData", v );
	}

	CompoundDataMap &m = writable();
	m.clear();
	container = container->subdirectory( g_membersEntry );

	IndexedIO::EntryIDList memberNames;
	container->entryIds( memberNames );
	IndexedIO::EntryIDList::const_iterator it;
	for( it=memberNames.begin(); it!=memberNames.end(); it++ )
	{
		m[*it] = context->load<Data>( container.get(), *it );
	}
}
Exemple #3
0
void Primitive::load( IECore::Object::LoadContextPtr context )
{
    unsigned int v = m_ioVersion;
    ConstIndexedIOPtr container = context->container( staticTypeName(), v );

    // we changed the inheritance hierarchy at io version 1
    if( v==0 )
    {
        Renderable::load( context );
    }
    else
    {
        VisibleRenderable::load( context );
    }

    ConstIndexedIOPtr ioVariables = container->subdirectory( g_variablesEntry );

    variables.clear();
    IndexedIO::EntryIDList names;
    ioVariables->entryIds( names, IndexedIO::Directory );
    IndexedIO::EntryIDList::const_iterator it;
    for( it=names.begin(); it!=names.end(); it++ )
    {
        ConstIndexedIOPtr ioPrimVar = ioVariables->subdirectory( *it );
        int i;
        ioPrimVar->read( g_interpolationEntry, i );
        variables.insert(
            PrimitiveVariableMap::value_type( *it, PrimitiveVariable( (PrimitiveVariable::Interpolation)i, context->load<Data>( ioPrimVar.get(), g_dataEntry ) ) )
        );
    }
}
Exemple #4
0
ObjectPtr Object::LoadContext::loadObjectOrReference( const IndexedIO *container, const IndexedIO::EntryID &name )
{
	IndexedIO::Entry e = container->entry( name );
	if( e.entryType()==IndexedIO::File )
	{
		IndexedIO::EntryIDList pathParts;
		if ( e.dataType() == IndexedIO::InternedStringArray )
		{
			pathParts.resize( e.arrayLength() );
			InternedString *p = &(pathParts[0]); 
			container->read( name, p, e.arrayLength() );
		}
		else 
		{
			// for backward compatibility...
			string path;
			container->read( name, path );
			typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
			// \todo: this would have trouble if the name of the object contains slashes...
			Tokenizer tokens(path, boost::char_separator<char>("/"));
			Tokenizer::iterator t = tokens.begin();

			for ( ; t != tokens.end(); t++ )
			{
				pathParts.push_back( *t );
			}
		}
		std::pair< LoadedObjectMap::iterator,bool > ret = m_loadedObjects->insert( std::pair<IndexedIO::EntryIDList, ObjectPtr>( pathParts, NULL ) );
		if ( ret.second )
		{
			// jump to the path..
			ConstIndexedIOPtr ioObject = m_ioInterface->directory( pathParts );
			// add the loaded object to the map.
			ret.first->second = loadObject( ioObject );
		}
		return ret.first->second;
	}
	else
	{
		ConstIndexedIOPtr ioObject = container->subdirectory( name );

		IndexedIO::EntryIDList pathParts;
		ioObject->path( pathParts );

		std::pair< LoadedObjectMap::iterator,bool > ret = m_loadedObjects->insert( std::pair<IndexedIO::EntryIDList, ObjectPtr>( pathParts, NULL ) );
		if ( ret.second )
		{
			// add the loaded object to the map.
			ret.first->second = loadObject( ioObject );
		}
		return ret.first->second;
	}
}
CompoundObjectPtr AttributeCache::readHeader( )
{
	CompoundObjectPtr dict = new CompoundObject();

	IndexedIO::EntryIDList directories;
	m_headersIO->entryIds( directories, IndexedIO::Directory );

	for (IndexedIO::EntryIDList::const_iterator it = directories.begin(); it != directories.end(); ++it)
	{
		ObjectPtr data = Object::load( m_headersIO, *it );
		dict->members()[ *it ] = data;
	}

	return dict;
}
CompoundObjectPtr AttributeCache::read( const ObjectHandle &obj )
{
	CompoundObjectPtr dict = new CompoundObject();

	IndexedIO::EntryIDList directories;
	IndexedIOPtr object = m_objectsIO->subdirectory( obj );
	object->entryIds( directories, IndexedIO::Directory );

	for (IndexedIO::EntryIDList::const_iterator it = directories.begin(); it != directories.end(); ++it)
	{
		ObjectPtr data = Object::load( object, *it );
		dict->members()[ *it ] = data;
	}

	return dict;
}
void MotionPrimitive::load( IECore::Object::LoadContextPtr context )
{
	VisibleRenderable::load( context );
	unsigned int v = m_ioVersion;
	ConstIndexedIOPtr container = context->container( staticTypeName(), v );
	ConstIndexedIOPtr snapshots = container->subdirectory( g_snapshotsEntry );
	m_snapshots.clear();
	IndexedIO::EntryIDList names;
	snapshots->entryIds( names, IndexedIO::Directory );
	IndexedIO::EntryIDList::const_iterator it;
	for( it=names.begin(); it!=names.end(); it++ )
	{
		ConstIndexedIOPtr snapshot = snapshots->subdirectory( *it );
		float t; 
		snapshot->read( g_timeEntry, t );
		m_snapshots[t] = context->load<Primitive>( snapshot, g_primitiveEntry );
	}
}
void AttributeCache::attributes(const ObjectHandle &obj, const std::string regex, std::vector<AttributeHandle> &attrs)
{
	IndexedIO::EntryIDList directories;
	attributes( obj, directories );

	boost::regex regexTest(regex);
	boost::cmatch what;

	attrs.clear();
	attrs.reserve( directories.size() );
	for (IndexedIO::EntryIDList::const_iterator it = directories.begin(); it != directories.end(); ++it)
	{
		if ( regex_match( (*it).value().c_str(), what, regexTest) )
		{
			attrs.push_back( *it );
		}
	}
}
void MatrixMotionTransform::load( LoadContextPtr context )
{
	Transform::load( context );
	unsigned int v = m_ioVersion;

	ConstIndexedIOPtr container = context->container( staticTypeName(), v );
	container = container->subdirectory( g_snapshotsEntry );
	m_snapshots.clear();
	IndexedIO::EntryIDList names;
	container->entryIds( names, IndexedIO::Directory );
	IndexedIO::EntryIDList::const_iterator it;
	for( it=names.begin(); it!=names.end(); it++ )
	{
		ConstIndexedIOPtr snapshotContainer = container->subdirectory( *it );
		float t; snapshotContainer->read( g_timeEntry, t );
		M44f m;
		float *f = m.getValue();
		snapshotContainer->read( g_matrixEntry, f, 16 );
		m_snapshots[t] = m;
	}
}
void ObjectVector::load( LoadContextPtr context )
{
	Object::load( context );
	unsigned int v = m_ioVersion;
	ConstIndexedIOPtr container = context->container( staticTypeName(), v );

	unsigned int size = 0;
	container->read( g_sizeEntry, size );

	m_members.resize( size );
	std::fill( m_members.begin(), m_members.end(), (IECore::Object*)0 );

	ConstIndexedIOPtr ioMembers = container->subdirectory( g_membersEntry );

	IndexedIO::EntryIDList l;
	ioMembers->entryIds(l);
	for( IndexedIO::EntryIDList::const_iterator it=l.begin(); it!=l.end(); it++ )
	{
		MemberContainer::size_type i = boost::lexical_cast<MemberContainer::size_type>( (*it).value() );
		m_members[i] = context->load<Object>( ioMembers, *it );
	}
}