Dynamically changing opacity in Python with vtkPieceWiseFunction

I am trying to figure out if it is possible to modify the vtkPieceWiseFunction, since I am trying to dynamically change the opacity according to a specific formula when using RayCasting. I’m using python 3.8.

The formula calculates the opacity in a way that the opacity will change depending on the angle we are looking at the volume. Taking into account factors such as the distance between sample point and eye point, opaque of previous sample point.

Is there a way to modify the vtkPieceWiseFunction instead of doing a AddPoint?
If a write a function for opacity, would it be possible to somehow use that function in “AddPoint” ?

I would appriciate any help,
Best regards