def updatePosns(self): xvals = [] yvals = [] for e in self.ellipses: x, y = e.posn() xvals.append((x / width)**2 * self.maxx) yvals.append((height - y) / height) xvals = N.array(xvals) yvals = N.array(yvals) # draw line xpts = N.arange(0, width) xv = (xpts / width)**2 * self.maxx yv = N.interp(xv, xvals, yvals) ypts = height - yv * height path = qt.QPainterPath() path.moveTo(qt.QPointF(xpts[0], ypts[0])) for x, y in zip(xpts[1:], ypts[1:]): path.lineTo(qt.QPointF(x, y)) self.pathitem.setPath(path) # send results to main program self.changed.emit((xvals, yvals))
def __init__(self, vals, *args): qt.QGraphicsScene.__init__(self) self.pathitem = qt.QGraphicsPathItem() self.addItem(self.pathitem) self.pathitem.setZValue(-1) self.ellipses = [] #for i in xrange(10): # ell = MarkerItem(self, i*40, 40) # self.addItem(ell) # self.ellipses.append(ell) maxx = N.max(vals[0]) maxy = N.max(vals[1]) self.maxx = maxx for x, y in zip(*vals): e = MarkerItem(self, N.sqrt(x / maxx) * width, height - y / maxy * height) self.addItem(e) self.ellipses.append(e) self.addLine(qt.QLineF(qt.QPointF(0, 0), qt.QPointF(width, 0))) self.addLine( qt.QLineF(qt.QPointF(0, height), qt.QPointF(width, height))) self.updatePosns()
def editMarkups(self, selectOption, fiducialsNode, curveNode, viewNode): layoutManager = slicer.app.layoutManager() threeDWidget = layoutManager.viewWidget(viewNode) threeDView = threeDWidget.threeDView() aspectRatio = threeDWidget.width / threeDWidget.height className = "vtkMRMLMarkupsDisplayableManager" markupsDisplayableManager = threeDView.displayableManagerByClassName( className) fiducialsWidget = markupsDisplayableManager.GetWidget( fiducialsNode.GetDisplayNode()) fiducialsRepresentation = fiducialsWidget.GetRepresentation() cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode( viewNode) camera = cameraNode.GetCamera() raswToXYZW = vtk.vtkMatrix4x4() modelView = camera.GetModelViewTransformMatrix() projection = camera.GetProjectionTransformMatrix( aspectRatio, 1, 100) # near/far are arbitrary raswToXYZW.Multiply4x4(projection, modelView, raswToXYZW) def rasToColumnRow(ras): rasw = *ras, 1 xyzw = raswToXYZW.MultiplyPoint(rasw) x, y = [xyzw[0], xyzw[1]] if viewNode.GetRenderMode() == viewNode.Perspective: x, y = [x / xyzw[3], y / xyzw[3]] column = (x + 1) / 2 * threeDWidget.width row = (1 - (y + 1) / 2) * threeDWidget.height return column, row selectionPolygon = qt.QPolygonF() for index in range(curveNode.GetNumberOfControlPoints()): ras = [0] * 3 curveNode.GetNthControlPointPositionWorld(index, ras) column, row = rasToColumnRow(ras) point = qt.QPointF(column, row) selectionPolygon.push_back(point) pickImage = qt.QImage(threeDWidget.width, threeDWidget.height, qt.QImage().Format_ARGB32) backgroundColor = qt.QColor("#ffffffff") pickImage.fill(backgroundColor) painter = qt.QPainter() painter.begin(pickImage) painterPath = qt.QPainterPath() painterPath.addPolygon(selectionPolygon) brush = qt.QBrush(qt.Qt.SolidPattern) painter.setBrush(brush) painter.drawPath(painterPath) painter.end() debugging = False if debugging: pixmap = qt.QPixmap().fromImage(pickImage) slicer.modules.label = qt.QLabel() slicer.modules.label.setPixmap(pixmap) slicer.modules.label.show() visibleCount = 0 pickedCount = 0 for index in range(fiducialsNode.GetNumberOfControlPoints()): pointVisible = fiducialsRepresentation.GetNthControlPointViewVisibility( index) if pointVisible: visibleCount += 1 ras = [0] * 3 fiducialsNode.GetNthControlPointPositionWorld(index, ras) column, row = rasToColumnRow(ras) if (column >= 0 and column < pickImage.width and row >= 0 and row < pickImage.height): pickColor = pickImage.pixelColor(column, row) picked = (pickColor != backgroundColor) if picked: pickedCount += 1 if selectOption == "set": if pointVisible: fiducialsNode.SetNthControlPointSelected(index, picked) else: fiducialsNode.SetNthControlPointSelected(index, False) elif selectOption == "add": if picked and pointVisible: fiducialsNode.SetNthControlPointSelected(index, True) elif selectOption == "unset": if picked and pointVisible: fiducialsNode.SetNthControlPointSelected(index, False) else: logging.error(f"Unknown selectOption {selectOption}")