Skip to content

Commit

Permalink
massive improvements in python
Browse files Browse the repository at this point in the history
  • Loading branch information
Liech committed Nov 17, 2023
1 parent 802b331 commit 363c28f
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 164 deletions.
98 changes: 38 additions & 60 deletions Examples/NonPlanarWobbleSlicer/Categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
config = getData({'Name':'config'});
VoxelResolution = config['VoxelResolution'];
WallThickness = config['WallThickness'];
NozzleDiameter = config['NozzleDiameter'];
Detail = config['Detail'];

NozzleDiameter = config['NozzleDiameter'];
Detail = config['Detail'];
WallAmount = config['WallAmount'];
IO = config['IntermediateFiles'];

print('Voxelize Model')
boundary = voxelizationBoundary({'Name':'Main', 'Resolution':VoxelResolution[0], 'OuterVoxels' : 2})
Expand All @@ -21,16 +22,17 @@
'Start' : voxelizeMin,
'End' : voxelizeMax
});
print(' Remesh Model')
triangulateVolume({
'VoxelName': 'Main',
'ModelName': 'Remeshed',
'Resolution' : VoxelResolution,
'Start' : voxelizeMin,
'End' : voxelizeMax
});
print(' Save Model')
#saveModel({"Name":"Remeshed","Filename":"remeshed.stl"});
if (IO):
print(' Remesh Model')
triangulateVolume({
'VoxelName': 'Main',
'ModelName': 'Remeshed',
'Resolution' : VoxelResolution,
'Start' : voxelizeMin,
'End' : voxelizeMax
});
print(' Save Model')
saveModel({"Name":"Remeshed","Filename":"dbg/remeshed.stl"});


print('Distance Map')
Expand All @@ -42,61 +44,37 @@
'Mode' : 'XY' # XY / XYZ
});



print(' transform for remesh');
transformDistanceMap({
'DistanceMapName' : 'Main',
'VoxelName' : 'Remeshed',
'Distance' : 1e-7
});
print(' remesh distancemap');
triangulateVolume({
'VoxelName': 'Main',
'ModelName': 'Remeshed',
'Resolution' : VoxelResolution,
'Start' : voxelizeMin,
'End' : voxelizeMax
});
#saveModel({"Name":"Remeshed","Filename":"dist_remeshed.stl"});


voxelSize = (voxelizeMax[0]-voxelizeMin[0]) / VoxelResolution[0];
print('Voxel Size: ' + str(voxelSize))

eroded = 0.0;

print('Mapping Areas');

transformDistanceMap({


for i in range(0,WallAmount+1):
print('Wall Number: ' + str(i) + "/" + str(WallAmount));
name= 'OuterAreaWall' + str(i)
transformDistanceMap({
'DistanceMapName' : 'Main',
'VoxelName' : 'InnerArea',
'Distance' : (NozzleDiameter*2/voxelSize)
});
copyVoxel({
'Source' : 'Main',
'Target' : 'OuterArea'
});
subtractVoxel({
'Target' : 'OuterArea',
'Tool' : 'InnerArea'
});
triangulateVolume({
'VoxelName': 'OuterArea',
'ModelName': 'OuterArea',
'Resolution' : VoxelResolution,
'Start' : voxelizeMin,
'End' : voxelizeMax
});
triangulateVolume({
'VoxelName': 'InnerArea',
'ModelName': 'InnerArea',
'VoxelName' : 'Erosion',
'Distance' : (i+0.5)*(NozzleDiameter/voxelSize)
});
if (i==WallAmount):
name = "InnerArea";
triangulateVolume({
'VoxelName': 'Erosion',
'ModelName': name,
'Resolution' : VoxelResolution,
'Start' : voxelizeMin,
'End' : voxelizeMax
});
if (Detail < 1):
simplifyModel({'Name':'InnerArea', "Ratio":Detail})
simplifyModel({'Name':'OuterArea', "Ratio":Detail})
#saveModel({"Name":"InnerArea","Filename":"dbg/InnerArea.stl"});
#saveModel({"Name":"OuterArea","Filename":"dbg/OuterArea.stl"});
});
if (IO):
saveModel({"Name":name,"Filename":"dbg/" + name + ".stl"});
if (Detail < 1):
simplifyModel({'Name':name, "Ratio":Detail})
if (IO):
saveModel({"Name":name,"Filename":"dbg/" + name + "_simplified.stl"});

