-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/recv2- Recording functionality #342
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee8c1e2
Updated create_new_vispy_canvas to add video recording functionality …
AdityaPandeyCN 80e739c
Updated plot_3D_cell_morphology to Create a MeshVisual for rendering …
AdityaPandeyCN 03a74d6
removed the type error
AdityaPandeyCN 7a65a5f
modified the code
AdityaPandeyCN fabb797
removed duplication
AdityaPandeyCN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ | |
import math | ||
import random | ||
import typing | ||
|
||
import imageio | ||
import glob | ||
from vispy.gloo import util | ||
import numpy | ||
import progressbar | ||
from neuroml import Cell, NeuroMLDocument, SegmentGroup, Segment | ||
|
@@ -47,6 +49,10 @@ | |
|
||
MAX_MESH_PRECISION = 3 | ||
|
||
# Global variables for video recording | ||
recording = False | ||
frames = [] | ||
|
||
|
||
def add_text_to_vispy_3D_plot( | ||
current_canvas: scene.SceneCanvas, | ||
|
@@ -210,10 +216,20 @@ def vispy_rotate(self): | |
|
||
rotation_timer = app.Timer(connect=vispy_rotate) | ||
|
||
@canvas.events.key_press.connect | ||
def vispy_on_key_press(event): | ||
recording = [False] | ||
frames = [] | ||
|
||
def vispy_on_key_press(event, canvas): | ||
nonlocal recording, frames | ||
nonlocal cam_index | ||
|
||
if event.text == "r": | ||
if not recording: | ||
output_file = f"output-{len(glob.glob('output-*.mp4')) + 1}.mp4" | ||
start_recording(canvas, output_file) | ||
else: | ||
stop_recording(canvas) | ||
|
||
# Disable camera cycling. The fly camera looks sufficient. | ||
# Keeping views/ranges same when switching cameras is not simple. | ||
# Prev | ||
|
@@ -238,6 +254,29 @@ def vispy_on_key_press(event): | |
elif event.text == "9": | ||
canvas.app.quit() | ||
|
||
def start_recording(canvas, output_file): | ||
nonlocal recording, frames | ||
recording = True | ||
frames = [] | ||
print(f"Recording started. Output file: {output_file}") | ||
|
||
def stop_recording(canvas): | ||
nonlocal recording, frames | ||
recording = False | ||
output_file = f"output-{len(glob.glob('output-*.mp4'))}.mp4" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we generated the name of the output file above already---can we not re-use that here also? |
||
imageio.mimwrite(output_file, frames, fps=24) | ||
print(f"Recording stopped. Video saved to {output_file}") | ||
frames = [] | ||
|
||
def capture_frame(event, canvas): | ||
nonlocal recording, frames | ||
|
||
if recording: | ||
frames.append(canvas.render().cv2png()) | ||
|
||
canvas.events.draw.connect(capture_frame) | ||
canvas.events.key_press.connect(vispy_on_key_press) | ||
|
||
return canvas, view | ||
|
||
|
||
|
@@ -735,6 +774,7 @@ def plot_3D_cell_morphology( | |
:raises: ValueError if `cell` is None | ||
|
||
""" | ||
|
||
if cell is None: | ||
raise ValueError( | ||
"No cell provided. If you would like to plot a network of point neurons, consider using `plot_2D_point_cells` instead" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to add this to the
setup.cfg
too, under thevispy-common
extra