Skip to content

Commit 7a73524

Browse files
authored
Merge pull request #892 from compas-dev/mesh-restructure
Datastructures Restructure
2 parents b93230b + 8998e13 commit 7a73524

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+528
-462
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
* Changed `compas_rhino.drawing.draw_breps` to assume provided polygon is closed and automatically add missing corner to polycurve constructor.
2929
* Changed conversion of edges and faces to uniques keys for the data dicts to use the string representation of a sorted tuple of identifiers.
3030
* Added `dtype` to JSON decoding error message.
31+
* Moved `compas.datastructures.mesh.core.halfedge.HalfEdge` to `compas.datastructures.halfedge.halfedge.HalfEdge`
32+
* Moved `compas.datastructures.network.core.graph.Graph` to `compas.datastructures.graph.graph.Graph`.
3133

3234
### Removed
3335

36+
* Removed `compas.datastructures.mesh.core.mesh.BaseMesh`.
37+
38+
* Removed `compas.datastructures.BaseNetwork`.
39+
3440
## [1.7.1] 2021-06-14
3541

3642
### Added

src/compas/datastructures/__init__.py

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
66
.. currentmodule:: compas.datastructures
77
8-
Network
9-
=======
10-
118
Classes
12-
-------
9+
=======
1310
1411
.. autosummary::
1512
:toctree: generated/
1613
:nosignatures:
1714
15+
Datastructure
16+
Graph
17+
HalfEdge
18+
HalfFace
19+
Mesh
1820
Network
21+
VolMesh
1922
2023
2124
Functions
22-
---------
25+
=========
26+
27+
Network
28+
-------
2329
2430
.. autosummary::
2531
:toctree: generated/
@@ -47,10 +53,6 @@
4753
network_transform
4854
network_transformed
4955
50-
51-
CPython-only
52-
------------
53-
5456
.. autosummary::
5557
:toctree: generated/
5658
:nosignatures:
@@ -62,17 +64,7 @@
6264
6365
6466
Mesh
65-
====
66-
67-
.. autosummary::
68-
:toctree: generated/
69-
:nosignatures:
70-
71-
Mesh
72-
73-
74-
Functions
75-
---------
67+
----
7668
7769
.. autosummary::
7870
:toctree: generated/
@@ -142,10 +134,6 @@
142134
trimesh_subdivide_loop
143135
trimesh_swap_edge
144136
145-
146-
CPython-only
147-
------------
148-
149137
.. autosummary::
150138
:toctree: generated/
151139
:nosignatures:
@@ -171,21 +159,8 @@
171159
172160
173161
VolMesh
174-
=======
175-
176-
Classes
177162
-------
178163
179-
.. autosummary::
180-
:toctree: generated/
181-
:nosignatures:
182-
183-
VolMesh
184-
185-
186-
Functions
187-
---------
188-
189164
.. autosummary::
190165
:toctree: generated/
191166
:nosignatures:
@@ -200,9 +175,11 @@
200175
import compas
201176

202177
from .datastructure import Datastructure
178+
179+
from .graph import (
180+
Graph
181+
)
203182
from .network import (
204-
BaseNetwork, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
205-
Graph,
206183
Network,
207184
network_complement,
208185
network_count_crossings,
@@ -226,9 +203,10 @@
226203
network_transform,
227204
network_transformed,
228205
)
206+
from .halfedge import (
207+
HalfEdge
208+
)
229209
from .mesh import (
230-
BaseMesh, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
231-
HalfEdge,
232210
Mesh,
233211
mesh_add_vertex_to_face_edge,
234212
mesh_bounding_box_xy,
@@ -294,9 +272,10 @@
294272
trimesh_subdivide_loop,
295273
trimesh_swap_edge,
296274
)
275+
from .halfface import (
276+
HalfFace
277+
)
297278
from .volmesh import (
298-
BaseVolMesh, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
299-
HalfFace,
300279
VolMesh,
301280
volmesh_bounding_box,
302281
volmesh_transform,
@@ -331,11 +310,16 @@
331310
trimesh_vertexarea_matrix,
332311
)
333312

