Skip to content

Commit

Permalink
Merge branch 'master' into blog-posts
Browse files Browse the repository at this point in the history
  • Loading branch information
antrikshmisri committed Sep 16, 2021
2 parents af97577 + ffee0a6 commit 9b75674
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 870 deletions.
97 changes: 66 additions & 31 deletions fury/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
VTK_9_PLUS = vtk.vtkVersion.GetVTKMajorVersion() >= 9


def manifest_pbr(actor, metallicity=1, roughness=.5):
def manifest_pbr(actor, metallicity=0, roughness=.5):
"""Apply the Physically Based Rendering properties to the selected actor.
Parameters
Expand All @@ -19,49 +19,84 @@ def manifest_pbr(actor, metallicity=1, roughness=.5):
"""
if not VTK_9_PLUS:
warnings.warn("Your PBR effect can not be apply due to VTK version. "
"Please upgrade your VTK version (should be >= 9.0.0).")
warnings.warn('Your PBR effect cannot be apply due to VTK version. '
'Please upgrade your VTK version (should be >= 9.0.0).')
return

prop = actor.GetProperty()
prop.SetInterpolationToPBR()
prop.SetMetallic(metallicity)
prop.SetRoughness(roughness)
try:
prop = actor.GetProperty()
try:
prop.SetInterpolationToPBR()
prop.SetMetallic(metallicity)
prop.SetRoughness(roughness)
except AttributeError:
warnings.warn(
'PBR interpolation cannot be applied to this actor. The '
'material will not be applied.')
return
except AttributeError:
warnings.warn('Actor does not have the attribute property. This '
'material will not be applied.')
return


def manifest_standard(actor, ambient_level=.7, diffuse_level=.8,
specular_level=.5, specular_power=10,
interpolation='phong'):
def manifest_standard(actor, ambient_level=0, ambient_color=(1, 1, 1),
diffuse_level=1, diffuse_color=(1, 1, 1),
specular_level=0, specular_color=(1, 1, 1),
specular_power=1, interpolation='gouraud'):
"""Apply the standard material to the selected actor.
Parameters
----------
actor : actor
ambient_level : float, optional
Metallic or non-metallic (dielectric) shading computation value. Values
must be between 0.0 and 1.0.
Ambient lighting coefficient. Value must be between 0.0 and 1.0.
ambient_color : tuple (3,), optional
Ambient RGB color where R, G and B should be in the range [0, 1].
diffuse_level : float, optional
Parameter used to specify how glossy the actor should be. Values must
be between 0.0 and 1.0.
Diffuse lighting coefficient. Value must be between 0.0 and 1.0.
diffuse_color : tuple (3,), optional
Diffuse RGB color where R, G and B should be in the range [0, 1].
specular_level : float, optional
Parameter used to specify how glossy the actor should be. Values must
be between 0.0 and 1.0.
Specular lighting coefficient. Value must be between 0.0 and 1.0.
specular_color : tuple (3,), optional
Specular RGB color where R, G and B should be in the range [0, 1].
specular_power : float, optional
Parameter used to specify how glossy the actor should be. Values must
be between 0.0 and 1.0.
interpolation : float, optional
Parameter used to specify how glossy the actor should be. Values must
be between 0.0 and 1.0.
Parameter used to specify the intensity of the specular reflection.
Value must be between 0.0 and 128.0.
interpolation : string, optional
If 'flat', the actor will be shaded using flat interpolation. If
'gouraud' (default), then the shading will be calculated at the
vertex level. If 'phong', then the shading will be calculated at the
fragment level.
"""
prop = actor.GetProperty()
prop.SetAmbient(ambient_level)
prop.SetDiffuse(diffuse_level)
prop.SetSpecular(specular_level)
prop.SetSpecularPower(specular_power)
try:
prop = actor.GetProperty()

interpolation = interpolation.lower()

if interpolation == 'flat':
prop.SetInterpolationToFlat()
elif interpolation == 'gouraud':
prop.SetInterpolationToGouraud()
elif interpolation == 'phong':
prop.SetInterpolationToPhong()
else:
message = 'Unknown interpolation. Ignoring "{}" interpolation ' \
'option and using the default ("{}") option.'
message = message.format(interpolation, 'gouraud')
warnings.warn(message)

prop.SetAmbient(ambient_level)
prop.SetAmbientColor(ambient_color)
prop.SetDiffuse(diffuse_level)
prop.SetDiffuseColor(diffuse_color)
prop.SetSpecular(specular_level)
prop.SetSpecularColor(specular_color)
prop.SetSpecularPower(specular_power)
except AttributeError:
warnings.warn('Actor does not have the attribute property. This '
'material will not be applied.')
return

if interpolation.lower() == 'phong':
prop.SetInterpolationToPhong()
else:
warnings.warn('Unknown interpolation. Ignoring "{}" interpolation '
'option.'.format(interpolation))
Loading

0 comments on commit 9b75674

Please sign in to comment.