setData({'Name':'OuterAreaWallAmount', 'Data':WallAmount});
17 changes: 14 additions & 3 deletions Examples/NonPlanarWobbleSlicer/LoadModel.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import os
import shutil

print("Load Model");

config = getData({'Name':'config'});
Filename = config['Filename'];
BuildplateCenter = config['BuildplateCenter'];
Detail = config['Detail'];
IO = config['IntermediateFiles'];

if (IO):
if os.path.exists('dbg') and os.path.isdir('dbg'):
shutil.rmtree('dbg')
os.mkdir('dbg')
os.mkdir('dbg/slice');

loadModel({'Name': 'Main', 'Filename':Filename})
repairModel({'Name':'Main'})
if (Detail < 1):
simplifyModel({'Name':'Main', "Ratio":Detail})
#if (Detail < 1):
simplifyModel({'Name':'Main', "Ratio":0.1})

print('Center Model')

Expand All @@ -23,5 +33,6 @@
offset[2] = BuildplateCenter[2]-BottomCenter[2];

transformModel({'Name':'Main','Offset':offset})
saveModel({"Name":"Main","Filename":"dbg/Main.stl"});
if (IO):
saveModel({"Name":"Main","Filename":"dbg/Main.stl"});
print('Load finished')
76 changes: 0 additions & 76 deletions Examples/NonPlanarWobbleSlicer/PrepareWall.py

This file was deleted.

11 changes: 9 additions & 2 deletions Examples/NonPlanarWobbleSlicer/SliceInner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

config = getData({'Name':'config'});
NozzleDiameter = config['NozzleDiameter'];
IO = config['IntermediateFiles'];


zCounter = getData({'Name':'ZCounter'});
Expand All @@ -17,7 +18,8 @@
'ResultName' : 'SliceZ'
});
print(" sliced");
saveModel({"Name":"SliceZ","Filename":"slice/SliceZ" + str(zCounter) + ".stl"});
if (IO):
saveModel({"Name":"SliceZ","Filename":"dbg/SliceZ" + str(zCounter) + ".stl"});

boundary = modelBoundary({'Name':'SliceZ'})
sliceMin=boundary['Min']
Expand All @@ -42,14 +44,19 @@
'Normal' : [1,0,0],
'Size' : 5000
});
if (IO):
saveModel({"Name":"SliceX","Filename":"dbg/SliceX" + str(X) + ".stl"});
streakName = 'Streak' + str(counter);
sliceModel({
'ModelName' : 'SliceZ',
'ToolName' : 'SliceX',
'Mode' : 'Line',
'LineName' : streakName
});

if (IO):
saveText({
'Text' : linearPrint({'Line': streakName,'Feedrate': 0.03}),
'Filename' : "dbg/slice/layer" + str(zCounter) + "_inner" + str(X) + ".gcode"});
streaks.append(streakName);

X = X + NozzleDiameter;
Expand Down
23 changes: 13 additions & 10 deletions Examples/NonPlanarWobbleSlicer/SliceOuter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

print('Slice Outer');

config = getData({'Name':'config'});
NozzleDiameter = config['NozzleDiameter'];
config = getData({'Name':'config'});
NozzleDiameter = config['NozzleDiameter'];
IO = config['IntermediateFiles'];

amountErosion = getData({'Name':'OuterAreaWallAmount'});
wallAmount = getData({'Name':'OuterAreaWallAmount'});

