diff --git a/ex6/README.md b/ex6/README.md index aa1c87a74b05f1e2257d0f4ea53af2a78c19c137..d34fedcdc725206700739c45526a4c5f1c36b226 100644 --- a/ex6/README.md +++ b/ex6/README.md @@ -26,7 +26,9 @@ An overview over the different transfer functions can be seen here: <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) 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: diff --git a/ex6/VolumeRenderingHead.py b/ex6/VolumeRenderingHead.py index 0e4952ccb55e641d940364ebedf356d139a0aeae..32e54b2b0aaef39be4be9cb17cf5cb1764a37017 100644 --- a/ex6/VolumeRenderingHead.py +++ b/ex6/VolumeRenderingHead.py @@ -27,6 +27,7 @@ def bump(val1: float, val2: float, colorval1: List[float], colorval2: List[float def main(): + global render_window, volume_prop, actor_volume, scalar_range colors = vtk.vtkNamedColors() color_bg = map(lambda x: x / 255.0, [255, 255, 255, 255]) colors.SetColor("BackGroundColor", *color_bg) @@ -49,6 +50,9 @@ def main(): # Create the RendererWindowInteractor and display the vtk_file interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(render_window) + interactor.RemoveObservers("KeyPressEvent") + interactor.RemoveObservers("CharEvent") + interactor.AddObserver('KeyPressEvent', keypress_callback, 1.0) render_window.SetWindowName('SCIVIS EX6') render_window.Render() @@ -81,6 +85,62 @@ def main(): renderer.ResetCamera() render_window.Render() 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__':