Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cura/LayerPolygon.py')
-rw-r--r--cura/LayerPolygon.py73
1 files changed, 42 insertions, 31 deletions
diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py
index 70d818f1ca..6e518e984a 100644
--- a/cura/LayerPolygon.py
+++ b/cura/LayerPolygon.py
@@ -26,14 +26,17 @@ class LayerPolygon:
__jump_map = numpy.logical_or(numpy.logical_or(numpy.arange(__number_of_types) == NoneType, numpy.arange(__number_of_types) == MoveCombingType), numpy.arange(__number_of_types) == MoveRetractionType)
- ## LayerPolygon, used in ProcessSlicedLayersJob
- # \param extruder The position of the extruder
- # \param line_types array with line_types
- # \param data new_points
- # \param line_widths array with line widths
- # \param line_thicknesses: array with type as index and thickness as value
- # \param line_feedrates array with line feedrates
def __init__(self, extruder: int, line_types: numpy.ndarray, data: numpy.ndarray, line_widths: numpy.ndarray, line_thicknesses: numpy.ndarray, line_feedrates: numpy.ndarray) -> None:
+ """LayerPolygon, used in ProcessSlicedLayersJob
+
+ :param extruder: The position of the extruder
+ :param line_types: array with line_types
+ :param data: new_points
+ :param line_widths: array with line widths
+ :param line_thicknesses: array with type as index and thickness as value
+ :param line_feedrates: array with line feedrates
+ """
+
self._extruder = extruder
self._types = line_types
for i in range(len(self._types)):
@@ -59,21 +62,21 @@ class LayerPolygon:
# re-used and can save alot of memory usage.
self._color_map = LayerPolygon.getColorMap()
self._colors = self._color_map[self._types] # type: numpy.ndarray
-
+
# When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType
# Should be generated in better way, not hardcoded.
self._is_infill_or_skin_type_map = numpy.array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], dtype = numpy.bool)
-
+
self._build_cache_line_mesh_mask = None # type: Optional[numpy.ndarray]
self._build_cache_needed_points = None # type: Optional[numpy.ndarray]
-
+
def buildCache(self) -> None:
# For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out.
self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype = bool)
mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask)
self._index_begin = 0
self._index_end = mesh_line_count
-
+
self._build_cache_needed_points = numpy.ones((len(self._types), 2), dtype = numpy.bool)
# Only if the type of line segment changes do we need to add an extra vertex to change colors
self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1]
@@ -83,19 +86,22 @@ class LayerPolygon:
self._vertex_begin = 0
self._vertex_end = numpy.sum( self._build_cache_needed_points )
- ## Set all the arrays provided by the function caller, representing the LayerPolygon
- # The arrays are either by vertex or by indices.
- #
- # \param vertex_offset : determines where to start and end filling the arrays
- # \param index_offset : determines where to start and end filling the arrays
- # \param vertices : vertex numpy array to be filled
- # \param colors : 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 line_types : vertex numpy array to be filled
- # \param indices : index numpy array to be filled
def build(self, vertex_offset: int, index_offset: int, vertices: numpy.ndarray, colors: numpy.ndarray, line_dimensions: numpy.ndarray, feedrates: numpy.ndarray, extruders: numpy.ndarray, line_types: numpy.ndarray, indices: numpy.ndarray) -> None:
+ """Set all the arrays provided by the function caller, representing the LayerPolygon
+
+ The arrays are either by vertex or by indices.
+
+ :param vertex_offset: determines where to start and end filling the arrays
+ :param index_offset: determines where to start and end filling the arrays
+ :param vertices: vertex numpy array to be filled
+ :param colors: 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 line_types: vertex numpy array to be filled
+ :param indices: index numpy array to be filled
+ """
+
if self._build_cache_line_mesh_mask is None or self._build_cache_needed_points is None:
self.buildCache()
@@ -105,16 +111,16 @@ class LayerPolygon:
line_mesh_mask = self._build_cache_line_mesh_mask
needed_points_list = self._build_cache_needed_points
-
+
# Index to the points we need to represent the line mesh. This is constructed by generating simple
# start and end points for each line. For line segment n these are points n and n+1. Row n reads [n n+1]
# Then then the indices for the points we don't need are thrown away based on the pre-calculated list.
index_list = ( numpy.arange(len(self._types)).reshape((-1, 1)) + numpy.array([[0, 1]]) ).reshape((-1, 1))[needed_points_list.reshape((-1, 1))]
-
+
# The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset.
self._vertex_begin += vertex_offset
self._vertex_end += vertex_offset
-
+
# Points are picked based on the index list to get the vertices needed.
vertices[self._vertex_begin:self._vertex_end, :] = self._data[index_list, :]
@@ -136,14 +142,14 @@ class LayerPolygon:
# The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset.
self._index_begin += index_offset
self._index_end += index_offset
-
+
indices[self._index_begin:self._index_end, :] = numpy.arange(self._index_end-self._index_begin, dtype = numpy.int32).reshape((-1, 1))
# When the line type changes the index needs to be increased by 2.
indices[self._index_begin:self._index_end, :] += numpy.cumsum(needed_points_list[line_mesh_mask.ravel(), 0], dtype = numpy.int32).reshape((-1, 1))
# Each line segment goes from it's starting point p to p+1, offset by the vertex index.
# The -1 is to compensate for the neccecarily True value of needed_points_list[0,0] which causes an unwanted +1 in cumsum above.
indices[self._index_begin:self._index_end, :] += numpy.array([self._vertex_begin - 1, self._vertex_begin])
-
+
self._build_cache_line_mesh_mask = None
self._build_cache_needed_points = None
@@ -189,7 +195,7 @@ class LayerPolygon:
@property
def lineFeedrates(self):
return self._line_feedrates
-
+
@property
def jumpMask(self):
return self._jump_mask
@@ -202,8 +208,12 @@ class LayerPolygon:
def jumpCount(self):
return self._jump_count
- # Calculate normals for the entire polygon using numpy.
def getNormals(self) -> numpy.ndarray:
+ """Calculate normals for the entire polygon using numpy.
+
+ :return: normals for the entire polygon
+ """
+
normals = numpy.copy(self._data)
normals[:, 1] = 0.0 # We are only interested in 2D normals
@@ -229,9 +239,10 @@ class LayerPolygon:
__color_map = None # type: numpy.ndarray
- ## Gets the instance of the VersionUpgradeManager, or creates one.
@classmethod
def getColorMap(cls) -> numpy.ndarray:
+ """Gets the instance of the VersionUpgradeManager, or creates one."""
+
if cls.__color_map is None:
theme = cast(Theme, QtApplication.getInstance().getTheme())
cls.__color_map = numpy.array([