grail.data.shlfile Module

Version: 16.2

Table of Contents

Overview

The Shell File (SHL) is used for describing 3D solids and surfaces as a combination of points, and face indices into that point list. The standard format is:

PointCount, FaceCount
X_0, Z_0, Y_0
X_1, Z_1, Y_1
     ...
X_n, Z_n, Y_n
F0
F1
...
Fn

where X_n, Z_n and Y_n are points and Fn is an face index into the point list. The point list and face list follow the standard definitions defined in the grail.ag's Standard Definitions section.

If used with the grail.mstype module, you will be able to read/write binary data without converting it to a python structure.

Examples

The following snippet illustrates how to read from a SHL file,

        
        
# Open a "sample_path" and read the points and face data.
        
shl = shlfile.open(sample_path, "r")
        
(point_list, face_list) = shl.read_shell()
        
shl.close()
        

At this point the point_list and face_list contain the standard point and face lists as defined in the grail.ag module's Standard Definitions.

An example of writing the contents would be as follows,

        point_list =[[63., 738., 360.],
                     
[63., 738., 362.],
                     
[63., 740., 360.],
                     
[65., 738., 360.],
                     
[63., 740., 362.],
                     
[65., 738., 362.],
                     
[65., 740., 360.],
                     
[65., 740., 362.]]
        
face_list = [3, 2, 6, 3,
                     
3, 2, 3, 0,
                     
3, 2, 6, 7,
                     
3, 2, 7, 4,
                     
3, 6, 3, 5,
                     
3, 6, 5, 7,
                     
3, 3, 0, 1,
                     
3, 3, 1, 5,
                     
3, 0, 2, 4,
                     
3, 0, 4, 1,
                     
3, 4, 7, 5,
                     
3, 4, 5, 1]
        
        
# Create a file (using "w") and write the point and face list to it.
        
f = shlfile.open(sample_path, "w")
        
f.write_shell(point_list, face_list)
        
f.close()

If the grail.mstype module is active, then the read/write operations will occur without converting the data to Python objects, if and only if you don't access the contents of the point list and face list.

Function

open(path [,mode])

Opens a file at the given path. The mode can be either "r" for read-only or "w" for write-only. If you want to create a new file use the "w" option. Using the

If you are attempting to open a file in "r" mode and it does not exist, an IOError is generated.

ShlFile

ShlFile

Use the open function to load/create a ShlFile object. For the most part this object behaves as a regular file like object in Python.

Methods

close()

This closes the file handle to the object. If you fail to close the file explicitly, the file will be closed implicitly when object falls out of scope.

read_shell()

Returns a Point List and Face List tuple as defined by the standard point and face lists in the grail.ag module's Standard Definitions.

write_shell(point_list, face_list)

Accepts a point_list and face_list as defined by the standard point and face lists in the grail.ag module's Standard Definitions.

Attributes

mode

Read-only. Indicates the mode that the file is in. For example this would be "w" (write-only) or "r" (read-only).

name

This is the path to the file.

closed

Is True when the object has been closed.