Skip to content

Commit

Permalink
Merge pull request #365 from vshekar/faster-raster-drawing
Browse files Browse the repository at this point in the history
Faster raster drawing
  • Loading branch information
vshekar authored Apr 22, 2024
2 parents 969ef44 + a6c9c7c commit fd3b0fc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 67 deletions.
113 changes: 52 additions & 61 deletions gui/control_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2918,13 +2918,15 @@ def center3LoopCB(self):
self.send_to_server("mvaDescriptor", ["omega", 0])

def fillPolyRaster(
self, rasterReq, waitTime=1
self, rasterReq
): # at this point I should have a drawn polyRaster
time.sleep(waitTime)
logger.info("filling poly for " + str(rasterReq["uid"]))
resultCount = len(db_lib.getResultsforRequest(rasterReq["uid"]))
rasterResults = db_lib.getResultsforRequest(rasterReq["uid"])

if not rasterResults:
return
rasterResult = {}

for i in range(0, len(rasterResults)):
if rasterResults[i]["result_type"] == "rasterResult":
rasterResult = rasterResults[i]
Expand All @@ -2934,6 +2936,7 @@ def fillPolyRaster(
except KeyError:
db_lib.deleteRequest(rasterReq["uid"])
return

rasterListIndex = 0
for i in range(len(self.rasterList)):
if self.rasterList[i] != None:
Expand All @@ -2950,12 +2953,17 @@ def fillPolyRaster(
self.currentRasterCellList = currentRasterGroup.childItems()
cellResults = rasterResult["result_obj"]["rasterCellResults"]["resultObj"]
numLines = len(cellResults)
cellResults_array = [{} for i in range(numLines)]
my_array = np.zeros(numLines)
spotLineCounter = 0
cellIndex = 0
rowStartIndex = 0
rasterEvalOption = str(self.rasterEvalComboBox.currentText())
if rasterEvalOption == "Spot Count":
cell_result_key = "spot_count_no_ice"
elif rasterEvalOption == "Intensity":
cell_result_key = "total_intensity"
else:
cell_result_key = "d_min"
lenX = abs(
rasterDef["rowDefs"][0]["end"]["x"] - rasterDef["rowDefs"][0]["start"]["x"]
) # ugly for tile flip/noflip
Expand All @@ -2974,12 +2982,7 @@ def fillPolyRaster(
"expected: " + str(len(rasterDef["rowDefs"]) * numsteps)
)
return # means a raster failure, and not enough data to cover raster, caused a gui crash
try:
spotcount = cellResult["spot_count_no_ice"]
filename = cellResult["image"]
except TypeError:
spotcount = 0
filename = "empty"


if (
lenX > 180 and self.scannerType == "PI"
Expand All @@ -2990,76 +2993,64 @@ def fillPolyRaster(
cellIndex = spotLineCounter
else:
cellIndex = rowStartIndex + ((numsteps - 1) - j)

try:
if rasterEvalOption == "Spot Count":
my_array[cellIndex] = spotcount
elif rasterEvalOption == "Intensity":
my_array[cellIndex] = cellResult["total_intensity"]
else:
if float(cellResult["d_min"]) == -1:
my_array[cellIndex] = 50.0
else:
my_array[cellIndex] = float(cellResult["d_min"])
my_array[cellIndex] = cellResult[cell_result_key]
if cell_result_key == 'd_min' and my_array[cellIndex] == -1:
my_array[cellIndex] = 50.0

except IndexError:
logger.error("caught index error #2")
logger.error("numlines = " + str(numLines))
logger.error(
"expected: " + str(len(rasterDef["rowDefs"]) * numsteps)
)
return # means a raster failure, and not enough data to cover raster, caused a gui crash
cellResults_array[
cellIndex
] = cellResult # instead of just grabbing filename, get everything. Not sure why I'm building my own list of results. How is this different from cellResults?
# I don't think cellResults_array is different from cellResults, could maybe test that below by subtituting one for the other. It may be a remnant of trying to store less than the whole result set.
spotLineCounter += 1
floor = np.amin(my_array)
ceiling = np.amax(my_array)

cellCounter = 0
color_id = None
if ceiling == 0:
color_id = 255
elif ceiling == floor:
if rasterEvalOption == "Resolution":
color_id = 0
else:
color_id = 255
if color_id is None:
color_ids = ((my_array - floor) / (ceiling - floor)) * 255.0
else:
color_ids = np.full(my_array.shape, color_id)

index = 0
for i in range(len(rasterDef["rowDefs"])):
rowCellCount = 0
for j in range(rasterDef["rowDefs"][i]["numsteps"]):
cellResult = cellResults_array[cellCounter]
try:
spotcount = int(cellResult["spot_count_no_ice"])
cellFilename = cellResult["image"]
d_min = float(cellResult["d_min"])
if d_min == -1:
d_min = 50.0 # trying to handle frames with no spots
total_intensity = int(cellResult["total_intensity"])
except TypeError:
spotcount = 0
cellFilename = "empty"
d_min = 50.0
total_intensity = 0

if rasterEvalOption == "Spot Count":
param = spotcount
elif rasterEvalOption == "Intensity":
param = total_intensity
numsteps = rasterDef["rowDefs"][i]["numsteps"]
rowStartIndex = cellCounter
for j in range(numsteps):
if i % 2 == 0: # this is trying to figure out row direction
index = cellCounter
else:
param = d_min
if ceiling == 0:
color_id = 255
elif ceiling == floor:
index = rowStartIndex + ((numsteps - 1) - j)
if color_id is None:
#param = my_array[cellCounter]
if rasterEvalOption == "Resolution":
color_id = 0
color = int(255 - color_ids[index])
else:
color_id = 255
elif rasterEvalOption == "Resolution":
color_id = int(
255.0 * (float(param - floor) / float(ceiling - floor))
color = int(color_ids[index])
self.currentRasterCellList[index].setBrush(
QtGui.QBrush(QtGui.QColor(0, color, 0, 127))
)
else:
color_id = int(
255 - (255.0 * (float(param - floor) / float(ceiling - floor)))
self.currentRasterCellList[index].setBrush(
QtGui.QBrush(QtGui.QColor(0, 255 - color_id, 0, 127))
)
self.currentRasterCellList[cellCounter].setBrush(
QtGui.QBrush(QtGui.QColor(0, 255 - color_id, 0, 127))
)
self.currentRasterCellList[cellCounter].setData(0, spotcount)
self.currentRasterCellList[cellCounter].setData(1, cellFilename)
self.currentRasterCellList[cellCounter].setData(2, d_min)
self.currentRasterCellList[cellCounter].setData(3, total_intensity)
cellResult = cellResults[cellCounter]
self.currentRasterCellList[index].setData(0, cellResult.get("spot_count_no_ice", 0))
self.currentRasterCellList[index].setData(1, cellResult.get("image", "empty"))
self.currentRasterCellList[index].setData(2, cellResult.get("d_min", 50.0))
self.currentRasterCellList[index].setData(3, cellResult.get("total_intensity", 0))
cellCounter += 1

def takeRasterSnapshot(self, rasterReq):
Expand Down
24 changes: 18 additions & 6 deletions gui/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,25 @@ def mouseReleaseEvent(self, e):
def hoverMoveEvent(self, e):
super(RasterGroup, self).hoverEnterEvent(e)
for cell in self.childItems():
if isInCell(e.scenePos(), cell):
if cell.contains(e.pos()):
if cell.data(0) != None:
spotcount = cell.data(0)
d_min = cell.data(2)
intensity = cell.data(3)
if not (self.parent.rasterExploreDialog.isVisible()):
self.parent.rasterExploreDialog.show()
self.parent.rasterExploreDialog.setSpotCount(spotcount)
self.parent.rasterExploreDialog.setTotalIntensity(intensity)
self.parent.rasterExploreDialog.setResolution(d_min)
viewPos = self.scene().views()[0].mapFromScene(self.scenePos())
globalPos = self.scene().views()[0].mapToGlobal(viewPos)
text = ""
table_data = {}

table_data['Spot Count'] = spotcount
table_data['Total Intensity'] = intensity
table_data['Resolution'] = d_min

text = """<table border='1' style='border-collapse: collapse;'>
"""
for key, value in table_data.items():
text += f"""<tr><td style='border: 1px solid black;'>{key}</td>
<td style='border: 1px solid black;'>{value}</td></tr>"""
text = text + "</table>"

QtWidgets.QToolTip.showText(globalPos, text)

0 comments on commit fd3b0fc

Please sign in to comment.