Skip to content

Commit dc9e600

Browse files
committed
Fix: generalized reversepropeller code to work with generic blades with z as main direction. Also cleaned a little bit the code
1 parent 412cb5b commit dc9e600

1 file changed

Lines changed: 34 additions & 74 deletions

File tree

bladex/reversepropeller.py

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,40 @@
55

66
import os, errno
77
import os.path
8-
import matplotlib.pyplot as plt
98
import numpy as np
109
import csv
11-
from bladex import NacaProfile, CustomProfile, Blade, Propeller, Shaft
12-
from OCC.Core.IGESControl import (IGESControl_Reader, IGESControl_Writer,
13-
IGESControl_Controller_Init)
10+
from bladex import CustomProfile, Blade, Propeller, Shaft
11+
from OCC.Core.IGESControl import (IGESControl_Reader)
1412
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeVertex,\
1513
BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeSolid, \
16-
BRepBuilderAPI_Sewing, BRepBuilderAPI_Transform, BRepBuilderAPI_NurbsConvert, \
17-
BRepBuilderAPI_MakeFace
18-
from OCC.Core.BRep import (BRep_Tool, BRep_Builder, BRep_Tool_Curve,
19-
BRep_Tool_CurveOnSurface)
14+
BRepBuilderAPI_Sewing, BRepBuilderAPI_NurbsConvert
15+
from OCC.Core.BRep import BRep_Tool
2016
import OCC.Core.TopoDS
21-
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse
22-
# from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
23-
from OCC.Core.TopTools import TopTools_ListOfShape, TopTools_MapOfShape
17+
from OCC.Core.TopTools import TopTools_ListOfShape
2418
from OCC.Core.TopExp import TopExp_Explorer
2519
from OCC.Core.TopAbs import TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_WIRE
26-
from OCC.Core.StlAPI import StlAPI_Writer
27-
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
28-
from OCC.Core.gp import gp_Pnt, gp_Pnt2d, gp_Dir, gp_Ax1, gp_Ax2, gp_Trsf, gp_Pln, gp_Vec, gp_Lin
29-
from OCC.Core.TopoDS import TopoDS_Shape
30-
from OCC.Core.TColgp import TColgp_HArray1OfPnt, TColgp_Array1OfPnt
31-
from OCC.Core.GeomAPI import GeomAPI_Interpolate, GeomAPI_IntCS, GeomAPI_ProjectPointOnSurf
20+
from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2, gp_Vec
21+
from OCC.Core.TColgp import TColgp_Array1OfPnt
3222
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
3323
from OCC.Core.GCPnts import GCPnts_AbscissaPoint
3424
from OCC.Core.BRep import BRep_Tool
35-
from OCC.Core.IntTools import IntTools_FClass2d
36-
from OCC.Core.TopAbs import TopAbs_IN
3725
from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape
38-
from OCC.Core.TopoDS import topods, TopoDS_Edge, TopoDS_Compound
39-
from subprocess import call
40-
from OCC.Core.IntCurvesFace import IntCurvesFace_ShapeIntersector
41-
from OCC.Core.Adaptor3d import Adaptor3d_Curve
42-
from OCC.Core.Geom import Geom_Line
26+
from OCC.Core.TopoDS import topods
4327
from OCC.Display.SimpleGui import init_display
44-
from OCC.Core.BRepGProp import (brepgprop_LinearProperties,
45-
brepgprop_SurfaceProperties,
46-
brepgprop_VolumeProperties)
47-
from OCC.Core.GProp import GProp_GProps
4828
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
4929
from OCC.Core.GeomLProp import GeomLProp_SLProps
5030
from OCC.Core.GCPnts import GCPnts_AbscissaPoint
5131
from OCC.Core.BRepAdaptor import (BRepAdaptor_Curve,
5232
BRepAdaptor_CompCurve)
53-
from OCC.Core.GCPnts import GCPnts_UniformDeflection
5433
from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline
55-
from OCC.Core.GeomAbs import (GeomAbs_C0, GeomAbs_G1, GeomAbs_C1, GeomAbs_G2,
56-
GeomAbs_C2, GeomAbs_C3, GeomAbs_CN)
57-
from OCC.Core.GeomProjLib import geomprojlib
58-
from OCC.Core.TopExp import topexp
59-
from OCC.Core.IntCurvesFace import IntCurvesFace_ShapeIntersector
34+
from OCC.Core.GeomAbs import GeomAbs_C2
35+
from OCC.Core.Bnd import Bnd_Box
36+
from OCC.Core.BRepBndLib import brepbndlib
37+
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
38+
from OCC.Display.SimpleGui import init_display
6039

