def __init__(self, parent, wid, name): wx.Frame.__init__(self, parent, wid, name, wx.DefaultPosition, wx.Size(1024, 768)) self.colony = CoralColony() self.interval = 10 self.growth_timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.growth_timer) self.growth_timer.Start(self.interval) self.show_skeleton = False self.ColonyView = ColonyViewControl(self) #self.ColonyView.SetMinSize((800,700)) self.PlayButton = wx.Button(self, wx.ID_ANY, 'Play') self.ResetButton = wx.Button(self, wx.ID_ANY, 'Reset') self.determinategrowth_checkbox = wx.CheckBox( self, ID_DETERMINATEGROWTH_CHECKBOX, "Determinate growth") self.Bind(wx.EVT_CHECKBOX, self.ToggleDeterminate, id=ID_DETERMINATEGROWTH_CHECKBOX) self.showskeleton_checkbox = wx.CheckBox(self, ID_SHOWSKELETON_CHECKBOX, "Show skeleton") self.Bind(wx.EVT_CHECKBOX, self.ToggleSkeleton, id=ID_SHOWSKELETON_CHECKBOX) self.timer_checkbox = wx.CheckBox(self, ID_TIMER_CHECKBOX, "Use Timer") self.Bind(wx.EVT_CHECKBOX, self.ToggleTimer, id=ID_TIMER_CHECKBOX) self.peripheralbudding_combobox = wx.ComboBox( self, ID_PERIPHERALBUDDING_COMBOBOX, "Peripheral budding", choices=["None", "Round", "Encrusting", "Platy"]) self.Bind(wx.EVT_COMBOBOX, self.PeripheralBudding, id=ID_PERIPHERALBUDDING_COMBOBOX) sizer1 = wx.BoxSizer(wx.HORIZONTAL) sizer1.Add(self.PlayButton, wx.ALIGN_CENTER) sizer1.Add(self.ResetButton, wx.ALIGN_CENTER) #sizer1.Add( self.ButtonExport, wx.ALIGN_CENTER ) self.forms = dict() self.irradiance_label = wx.StaticText(self, -1, 'Irradiance', style=wx.ALIGN_RIGHT) self.irradiance_value = wx.TextCtrl(self, -1, '') self.depth_label = wx.StaticText(self, -1, 'Depth', style=wx.ALIGN_RIGHT) self.forms['depth'] = wx.TextCtrl(self, -1, str(CoralConfig3D.DEPTH)) self.lateral_growth_period_label = wx.StaticText(self, -1, 'Lat. Growth Period', style=wx.ALIGN_RIGHT) self.forms['lateral_growth_period'] = wx.TextCtrl( self, -1, str(CoralConfig3D.LATERAL_GROWTH_PERIOD)) self.lateral_growth_criterion_label = wx.StaticText( self, -1, 'Lat. Growth Criterion', style=wx.ALIGN_RIGHT) self.forms['lateral_growth_criterion'] = wx.TextCtrl( self, -1, str(CoralConfig3D.LATERAL_GROWTH_CRITERION)) self.surface_irradiance_label = wx.StaticText(self, -1, 'Surface Irradiance', style=wx.ALIGN_RIGHT) self.forms['surface_irradiance'] = wx.TextCtrl( self, -1, str(CoralConfig3D.SURFACE_IRRADIANCE)) self.attenuation_coefficient_label = wx.StaticText( self, -1, 'Attenuation Coeff.', style=wx.ALIGN_RIGHT) self.forms['attenuation_coefficient'] = wx.TextCtrl( self, -1, str(CoralConfig3D.ATTENUATION_COEFFICIENT)) self.max_irradiance_label = wx.StaticText(self, -1, 'Max Irradiance', style=wx.ALIGN_RIGHT) self.forms['max_irradiance'] = wx.TextCtrl( self, -1, str(CoralConfig3D.MAX_IRRADIANCE)) self.reflection_rate_label = wx.StaticText(self, -1, 'Reflection Rate', style=wx.ALIGN_RIGHT) self.forms['reflection_rate'] = wx.TextCtrl( self, -1, str(CoralConfig3D.REFLECTION_RATE)) self.growth_constant_label = wx.StaticText(self, -1, 'Growth constant', style=wx.ALIGN_RIGHT) self.forms['growth_constant'] = wx.TextCtrl( self, -1, str(CoralConfig3D.GROWTH_CONSTANT)) self.polyp_radius_label = wx.StaticText(self, -1, 'Polyp radius', style=wx.ALIGN_RIGHT) self.forms['polyp_radius'] = wx.TextCtrl( self, -1, str(CoralConfig3D.POLYP_RADIUS)) self.zoom_label = wx.StaticText(self, -1, 'Zoom', style=wx.ALIGN_RIGHT) self.forms['zoom'] = wx.TextCtrl(self, -1, str(CoralConfig3D.ZOOM)) self.polyp_list_label = wx.StaticText(self, -1, 'Polyps', style=wx.ALIGN_RIGHT) self.polyp_listbox = wx.ListBox(self, -1, choices=(), size=(100, 200), style=wx.LB_SINGLE) sizer2 = wx.FlexGridSizer(3, 3, 0, 0) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.determinategrowth_checkbox, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.showskeleton_checkbox, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.timer_checkbox, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.peripheralbudding_combobox, flag=wx.EXPAND) sizer2.Add(self.depth_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['depth'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.lateral_growth_period_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['lateral_growth_period'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.lateral_growth_criterion_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['lateral_growth_criterion'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.surface_irradiance_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['surface_irradiance'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.attenuation_coefficient_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['attenuation_coefficient'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.max_irradiance_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['max_irradiance'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.reflection_rate_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['reflection_rate'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.growth_constant_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['growth_constant'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.polyp_radius_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['polyp_radius'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.zoom_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.forms['zoom'], flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.polyp_list_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.polyp_listbox, flag=wx.EXPAND | wx.ALIGN_CENTER) sizer2.Add(self.irradiance_label, flag=wx.EXPAND) sizer2.Add((10, 10), flag=wx.EXPAND) sizer2.Add(self.irradiance_value, flag=wx.EXPAND) fs = wx.FlexGridSizer(2, 2, 10, 5) fs.AddGrowableCol(0, 80) fs.AddGrowableCol(1, 20) fs.AddGrowableRow(0, 90) fs.Add(self.ColonyView, 0, wx.EXPAND) fs.Add(sizer2, 0, wx.ALIGN_CENTER) fs.Add(sizer1, 0, wx.EXPAND) self.Bind(wx.EVT_BUTTON, self.OnPlay, self.PlayButton) self.Bind(wx.EVT_BUTTON, self.OnReset, self.ResetButton) self.Bind(wx.EVT_LISTBOX, self.OnPolypSelected, self.polyp_listbox) self.SetSizer(fs) self.is_growing = False self.determinate_growth = False self.determinategrowth_checkbox.SetValue(self.determinate_growth) self.use_timer = True self.timer_checkbox.SetValue(self.use_timer) self.peripheral_budding = CoralConfig3D.ID_ROUND self.peripheralbudding_combobox.SetStringSelection("Round") self.ResetColony()
def ResetColony(self): #self.colony = CoralColony() depth = int(self.forms['depth'].GetValue()) self.colony = CoralColony(depth=depth) config = {} config['lateral_growth_criterion'] = float( self.forms['lateral_growth_criterion'].GetValue()) config['lateral_growth_period'] = int( self.forms['lateral_growth_period'].GetValue()) config['surface_irradiance'] = float( self.forms['surface_irradiance'].GetValue()) config['attenuation_coefficient'] = float( self.forms['attenuation_coefficient'].GetValue()) config['max_irradiance'] = float( self.forms['max_irradiance'].GetValue()) config['reflection_rate'] = float( self.forms['reflection_rate'].GetValue()) config['growth_constant'] = float( self.forms['growth_constant'].GetValue()) config['polyp_radius'] = float(self.forms['polyp_radius'].GetValue()) config['zoom'] = float(self.forms['zoom'].GetValue()) #config['peripheral_budding'] = self.peripheral_budding config['show_skeleton'] = self.show_skeleton config['determinate_growth'] = self.determinate_growth #print "show skeleton on reset", self.show_skeleton config[ 'peripheral_budding'] = self.peripheralbudding_combobox.GetCurrentSelection( ) #print "peripheral_budding on reset colony", config['peripheral_budding'] self.colony.config = config #pos_list = [ [ -9, 0, 0 ], [-5, 0, 3 ], [ 0, 0, 5 ], [5, 0, 3], [9, 0, 0 ] ] #vec_list = [ array( [ -1, 0, 0.01 ], float ), array( [ -1, 0, 1 ], float ), array( [ 0, 0, 1 ], float ) , array( [ 1, 0, 1 ], float ),array( [ 1, 0, 0.01 ], float ) ] #pos_list = [ [-5, 0, 3 ], [ 0, 0, 5 ], [5, 0, 3] ] #vec_list = [ array( [ -1, 0, 1 ], float ), array( [ 0, 0, 1 ], float ) , array( [ 1, 0, 1 ], float ) ] pos_list = [[-2, 0, 3], [2, 0, 3], [0, 2, 3], [0, -2, 3]] vec_list = [ array([-1, 0, 1], float), array([1, 0, 1], float), array([0, 1, 1], float), array([0, -1, 1], float) ] tri_list = [[0, 1, 2], [1, 0, 3]] for i in xrange(len(pos_list)): p = CoralPolyp(self.colony, pos=array(pos_list[i], float)) p.growth_vector = vec_list[i] / linalg.norm(vec_list[i]) self.colony.add_polyp(p) for i in xrange(len(tri_list)): t = CoralPolygon(self.colony, tri_list[i]) self.colony.add_polygon(t) """ x_pos = [ -9, -5, 0, 5, 9 ] y_pos = [ 0, 0, 0, 0, 0 ] z_pos = [ 0, 3, 5, 3, 0] grow_vector = [ array( [ -1, 0, 0.01 ], float ), array( [ -1, 0, 1 ], float ), array( [ 0, 0, 1 ], float ) , array( [ 1, 0, 1 ], float ),array( [ 1, 0, 0.01 ], float ) ] for i in xrange( 5 ): p = CoralPolyp( self.colony, pos = array( pos_list[i], float ) ) p.growth_vector = grow_vector[i] / linalg.norm( grow_vector[i] ) self.colony.add_polyp( p ) """ #colony.prev_polyp_count = 3 self.colony.init_colony_2d() #self.colony.apical_polyp_list.append( self.colony.head_polyp.next_polyp ) #self.colony.head_polyp.next_polyp.apical_polyp = True self.ColonyView.SetColony(self.colony) self.ColonyView.Reset() self.ColonyView.DrawToBuffer() self.LoadList() '''