Skip to content

Commit

Permalink
modified: separate scripting and povray rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
skim0119 committed Oct 30, 2020
1 parent ec208b9 commit 58ce9b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
44 changes: 23 additions & 21 deletions examples/Visualization/_povmacros.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def pyelastica_rod(


def render(
script,
frame_number,
script_file,
image_file,
width,
height,
antialias="on",
directory="frames",
quality=11,
display="Off",
pov_thread=4
):
"""Rendering frame
Expand All @@ -89,22 +89,25 @@ def render(
Parameters
----------
script : str
The povray script in string
frame_number : int
The frame number to export
script_file : str
Input .pov file path
image_file : str
Output .png file path
width : int
The width of the output image.
height : int
The height of the output image.
antialias : str ['on', 'off']
Turns anti-aliasing on/off [default='on']
directory : str
Output directory. [default='frames']
quality : int
Image output quality. [default=11]
display : str
Turns display option on/off during POVray rendering. [default='off']
pov_thread : int
Number of thread per povray process. [default=4]
Acceptable range is (4,512).
Refer 'Symmetric Multiprocessing (SMP)' for further details
https://www.povray.org/documentation/3.7.0/r3_2.html#r3_2_8_1
Raises
------
Expand All @@ -114,19 +117,18 @@ def render(
"""

# Define file names
image_file = os.path.join(directory, "frame_{:04d}.png".format(frame_number))
pov_file = os.path.join(directory, "frame_{:04d}.pov".format(frame_number))

# Write - POVray script
with open(pov_file, "w+") as f:
f.write(script)

# Run Povray as subprocess
cmds = ["povray", "+I" + pov_file, "+O" + image_file, f"-H{height}", f"-W{width}"]
cmds.append(f"Antialias={antialias}")
cmds.append(f"Quality={quality}")
cmds.append(f"Display={display}")
cmds = [
"povray",
"+I" + script_file,
"+O" + image_file,
f"-H{height}",
f"-W{width}",
f"Work_Threads={pov_thread}",
f"Antialias={antialias}",
f"Quality={quality}",
f"Display={display}"
]
process = subprocess.Popen(
cmds, stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
Expand Down
33 changes: 22 additions & 11 deletions examples/Visualization/continuum_snake_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
base_radius = np.ones_like(xs[:, 0, :]) * 0.050 # (TODO) radius could change

# Rendering
# For each frames, a 'png' image file is generated in OUTPUT_IMAGE_DIR directory.
# For each frame, a 'pov' script file is generated in OUTPUT_IMAGE_DIR directory.
batch_in = []
batch_out = []
for view_name in stage_scripts.keys(): # Make Directory
output_path = os.path.join(OUTPUT_IMAGES_DIR, view_name)
os.makedirs(output_path, exist_ok=True)
Expand All @@ -133,17 +135,26 @@
color='rgb<0.45,0.39,1>'
)
script.append(rod_object)

# Render
pov_script = "\n".join(script)
render(
pov_script,
frame_number,
width=WIDTH,
height=HEIGHT,
directory=output_path,
display=DISPLAY_FRAMES,
)

# Write .pov script file
pov_file = os.path.join(output_path, "frame_{:04d}.pov".format(frame_number))
image_file = os.path.join(output_path, "frame_{:04d}.png".format(frame_number))
with open(pov_file, "w+") as f:
f.write(pov_script)
batch_in.append(pov_file)
batch_out.append(image_file)

# Process POVray
# For each frames, a 'png' image file is generated in OUTPUT_IMAGE_DIR directory.
for script_file, image_file in tqdm(zip(batch_in, batch_out), total=total_frame):
render(
script_file,
image_file,
width=WIDTH,
height=HEIGHT,
display=DISPLAY_FRAMES,
)

# Create Video using moviepy
for view_name in stage_scripts.keys():
Expand Down

0 comments on commit 58ce9b4

Please sign in to comment.