Exemple #1
0
    def execute(self, context):
        if self.typ == 1:
            handle = handle_read(self.handle_name)
            prop = handle[1]
            Elman = SvNeuro_Elman()
            if handle[0]:
                prop['wA']=Elman.init_w(prop['InA'], prop['InB'], prop['trashold'])
                prop['wB']=Elman.init_w(prop['InB'], prop['InC'], prop['trashold'])
                handle_write(self.handle_name, prop)

        return {'FINISHED'}
Exemple #2
0
 def execute(self, context):
     if self.typ == 1:
         handle = handle_read(self.handle_name)
         prop = handle[1]
         Elman = SvNeuro_Elman()
         if handle[0]:
             prop['wA']=Elman.init_w(prop['InA'], prop['InB'], prop['trashold'])
             prop['wB']=Elman.init_w(prop['InB'], prop['InC'], prop['trashold'])
             handle_write(self.handle_name, prop)
             
     return {'FINISHED'}
    def draw_buttons(self, context, layout):
        #row.prop(self, 'groupname', text='')
        col = layout.column(align=True)
        row = col.row(align=True)
        row.prop_search(self,
                        'groupname',
                        bpy.data,
                        'groups',
                        text='',
                        icon='HAND')

        row = col.row()
        addon = context.user_preferences.addons.get(sverchok.__name__)
        if addon.preferences.over_sized_buttons:
            row.scale_y = 4.0
            op_text = "G E T"
        else:
            row.scale_y = 1
            op_text = "Get selection"

        opera = row.operator('node.sverchok_object_insertion', text=op_text)
        opera.node_name = self.name
        opera.tree_name = self.id_data.name
        opera.grup_name = self.groupname
        opera.sort = self.sort

        col = layout.column(align=True)
        row = col.row(align=True)
        row.prop(self, 'sort', text='Sort', toggle=True)
        row.prop(self, "modifiers", text="Post", toggle=True)
        # row = layout.row(align=True)
        row.prop(self, "vergroups", text="VeGr", toggle=True)

        row = col.row(align=True)
        opera = row.operator('node.sverchok_object_in_selector', text='Select')
        opera.node_name = self.name
        opera.tree_name = self.id_data.name

        handle = handle_read(self.name + self.id_data.name)
        if self.objects_local:
            if handle[0]:
                for i, o in enumerate(handle[1]):
                    if i > 4:
                        layout.label('. . . more ' + str(len(handle[1]) - 5) +
                                     ' items')
                        break
                    layout.label(o)
            else:
                handle_write(self.name + self.id_data.name,
                             literal_eval(self.objects_local))
        else:
            layout.label('--None--')
Exemple #4
0
    def draw_buttons(self, context, layout):
        #row.prop(self, 'groupname', text='')
        col = layout.column(align=True)
        row = col.row(align=True)
        row.prop_search(self, 'groupname', bpy.data, 'groups', text='', icon='HAND')

        row = col.row()
        addon = context.user_preferences.addons.get(sverchok.__name__)
        if addon.preferences.over_sized_buttons:
            row.scale_y = 4.0
            op_text = "G E T"
        else:
            row.scale_y = 1
            op_text = "Get selection"

        opera = row.operator('node.sverchok_object_insertion', text=op_text)
        opera.node_name = self.name
        opera.tree_name = self.id_data.name
        opera.grup_name = self.groupname
        opera.sort = self.sort

        col = layout.column(align=True)
        row = col.row(align=True)
        row.prop(self, 'sort', text='Sort', toggle=True)
        row.prop(self, "modifiers", text="Post", toggle=True)
        # row = layout.row(align=True)
        row.prop(self, "vergroups", text="VeGr", toggle=True)

        row = col.row(align=True)
        opera = row.operator('node.sverchok_object_in_selector', text='Select')
        opera.node_name = self.name
        opera.tree_name = self.id_data.name

        handle = handle_read(self.name + self.id_data.name)
        if self.objects_local:
            if handle[0]:
                for i, o in enumerate(handle[1]):
                    if i > 4:
                        layout.label('. . . more ' + str(len(handle[1]) - 5) + ' items')
                        break
                    layout.label(o)
            else:
                handle_write(self.name + self.id_data.name, literal_eval(self.objects_local))
        else:
            layout.label('--None--')
