Skip to content

Commit 6d79319

Browse files
author
unknown
committed
Issues 1 and 2 fixed
1 parent c766db7 commit 6d79319

File tree

6 files changed

+60
-33
lines changed

6 files changed

+60
-33
lines changed

d3dslic3r.egg-info/PKG-INFO

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: d3dslic3r
3-
Version: 0.3.post1
3+
Version: 0.3.post2
44
Summary: DED SLICER
55
Home-page: https://github.com/majroy/d3dslic3r
66
Author: M J Roy
@@ -16,5 +16,15 @@ Classifier: Programming Language :: Python :: 3.11
1616
Classifier: Intended Audience :: End Users/Desktop
1717
Classifier: Natural Language :: English
1818
License-File: LICENSE
19+
Requires-Dist: vtk>=6.0
20+
Requires-Dist: numpy
21+
Requires-Dist: scipy
22+
Requires-Dist: pyyaml>=5.0
23+
Requires-Dist: matplotlib
24+
Requires-Dist: PyQt5>=5
25+
Requires-Dist: h5py
26+
Requires-Dist: scikit-learn
27+
Requires-Dist: shapely
28+
Requires-Dist: pyclipper
1929

2030
https://github.com/majroy/d3dslic3r

d3dslic3r/d3dslic3r_common.py

+44-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def order_points_in_loop(points):
3535

3636
return np.array(ordered_points)
3737

38-
def get_slice_data(polydata,param,num_slices = True):
38+
def get_slice_data(inp_polydata,param,num_slices = True):
3939
"""
4040
Obtains x,y pairs corresponding to a vtkCutter operation on input polydata
4141
Params:
@@ -46,6 +46,9 @@ def get_slice_data(polydata,param,num_slices = True):
4646
slices: list of numpy arrays corresponding to each polydata intersection
4747
slice_actor_collection: vtkAssembly of slices for display
4848
"""
49+
#make sure that incoming polydata isn't connected to anything
50+
polydata = vtk.vtkPolyData()
51+
polydata.DeepCopy(inp_polydata)
4952
#suppress output from the vtk logger
5053
vtk.vtkLogger.SetStderrVerbosity(vtk.vtkLogger.VERBOSITY_OFF)
5154

@@ -62,6 +65,7 @@ def get_slice_data(polydata,param,num_slices = True):
6265

6366
slice_actor_collection = vtk.vtkAssembly()
6467
slices = []
68+
6569
for z in z_vals:
6670
plane = vtk.vtkPlane()
6771
plane.SetNormal(0, 0, 1)
@@ -72,13 +76,32 @@ def get_slice_data(polydata,param,num_slices = True):
7276
cutter.SetInputData(polydata)
7377
cutter.Update()
7478

75-
points = cutter.GetOutput().GetPoints()
79+
#create loop extractor
80+
loops_extract = vtk.vtkContourLoopExtraction()
81+
#make sure loops are closed
82+
loops_extract.SetOutputModeToPolylines()
83+
#remove any duplicates etc.
84+
loops_extract.CleanPointsOn()
85+
loops_extract.SetInputData(cutter.GetOutput())
86+
loops_extract.Update()
7687

77-
# Convert VTK points to numpy array
78-
if points:
79-
slice_points = v2n(points.GetData())
80-
slices.append(slice_points)
88+
#get output from loop extractor
89+
output = loops_extract.GetOutput()
90+
loop_points = output.GetPoints().GetData()
91+
loops = output.GetLines().GetData()
92+
num_loops = output.GetLines().GetNumberOfCells()
8193

