Skip to content

Commit 0778515

Browse files
committed
default attributes
1 parent 6d0b71d commit 0778515

File tree

6 files changed

+149
-59
lines changed

6 files changed

+149
-59
lines changed

src/compas/datastructures/graph/graph.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
class Graph(Datastructure):
1818
"""Base graph data structure for describing the topological relationships between nodes connected by edges.
1919
20+
Parameters
21+
----------
22+
name: str, optional
23+
The name of the graph.
24+
Defaults to "Graph".
25+
default_node_attributes: dict, optional
26+
Default values for node attributes.
27+
default_edge_attributes: dict, optional
28+
Default values for edge attributes.
29+
2030
Attributes
2131
----------
2232
node : dict
@@ -65,7 +75,7 @@ def DATASCHEMA(self):
6575
def JSONSCHEMANAME(self):
6676
return 'graph'
6777

68-
def __init__(self, name=None):
78+
def __init__(self, name=None, default_node_attributes=None, default_edge_attributes=None):
6979
super(Graph, self).__init__()
7080
self._max_node = -1
7181
self.attributes = {'name': name or 'Graph'}
@@ -74,6 +84,10 @@ def __init__(self, name=None):
7484
self.adjacency = {}
7585
self.default_node_attributes = {}
7686
self.default_edge_attributes = {}
87+
if default_node_attributes:
88+
self.default_node_attributes.update(default_node_attributes)
89+
if default_edge_attributes:
90+
self.default_edge_attributes.update(default_edge_attributes)
7791

7892
def __str__(self):
7993
tpl = "<Graph with {} nodes, {} edges>"

src/compas/datastructures/halfedge/halfedge.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515

1616

1717
class HalfEdge(Datastructure):
18-
"""Base half-edge data structure for representing meshes.
18+
"""Base half-edge data structure for representing the topology of open oor closed surface meshes.
19+
20+
Parameters
21+
----------
22+
name: str, optional
23+
The name of the graph.
24+
Defaults to "Graph".
25+
default_vertex_attributes: dict, optional
26+
Default values for vertex attributes.
27+
default_edge_attributes: dict, optional
28+
Default values for edge attributes.
29+
default_face_attributes: dict, optional
30+
Default values for face attributes.
1931
2032
Attributes
2133
----------
@@ -51,7 +63,6 @@ def DATASCHEMA(self):
5163
"vertex": schema.And(
5264
dict,
5365
is_sequence_of_uint,
54-
# lambda x: all(('x' in attr and 'y' in attr and 'z' in attr) for attr in x.values())
5566
),
5667
"face": schema.And(
5768
dict,
@@ -79,7 +90,7 @@ def DATASCHEMA(self):
7990
def JSONSCHEMANAME(self):
8091
return 'halfedge'
8192

82-
def __init__(self):
93+
def __init__(self, name=None, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None):
8394
super(HalfEdge, self).__init__()
8495
self._max_vertex = -1
8596
self._max_face = -1
@@ -88,10 +99,16 @@ def __init__(self):
8899
self.face = {}
89100
self.facedata = {}
90101
self.edgedata = {}
91-
self.attributes = {'name': 'HalfEdge'}
102+
self.attributes = {'name': name or 'HalfEdge'}
92103
self.default_vertex_attributes = {}
93104
self.default_edge_attributes = {}
94105
self.default_face_attributes = {}
106+
if default_vertex_attributes:
107+
self.default_vertex_attributes.update(default_vertex_attributes)
108+
if default_edge_attributes:
109+
self.default_edge_attributes.update(default_edge_attributes)
110+
if default_face_attributes:
111+
self.default_face_attributes.update(default_face_attributes)
95112

96113
def __str__(self):
97114
tpl = "<HalfEdge with {} vertices, {} faces, {} edges>"

src/compas/datastructures/halfface/halfface.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
class HalfFace(Datastructure):
2020
"""Base half-face data structure fore representing volumetric meshes.
2121
22+
Parameters
23+
----------
24+
name: str, optional
25+
The name of the graph.
26+
Defaults to "Graph".
27+
default_vertex_attributes: dict, optional
28+
Default values for vertex attributes.
29+
default_edge_attributes: dict, optional
30+
Default values for edge attributes.
31+
default_face_attributes: dict, optional
32+
Default values for face attributes.
33+
default_cell_attributes: dict, optional
34+
Default values for cell attributes.
35+
2236
Attributes
2337
----------
2438
attributes : dict
@@ -60,7 +74,12 @@ def DATASCHEMA(self):
6074
def JSONSCHEMANAME(self):
6175
return 'halfface'
6276

