LidarView temporal camera animations

In this post, we will see how to use tools included in LidarView to programmatically generate visualizations of a temporal dataset (a dataset evolving with time, such as a Lidar recording) with a moving camera using ParaView animations and screenshots.

Animations in LidarView

We can distinguish 2 types of animations in LidarView:

  • temporal animations are animations that depend on the data flow. They increment the pipeline time at each step and require providing a trajectory input which is used to move the data reference (e.g. the car reference for a Lidar placed on a car) at each step.
  • non-temporal animations are simpler animations, moving the camera but not updating the pipeline time. The camera moves in a “frozen” version of the data. This kind of animation also works on both temporal and non-temporal data.

In this tutorial, we’ll see how to generate temporal animations like the following:

Overview of the different kinds of temporal animations

Animations with a movement relative to the scene

Fixed position view

The scene is viewed from a constant point in the scene reference, fixed compared to the background.

Fixed position view example

Absolute orbit

The scene is viewed following an orbit around a point of the scene reference.

Absolute orbit example

Animations with a movement relative to the trajectory

First person view

The scene is viewed from the current point in the trajectory.

First person view example

Third person view

The scene is viewed from a constant point relative to the vehicle (ie. to the current trajectory point).

Third person view example

Relative orbit

The scene is viewed following an orbit centered on the vehicle (ie. around the current trajectory point).

Relative orbit example

How to create such animations

Camera animations in LidarView are generated with a PythonAnimationCue object, which expects a script to define what the animation is doing when it starts, at each step and when it ends.

This script must have the following structure:

The smp.PythonAnimationCue() object requires this python script to be manually copy/pasted to the LidarView interface or provided as its animation.Script property (as a string).

LidarView now provides helper modules to create such scripts:

  • temporal_animation_cue_helpers.py and
  • camera_path.py

Those scripts require to have scipy installed on the python used by LidarView (pip install scipy on Linux or OS X).

How to define an animation cue script with temporal_animation_cue_helpers

An animation cue script is meant to be provided to a PythonAnimationCue. The usage of PythonAnimationCue is explained further down in this tutorial.

temporal_animation_cue_helpers provides some helpers functions in order to generate start_cue / tick / end_cue for temporal data with a trajectory using minimal code:

  • start_cue_generic_setup
  • tick
  • end_cue

Some of the module parameters can/must be overridden to correspond to your actual setup:

  • trajectory_name: the name of the element of the pipeline that serves for trajectory (it must contain Time and Orientation(AxisAngle) for each point)
  • cp.R_cam_to_lidar: the rotation between the Lidar reference and the camera reference, see below for more details on how to set it (it is actually a parameter of camera_path)
  • frames_output_dir: directory where you save the output screenshots (use empty string to disable saving)
  • cad_model_name (optional): the name of the element of the pipeline that serves for the 3D model to place at the current trajectory point for each frame.

start_cue_generic_setup

This method runs generic setup steps at cue start. It is intended to be run inside a start_cue before the camera definition step.

The different steps it runs are:

  • getting the trajectory
  • getting the frames orientations from the trajectory
  • (optional) getting a 3D model (for example a car model to add to the frame display)
  • setting the start timestep

The only setup left to do is the camera path, which can be composed of:

  • CameraPath objects (FirstPersonVew, ThirdPersonView, …). See below for hints on how to set their parameters.
  • Transitions between those objects following this model:

Example:

Please note that each camera path takes beginning and end timesteps with an offset of self.i, this enables the animation to start at the trajectory point corresponding to the current View timestep (see examples further down).

tick

This method runs the following steps at each timestep:

  • get the current orientation and position from the trajectory
  • move the camera according to this pose and the CameraPath defined for the current timestep
  • move the 3D model
  • save the current frame using ParaView’s saveScreenshot method.

As a PythonAnimationCue script expects a tick function with only a self argument, this function can be either directly used with its default keyword arguments or wrapped in another function that provides its keyword arguments.

Example:

end_cue

This method only prints that the animation is finished. It can be used directly with an import.

Example:

Example

Here is an example of a full PythonAnimationCue script.

See example_temporal_animation.py (https://gitlab.kitware.com/LidarView/lidarview-core/-/blob/master/Utilities/Animation/example_temporal_animation.py) for an example in context.

How to set the parameters (position, up_vector, focal_point, …) for the different camera paths

  • AbsoluteOrbit and FixedPositionView are camera paths that are not relative to the trajectory, hence they expect absolute parameters (with coordinates in the fix reference of the view).
  • ThirdPersonView, FirstPersonView and RelativeOrbit expect coordinates that are relative to the trajectory, so they expect coordinates in the camera reference (ie. the reference of the current lidar frame, rotated by R_cam_to_lidar).

How to set R_cam_to_lidar

R_cam_to_lidar is the rotation between the camera frame and the lidar frame. The camera has to be set with X, Y forming the image plane, and Z pointing in the field of view of the image.

Example:

In the following case (from dataset-la-doua), the Z axis of the lidar is vertical, but X doesn’t point to the front of the car, R_car_to_lidar should be set to something like:

Which is composed of:

  • a rotation of 17 deg around Z to compensate for the Lidar/trajectory yaw angle offset
  • a rotation of [0, 90.0, -90.0] to pass from Z in the front (camera reference) to X in the front (Lidar reference)
Lidar, camera and car references

How to set the camera path parameters

  • position: position of the camera, either
    • in the frame reference for absolute camera paths
    • in the camera reference, with the Lidar position as origin for relative camera paths
  • focal_point: focal point of the camera in the camera reference (where the camera is pointing to)
  • up_vector: direction of the top of the image.
Camera path parameters

Specifics to orbits:

  • initial_pos: initial position of the camera (similar to position)
  • up_vector: rotation axis
  • center: center of rotation
  • ccw: 1 or -1, decides the rotation direction (counter-clock-wise by default)
Orbit parameters

Specific to FixedPositionView:

  • position is by default to None, in which case it takes the current position
  • focal_point is by default to None, in which case it uses the Lidar position

Tips

How to generate a pseudo first person view from the top of a car model

This enables being slightly behind and on top of the car and see the front of it in the view.

How to add, scale and center a 3D car model

(The values for this example are valid for dataset-la-doua)

Steps:

  • add a cad model reader
  • add a transform to make the model look forward in the Lidar reference
  • add a second transform to let the camera_animation_cue move the car with the trajectory.

Example:

How to apply those animations to a pipeline in LidarView

  • Define a LidarView processing pipeline
  • Make sure the trajectory the View have a similar time base (which can be different of the pointcloud’s time base)
  • Select what you want to show in the animation
  • Setup the animation
  • Play the animation

Using a python script

Define a LidarView processing pipeline

See example_temporal_animation.py (https://gitlab.kitware.com/LidarView/lidarview-core/-/blob/master/Utilities/Animation/example_temporal_animation.py) for an example.

Make sure the trajectory and the data have a similar time base

To do so, you might need to update the trajectory with a timeshift.

Example:

Select what you want to show in the animation

Example:

Set up the animation

Play the animation

Using LidarView GUI

Define your pipeline in the Pipeline Browser pane.

Example:

Animation pipeline example

Open the Animation pane, choose the Snap to timesteps mode

Animation pane

Double-click on the Python button in the animation table if it has automatically been added (normal behavior) or add a Python animation by selecting it in the drop-down list under the table and clicking on +.

This will open a pop-up window. Replace its content by the animation script.

Example:

Animation script example

Press OK and run the animation with the Play button in the top bar.

This will save a screenshot at each timestep of the data into the folder that is defined as tach.frames_output_dir.

Questions or comments are always welcome!

X