def createIntensityTransferPage(self): """ Creates a frame holding the entries for configuring intensity """ self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.iTFEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.iTFEditor, (0, 0)) # ,span=(1,2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.createIntensityInterpolationPanel() self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset current timepoint") self.restoreBtn.Bind(wx.EVT_BUTTON, self.iTFEditor.restoreDefaults) self.box.Add(self.restoreBtn) self.resetBtn = wx.Button(self.editIntensityPanel, -1, "Reset all timepoints") self.resetBtn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.box.Add(self.resetBtn) self.copyiTFBtn = wx.Button(self.editIntensityPanel, -1, "Copy to all timepoints") self.copyiTFBtn.Bind(wx.EVT_BUTTON, self.copyTransferFunctionToAll) self.box.Add(self.copyiTFBtn) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.settingsNotebook.InsertPage(0, self.editIntensityPanel, "Transfer Function") self.settingsNotebook.SetSelection(0) self.updateSettings()
def createIntensityTransferPage(self): """ Creates a frame holding the entries for configuring intensity """ self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.iTFEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.iTFEditor, (0, 0)) #,span=(1,2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.createIntensityInterpolationPanel() self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset current timepoint") self.restoreBtn.Bind(wx.EVT_BUTTON, self.iTFEditor.restoreDefaults) self.box.Add(self.restoreBtn) self.resetBtn = wx.Button(self.editIntensityPanel, -1, "Reset all timepoints") self.resetBtn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.box.Add(self.resetBtn) self.copyiTFBtn = wx.Button(self.editIntensityPanel, -1, "Copy to all timepoints") self.copyiTFBtn.Bind(wx.EVT_BUTTON, self.copyTransferFunctionToAll) self.box.Add(self.copyiTFBtn) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.settingsNotebook.InsertPage(0, self.editIntensityPanel, "Transfer Function") self.settingsNotebook.SetSelection(0) self.updateSettings()
def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = ColorTransferEditor.CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.intensityTransferEditor = IntensityTransferEditor( self.editIntensityPanel) self.editIntensitySizer.Add(self.intensityTransferEditor, (0, 0), span=(1, 2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset") self.restoreBtn.Bind(wx.EVT_BUTTON, self.intensityTransferEditor.restoreDefaults) self.box.Add(self.restoreBtn) # The alpha function doesn't need to be edited # Code left if futher need shows ups #self.editAlphaPanel = wx.Panel(self.settingsNotebook,-1) self.editAlphaPanel = wx.Panel(self.editIntensityPanel, -1) self.editAlphaSizer = wx.GridBagSizer() self.alphaModeBox = wx.RadioBox(self.editAlphaPanel, -1, "Alpha channel construction", choices = ["Maximum Mode", "Average Mode", "Image Luminance", "No alpha"], \ majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.alphaModeBox.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.alphaModeBox.Bind(wx.EVT_RADIOBOX, self.modeSelect) self.averageLbl = wx.StaticText(self.editAlphaPanel, -1, "Average Threshold:") self.averageLbl.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit = wx.TextCtrl(self.editAlphaPanel, -1, "", size=(150, -1)) self.averageEdit.Enable(0) self.averageEdit.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit.Bind(wx.EVT_TEXT_ENTER, self.onAverageEdit) self.averageEdit.Bind(wx.EVT_KILL_FOCUS, self.onAverageEdit) box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.averageLbl) box.Add(self.averageEdit) self.editAlphaSizer.Add(self.alphaModeBox, (0, 0)) self.editAlphaSizer.Add(box, (2, 0)) self.editAlphaPanel.SetSizer(self.editAlphaSizer) self.editAlphaSizer.Fit(self.editAlphaPanel) self.editIntensitySizer.Add(self.editAlphaPanel, (4, 0)) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.editIntensityPanel.Layout() self.editIntensitySizer.Fit(self.editIntensityPanel) self.settingsNotebook.AddPage(self.editIntensityPanel, "Intensity")
class MergingPanel(TaskPanel.TaskPanel): """ Description: A window for controlling the settings of the color combination module """ def __init__(self, parent, tb): """ Initialization Parameters: parent Is the parent widget of this window """ self.alphaTF = vtkbxd.vtkIntensityTransferFunction() self.operationName = "Merge" self.createItemSelection = 1 TaskPanel.TaskPanel.__init__(self, parent, tb) self.oldBg = self.GetBackgroundColour() self.mainsizer.Layout() self.mainsizer.Fit(self) def createButtonBox(self): """ Creates a button box containing the buttons Render, Preview and Close """ TaskPanel.TaskPanel.createButtonBox(self) lib.messenger.connect(None, "process_dataset", self.doColorMergingCallback) def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = ColorTransferEditor.CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.intensityTransferEditor = IntensityTransferEditor( self.editIntensityPanel) self.editIntensitySizer.Add(self.intensityTransferEditor, (0, 0), span=(1, 2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset") self.restoreBtn.Bind(wx.EVT_BUTTON, self.intensityTransferEditor.restoreDefaults) self.box.Add(self.restoreBtn) # The alpha function doesn't need to be edited # Code left if futher need shows ups #self.editAlphaPanel = wx.Panel(self.settingsNotebook,-1) self.editAlphaPanel = wx.Panel(self.editIntensityPanel, -1) self.editAlphaSizer = wx.GridBagSizer() self.alphaModeBox = wx.RadioBox(self.editAlphaPanel, -1, "Alpha channel construction", choices = ["Maximum Mode", "Average Mode", "Image Luminance", "No alpha"], \ majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.alphaModeBox.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.alphaModeBox.Bind(wx.EVT_RADIOBOX, self.modeSelect) self.averageLbl = wx.StaticText(self.editAlphaPanel, -1, "Average Threshold:") self.averageLbl.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit = wx.TextCtrl(self.editAlphaPanel, -1, "", size=(150, -1)) self.averageEdit.Enable(0) self.averageEdit.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit.Bind(wx.EVT_TEXT_ENTER, self.onAverageEdit) self.averageEdit.Bind(wx.EVT_KILL_FOCUS, self.onAverageEdit) box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.averageLbl) box.Add(self.averageEdit) self.editAlphaSizer.Add(self.alphaModeBox, (0, 0)) self.editAlphaSizer.Add(box, (2, 0)) self.editAlphaPanel.SetSizer(self.editAlphaSizer) self.editAlphaSizer.Fit(self.editAlphaPanel) self.editIntensitySizer.Add(self.editAlphaPanel, (4, 0)) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.editIntensityPanel.Layout() self.editIntensitySizer.Fit(self.editIntensityPanel) self.settingsNotebook.AddPage(self.editIntensityPanel, "Intensity") #self.settingsNotebook.AddPage(self.editAlphaPanel,"Alpha Channel") # self.optionssizer.Add(self.intensityTransferEditor,(3,0)) def modeSelect(self, event): """ A method that is called when the selection of alpha mode is chan ged """ mode = event.GetInt() try: value = int(self.averageEdit.GetValue()) except: value = 0 self.settings.set("AlphaMode", [mode, value]) if mode == 1: self.averageEdit.Enable(1) else: self.averageEdit.Enable(0) def onAverageEdit(self, evt): """ Method to update settings of current average value """ try: value = int(self.averageEdit.GetValue()) except: value = 0 mode = self.settings.get("AlphaMode") mode[1] = value self.settings.set("AlphaMode", mode) def resetTransferFunctions(self, event=None): """ A method to reset all the intensity transfer functions """ dataunits = self.dataUnit.getSourceDataUnits() for unit in dataunits: setting = unit.getSettings() minval, maxval = unit.getScalarRange() ctf = unit.getColorTransferFunction() ctfmin, ctfmax = ctf.GetRange() print "CTF range=", ctfmax bitmax = (2**unit.getSingleComponentBitDepth() - 1) print "bitmax=", bitmax maxval = max(ctfmax, maxval, bitmax) itf = vtkbxd.vtkIntensityTransferFunction() itf.SetRangeMax(maxval) self.alphaTF.SetRangeMax(maxval) setting.set("IntensityTransferFunction", itf) def updateSettings(self, force=0): """ A method used to set the GUI widgets to their proper values based on the selected channel, the settings of which are stored in the instance variable self.configSetting """ if self.dataUnit and self.settings: ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: Logging.info("Setting ctf of color button", kw="ctf") self.colorBtn.setColorTransferFunction(ctf) self.colorBtn.Refresh() #Logging.info("settings=",self.settings,kw="task") tf = self.settings.get("IntensityTransferFunction") self.intensityTransferEditor.setIntensityTransferFunction(tf) try: mode = self.settings.get("AlphaMode") if types.StringType == type(mode): mode = eval(mode) self.alphaModeBox.SetSelection(mode[0]) if mode[0] == 1: self.averageEdit.Enable(1) else: self.averageEdit.Enable(0) self.averageEdit.SetValue(str(mode[1])) except: pass def doColorMergingCallback(self, *args): """ A callback for the processing button """ #print "\n\n\n\n\nDO COLOR MERGING" method = self.alphaModeBox.GetSelection() val = 0 if method == 1: val = int(self.averageEdit.GetValue()) lst = [method, val] Logging.info("Setting alpha mode to ", lst, kw="task") #self.dataUnit.setAlphaMode(lst) self.settings.set("AlphaMode", lst) TaskPanel.TaskPanel.doOperation(self) def setCombinedDataUnit(self, dataUnit): """ Sets the combined dataunit that is to be processed. It is then used to get the names of all the source data units and they are added to the menu. """ TaskPanel.TaskPanel.setCombinedDataUnit(self, dataUnit) # We add entry "Alpha Channel" to the list of channels to allow # the user to edit the alpha channel for the 24-bit color merging #self.dataUnit.setOpacityTransfer(self.alphaTF) self.settings.set("AlphaTransferFunction", self.alphaTF) ctf = self.settings.get("ColorTransferFunction") sources = dataUnit.getSourceDataUnits() totmax = 0 for i in sources: minval, maxval = i.getScalarRange() ctf = i.getColorTransferFunction() ctfmin, ctfmax = ctf.GetRange() bitmax = 0 sBitDepth = i.getSingleComponentBitDepth() if sBitDepth == 8 or sBitDepth == 12: bitmax = (2**i.getSingleComponentBitDepth() - 1) maxval = max(ctfmax, maxval, bitmax) if maxval > totmax: totmax = maxval self.alphaTF.SetRangeMax(int(totmax)) for i in range(len(sources)): tf = vtkbxd.vtkIntensityTransferFunction() tf.SetRangeMax(int(totmax)) #self.settings.setCounted("IntensityTransferFunction",i,tf,0) sources[i].getSettings().set("IntensityTransferFunction", tf) tf = sources[0].getSettings().get("IntensityTransferFunction") #print "\n\nSETTING ITF EDITOR FUNCTION" self.intensityTransferEditor.setIntensityTransferFunction(tf) for i in range(len(sources)): self.dataUnit.setOutputChannel(i, 1) if self.colorBtn: #Logging.info("Setting ctf of colorbutton to ",ctf,kw="ctf") self.colorBtn.setColorTransferFunction(ctf) else: Logging.info("No color button to set ctf to ", kw="ctf") self.restoreFromCache()
class AdjustPanel(TaskPanel): """ Description: A window for processing a single dataunit """ def __init__(self, parent, tb): """ Initialization Parameters: root Is the parent widget of this window """ self.operationName = "Adjust" self.lbls = [] self.btns = [] self.entries = [] self.timePoint = 0 TaskPanel.__init__(self, parent, tb) # Preview has to be generated heregoto # self.colorChooser=None self.createIntensityTransferPage() lib.messenger.connect(None, "timepoint_changed", self.updateTimepoint) self.Show() self.mainsizer.Fit(self) self.mainsizer.Layout() def createIntensityInterpolationPanel(self): """ Creates a frame holding the entries for configuring interpolation """ self.interpolationPanel = wx.Panel(self.settingsNotebook) # self.interpolationPanel=wx.Panel(self.iTFEditor) self.interpolationSizer = wx.GridBagSizer() lbl = wx.StaticText(self.interpolationPanel, -1, "Interpolate intensities:") self.interpolationSizer.Add(lbl, (0, 0)) lbl = wx.StaticText(self.interpolationPanel, -1, "from timepoint") self.lbls.append(lbl) self.numOfPoints = 5 for i in range(self.numOfPoints - 2): lbl = wx.StaticText(self.interpolationPanel, -1, "thru") self.lbls.append(lbl) lbl = wx.StaticText(self.interpolationPanel, -1, "to timepoint") self.lbls.append(lbl) for i in range(self.numOfPoints): btn = wx.Button(self.interpolationPanel, -1, "goto") btn.Bind(wx.EVT_BUTTON, lambda event, x=i: self.gotoInterpolationTimePoint(x)) entry = wx.TextCtrl(self.interpolationPanel, size=(50, -1)) self.btns.append(btn) self.entries.append(entry) for entry in self.entries: entry.Bind(wx.EVT_TEXT, self.setInterpolationTimePoints) last = 0 for i in range(self.numOfPoints): lbl, entry, btn = self.lbls[i], self.entries[i], self.btns[i] self.interpolationSizer.Add(lbl, (i + 1, 0)) self.interpolationSizer.Add(entry, (i + 1, 1)) self.interpolationSizer.Add(btn, (i + 1, 2)) last = i + 1 # self.editIntensitySizer.Add(self.interpolationPanel,(0,1)) self.interpolationPanel.SetSizer(self.interpolationSizer) self.interpolationPanel.SetAutoLayout(1) self.interpolationSizer.SetSizeHints(self.interpolationPanel) self.settingsNotebook.AddPage(self.interpolationPanel, "Interpolation") self.interpolationBox = wx.BoxSizer(wx.HORIZONTAL) self.reset2Btn = wx.Button(self.interpolationPanel, -1, "Reset all timepoints") self.reset2Btn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.interpolationBox.Add(self.reset2Btn) self.interpolateBtn = wx.Button(self.interpolationPanel, -1, "Interpolate") self.interpolateBtn.Bind(wx.EVT_BUTTON, self.startInterpolation) self.interpolationBox.Add(self.interpolateBtn) self.interpolationSizer.Add(self.interpolationBox, (last + 1, 0)) # self.mainsizer.Add(self.interpolationPanel,(1,0)) # self.panel.Layout() # self.mainsizer.Fit(self.panel) def createIntensityTransferPage(self): """ Creates a frame holding the entries for configuring intensity """ self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.iTFEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.iTFEditor, (0, 0)) # ,span=(1,2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.createIntensityInterpolationPanel() self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset current timepoint") self.restoreBtn.Bind(wx.EVT_BUTTON, self.iTFEditor.restoreDefaults) self.box.Add(self.restoreBtn) self.resetBtn = wx.Button(self.editIntensityPanel, -1, "Reset all timepoints") self.resetBtn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.box.Add(self.resetBtn) self.copyiTFBtn = wx.Button(self.editIntensityPanel, -1, "Copy to all timepoints") self.copyiTFBtn.Bind(wx.EVT_BUTTON, self.copyTransferFunctionToAll) self.box.Add(self.copyiTFBtn) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.settingsNotebook.InsertPage(0, self.editIntensityPanel, "Transfer Function") self.settingsNotebook.SetSelection(0) self.updateSettings() def setInterpolationTimePoints(self, event): """ A callback that is called when a timepoint entry for intensity interpolation changes. Updates the list of timepoints between which the interpolation is carried out by the dataunit """ lst = [] for i in self.entries: val = i.GetValue() try: n = int(val) # n -= 1 lst.append(n) except: # For entries that have no value, add -1 as a place holder lst.append(-1) # self.dataUnit.setInterpolationTimePoints(lst) self.settings.set("InterpolationTimepoints", lst) def gotoInterpolationTimePoint(self, entrynum): """ The previewed timepoint is set to timepoint specified in self.entries[entrynum] """ try: tp = int(self.entries[entrynum].GetValue()) except: pass else: tp -= 1 Logging.info("Previewing timepoint ", tp, "(will send change event)", kw="task") lib.messenger.send(None, "timepoint_changed", tp) # self.updateTimepoint(evt) def createButtonBox(self): """ Creates a button box containing the buttons Render, Preview and Close """ TaskPanel.createButtonBox(self) # self.processButton.SetLabel("Process Dataset Series") # self.processButton.Bind(wx.EVT_BUTTON,self.doProcessingCallback) lib.messenger.connect(None, "process_dataset", self.doProcessingCallback) def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.Layout() def updateTimepoint(self, obj, evt, timePoint): """ A callback function called when the timepoint is changed """ # timePoint=event.getValue() Logging.info("Now configuring timepoint", timePoint, kw="task") itf = self.settings.getCounted("IntensityTransferFunctions", timePoint) self.iTFEditor.setIntensityTransferFunction(itf) self.timePoint = timePoint def copyTransferFunctionToAll(self, event=None): """ A method to copy this transfer function to all timepooints """ itf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) l = self.dataUnit.getNumberOfTimepoints() for i in range(l): if i != self.timePoint: self.settings.setCounted("IntensityTransferFunctions", i, itf) def resetTransferFunctions(self, event=None): """ A method to reset all the intensity transfer functions """ l = self.dataUnit.getNumberOfTimepoints() sources = self.dataUnit.getSourceDataUnits() for i in range(l): minval = min([a.getScalarRange()[0] for a in sources]) maxval = max([a.getScalarRange()[1] for a in sources]) bitdepth = sources[0].getBitDepth() minval = min(0, minval) maxval = max(2 ** bitdepth - 1, maxval) itf = vtkbxd.vtkIntensityTransferFunction() itf.SetRangeMax(maxval) self.settings.setCounted("IntensityTransferFunctions", i, itf) itf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) self.iTFEditor.setIntensityTransferFunction(itf) def startInterpolation(self, evt): """ A callback to interpolate intensity transfer functions between the specified timepoints """ self.dataUnit.interpolateIntensities() # self.doPreviewCallback() def updateSettings(self, force=0): """ A method used to set the GUI widgets to their proper values """ if self.dataUnit: self.iTFEditor.setIntensityTransferFunction( self.settings.getCounted("IntensityTransferFunctions", self.timePoint) ) tps = self.settings.get("InterpolationTimepoints") if not tps: tps = [] for i in range(len(tps)): n = tps[i] # If there was nothing in the entry at this position, the # value is -1 in that case, we leave the entry empty if n != -1: self.entries[i].SetValue(str(n)) ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: self.colorBtn.setColorTransferFunction(ctf) self.colorBtn.Refresh() def doProcessingCallback(self, *args): """ A callback for the button "Process Dataset Series" """ TaskPanel.doOperation(self) def setCombinedDataUnit(self, dataUnit): """ Sets the processed dataunit that is to be processed. It is then used to get the names of all the source data units and they are added to the menu. This is overwritten from TaskPanel since we only process one dataunit here, not multiple source data units """ TaskPanel.setCombinedDataUnit(self, dataUnit) ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: self.colorBtn.setColorTransferFunction(ctf) # We register a callback to be notified when the timepoint changes # We do it here because the timePointChanged() code requires the dataunit # self.Bind(EVT_TIMEPOINT_CHANGED,self.timePointChanged,id=ID_TIMEPOINT) tf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) self.iTFEditor.setIntensityTransferFunction(tf) self.iTFEditor.updateCallback = self.doPreviewCallback self.restoreFromCache() self.updateSettings()
def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = ColorTransferEditor.CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.intensityTransferEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.intensityTransferEditor, (0, 0), span = (1, 2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset") self.restoreBtn.Bind(wx.EVT_BUTTON, self.intensityTransferEditor.restoreDefaults) self.box.Add(self.restoreBtn) # The alpha function doesn't need to be edited # Code left if futher need shows ups #self.editAlphaPanel = wx.Panel(self.settingsNotebook,-1) self.editAlphaPanel = wx.Panel(self.editIntensityPanel, -1) self.editAlphaSizer = wx.GridBagSizer() self.alphaModeBox = wx.RadioBox(self.editAlphaPanel, -1, "Alpha channel construction", choices = ["Maximum Mode", "Average Mode", "Image Luminance", "No alpha"], \ majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.alphaModeBox.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.alphaModeBox.Bind(wx.EVT_RADIOBOX, self.modeSelect) self.averageLbl = wx.StaticText(self.editAlphaPanel, -1, "Average Threshold:") self.averageLbl.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit = wx.TextCtrl(self.editAlphaPanel, -1, "", size = (150, -1)) self.averageEdit.Enable(0) self.averageEdit.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit.Bind(wx.EVT_TEXT_ENTER, self.onAverageEdit) self.averageEdit.Bind(wx.EVT_KILL_FOCUS, self.onAverageEdit) box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.averageLbl) box.Add(self.averageEdit) self.editAlphaSizer.Add(self.alphaModeBox, (0, 0)) self.editAlphaSizer.Add(box, (2, 0)) self.editAlphaPanel.SetSizer(self.editAlphaSizer) self.editAlphaSizer.Fit(self.editAlphaPanel) self.editIntensitySizer.Add(self.editAlphaPanel, (4, 0)) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.editIntensityPanel.Layout() self.editIntensitySizer.Fit(self.editIntensityPanel) self.settingsNotebook.AddPage(self.editIntensityPanel, "Intensity")
class MergingPanel(TaskPanel.TaskPanel): """ Description: A window for controlling the settings of the color combination module """ def __init__(self, parent, tb): """ Initialization Parameters: parent Is the parent widget of this window """ self.alphaTF = vtkbxd.vtkIntensityTransferFunction() self.operationName = "Merge" self.createItemSelection = 1 TaskPanel.TaskPanel.__init__(self, parent, tb) self.oldBg = self.GetBackgroundColour() self.mainsizer.Layout() self.mainsizer.Fit(self) def createButtonBox(self): """ Creates a button box containing the buttons Render, Preview and Close """ TaskPanel.TaskPanel.createButtonBox(self) lib.messenger.connect(None, "process_dataset", self.doColorMergingCallback) def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = ColorTransferEditor.CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.intensityTransferEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.intensityTransferEditor, (0, 0), span = (1, 2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset") self.restoreBtn.Bind(wx.EVT_BUTTON, self.intensityTransferEditor.restoreDefaults) self.box.Add(self.restoreBtn) # The alpha function doesn't need to be edited # Code left if futher need shows ups #self.editAlphaPanel = wx.Panel(self.settingsNotebook,-1) self.editAlphaPanel = wx.Panel(self.editIntensityPanel, -1) self.editAlphaSizer = wx.GridBagSizer() self.alphaModeBox = wx.RadioBox(self.editAlphaPanel, -1, "Alpha channel construction", choices = ["Maximum Mode", "Average Mode", "Image Luminance", "No alpha"], \ majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.alphaModeBox.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.alphaModeBox.Bind(wx.EVT_RADIOBOX, self.modeSelect) self.averageLbl = wx.StaticText(self.editAlphaPanel, -1, "Average Threshold:") self.averageLbl.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit = wx.TextCtrl(self.editAlphaPanel, -1, "", size = (150, -1)) self.averageEdit.Enable(0) self.averageEdit.SetForegroundColour(scripting.COLOR_EXPERIENCED) self.averageEdit.Bind(wx.EVT_TEXT_ENTER, self.onAverageEdit) self.averageEdit.Bind(wx.EVT_KILL_FOCUS, self.onAverageEdit) box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.averageLbl) box.Add(self.averageEdit) self.editAlphaSizer.Add(self.alphaModeBox, (0, 0)) self.editAlphaSizer.Add(box, (2, 0)) self.editAlphaPanel.SetSizer(self.editAlphaSizer) self.editAlphaSizer.Fit(self.editAlphaPanel) self.editIntensitySizer.Add(self.editAlphaPanel, (4, 0)) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.editIntensityPanel.Layout() self.editIntensitySizer.Fit(self.editIntensityPanel) self.settingsNotebook.AddPage(self.editIntensityPanel, "Intensity") #self.settingsNotebook.AddPage(self.editAlphaPanel,"Alpha Channel") # self.optionssizer.Add(self.intensityTransferEditor,(3,0)) def modeSelect(self, event): """ A method that is called when the selection of alpha mode is chan ged """ mode = event.GetInt() try: value = int(self.averageEdit.GetValue()) except: value = 0 self.settings.set("AlphaMode", [mode, value]) if mode == 1: self.averageEdit.Enable(1) else: self.averageEdit.Enable(0) def onAverageEdit(self, evt): """ Method to update settings of current average value """ try: value = int(self.averageEdit.GetValue()) except: value = 0 mode = self.settings.get("AlphaMode") mode[1] = value self.settings.set("AlphaMode", mode) def resetTransferFunctions(self, event = None): """ A method to reset all the intensity transfer functions """ dataunits = self.dataUnit.getSourceDataUnits() for unit in dataunits: setting = unit.getSettings() minval, maxval = unit.getScalarRange() ctf = unit.getColorTransferFunction() ctfmin, ctfmax = ctf.GetRange() print "CTF range=",ctfmax bitmax = (2**unit.getSingleComponentBitDepth()-1) print "bitmax=",bitmax maxval = max(ctfmax, maxval,bitmax) itf = vtkbxd.vtkIntensityTransferFunction() itf.SetRangeMax(maxval) self.alphaTF.SetRangeMax(maxval) setting.set("IntensityTransferFunction", itf) def updateSettings(self, force = 0): """ A method used to set the GUI widgets to their proper values based on the selected channel, the settings of which are stored in the instance variable self.configSetting """ if self.dataUnit and self.settings: ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: Logging.info("Setting ctf of color button", kw = "ctf") self.colorBtn.setColorTransferFunction(ctf) self.colorBtn.Refresh() #Logging.info("settings=",self.settings,kw="task") tf = self.settings.get("IntensityTransferFunction") self.intensityTransferEditor.setIntensityTransferFunction(tf) try: mode = self.settings.get("AlphaMode") if types.StringType == type(mode): mode = eval(mode) self.alphaModeBox.SetSelection(mode[0]) if mode[0] == 1: self.averageEdit.Enable(1) else: self.averageEdit.Enable(0) self.averageEdit.SetValue(str(mode[1])) except: pass def doColorMergingCallback(self, *args): """ A callback for the processing button """ #print "\n\n\n\n\nDO COLOR MERGING" method = self.alphaModeBox.GetSelection() val = 0 if method == 1: val = int(self.averageEdit.GetValue()) lst = [method, val] Logging.info("Setting alpha mode to ", lst, kw = "task") #self.dataUnit.setAlphaMode(lst) self.settings.set("AlphaMode", lst) TaskPanel.TaskPanel.doOperation(self) def setCombinedDataUnit(self, dataUnit): """ Sets the combined dataunit that is to be processed. It is then used to get the names of all the source data units and they are added to the menu. """ TaskPanel.TaskPanel.setCombinedDataUnit(self, dataUnit) # We add entry "Alpha Channel" to the list of channels to allow # the user to edit the alpha channel for the 24-bit color merging #self.dataUnit.setOpacityTransfer(self.alphaTF) self.settings.set("AlphaTransferFunction", self.alphaTF) ctf = self.settings.get("ColorTransferFunction") sources = dataUnit.getSourceDataUnits() totmax = 0 for i in sources: minval, maxval = i.getScalarRange() ctf = i.getColorTransferFunction() ctfmin, ctfmax = ctf.GetRange() bitmax = 0 sBitDepth = i.getSingleComponentBitDepth() if sBitDepth == 8 or sBitDepth == 12: bitmax = (2**i.getSingleComponentBitDepth()-1) maxval = max(ctfmax, maxval, bitmax) if maxval > totmax: totmax = maxval self.alphaTF.SetRangeMax(int(totmax)) for i in range(len(sources)): tf = vtkbxd.vtkIntensityTransferFunction() tf.SetRangeMax(int(totmax)) #self.settings.setCounted("IntensityTransferFunction",i,tf,0) sources[i].getSettings().set("IntensityTransferFunction", tf) tf = sources[0].getSettings().get("IntensityTransferFunction") #print "\n\nSETTING ITF EDITOR FUNCTION" self.intensityTransferEditor.setIntensityTransferFunction(tf) for i in range(len(sources)): self.dataUnit.setOutputChannel(i, 1) if self.colorBtn: #Logging.info("Setting ctf of colorbutton to ",ctf,kw="ctf") self.colorBtn.setColorTransferFunction(ctf) else: Logging.info("No color button to set ctf to ", kw = "ctf") self.restoreFromCache()
class AdjustPanel(TaskPanel): """ Description: A window for processing a single dataunit """ def __init__(self, parent, tb): """ Initialization Parameters: root Is the parent widget of this window """ self.operationName = "Adjust" self.lbls = [] self.btns = [] self.entries = [] self.timePoint = 0 TaskPanel.__init__(self, parent, tb) # Preview has to be generated heregoto # self.colorChooser=None self.createIntensityTransferPage() lib.messenger.connect(None, "timepoint_changed", self.updateTimepoint) self.Show() self.mainsizer.Fit(self) self.mainsizer.Layout() def createIntensityInterpolationPanel(self): """ Creates a frame holding the entries for configuring interpolation """ self.interpolationPanel = wx.Panel(self.settingsNotebook) #self.interpolationPanel=wx.Panel(self.iTFEditor) self.interpolationSizer = wx.GridBagSizer() lbl = wx.StaticText(self.interpolationPanel, -1, "Interpolate intensities:") self.interpolationSizer.Add(lbl, (0, 0)) lbl = wx.StaticText(self.interpolationPanel, -1, "from timepoint") self.lbls.append(lbl) self.numOfPoints = 5 for i in range(self.numOfPoints - 2): lbl = wx.StaticText(self.interpolationPanel, -1, "thru") self.lbls.append(lbl) lbl = wx.StaticText(self.interpolationPanel, -1, "to timepoint") self.lbls.append(lbl) for i in range(self.numOfPoints): btn = wx.Button(self.interpolationPanel, -1, "goto") btn.Bind(wx.EVT_BUTTON, lambda event, x=i: self.gotoInterpolationTimePoint(x)) entry = wx.TextCtrl(self.interpolationPanel, size=(50, -1)) self.btns.append(btn) self.entries.append(entry) for entry in self.entries: entry.Bind(wx.EVT_TEXT, self.setInterpolationTimePoints) last = 0 for i in range(self.numOfPoints): lbl, entry, btn = self.lbls[i], self.entries[i], self.btns[i] self.interpolationSizer.Add(lbl, (i + 1, 0)) self.interpolationSizer.Add(entry, (i + 1, 1)) self.interpolationSizer.Add(btn, (i + 1, 2)) last = i + 1 #self.editIntensitySizer.Add(self.interpolationPanel,(0,1)) self.interpolationPanel.SetSizer(self.interpolationSizer) self.interpolationPanel.SetAutoLayout(1) self.interpolationSizer.SetSizeHints(self.interpolationPanel) self.settingsNotebook.AddPage(self.interpolationPanel, "Interpolation") self.interpolationBox = wx.BoxSizer(wx.HORIZONTAL) self.reset2Btn = wx.Button(self.interpolationPanel, -1, "Reset all timepoints") self.reset2Btn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.interpolationBox.Add(self.reset2Btn) self.interpolateBtn = wx.Button(self.interpolationPanel, -1, "Interpolate") self.interpolateBtn.Bind(wx.EVT_BUTTON, self.startInterpolation) self.interpolationBox.Add(self.interpolateBtn) self.interpolationSizer.Add(self.interpolationBox, (last + 1, 0)) #self.mainsizer.Add(self.interpolationPanel,(1,0)) #self.panel.Layout() #self.mainsizer.Fit(self.panel) def createIntensityTransferPage(self): """ Creates a frame holding the entries for configuring intensity """ self.editIntensityPanel = wx.Panel(self.settingsNotebook, -1) self.editIntensitySizer = wx.GridBagSizer() self.iTFEditor = IntensityTransferEditor(self.editIntensityPanel) self.editIntensitySizer.Add(self.iTFEditor, (0, 0)) #,span=(1,2)) self.box = wx.BoxSizer(wx.HORIZONTAL) self.editIntensitySizer.Add(self.box, (2, 0)) self.createIntensityInterpolationPanel() self.restoreBtn = wx.Button(self.editIntensityPanel, -1, "Reset current timepoint") self.restoreBtn.Bind(wx.EVT_BUTTON, self.iTFEditor.restoreDefaults) self.box.Add(self.restoreBtn) self.resetBtn = wx.Button(self.editIntensityPanel, -1, "Reset all timepoints") self.resetBtn.Bind(wx.EVT_BUTTON, self.resetTransferFunctions) self.box.Add(self.resetBtn) self.copyiTFBtn = wx.Button(self.editIntensityPanel, -1, "Copy to all timepoints") self.copyiTFBtn.Bind(wx.EVT_BUTTON, self.copyTransferFunctionToAll) self.box.Add(self.copyiTFBtn) self.editIntensityPanel.SetSizer(self.editIntensitySizer) self.editIntensityPanel.SetAutoLayout(1) self.settingsNotebook.InsertPage(0, self.editIntensityPanel, "Transfer Function") self.settingsNotebook.SetSelection(0) self.updateSettings() def setInterpolationTimePoints(self, event): """ A callback that is called when a timepoint entry for intensity interpolation changes. Updates the list of timepoints between which the interpolation is carried out by the dataunit """ lst = [] for i in self.entries: val = i.GetValue() try: n = int(val) #n -= 1 lst.append(n) except: # For entries that have no value, add -1 as a place holder lst.append(-1) #self.dataUnit.setInterpolationTimePoints(lst) self.settings.set("InterpolationTimepoints", lst) def gotoInterpolationTimePoint(self, entrynum): """ The previewed timepoint is set to timepoint specified in self.entries[entrynum] """ try: tp = int(self.entries[entrynum].GetValue()) except: pass else: tp -= 1 Logging.info("Previewing timepoint ", tp, "(will send change event)", kw="task") lib.messenger.send(None, "timepoint_changed", tp) #self.updateTimepoint(evt) def createButtonBox(self): """ Creates a button box containing the buttons Render, Preview and Close """ TaskPanel.createButtonBox(self) #self.processButton.SetLabel("Process Dataset Series") #self.processButton.Bind(wx.EVT_BUTTON,self.doProcessingCallback) lib.messenger.connect(None, "process_dataset", self.doProcessingCallback) def createOptionsFrame(self): """ Creates a frame that contains the various widgets used to control the colocalization settings """ TaskPanel.createOptionsFrame(self) self.paletteLbl = wx.StaticText(self, -1, "Channel palette:") self.commonSettingsSizer.Add(self.paletteLbl, (1, 0)) self.colorBtn = CTFButton(self) self.commonSettingsSizer.Add(self.colorBtn, (2, 0)) self.Layout() def updateTimepoint(self, obj, evt, timePoint): """ A callback function called when the timepoint is changed """ #timePoint=event.getValue() Logging.info("Now configuring timepoint", timePoint, kw="task") itf = self.settings.getCounted("IntensityTransferFunctions", timePoint) self.iTFEditor.setIntensityTransferFunction(itf) self.timePoint = timePoint def copyTransferFunctionToAll(self, event=None): """ A method to copy this transfer function to all timepooints """ itf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) l = self.dataUnit.getNumberOfTimepoints() for i in range(l): if i != self.timePoint: self.settings.setCounted("IntensityTransferFunctions", i, itf) def resetTransferFunctions(self, event=None): """ A method to reset all the intensity transfer functions """ l = self.dataUnit.getNumberOfTimepoints() sources = self.dataUnit.getSourceDataUnits() for i in range(l): minval = min([a.getScalarRange()[0] for a in sources]) maxval = max([a.getScalarRange()[1] for a in sources]) bitdepth = sources[0].getBitDepth() minval = min(0, minval) maxval = max(2**bitdepth - 1, maxval) itf = vtkbxd.vtkIntensityTransferFunction() itf.SetRangeMax(maxval) self.settings.setCounted("IntensityTransferFunctions", i, itf) itf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) self.iTFEditor.setIntensityTransferFunction(itf) def startInterpolation(self, evt): """ A callback to interpolate intensity transfer functions between the specified timepoints """ self.dataUnit.interpolateIntensities() # self.doPreviewCallback() def updateSettings(self, force=0): """ A method used to set the GUI widgets to their proper values """ if self.dataUnit: self.iTFEditor.setIntensityTransferFunction( self.settings.getCounted("IntensityTransferFunctions", self.timePoint)) tps = self.settings.get("InterpolationTimepoints") if not tps: tps = [] for i in range(len(tps)): n = tps[i] # If there was nothing in the entry at this position, the # value is -1 in that case, we leave the entry empty if n != -1: self.entries[i].SetValue(str(n)) ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: self.colorBtn.setColorTransferFunction(ctf) self.colorBtn.Refresh() def doProcessingCallback(self, *args): """ A callback for the button "Process Dataset Series" """ TaskPanel.doOperation(self) def setCombinedDataUnit(self, dataUnit): """ Sets the processed dataunit that is to be processed. It is then used to get the names of all the source data units and they are added to the menu. This is overwritten from TaskPanel since we only process one dataunit here, not multiple source data units """ TaskPanel.setCombinedDataUnit(self, dataUnit) ctf = self.settings.get("ColorTransferFunction") if ctf and self.colorBtn: self.colorBtn.setColorTransferFunction(ctf) # We register a callback to be notified when the timepoint changes # We do it here because the timePointChanged() code requires the dataunit #self.Bind(EVT_TIMEPOINT_CHANGED,self.timePointChanged,id=ID_TIMEPOINT) tf = self.settings.getCounted("IntensityTransferFunctions", self.timePoint) self.iTFEditor.setIntensityTransferFunction(tf) self.iTFEditor.updateCallback = self.doPreviewCallback self.restoreFromCache() self.updateSettings()