mitsuba-af602c6fd98a/src/sensors/thinlens.cpp
/**
	 * \brief Compute the directional sensor response function
	 * of the camera multiplied with the cosine foreshortening
	 * factor associated with the image plane
	 *
	 * \param p
	 *     A position on the aperture
	 *
	 * \param d
	 *     A normalized direction vector from the aperture position to the
	 *     reference point in question (all in local camera space)
	 *
	 * \param sample
	 *     Optional: a pointer to a 2D point data structure, which will be
	 *     used to return the fractional pixel position associated with the
	 *     reference point
	 */
\brief Compute the directional sensor response function
of the camera multiplied with the cosine foreshortening
factor associated with the image plane

\param p
A position on the aperture

\param d
A normalized direction vector from the aperture position to the
reference point in question (all in local camera space)

\param sample
Optional: a pointer to a 2D point data structure, which will be
used to return the fractional pixel position associated with the
reference point
\ brief Compute the directional sensor response function of the camera multiplied with the cosine foreshortening factor associated with the image plane \ param p A position on the aperture \ param d A normalized direction vector from the aperture position to the reference point in question ( all in local camera space ) \ param sample Optional : a pointer to a 2D point data structure which will be used to return the fractional pixel position associated with the reference point
inline Float importance(const Point &p, const Vector &d, Point2 *sample = NULL) const {
		Float cosTheta = Frame::cosTheta(d);
		if (cosTheta <= 0)
			return 0.0f;
		Float invCosTheta = 1.0f / cosTheta;
		Point scr = m_cameraToSample(p
			+ d * (m_focusDistance*invCosTheta));
		if (scr.x < 0 || scr.x > 1 ||
			scr.y < 0 || scr.y > 1)
			return 0.0f;
		if (sample) {
			sample->x = scr.x * m_resolution.x;
			sample->y = scr.y * m_resolution.y;
		}
		return m_normalization * invCosTheta *
			invCosTheta * invCosTheta;
	}
inline Float importance ( const Point & p , const Vector & d , Point2 * sample = NULL ) const { Float cosTheta = Frame :: cosTheta ( d ) ; if ( cosTheta <= 0 ) return 0.0f ; Float invCosTheta = 1.0f / cosTheta ; Point scr = m_cameraToSample ( p + d * ( m_focusDistance * invCosTheta ) ) ; if ( scr . x < 0 || scr . x > 1 || scr . y < 0 || scr . y > 1 ) return 0.0f ; if ( sample ) { sample -> x = scr . x * m_resolution . x ; sample -> y = scr . y * m_resolution . y ; } return m_normalization * invCosTheta * invCosTheta * invCosTheta ; }
\brief Compute the directional sensor response function
 of the camera multiplied with the cosine foreshortening
 factor associated with the image plane
\ brief Compute the directional sensor response function of the camera multiplied with the cosine foreshortening factor associated with the image plane
/* How is this derived? Imagine a hypothetical image plane at a
		   distance of d=1 away from the aperture in camera space.

		   Then the visible rectangular portion of the plane has the area

		      A = (2 * tan(0.5 * xfov in radians))^2 / aspect

		   Since we allow crop regions, the actual visible area is
		   potentially reduced:

		      A' = A * (cropX / filmX) * (cropY / filmY)

		   Perspective transformations of such aligned rectangles produce
		   an equivalent scaled (but otherwise undistorted) rectangle
		   in screen space. This means that a strategy, which uniformly
		   generates samples in screen space has an associated area
		   density of 1/A' on this rectangle.

		   To compute the solid angle density of a sampled point P on
		   the rectangle, we can apply the usual measure conversion term:

		      d_omega = 1/A' * distance(P, origin)^2 / cos(theta)

		   where theta is the angle that the unit direction vector from
		   the origin to P makes with the rectangle. Since

		      distance(P, origin)^2 = Px^2 + Py^2 + 1

		   and

		      cos(theta) = 1/sqrt(Px^2 + Py^2 + 1),

		   we have

		      d_omega = 1 / (A' * cos^3(theta))
		*/ /* Check if the direction points behind the camera */ /* Check if the associated pixel is visible */