Skip to content

Commit

Permalink
Removed need to save stl's
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBell committed Mar 5, 2025
1 parent c640f6c commit f79dbc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
20 changes: 6 additions & 14 deletions ShipGen/Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .tools import Guided_Cond_DDPM_Tools as GC_DDPM
from .tools.HullParameterization import Hull_Parameterization as HP
from .__init__ import data_path, trained_models_path

from stl import mesh


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Expand Down Expand Up @@ -206,7 +206,7 @@ def check_feasibility(x_samples:np.ndarray):
def generate_hulls(final_count:int,
reject_count:int|None = None,
characteristics:ShipCharacteristics|None = None,
reject_ratio:float = 9):
reject_ratio:float = 9) -> list[mesh.Mesh]:
if characteristics is None:
Ship = np.array([333, 42.624, 11.28, 29.064, 97561,16])
else: Ship = characteristics.as_array()
Expand All @@ -232,23 +232,15 @@ def generate_hulls(final_count:int,

Rt_guidance = T.Predict_Drag(unnorm, drag_cond)

path = "./Hulls/"

label = 'Hull_'

isExist = os.path.exists(path)
if not isExist:
os.makedirs(path)

valid_idx = check_feasibility(x_samples)

idxs = np.argsort(Rt_guidance[valid_idx].flatten())

meshs:list[mesh.Mesh] = []
for i in tqdm(range(0,10)):
Hull = HP(x_samples[valid_idx[idxs[i]]])
#make the .stl file of the hull:
strpath = path+label + '_' + str(valid_idx[idxs[i]])
try:
mesh = Hull.gen_stl(NUM_WL=47, PointsPerWL=151, bit_AddTransom = 1, bit_AddDeckLid = 1, bit_RefineBowAndStern = 1,namepath = strpath)
meshs.append(Hull.gen_stl(NUM_WL=47, PointsPerWL=151, bit_AddTransom = 1, bit_AddDeckLid = 1, bit_RefineBowAndStern = 1,namepath = None))
except:
print('Error at hull {}'.format(valid_idx[idxs[i]]))
print('Error at hull {}'.format(valid_idx[idxs[i]]))
return meshs
4 changes: 2 additions & 2 deletions ShipGen/tools/HullParameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1931,8 +1931,8 @@ def gen_stl(self, NUM_WL = 50, PointsPerWL = 300, bit_AddTransom = 1, bit_AddDec
HULL.vectors[startTriangles + 2*i - 1] = np.array([pts_Lids[i], pts_Lidp[i], pts_Lids[i+1]])
HULL.vectors[startTriangles + 2*i] = np.array([pts_Lids[i+1], pts_Lidp[i], pts_Lidp[i+1]])

HULL.save(namepath + '.stl')
if not (namepath is None):
HULL.save(namepath + '.stl')
return HULL


Expand Down

0 comments on commit f79dbc1

Please sign in to comment.