ddg.datastructures.halfedge.io module

class ddg.datastructures.halfedge.io.HalfedgeEncoder(vertex_attrs=[], edge_attrs=[], face_attrs=[], **kwargs)[source]

Bases: JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(o)

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
item_separator = ', '
iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
key_separator = ': '
ddg.datastructures.halfedge.io.to_json_string(surface, vertex_attrs=[], edge_attrs=[], face_attrs=[], write_index=False)[source]

Create a json string from a given halfedge surface. Additional attributes to be included in the json string need to be specified explicitly in the respective dictionaries. All the references to vertices, edges, and faces are realized using integer indices. The None face corresponds to -1

Parameters:
surfacehalfedge surface

The surface to be converted to a json string

vertex_attrslist of strings

vertex attributes to be contained in the json string in addition to edge

edge_attrs

edge attributes to be contained in the json string in addition to pre, nex, opp, head, face

face_attrs

face attributes to be contained in the json string in addition to edge

Returns:
string
ddg.datastructures.halfedge.io.write_json_file(surface, filename, vertex_attrs=[], edge_attrs=[], face_attrs=[])[source]

Create a file in json format from a given halfedge surface. Additional attributes to be included in the json string need to be specified explicitly in the respective dictionaries. All the references to vertices, edges, and faces are realized using integer indices. The None face corresponds to -1

Parameters:
surfacehalfedge surface

The surface to be converted to a json string

filenamestring

file to be written

vertex_attrslist of strings

vertex attributes to be contained in the json string in addition to edge

edge_attrs

edge attributes to be contained in the json string in addition to pre, nex, opp, head, face

face_attrs

face attributes to be contained in the json string in addition to edge

ddg.datastructures.halfedge.io.read_json_file(filename)[source]

Create a surface from a json file. All keys will be mapped to respective attribute of the vertices, edges, and faces.

Parameters:
filename: string

file containing a json representing a halfedge surface

Returns:
surface
Raises:
ValueError

If required attributes are missing in the json string

ddg.datastructures.halfedge.io.parse_json_string(json_string)[source]

Create a surface from a json string. All keys will be mapped to respective attribute of the vertices, edges, and faces.

Parameters:
json_stringstring

formatted string containing a halfedge surface

Returns:
surface
Raises:
ValueError

If required attributes are missing in the json string

ddg.datastructures.halfedge.io.surface_to_ifs_json(surface, vertex_attrs=['co'])[source]
class ddg.datastructures.halfedge.io.SurfaceToIFSEncoder(vertex_attrs=['co'], **kwargs)[source]

Bases: JSONEncoder

default(surface)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(o)

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
item_separator = ', '
iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
key_separator = ': '