313+
BaseNetwork = Network
314+
BaseMesh = Mesh
315+
BaseVolMesh = VolMesh
316+
334317
__all__ = [
335318
'Datastructure',
319+
# Graphs
320+
'Graph',
336321
# Networks
337322
'BaseNetwork',
338-
'Graph',
339323
'Network',
340324
'network_complement',
341325
'network_count_crossings',
@@ -358,9 +342,10 @@
358342
'network_split_edge',
359343
'network_transform',
360344
'network_transformed',
345+
# HalfEdge
346+
'HalfEdge',
361347
# Meshes
362348
'BaseMesh',
363-
'HalfEdge',
364349
'Mesh',
365350
'mesh_add_vertex_to_face_edge',
366351
'mesh_bounding_box_xy',
@@ -425,9 +410,10 @@
425410
'trimesh_split_edge',
426411
'trimesh_subdivide_loop',
427412
'trimesh_swap_edge',
413+
# HalfFace
414+
'HalfFace',
428415
# Volumetric Meshes
429416
'BaseVolMesh',
430-
'HalfFace',
431417
'VolMesh',
432418
'volmesh_bounding_box',
433419
'volmesh_transform',

src/compas/datastructures/datastructure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
class Datastructure(Data):
11+
"""Base class for all data structures."""
1112

1213
def __init__(self):
1314
super(Datastructure, self).__init__()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .graph import Graph # noqa: F401

src/compas/datastructures/network/core/graph.py renamed to src/compas/datastructures/graph/graph.py

Lines changed: 27 additions & 5 deletions
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,18 +75,22 @@ def DATASCHEMA(self):
6575
def JSONSCHEMANAME(self):
6676
return 'graph'
6777

68-
def __init__(self):
78+
def __init__(self, name=None, default_node_attributes=None, default_edge_attributes=None):
6979
super(Graph, self).__init__()
7080
self._max_node = -1
71-
self.attributes = {'name': 'Graph'}
81+
self.attributes = {'name': name or 'Graph'}
7282
self.node = {}
7383
self.edge = {}
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):
79-
tpl = "<Network with {} nodes, {} edges>"
93+
tpl = "<Graph with {} nodes, {} edges>"
8094
return tpl.format(self.number_of_nodes(), self.number_of_edges())
8195

8296
# --------------------------------------------------------------------------
@@ -352,7 +366,7 @@ def index_uv(self):
352366
# builders
353367
# --------------------------------------------------------------------------
354368

355-
def add_node(self, key, attr_dict=None, **kwattr):
369+
def add_node(self, key=None, attr_dict=None, **kwattr):
356370
"""Add a node and specify its attributes (optional).
357371
358372
Parameters
@@ -367,7 +381,7 @@ def add_node(self, key, attr_dict=None, **kwattr):
367381
368382
Returns
369383
-------
370-
str
384+
hashable
371385
The key of the node.
372386
373387
Notes
@@ -382,6 +396,14 @@ def add_node(self, key, attr_dict=None, **kwattr):
382396
--------
383397
>>>
384398
"""
399+
if key is None:
400+
key = self._max_node = self._max_node + 1
401+
try:
402+
if key > self._max_node:
403+
self._max_node = key
404+
except (ValueError, TypeError):
405+
pass
406+
385407
if key not in self.node:
386408
self.node[key] = {}
387409
self.edge[key] = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .halfedge import HalfEdge # noqa: F401

src/compas/datastructures/mesh/core/halfedge.py renamed to src/compas/datastructures/halfedge/halfedge.py

Lines changed: 23 additions & 6 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,13 +99,19 @@ def __init__(self):
8899
self.face = {}
89100
self.facedata = {}
90101
self.edgedata = {}
91-
self.attributes = {'name': 'Mesh'}
92-
self.default_vertex_attributes = {'x': 0.0, 'y': 0.0, 'z': 0.0}
102+
self.attributes = {'name': name or 'HalfEdge'}
103+
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):
97-
tpl = "<Mesh with {} vertices, {} faces, {} edges>"
114+
tpl = "<HalfEdge with {} vertices, {} faces, {} edges>"
98115
return tpl.format(self.number_of_vertices(), self.number_of_faces(), self.number_of_edges())
99116

100117
# --------------------------------------------------------------------------
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .halfface import HalfFace # noqa: F401

0 commit comments

Comments
 (0)