Introduction
The PerspectiveInstrument class in SKIRT implements a full perspective view of the simulated model, with arbitrary placement of the viewport outside or inside the model. Only photon packets arriving from the front are recorded; light emitted behind the viewport is ignored. For each wavelength the instrument outputs the detected surface brightness in every pixel of a given frame as a data cube in a FITS file. The instrument does not support recording of spatially integrated flux densities.
The perspective instrument is intended mostly for making movies. Each movie frame is generated by a separate perspective instrument with the appropriate parameters.
Parameters and coordinate systems
The following table lists all parameters for the perspective instrument other than the options common to all instrument, which obviously have no effect on the perspective transformation. Positions and sizes are specified in the right-handed world coordinate system, i.e. the coordinate system in which the SKIRT model is defined, using units of length such as parsec. Usually the model is centered around the origin of the world coordinate system.
Parameter(s) | Description |
| The number of pixels in the viewport in the local and directions |
| The size (twice the extent) of the viewport in the local and directions |
| The position of the viewport origin |
| The crosshair position that determines the orientation of the viewport's axis |
| The upwards position that determines the orientation of the viewport's axis |
| The focal length that determines the position of the eye |
The aspect ratio of the viewport is assumed to be the same when calculated in pixels ( ) or in world size ( ). If not the perspective transformation will introduce a distortion.
The viewport is placed in the plane of the left-handed viewport coordinate system (left-handed so that depth increases along the -axis). Both the viewport and the coordinate system are centered around the viewport origin . The axis is placed along the crosshair line , i.e. the line connecting the viewport origin with the crosshair position, in the direction of . Consequently the viewport is perpendicular to . The axis is placed such that it is parallel with the upwards line , i.e. the line connecting the world origin with the upwards position, and in the same direction.
The eye and the origin of the left-handed eye coordinate system are placed on the crosshair line at a distance from the viewport origin , at the opposite side from . In other words, the eye is behind the viewport and looks towards the crosshair position through the viewport. The axes of the eye coordinate system have the same orientation as those of the viewport coordinate system. The perspective transformation occurs from the eye to the viewport system.
Derived positions and directions
We denote the norm of an arbitrary point or vector as
A unit vector in the direction from the crosshair position to the viewport origin can then be written as
and the eye position becomes
When a peel-off photon packet is launched towards the instrument from position , a unit vector with the appropriate direction is given by
Homogeneous coordinates
We use homogeneous coordinates with arbitrary scale factor . An arbitary point can be represented in homogeneous coordinates as . An arbitrary direction is represented as a point at infinity .
Vice versa, given the homogeneous coordinates , the corresponding regular coordinates for the point can be retrieved as provided .
A homogeneous coordinate transformation can be written as where is a transformation matrix which can represent a scaling, rotation, translation, perspective transformation or any combination thereof; or more explicitly
Consecutive transformations can be combined into a single transformation matrix through regular matrix multiplication.
The instrument transformation
When a peel-off photon packet launched from position arrives at the perspective instrument, a single transformation is applied to find the homogeneous coordinates of the pixel receiving the photon packet's luminosity
where and represents the composite transformation from world coordinates to pixel coordinates which will be developed below.
The incoming photon packet's luminosity is taken into account only if the packet originated in front of the viewport and if the pixel indices are both within range (from zero up to the number of pixels in the relevant direction minus one). The pixel indices can be retrieved using
based on the standard mechanism for converting homogeneous to regular coordinates. The perspective transformation developed below is such that the distance from the launching position to the the viewport plane is given by
and is in front of the viewport if and only if . In this case there is no division by to avoid distortion of the distance scale by the perspective transformation.
Developing the transformation
At the highest level we compose the instrument transformation as follows
where
- transforms from world coordinates to eye coordinates
- transforms from eye coordinates to viewport coordinates
- transforms from viewport coordinates to pixel coordinates
From world to eye coordinates
The transformation from world to eye coordinates can be composed as follows
with from left to right:
- translate the origin to the eye position;
- rotate around the and axes to align the axis with the crosshair line , pointing in the direction of the eye; the plane is now parallel with the viewport;
- rotate around the axis to align the axis so that it is parallel with and in the same direction as the projection on the plane of the upwards line ; the axis now points up and the axis now points to the right when looking down from the positive axis;
- flip the direction of the axis so that depth increases away from the eye.
It is easy to see that
To determine let be the direction cosines of the desired axis alignment, i.e. the direction from the crosshair position to the eye position
and define as the hypothenuse of the direction vector's projection in the plane. For the time being, assume that .
Alignment of the axis with can then be accomplished by a rotation over about the axis (figure (a)) followed by a rotation over about the axis (figure (b)) – the angles are directed clockwise when looking down from the positive rotation axis. The projection of vector in the plane has components along the axis and along the axis, so that and . The situation after the first rotation is shown in figure (b). The length of the hypothenuse in this figure is since the direction cosines are normalized. It is then immediately clear that and . Thus we find
To determine , let be the direction cosines of the desired axis alignment, i.e. the direction from the world origin to the upwards position, after partial transformation to eye coordinates
so that the projection of the upwards direction on the eye plane has components along the axis and along the axis. Using the previously derived value for simple matrix algebra leads to
where we dropped a proportionality factor of in both values, since and are not normalized.
We need a rotation over about the axis (figure (c)). Defining , a reasoning similar to the one before gives and , and thus
In case the matrices and as derived above are not well defined and the rotations to align the axis should be performed in reverse order, i.e. first about the axis and then about the axis. A reasoning similar to the above leads to the alternative
From eye to viewport coordinates
The figure shows the plane of the eye and viewport coordinate systems. To develop the perspective transformation, note that the triangles and are similar so that . With similar reasoning in the plane, we get
In the direction we wish to preserve the distance scale and simply perform the translation
This can be accomplished through the homogeneous transformation matrix
keeping in mind that the and coordinates will be divided by when converting from homogeneous to regular coordinates, and assuming that the coordinate will not be divided by this factor. This `‘trick’' for the coordinate works only because we have set when converting the original point to homogeneous coordinates, and none of the other transformation matrices change the coordinate.
From viewport to pixel coordinates
The viewport is centered on the origin and is scaled in world distances, while pixel indices range from zero to the number of pixels in each direction minus one. Thus we need to apply the following scaling and translation
We leave the depth coordinate unchanged, which means it is still scaled in world distances, zero depth corresponds with the viewport plane, and positive depth indicates positions in front of the viewport.
Flux calibration
Each photon packet arriving at the instrument carries a certain fraction of luminosity at a particular wavelength . The contribution of the photon packet to the surface brightness of the target instrument pixel can be written as (also see the FluxRecorder class),
where is the width of the wavelength bin containing the wavelength , is the distance from the photon packet's origin to the instrument, and is the solid angle subtended by the target pixel as seen from the eye position.
This solid angle depends on the location of the pixel in the viewport. Pixels at the edges or in the corners of the viewport subtend a smaller solid angle than central pixels. The current implementation of the instrument, though, uses the solid angle of the central pixel for all pixels in the viewport. Let us examine the nature of the error introduced by this approximation. For simplicity, we assume a square viewport of size with square pixels and a distance from the viewport to the eye position (focal length) of . Further assuming that is uneven, the solid angle of the central viewport pixel is given by
It is straightforward to also calculate the solid angle of a pixel in of the corners of the viewport. The relative error is plotted in the figure below (as a percentage) as a function of the ratio of the viewport size and the focal length:
It is thus recommended to place the eye at a distance of at least twice the size of the viewpoint. In that case, the error in the flux calibration at the edges of the viewport is limited to about 10%. Conversely, if the focal distance becomes smaller than the viewport size, the error quickly rises to an unacceptable level.
Lastly, to avoid overly large contributions from extremely nearby objects, the instrument ignores any photon packets that originated at a distance to the viewport . (Photon packets originating behind the viewport are ignored in any case).