-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #67
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,7 @@ | |
|
||
def build_shape(): | ||
boxshp = BRepPrimAPI_MakeBox(50.0, 50.0, 50.0).Shape() | ||
ais_boxshp = display.DisplayShape(boxshp, update=True)[0] | ||
return ais_boxshp | ||
return display.DisplayShape(boxshp, update=True)[0] | ||
|
||
|
||
def rotating_cube_1_axis(event=None): | ||
|
@@ -44,7 +43,7 @@ def rotating_cube_1_axis(event=None): | |
angle = 0.0 | ||
tA = time.time() | ||
n_rotations = 200 | ||
for i in range(n_rotations): | ||
for _ in range(n_rotations): | ||
Comment on lines
-47
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
aCubeTrsf.SetRotation(ax1, angle) | ||
aCubeToploc = TopLoc_Location(aCubeTrsf) | ||
display.Context.SetLocation(ais_boxshp, aCubeToploc) | ||
|
@@ -63,7 +62,7 @@ def rotating_cube_2_axis(event=None): | |
angle = 0.0 | ||
tA = time.time() | ||
n_rotations = 200 | ||
for i in range(n_rotations): | ||
for _ in range(n_rotations): | ||
Comment on lines
-66
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
a_cube_trsf.SetRotation(ax1, angle) | ||
a_cube_trsf2.SetRotation(ax2, angle) | ||
aCubeToploc = TopLoc_Location(a_cube_trsf * a_cube_trsf2) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,12 @@ | |
|
||
|
||
def random_pnt(): | ||
x, y, z = [random.uniform(0, 1) for i in range(3)] | ||
x, y, z = [random.uniform(0, 1) for _ in range(3)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return gp_Pnt(x, y, z) | ||
|
||
|
||
def random_vec(): | ||
x, y, z = [random.uniform(-1, 1) for i in range(3)] | ||
x, y, z = [random.uniform(-1, 1) for _ in range(3)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return gp_Vec(x, y, z) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,7 @@ | |
def MakeSolidFromShell(shell): | ||
ms = BRepBuilderAPI_MakeSolid() | ||
ms.Add(topods.Shell(shell)) | ||
solid = ms.Solid() | ||
return solid | ||
return ms.Solid() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def make_face_from_4_points(pnt1, pnt2, pnt3, pnt4): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,10 +76,10 @@ def createLayout(self): | |
def show_layer(self): | ||
if self.show_layer_button.isChecked(): | ||
self.layer.show() | ||
self.display.FitAll() | ||
else: | ||
self.layer.hide() | ||
self.display.FitAll() | ||
|
||
self.display.FitAll() | ||
Comment on lines
-79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def activate_manipulator(self): | ||
if self.activate_manip_button.isChecked(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ def print_xy_click(shp, *kwargs): | |
|
||
|
||
def compute_bbox(shp, *kwargs): | ||
print("Compute bbox for %s " % shp) | ||
print(f"Compute bbox for {shp} ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for shape in shp: | ||
bbox = Bnd_Box() | ||
brepbndlib_Add(shape, bbox) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ def disable_clip_plane(event=None): | |
def animate_translate_clip_plane(event=None): | ||
plane_definition = clip_plane_1.ToPlane() # it's a gp_Pln | ||
h = 0.2 | ||
for i in range(100): | ||
for _ in range(100): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
plane_definition.Translate(gp_Vec(0.0, 0.0, h)) | ||
clip_plane_1.SetEquation(plane_definition) | ||
display.Context.UpdateCurrentViewer() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
s = BRepPrimAPI_MakeCylinder(radius, 200).Shape() | ||
delta_x = 0.0 | ||
solids = [] | ||
for mat in available_materials: | ||
for _ in available_materials: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
s2 = translate_shp(s, gp_Vec(delta_x, 0.0, 0.0)) | ||
delta_x += 2 * radius + 1.0 | ||
solids.append(s2) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,21 +45,20 @@ def pcd_get_number_of_vertices(pcd_filename): | |
POINTS 397 | ||
DATA ascii | ||
""" | ||
f = open(pcd_filename, "r") | ||
# read 8 lines | ||
for i in range(8): | ||
f.readline() | ||
# the 9th line holds the number of points | ||
number_of_points = int(f.readline().split()[1]) | ||
f.close() | ||
with open(pcd_filename, "r") as f: | ||
# read 8 lines | ||
for _ in range(8): | ||
f.readline() | ||
# the 9th line holds the number of points | ||
number_of_points = int(f.readline().split()[1]) | ||
Comment on lines
-48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return number_of_points | ||
|
||
|
||
def random_points(event=None): | ||
n_points = 500000 | ||
# first, create a set of 1000 points | ||
points_3d = Graphic3d_ArrayOfPoints(n_points) | ||
for idx in range(n_points): | ||
for _ in range(n_points): | ||
Comment on lines
-62
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
x = random.uniform(-50, 50) | ||
y = random.uniform(-50, 50) | ||
z = random.uniform(-50, 50) | ||
|
@@ -86,9 +85,9 @@ def bunny(event=None): | |
# fedd it with vertices | ||
fp = open(pcd_file_name, "r") | ||
# read 11 lines to skip header | ||
for i in range(10): | ||
for _ in range(10): | ||
fp.readline() | ||
for i in range(nbr_of_vertices): | ||
for _ in range(nbr_of_vertices): | ||
Comment on lines
-89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
line = fp.readline() | ||
x, y, z = map(float, line.split()) | ||
pc.AddVertex(x, y, z) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,7 @@ def get_occ_viewer(): | |
widgets = app.topLevelWidgets() | ||
for wi in widgets: | ||
if hasattr(wi, "_menus"): # OCC.Display.SimpleGui.MainWindow | ||
viewer = wi.findChild(qtViewer3d, "qt_viewer_3d") | ||
return viewer | ||
return wi.findChild(qtViewer3d, "qt_viewer_3d") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def on_select(shapes): | ||
|
@@ -75,8 +74,7 @@ def also_on_select(shapes): | |
def location_from_vector(x, y, z): | ||
trsf = gp_Trsf() | ||
trsf.SetTranslation(gp_Vec(x, y, z)) | ||
loc = TopLoc_Location(trsf) | ||
return loc | ||
return TopLoc_Location(trsf) | ||
Comment on lines
-78
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
cube = BRepPrimAPI_MakeBox(100, 100, 100).Shape() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ def __init__(self, chord, span, profile): | |
def make_shape(self): | ||
# 1 - retrieve the data from the UIUC airfoil data page | ||
foil_dat_url = ( | ||
"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat" % self.profile | ||
f"http://m-selig.ae.illinois.edu/ads/coord_seligFmt/{self.profile}.dat" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
) | ||
# explicitly tell to not use ssl verification | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,22 +85,20 @@ def make_n_sided(edges, points, continuity=GeomAbs_C0): | |
for pt in points: | ||
n_sided.Add(pt) | ||
n_sided.Build() | ||
face = n_sided.Face() | ||
return face | ||
return n_sided.Face() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def make_closed_polygon(*args): | ||
poly = BRepBuilderAPI_MakePolygon() | ||
for pt in args: | ||
if isinstance(pt, list) or isinstance(pt, tuple): | ||
if isinstance(pt, (list, tuple)): | ||
for i in pt: | ||
poly.Add(i) | ||
else: | ||
poly.Add(pt) | ||
poly.Build() | ||
poly.Close() | ||
result = poly.Wire() | ||
return result | ||
return poly.Wire() | ||
Comment on lines
-95
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def geom_plate(event=None): | ||
|
@@ -111,7 +109,7 @@ def geom_plate(event=None): | |
p4 = gp_Pnt(0, 0, 10) | ||
p5 = gp_Pnt(5, 5, 5) | ||
poly = make_closed_polygon([p1, p2, p3, p4]) | ||
edges = [i for i in TopologyExplorer(poly).edges()] | ||
edges = list(TopologyExplorer(poly).edges()) | ||
Comment on lines
-114
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
face = make_n_sided(edges, [p5]) | ||
display.DisplayShape(edges) | ||
display.DisplayShape(make_vertex(p5)) | ||
|
@@ -244,7 +242,7 @@ def solve_radius(event=None): | |
for i in (0.1, 0.5, 1.5, 2.0, 3.0, 0.2): | ||
rcs = RadiusConstrainedSurface(display, poly, p5, i) | ||
rcs.solve() | ||
print("Goal: %s radius: %s" % (i, rcs.curr_radius)) | ||
print(f"Goal: {i} radius: {rcs.curr_radius}") | ||
Comment on lines
-247
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
time.sleep(0.1) | ||
|
||
|
||
|
@@ -267,8 +265,7 @@ def build_geom_plate(edges): | |
plate = GeomPlate_MakeApprox(srf, 0.01, 10, 5, 0.01, 0, GeomAbs_C0) | ||
|
||
uMin, uMax, vMin, vMax = srf.Bounds() | ||
face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6) | ||
return face | ||
return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6) | ||
Comment on lines
-270
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def build_curve_network(event=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,7 @@ def boolean_cut(shapeToCutFrom, cuttingShape): | |
|
||
cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape) | ||
|
||
shp = cut.Shape() | ||
return shp | ||
return cut.Shape() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def make_face_to_contour_from(): | ||
|
@@ -63,8 +62,7 @@ def make_face_to_contour_from(): | |
f = make_face(w1) | ||
w2 = make_wire(e7, e8, e9, e10) | ||
f2 = make_face(w2) | ||
f3 = boolean_cut(f, f2) | ||
return f3 | ||
return boolean_cut(f, f2) | ||
Comment on lines
-66
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def create_offsets(face, nr_of_counters, distance_between_contours): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,13 @@ | |
|
||
expl = TopologyExplorer(converted_shape) | ||
|
||
# loop over faces | ||
fc_idx = 1 | ||
|
||
for face in expl.faces(): | ||
for fc_idx, face in enumerate(expl.faces(), start=1): | ||
print("=== Face %i ===" % fc_idx) | ||
surf = BRepAdaptor_Surface(face, True) | ||
surf_type = surf.GetType() | ||
# check each of the is a BSpline surface | ||
# it should be, since we used the nurbs converter before | ||
if not surf_type == GeomAbs_BSplineSurface: | ||
if surf_type != GeomAbs_BSplineSurface: | ||
Comment on lines
-37
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ):
|
||
raise AssertionError("the face was not converted to a GeomAbs_BSplineSurface") | ||
# get the nurbs | ||
bsrf = surf.BSpline() | ||
|
@@ -78,4 +75,3 @@ | |
p = poles.Value(i + 1, j + 1) | ||
print(p.X(), p.Y(), p.Z(), end=" ") | ||
print() | ||
fc_idx += 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,9 @@ def convert_bnd_to_shape(the_box): | |
axes.SetLocation( | ||
gp_Pnt(point.XYZ() - x_vec * half_x - y_vec * half_y - z_vec * half_z) | ||
) | ||
box = BRepPrimAPI_MakeBox(axes, 2.0 * half_x, 2.0 * half_y, 2.0 * half_z).Shape() | ||
return box | ||
return BRepPrimAPI_MakeBox( | ||
axes, 2.0 * half_x, 2.0 * half_y, 2.0 * half_z | ||
).Shape() | ||
Comment on lines
-51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
# compute the oriented bounding box of a point cloud | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,9 +78,7 @@ def frange(start, end=None, inc=None): | |
L = [] | ||
while 1: | ||
next_ = start + len(L) * inc | ||
if inc > 0 and next_ >= end: | ||
break | ||
elif inc < 0 and next_ <= end: | ||
if inc > 0 and next_ >= end or inc < 0 and next_ <= end: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
break | ||
L.append(next_) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ def recognize_face(a_face): | |
if a plane, returns the normal | ||
if a cylinder, returns the radius | ||
""" | ||
if not type(a_face) is TopoDS_Face: | ||
if type(a_face) is not TopoDS_Face: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
print("Please hit the 'G' key to switch to face selection mode") | ||
return False | ||
surf = BRepAdaptor_Surface(a_face, True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,12 @@ def random_color(): | |
|
||
def length_from_edge(edg): | ||
curve_adapt = BRepAdaptor_Curve(edg) | ||
length = GCPnts_AbscissaPoint().Length( | ||
curve_adapt, curve_adapt.FirstParameter(), curve_adapt.LastParameter(), 1e-6 | ||
return GCPnts_AbscissaPoint().Length( | ||
curve_adapt, | ||
curve_adapt.FirstParameter(), | ||
curve_adapt.LastParameter(), | ||
1e-6, | ||
) | ||
return length | ||
Comment on lines
-45
to
-48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def divide_edge_by_nr_of_points(edg, n_pts): | ||
|
@@ -105,7 +107,7 @@ def build_curve_network(event=None, enforce_tangency=True): | |
root_compound_shape = read_step_file("../assets/models/splinecage.stp") | ||
topology_explorer = TopologyExplorer(root_compound_shape) | ||
|
||
tangent_constraint_faces = [f for f in topology_explorer.faces()] | ||
tangent_constraint_faces = list(topology_explorer.faces()) | ||
Comment on lines
-108
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
# loop through the imported faces | ||
# associate the length of each of the faces edges to the corresponding face | ||
|
@@ -115,12 +117,11 @@ def build_curve_network(event=None, enforce_tangency=True): | |
|
||
# loop through the imported curves, avoiding the imported faces | ||
# when we've got these filtered out, we retrieved the geometry to build the surface from | ||
filtered_edges = [ | ||
e | ||
for e in topology_explorer._loop_topo( | ||
filtered_edges = list( | ||
topology_explorer._loop_topo( | ||
TopAbs_EDGE, root_compound_shape, TopAbs_FACE | ||
) | ||
] | ||
) | ||
|
||
filtered_length = {} | ||
for e in filtered_edges: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,7 @@ def surface_from_curves(): | |
@param display: | ||
""" | ||
# First spline | ||
array = [] | ||
array.append(gp_Pnt(-4, 0, 2)) | ||
array = [gp_Pnt(-4, 0, 2)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
array.append(gp_Pnt(-7, 2, 2)) | ||
array.append(gp_Pnt(-6, 3, 1)) | ||
array.append(gp_Pnt(-4, 3, -1)) | ||
|
@@ -52,8 +51,7 @@ def surface_from_curves(): | |
SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve() | ||
|
||
# Second spline | ||
a2 = [] | ||
a2.append(gp_Pnt(-4, 0, 2)) | ||
a2 = [gp_Pnt(-4, 0, 2)] | ||
a2.append(gp_Pnt(-2, 2, 0)) | ||
a2.append(gp_Pnt(2, 3, -1)) | ||
a2.append(gp_Pnt(3, 7, -2)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,18 +44,14 @@ def mesh_shape(a_topods_shape): | |
|
||
a() = ShapeFromFile("shape.brep"); | ||
""" | ||
gmsh_geo_file = open("shape.geo", "w") | ||
gmsh_geo_file.write(gmsh_geo_file_content) | ||
gmsh_geo_file.close() | ||
|
||
with open("shape.geo", "w") as gmsh_geo_file: | ||
gmsh_geo_file.write(gmsh_geo_file_content) | ||
# call gmsh | ||
gmsh_success = os.system("gmsh shape.geo -2 -o shape.stl -format stl") | ||
# load the stl file | ||
if gmsh_success != 0 and os.path.isfile("shape.stl"): | ||
return read_stl_file("shape.stl") | ||
else: | ||
print("Be sure gmsh is in your PATH") | ||
sys.exit() | ||
print("Be sure gmsh is in your PATH") | ||
sys.exit() | ||
Comment on lines
-47
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
|
||
|
||
# First example, a simple torus | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
build_shape
refactored with the following changes:inline-immediately-returned-variable
)