de.grogra.imp3d.io
Class SceneGraphExport

java.lang.Object
  extended by de.grogra.pf.io.FilterBase
      extended by de.grogra.imp3d.io.SceneGraphExport
All Implemented Interfaces:
SceneTree.Visitor, Filter, FilterSource, RegistryContext, Map
Direct Known Subclasses:
MTGExport, X3DExport

public abstract class SceneGraphExport
extends FilterBase
implements SceneTree.Visitor

This base class is used to export the 3D scene graph of a View3D to another representation (usually, this is a file representation for which this class provides a set of useful methods). The export is done via the creation of an intermediate SceneTree in the method createSceneTree(View3D).

Author:
Ole Kniemeyer

Nested Class Summary
static interface SceneGraphExport.NodeExport
          This interface is used to export a leaf of the SceneTree to the destination.
static interface SceneGraphExport.ObjectExport
          This interface is used to export an object (as an attribute of a node of the scene tree) to the destination.
 
Nested classes/interfaces inherited from interface de.grogra.pf.io.FilterSource
FilterSource.MetaDataKey<V>
 
Nested classes/interfaces inherited from interface de.grogra.util.Map
Map.Chain
 
Field Summary
protected  ObjectList files
          The list of files which have been created by this export.
 
Fields inherited from class de.grogra.pf.io.FilterBase
item, source
 
Fields inherited from interface de.grogra.pf.io.FilterSource
AUTO_PROGRESS, DESTINATION_FILE, DESTINATION_URL
 
Fields inherited from interface de.grogra.util.Map
DEFAULT_VALUE, EMPTY_MAP
 
Constructor Summary
SceneGraphExport(FilterItem item, FilterSource source)
          Delegates to FilterBase.FilterBase(FilterItem, FilterSource).
 
Method Summary
protected abstract  void beginGroup(SceneTree.InnerNode group)
          This method is invoked at the beginning of every inner node group which has more than one child.
protected abstract  SceneTree createSceneTree(View3D scene)
          The implementation of this method creates the scene tree which is to be exported by this export.
protected abstract  void endGroup(SceneTree.InnerNode group)
          This method is invoked at the end of every inner node group which has more than one child.
 boolean export(java.lang.Object object)
          This method is invoked for some attribute value in order to export the value.
protected  void export(SceneTree.Leaf node, SceneTree.InnerNode transform)
          This method is invoked for every leaf of the scene tree in order to export this leaf.
 java.lang.Object getDirectory()
          This method returns the base directory within getFileSystem() to use for the export.
 SceneGraphExport.NodeExport getExportFor(java.lang.Object object, boolean asNode)
          This method is used to obtain an instance of NodeExport capable of exporting the object of a SceneTree.Leaf.
 SceneGraphExport.ObjectExport getExportForObject(java.lang.Object object)
          This method is used to obtain an instance of ObjectExport capable of exporting the object (which is some attribute value).
 java.lang.Object getFile(java.lang.String name)
          This method creates a file in getDirectory().
 java.util.Collection getFiles()
          Returns the list of files which have been created during export.
 FileSystem getFileSystem()
          This method returns the file system to use for the export.
 GraphState getGraphState()
          Returns the graph state which is used for export.
 java.io.OutputStream getOutputStream(java.lang.Object file)
           
 java.lang.String getPath(FileObjectItem file)
           
 java.lang.String getPath(java.lang.Object file)
          Returns the path of a file of this export's file system (getFileSystem()) as a string.
 View3D getView()
          Returns the view which defines the scene to export.
protected  java.lang.Object initDirectory()
          Determines the directory to use.
protected  FileSystem initFileSystem()
          Determines the file system to use.
 void visit(SceneTree.Leaf leaf)
          Informs the visitor that a leaf is visited.
 void visitEnter(SceneTree.InnerNode node)
          Informs the visitor that an inner node has been entered.
 void visitLeave(SceneTree.InnerNode node)
          Informs the visitor that an inner node has been left.
protected  void write()
          Exports the scene of the view.
 
Methods inherited from class de.grogra.pf.io.FilterBase
get, getFilter, getFlavor, getImpl, getMetaData, getRegistry, getSource, getSystemId, initProgressMonitor, setFlavor, setMetaData, setMetaData, setProgress, setSystemId, toString, toURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

files

protected ObjectList files
The list of files which have been created by this export.

Constructor Detail

SceneGraphExport

public SceneGraphExport(FilterItem item,
                        FilterSource source)
Delegates to FilterBase.FilterBase(FilterItem, FilterSource). The source is expected to be an ObjectSource representing an instance of View3D.

Parameters:
item - the defining FilterItem
source - the data source
Method Detail

beginGroup

protected abstract void beginGroup(SceneTree.InnerNode group)
                            throws java.io.IOException
This method is invoked at the beginning of every inner node group which has more than one child. Its children will be processed until the corresponding method endGroup(de.grogra.imp3d.objects.SceneTree.InnerNode) is invoked. The export should write the hierarchy and transformation information of the group.

Parameters:
group - the group
Throws:
java.io.IOException

createSceneTree

protected abstract SceneTree createSceneTree(View3D scene)
The implementation of this method creates the scene tree which is to be exported by this export.

Parameters:
scene - the view which defines the scene to export
Returns:
scene tree for the view

endGroup

protected abstract void endGroup(SceneTree.InnerNode group)
                          throws java.io.IOException
This method is invoked at the end of every inner node group which has more than one child. Its children have been processed completely.

