Example #1
0
def safe_filename_from_image(image):
    # is it actually possible for image.name to be empty?
    # Blender seams to always enumerate "undefined" if no name is specified
    # defaults to file name which is what we would use anyway
    image_name = image.name if image.name != "" else display_name_from_filepath(image.filepath)
    # a name in blender is allowed to contain any utf8 character
    # filesystems are not that permissive
    # to be as compatible as possible we replace the most common invalid characters with an underscore
    # there are many other invalid names like reserved DOS names but handling all edge cases is not feasible
    image_name = re.sub(r"\\|\*|\.|\"|\/|\[|\]|:|;|#|\||=|,|<|>", "_", image_name)
    return image_name
Example #2
0
def readSimulationData(simulationFile):
    # Open timing file (output.csv)
    neuronTimingPath = abspath(simulationFile)
    fileName = display_name_from_filepath(simulationFile)
    timingZip = import_model_from_zip(neuronTimingPath)

    # read the data into the TIMINGS variable
    global TIMINGS
    TIMINGS = []
    timing_data = timingZip['spikes']

    for row in timing_data:
        if len(row) == 3:

            # if start time point is not reached, simply continue
            if (float(row[2]) <
                    bpy.context.scene.pam_anim_animation.startTime):
                continue

            # only load data up to the prespecified time point
            if (float(row[2]) < bpy.context.scene.pam_anim_animation.endTime):
                TIMINGS.append((int(row[0]), int(row[1]), float(row[2])))

    # Sort by fire time
    TIMINGS.sort(key=lambda x: x[2])

    global DELAYS
    DELAYS = []
    for i in range(0, len(model.MODEL.connections)):
        try:
            DELAYS.append(timingZip["delay_" + str(i)])
        except:
            print('cannot find file: ' + 'delay_' + str(i) + '.csv')

    DELAYS = numpy.array(DELAYS)
    global noAvailableConnections
    noAvailableConnections = len(DELAYS[0][0])
def readSimulationData(simulationFile):
    # Open timing file (output.csv)
    neuronTimingPath = abspath(simulationFile)
    fileName = display_name_from_filepath(simulationFile)
    timingZip = import_model_from_zip(neuronTimingPath)
    
    # read the data into the TIMINGS variable
    global TIMINGS
    TIMINGS = []
    timing_data = timingZip['spikes']

    for row in timing_data:
        if len(row) == 3:
            
            # if start time point is not reached, simply continue
            if (float(row[2]) < bpy.context.scene.pam_anim_animation.startTime):
                continue
            
            # only load data up to the prespecified time point
            if (float(row[2]) < bpy.context.scene.pam_anim_animation.endTime):
                TIMINGS.append((int(row[0]), int(row[1]), float(row[2])))

    # Sort by fire time
    TIMINGS.sort(key = lambda x: x[2])

    global DELAYS
    DELAYS = []
    for i in range(0, len(model.MODEL.connections)):
        try:
            DELAYS.append(timingZip["delay_" + str(i)])
        except:
            print('cannot find file: ' + 'delay_' + str(i) + '.csv')
    
    DELAYS = numpy.array(DELAYS)
    global noAvailableConnections
    noAvailableConnections = len(DELAYS[0][0])