94+
#acquire discrete loops from loop extractor. index references the specific loop in each slice
95+
index = 0
96+
for i in range(num_loops):
97+
#poly_point_count is the number of points that comprise each loop
98+
poly_point_count = np.asarray(loops)[index]
99+
#generate local index of points that comprise each loop
100+
poly_point_ind = np.asarray(loops)[index + 1:index + 1 + poly_point_count]
101+
#push to slices
102+
slices.append(np.asarray(loop_points)[poly_point_ind,:])
103+
index += poly_point_count + 1
104+
82105
# Create a mapper and actor for visualization
83106
cutter_mapper = vtk.vtkPolyDataMapper()
84107
cutter_mapper.SetInputConnection(cutter.GetOutputPort())
@@ -88,6 +111,9 @@ def get_slice_data(polydata,param,num_slices = True):
88111
actor.GetProperty().SetLineWidth(2)
89112
actor.SetMapper(cutter_mapper)
90113
slice_actor_collection.AddPart(actor)
114+
115+
#debug
116+
# np.savetxt('new_outlines.csv', slices[0], delimiter=',')
91117

92118
return slices, slice_actor_collection
93119

@@ -274,20 +300,20 @@ def get_intersections(outline, angular_offset, width, bead_offset = 0.5):
274300
Intersections in all cases, the width of each pass or the number of passes depending on pass_param
275301
"""
276302

277-
zval = np.mean(outline[:,-1])
278-
print('get intersections',zval)
279-
# outline = outline[:,0:2]
303+
trans_cent = np.eye(4)
304+
#move outline to centroid
305+
trans_cent[0:3,-1] = -np.mean(outline, axis=0)
306+
X = do_transform(outline,trans_cent)
307+
#and rotate by angular_offset
280308
trans = np.eye(4)
281-
#move outline to centroid and rotate by angular_offset
282309
a = np.deg2rad(angular_offset) #negative for counterclockwise
283310
trans[0:2,0:2]=np.array([[np.cos(a),-np.sin(a)],[np.sin(a),np.cos(a)]])
284-
trans[0:3,-1] = -np.mean(outline, axis=0)
285-
X = do_transform(outline,trans)
286-
311+
X = do_transform(X,trans)
312+
zval = np.mean(X[:,-1])
287313

288314
limits = get_limits(X,0.)
289315

290-
yrange = [limits[2]*1.2,limits[3]*1.2]
316+
yrange = [limits[2]*2,limits[3]*2]
291317
#break up on the basis of bead width
292318
num_passes = int(np.floor((limits[1]-(width*bead_offset) - limits[0]+(width*bead_offset))/(width*bead_offset)))
293319
xrange = np.linspace(limits[0]+(width*bead_offset),limits[1]-(width*bead_offset),num_passes)
@@ -305,8 +331,9 @@ def get_intersections(outline, angular_offset, width, bead_offset = 0.5):
305331
#Needs to be 3D for transformation
306332
intersections = np.asarray(intersections)
307333
trans_intersections = do_transform(intersections,np.linalg.inv(trans))
334+
trans_intersections = do_transform(trans_intersections,np.linalg.inv(trans_cent))
308335
#return intersections , actual bead offset
309-
return np.column_stack((trans_intersections[:,0:2],np.ones(len(intersections))*zval)) , (xrange[1]-xrange[0])/width
336+
return trans_intersections, (xrange[1]-xrange[0])/width
310337

311338
def line_intersection(line1, line2):
312339
'''
@@ -381,7 +408,8 @@ def respace_equally(X,val):
381408
Ynew=fy(sNew)
382409

383410
X_new=np.stack((Xnew,Ynew),axis=-1)
384-
X_new = np.vstack((X_new, X_new[0,:]))#make sure last point is the same as the first point
411+
if not closed:
412+
X_new = np.vstack((X_new, X_new[0,:]))#make sure last point is the same as the first point
385413
return X_new,Perimeter,nPts
386414

387415
def offset_poly(poly, offset):

d3dslic3r/slic3_widget.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from matplotlib.patches import Polygon
2424
import importlib.resources
2525

26-
from d3dslic3r_common import *
26+
from d3dslic3r.d3dslic3r_common import *
2727
from d3dslic3r.d3dslic3r_gui_common import *
2828
from d3dslic3r.export_widget import export_widget
2929
from d3dslic3r.transform_widget import make_transformation_button_layout, get_trans_from_euler_angles
@@ -154,13 +154,6 @@ def setup(self, MainWindow):
154154
self.by_num_sb.setMaximum(10000)
155155
self.by_num_sb.setValue(20)
156156
self.by_num_sb.setToolTip('Specify number of slices')
157-
self.agglom_param_sb = QtWidgets.QDoubleSpinBox()
158-
self.agglom_param_sb.setPrefix('Threshold = ')
159-
self.agglom_param_sb.setMinimum(0.001)
160-
self.agglom_param_sb.setMaximum(10000)
161-
self.agglom_param_sb.setDecimals(1)
162-
self.agglom_param_sb.setValue(5)
163-
self.agglom_param_sb.setToolTip('Threshold for sub-slicing')
164157
self.update_slice_button = QtWidgets.QPushButton('Slice')
165158
self.update_slice_button.setToolTip('Slice with given paramters')
166159

@@ -169,7 +162,6 @@ def setup(self, MainWindow):
169162
slice_layout.addWidget(self.quantity_rb, 1, 1, 1, 1)
170163
slice_layout.addWidget(self.by_height_sb,2,0,1,1)
171164
slice_layout.addWidget(self.by_num_sb,2,1,1,1)
172-
slice_layout.addWidget(self.agglom_param_sb,3,0,1,1)
173165
slice_layout.addWidget(self.update_slice_button,3,1,1,1)
174166

175167
self.slice_box.setEnabled(False)
@@ -188,6 +180,7 @@ def setup(self, MainWindow):
188180
self.path_outline_cb.setToolTip('Include outline in pathing')
189181
self.rotate_z_path_sb = QtWidgets.QDoubleSpinBox()
190182
self.rotate_z_path_sb.setToolTip('Rotational offset for pathing of slice. Positive is clockwise.')
183+
self.rotate_z_path_sb.setSingleStep(5.00)
191184
self.rotate_z_path_sb.setValue(0)
192185
self.rotate_z_path_sb.setMaximum(180)
193186
self.rotate_z_path_sb.setMinimum(-180)
@@ -629,12 +622,8 @@ def do_slice(self):
629622
else:
630623
self.outlines, self.slice_actors = get_slice_data(self.polydata,self.ui.by_height_sb.value(), False)
631624

632-
self.outlines = get_sub_slice_data(self.outlines,self.ui.agglom_param_sb.value())
633-
634625
#order points
635626
for i in range(len(self.outlines)):
636-
self.outlines[i] = order_points_in_loop(self.outlines[i])
637-
#check for self intersection
638627
if check_self_intersecting(self.outlines[i]):
639628
print('Issue on slice %i'%i)
640629

@@ -752,8 +741,8 @@ def make_paths(self):
752741
intersections, param = get_intersections(outline,theta,self.ui.by_width_sb.value(),offset)
753742

754743

755-
self.ui.bead_offset_sb.setValue(param*100)
756-
self.ui.num_paths_label.setText('N = %i'%(len(intersections)-1))
744+
# update interactor with result
745+
self.ui.num_paths_label.setText('N = %i at %0.2f%%'%(len(intersections)-1,param*100))
757746

758747
#pack up/pair intersections for line paths
759748
for i in np.arange(len(intersections)-1)[::2]:

dist/d3dslic3r-0.3.post1.tar.gz

129 Bytes
Binary file not shown.

dist/d3dslic3r-0.3.post2.tar.gz

198 KB
Binary file not shown.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
setup(name = 'd3dslic3r',
7-
version = '0.3post1',
7+
version = '0.3post2',
88
description = 'DED SLICER',
99
long_description = 'https://github.com/majroy/d3dslic3r',
1010
url = 'https://github.com/majroy/d3dslic3r',

0 commit comments

Comments
 (0)