Пример #1
0
 def toImage(self, xMap, yMap, series, from_, to, pen, antialiased,
             numThreads):
     if USE_THREADS:
         if numThreads == 0:
             numThreads = QThread.idealThreadCount()
         if numThreads <= 0:
             numThreads = 1
     rect = self.__data.boundingRect.toAlignedRect()
     image = QImage(rect.size(), QImage.Format_ARGB32)
     image.fill(Qt.transparent)
     if pen.width() <= 1 and pen.color().alpha() == 255:
         command = QwtDotsCommand()
         command.series = series
         command.rgb = pen.color().rgba()
         if USE_THREADS:
             numPoints = int((to - from_ + 1) / numThreads)
             futures = []
             for i in range(numThreads):
                 pos = rect.topLeft()
                 index0 = from_ + i * numPoints
                 if i == numThreads - 1:
                     command.from_ = index0
                     command.to = to
                     qwtRenderDots(xMap, yMap, command, pos, image)
                 else:
                     command.from_ = index0
                     command.to = index0 + numPoints - 1
                     futures += [
                         QtConcurrent.run(qwtRenderDots, xMap, yMap,
                                          command, pos, image)
                     ]
             for future in futures:
                 future.waitForFinished()
         else:
             command.from_ = from_
             command.to = to
             qwtRenderDots(xMap, yMap, command, rect.topLeft(), image)
     else:
         painter = QPainter(image)
         painter.setPen(pen)
         painter.setRenderHint(QPainter.Antialiasing, antialiased)
         chunkSize = 1000
         for i in range(chunkSize):
             indexTo = min([i + chunkSize - 1, to])
             points = self.toPoints(xMap, yMap, series, i, indexTo)
             painter.drawPoints(points)
     return image
Пример #2
0
 def toImage(self, xMap, yMap, series, from_, to, pen, antialiased):
     """
     Translate a series into a QImage
     
     :param qwt.scale_map.QwtScaleMap xMap: x map
     :param qwt.scale_map.QwtScaleMap yMap: y map
     :param series: Series of points to be mapped
     :param int from_: Index of the first point to be painted
     :param int to: Index of the last point to be painted
     :param QPen pen: Pen used for drawing a point of the image, where a point is mapped to
     :param bool antialiased: True, when the dots should be displayed antialiased
     :return: Image displaying the series
     """
     #TODO: rewrite this method to fix performance issue (litteral translation from C++!)
     rect = self.__data.boundingRect.toAlignedRect()
     image = QImage(rect.size(), QImage.Format_ARGB32)
     image.fill(Qt.transparent)
     if pen.width() <= 1 and pen.color().alpha() == 255:
         bits = image.bits()
         w = image.width()
         h = image.height()
         x0 = rect.topLeft().x()
         y0 = rect.topLeft().y()
         for i in range(from_, to + 1):
             sample = series.sample(i)
             x = int(xMap.transform(sample.x()) + 0.5) - x0
             y = int(yMap.transform(sample.y()) + 0.5) - y0
             if x >= 0 and x < w and y >= 0 and y < h:
                 bits[y * w + x] = pen.color().rgba()
     else:
         painter = QPainter(image)
         painter.setPen(pen)
         painter.setRenderHint(QPainter.Antialiasing, antialiased)
         chunkSize = 1000
         for i in range(chunkSize):
             indexTo = min([i + chunkSize - 1, to])
             points = self.toPoints(xMap, yMap, series, i, indexTo)
             painter.drawPoints(points)
     return image
Пример #3
0
 def toImage(self, xMap, yMap, series, from_, to, pen, antialiased):
     """
     Translate a series into a QImage
     
     :param qwt.scale_map.QwtScaleMap xMap: x map
     :param qwt.scale_map.QwtScaleMap yMap: y map
     :param series: Series of points to be mapped
     :param int from_: Index of the first point to be painted
     :param int to: Index of the last point to be painted
     :param QPen pen: Pen used for drawing a point of the image, where a point is mapped to
     :param bool antialiased: True, when the dots should be displayed antialiased
     :return: Image displaying the series
     """
     #TODO: rewrite this method to fix performance issue (litteral translation from C++!)
     rect = self.__data.boundingRect.toAlignedRect()
     image = QImage(rect.size(), QImage.Format_ARGB32)
     image.fill(Qt.transparent)
     if pen.width() <= 1 and pen.color().alpha() == 255:
         bits = image.bits()
         w = image.width()
         h = image.height()
         x0 = rect.topLeft().x()
         y0 = rect.topLeft().y()
         for i in range(from_, to+1):
             sample = series.sample(i)
             x = int(xMap.transform(sample.x())+0.5)-x0
             y = int(yMap.transform(sample.y())+0.5)-y0
             if x >= 0 and x < w and y >= 0 and y < h:
                 bits[y*w+x] = pen.color().rgba()
     else:
         painter = QPainter(image)
         painter.setPen(pen)
         painter.setRenderHint(QPainter.Antialiasing, antialiased)
         chunkSize = 1000
         for i in range(chunkSize):
             indexTo = min([i+chunkSize-1, to])
             points = self.toPoints(xMap, yMap, series, i, indexTo)
             painter.drawPoints(points)
     return image