Example #4
0
class RENDER_PT_SetupTiles(bpy.types.Panel):
    bl_label = "Monster Tile Renderer"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = 'render'

    bts = bpy.types.Scene

    bts.MyFilePath = StringProperty(name='path to file', subtype='DIR_PATH')

    # looks at current blend and uses it as a basename, the way i like it.
    # [TODO] update with new file name, without restart blender.
    # bpy.context.scene.update()
    mfilepath = bpy.data.filepath
    this_blend = path.display_name_from_filepath(mfilepath)

    bts.MyFileName = StringProperty(
        name='file name',
        description='file name will be suffixed by cell name',
        default=this_blend)

    bts.MyDPIsetting = IntProperty(
        name='DPI',
        description='set some reasonable value here, 150/300/600/1200',
        min=10,
        max=1200,
        default=300)

    # arbitrary value 10meters, if you need something that big contact me.
    # i'd love to see it :)
    bts.MyDimW = FloatProperty(description="real width in cm/inch",
                               min=5.0,
                               max=1000.0,
                               default=100.0)
    bts.MyDimH = FloatProperty(description="real height in cm/inch",
                               min=5.0,
                               max=1000.0,
                               default=100.0)

    bts.MyPXwide = IntProperty(description="px width",
                               min=1000,
                               max=327670,
                               default=1920)
    bts.MyPXhigh = IntProperty(description="px height",
                               min=1000,
                               max=327670,
                               default=1080)

    bts.MyMaxTileWidth = IntProperty(description="max px width",
                                     min=500,
                                     max=10000,
                                     default=1000)
    bts.MyMaxTileHeight = IntProperty(description="max px height",
                                      min=500,
                                      max=10000,
                                      default=1000)

    bts.MyTilesWidth = IntProperty()
    bts.MyTilesHeight = IntProperty()
    bts.MyEnlargePercentage = IntProperty()
    bts.MyShowSwitch = BoolProperty(default=False)

    bts.MyTileSelection = BoolProperty(name="Render subset of tiles",
                                       default=False)

    bts.MySubset = StringProperty(name="Subset", description=description_full)

    bts.MyRenderResX = IntProperty()
    bts.MyRenderResY = IntProperty()

    # using the panel to display currently calculated settings
    bts.MyOutput1 = StringProperty(default=DEFAULTLINE)
    bts.MyOutput2 = StringProperty(default=DEFAULTLINE)
    bts.MyOutput3 = StringProperty(default=DEFAULTLINE)

    def draw(self, context):

        layout = self.layout
        scn = context.scene
        unit = scn.unit_settings

        row1 = layout.row(align=True)
        row2 = layout.row(align=True)
        row3 = layout.row(align=True)
        row4 = layout.row(align=True)
        row5 = layout.row(align=True)
        row6 = layout.row(align=True)

        row1.prop(scn, "MyFilePath")
        row2.prop(scn, "MyFileName")

        # side by side
        row3.label("file type")
        # row3.prop(scn.render, "file_format", text="")
        row3.prop(scn.render.image_settings, "file_format",
                  text="")  #update for 2.6

        if unit.system in ('METRIC', 'IMPERIAL'):
            row3.prop(scn, "MyDPIsetting")

        row4.prop(unit, "system", expand=True)

        # discriminate
        if unit.system in ('METRIC', 'IMPERIAL'):
            unittype = "cm"
            if unit.system == 'IMPERIAL':
                unittype = "Inch"

            row5.label("W * H in " + unittype)
            row5.prop(scn, "MyDimW")
            row5.prop(scn, "MyDimH")
        else:
            row5.label("Pixels X * Y")
            row5.prop(scn, "MyPXwide")
            row5.prop(scn, "MyPXhigh")

        # choices
        row6.label("tile size limits")
        row6.prop(scn, "MyMaxTileWidth")
        row6.prop(scn, "MyMaxTileHeight")

        row7 = layout.row(align=True)
        row7.operator("object.calculate")

        if scn.MyShowSwitch != False:
            row8 = layout.row(align=True)
            row8.label(scn.MyOutput1)
            row9 = layout.row(align=True)
            row9.label(scn.MyOutput2)
            row10 = layout.row(align=True)
            row10.label(scn.MyOutput3)
            row11 = layout.row(align=True)
            row11.operator("object.setvalues")

        row12 = layout.row(align=True)
        row12.prop(scn, "MyTileSelection")

        row13 = layout.row(align=True)
        row13.prop(scn, "MySubset")

        if scn.MyTileSelection == True:
            row13.active = True
            row13.enabled = True

            temp_subset_list = list(set(scn.MySubset.split(", ")))
            if temp_subset_list != ['']:
                num_subset = len(temp_subset_list)

        else:
            row13.active = False
            row13.enabled = False
            num_subset = 0

        # a few lines to indicate the number of subset tiles.
        row14 = layout.row(align=True)
        num_tiles = str(scn.MyTilesWidth * scn.MyTilesHeight)
        button_title = "render job! " + num_tiles + " Tiles"
        if scn.MyTileSelection == True:
            subset_str = " subset: " + str(num_subset)
            button_title += subset_str
        row14.operator("object.starttilejob",
                       text=button_title,
                       icon="MESH_GRID")
    def execute(self, context):

        print('execute miura')

        scene = context.scene
        sequence_editor = scene.sequence_editor

        active_strip = sequence_editor.active_strip
        target_path = abspath(active_strip.directory)
        processed_dir = join(target_path, clean_name(active_strip.name))
        window_manager = context.window_manager


        makedirs(processed_dir, exist_ok=True)

        elements = active_strip.elements
        frame_offset_start = active_strip.frame_offset_start
        frame_final_start = active_strip.frame_final_start
        frame_final_duration = active_strip.frame_final_duration

        elements_to_process = elements[
            frame_offset_start:frame_final_duration + frame_offset_start]

        window_manager.progress_begin(0, len(elements_to_process))

        module_name = self.module_name

        if module_name in loaded_modules and self.reload_if_loaded:
            module = importlib.reload(loaded_modules.get(module_name))
        else:
            module = importlib.import_module(module_name)

        loaded_modules[module_name] = module

        use_multiview = active_strip.use_multiview

        if use_multiview:
            print('stereo strip\n', active_strip, dir(active_strip))
            print(active_strip)
            print('—' * 10)
            print(dir(active_strip))
            print(active_strip.views_format)
            print(active_strip.stereo_3d_format)
            print(active_strip.stereo_3d_format.display_mode)
            print('^' * 10)

            assert active_strip.views_format == 'STEREO_3D', 'Only STEREO_3D views formatsupported'
            assert active_strip.stereo_3d_format.display_mode == 'TOPBOTTOM', 'Only TOPBOTTOM display mode supported'

        for i, element in enumerate(elements_to_process):

            window_manager.progress_update(i)

            image_path = join(target_path, element.filename)

            print('image_path', image_path)

            orig = imageio.imread(image_path)
            original_file_name = display_name_from_filepath(element.filename)
            process_name = 'hcy_' + original_file_name 

            print('--- cer cebprff', orig, orig.shape)

            processed = module.process_frame(
                orig, frame_final_start + i, process_name, 
                is_topbottom=use_multiview)

            print('--- cbfg cebprff')

            new_file_name = process_name + '.png'
            process_full_path = path.join(processed_dir, new_file_name)

            print('path to save', process_full_path)

            imageio.imsave(process_full_path, processed)

            print('saved image', process_full_path)

            if i == 0:
                new_sequence_name = active_strip.name + '_processed.000'
                print('Creating new image sequence "{}"', new_sequence_name)
                new_sequence = sequence_editor.sequences.new_image(
                    name=new_sequence_name,
                    filepath=relpath(process_full_path),
                    frame_start=frame_final_start,
                    channel=active_strip.channel + 1)
            else:
                new_sequence.elements.append(new_file_name)

        if use_multiview:
            new_sequence.use_multiview = use_multiview
            new_sequence.views_format = 'STEREO_3D'
            new_sequence.stereo_3d_format.display_mode = 'TOPBOTTOM'

        new_sequence.blend_type = 'ALPHA_OVER'

        window_manager.progress_end()
        print('Done!')

        return {'FINISHED'}
    def execute(self, context):
        scene = context.scene
        sequence_editor = scene.sequence_editor

        curve_by_key = find_custom_curves(scene)

        active_strip = sequence_editor.active_strip
        target_path = abspath(active_strip.directory)

        effective_strip_name = self.new_strip_name or active_strip.name
        processed_dir = join(target_path, clean_name(effective_strip_name))
        makedirs(processed_dir, exist_ok=True)

        elements = active_strip.elements
        frame_offset_start = active_strip.frame_offset_start
        frame_final_start = active_strip.frame_final_start
        frame_final_duration = active_strip.frame_final_duration

        window_manager = context.window_manager

        elements_to_process = elements[
            frame_offset_start:frame_final_duration + frame_offset_start]

        window_manager.progress_begin(0, len(elements_to_process))

        use_multiview = active_strip.use_multiview

        if use_multiview:
            assert active_strip.views_format == 'STEREO_3D', 'Only STEREO_3D views formatsupported'
            assert active_strip.stereo_3d_format.display_mode == 'TOPBOTTOM', 'Only TOPBOTTOM display mode supported'

        for i, element in enumerate(elements_to_process):

            window_manager.progress_update(i)
            image_path = join(target_path, element.filename)
            original_file_name = display_name_from_filepath(element.filename)
            frame_number = frame_final_start + i

            payload = {
                'original_file_name': original_file_name,
                'image_path': image_path,
                'processed_dir': processed_dir,
                'use_multiview': use_multiview,
                'frame_number': frame_number
            }

            payload.update(extract_curve_for_frame(curve_by_key, frame_number))

            r = post(f'http://0.0.0.0:{self.server_port}/process',
                     json=payload)
            process_full_path = r.text
            assert isfile(process_full_path), 'Image not created!'

            if i == 0:
                new_sequence_name = effective_strip_name + '.000'
                new_sequence = sequence_editor.sequences.new_image(
                    name=new_sequence_name,
                    filepath=relpath(process_full_path),
                    frame_start=frame_final_start,
                    channel=active_strip.channel + 1)
            else:
                new_sequence.elements.append(basename(process_full_path))

        if use_multiview:
            new_sequence.use_multiview = use_multiview
            new_sequence.views_format = 'STEREO_3D'
            new_sequence.stereo_3d_format.display_mode = 'TOPBOTTOM'

        new_sequence.blend_type = 'ALPHA_OVER'
        if self.copy_transform_and_crop:

            new_sequence.crop.max_x = active_strip.crop.max_x
            new_sequence.crop.max_y = active_strip.crop.max_y
            new_sequence.crop.min_x = active_strip.crop.min_x
            new_sequence.crop.min_y = active_strip.crop.min_y

            new_sequence.transform.offset_x = active_strip.transform.offset_x
            new_sequence.transform.offset_y = active_strip.transform.offset_y
            new_sequence.transform.scale_x = active_strip.transform.scale_x
            new_sequence.transform.scale_y = active_strip.transform.scale_y
            new_sequence.transform.rotation = active_strip.transform.rotation
            new_sequence.transform.origin = active_strip.transform.origin

        window_manager.progress_end()
        return {'FINISHED'}