Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas_rhino.drawing.draw_breps` to assume provided polygon is closed and automatically add missing corner to polycurve constructor.
* Changed conversion of edges and faces to uniques keys for the data dicts to use the string representation of a sorted tuple of identifiers.
* Added `dtype` to JSON decoding error message.
* Moved `compas.datastructures.mesh.core.halfedge.HalfEdge` to `compas.datastructures.halfedge.halfedge.HalfEdge`
* Moved `compas.datastructures.network.core.graph.Graph` to `compas.datastructures.graph.graph.Graph`.

### Removed

* Removed `compas.datastructures.mesh.core.mesh.BaseMesh`.

* Removed `compas.datastructures.BaseNetwork`.

## [1.7.1] 2021-06-14

### Added
Expand Down
78 changes: 32 additions & 46 deletions src/compas/datastructures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@

.. currentmodule:: compas.datastructures

Network
=======

Classes
-------
=======

.. autosummary::
:toctree: generated/
:nosignatures:

Datastructure
Graph
HalfEdge
HalfFace
Mesh
Network
VolMesh


Functions
---------
=========

Network
-------

.. autosummary::
:toctree: generated/
Expand Down Expand Up @@ -47,10 +53,6 @@
network_transform
network_transformed


CPython-only
------------

.. autosummary::
:toctree: generated/
:nosignatures:
Expand All @@ -62,17 +64,7 @@


Mesh
====

.. autosummary::
:toctree: generated/
:nosignatures:

Mesh


Functions
---------
----

.. autosummary::
:toctree: generated/
Expand Down Expand Up @@ -142,10 +134,6 @@
trimesh_subdivide_loop
trimesh_swap_edge


CPython-only
------------

.. autosummary::
:toctree: generated/
:nosignatures:
Expand All @@ -171,21 +159,8 @@


VolMesh
=======

Classes
-------

.. autosummary::
:toctree: generated/
:nosignatures:

VolMesh


Functions
---------

.. autosummary::
:toctree: generated/
:nosignatures:
Expand All @@ -200,9 +175,11 @@
import compas

from .datastructure import Datastructure

from .graph import (
Graph
)
from .network import (
BaseNetwork, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
Graph,
Network,
network_complement,
network_count_crossings,
Expand All @@ -226,9 +203,10 @@
network_transform,
network_transformed,
)
from .halfedge import (
HalfEdge
)
from .mesh import (
BaseMesh, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
HalfEdge,
Mesh,
mesh_add_vertex_to_face_edge,
mesh_bounding_box_xy,
Expand Down Expand Up @@ -294,9 +272,10 @@
trimesh_subdivide_loop,
trimesh_swap_edge,
)
from .halfface import (
HalfFace
)
from .volmesh import (
BaseVolMesh, # NOTE: this class being in the stable API is something we should deprecate before 2.x release
HalfFace,
VolMesh,
volmesh_bounding_box,
volmesh_transform,
Expand Down Expand Up @@ -331,11 +310,16 @@
trimesh_vertexarea_matrix,
)

BaseNetwork = Network
BaseMesh = Mesh
BaseVolMesh = VolMesh

__all__ = [
'Datastructure',
# Graphs
'Graph',
# Networks
'BaseNetwork',
'Graph',
'Network',
'network_complement',
'network_count_crossings',
Expand All @@ -358,9 +342,10 @@
'network_split_edge',
'network_transform',
'network_transformed',
# HalfEdge
'HalfEdge',
# Meshes
'BaseMesh',
'HalfEdge',
'Mesh',
'mesh_add_vertex_to_face_edge',
'mesh_bounding_box_xy',
Expand Down Expand Up @@ -425,9 +410,10 @@
'trimesh_split_edge',
'trimesh_subdivide_loop',
'trimesh_swap_edge',
# HalfFace
'HalfFace',
# Volumetric Meshes
'BaseVolMesh',
'HalfFace',
'VolMesh',
'volmesh_bounding_box',
'volmesh_transform',
Expand Down
1 change: 1 addition & 0 deletions src/compas/datastructures/datastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class Datastructure(Data):
"""Base class for all data structures."""

def __init__(self):
super(Datastructure, self).__init__()
1 change: 1 addition & 0 deletions src/compas/datastructures/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .graph import Graph # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
class Graph(Datastructure):
"""Base graph data structure for describing the topological relationships between nodes connected by edges.

Parameters
----------
name: str, optional
The name of the graph.
Defaults to "Graph".
default_node_attributes: dict, optional
Default values for node attributes.
default_edge_attributes: dict, optional
Default values for edge attributes.

Attributes
----------
node : dict
Expand Down Expand Up @@ -65,18 +75,22 @@ def DATASCHEMA(self):
def JSONSCHEMANAME(self):
return 'graph'

def __init__(self):
def __init__(self, name=None, default_node_attributes=None, default_edge_attributes=None):
super(Graph, self).__init__()
self._max_node = -1
self.attributes = {'name': 'Graph'}
self.attributes = {'name': name or 'Graph'}
self.node = {}
self.edge = {}
self.adjacency = {}
self.default_node_attributes = {}
self.default_edge_attributes = {}
if default_node_attributes:
self.default_node_attributes.update(default_node_attributes)
if default_edge_attributes:
self.default_edge_attributes.update(default_edge_attributes)

def __str__(self):
tpl = "<Network with {} nodes, {} edges>"
tpl = "<Graph with {} nodes, {} edges>"
return tpl.format(self.number_of_nodes(), self.number_of_edges())

# --------------------------------------------------------------------------
Expand Down Expand Up @@ -352,7 +366,7 @@ def index_uv(self):
# builders
# --------------------------------------------------------------------------

def add_node(self, key, attr_dict=None, **kwattr):
def add_node(self, key=None, attr_dict=None, **kwattr):
"""Add a node and specify its attributes (optional).

Parameters
Expand All @@ -367,7 +381,7 @@ def add_node(self, key, attr_dict=None, **kwattr):

Returns
-------
str
hashable
The key of the node.

Notes
Expand All @@ -382,6 +396,14 @@ def add_node(self, key, attr_dict=None, **kwattr):
--------
>>>
"""
if key is None:
key = self._max_node = self._max_node + 1
try:
if key > self._max_node:
self._max_node = key
except (ValueError, TypeError):
pass

if key not in self.node:
self.node[key] = {}
self.edge[key] = {}
Expand Down
1 change: 1 addition & 0 deletions src/compas/datastructures/halfedge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .halfedge import HalfEdge # noqa: F401
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@


class HalfEdge(Datastructure):
"""Base half-edge data structure for representing meshes.
"""Base half-edge data structure for representing the topology of open oor closed surface meshes.

Parameters
----------
name: str, optional
The name of the graph.
Defaults to "Graph".
default_vertex_attributes: dict, optional
Default values for vertex attributes.
default_edge_attributes: dict, optional
Default values for edge attributes.
default_face_attributes: dict, optional
Default values for face attributes.

Attributes
----------
Expand Down Expand Up @@ -51,7 +63,6 @@ def DATASCHEMA(self):
"vertex": schema.And(
dict,
is_sequence_of_uint,
# lambda x: all(('x' in attr and 'y' in attr and 'z' in attr) for attr in x.values())
),
"face": schema.And(
dict,
Expand Down Expand Up @@ -79,7 +90,7 @@ def DATASCHEMA(self):
def JSONSCHEMANAME(self):
return 'halfedge'

def __init__(self):
def __init__(self, name=None, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None):
super(HalfEdge, self).__init__()
self._max_vertex = -1
self._max_face = -1
Expand All @@ -88,13 +99,19 @@ def __init__(self):
self.face = {}
self.facedata = {}
self.edgedata = {}
self.attributes = {'name': 'Mesh'}
self.default_vertex_attributes = {'x': 0.0, 'y': 0.0, 'z': 0.0}
self.attributes = {'name': name or 'HalfEdge'}
self.default_vertex_attributes = {}
self.default_edge_attributes = {}
self.default_face_attributes = {}
if default_vertex_attributes:
self.default_vertex_attributes.update(default_vertex_attributes)
if default_edge_attributes:
self.default_edge_attributes.update(default_edge_attributes)
if default_face_attributes:
self.default_face_attributes.update(default_face_attributes)

def __str__(self):
tpl = "<Mesh with {} vertices, {} faces, {} edges>"
tpl = "<HalfEdge with {} vertices, {} faces, {} edges>"
return tpl.format(self.number_of_vertices(), self.number_of_faces(), self.number_of_edges())

# --------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/compas/datastructures/halfface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .halfface import HalfFace # noqa: F401
Loading