Exemple #5
0
    def enable(self, name_no, name_tr, handle, sorting):
        objects = []
        if self.grup_name and bpy.data.groups[self.grup_name].objects:
            objs = bpy.data.groups[self.grup_name].objects
        elif bpy.context.selected_objects:
            objs = bpy.context.selected_objects
        else:
            self.report({'WARNING'}, 'No object selected')
            return
        for o in objs:
            objects.append(o.name)
        if sorting:
            objects.sort()
        handle_write(name_no + name_tr, objects)

        if bpy.data.node_groups[name_tr]:
            handle = handle_read(name_no + name_tr)
            bpy.data.node_groups[name_tr].nodes[name_no].objects_local = str(handle[1])
Exemple #6
0
 def enable(self, name_no, name_tr, handle, sorting):
     objects = []
     if self.grup_name and bpy.data.groups[self.grup_name].objects:
         objs = bpy.data.groups[self.grup_name].objects
     elif bpy.context.selected_objects:
         objs = bpy.context.selected_objects
     else:
         self.report({'WARNING'},'No object selected')
         return
     for o in objs:
         objects.append(o.name)
     if sorting:
         objects.sort()
     handle_write(name_no+name_tr, objects)
     # временное решение с группой. надо решать, как достать имя группы узлов
     if bpy.data.node_groups[name_tr]:
         handle = handle_read(name_no+name_tr)
         #print ('exec',name)
         bpy.data.node_groups[name_tr].nodes[name_no].objects_local = str(handle[1])
Exemple #7
0
    def draw_buttons(self, context, layout):
        row = layout.row()
        addon = context.user_preferences.addons.get(sverchok.__name__)
        if addon.preferences.over_sized_buttons:
            row.scale_y = 4.0
            op_text = "G E T"
        else:
            row.scale_y = 1
            op_text = "Get selection"

        opera = row.operator("node.sverchok_object_insertion", text=op_text)
        opera.node_name = self.name
        opera.tree_name = self.id_data.name
        opera.grup_name = self.groupname
        opera.sort = self.sort

        row = layout.row(align=True)
        opera = row.operator("node.sverchok_object_in_selector", text="Select")
        opera.node_name = self.name
        opera.tree_name = self.id_data.name

        row = layout.row(align=True)
        row.prop(self, "groupname", text="")
        row.prop(self, "sort", text="Sort objects")

        row = layout.row(align=True)
        row.prop(self, "modifiers", text="Post modifiers")
        # row = layout.row(align=True)
        row.prop(self, "vergroups", text="Vert groups")

        handle = handle_read(self.name + self.id_data.name)
        if self.objects_local:
            if handle[0]:
                for i, o in enumerate(handle[1]):
                    if i > 4:
                        layout.label(". . . more " + str(len(handle[1]) - 5) + " items")
                        break
                    layout.label(o)
            else:
                handle_write(self.name + self.id_data.name, literal_eval(self.objects_local))
        else:
            layout.label("--None--")
