<commit_before>from external.SwitchColourDialog import ColourDialog
from moduleBase import moduleBase
from moduleMixins import vtkPipelineConfigModuleMixin
import moduleUtils
from wxPython.wx import *
import vtk
import vtkdscas

class shellSplatSimpleFLT(moduleBase, vtkPipelineConfigModuleMixin):

    def __init__(self, moduleManager):
        # initialise our base class
        moduleBase.__init__(self, moduleManager)

        # setup the whole VTK pipeline that we're going to use
        self._createPipeline()

        # this is a list of all the objects in the pipeline and will
        # be used by the object and pipeline introspection
        self._objectDict = {'splatMapper' : self._splatMapper,
                            'opacity TF' : self._otf,
                            'colour TF' : self._ctf,
                            'volumeProp' : self._volumeProperty,
                            'volume' : self._volume}

        # setup some config defaults
        
        # for segmetented data
        self._config.threshold = 1.0
        # bony kind of colour
        self._config.colour = (1.0, 0.937, 0.859)
        # high quality, doh
        self._config.renderMode = 0

        # create the gui
        self._viewFrame = None
        self._createViewFrame()

        # pass the data down to the underlying logic
        self.configToLogic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()

        # some more UI elements that we'll need
        ccd = wxColourData()
        ccd.SetCustomColour(0,wxColour(255, 239, 219))
        # under windows, we want the complete thing
        ccd.SetChooseFull(True)
        # and create the bugger
        self._colourDialog = ColourDialog(self._viewFrame, ccd)


    def close(self):
        # we play it safe... (the graph_editor/module_manager should have
        # disconnected us by now)
        for inputIdx in range(len(self.getInputDescriptions())):
            self.setInput(inputIdx, None)

        # get rid of our reference
        del self._splatMapper
        del self._otf
        del self._ctf
        del self._volumeProperty
        del self._volume

        del self._objectDict

        if self._colourDialog:
            self._colourDialog.Destroy()
            
        del self._colourDialog

        # we have to call this mixin close so that all inspection windows
        # can be taken care of.  They should be taken care of in anycase
        # when the viewFrame is destroyed, but we like better safe than
        # sorry
        vtkPipelineConfigModuleMixin.close(self)

        # take care of our own window
        self._viewFrame.Destroy()
        del self._viewFrame

    def getInputDescriptions(self):
	return ('vtkVolume',)

    def setInput(self, idx, inputStream):
        self._splatMapper.SetInput(inputStream)

    def getOutputDescriptions(self):
        return (self._volume.GetClassName(),)

    def getOutput(self, idx):
        return self._volume

    def logicToConfig(self):
        # we CAN'T derive the threshold and colour from the opacity and colour
        # transfer functions (or we could, but it'd be terribly dirty)
        # but fortunately we don't really have to - logiToConfig is only really
        # for cases where the logic could return config information different
        # from that we programmed it with

        # this we can get
        self._config.renderMode = self._splatMapper.GetRenderMode()
        

    def configToLogic(self):

        # make a step in the opacity transfer function
        self._otf.RemoveAllPoints()
        self._otf.AddPoint(self._config.threshold - 0.1, 0.0)
        self._otf.AddPoint(self._config.threshold, 1.0)

        # make a step in the colour transfer function
        self._ctf.RemoveAllPoints()
        r,g,b = self._config.colour
        self._ctf.AddRGBPoint(self._config.threshold - 0.1, r, g, b)
        self._ctf.AddRGBPoint(self._config.threshold, r, g, b)

        # set the rendering mode
        self._splatMapper.SetRenderMode(self._config.renderMode)

    def viewToConfig(self):
        # get the threshold
        try:
            threshold = float(self._viewFrame.thresholdText.GetValue())
        except:
            # this means the user did something stupid, so we revert
            # to what's in the config - this will also turn up back
            # in the input box, as the DSCAS3 arch automatically syncs
            # view with logic after having applied changes
            threshold = self._config.threshold

        # store it in the config
        self._config.threshold = threshold
        <commit_msg>We don't need to recalculate the shell data structures if only the renderMode is changed.  Some convoluted caching required to achieve this.<commit_after>from external.SwitchColourDialog import ColourDialog
import operator
from moduleBase import moduleBase
from moduleMixins import vtkPipelineConfigModuleMixin
import moduleUtils
from wxPython.wx import *
import vtk
import vtkdscas

