mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Add line thickness and feedrate to the data sent from the backend
This commit is contained in:
parent
1ff2541947
commit
aa9f9d5b88
6 changed files with 42 additions and 15 deletions
|
@ -47,12 +47,12 @@ class Layer:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices):
|
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices):
|
||||||
result_vertex_offset = vertex_offset
|
result_vertex_offset = vertex_offset
|
||||||
result_index_offset = index_offset
|
result_index_offset = index_offset
|
||||||
self._element_count = 0
|
self._element_count = 0
|
||||||
for polygon in self._polygons:
|
for polygon in self._polygons:
|
||||||
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, extruders, line_types, indices)
|
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices)
|
||||||
result_vertex_offset += polygon.lineMeshVertexCount()
|
result_vertex_offset += polygon.lineMeshVertexCount()
|
||||||
result_index_offset += polygon.lineMeshElementCount()
|
result_index_offset += polygon.lineMeshElementCount()
|
||||||
self._element_count += polygon.elementCount
|
self._element_count += polygon.elementCount
|
||||||
|
|
|
@ -20,11 +20,11 @@ class LayerDataBuilder(MeshBuilder):
|
||||||
if layer not in self._layers:
|
if layer not in self._layers:
|
||||||
self._layers[layer] = Layer(layer)
|
self._layers[layer] = Layer(layer)
|
||||||
|
|
||||||
def addPolygon(self, layer, polygon_type, data, line_width):
|
def addPolygon(self, layer, polygon_type, data, line_width, line_thickness, line_feedrate):
|
||||||
if layer not in self._layers:
|
if layer not in self._layers:
|
||||||
self.addLayer(layer)
|
self.addLayer(layer)
|
||||||
|
|
||||||
p = LayerPolygon(self, polygon_type, data, line_width)
|
p = LayerPolygon(self, polygon_type, data, line_width, line_thickness, line_feedrate)
|
||||||
self._layers[layer].polygons.append(p)
|
self._layers[layer].polygons.append(p)
|
||||||
|
|
||||||
def getLayer(self, layer):
|
def getLayer(self, layer):
|
||||||
|
@ -64,13 +64,14 @@ class LayerDataBuilder(MeshBuilder):
|
||||||
line_dimensions = numpy.empty((vertex_count, 2), numpy.float32)
|
line_dimensions = numpy.empty((vertex_count, 2), numpy.float32)
|
||||||
colors = numpy.empty((vertex_count, 4), numpy.float32)
|
colors = numpy.empty((vertex_count, 4), numpy.float32)
|
||||||
indices = numpy.empty((index_count, 2), numpy.int32)
|
indices = numpy.empty((index_count, 2), numpy.int32)
|
||||||
|
feedrates = numpy.empty((vertex_count), numpy.float32)
|
||||||
extruders = numpy.empty((vertex_count), numpy.float32)
|
extruders = numpy.empty((vertex_count), numpy.float32)
|
||||||
line_types = numpy.empty((vertex_count), numpy.float32)
|
line_types = numpy.empty((vertex_count), numpy.float32)
|
||||||
|
|
||||||
vertex_offset = 0
|
vertex_offset = 0
|
||||||
index_offset = 0
|
index_offset = 0
|
||||||
for layer, data in sorted(self._layers.items()):
|
for layer, data in sorted(self._layers.items()):
|
||||||
( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices)
|
( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices)
|
||||||
self._element_counts[layer] = data.elementCount
|
self._element_counts[layer] = data.elementCount
|
||||||
|
|
||||||
self.addVertices(vertices)
|
self.addVertices(vertices)
|
||||||
|
@ -107,6 +108,11 @@ class LayerDataBuilder(MeshBuilder):
|
||||||
"value": line_types,
|
"value": line_types,
|
||||||
"opengl_name": "a_line_type",
|
"opengl_name": "a_line_type",
|
||||||
"opengl_type": "float"
|
"opengl_type": "float"
|
||||||
|
},
|
||||||
|
"feedrates": {
|
||||||
|
"value": feedrates,
|
||||||
|
"opengl_name": "a_feedrate",
|
||||||
|
"opengl_type": "float"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ class LayerPolygon:
|
||||||
# \param data new_points
|
# \param data new_points
|
||||||
# \param line_widths array with line widths
|
# \param line_widths array with line widths
|
||||||
# \param line_thicknesses: array with type as index and thickness as value
|
# \param line_thicknesses: array with type as index and thickness as value
|
||||||
def __init__(self, extruder, line_types, data, line_widths, line_thicknesses):
|
# \param line_feedrates array with line feedrates
|
||||||
|
def __init__(self, extruder, line_types, data, line_widths, line_thicknesses, line_feedrates):
|
||||||
self._extruder = extruder
|
self._extruder = extruder
|
||||||
self._types = line_types
|
self._types = line_types
|
||||||
for i in range(len(self._types)):
|
for i in range(len(self._types)):
|
||||||
|
@ -37,6 +38,7 @@ class LayerPolygon:
|
||||||
self._data = data
|
self._data = data
|
||||||
self._line_widths = line_widths
|
self._line_widths = line_widths
|
||||||
self._line_thicknesses = line_thicknesses
|
self._line_thicknesses = line_thicknesses
|
||||||
|
self._line_feedrates = line_feedrates
|
||||||
|
|
||||||
self._vertex_begin = 0
|
self._vertex_begin = 0
|
||||||
self._vertex_end = 0
|
self._vertex_end = 0
|
||||||
|
@ -84,10 +86,11 @@ class LayerPolygon:
|
||||||
# \param vertices : vertex numpy array to be filled
|
# \param vertices : vertex numpy array to be filled
|
||||||
# \param colors : vertex numpy array to be filled
|
# \param colors : vertex numpy array to be filled
|
||||||
# \param line_dimensions : vertex numpy array to be filled
|
# \param line_dimensions : vertex numpy array to be filled
|
||||||
|
# \param feedrates : vertex numpy array to be filled
|
||||||
# \param extruders : vertex numpy array to be filled
|
# \param extruders : vertex numpy array to be filled
|
||||||
# \param line_types : vertex numpy array to be filled
|
# \param line_types : vertex numpy array to be filled
|
||||||
# \param indices : index numpy array to be filled
|
# \param indices : index numpy array to be filled
|
||||||
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices):
|
def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices):
|
||||||
if self._build_cache_line_mesh_mask is None or self._build_cache_needed_points is None:
|
if self._build_cache_line_mesh_mask is None or self._build_cache_needed_points is None:
|
||||||
self.buildCache()
|
self.buildCache()
|
||||||
|
|
||||||
|
@ -109,10 +112,13 @@ class LayerPolygon:
|
||||||
# Create an array with colors for each vertex and remove the color data for the points that has been thrown away.
|
# Create an array with colors for each vertex and remove the color data for the points that has been thrown away.
|
||||||
colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()]
|
colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()]
|
||||||
|
|
||||||
# Create an array with line widths for each vertex.
|
# Create an array with line widths and thicknesses for each vertex.
|
||||||
line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||||
line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||||
|
|
||||||
|
# Create an array with feedrates for each line
|
||||||
|
feedrates[self._vertex_begin:self._vertex_end] = numpy.tile(self._line_feedrates, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0]
|
||||||
|
|
||||||
extruders[self._vertex_begin:self._vertex_end] = self._extruder
|
extruders[self._vertex_begin:self._vertex_end] = self._extruder
|
||||||
|
|
||||||
# Convert type per vertex to type per line
|
# Convert type per vertex to type per line
|
||||||
|
@ -167,6 +173,14 @@ class LayerPolygon:
|
||||||
def lineWidths(self):
|
def lineWidths(self):
|
||||||
return self._line_widths
|
return self._line_widths
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lineThicknesses(self):
|
||||||
|
return self._line_thicknesses
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lineFeedrates(self):
|
||||||
|
return self._line_feedrates
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def jumpMask(self):
|
def jumpMask(self):
|
||||||
return self._jump_mask
|
return self._jump_mask
|
||||||
|
|
|
@ -61,6 +61,8 @@ message Polygon {
|
||||||
Type type = 1; // Type of move
|
Type type = 1; // Type of move
|
||||||
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)
|
bytes points = 2; // The points of the polygon, or two points if only a line segment (Currently only line segments are used)
|
||||||
float line_width = 3; // The width of the line being laid down
|
float line_width = 3; // The width of the line being laid down
|
||||||
|
float line_thickness = 4; // The thickness of the line being laid down
|
||||||
|
float line_feedrate = 5; // The feedrate of the line being laid down
|
||||||
}
|
}
|
||||||
|
|
||||||
message LayerOptimized {
|
message LayerOptimized {
|
||||||
|
@ -82,6 +84,8 @@ message PathSegment {
|
||||||
bytes points = 3; // The points defining the line segments, bytes of float[2/3] array of length N+1
|
bytes points = 3; // The points defining the line segments, bytes of float[2/3] array of length N+1
|
||||||
bytes line_type = 4; // Type of line segment as an unsigned char array of length 1 or N, where N is the number of line segments in this path
|
bytes line_type = 4; // Type of line segment as an unsigned char array of length 1 or N, where N is the number of line segments in this path
|
||||||
bytes line_width = 5; // The widths of the line segments as bytes of a float array of length 1 or N
|
bytes line_width = 5; // The widths of the line segments as bytes of a float array of length 1 or N
|
||||||
|
bytes line_thickness = 6; // The thickness of the line segments as bytes of a float array of length 1 or N
|
||||||
|
bytes line_feedrate = 7; // The feedrate of the line segments as bytes of a float array of length 1 or N
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -128,10 +128,11 @@ class ProcessSlicedLayersJob(Job):
|
||||||
line_widths = numpy.fromstring(polygon.line_width, dtype="f4") # Convert bytearray to numpy array
|
line_widths = numpy.fromstring(polygon.line_width, dtype="f4") # Convert bytearray to numpy array
|
||||||
line_widths = line_widths.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
line_widths = line_widths.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||||
|
|
||||||
# In the future, line_thicknesses should be given by CuraEngine as well.
|
line_thicknesses = numpy.fromstring(polygon.line_thickness, dtype="f4") # Convert bytearray to numpy array
|
||||||
# Currently the infill layer thickness also translates to line width
|
line_thicknesses = line_thicknesses.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||||
line_thicknesses = numpy.zeros(line_widths.shape, dtype="f4")
|
|
||||||
line_thicknesses[:] = layer.thickness / 1000 # from micrometer to millimeter
|
line_feedrates = numpy.fromstring(polygon.line_feedrate, dtype="f4") # Convert bytearray to numpy array
|
||||||
|
line_feedrates = line_feedrates.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
|
||||||
|
|
||||||
# Create a new 3D-array, copy the 2D points over and insert the right height.
|
# Create a new 3D-array, copy the 2D points over and insert the right height.
|
||||||
# This uses manual array creation + copy rather than numpy.insert since this is
|
# This uses manual array creation + copy rather than numpy.insert since this is
|
||||||
|
@ -146,7 +147,7 @@ class ProcessSlicedLayersJob(Job):
|
||||||
new_points[:, 1] = points[:, 2]
|
new_points[:, 1] = points[:, 2]
|
||||||
new_points[:, 2] = -points[:, 1]
|
new_points[:, 2] = -points[:, 1]
|
||||||
|
|
||||||
this_poly = LayerPolygon.LayerPolygon(extruder, line_types, new_points, line_widths, line_thicknesses)
|
this_poly = LayerPolygon.LayerPolygon(extruder, line_types, new_points, line_widths, line_thicknesses, line_feedrates)
|
||||||
this_poly.buildCache()
|
this_poly.buildCache()
|
||||||
|
|
||||||
this_layer.polygons.append(this_poly)
|
this_layer.polygons.append(this_poly)
|
||||||
|
|
|
@ -114,9 +114,11 @@ class GCodeReader(MeshReader):
|
||||||
line_types = numpy.empty((count - 1, 1), numpy.int32)
|
line_types = numpy.empty((count - 1, 1), numpy.int32)
|
||||||
line_widths = numpy.empty((count - 1, 1), numpy.float32)
|
line_widths = numpy.empty((count - 1, 1), numpy.float32)
|
||||||
line_thicknesses = numpy.empty((count - 1, 1), numpy.float32)
|
line_thicknesses = numpy.empty((count - 1, 1), numpy.float32)
|
||||||
|
line_feedrates = numpy.empty((count - 1, 1), numpy.float32)
|
||||||
# TODO: need to calculate actual line width based on E values
|
# TODO: need to calculate actual line width based on E values
|
||||||
line_widths[:, 0] = 0.35 # Just a guess
|
line_widths[:, 0] = 0.35 # Just a guess
|
||||||
line_thicknesses[:, 0] = layer_thickness
|
line_thicknesses[:, 0] = layer_thickness # TODO Same for all, but it should be calculated from the layer height differences
|
||||||
|
line_feedrates[:, 0] = 50 # TODO Now we use 50mm/s as a demo, it should be obtained from the GCode
|
||||||
points = numpy.empty((count, 3), numpy.float32)
|
points = numpy.empty((count, 3), numpy.float32)
|
||||||
i = 0
|
i = 0
|
||||||
for point in path:
|
for point in path:
|
||||||
|
@ -127,7 +129,7 @@ class GCodeReader(MeshReader):
|
||||||
line_widths[i - 1] = 0.1
|
line_widths[i - 1] = 0.1
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
this_poly = LayerPolygon(self._extruder_number, line_types, points, line_widths, line_thicknesses)
|
this_poly = LayerPolygon(self._extruder_number, line_types, points, line_widths, line_thicknesses, line_feedrates)
|
||||||
this_poly.buildCache()
|
this_poly.buildCache()
|
||||||
|
|
||||||
this_layer.polygons.append(this_poly)
|
this_layer.polygons.append(this_poly)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue