Ejemplo n.º 1
0
  def color_source(self):

    csname = self.color_source_menu.get()
    from SurfaceColor import coloring_methods
    csclass = [cm for cm in coloring_methods if cm.menu_name == csname][0]
    cs = csclass()

    cmap = self.colormap()
    if cmap:
      cs.set_colormap(cmap)

    if cs.uses_volume_data:
      cs.set_volume(self.volume_menu.volume())

    if cs.uses_origin:
      o = parse_vector(self.origin_variable.get(), default = (0,0,0))
      cs.set_origin(o)

    if cs.uses_axis:
      a = parse_vector(self.axis_variable.get(), default = (0,0,1))
      cs.set_axis(a)

    cs.per_pixel_coloring = self.per_pixel_color.get()

    from SurfaceColor import Electrostatic_Color
    if isinstance(cs, Electrostatic_Color):
      from CGLtk import Hybrid
      cs.offset = Hybrid.float_variable_value(self.surface_offset, 0)

    return cs
Ejemplo n.º 2
0
    def color_source(self):

        csname = self.color_source_menu.get()
        from SurfaceColor import coloring_methods
        csclass = [cm for cm in coloring_methods if cm.menu_name == csname][0]
        cs = csclass()

        cmap = self.colormap()
        if cmap:
            cs.set_colormap(cmap)

        if cs.uses_volume_data:
            cs.set_volume(self.volume_menu.volume())

        if cs.uses_origin:
            o = parse_vector(self.origin_variable.get(), default=(0, 0, 0))
            cs.set_origin(o)

        if cs.uses_axis:
            a = parse_vector(self.axis_variable.get(), default=(0, 0, 1))
            cs.set_axis(a)

        cs.per_pixel_coloring = self.per_pixel_color.get()

        from SurfaceColor import Electrostatic_Color
        if isinstance(cs, Electrostatic_Color):
            from CGLtk import Hybrid
            cs.offset = Hybrid.float_variable_value(self.surface_offset, 0)

        return cs
Ejemplo n.º 3
0
  def mesh_offset_changed_cb(self, event = None):

    p = self.mesh_surface_piece()
    if p:
      varray, tarray = p.geometry
      from CGLtk import Hybrid
      mesh_offset = Hybrid.float_variable_value(self.mesh_offset, 0)
      varray[:,2] = mesh_offset
      p.geometry = varray, tarray
Ejemplo n.º 4
0
    def mesh_offset_changed_cb(self, event=None):

        p = self.mesh_surface_piece()
        if p:
            varray, tarray = p.geometry
            from CGLtk import Hybrid
            mesh_offset = Hybrid.float_variable_value(self.mesh_offset, 0)
            varray[:, 2] = mesh_offset
            p.geometry = varray, tarray
Ejemplo n.º 5
0
    def settings_changed_cb(self, event=None):

        cap = self.show_caps.get()
        from surfcaps import capper
        c = capper()
        if cap:
            if self.use_cap_color.get():
                color = self.cap_color.rgba
            else:
                color = None
            c.set_cap_color(color)
            c.set_style(self.cap_style.get() == 'mesh')
            from CGLtk import Hybrid
            sf = Hybrid.float_variable_value(self.subdivision_factor, 1.0)
            c.set_subdivision_factor(sf)
            cap_offset = Hybrid.float_variable_value(self.cap_offset,
                                                     c.default_cap_offset)
            c.set_cap_offset(cap_offset)
            c.show_caps()
        else:
            c.unshow_caps()
Ejemplo n.º 6
0
  def settings_changed_cb(self, event = None):

    cap = self.show_caps.get()
    from surfcaps import capper
    c = capper()
    if cap:
      if self.use_cap_color.get():
        color = self.cap_color.rgba
      else:
        color = None
      c.set_cap_color(color)
      c.set_style(self.cap_style.get() == 'mesh')
      from CGLtk import Hybrid      
      sf = Hybrid.float_variable_value(self.subdivision_factor, 1.0)
      c.set_subdivision_factor(sf)
      cap_offset = Hybrid.float_variable_value(self.cap_offset,
                                               c.default_cap_offset)
      c.set_cap_offset(cap_offset)
      c.show_caps()
    else:
      c.unshow_caps()
Ejemplo n.º 7
0
  def flatten_cb(self, event = None):

    self.Unflatten()
    self.message('')
    import FlattenIcosahedron
    mlist = FlattenIcosahedron.multiscale_models()
    from CGLtk import Hybrid
    r = Hybrid.float_variable_value(self.radius)
    if r == None:
      r = FlattenIcosahedron.model_radius(mlist)
      if r != None:
        self.radius.set(r)
    elif r <= 0:
      self.message('Radius must be greater than 0.')
      return
    if r != None:
      FlattenIcosahedron.flatten_icosahedron(mlist, r)
      if self.show_mesh.get() and mlist:
        rgba = self.mesh_color.rgba
        zoffset = Hybrid.float_variable_value(self.mesh_offset, 0)
        self.show_triangle_mesh(mlist[0].surface_model(), r, rgba, zoffset)
Ejemplo n.º 8
0
    def flatten_cb(self, event=None):

        self.Unflatten()
        self.message('')
        import FlattenIcosahedron
        mlist = FlattenIcosahedron.multiscale_models()
        from CGLtk import Hybrid
        r = Hybrid.float_variable_value(self.radius)
        if r == None:
            r = FlattenIcosahedron.model_radius(mlist)
            if r != None:
                self.radius.set(r)
        elif r <= 0:
            self.message('Radius must be greater than 0.')
            return
        if r != None:
            FlattenIcosahedron.flatten_icosahedron(mlist, r)
            if self.show_mesh.get() and mlist:
                rgba = self.mesh_color.rgba
                zoffset = Hybrid.float_variable_value(self.mesh_offset, 0)
                self.show_triangle_mesh(mlist[0].surface_model(), r, rgba,
                                        zoffset)
Ejemplo n.º 9
0
  def colormap(self, message_cb):

    cmap = []
    for c in range(self.n):
      v = self.entry_fields[c].variable
      if v.get().strip() == '':
        continue                    # unused color
      from CGLtk import Hybrid
      dv = Hybrid.float_variable_value(v)
      if dv == None:
        message_cb('Data value "%s" is not a number' % v.get())
        continue
      cw = self.colorwells[c]
      cmap.append((dv, cw.rgba))
    cmap.sort()
    return cmap
Ejemplo n.º 10
0
    def colormap(self, message_cb):

        cmap = []
        for c in range(self.n):
            v = self.entry_fields[c].variable
            if v.get().strip() == '':
                continue  # unused color
            from CGLtk import Hybrid
            dv = Hybrid.float_variable_value(v)
            if dv == None:
                message_cb('Data value "%s" is not a number' % v.get())
                continue
            cw = self.colorwells[c]
            cmap.append((dv, cw.rgba))
        cmap.sort()
        return cmap
Ejemplo n.º 11
0
  def subdivision_levels(self, radius, update_subdivision_spacing = True):
    
    from CGLtk import Hybrid
    subdivision_factor = Hybrid.float_variable_value(self.subdivision_factor,
                                                     1)
    if subdivision_factor <= 0:
      subdivision_factor = 1
      
    from math import log, pow
    subdivision_levels = max(0, int(round(log(subdivision_factor)/log(2))))

    if update_subdivision_spacing:
      import Icosahedron
      edge = radius * Icosahedron.icosahedron_edge_length()
      subdivision_spacing = edge / pow(2.0, subdivision_levels)
      self.subdivision_spacing['text'] = ' spacing %.3g' % subdivision_spacing

    return subdivision_levels
Ejemplo n.º 12
0
    def subdivision_levels(self, radius, update_subdivision_spacing=True):

        from CGLtk import Hybrid
        subdivision_factor = Hybrid.float_variable_value(
            self.subdivision_factor, 1)
        if subdivision_factor <= 0:
            subdivision_factor = 1

        from math import log, pow
        subdivision_levels = max(0,
                                 int(round(log(subdivision_factor) / log(2))))

        if update_subdivision_spacing:
            import Icosahedron
            edge = radius * Icosahedron.icosahedron_edge_length()
            subdivision_spacing = edge / pow(2.0, subdivision_levels)
            self.subdivision_spacing[
                'text'] = ' spacing %.3g' % subdivision_spacing

        return subdivision_levels
Ejemplo n.º 13
0
  def state_from_dialog(self, icosahedron_dialog):

    d = icosahedron_dialog

    self.is_visible = d.isVisible()
    t = d.uiMaster().winfo_toplevel()
    self.geometry = t.wm_geometry()

    self.radius = d.radius.value(d.default_radius)
    self.sphere_factor = d.sphere_factor.value(0)
    self.orientation = d.orientation.get()
    from CGLtk import Hybrid
    self.subdivision_factor = Hybrid.float_variable_value(d.subdivision_factor,
                                                          1)
    self.style = d.surface_style.get()
    self.color = d.color.rgba

    if d.surface_model is None:
      self.surface_model = None
    else:
      from SessionUtil.stateclasses import Model_State
      self.surface_model = Model_State()
      self.surface_model.state_from_model(d.surface_model)
Ejemplo n.º 14
0
    def state_from_dialog(self, icosahedron_dialog):

        d = icosahedron_dialog

        self.is_visible = d.isVisible()
        t = d.uiMaster().winfo_toplevel()
        self.geometry = t.wm_geometry()

        self.radius = d.radius.value(d.default_radius)
        self.sphere_factor = d.sphere_factor.value(0)
        self.orientation = d.orientation.get()
        from CGLtk import Hybrid
        self.subdivision_factor = Hybrid.float_variable_value(
            d.subdivision_factor, 1)
        self.style = d.surface_style.get()
        self.color = d.color.rgba

        if d.surface_model is None:
            self.surface_model = None
        else:
            from SessionUtil.stateclasses import Model_State
            self.surface_model = Model_State()
            self.surface_model.state_from_model(d.surface_model)