class shellSplatSimpleFLT(moduleBase, vtkPipelineConfigModuleMixin):

    def __init__(self, moduleManager):
        # initialise our base class
        moduleBase.__init__(self, moduleManager)

        # setup the whole VTK pipeline that we're going to use
        self._createPipeline()

        # this is a list of all the objects in the pipeline and will
        # be used by the object and pipeline introspection
        self._objectDict = {'splatMapper' : self._splatMapper,
                            'opacity TF' : self._otf,
                            'colour TF' : self._ctf,
                            'volumeProp' : self._volumeProperty,
                            'volume' : self._volume}


        # setup some config defaults
        # for segmetented data
        self._config.threshold = 1.0
        # bony kind of colour
        self._config.colour = (1.0, 0.937, 0.859)
        # high quality, doh
        self._config.renderMode = 0

        # create the gui
        self._viewFrame = None
        self._createViewFrame()

        # some more UI elements that we'll need
        ccd = wxColourData()
        ccd.SetCustomColour(0,wxColour(255, 239, 219))
        # under windows, we want the complete thing
        ccd.SetChooseFull(True)
        # and create the bugger
        self._colourDialog = ColourDialog(self._viewFrame, ccd)

        # pass the data down to the underlying logic
        self.configToLogic()
        # and all the way up from logic -> config -> view to make sure
        self.syncViewWithLogic()

        # display the module view
        self.view()

    def close(self):
        # we play it safe... (the graph_editor/module_manager should have
        # disconnected us by now)
        for inputIdx in range(len(self.getInputDescriptions())):
            self.setInput(inputIdx, None)

        # get rid of our reference
        del self._splatMapper
        del self._otf
        del self._ctf
        del self._volumeProperty
        del self._volume

        del self._objectDict

        if self._colourDialog:
            self._colourDialog.Destroy()
            
        del self._colourDialog

        # we have to call this mixin close so that all inspection windows
        # can be taken care of.  They should be taken care of in anycase
        # when the viewFrame is destroyed, but we like better safe than
        # sorry
        vtkPipelineConfigModuleMixin.close(self)

        # take care of our own window
        self._viewFrame.Destroy()
        del self._viewFrame

    def getInputDescriptions(self):
	return ('vtkVolume',)

    def setInput(self, idx, inputStream):
        self._splatMapper.SetInput(inputStream)

    def getOutputDescriptions(self):
        return (self._volume.GetClassName(),)

    def getOutput(self, idx):
        return self._volume

    def logicToConfig(self):
        # we CAN'T derive the threshold and colour from the opacity and colour
        # transfer functions (or we could, but it'd be terribly dirty)
        # but fortunately we don't really have to - logiToConfig is only really
        # for cases where the logic could return config information different
        # from that we programmed it with

        # this we can get
        self._config.renderMode = self._splatMapper.GetRenderMode()
        

    def configToLogic(self):

        # only modify the transfer functions if they've actually changed
        if self._otf.GetSize() != 2 or \
           self._otf.GetValue(self._config.threshold - 0.1) != 0.0 or \
           self._otf.GetValue(self._config.threshold) != 1.0:
            # make a step in the opacity transfer function
            self._otf.RemoveAllPoints()
            self._otf.AddPoint(self._config.threshold - 0.1, 0.0)
            self._otf.AddPoint(self._config.threshold, 1.0)

        # sample the two points and check that they haven't changed too much
        tfCol1 = self._ctf.GetColor(self._config.threshold)
        colDif1 = [i for i in
                  map(abs, map(operator.sub, self._config.colour, tfCol1))
                  if i > 0.001]

        tfCol2 = self._ctf.GetColor(self._config.threshold - 0.1)
        colDif2 = [i for i in
                  map(abs, map(operator.sub, (0,0,0), tfCol2))
                  if i > 0.001]
        
        if self._ctf.GetSize() != 2 or colDif1 or colDif2:
            # make a step in the colour transfer
            self._ctf.RemoveAllPoints()
            r,g,b = self._config.colour
            # setting two points is not necessary, but we play it safe
            self._ctf.AddRGBPoint(self._config.threshold - 0.1, 0, 0, 0)
            self._ctf.AddRGBPoint(self._config.threshold, r, g, b)

        # set the rendering mode
        self._splatMapper.SetRenderMode(self._config.renderMode)

    def viewToConfig(self):
        # get the threshold
        try:
            threshold = float(self._viewFrame.thresholdText.GetValue())
        except:
            # this means the user did something stupid, so we revert
            # to what's in the config - this will also turn up back
            # in the input box, as the DSCAS3 arch automatically syncs
            # view with logic after having applied changes
            threshold = self._config.threshold

        # store it in the config
        self._config.threshold = threshold
        
{'fraction_non_alphanumeric': 0.0704604441026627, 'fraction_numerical': 0.009228107276747092, 'mean_word_length': 2.105671641791045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '902217', 'n_tokens_mistral': 2892, 'n_tokens_neox': 2732, 'n_words': 937}