Exemple #8
0
    def process(self):
        handle_name = self.name + self.id_data.name
        handle = handle_read(handle_name)
        props = handle[1]
        if not handle[0]:
            elman = SvNeuroElman()
            props = {
                'InA': 2,
                'InB': 5,
                'InC': 1,
                'wA': [],
                'wB': [],
                'gister': 0.01,
                'k_learning': 0.1,
                'epsilon': 1.3,
                'cycles': 3,
                'trashold': 0.01,
                'k_lambda': 0.0001,
                'Elman': elman,
            }

        self.elman = props['Elman']
        result = []
        if self.outputs['result'].is_linked and self.inputs['data'].is_linked:

            if self.inputs['etalon'].is_linked:
                input_etalon = self.inputs['etalon'].sv_get()
                is_learning = True
            else:
                input_etalon = [[0]]
                is_learning = False

            if (props['InA'] != self.lA +
                    1) or props['InB'] != self.lB or props['InC'] != self.lC:
                props['InA'] = self.lA + 1
                props['InB'] = self.lB
                props['InC'] = self.lC
                props['wA'] = self.elman.init_w(props['InA'], props['InB'],
                                                props['trashold'])
                props['wB'] = self.elman.init_w(props['InB'], props['InC'],
                                                props['trashold'])

            props['gister'] = self.gisterezis
            props['k_learning'] = self.k_learning
            props['epsilon'] = self.epsilon
            props['k_lambda'] = self.k_lambda
            props['cycles'] = self.cycles
            props['trashold'] = self.treshold

            input_data = self.inputs['data'].sv_get()

            if type(input_etalon[0]) not in [list, tuple]:
                input_etalon = [input_etalon]
            if type(input_data[0]) not in [list, tuple]:
                input_data = [input_data]

            for idx, data in enumerate(input_data):
                let = len(input_etalon) - 1
                eta = input_etalon[min(idx, let)]
                data2 = [1.0] + data
                if type(eta) not in [list, tuple]:
                    eta = [eta]

                result.append(
                    self.elman.neuro(data2, eta, self.maximum, is_learning,
                                     props))
        else:
            result = [[]]

        handle_write(handle_name, props)
        self.outputs['result'].sv_set(result)
Exemple #9
0
    def process(self):
        name = self.name + self.id_data.name
        handle = handle_read(name)
        #reload handle if possible
        if self.objects_local and not handle[0]:
            handle_write(name, literal_eval(self.objects_local))
            handle = handle_read(name)    
            
        if handle[0]:
            objs = handle[1]
            edgs_out = []
            vers_out = []
            vers_out_grouped = []
            pols_out = []
            mtrx_out = []
            for obj_ in objs:  # names of objects
                edgs = []
                vers = []
                vers_grouped = []
                pols = []
                mtrx = []
                obj = bpy.data.objects[obj_]  # objects itself
                if obj.type == 'EMPTY':
                    for m in obj.matrix_world:
                        mtrx.append(m[:])

                else:
                    scene = bpy.context.scene
                    settings = 'PREVIEW'
                    # create a temporary mesh
                    obj_data = obj.to_mesh(scene, self.modifiers, settings)

                    for m in obj.matrix_world:
                        mtrx.append(list(m))
                    for k, v in enumerate(obj_data.vertices):
                        if self.vergroups and v.groups.values():
                            vers_grouped.append(k)
                        vers.append(list(v.co))
                    edgs = obj_data.edge_keys
                    for p in obj_data.polygons:
                        pols.append(list(p.vertices))
                    # remove the temp mesh
                    bpy.data.meshes.remove(obj_data)

                edgs_out.append(edgs)
                vers_out.append(vers)
                vers_out_grouped.append(vers_grouped)
                pols_out.append(pols)
                mtrx_out.append(mtrx)
            if vers_out[0]:

                if self.outputs['Vertices'].is_linked:
                    SvSetSocketAnyType(self, 'Vertices', vers_out)

                if self.outputs['Edges'].is_linked:
                    SvSetSocketAnyType(self, 'Edges', edgs_out)

                if self.outputs['Polygons'].is_linked:
                    SvSetSocketAnyType(self, 'Polygons', pols_out)

                if self.vergroups and self.outputs['Vers_grouped'].is_linked:
                    SvSetSocketAnyType(self, 'Vers_grouped', vers_out_grouped)

            if self.outputs['Matrixes'].is_linked:
                SvSetSocketAnyType(self, 'Matrixes', mtrx_out)
Exemple #10
0
 def copy(self, node):
     if self.objects_local:
         name = self.name + self.id_data.name
         handle_write(name, literal_eval(self.objects_local))
