Skip to content
Snippets Groups Projects
Commit 3a8f16fe authored by wetzels's avatar wetzels
Browse files

Added test cases for different transfer functions in Exercise 6.

parent 56923d02
Branches
No related tags found
2 merge requests!2Exercise1,!1Exercise 1
...@@ -26,7 +26,9 @@ An overview over the different transfer functions can be seen here: ...@@ -26,7 +26,9 @@ An overview over the different transfer functions can be seen here:
<img src="img/tfs.png" width="500"> <img src="img/tfs.png" width="500">
**Summary of Tasks:** Implement the 5 transfer functions. Save your code as `task1.py`. Please mark the line to change the transfer functions through comments or make it possible to switch between them through a button. The provided code in `VolumeRenderingHead.py` contains test cases (i.e. transfer function calls) that can be selected through by using buttons 1-7. You can use them for testing your implementation as well as initial function calls in the designated part of the main method. We will use the provided test cases to check the correctness of your solution.
**Summary of Tasks:** Implement the 5 transfer functions. Save your code as `task1.py`.
## Task 2: Creating an interesting visualization (1P) ## Task 2: Creating an interesting visualization (1P)
Now that we have our basic transfer functions, we can use them to create meaningful visualizations. Use one or multiple tfs with different values to create such a visualization. One example could look like the following: Now that we have our basic transfer functions, we can use them to create meaningful visualizations. Use one or multiple tfs with different values to create such a visualization. One example could look like the following:
......
...@@ -27,6 +27,7 @@ def bump(val1: float, val2: float, colorval1: List[float], colorval2: List[float ...@@ -27,6 +27,7 @@ def bump(val1: float, val2: float, colorval1: List[float], colorval2: List[float
def main(): def main():
global render_window, volume_prop, actor_volume, scalar_range
colors = vtk.vtkNamedColors() colors = vtk.vtkNamedColors()
color_bg = map(lambda x: x / 255.0, [255, 255, 255, 255]) color_bg = map(lambda x: x / 255.0, [255, 255, 255, 255])
colors.SetColor("BackGroundColor", *color_bg) colors.SetColor("BackGroundColor", *color_bg)
...@@ -49,6 +50,9 @@ def main(): ...@@ -49,6 +50,9 @@ def main():
# Create the RendererWindowInteractor and display the vtk_file # Create the RendererWindowInteractor and display the vtk_file
interactor = vtk.vtkRenderWindowInteractor() interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(render_window) interactor.SetRenderWindow(render_window)
interactor.RemoveObservers("KeyPressEvent")
interactor.RemoveObservers("CharEvent")
interactor.AddObserver('KeyPressEvent', keypress_callback, 1.0)
render_window.SetWindowName('SCIVIS EX6') render_window.SetWindowName('SCIVIS EX6')
render_window.Render() render_window.Render()
...@@ -82,6 +86,62 @@ def main(): ...@@ -82,6 +86,62 @@ def main():
render_window.Render() render_window.Render()
interactor.Start() interactor.Start()
def keypress_callback(obj, ev):
key = obj.GetKeySym()
if key == '1':
update_rendering(1)
elif key == '2':
update_rendering(2)
elif key == '3':
update_rendering(3)
elif key == '4':
update_rendering(4)
elif key == '5':
update_rendering(5)
elif key == '6':
update_rendering(6)
elif key == '7':
update_rendering(7)
else:
pass
def update_rendering(testcase):
global volume_prop, actor_volume, scalar_range, render_window
opacity = vtk.vtkPiecewiseFunction()
color = vtk.vtkColorTransferFunction()
if testcase == 1:
constant([1,1,0], 0.02, scalar_range, opacity, color) #test constant function (alpha)
elif testcase == 2:
step(1500, [1,1,0], 0.5, opacity, color) #test step function (alpha)
elif testcase == 3:
rect(1500, 2000, [1,1,0], [1,1,0], 0.5, opacity, color) #test rect and rect vs step (alpha)
elif testcase == 4:
rect(1200, 2200, [1,0,0], [0,0,1], 0.4, opacity, color) #test colors
elif testcase == 5:
hat(1500, 2000, [1,1,0], [1,1,0], 0.5, opacity, color) #test hat and hat vs rect (alpha)
elif testcase == 6:
bump(1500, 2000, [1,1,0], [1,1,0], .5, 20, opacity, color) #test bump and bump vs hat (alpha)
elif testcase == 7:
bump(1500, 2000, [1,1,0], [1,1,0], .5, 1, opacity, color) #test smoothness
else:
print("Undefined Transferfunction state!")
return
volume_prop = vtk.vtkVolumeProperty()
volume_prop.ShadeOn()
volume_prop.SetInterpolationTypeToLinear()
volume_prop.SetScalarOpacity(opacity)
volume_prop.SetColor(color)
actor_volume.SetProperty(volume_prop)
render_window.Render()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment