topologicpy 0.2.2__py3-none-any.whl → 0.2.3__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.
@@ -5,7 +5,7 @@ import math
5
5
  class CellComplex(topologic.CellComplex):
6
6
  @staticmethod
7
7
  def Box(origin=None, width=1, length=1, height=1, uSides=2, vSides=2, wSides=2,
8
- dirX=0, dirY=0, dirZ=1, placement="center"):
8
+ direction=[0,0,1], placement="center"):
9
9
  """
10
10
  Creates a box with internal cells.
11
11
 
@@ -25,12 +25,8 @@ class CellComplex(topologic.CellComplex):
25
25
  The number of sides along the length. The default is 1.
26
26
  wSides : int , optional
27
27
  The number of sides along the height. The default is 1.
28
- dirX : float , optional
29
- The X component of the vector representing the up direction of the box. The default is 0.
30
- dirY : float , optional
31
- The Y component of the vector representing the up direction of the box. The default is 0.
32
- dirZ : float , optional
33
- The Z component of the vector representing the up direction of the box. The default is 1.
28
+ direction : list , optional
29
+ The vector representing the up direction of the box. The default is [0,0,1].
34
30
  placement : str , optional
35
31
  The description of the placement of the origin of the box. This can be "bottom", "center", or "lowerleft". It is case insensitive. The default is "center".
36
32
 
@@ -41,7 +37,7 @@ class CellComplex(topologic.CellComplex):
41
37
 
42
38
  """
43
39
  return CellComplex.Prism(origin=origin, width=width, length=length, height=height, uSides=uSides, vSides=vSides, wSides=wSides,
44
- dirX=dirX, dirY=dirY, dirZ=dirZ, placement=placement)
40
+ direction=direction, placement=placement)
45
41
  @staticmethod
46
42
  def ByCells(cells, tolerance=0.0001):
47
43
  """
@@ -135,24 +131,30 @@ class CellComplex(topologic.CellComplex):
135
131
  faces = [x for x in faces if isinstance(x, topologic.Face)]
136
132
  if len(faces) < 1:
137
133
  return None
138
- cellComplex = topologic.CellComplex.ByFaces(faces, tolerance, False)
134
+ try:
135
+ cellComplex = topologic.CellComplex.ByFaces(faces, tolerance, False)
136
+ except:
137
+ cellComplex = None
139
138
  if not cellComplex:
140
- warnings.warn("Warning: Default CellComplex.ByFaces method failed. Attempting to Merge the Faces.", UserWarning)
139
+ print("Warning: Default CellComplex.ByFaces method failed. Attempting to Merge the Faces.")
141
140
  cellComplex = faces[0]
142
141
  for i in range(1,len(faces)):
143
142
  newCellComplex = None
144
143
  try:
145
144
  newCellComplex = cellComplex.Merge(faces[i], False)
146
145
  except:
147
- warnings.warn("Warning: Failed to merge Face #"+i+". Skipping.", UserWarning)
146
+ print("Warning: Failed to merge Face #"+str(i)+". Skipping.")
148
147
  if newCellComplex:
149
148
  cellComplex = newCellComplex
150
149
  if cellComplex.Type() != 64: #64 is the type of a CellComplex
151
- warnings.warn("Warning: Input Faces do not form a CellComplex", UserWarning)
150
+ print("Warning: Input Faces do not form a CellComplex")
152
151
  if cellComplex.Type() > 64:
153
152
  returnCellComplexes = []
154
153
  _ = cellComplex.CellComplexes(None, returnCellComplexes)
155
- return returnCellComplexes[0]
154
+ if len(returnCellComplexes) > 0:
155
+ return returnCellComplexes[0]
156
+ else:
157
+ return None
156
158
  else:
157
159
  return None
158
160
  else:
@@ -593,7 +595,7 @@ class CellComplex(topologic.CellComplex):
593
595
 
594
596
  @staticmethod
595
597
  def Prism(origin=None, width=1, length=1, height=1, uSides=2, vSides=2, wSides=2,
596
- dirX=0, dirY=0, dirZ=1, placement="center"):
598
+ direction=[0,0,1], placement="center"):
597
599
  """
598
600
  Creates a prismatic cellComplex with internal cells.
599
601
 
@@ -613,12 +615,8 @@ class CellComplex(topologic.CellComplex):
613
615
  The number of sides along the length. The default is 1.
614
616
  wSides : int , optional
615
617
  The number of sides along the height. The default is 1.
616
- dirX : float , optional
617
- The X component of the vector representing the up direction of the prism. The default is 0.
618
- dirY : float , optional
619
- The Y component of the vector representing the up direction of the prism. The default is 0.
620
- dirZ : float , optional
621
- The Z component of the vector representing the up direction of the prism. The default is 1.
618
+ direction : list , optional
619
+ The vector representing the up direction of the prism. The default is [0,0,1].
622
620
  placement : str , optional
623
621
  The description of the placement of the origin of the prism. This can be "bottom", "center", or "lowerleft". It is case insensitive. The default is "center".
624
622
 
@@ -664,9 +662,9 @@ class CellComplex(topologic.CellComplex):
664
662
  x1 = origin.X()
665
663
  y1 = origin.Y()
666
664
  z1 = origin.Z()
667
- x2 = origin.X() + dirX
668
- y2 = origin.Y() + dirY
669
- z2 = origin.Z() + dirZ
665
+ x2 = origin.X() + direction[0]
666
+ y2 = origin.Y() + direction[1]
667
+ z2 = origin.Z() + direction[2]
670
668
  dx = x2 - x1
671
669
  dy = y2 - y1
672
670
  dz = z2 - z1
topologicpy/Cluster.py CHANGED
@@ -378,7 +378,7 @@ class Cluster(topologic.Cluster):
378
378
  return topologic.Vertex.Type()
379
379
 
380
380
  @staticmethod
381
- def MysticRose(wire=None, origin=None, radius=1, sides=16, perimeter=True, dirX=0, dirY=0, dirZ=1, placement="center", tolerance=0.0001):
381
+ def MysticRose(wire=None, origin=None, radius=1, sides=16, perimeter=True, direction=[0,0,1], placement="center", tolerance=0.0001):
382
382
  """
383
383
  Creates a mystic rose.
384
384
 
@@ -389,19 +389,15 @@ class Cluster(topologic.Cluster):
389
389
  origin : topologic.Vertex , optional
390
390
  The location of the origin of the circle. The default is None which results in the circle being placed at (0,0,0).
391
391
  radius : float , optional
392
- The radius of the circle. The default is 1.
392
+ The radius of the mystic rose. The default is 1.
393
393
  sides : int, optional
394
- The number of sides of the circle. The default is 16.
394
+ The number of sides of the mystic rose. The default is 16.
395
395
  perimeter : bool, optional
396
396
  If True, the perimeter edges are included in the output. The default is True.
397
- dirX : float , optional
398
- The X component of the vector representing the up direction of the circle. The default is 0.
399
- dirY : float , optional
400
- The Y component of the vector representing the up direction of the circle. The default is 0.
401
- dirZ : float , optional
402
- The Z component of the vector representing the up direction of the circle. The default is 1.
397
+ direction : list , optional
398
+ The vector representing the up direction of the mystic rose. The default is [0,0,1].
403
399
  placement : str , optional
404
- The description of the placement of the origin of the circle. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
400
+ The description of the placement of the origin of the mystic rose. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
405
401
  tolerance : float , optional
406
402
  The desired tolerance. The default is 0.0001.
407
403
 
@@ -419,7 +415,7 @@ class Cluster(topologic.Cluster):
419
415
  from itertools import combinations
420
416
 
421
417
  if not wire:
422
- wire = Wire.Circle(origin=origin, radius=radius, sides=sides, fromAngle=0, toAngle=360, close=True, dirX=dirX,dirY=dirY, dirZ=dirZ, placement=placement, tolerance=tolerance)
418
+ wire = Wire.Circle(origin=origin, radius=radius, sides=sides, fromAngle=0, toAngle=360, close=True, direction=direction, placement=placement, tolerance=tolerance)
423
419
  if not Wire.IsClosed(wire):
424
420
  return None
425
421
  vertices = Wire.Vertices(wire)
topologicpy/DGL.py CHANGED
@@ -717,12 +717,17 @@ class DGL:
717
717
  accuracy = round(float(correct) / float(len(predicted)), mantissa)
718
718
  return {"accuracy":accuracy, "correct":correct, "mask":mask, "size":size, "wrong":wrong}
719
719
 
720
- def ConfusionMatrix(actual, predicted, categories, renderer="notebook"):
720
+ def ConfusionMatrix(actual, predicted, normalize=False):
721
721
  from sklearn import metrics
722
- return metrics.confusion_matrix(actual, predicted)
722
+ if normalize:
723
+ cf = metrics.confusion_matrix(y_true=actual, y_pred=predicted, normalize="true")
724
+ else:
725
+ cf = metrics.confusion_matrix(y_true=actual, y_pred=predicted)
726
+ return cf
727
+
723
728
 
724
729
  @staticmethod
725
- def ClassifierBypath(path):
730
+ def ClassifierByFilePath(path):
726
731
  """
727
732
  Returns the classifier found at the input file path.
728
733
  Parameters
topologicpy/Face.py CHANGED
@@ -548,8 +548,8 @@ class Face(topologic.Face):
548
548
  return Face.ByWires(externalBoundary, internalBoundaries)
549
549
 
550
550
  @staticmethod
551
- def Circle(origin=None, radius=0.5, sides=16, fromAngle=0, toAngle=360, dirX=0,
552
- dirY=0, dirZ=1, placement="center", tolerance=0.0001):
551
+ def Circle(origin=None, radius=0.5, sides=16, fromAngle=0, toAngle=360, direction=[0,0,1],
552
+ placement="center", tolerance=0.0001):
553
553
  """
554
554
  Creates a circle.
555
555
 
@@ -565,12 +565,8 @@ class Face(topologic.Face):
565
565
  The angle in degrees from which to start creating the arc of the circle. The default is 0.
566
566
  toAngle : float , optional
567
567
  The angle in degrees at which to end creating the arc of the circle. The default is 360.
568
- dirX : float , optional
569
- The X component of the vector representing the up direction of the circle. The default is 0.
570
- dirY : float , optional
571
- The Y component of the vector representing the up direction of the circle. The default is 0.
572
- dirZ : float , optional
573
- The Z component of the vector representing the up direction of the circle. The default is 1.
568
+ direction : list , optional
569
+ The vector representing the up direction of the circle. The default is [0,0,1].
574
570
  placement : str , optional
575
571
  The description of the placement of the origin of the circle. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
576
572
  tolerance : float , optional
@@ -583,7 +579,7 @@ class Face(topologic.Face):
583
579
 
584
580
  """
585
581
  from topologicpy.Wire import Wire
586
- wire = Wire.Circle(origin, radius, sides, fromAngle, toAngle, True, dirX, dirY, dirZ, placement, tolerance)
582
+ wire = Wire.Circle(origin=origin, radius=radius, sides=sides, fromAngle=fromAngle, toAngle=toAngle, close=True, direction=direction, placement=placement, tolerance=tolerance)
587
583
  if not isinstance(wire, topologic.Wire):
588
584
  return None
589
585
  return Face.ByWire(wire)
@@ -705,7 +701,7 @@ class Face(topologic.Face):
705
701
  return True
706
702
 
707
703
  @staticmethod
708
- def Flatten(face, oldLocation=None, newLocation=None):
704
+ def Flatten(face, oldLocation=None, newLocation=None, direction=None):
709
705
  """
710
706
  Flattens the input face such that its center of mass is located at the origin and its normal is pointed in the positive Z axis.
711
707
 
@@ -717,6 +713,8 @@ class Face(topologic.Face):
717
713
  The old location to use as the origin of the movement. If set to None, the center of mass of the input topology is used. The default is None.
718
714
  newLocation : topologic.Vertex , optional
719
715
  The new location at which to place the topology. If set to None, the world origin (0,0,0) is used. The default is None.
716
+ direction : list , optional
717
+ The direction, expressed as a list of [X,Y,Z] that signifies the direction of the face. If set to None, the normal at *u* 0.5 and *v* 0.5 is considered the direction of the face. The deafult is None.
720
718
 
721
719
  Returns
722
720
  -------
@@ -735,13 +733,14 @@ class Face(topologic.Face):
735
733
  newLocation = Vertex.ByCoordinates(0,0,0)
736
734
  cm = oldLocation
737
735
  world_origin = newLocation
738
- coords = Face.NormalAtParameters(face, 0.5, 0.5)
736
+ if not direction or len(direction) < 3:
737
+ direction = Face.NormalAtParameters(face, 0.5, 0.5)
739
738
  x1 = Vertex.X(cm)
740
739
  y1 = Vertex.Y(cm)
741
740
  z1 = Vertex.Z(cm)
742
- x2 = Vertex.X(cm) + coords[0]
743
- y2 = Vertex.Y(cm) + coords[1]
744
- z2 = Vertex.Z(cm) + coords[2]
741
+ x2 = Vertex.X(cm) + direction[0]
742
+ y2 = Vertex.Y(cm) + direction[1]
743
+ z2 = Vertex.Z(cm) + direction[2]
745
744
  dx = x2 - x1
746
745
  dy = y2 - y1
747
746
  dz = z2 - z1
@@ -775,6 +774,54 @@ class Face(topologic.Face):
775
774
  flatFace = Topology.SetDictionary(flatFace, dictionary)
776
775
  return flatFace
777
776
 
777
+ @staticmethod
778
+ def Planarize(face, origin=None, direction=None):
779
+ """
780
+ Planarizes the input face such that its center of mass is located at the input origin and its normal is pointed in the input direction.
781
+
782
+ Parameters
783
+ ----------
784
+ face : topologic.Face
785
+ The input face.
786
+ origin : topologic.Vertex , optional
787
+ The old location to use as the origin of the movement. If set to None, the center of mass of the input face is used. The default is None.
788
+ direction : list , optional
789
+ The direction, expressed as a list of [X,Y,Z] that signifies the direction of the face. If set to None, the normal at *u* 0.5 and *v* 0.5 is considered the direction of the face. The deafult is None.
790
+
791
+ Returns
792
+ -------
793
+ topologic.Face
794
+ The planarized face.
795
+
796
+ """
797
+
798
+ from topologicpy.Vertex import Vertex
799
+ from topologicpy.Wire import Wire
800
+ from topologicpy.Topology import Topology
801
+ from topologicpy.Dictionary import Dictionary
802
+
803
+ if not isinstance(face, topologic.Face):
804
+ return None
805
+ if not isinstance(origin, topologic.Vertex):
806
+ origin = Topology.CenterOfMass(face)
807
+ if not isinstance(direction, list):
808
+ direction = Face.NormalAtParameters(face, 0.5, 0.5)
809
+ flatFace = Face.Flatten(face, oldLocation=origin, direction=direction)
810
+
811
+ world_origin = Vertex.ByCoordinates(0,0,0)
812
+ # Retrieve the needed transformations
813
+ dictionary = Topology.Dictionary(flatFace)
814
+ xTran = Dictionary.ValueAtKey(dictionary,"xTran")
815
+ yTran = Dictionary.ValueAtKey(dictionary,"yTran")
816
+ zTran = Dictionary.ValueAtKey(dictionary,"zTran")
817
+ phi = Dictionary.ValueAtKey(dictionary,"phi")
818
+ theta = Dictionary.ValueAtKey(dictionary,"theta")
819
+
820
+ planarizedFace = Topology.Rotate(flatFace, origin=world_origin, x=0, y=1, z=0, degree=theta)
821
+ planarizedFace = Topology.Rotate(planarizedFace, origin=world_origin, x=0, y=0, z=1, degree=phi)
822
+ planarizedFace = Topology.Translate(planarizedFace, xTran, yTran, zTran)
823
+ return planarizedFace
824
+
778
825
  @staticmethod
779
826
  def Harmonize(face):
780
827
  """
@@ -1206,6 +1253,57 @@ class Face(topologic.Face):
1206
1253
  returnResult = None
1207
1254
  return returnResult
1208
1255
 
1256
+ @staticmethod
1257
+ def NormalEdge(face, length=1):
1258
+ """
1259
+ Returns the normal vector to the input face as an edge with the desired input length. A normal vector of a face is a vector perpendicular to it.
1260
+
1261
+ Parameters
1262
+ ----------
1263
+ face : topologic.Face
1264
+ The input face.
1265
+ length : float , optional
1266
+ The desired length of the normal edge. The default is 1.
1267
+
1268
+ Returns
1269
+ -------
1270
+ topologic.Edge
1271
+ The created normal edge to the input face. This is computed at the approximate center of the face.
1272
+
1273
+ """
1274
+ return Face.NormalEdgeAtParameters(face, u=0.5, v=0.5, length=length)
1275
+
1276
+ @staticmethod
1277
+ def NormalEdgeAtParameters(face, u=0.5, v=0.5, length=1):
1278
+ """
1279
+ Returns the normal vector to the input face as an edge with the desired input length. A normal vector of a face is a vector perpendicular to it.
1280
+
1281
+ Parameters
1282
+ ----------
1283
+ face : topologic.Face
1284
+ The input face.
1285
+ u : float , optional
1286
+ The *u* parameter at which to compute the normal to the input face. The default is 0.5.
1287
+ v : float , optional
1288
+ The *v* parameter at which to compute the normal to the input face. The default is 0.5.
1289
+ length : float , optional
1290
+ The desired length of the normal edge. The default is 1.
1291
+
1292
+ Returns
1293
+ -------
1294
+ topologic.Edge
1295
+ The created normal edge to the input face. This is computed at the approximate center of the face.
1296
+
1297
+ """
1298
+ from topologicpy.Edge import Edge
1299
+ from topologicpy.Topology import Topology
1300
+ if not isinstance(face, topologic.Face):
1301
+ return None
1302
+ sv = Face.VertexByParameters(face=face, u=u, v=v)
1303
+ vec = Face.NormalAtParameters(face, u=u, v=v)
1304
+ ev = Topology.TranslateByDirectionDistance(sv, vec, length)
1305
+ return Edge.ByVertices([sv, ev])
1306
+
1209
1307
  @staticmethod
1210
1308
  def Project(faceA, faceB, direction=None, mantissa=4, tolerance=0.0001):
1211
1309
  """
@@ -1250,7 +1348,7 @@ class Face(topologic.Face):
1250
1348
  return Face.ByWires(p_eb, p_ib_list)
1251
1349
 
1252
1350
  @staticmethod
1253
- def Rectangle(origin=None, width=1.0, length=1.0, dirX=0, dirY=0, dirZ=1, placement="center", tolerance=0.0001):
1351
+ def Rectangle(origin=None, width=1.0, length=1.0, direction=[0,0,1], placement="center", tolerance=0.0001):
1254
1352
  """
1255
1353
  Creates a rectangle.
1256
1354
 
@@ -1262,12 +1360,8 @@ class Face(topologic.Face):
1262
1360
  The width of the rectangle. The default is 1.0.
1263
1361
  length : float , optional
1264
1362
  The length of the rectangle. The default is 1.0.
1265
- dirX : float , optional
1266
- The X component of the vector representing the up direction of the rectangle. The default is 0.
1267
- dirY : float , optional
1268
- The Y component of the vector representing the up direction of the rectangle. The default is 0.
1269
- dirZ : float , optional
1270
- The Z component of the vector representing the up direction of the rectangle. The default is 1.
1363
+ direction : list , optional
1364
+ The vector representing the up direction of the rectangle. The default is [0,0,1].
1271
1365
  placement : str , optional
1272
1366
  The description of the placement of the origin of the rectangle. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
1273
1367
  tolerance : float , optional
@@ -1279,13 +1373,13 @@ class Face(topologic.Face):
1279
1373
  The created face.
1280
1374
 
1281
1375
  """
1282
- wire = Wire.Rectangle(origin, width, length, dirX, dirY, dirZ, placement, tolerance)
1376
+ wire = Wire.Rectangle(origin=origin, width=width, length=length, direction=direction, placement=placement, tolerance=tolerance)
1283
1377
  if not isinstance(wire, topologic.Wire):
1284
1378
  return None
1285
1379
  return Face.ByWire(wire)
1286
1380
 
1287
1381
  @staticmethod
1288
- def Star(origin=None, radiusA=1.0, radiusB=0.4, rays=5, dirX=0, dirY=0, dirZ=1, placement="center", tolerance=0.0001):
1382
+ def Star(origin=None, radiusA=1.0, radiusB=0.4, rays=5, direction=[0,0,1], placement="center", tolerance=0.0001):
1289
1383
  """
1290
1384
  Creates a star.
1291
1385
 
@@ -1299,12 +1393,8 @@ class Face(topologic.Face):
1299
1393
  The outer radius of the star. The default is 0.4.
1300
1394
  rays : int , optional
1301
1395
  The number of star rays. The default is 5.
1302
- dirX : float , optional
1303
- The X component of the vector representing the up direction of the star. The default is 0.
1304
- dirY : float , optional
1305
- The Y component of the vector representing the up direction of the star. The default is 0.
1306
- dirZ : float , optional
1307
- The Z component of the vector representing the up direction of the star. The default is 1.
1396
+ direction : list , optional
1397
+ The vector representing the up direction of the star. The default is [0,0,1].
1308
1398
  placement : str , optional
1309
1399
  The description of the placement of the origin of the star. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
1310
1400
  tolerance : float , optional
@@ -1316,13 +1406,13 @@ class Face(topologic.Face):
1316
1406
  The created face.
1317
1407
 
1318
1408
  """
1319
- wire = Wire.Star(origin, radiusA, radiusB, rays, dirX, dirY, dirZ, placement, tolerance)
1409
+ wire = Wire.Star(origin=origin, radiusA=radiusA, radiusB=radiusB, rays=rays, direction=direction, placement=placement, tolerance=tolerance)
1320
1410
  if not isinstance(wire, topologic.Wire):
1321
1411
  return None
1322
1412
  return Face.ByWire(wire)
1323
1413
 
1324
1414
  @staticmethod
1325
- def Trapezoid(origin=None, widthA=1.0, widthB=0.75, offsetA=0.0, offsetB=0.0, length=1.0, dirX=0, dirY=0, dirZ=1, placement="center", tolerance=0.0001):
1415
+ def Trapezoid(origin=None, widthA=1.0, widthB=0.75, offsetA=0.0, offsetB=0.0, length=1.0, direction=[0,0,1], placement="center", tolerance=0.0001):
1326
1416
  """
1327
1417
  Creates a trapezoid.
1328
1418
 
@@ -1340,12 +1430,8 @@ class Face(topologic.Face):
1340
1430
  The offset of the top edge of the trapezoid. The default is 0.0.
1341
1431
  length : float , optional
1342
1432
  The length of the trapezoid. The default is 1.0.
1343
- dirX : float , optional
1344
- The X component of the vector representing the up direction of the trapezoid. The default is 0.
1345
- dirY : float , optional
1346
- The Y component of the vector representing the up direction of the trapezoid. The default is 0.
1347
- dirZ : float , optional
1348
- The Z component of the vector representing the up direction of the trapezoid. The default is 1.
1433
+ direction : list , optional
1434
+ The vector representing the up direction of the trapezoid. The default is [0,0,1].
1349
1435
  placement : str , optional
1350
1436
  The description of the placement of the origin of the trapezoid. This can be "center", or "lowerleft". It is case insensitive. The default is "center".
1351
1437
  tolerance : float , optional
@@ -1357,7 +1443,7 @@ class Face(topologic.Face):
1357
1443
  The created trapezoid.
1358
1444
 
1359
1445
  """
1360
- wire = Wire.Trapezoid(origin, widthA, widthB, offsetA, offsetB, length, dirX, dirY, dirZ, placement, tolerance)
1446
+ wire = Wire.Trapezoid(origin=origin, widthA=widthA, widthB=widthB, offsetA=offsetA, offsetB=offsetB, length=length, direction=direction, placement=placement, tolerance=tolerance)
1361
1447
  if not isinstance(wire, topologic.Wire):
1362
1448
  return None
1363
1449
  return Face.ByWire(wire)