zCounter = getData({'Name':'ZCounter'});
streaks = [];
for i in range(0,amountErosion):
for i in range(0,wallAmount):
print(i);
streakname = "Streak" + str(i);
sliceModel({
Expand All @@ -18,16 +19,18 @@
'LineName' : streakname
});
streaks.append(streakname);
#saveText({
# 'Text' : linearPrint({'Line': streakname,'Feedrate': 0.03}),
# 'Filename' : "dbg/SliceOuter/layer" + str(zCounter) + "ero" + str(i) + ".gcode"});
sliceModel({

if (IO):
saveText({
'Text' : linearPrint({'Line': streakname,'Feedrate': 0.03}),
'Filename' : "dbg/slice/layer" + str(zCounter) + "_wall" + str(i) + ".gcode"});
sliceModel({
'ModelName' : 'OuterAreaWall' + str(i),
'ToolName' : 'Slice',
'Mode' : 'Model',
'ResultName' : 'dbg'
});
#saveModel({"Name":"dbg","Filename":"dbg/SliceOuter/layer" + str(zCounter) + "ero" + str(i) + ".stl"});
});
saveModel({"Name":"dbg","Filename":"dbg/slice/layer" + str(zCounter) + "_wall" + str(i) + ".stl"});

mergeLines({
'Result':'Result' + str(zCounter),
Expand Down
8 changes: 5 additions & 3 deletions Examples/NonPlanarWobbleSlicer/createSlice.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
print("Create Z Slice");

config = getData({'Name':'config'});
config = getData({'Name':'config'});
SliceResolution = config['SliceResolution'];
PlanarSlicing = config["PlanarSlicing"];
PlanarSlicing = config["PlanarSlicing"];
IO = config['IntermediateFiles'];

Z = getData({'Name':'Z'});
counter = getData({'Name':'ZCounter'});
Expand Down Expand Up @@ -37,6 +38,7 @@
else:
triangulateDouble({"DoubleName":"Slice","ModelName":"Slice","Resolution":SliceResolution,"Start":voxelizeMin,"End":voxelizeMax,"Isovalue":isovalue})

saveModel({"Name":"Slice","Filename":"dbg/createSlice/Slice" + "{:.2f}".format(Z) + ".stl"});
if (IO):
saveModel({"Name":"Slice","Filename":"dbg/slice/ZSlice" + "{:.2f}".format(Z) + ".stl"});
#simplifyModel({'Name':'Slice', "Ratio":0.6})
#saveModel({"Name":"Slice","Filename":"slice/SliceR" + "{:.2f}".format(Z) + ".stl"});
18 changes: 12 additions & 6 deletions Examples/NonPlanarWobbleSlicer/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from PolyglotModule import *

print("Prepare Config");
config = {
'Filename':"3DBenchy.stl",
'ResultFilename' : '3DBenchy.gcode',
'BuildplateCenter' : [100,100,0],
'LayerHeight' : 0.2,
'WallAmount' : 2,
'NozzleDiameter' : 0.43,
'VoxelResolution':[1024,1024,1024],
'VoxelResolution':[512,512,512],
'SliceResolution':[32,32,32],
'WallThickness' : 0.4,
'PlanarSlicing' : False,
'LayerLimit' : -1,
'Detail' : 0.1 #0.0-1.0
'PlanarSlicing' : True,
'LayerLimit' : -1, # -1 for unlimited
'Detail' : 0.3, #0.0-1.0
'IntermediateFiles' : False
};

#createPlane({
Expand All @@ -33,12 +35,16 @@

setData({'Name':'ZCounter', 'Data' : 0});

print("Start:" + 'LoadModel.py');
executePythonFile({'Filename' : 'LoadModel.py'}); # Defines Model 'Main'
if (config["PlanarSlicing"] == False):
print("Start:" + 'BuildZSliceField.py');
executePythonFile({'Filename' : 'BuildZSliceField.py'});
print("Start:" + 'Categorize.py');
executePythonFile({'Filename' : 'Categorize.py'}); # Defines Model 'InnerArea' and 'OuterArea'
executePythonFile({'Filename' : 'PrepareWall.py'});
print("Start:" + 'SliceZ.py');
executePythonFile({'Filename' : 'SliceZ.py'}); # Defines Lines 'Result0'...'ResultN' [N = getData({'ZCounter'})
print("Start:" + 'WriteGCode.py');
executePythonFile({'Filename' : 'WriteGCode.py'});


Expand Down
Binary file removed Examples/NonPlanarWobbleSlicer/slice2model.stl
Binary file not shown.
Binary file removed Examples/NonPlanarWobbleSlicer/slice2tool.stl
Binary file not shown.
Loading

0 comments on commit 363c28f

Please sign in to comment.