63-
def __init__(self, name=None):
77+
def __init__(self,
78+
name=None,
79+
default_vertex_attributes=None,
80+
default_edge_attributes=None,
81+
default_face_attributes=None,
82+
default_cell_attributes=None):
6483
super(HalfFace, self).__init__()
6584
self._max_vertex = -1
6685
self._max_face = -1
@@ -77,6 +96,14 @@ def __init__(self, name=None):
7796
self.default_edge_attributes = {}
7897
self.default_face_attributes = {}
7998
self.default_cell_attributes = {}
99+
if default_vertex_attributes:
100+
self.default_vertex_attributes.update(default_vertex_attributes)
101+
if default_edge_attributes:
102+
self.default_edge_attributes.update(default_edge_attributes)
103+
if default_face_attributes:
104+
self.default_face_attributes.update(default_face_attributes)
105+
if default_cell_attributes:
106+
self.default_cell_attributes.update(default_cell_attributes)
80107

81108
def __str__(self):
82109
tpl = "<HalfFace with {} vertices, {} faces, {} cells, {} edges>"

src/compas/datastructures/mesh/mesh.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262
class Mesh(HalfEdge):
6363
"""Geometric implementation of a half edge data structure for polygon meshses.
6464
65+
Parameters
66+
----------
67+
name: str, optional
68+
The name of the graph.
69+
Defaults to "Graph".
70+
default_vertex_attributes: dict, optional
71+
Default values for vertex attributes.
72+
default_edge_attributes: dict, optional
73+
Default values for edge attributes.
74+
default_face_attributes: dict, optional
75+
Default values for face attributes.
76+
6577
Attributes
6678
----------
6779
attributes : dict
@@ -111,10 +123,21 @@ class Mesh(HalfEdge):
111123
unify_cycles = mesh_unify_cycles
112124
quads_to_triangles = mesh_quads_to_triangles
113125

114-
def __init__(self):
115-
super(Mesh, self).__init__()
116-
self.attributes.update({'name': 'Mesh'})
117-
self.default_vertex_attributes.update({'x': 0.0, 'y': 0.0, 'z': 0.0})
126+
def __init__(self, name=None, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None):
127+
name = name or 'Mesh'
128+
_default_vertex_attributes = {'x': 0.0, 'y': 0.0, 'z': 0.0}
129+
_default_edge_attributes = {}
130+
_default_face_attributes = {}
131+
if default_vertex_attributes:
132+
_default_vertex_attributes.update(default_vertex_attributes)
133+
if default_edge_attributes:
134+
_default_edge_attributes.update(default_edge_attributes)
135+
if default_face_attributes:
136+
_default_face_attributes.update(default_face_attributes)
137+
super(Mesh, self).__init__(name=name,
138+
default_vertex_attributes=_default_vertex_attributes,
139+
default_edge_attributes=_default_edge_attributes,
140+
default_face_attributes=_default_face_attributes)
118141

119142
def __str__(self):
120143
tpl = "<Mesh with {} vertices, {} faces, {} edges>"

src/compas/datastructures/network/network.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737

3838
class Network(Graph):
3939
"""Geometric implementation of an edge graph.
40+
41+
Parameters
42+
----------
43+
name: str, optional
44+
The name of the graph.
45+
Defaults to "Graph".
46+
default_node_attributes: dict, optional
47+
Default values for node attributes.
48+
default_edge_attributes: dict, optional
49+
Default values for edge attributes.
50+
4051
"""
4152

4253
complement = network_complement
@@ -71,11 +82,17 @@ class Network(Graph):
7182
is_planar = network_is_planar
7283
is_planar_embedding = network_is_planar_embedding
7384

74-
def __init__(self, name=None):
75-
super(Network, self).__init__()
76-
self._max_int_key = -1
77-
self.attributes.update({'name': name or 'Network'})
78-
self.default_node_attributes.update({'x': 0.0, 'y': 0.0, 'z': 0.0})
85+
def __init__(self, name=None, default_node_attributes=None, default_edge_attributes=None):
86+
name = name or 'Network'
87+
_default_node_attributes = {'x': 0.0, 'y': 0.0, 'z': 0.0}
88+
_default_edge_attributes = {}
89+
if default_node_attributes:
90+
_default_node_attributes.update(default_node_attributes)
91+
if default_edge_attributes:
92+
_default_edge_attributes.update(default_edge_attributes)
93+
super(Network, self).__init__(name=name,
94+
default_node_attributes=_default_node_attributes,
95+
default_edge_attributes=_default_edge_attributes)
7996

8097
def __str__(self):
8198
tpl = "<Network with {} nodes, {} edges>"

src/compas/datastructures/volmesh/volmesh.py

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,58 +33,50 @@
3333
class VolMesh(HalfFace):
3434
"""Geometric implementation of a face data structure for volumetric meshes.
3535
36-
Attributes
36+
Parameters
3737
----------
38-
attributes : dict
39-
A dictionary of general volmesh attributes.
40-
41-
* ``'name': "VolMesh"``
42-
43-
default_vertex_attributes : dict
44-
The names of pre-assigned vertex attributes and their default values.
45-
46-
* ``'x': 0.0``
47-
* ``'y': 0.0``
48-
* ``'z': 0.0``
49-
50-
default_edge_attributes : dict
51-
The default data attributes assigned to every new edge.
52-
default_face_attributes : dict
53-
The default data attributes assigned to every new face.
54-
name : str
55-
The name of the volmesh.
56-
Shorthand for ``volmesh.attributes['name']``
57-
58-
data : dict
59-
The data representing the mesh.
60-
The dict has the following structure:
61-
62-
* 'attributes' => dict
63-
* 'dva' => dict
64-
* 'dea' => dict
65-
* 'dfa' => dict
66-
* 'dca' => dict
67-
* 'vertex' => dict
68-
* 'halface' => dict
69-
* 'cell' => dict
70-
* 'plane' => dict
71-
* 'edgedata' => dict
72-
* 'facedata' => dict
73-
* 'celldata' => dict
74-
* 'max_int_key' => int
75-
* 'max_int_hfkey' => int
76-
* 'max_int_ckey' => int
38+
name: str, optional
39+
The name of the graph.
40+
Defaults to "Graph".
41+
default_vertex_attributes: dict, optional
42+
Default values for vertex attributes.
43+
default_edge_attributes: dict, optional
44+
Default values for edge attributes.
45+
default_face_attributes: dict, optional
46+
Default values for face attributes.
47+
default_cell_attributes: dict, optional
48+
Default values for cell attributes.
7749
7850
"""
7951

8052
bounding_box = volmesh_bounding_box
8153
transform = volmesh_transform
8254
transformed = volmesh_transformed
8355

84-
def __init__(self, name=None):
85-
super(VolMesh, self).__init__()
86-
self.attributes.update({'name': name or 'VolMesh'})
87-
self.default_vertex_attributes.update({'x': 0.0, 'y': 0.0, 'z': 0.0})
56+
def __init__(self,
57+
name=None,
58+
default_vertex_attributes=None,
59+
default_edge_attributes=None,
60+
default_face_attributes=None,
61+
default_cell_attributes=None):
62+
name = name or 'VolMesh'
63+
_default_vertex_attributes = {'x': 0.0, 'y': 0.0, 'z': 0.0}
64+
_default_edge_attributes = {}
65+
_default_face_attributes = {}
66+
_default_cell_attributes = {}
67+
if default_vertex_attributes:
68+
_default_vertex_attributes.update(default_vertex_attributes)
69+
if default_edge_attributes:
70+
_default_edge_attributes.update(default_edge_attributes)
71+
if default_face_attributes:
72+
_default_face_attributes.update(default_face_attributes)
73+
if default_cell_attributes:
74+
_default_cell_attributes.update(default_cell_attributes)
75+
super(VolMesh, self).__init__(name=name,
76+
default_vertex_attributes=_default_vertex_attributes,
77+
default_edge_attributes=_default_edge_attributes,
78+
default_face_attributes=_default_face_attributes,
79+
default_cell_attributes=_default_cell_attributes)
8880

8981
def __str__(self):
9082
tpl = "<VolMesh with {} vertices, {} faces, {} cells, {} edges>"

0 commit comments

Comments
 (0)