Guest User

Untitled

a guest
Dec 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. diff --git a/yt/visualization/volume_rendering/lens.py b/yt/visualization/volume_rendering/lens.py
  2. index b5b466467..31ff6dfec 100644
  3. --- a/yt/visualization/volume_rendering/lens.py
  4. +++ b/yt/visualization/volume_rendering/lens.py
  5. @@ -46,12 +46,15 @@ class Lens(ParallelAnalysisInterface):
  6. """
  7. self.setup_box_properties(camera)
  8.  
  9. - def new_image(self, camera):
  10. + def new_image(self, camera, color='k'):
  11. """Initialize a new ImageArray to be used with this lens."""
  12. + from matplotlib.colors import to_rgba
  13. + color = to_rgba(color)
  14. self.current_image = ImageArray(
  15. np.zeros((camera.resolution[0], camera.resolution[1],
  16. 4), dtype='float64', order='C'),
  17. info={'imtype': 'rendering'})
  18. + self.current_image += color
  19. return self.current_image
  20.  
  21. def setup_box_properties(self, camera):
  22. @@ -152,13 +155,6 @@ class PerspectiveLens(Lens):
  23. def __init__(self):
  24. super(PerspectiveLens, self).__init__()
  25.  
  26. - def new_image(self, camera):
  27. - self.current_image = ImageArray(
  28. - np.zeros((camera.resolution[0], camera.resolution[1],
  29. - 4), dtype='float64', order='C'),
  30. - info={'imtype': 'rendering'})
  31. - return self.current_image
  32. -
  33. def _get_sampler_params(self, camera, render_source):
  34. # Enforce width[1] / width[0] = resolution[1] / resolution[0]
  35. camera.width[1] = camera.width[0] \
  36. @@ -299,14 +295,6 @@ class StereoPerspectiveLens(Lens):
  37. super(StereoPerspectiveLens, self).__init__()
  38. self.disparity = None
  39.  
  40. - def new_image(self, camera):
  41. - """Initialize a new ImageArray to be used with this lens."""
  42. - self.current_image = ImageArray(
  43. - np.zeros((camera.resolution[0], camera.resolution[1], 4),
  44. - dtype='float64', order='C'),
  45. - info={'imtype': 'rendering'})
  46. - return self.current_image
  47. -
  48. def _get_sampler_params(self, camera, render_source):
  49. # Enforce width[1] / width[0] = 2 * resolution[1] / resolution[0]
  50. # For stereo-type lens, images for left and right eye are pasted together,
  51. @@ -524,14 +512,6 @@ class FisheyeLens(Lens):
  52. super(FisheyeLens, self).setup_box_properties(camera)
  53. self.set_viewpoint(camera)
  54.  
  55. - def new_image(self, camera):
  56. - """Initialize a new ImageArray to be used with this lens."""
  57. - self.current_image = ImageArray(
  58. - np.zeros((camera.resolution[0], camera.resolution[0],
  59. - 4), dtype='float64', order='C'),
  60. - info={'imtype': 'rendering'})
  61. - return self.current_image
  62. -
  63. def _get_sampler_params(self, camera, render_source):
  64. vp = -arr_fisheye_vectors(camera.resolution[0], self.fov)
  65. vp.shape = (camera.resolution[0], camera.resolution[0], 3)
  66. diff --git a/yt/visualization/volume_rendering/render_source.py b/yt/visualization/volume_rendering/render_source.py
  67. index 434401f87..0b06b90cc 100644
  68. --- a/yt/visualization/volume_rendering/render_source.py
  69. +++ b/yt/visualization/volume_rendering/render_source.py
  70. @@ -467,10 +467,7 @@ class VolumeSource(RenderSource):
  71. if self._volume is not None:
  72. image = self.volume.reduce_tree_images(image, camera.lens.viewpoint)
  73. image.shape = camera.resolution[0], camera.resolution[1], 4
  74. - # If the call is from VR, the image is rotated by 180 to get correct
  75. - # up direction
  76. - if self.transfer_function.grey_opacity is False:
  77. - image[:, :, 3] = 1
  78. +
  79. return image
  80.  
  81. def __repr__(self):
  82. diff --git a/yt/visualization/volume_rendering/scene.py b/yt/visualization/volume_rendering/scene.py
  83. index e27185943..309a0bb7a 100644
  84. --- a/yt/visualization/volume_rendering/scene.py
  85. +++ b/yt/visualization/volume_rendering/scene.py
  86. @@ -107,6 +107,34 @@ class Scene(object):
  87. return self.sources[item]
  88. return self.get_source(item)
  89.  
  90. + _background_color = "black"
  91. + def background_color():
  92. + doc = """
  93. + The background color sets the color of the scene's background.
  94. + Note that background_color cannot be set if the scene contains
  95. + a VolumeSource with a grey_opacity=False transfer function
  96. +
  97. + Parameters
  98. + ----------
  99. + background_color : string or 3 or 4 element iterable
  100. + The color to use for the background. It will be converted
  101. + to an RGBA tuple using matplotlib.colors.to_rgba.
  102. + """
  103. + def fget(self):
  104. + return self._background_color
  105. +
  106. + def fset(self, value):
  107. + for source in self.sources.values():
  108. + if isinstance(source, VolumeSource):
  109. + tf = source.transfer_function
  110. + if not getattr(tf, 'grey_opacity', False):
  111. + raise RuntimeError(
  112. + "Cannot set the background color for a render "
  113. + "source with grey_opacity=True")
  114. + self._background_color = value
  115. + return locals()
  116. + background_color = property(**background_color())
  117. +
  118. @property
  119. def opaque_sources(self):
  120. """
  121. @@ -522,7 +550,7 @@ class Scene(object):
  122. """
  123. if camera is None:
  124. camera = self.camera
  125. - empty = camera.lens.new_image(camera)
  126. + empty = camera.lens.new_image(camera, color=self.background_color)
  127. opaque = ZBuffer(empty, np.full(empty.shape[:2], np.inf))
  128.  
  129. for k, source in self.opaque_sources:
Add Comment
Please, Sign In to add comment