EMAN2 3D Widget for Python applications:

The 3D widget is a python class allowing display of 3D items in EMAN2. These include isosurafces, volume slices, volumes, in additon to text and shapes for annotation. The 3D object is arranged in a tree datastructure for easy data grouping and control. The scene itself can be save for later analysis and snapshots can be taken for publication.

Importing the widget and assoicated classes:

To use the EMAN2 3D widget you need to add the line: from emscene3d import EMScene3D to your python programs. This will allow creation of the 3D Widget. If you want to add enable to additon of EMData objects to the 3D widget for display of isosurfaces, slices, and volumes, then the lines: from emdataitem3d import EMDataItem3D, EMIsosurface, EMSliceItem3D, EMVolumeItem3D need to added to your python programs.

Creating the 3D widget and adding EMData items for rendering:

To create the 3D widget simply instatiate it by: widget = EMScene3D(). To add a EMData item, you need to first instatiate a data widget by:

dataitem = EMDataItem3D("mydatafile.hdf", transform=Transform())
or
EMDataItem3D(myemdataobject, transform=Transform()) 

if you want to use a emdata object rather than a file as the EMData source. After instantiation, you need to add the EMDataItem3D as a child of the 3D widget by:

widget.insertNewNode('My Data', dataitem, parentnode=widget)

This does not add isosurfaces and the like to the 3D widget, so you need to add these as children of the EMDataItem3D widget. For example:

isosurfacewidget = EMIsosurface(dataitem, transform=Transform())
widget.insertNewNode('My Iso', isosurfacewidget, parentnode=dataitem)

Similar logic applies to the slice and volume objects.

If you want to set the sclae such that the isosurface fills the viewport window, you need to call the EMScene method: initialViewportDims(dims) where dims is the size of the object filling the viewport. This viewport filling will occur when the widget is shown by the QT showEvent(). For example to fill the viewport with the dataitem:

widget.initialViewportDims(dataitem.getData().get_xsize())

Useful EMScene3D functions:

InsertNewNode(name, node, parentnode=None, parentidx=None): Inserts a node into the 3D widget. If the inspector is open the node is inserted below which ever item is currently selected. name is the name of the node, node is the node to be inserted, parentnode sets the parent of node, and parentidx determines where the insertion takes place.

deleteNode(node): Deletes the node, 'node'.

loadSession(filename): Loads a session from file. The file, filename, must be a python pickle, which was previously saved.

saveSession(filename): Saves a session to a file named, filename. The file is saved as a python pickle.

updateSG(): Updates the 3D widget, used when you have finished building the 3D widget

updateTree(): Updates the tree representation in the inspector. Useful if you have altered the 3D tree structure using a function other than insetNewNode(...)

copyNodes(nodes): Makes a copy of the supplied nodes. Does not work for data nodes and their children

groupNodes(nodes): Groups the nodes by placing them in their own subnode. Useful if you want to control a group of node together.

unGroupNodes(nodes): Does the opposite of the above.

setCurrentSelection(item): Sets the item currently displayed in the inspector tree. If the inspector is not displayed, then the current item in the inspector will be set to this value. Dealut is self(in other words the SG item will be displayed in the inspector upon instantiation).

Useful EMDataItem3D functions:

setData(data): sets the data that the EMDataItem3D owns, useful if you process the EMData and want to re display

Useful function for any EMItem object:

insertChild(node, nodeindex): an alternative to the 3D widget's insertNewNode function for inserting a node into the tree. Here a node is inserted as a child of this object. You will need to run the 3D widget's updateTree() after all modifications are made.

addChild(node): same as above, but appends a node

Eman2Using3DWidget (last edited 2012-05-02 22:15:22 by JohnFlanagan)