Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

File Input/Output

As OpenSG user/developer you can always instantiate all your nodes, cores or whatever objects you need one by one in your application code.

In addition OpenSG also provides - as most scene-graph libraries - a set of loaders, which create a scene tree or image from a given file. The system creates singleton Handlers for both types (SceneFileHandler and ImageFileHandler), which handle all abstract requests. The concrete loaders are coded in mime/file type handlers (e.g. OSGTIFImageFileType.h/OSGTIFImageFileType.cpp) and are automatically registered.

The system architecture is designed to handle built-in types and to fetch loaders for a specific type on request. In the current version (1.0) only built-in types are provided since the meta interfaces may not be final yet. However the 1.0 version comes with a sufficient set of built-in loaders and you can always extend the library to handle you own file format.

Usage

You can always use a specific loader directly, but in most cases you would ask the Handler (e.g. SceneFileHandler) to load a file independent of the file type. There is always just one handler (it is a singleton object) you can access the object using the static the() method (e.g. osg::SceneFileType::the()). The Handler knows all the valid suffixes for every mime/file type and can pick the correct loader automatically.

If you would like to get a loader for a specific type or suffix you can just ask the handler to find it (e.g. SceneFileHandler::the().getFileType("wrl")).

Scene

The Scene Handler provides two interfaces to load a scene: read (returns a single root node or NullFC on failure) or readTopNodes (does not create an extra root but returns all top nodes ).

Just use the Handler to find and use the correct type for the given suffix: osg::NodePtr rootPtr = osg::SceneFileTypeSceneFileHandler::the().read("test.wrl") for example would pick the VRML loader (suffix is "wrl"), parse the file and return the result.

Image

The image loader works more or less the same way as the scene loader. Let the singleton handler pick the mime type and just check the return value: osg::ImageFileHandler::the().read("test.tif") for example would pick the tif loader (suffix "tif" ), start loading the file, and return the new Image or Null.

Ext:

Write our own

For every new mime/file you have to write a new "Type" class (e.g. FooImageType.h/FooImageType.cpp). Every Type is handled as a singleton object and must provide a the() method to access the static instance. The class must be derived from the base Type (e.g. ImageFileType) to be registered. You don't have to register the new type in any extra class. Just included it in the OpenSG source tree and it should work with the Handler.

Scene

Since scene loaders are usually more complex and require sometimes some extra library they have extra directories for their sources (e.g. OpenSG/Loader/WRL). To write your own scene handler perform the following steps:

Image

Image loaders are usually not too complex. They usually just use some external library (e.g. tifflib) to load the image data. Since the extra lib is usually not included in the opensg source tree we do not store the code in an extra, mime type specific directory. They are all stored in OpenSG/Image.

To write you own image loader perform the following steps:


Generated on Thu Aug 25 04:12:27 2005 for OpenSG by  doxygen 1.4.3