Parameters:
group - the group
Throws:
java.io.IOException
See Also:
beginGroup(de.grogra.imp3d.objects.SceneTree.InnerNode)

export

public boolean export(java.lang.Object object)
               throws java.io.IOException
This method is invoked for some attribute value in order to export the value.

This implementation obtains an SceneGraphExport.ObjectExport via getExportForObject(Object) and, if successful, uses this to export the value.

Parameters:
object - object to export
Throws:
java.io.IOException

export

protected void export(SceneTree.Leaf node,
                      SceneTree.InnerNode transform)
               throws java.io.IOException
This method is invoked for every leaf of the scene tree in order to export this leaf. If transform is non-null, this means that node is the only child of transform and the transformation of transform has to be exported together with the node.

This implementation obtains a SceneGraphExport.NodeExport via getExportFor(Object, boolean) and, if successful, uses this to export the leaf.

Parameters:
node - a leaf of the scene tree
transform - transformation of node
Throws:
java.io.IOException
See Also:
beginGroup(de.grogra.imp3d.objects.SceneTree.InnerNode), endGroup(de.grogra.imp3d.objects.SceneTree.InnerNode)

getDirectory

public java.lang.Object getDirectory()
                              throws java.io.IOException
This method returns the base directory within getFileSystem() to use for the export. On first invocation, the directory is obtained from initDirectory().

Returns:
directory to use for export
Throws:
java.io.IOException

getExportFor

public SceneGraphExport.NodeExport getExportFor(java.lang.Object object,
                                                boolean asNode)
This method is used to obtain an instance of NodeExport capable of exporting the object of a SceneTree.Leaf. If no such export is defined, null is returned.

This implementation looks for an export defined in the registry: As name, the name of the class of object is chosen, the export is searched as a child of FilterBase.item.

Parameters:
object - object of the original scene graph
asNode - is object a node or an edge?
Returns:
suitable export for the object or null

getExportForObject

public SceneGraphExport.ObjectExport getExportForObject(java.lang.Object object)
This method is used to obtain an instance of ObjectExport capable of exporting the object (which is some attribute value). If no such export is defined, null is returned.

This implementation looks for an export defined in the registry: As name, the name of the class of object is chosen, the export is searched as a child of FilterBase.item.

Parameters:
object - object to export
Returns:
suitable export for the object or null

getFile

public java.lang.Object getFile(java.lang.String name)
                         throws java.io.IOException
This method creates a file in getDirectory(). The file name is based ob name: E.g., if name is test.png, the actual name could be something like test123.png. It is ensured that no file will be returned twice during a single export.

Parameters:
name - name for file
Returns:
file
Throws:
java.io.IOException

getFiles

public java.util.Collection getFiles()
Returns the list of files which have been created during export.

Returns:
created files

getFileSystem

public FileSystem getFileSystem()
                         throws java.io.IOException
This method returns the file system to use for the export. On first invocation, the file system is obtained from initFileSystem().

Returns:
file system to use for export
Throws:
java.io.IOException

getGraphState

public GraphState getGraphState()
Returns the graph state which is used for export. This is the graph state of the view's workbench.

Returns:
graph state for export

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.Object file)
                                     throws java.io.IOException
Throws:
java.io.IOException

getPath

public java.lang.String getPath(FileObjectItem file)
                         throws java.io.IOException
Throws:
java.io.IOException

getPath

public java.lang.String getPath(java.lang.Object file)
                         throws java.io.IOException
Returns the path of a file of this export's file system (getFileSystem()) as a string.

Parameters:
file - file of this export's file system
Returns:
path of file
Throws:
java.io.IOException

getView

public View3D getView()
               throws java.io.IOException
Returns the view which defines the scene to export. This requires that the source of this export is an ObjectSource representing an instance of View3D.

Returns:
view
Throws:
java.io.IOException

initDirectory

protected java.lang.Object initDirectory()
                                  throws java.io.IOException
Determines the directory to use. This method is invoked once by getDirectory().

Returns:
directory to use
Throws:
java.io.IOException

initFileSystem

protected FileSystem initFileSystem()
                             throws java.io.IOException
Determines the file system to use. This method is invoked once by getFileSystem().

Returns:
file system to use
Throws:
java.io.IOException

visit

public void visit(SceneTree.Leaf leaf)
Description copied from interface: SceneTree.Visitor
Informs the visitor that a leaf is visited.

Specified by:
visit in interface SceneTree.Visitor
Parameters:
leaf - the leaf being visited

visitEnter

public void visitEnter(SceneTree.InnerNode node)
Description copied from interface: SceneTree.Visitor
Informs the visitor that an inner node has been entered.

Specified by:
visitEnter in interface SceneTree.Visitor
Parameters:
node - the node being entered

visitLeave

public void visitLeave(SceneTree.InnerNode node)
Description copied from interface: SceneTree.Visitor
Informs the visitor that an inner node has been left.

Specified by:
visitLeave in interface SceneTree.Visitor
Parameters:
node - the node being left

write

protected void write()
              throws java.io.IOException
Exports the scene of the view. This method at first creates the scene tree using createSceneTree(View3D), then it lets this export instance visit the created scene tree. During visit, the methods beginGroup(de.grogra.imp3d.objects.SceneTree.InnerNode), endGroup(de.grogra.imp3d.objects.SceneTree.InnerNode) and export(SceneTree.Leaf, SceneTree.InnerNode) are invoked; these have to be implemented to perform the actual export to the destination.

Throws:
java.io.IOException