def updatePlotItems_2D(self, ingredientsList, sliceToPlot=None, resetToMiddleLayer=False): """ Update all plot items on axis, redrawing so everything associated with a specified slice (sliceToPlot) is shown. This is done based upon a list of ingredients """ verbose=False # loop through all plot items searching for imagestack items (these need to be plotted first) for thisIngredient in ingredientsList: if isinstance(thisIngredient, ingredients.imagestack.imagestack): # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #TODO: AXIS need some way of linking the ingredient to the plot item but keeping in mind # that this same object needs to be plotted in different axes, each of which has its own # plot items. So I can't assign a single plot item to the ingredient. Options? # a list of items and axes in the ingredient? I don't like that. #Got to the middle of the stack if sliceToPlot is None or resetToMiddleLayer: stacks = self.lasagna.returnIngredientByType('imagestack') numSlices = [] [numSlices.append(thisStack.data(self.axisToPlot).shape[0]) for thisStack in stacks] numSlices = max(numSlices) sliceToPlot=numSlices/2 self.currentSlice = sliceToPlot if verbose: print "lasagna_axis.updatePlotItems_2D - plotting ingredient " + thisIngredient.objectName thisIngredient.plotIngredient( pyqtObject=lasHelp.findPyQtGraphObjectNameInPlotWidget(self.view,thisIngredient.objectName,verbose=verbose), axisToPlot=self.axisToPlot, sliceToPlot=self.currentSlice ) # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # the image is now displayed # loop through all plot items searching for non-image items (these need to be overlaid on top of the image) for thisIngredient in ingredientsList: if isinstance(thisIngredient, ingredients.imagestack.imagestack)==False: if verbose: print "lasagna_axis.updatePlotItems_2D - plotting ingredient " + thisIngredient.objectName thisIngredient.plotIngredient(pyqtObject=lasHelp.findPyQtGraphObjectNameInPlotWidget(self.view,thisIngredient.objectName,verbose=verbose), axisToPlot=self.axisToPlot, sliceToPlot=self.currentSlice )
def hook_updateMainWindowOnMouseMove_End(self): """ This will run whenever the mouse moves in x or y across one of the axes in the main plot TODO: it would be nice to also run this on mouse wheel """ X = self.lasagna.mouseX Y = self.lasagna.mouseY #Get the widget that the mouse is currently in pos = QtGui.QCursor.pos() PlotWidget = QtGui.qApp.widgetAt( pos).parent() #The mouse is in this widget #Get the base image from this widget selectedStackName = self.lasagna.selectedStackName() ImageItem = lasagna_helperFunctions.findPyQtGraphObjectNameInPlotWidget( PlotWidget, itemName=selectedStackName, regex=True) if ImageItem == False: return #Extract data from base image if ImageItem != None: if ImageItem.image.shape[1] <= Y or Y < 0: return xData = ImageItem.image[:, Y] self.graphicsView.clear() self.graphicsView.plot(xData) #Link the x axis of the cross-section view with the x axis of the image view #Do not use self.graphicsView.setXLink() as it is bidirectional xRange = PlotWidget.viewRange()[0] self.graphicsView.setXRange(min=xRange[0], max=xRange[1])
def hook_updateMainWindowOnMouseMove_End(self): """ This will run whenever the mouse moves in x or y across one of the axes in the main plot TODO: it would be nice to also run this on mouse wheel """ X = self.lasagna.mouseX Y = self.lasagna.mouseY #Get the widget that the mouse is currently in pos = QtGui.QCursor.pos() PlotWidget = QtGui.qApp.widgetAt(pos).parent() #The mouse is in this widget #Get the base image from this widget selectedStackName = self.lasagna.selectedStackName() ImageItem = lasagna_helperFunctions.findPyQtGraphObjectNameInPlotWidget(PlotWidget,itemName=selectedStackName,regex=True) if ImageItem==False: return #Extract data from base image if ImageItem != None: if ImageItem.image.shape[1]<=Y or Y<0: return xData = ImageItem.image[:,Y] self.graphicsView.clear() self.graphicsView.plot(xData) #Link the x axis of the cross-section view with the x axis of the image view #Do not use self.graphicsView.setXLink() as it is bidirectional xRange = PlotWidget.viewRange()[0] self.graphicsView.setXRange(min=xRange[0], max=xRange[1])