61-
from scipy.spatial import Voronoi, voronoi_plot_2d
40+
from scipy.spatial import Voronoi
6241
from scipy.interpolate import interp1d
63-
import matplotlib.pyplot as plt
64-
6542

6643
def distance(P1, P2):
6744
"""
@@ -249,7 +226,7 @@ def _extract_solid_from_file(self):
249226
sewer.Perform()
250227
result_sewed_blade = sewer.SewedShape()
251228
blade_solid_maker = BRepBuilderAPI_MakeSolid()
252-
blade_solid_maker.Add(OCC.Core.TopoDS.topods_Shell(result_sewed_blade))
229+
blade_solid_maker.Add(OCC.Core.TopoDS.topods.Shell(result_sewed_blade))
253230
if (blade_solid_maker.IsDone()):
254231
self.blade_solid = blade_solid_maker.Solid()
255232
else:
@@ -263,23 +240,27 @@ def _build_cylinder(self, radius):
263240
section taken into account. This method is applied to all the radii in
264241
list 'radii_list' given as input.
265242
"""
266-
axis = gp_Ax2(gp_Pnt(-0.5 * self.conversion_unit, 0.0, 0.0),
243+
# Base point such that cylinder intersect all section
244+
bbox = Bnd_Box()
245+
brepbndlib.Add(self.blade_solid, bbox)
246+
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
247+
248+
axis = gp_Ax2(gp_Pnt(xmin-0.2*abs(xmin), 0.0, 0.0),
267249
gp_Dir(1.0, 0.0, 0.0))
268-
self.cylinder = BRepPrimAPI_MakeCylinder(axis, radius, 1 *
269-
self.conversion_unit).Shape()
250+
self.cylinder = BRepPrimAPI_MakeCylinder(axis, radius, 1.2*(xmax-xmin)).Shape()
270251
faceCount = 0
271252
faces_explorer = TopExp_Explorer(self.cylinder, TopAbs_FACE)
272253

273254
while faces_explorer.More():
274-
face = OCC.Core.TopoDS.topods_Face(faces_explorer.Current())
255+
face = OCC.Core.TopoDS.topods.Face(faces_explorer.Current())
275256
faceCount += 1
276257
# Convert the cylinder faces into Non Uniform Rational Basis-Splines geometry (NURBS)
277258
nurbs_converter = BRepBuilderAPI_NurbsConvert(face)
278259
nurbs_converter.Perform(face)
279260
nurbs_face_converter = nurbs_converter.Shape()
280-
nurbs_face = OCC.Core.TopoDS.topods_Face(nurbs_face_converter)
261+
nurbs_face = OCC.Core.TopoDS.topods.Face(nurbs_face_converter)
281262

282-
surface = BRep_Tool.Surface(OCC.Core.TopoDS.topods_Face(nurbs_face))
263+
surface = BRep_Tool.Surface(OCC.Core.TopoDS.topods.Face(nurbs_face))
283264
self.bounds = 0.0
284265
self.bounds = surface.Bounds()
285266

@@ -301,7 +282,7 @@ def _build_intersection_cylinder_blade(self, radius):
301282
"""
302283
# Construction of the section lines between two shapes (in this case the
303284
# blade and the lateral face of the cylinder)
304-
section_builder = BRepAlgo_Section(self.blade_solid,
285+
section_builder = BRepAlgoAPI_Section(self.blade_solid,
305286
self.cylinder_lateral_face, False)
306287
# Define and build the parametric 2D curve (pcurve) for the section lines defined above
307288
section_builder.ComputePCurveOn2(True)
@@ -320,9 +301,8 @@ def _build_intersection_cylinder_blade(self, radius):
320301
edgeExplorer.Next()
321302
wire_maker.Add(edgeList)
322303
self.wire = wire_maker.Wire()
323-
# Create a 3D curve from a wire
324304
self.curve_adaptor = BRepAdaptor_CompCurve(
325-
OCC.Core.TopoDS.topods_Wire(self.wire))
305+
OCC.Core.TopoDS.topods.Wire(self.wire))
326306
# Length of the curve section (ascissa curvilinea)
327307
self.total_section_length = GCPnts_AbscissaPoint.Length(
328308
self.curve_adaptor)
@@ -366,42 +346,22 @@ def _voronoi_points(self, radius):
366346
# Create the Voronoi diagram for the 2D points
367347
vor = Voronoi(self.param_plane_points)
368348
vor_points = []
369-
min_u = 1e8
370-
self.start = vor.vertices[0]
371349
# Find in an iterative way the Voronoi points
372350
for i in range(len(vor.vertices)):
373351
p = [vor.vertices[i][0], vor.vertices[i][1]]
374352
if (point_inside_polygon(p[0],
375353
p[1],
376354
self.param_plane_points,
377355
include_edges=True)):
378-
if (p[0] < min_u):
379-
min_u = p[0]
380-
self.start = p
381356
vor_points.append(p)
382-
optimized_vor_points = optimized_path(vor_points, self.start)
383-
us = []
384-
vs = []
385-
uss = []
386-
vss = []
357+
optimized_vor_points = sorted(vor_points, key=lambda x: x[0])
358+
#vor_us includes the X coordinates and vor_vs the Z coordinates
387359
self.vor_us = []
388360
self.vor_vs = []
389-
for p in self.orig_param_plane_points:
390-
us.append(p[0])
391-
vs.append(p[1])
392-
for p in self.param_plane_points:
393-
uss.append(
394-
p[0]
395-
) # coordinates of the points of the original parametric curve
396-
vss.append(p[1])
397361
for p in optimized_vor_points:
398-
self.vor_us.append(
399-
p[0]) # coordinates of the points of the Voronoi map
400-
self.vor_vs.append(
401-
p[1]
402-
) #vor_us includes the X coordinates and vor_vs the Z coordinates
403-
us.append(self.orig_param_plane_points[0][0])
404-
vs.append(self.orig_param_plane_points[0][1])
362+
# coordinates of the points of the Voronoi map
363+
self.vor_us.append(p[0])
364+
self.vor_vs.append(p[1])
405365

406366
def _camber_curve(self, radius):
407367
"""
@@ -427,7 +387,7 @@ def _camber_curve(self, radius):
427387
# BUild the camber line from 3D edges
428388
self.edge_3d = BRepBuilderAPI_MakeEdge(camber_curve).Edge()
429389
camber_curve_adaptor = BRepAdaptor_Curve(
430-
OCC.Core.TopoDS.topods_Edge(self.edge_3d))
390+
OCC.Core.TopoDS.topods.Edge(self.edge_3d))
431391
# Compute the length of the camber curve for each section
432392
camber_curve_length = GCPnts_AbscissaPoint.Length(camber_curve_adaptor)
433393
relative_tolerance = 2.5e-3
@@ -544,7 +504,7 @@ def _camber_curve(self, radius):
544504

545505
full_camber_wire = wire_maker.Wire()
546506
self.full_camber_curve_adaptor = BRepAdaptor_CompCurve(
547-
OCC.Core.TopoDS.topods_Wire(full_camber_wire))
507+
OCC.Core.TopoDS.topods.Wire(full_camber_wire))
548508
self.full_camber_length = GCPnts_AbscissaPoint.Length(
549509
self.full_camber_curve_adaptor)
550510

0 commit comments

Comments
 (0)