Exemple #11
0
    def process(self):
        handle_name = self.name + self.id_data.name
        handle = handle_read(handle_name)
        props = handle[1]
        if not handle[0]:
            props = {'InA':2,
                     'InB':5,
                     'InC':1,
                     'wA':[],
                     'wB':[],
                     'gister':0.01,
                     'k_learning':0.1,
                     'epsilon':1.3,
                     'cycles':3,
                     'trashold':0.01,
                     'k_lambda':0.0001}

            props['wA'] = self.Elman.init_w(props['InA'], props['InB'], props['trashold'])
            props['wB'] = self.Elman.init_w(props['InB'], props['InC'], props['trashold'])


        self.Elman.gister = abs(self.gisterezis)
        self.Elman.k_learning = self.k_learning

        result = []
        if self.outputs['result'].is_linked and self.inputs['data'].is_linked:

            if self.inputs['etalon'].is_linked:
                etalon = self.inputs['etalon'].sv_get()[0]
                flag = True
            else:
                flag = False
                etalon = [[0]]

            if (props['InA']!=self.lA+1) or props['InB']!=self.lB or props['InC']!=self.lC:
                props['InA'] = self.lA+1
                props['InB'] = self.lB
                props['InC'] = self.lC
                props['wA'] = self.Elman.init_w(props['InA'], props['InB'])
                props['wB'] = self.Elman.init_w(props['InB'], props['InC'])

            props['gister'] = self.gisterezis
            props['k_learning'] = self.k_learning
            props['epsilon'] = self.epsilon
            props['k_lambda'] = self.k_lambda
            props['cycles'] = self.cycles
            props['trashold'] = self.treshold

            data_ = self.inputs['data'].sv_get()[0]
            if type(etalon[0]) not in [list, tuple]: etalon = [etalon]
            if type(data_[0]) not in [list, tuple]: data_ = [data_]
            for idx, data in enumerate(data_):
                let = len(etalon)-1
                eta = etalon[min(idx,let)]
                data2 = [1.0]+data
                if type(eta) not in [list, tuple]: eta = [eta]
                result.append([self.Elman.neuro(data2, eta, self.maximum, flag, props)])

        else:
            result = [[[]]]

        handle_write(handle_name, props)
        self.outputs['result'].sv_set(result)
Exemple #12
0
 def process(self):
     handle_name = self.name + self.id_data.name
     handle = handle_read(handle_name)
     props = handle[1]
     if not handle[0]:
         props = {'InA':2,
                  'InB':5,
                  'InC':1,
                  'wA':[],
                  'wB':[],
                  'gister':0.01,
                  'k_learning':0.1,
                  'epsilon':1.3,
                  'cycles':3,
                  'trashold':0.01,
                  'k_lambda':0.0001}
                  
         props['wA'] = self.Elman.init_w(props['InA'], props['InB'], props['trashold'])
         props['wB'] = self.Elman.init_w(props['InB'], props['InC'], props['trashold'])
         
         
     self.Elman.gister = abs(self.gisterezis)
     self.Elman.k_learning = self.k_learning
     
     result = []
     if 'result' in self.outputs and len(self.outputs['result'].links) > 0 \
             and 'data' in self.inputs and len(self.inputs['data'].links) > 0:
         
         if 'etalon' in self.inputs and len(self.inputs['etalon'].links) > 0:
             etalon = SvGetSocketAnyType(self, self.inputs['etalon'])[0]
             flag = True
         else:
             flag = False
             etalon = [[0]]
         
         if (props['InA']!=self.lA+1) or props['InB']!=self.lB or \
             props['InC']!=self.lC:
             props['InA'] = self.lA+1
             props['InB'] = self.lB
             props['InC'] = self.lC
             props['wA'] = self.Elman.init_w(props['InA'], props['InB'])
             props['wB'] = self.Elman.init_w(props['InB'], props['InC'])
             
         props['gister'] = self.gisterezis
         props['k_learning'] = self.k_learning
         props['epsilon'] = self.epsilon
         props['k_lambda'] = self.k_lambda
         props['cycles'] = self.cycles
         props['trashold'] = self.treshold
         
         data_ = SvGetSocketAnyType(self, self.inputs['data'])[0]
         if type(etalon[0]) not in [list, tuple]: etalon = [etalon]
         if type(data_[0]) not in [list, tuple]: data_ = [data_]
         for idx, data in enumerate(data_):
             let = len(etalon)-1
             eta = etalon[min(idx,let)]
             data2 = [1.0]+data
             if type(eta) not in [list, tuple]: eta = [eta]
             result.append([self.Elman.neuro(data2, eta, self.maximum, flag, props)])
     
     else:
         result = [[[]]]
     
     handle_write(handle_name, props)
     SvSetSocketAnyType(self, 'result', result)