22from __future__ import division
33from __future__ import print_function
44
5- # from itertools import product
65from random import sample
76
87from compas .datastructures import Mesh
2827from compas .geometry import normal_polygon
2928from compas .geometry import normalize_vector
3029from compas .geometry import volume_polyhedron
31-
32- # from compas.topology import face_adjacency
3330from compas .geometry import add_vectors
3431from compas .geometry import bestfit_plane
3532from compas .geometry import project_point_plane
3633from compas .geometry import scale_vector
3734from compas .geometry import subtract_vectors
3835from compas .geometry import bounding_box
3936
40- # from compas.geometry import transform_points
41-
42- # from compas.utilities import linspace
4337from compas .utilities import pairwise
4438
4539from compas .tolerance import TOL
@@ -91,6 +85,7 @@ class CellNetwork(Datastructure):
9185 DATASCHEMA = {
9286 "type" : "object" ,
9387 "properties" : {
88+ "attributes" : {"type" : "object" },
9489 "dva" : {"type" : "object" },
9590 "dea" : {"type" : "object" },
9691 "dfa" : {"type" : "object" },
@@ -100,6 +95,28 @@ class CellNetwork(Datastructure):
10095 "patternProperties" : {"^[0-9]+$" : {"type" : "object" }},
10196 "additionalProperties" : False ,
10297 },
98+ "edge" : {
99+ "type" : "object" ,
100+ "patternProperties" : {
101+ "^[0-9]+$" : {
102+ "type" : "object" ,
103+ "patternProperties" : {"^[0-9]+$" : {"type" : "object" }},
104+ "additionalProperties" : False ,
105+ }
106+ },
107+ "additionalProperties" : False ,
108+ },
109+ "face" : {
110+ "type" : "object" ,
111+ "patternProperties" : {
112+ "^[0-9]+$" : {
113+ "type" : "array" ,
114+ "items" : {"type" : "integer" , "minimum" : 0 },
115+ "minItems" : 3 ,
116+ }
117+ },
118+ "additionalProperties" : False ,
119+ },
103120 "cell" : {
104121 "type" : "object" ,
105122 "patternProperties" : {
@@ -115,11 +132,6 @@ class CellNetwork(Datastructure):
115132 },
116133 "additionalProperties" : False ,
117134 },
118- "edge_data" : {
119- "type" : "object" ,
120- "patternProperties" : {"^\\ ([0-9]+, [0-9]+\\ )$" : {"type" : "object" }},
121- "additionalProperties" : False ,
122- },
123135 "face_data" : {
124136 "type" : "object" ,
125137 "patternProperties" : {"^\\ ([0-9]+(, [0-9]+){3, }\\ )$" : {"type" : "object" }},
@@ -140,8 +152,9 @@ class CellNetwork(Datastructure):
140152 "dfa" ,
141153 "dca" ,
142154 "vertex" ,
155+ "edge" ,
156+ "face" ,
143157 "cell" ,
144- "edge_data" ,
145158 "face_data" ,
146159 "cell_data" ,
147160 "max_vertex" ,
@@ -158,7 +171,7 @@ def __init__(
158171 default_cell_attributes = None ,
159172 ** kwargs
160173 ):
161- super (Datastructure , self ).__init__ (** kwargs )
174+ super (CellNetwork , self ).__init__ (** kwargs )
162175 self ._max_vertex = - 1
163176 self ._max_face = - 1
164177 self ._max_cell = - 1
@@ -243,19 +256,20 @@ def from_data(cls, data):
243256 dfa = data .get ("dfa" ) or {}
244257 dca = data .get ("dca" ) or {}
245258
259+ attributes = data .get ("attributes" ) or {}
260+
246261 cell_network = cls (
247262 default_vertex_attributes = dva ,
248263 default_edge_attributes = dea ,
249264 default_face_attributes = dfa ,
250265 default_cell_attributes = dca ,
266+ ** attributes
251267 )
252268
253- cell_network .attributes .update (data .get ("attributes" ) or {})
254-
255- vertex = data .get ("vertex" ) or {}
256- edge = data .get ("edge" ) or {}
257- face = data .get ("face" ) or {}
258- cell = data .get ("cell" ) or {}
269+ vertex = data ["vertex" ] or {}
270+ edge = data ["edge" ] or {}
271+ face = data ["face" ] or {}
272+ cell = data ["cell" ] or {}
259273
260274 for key , attr in iter (vertex .items ()):
261275 cell_network .add_vertex (key = key , attr_dict = attr )
0 commit comments