topologicpy 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topologicpy/Aperture.py +3 -3
- topologicpy/Cluster.py +24 -6
- topologicpy/Context.py +19 -19
- topologicpy/DGL.py +620 -453
- topologicpy/Edge.py +36 -31
- topologicpy/Face.py +120 -73
- topologicpy/Graph.py +338 -64
- topologicpy/Plotly.py +122 -16
- topologicpy/Topology.py +26 -23
- topologicpy/Vertex.py +35 -22
- topologicpy/Wire.py +114 -44
- topologicpy/__init__.py +1 -1
- {topologicpy-0.3.0.dist-info → topologicpy-0.3.2.dist-info}/METADATA +1 -1
- {topologicpy-0.3.0.dist-info → topologicpy-0.3.2.dist-info}/RECORD +17 -17
- {topologicpy-0.3.0.dist-info → topologicpy-0.3.2.dist-info}/LICENSE +0 -0
- {topologicpy-0.3.0.dist-info → topologicpy-0.3.2.dist-info}/WHEEL +0 -0
- {topologicpy-0.3.0.dist-info → topologicpy-0.3.2.dist-info}/top_level.txt +0 -0
topologicpy/Graph.py
CHANGED
|
@@ -4,6 +4,7 @@ from topologicpy.Dictionary import Dictionary
|
|
|
4
4
|
from topologicpy.Topology import Topology
|
|
5
5
|
import random
|
|
6
6
|
import time
|
|
7
|
+
import networkx as nx
|
|
7
8
|
|
|
8
9
|
class Graph:
|
|
9
10
|
@staticmethod
|
|
@@ -28,9 +29,8 @@ class Graph:
|
|
|
28
29
|
from topologicpy.Topology import Topology
|
|
29
30
|
if not isinstance(graph, topologic.Graph):
|
|
30
31
|
return None
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
vertices = Topology.SubTopologies(topology, "vertex")
|
|
32
|
+
|
|
33
|
+
vertices = Graph.Vertices(graph)
|
|
34
34
|
order = len(vertices)
|
|
35
35
|
matrix = []
|
|
36
36
|
for i in range(order):
|
|
@@ -39,13 +39,11 @@ class Graph:
|
|
|
39
39
|
tempRow.append(0)
|
|
40
40
|
matrix.append(tempRow)
|
|
41
41
|
for i in range(order):
|
|
42
|
-
|
|
43
|
-
adjVertices = Graph.AdjacentVertices(graph, v)
|
|
42
|
+
adjVertices = Graph.AdjacentVertices(graph, vertices[i])
|
|
44
43
|
for adjVertex in adjVertices:
|
|
45
|
-
adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=
|
|
46
|
-
if adjIndex:
|
|
47
|
-
|
|
48
|
-
matrix[i][adjIndex] = 1
|
|
44
|
+
adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=True, tolerance=0.01)
|
|
45
|
+
if not adjIndex == None:
|
|
46
|
+
matrix[i][adjIndex] = 1
|
|
49
47
|
return matrix
|
|
50
48
|
@staticmethod
|
|
51
49
|
def AdjacencyList(graph, tolerance=0.0001):
|
|
@@ -68,9 +66,7 @@ class Graph:
|
|
|
68
66
|
from topologicpy.Topology import Topology
|
|
69
67
|
if not isinstance(graph, topologic.Graph):
|
|
70
68
|
return None
|
|
71
|
-
|
|
72
|
-
topology = Topology.SelfMerge(topology)
|
|
73
|
-
vertices = Topology.SubTopologies(topology, "vertex")
|
|
69
|
+
vertices = Graph.Vertices(graph)
|
|
74
70
|
order = len(vertices)
|
|
75
71
|
adjList = []
|
|
76
72
|
for i in range(order):
|
|
@@ -78,7 +74,7 @@ class Graph:
|
|
|
78
74
|
v = Graph.NearestVertex(graph, vertices[i])
|
|
79
75
|
adjVertices = Graph.AdjacentVertices(graph, v)
|
|
80
76
|
for adjVertex in adjVertices:
|
|
81
|
-
adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=
|
|
77
|
+
adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=True, tolerance=tolerance)
|
|
82
78
|
if not adjIndex == None:
|
|
83
79
|
tempRow.append(adjIndex)
|
|
84
80
|
tempRow.sort()
|
|
@@ -320,7 +316,7 @@ class Graph:
|
|
|
320
316
|
return [graphs, labels]
|
|
321
317
|
'''
|
|
322
318
|
@staticmethod
|
|
323
|
-
def ByTopology(topology, direct=True, directApertures=False, viaSharedTopologies=False, viaSharedApertures=False, toExteriorTopologies=False, toExteriorApertures=False, toContents=False, useInternalVertex=True, storeBRep=False, tolerance=0.0001):
|
|
319
|
+
def ByTopology(topology, direct=True, directApertures=False, viaSharedTopologies=False, viaSharedApertures=False, toExteriorTopologies=False, toExteriorApertures=False, toContents=False, toOutposts=False, idKey="TOPOLOGIC_ID", outpostsKey="outposts", useInternalVertex=True, storeBRep=False, tolerance=0.0001):
|
|
324
320
|
"""
|
|
325
321
|
Creates a graph.See https://en.wikipedia.org/wiki/Graph_(discrete_mathematics).
|
|
326
322
|
|
|
@@ -342,6 +338,12 @@ class Graph:
|
|
|
342
338
|
If set to True, connect the subtopologies to their exterior apertures. The default is False.
|
|
343
339
|
toContents : bool , optional
|
|
344
340
|
If set to True, connect the subtopologies to their contents. The default is False.
|
|
341
|
+
toOutposts : bool , optional
|
|
342
|
+
If set to True, connect the topology to the list specified in its outposts. The default is False.
|
|
343
|
+
idKey : str , optional
|
|
344
|
+
The key to use to find outpost by ID. It is case insensitive. The default is "TOPOLOGIC_ID".
|
|
345
|
+
outpostsKey : str , optional
|
|
346
|
+
The key to use to find the list of outposts. It is case insensitive. The default is "outposts".
|
|
345
347
|
useInternalVertex : bool , optional
|
|
346
348
|
If set to True, use an internal vertex to represent the subtopology. Otherwise, use its centroid. The default is False.
|
|
347
349
|
storeBRep : bool , optional
|
|
@@ -356,6 +358,7 @@ class Graph:
|
|
|
356
358
|
|
|
357
359
|
"""
|
|
358
360
|
from topologicpy.Dictionary import Dictionary
|
|
361
|
+
from topologicpy.Cluster import Cluster
|
|
359
362
|
from topologicpy.Topology import Topology
|
|
360
363
|
|
|
361
364
|
def mergeDictionaries(sources):
|
|
@@ -431,9 +434,33 @@ class Graph:
|
|
|
431
434
|
if len(sinkKeys) > 0 and len(sinkValues) > 0:
|
|
432
435
|
return Dictionary.ByKeysValues(sinkKeys, sinkValues)
|
|
433
436
|
return None
|
|
434
|
-
|
|
437
|
+
|
|
438
|
+
def outpostsByID(topologies, ids, idKey="TOPOLOGIC_ID"):
|
|
439
|
+
returnList = []
|
|
440
|
+
idList = []
|
|
441
|
+
for t in topologies:
|
|
442
|
+
d = Topology.Dictionary(t)
|
|
443
|
+
keys = Dictionary.Keys(d)
|
|
444
|
+
k = None
|
|
445
|
+
for key in keys:
|
|
446
|
+
if key.lower() == idKey.lower():
|
|
447
|
+
k = key
|
|
448
|
+
if k:
|
|
449
|
+
id = Dictionary.ValueAtKey(d, k)
|
|
450
|
+
else:
|
|
451
|
+
id = ""
|
|
452
|
+
idList.append(id)
|
|
453
|
+
for id in ids:
|
|
454
|
+
try:
|
|
455
|
+
index = idList.index(id)
|
|
456
|
+
except:
|
|
457
|
+
index = None
|
|
458
|
+
if index:
|
|
459
|
+
returnList.append(topologies[index])
|
|
460
|
+
return returnList
|
|
461
|
+
|
|
435
462
|
def processCellComplex(item):
|
|
436
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
463
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
437
464
|
edges = []
|
|
438
465
|
vertices = []
|
|
439
466
|
cellmat = []
|
|
@@ -506,6 +533,37 @@ class Graph:
|
|
|
506
533
|
if mDict:
|
|
507
534
|
e.SetDictionary(mDict)
|
|
508
535
|
edges.append(e)
|
|
536
|
+
if toOutposts and others:
|
|
537
|
+
d = Topology.Dictionary(topology)
|
|
538
|
+
keys = Dictionary.Keys(d)
|
|
539
|
+
k = None
|
|
540
|
+
for key in keys:
|
|
541
|
+
if key.lower() == outpostsKey.lower():
|
|
542
|
+
k = key
|
|
543
|
+
if k:
|
|
544
|
+
ids = Dictionary.ValueAtKey(k)
|
|
545
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
546
|
+
for outpost in outposts:
|
|
547
|
+
if useInternalVertex == True:
|
|
548
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
549
|
+
vcc = Topology.InternalVertex(topology, tolerance)
|
|
550
|
+
else:
|
|
551
|
+
vop = Topology.CenterOfMass(outpost)
|
|
552
|
+
vcc = Topology.CenterOfMass(topology)
|
|
553
|
+
d1 = Topology.Dictionary(vcc)
|
|
554
|
+
if storeBRep:
|
|
555
|
+
d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [topology.String(), topology.Type(), topology.GetTypeAsString()])
|
|
556
|
+
d3 = mergeDictionaries2([d1, d2])
|
|
557
|
+
_ = vcc.SetDictionary(d3)
|
|
558
|
+
else:
|
|
559
|
+
_ = vcc.SetDictionary(d1)
|
|
560
|
+
vertices.append(vcc)
|
|
561
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vcc, vop)
|
|
562
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
563
|
+
_ = tempe.SetDictionary(tempd)
|
|
564
|
+
edges.append(tempe)
|
|
565
|
+
|
|
566
|
+
|
|
509
567
|
cells = []
|
|
510
568
|
_ = topology.Cells(None, cells)
|
|
511
569
|
if (viaSharedTopologies == True) or (viaSharedApertures == True) or (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
|
|
@@ -698,10 +756,10 @@ class Graph:
|
|
|
698
756
|
else:
|
|
699
757
|
_ = vCell.SetDictionary(d1)
|
|
700
758
|
vertices.append(vCell)
|
|
701
|
-
return
|
|
759
|
+
return [vertices,edges]
|
|
702
760
|
|
|
703
761
|
def processCell(item):
|
|
704
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
762
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
705
763
|
vertices = []
|
|
706
764
|
edges = []
|
|
707
765
|
|
|
@@ -718,6 +776,25 @@ class Graph:
|
|
|
718
776
|
_ = vCell.SetDictionary(d1)
|
|
719
777
|
vertices.append(vCell)
|
|
720
778
|
|
|
779
|
+
if toOutposts and others:
|
|
780
|
+
d = Topology.Dictionary(topology)
|
|
781
|
+
keys = Dictionary.Keys(d)
|
|
782
|
+
k = None
|
|
783
|
+
for key in keys:
|
|
784
|
+
if key.lower() == outpostsKey.lower():
|
|
785
|
+
k = key
|
|
786
|
+
if k:
|
|
787
|
+
ids = Dictionary.ValueAtKey(d, k)
|
|
788
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
789
|
+
for outpost in outposts:
|
|
790
|
+
if useInternalVertex == True:
|
|
791
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
792
|
+
else:
|
|
793
|
+
vop = Topology.CenterOfMass(outpost)
|
|
794
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vCell, vop)
|
|
795
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
796
|
+
_ = tempe.SetDictionary(tempd)
|
|
797
|
+
edges.append(tempe)
|
|
721
798
|
if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
|
|
722
799
|
faces = []
|
|
723
800
|
_ = topology.Faces(None, faces)
|
|
@@ -809,11 +886,10 @@ class Graph:
|
|
|
809
886
|
tempd = Dictionary.ByKeysValues(["relationship"],["To Contents"])
|
|
810
887
|
_ = tempe.SetDictionary(tempd)
|
|
811
888
|
edges.append(tempe)
|
|
812
|
-
|
|
813
|
-
return topologic.Graph.ByVerticesEdges(vertices, edges)
|
|
889
|
+
return [vertices, edges]
|
|
814
890
|
|
|
815
891
|
def processShell(item):
|
|
816
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
892
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
817
893
|
graph = None
|
|
818
894
|
edges = []
|
|
819
895
|
vertices = []
|
|
@@ -1068,11 +1144,39 @@ class Graph:
|
|
|
1068
1144
|
else:
|
|
1069
1145
|
_ = vFace.SetDictionary(d1)
|
|
1070
1146
|
vertices.append(vFace)
|
|
1071
|
-
|
|
1147
|
+
if toOutposts and others:
|
|
1148
|
+
d = Topology.Dictionary(topology)
|
|
1149
|
+
keys = Dictionary.Keys(d)
|
|
1150
|
+
k = None
|
|
1151
|
+
for key in keys:
|
|
1152
|
+
if key.lower() == outpostsKey.lower():
|
|
1153
|
+
k = key
|
|
1154
|
+
if k:
|
|
1155
|
+
ids = Dictionary.ValueAtKey(k)
|
|
1156
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
1157
|
+
for outpost in outposts:
|
|
1158
|
+
if useInternalVertex == True:
|
|
1159
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
1160
|
+
vcc = Topology.InternalVertex(topology, tolerance)
|
|
1161
|
+
else:
|
|
1162
|
+
vop = Topology.CenterOfMass(outpost)
|
|
1163
|
+
vcc = Topology.CenterOfMass(topology)
|
|
1164
|
+
d1 = Topology.Dictionary(vcc)
|
|
1165
|
+
if storeBRep:
|
|
1166
|
+
d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [topology.String(), topology.Type(), topology.GetTypeAsString()])
|
|
1167
|
+
d3 = mergeDictionaries2([d1, d2])
|
|
1168
|
+
_ = vcc.SetDictionary(d3)
|
|
1169
|
+
else:
|
|
1170
|
+
_ = vcc.SetDictionary(d1)
|
|
1171
|
+
vertices.append(vcc)
|
|
1172
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vcc, vop)
|
|
1173
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
1174
|
+
_ = tempe.SetDictionary(tempd)
|
|
1175
|
+
edges.append(tempe)
|
|
1176
|
+
return [vertices, edges]
|
|
1072
1177
|
|
|
1073
1178
|
def processFace(item):
|
|
1074
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
1075
|
-
|
|
1179
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
1076
1180
|
graph = None
|
|
1077
1181
|
vertices = []
|
|
1078
1182
|
edges = []
|
|
@@ -1089,6 +1193,25 @@ class Graph:
|
|
|
1089
1193
|
else:
|
|
1090
1194
|
_ = vFace.SetDictionary(d1)
|
|
1091
1195
|
vertices.append(vFace)
|
|
1196
|
+
if toOutposts and others:
|
|
1197
|
+
d = Topology.Dictionary(topology)
|
|
1198
|
+
keys = Dictionary.Keys(d)
|
|
1199
|
+
k = None
|
|
1200
|
+
for key in keys:
|
|
1201
|
+
if key.lower() == outpostsKey.lower():
|
|
1202
|
+
k = key
|
|
1203
|
+
if k:
|
|
1204
|
+
ids = Dictionary.ValueAtKey(d, k)
|
|
1205
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
1206
|
+
for outpost in outposts:
|
|
1207
|
+
if useInternalVertex == True:
|
|
1208
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
1209
|
+
else:
|
|
1210
|
+
vop = Topology.CenterOfMass(outpost)
|
|
1211
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vFace, vop)
|
|
1212
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
1213
|
+
_ = tempe.SetDictionary(tempd)
|
|
1214
|
+
edges.append(tempe)
|
|
1092
1215
|
if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
|
|
1093
1216
|
fEdges = []
|
|
1094
1217
|
_ = topology.Edges(None, fEdges)
|
|
@@ -1181,10 +1304,10 @@ class Graph:
|
|
|
1181
1304
|
tempd = Dictionary.ByKeysValues(["relationship"],["To Contents"])
|
|
1182
1305
|
_ = tempe.SetDictionary(tempd)
|
|
1183
1306
|
edges.append(tempe)
|
|
1184
|
-
return
|
|
1307
|
+
return [vertices, edges]
|
|
1185
1308
|
|
|
1186
1309
|
def processWire(item):
|
|
1187
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
1310
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
1188
1311
|
graph = None
|
|
1189
1312
|
edges = []
|
|
1190
1313
|
vertices = []
|
|
@@ -1438,10 +1561,41 @@ class Graph:
|
|
|
1438
1561
|
else:
|
|
1439
1562
|
_ = vEdge.SetDictionary(d1)
|
|
1440
1563
|
vertices.append(vEdge)
|
|
1441
|
-
|
|
1564
|
+
|
|
1565
|
+
if toOutposts and others:
|
|
1566
|
+
d = Topology.Dictionary(topology)
|
|
1567
|
+
keys = Dictionary.Keys(d)
|
|
1568
|
+
k = None
|
|
1569
|
+
for key in keys:
|
|
1570
|
+
if key.lower() == outpostsKey.lower():
|
|
1571
|
+
k = key
|
|
1572
|
+
if k:
|
|
1573
|
+
ids = Dictionary.ValueAtKey(k)
|
|
1574
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
1575
|
+
for outpost in outposts:
|
|
1576
|
+
if useInternalVertex == True:
|
|
1577
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
1578
|
+
vcc = Topology.InternalVertex(topology, tolerance)
|
|
1579
|
+
else:
|
|
1580
|
+
vop = Topology.CenterOfMass(outpost)
|
|
1581
|
+
vcc = Topology.CenterOfMass(topology)
|
|
1582
|
+
d1 = Topology.Dictionary(vcc)
|
|
1583
|
+
if storeBRep:
|
|
1584
|
+
d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [topology.String(), topology.Type(), topology.GetTypeAsString()])
|
|
1585
|
+
d3 = mergeDictionaries2([d1, d2])
|
|
1586
|
+
_ = vcc.SetDictionary(d3)
|
|
1587
|
+
else:
|
|
1588
|
+
_ = vcc.SetDictionary(d1)
|
|
1589
|
+
vertices.append(vcc)
|
|
1590
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vcc, vop)
|
|
1591
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
1592
|
+
_ = tempe.SetDictionary(tempd)
|
|
1593
|
+
edges.append(tempe)
|
|
1594
|
+
|
|
1595
|
+
return [vertices, edges]
|
|
1442
1596
|
|
|
1443
1597
|
def processEdge(item):
|
|
1444
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
1598
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
1445
1599
|
graph = None
|
|
1446
1600
|
vertices = []
|
|
1447
1601
|
edges = []
|
|
@@ -1465,6 +1619,26 @@ class Graph:
|
|
|
1465
1619
|
|
|
1466
1620
|
vertices.append(vEdge)
|
|
1467
1621
|
|
|
1622
|
+
if toOutposts and others:
|
|
1623
|
+
d = Topology.Dictionary(topology)
|
|
1624
|
+
keys = Dictionary.Keys(d)
|
|
1625
|
+
k = None
|
|
1626
|
+
for key in keys:
|
|
1627
|
+
if key.lower() == outpostsKey.lower():
|
|
1628
|
+
k = key
|
|
1629
|
+
if k:
|
|
1630
|
+
ids = Dictionary.ValueAtKey(d, k)
|
|
1631
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
1632
|
+
for outpost in outposts:
|
|
1633
|
+
if useInternalVertex == True:
|
|
1634
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
1635
|
+
else:
|
|
1636
|
+
vop = Topology.CenterOfMass(outpost)
|
|
1637
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(vEdge, vop)
|
|
1638
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
1639
|
+
_ = tempe.SetDictionary(tempd)
|
|
1640
|
+
edges.append(tempe)
|
|
1641
|
+
|
|
1468
1642
|
if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
|
|
1469
1643
|
eVertices = []
|
|
1470
1644
|
_ = topology.Vertices(None, eVertices)
|
|
@@ -1536,34 +1710,14 @@ class Graph:
|
|
|
1536
1710
|
tempd = Dictionary.ByKeysValues(["relationship"],["To Exterior Apertures"])
|
|
1537
1711
|
_ = tempe.SetDictionary(tempd)
|
|
1538
1712
|
edges.append(tempe)
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
_ = topology.Contents(contents)
|
|
1542
|
-
for content in contents:
|
|
1543
|
-
if useInternalVertex == True:
|
|
1544
|
-
vst = Topology.InternalVertex(content, tolerance)
|
|
1545
|
-
else:
|
|
1546
|
-
vst = content.CenterOfMass()
|
|
1547
|
-
d1 = content.GetDictionary()
|
|
1548
|
-
vst = topologic.Vertex.ByCoordinates(vst.X()+(tolerance*100), vst.Y()+(tolerance*100), vst.Z()+(tolerance*100))
|
|
1549
|
-
if storeBRep:
|
|
1550
|
-
d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [content.String(), content.Type(), content.GetTypeAsString()])
|
|
1551
|
-
d3 = mergeDictionaries2([d1, d2])
|
|
1552
|
-
_ = vst.SetDictionary(d3)
|
|
1553
|
-
else:
|
|
1554
|
-
_ = vst.SetDictionary(d1)
|
|
1555
|
-
vertices.append(vst)
|
|
1556
|
-
tempe = topologic.Edge.ByStartVertexEndVertex(vEdge, vst)
|
|
1557
|
-
tempd = Dictionary.ByKeysValues(["relationship"],["To Contents"])
|
|
1558
|
-
_ = tempe.SetDictionary(tempd)
|
|
1559
|
-
edges.append(tempe)
|
|
1560
|
-
graph = topologic.Graph.ByVerticesEdges(vertices, edges)
|
|
1561
|
-
return graph
|
|
1713
|
+
|
|
1714
|
+
return [vertices, edges]
|
|
1562
1715
|
|
|
1563
1716
|
def processVertex(item):
|
|
1564
|
-
topology, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, useInternalVertex, storeBRep, tolerance = item
|
|
1717
|
+
topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance = item
|
|
1565
1718
|
vertices = [topology]
|
|
1566
1719
|
edges = []
|
|
1720
|
+
|
|
1567
1721
|
if toContents:
|
|
1568
1722
|
contents = []
|
|
1569
1723
|
_ = topology.Contents(contents)
|
|
@@ -1585,32 +1739,92 @@ class Graph:
|
|
|
1585
1739
|
tempd = Dictionary.ByKeysValues(["relationship"],["To Contents"])
|
|
1586
1740
|
_ = tempe.SetDictionary(tempd)
|
|
1587
1741
|
edges.append(tempe)
|
|
1588
|
-
|
|
1742
|
+
|
|
1743
|
+
if toOutposts and others:
|
|
1744
|
+
d = Topology.Dictionary(topology)
|
|
1745
|
+
keys = Dictionary.Keys(d)
|
|
1746
|
+
k = None
|
|
1747
|
+
for key in keys:
|
|
1748
|
+
if key.lower() == outpostsKey.lower():
|
|
1749
|
+
k = key
|
|
1750
|
+
if k:
|
|
1751
|
+
ids = Dictionary.ValueAtKey(d, k)
|
|
1752
|
+
outposts = outpostsByID(others, ids, idKey)
|
|
1753
|
+
for outpost in outposts:
|
|
1754
|
+
if useInternalVertex == True:
|
|
1755
|
+
vop = Topology.InternalVertex(outpost, tolerance)
|
|
1756
|
+
else:
|
|
1757
|
+
vop = Topology.CenterOfMass(outpost)
|
|
1758
|
+
tempe = topologic.Edge.ByStartVertexEndVertex(topology, vop)
|
|
1759
|
+
tempd = Dictionary.ByKeysValues(["relationship"],["To Outposts"])
|
|
1760
|
+
_ = tempe.SetDictionary(tempd)
|
|
1761
|
+
edges.append(tempe)
|
|
1762
|
+
|
|
1763
|
+
return [vertices, edges]
|
|
1589
1764
|
|
|
1590
1765
|
|
|
1591
1766
|
if not isinstance(topology, topologic.Topology):
|
|
1592
1767
|
return None
|
|
1593
1768
|
graph = None
|
|
1594
|
-
item = [topology,
|
|
1769
|
+
item = [topology, None, None, None, None, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, None, useInternalVertex, storeBRep, tolerance]
|
|
1770
|
+
vertices = []
|
|
1771
|
+
edges = []
|
|
1595
1772
|
if isinstance(topology, topologic.CellComplex):
|
|
1596
|
-
|
|
1773
|
+
vertices, edges = processCellComplex(item)
|
|
1597
1774
|
elif isinstance(topology, topologic.Cell):
|
|
1598
|
-
|
|
1775
|
+
vertices, edges = processCell(item)
|
|
1599
1776
|
elif isinstance(topology, topologic.Shell):
|
|
1600
|
-
|
|
1777
|
+
vertices, edges = processShell(item)
|
|
1601
1778
|
elif isinstance(topology, topologic.Face):
|
|
1602
|
-
|
|
1779
|
+
vertices, edges = processFace(item)
|
|
1603
1780
|
elif isinstance(topology, topologic.Wire):
|
|
1604
|
-
|
|
1781
|
+
vertices, edges = processWire(item)
|
|
1605
1782
|
elif isinstance(topology, topologic.Edge):
|
|
1606
|
-
|
|
1783
|
+
vertices, edges = processEdge(item)
|
|
1607
1784
|
elif isinstance(topology, topologic.Vertex):
|
|
1608
|
-
|
|
1785
|
+
vertices, edges = processVertex(item)
|
|
1609
1786
|
elif isinstance(topology, topologic.Cluster):
|
|
1610
|
-
|
|
1787
|
+
c_cellComplexes = Topology.CellComplexes(topology)
|
|
1788
|
+
c_cells = Cluster.FreeCells(topology)
|
|
1789
|
+
c_shells = Cluster.FreeShells(topology)
|
|
1790
|
+
c_faces = Cluster.FreeFaces(topology)
|
|
1791
|
+
c_wires = Cluster.FreeWires(topology)
|
|
1792
|
+
c_edges = Cluster.FreeEdges(topology)
|
|
1793
|
+
c_vertices = Cluster.FreeVertices(topology)
|
|
1794
|
+
others = c_cellComplexes+c_cells+c_shells+c_faces+c_wires+c_edges+c_vertices
|
|
1795
|
+
parameters = [others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBRep, tolerance]
|
|
1796
|
+
|
|
1797
|
+
for t in c_cellComplexes:
|
|
1798
|
+
v, e = processCellComplex([t]+parameters)
|
|
1799
|
+
vertices += v
|
|
1800
|
+
edges += e
|
|
1801
|
+
for t in c_cells:
|
|
1802
|
+
v, e = processCell([t]+parameters)
|
|
1803
|
+
vertices += v
|
|
1804
|
+
edges += e
|
|
1805
|
+
for t in c_shells:
|
|
1806
|
+
v, e = processShell([t]+parameters)
|
|
1807
|
+
vertices += v
|
|
1808
|
+
edges += e
|
|
1809
|
+
for t in c_faces:
|
|
1810
|
+
v, e = processFace([t]+parameters)
|
|
1811
|
+
vertices += v
|
|
1812
|
+
edges += e
|
|
1813
|
+
for t in c_wires:
|
|
1814
|
+
v, e = processWire([t]+parameters)
|
|
1815
|
+
vertices += v
|
|
1816
|
+
edges += e
|
|
1817
|
+
for t in c_edges:
|
|
1818
|
+
v, e = processEdge([t]+parameters)
|
|
1819
|
+
vertices += v
|
|
1820
|
+
edges += e
|
|
1821
|
+
for t in c_vertices:
|
|
1822
|
+
v, e = processVertex([t]+parameters)
|
|
1823
|
+
vertices += v
|
|
1824
|
+
edges += e
|
|
1611
1825
|
else:
|
|
1612
|
-
|
|
1613
|
-
return
|
|
1826
|
+
return None
|
|
1827
|
+
return topologic.Graph.ByVerticesEdges(vertices, edges)
|
|
1614
1828
|
|
|
1615
1829
|
@staticmethod
|
|
1616
1830
|
def ByVerticesEdges(vertices, edges):
|
|
@@ -2188,6 +2402,66 @@ class Graph:
|
|
|
2188
2402
|
nearestVertex = aGraphVertex
|
|
2189
2403
|
return nearestVertex
|
|
2190
2404
|
|
|
2405
|
+
@staticmethod
|
|
2406
|
+
def NetworkXGraph(graph, tolerance=0.0001):
|
|
2407
|
+
"""
|
|
2408
|
+
converts the input graph into a NetworkX Graph. See http://networkx.org
|
|
2409
|
+
|
|
2410
|
+
Parameters
|
|
2411
|
+
----------
|
|
2412
|
+
graph : topologic.Graph
|
|
2413
|
+
The input graph.
|
|
2414
|
+
|
|
2415
|
+
Returns
|
|
2416
|
+
-------
|
|
2417
|
+
networkX Graph
|
|
2418
|
+
The created networkX Graph
|
|
2419
|
+
|
|
2420
|
+
"""
|
|
2421
|
+
from topologicpy.Vertex import Vertex
|
|
2422
|
+
from topologicpy.Edge import Edge
|
|
2423
|
+
from topologicpy.Topology import Topology
|
|
2424
|
+
from topologicpy.Dictionary import Dictionary
|
|
2425
|
+
import random
|
|
2426
|
+
|
|
2427
|
+
if not isinstance(graph, topologic.Graph):
|
|
2428
|
+
return None
|
|
2429
|
+
|
|
2430
|
+
nxGraph = nx.Graph()
|
|
2431
|
+
vertices = Graph.Vertices(graph)
|
|
2432
|
+
order = len(vertices)
|
|
2433
|
+
nodes = []
|
|
2434
|
+
for i in range(order):
|
|
2435
|
+
v = vertices[i]
|
|
2436
|
+
d = Topology.Dictionary(vertices[i])
|
|
2437
|
+
if d:
|
|
2438
|
+
keys = Dictionary.Keys(d)
|
|
2439
|
+
if not keys:
|
|
2440
|
+
keys = []
|
|
2441
|
+
values = Dictionary.Values(d)
|
|
2442
|
+
if not values:
|
|
2443
|
+
values = []
|
|
2444
|
+
keys += ["x","y","z"]
|
|
2445
|
+
import random
|
|
2446
|
+
values += [Vertex.X(v), Vertex.Y(v), Vertex.Z(v)]
|
|
2447
|
+
d = Dictionary.ByKeysValues(keys,values)
|
|
2448
|
+
pythonD = Dictionary.PythonDictionary(d)
|
|
2449
|
+
nodes.append((i, pythonD))
|
|
2450
|
+
else:
|
|
2451
|
+
nodes.append((i, {"name": str(i)}))
|
|
2452
|
+
nxGraph.add_nodes_from(nodes)
|
|
2453
|
+
for i in range(order):
|
|
2454
|
+
v = vertices[i]
|
|
2455
|
+
adjVertices = Graph.AdjacentVertices(graph, vertices[i])
|
|
2456
|
+
for adjVertex in adjVertices:
|
|
2457
|
+
adjIndex = Vertex.Index(vertex=adjVertex, vertices=vertices, strict=True, tolerance=tolerance)
|
|
2458
|
+
if not adjIndex == None:
|
|
2459
|
+
nxGraph.add_edge(i,adjIndex, length=(Vertex.Distance(v, adjVertex)))
|
|
2460
|
+
|
|
2461
|
+
pos=nx.spring_layout(nxGraph, k=0.2)
|
|
2462
|
+
nx.set_node_attributes(nxGraph, pos, "pos")
|
|
2463
|
+
return nxGraph
|
|
2464
|
+
|
|
2191
2465
|
@staticmethod
|
|
2192
2466
|
def Order(graph):
|
|
2193
2467
|
"""
|