예제 #1
0
파일: objects.py 프로젝트: beeka5/sverchok
 def draw_buttons(self, context, layout):
     row = layout.row()
     row.scale_y = 4.0
     opera = row.operator('node.sverchok_object_insertion', text='G E T')
     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)
     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--')
예제 #2
0
    def draw_buttons(self, context, layout):
        row = layout.row()
        row.scale_y = 4.0
        opera = row.operator('node.sverchok_object_insertion', text='G E T')
        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)
        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--')
예제 #3
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'}
예제 #4
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'}
예제 #5
0
파일: objects.py 프로젝트: beeka5/sverchok
 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('Go home, you tired, there is 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])
예제 #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])
예제 #7
0
파일: objects.py 프로젝트: beeka5/sverchok
    def update(self):
        # check for grouping socket
        if self.vergroups and not ('Vers_grouped' in self.outputs):
            self.outputs.new('StringsSocket', "Vers_grouped", "Vers_grouped")
        elif not self.vergroups and ('Vers_grouped' in self.outputs):
            self.outputs.remove(self.outputs['Vers_grouped'])
        
        name = self.name + self.id_data.name
        handle = handle_read(name)
        #print (handle)
        if self.objects_local:
            # bpy.ops.node.sverchok_object_insertion(node_name=self.name, tree_name=self.id_data.name, grup_name=self.groupname)
            # not updating. need to understand mechanic of update
            self.use_custom_color = True
            self.color = (0, 0.5, 0.2)
        else:
            self.use_custom_color = True
            self.color = (0, 0.1, 0.05)
        if self.objects_local and not handle[0]:
            handle_write(name, literal_eval(self.objects_local))
        elif 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:
                    #obj_data = obj.data
                    # post modifier geometry if ticked
                    scene = bpy.context.scene
                    settings = 'PREVIEW'
                    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))
                    for edg in obj_data.edges:
                        edgs.append([edg.vertices[0], edg.vertices[1]])
                    for p in obj_data.polygons:
                        pols.append(list(p.vertices))
                    bpy.data.meshes.remove(obj_data)
                    #print (vers, edgs, pols, mtrx)
                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 'Vertices' in self.outputs and self.outputs['Vertices'].links:
                    SvSetSocketAnyType(self, 'Vertices', vers_out)

                if 'Edges' in self.outputs and self.outputs['Edges'].links:
                    SvSetSocketAnyType(self, 'Edges', edgs_out)

                if 'Polygons' in self.outputs and self.outputs['Polygons'].links:
                    SvSetSocketAnyType(self, 'Polygons', pols_out)

                if 'Vers_grouped' in self.outputs and self.outputs['Vers_grouped'].links:
                    SvSetSocketAnyType(self, 'Vers_grouped', vers_out_grouped)

            if 'Matrixes' in self.outputs and self.outputs['Matrixes'].links:
                SvSetSocketAnyType(self, 'Matrixes', mtrx_out)
예제 #8
0
    def update(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)
예제 #9
0
 def update(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)
예제 #10
0
    def update(self):
        # check for grouping socket
        if self.vergroups and not ('Vers_grouped' in self.outputs):
            self.outputs.new('StringsSocket', "Vers_grouped", "Vers_grouped")
        elif not self.vergroups and ('Vers_grouped' in self.outputs):
            self.outputs.remove(self.outputs['Vers_grouped'])

        name = self.name + self.id_data.name
        handle = handle_read(name)
        #print (handle)
        if self.objects_local:
            # bpy.ops.node.sverchok_object_insertion(node_name=self.name, tree_name=self.id_data.name, grup_name=self.groupname)
            # not updating. need to understand mechanic of update
            self.use_custom_color = True
            self.color = (0, 0.5, 0.2)
        else:
            self.use_custom_color = True
            self.color = (0, 0.1, 0.05)
        #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:
                    #obj_data = obj.data
                    # post modifier geometry if ticked
                    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))
                    #for edg in obj_data.edges:
                    #    edgs.append([edg.vertices[0], edg.vertices[1]])
                    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)
                    #print (vers, edgs, pols, mtrx)
                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 'Vertices' in self.outputs and self.outputs[
                        'Vertices'].links:
                    SvSetSocketAnyType(self, 'Vertices', vers_out)

                if 'Edges' in self.outputs and self.outputs['Edges'].links:
                    SvSetSocketAnyType(self, 'Edges', edgs_out)

                if 'Polygons' in self.outputs and self.outputs[
                        'Polygons'].links:
                    SvSetSocketAnyType(self, 'Polygons', pols_out)

                if 'Vers_grouped' in self.outputs and self.outputs[
                        'Vers_grouped'].links:
                    SvSetSocketAnyType(self, 'Vers_grouped', vers_out_grouped)

            if 'Matrixes' in self.outputs and self.outputs['Matrixes'].links:
                SvSetSocketAnyType(self, 'Matrixes', mtrx_out)