mitsuba-af602c6fd98a/src/sensors/perspective_rdist.cpp
/**
	 * \brief Compute the directional sensor response function
	 * of the camera multiplied with the cosine foreshortening
	 * factor associated with the image plane
	 *
	 * \param d
	 *     A normalized direction vector from the aperture position to the
	 *     reference point in question (all in local camera space)
	 */
\brief Compute the directional sensor response function
of the camera multiplied with the cosine foreshortening
factor associated with the image plane

\param d
A normalized direction vector from the aperture position to the
reference point in question (all in local camera space)
\ brief Compute the directional sensor response function of the camera multiplied with the cosine foreshortening factor associated with the image plane \ param d A normalized direction vector from the aperture position to the reference point in question ( all in local camera space )
inline Float importance(const Vector &d) const {
		Float cosTheta = Frame::cosTheta(d);
		if (cosTheta <= 0)
			return 0.0f;
		Float invCosTheta = 1.0f / cosTheta;
		Point2 p(d.x * invCosTheta, d.y * invCosTheta);
		Float importance = m_normalization * invCosTheta
				* invCosTheta * invCosTheta;
		if (m_distortion) {
			Float rOrig2  = Vector2(p).lengthSquared(),
				  rFactor = applyDistortion(rOrig2);
			Float deriv = 1 + rOrig2*(3*m_kc[0] + 5*m_kc[1]*rOrig2);
			importance *= std::abs(rFactor*deriv);
			p *= rFactor;
		}
		if (!m_imageRect.contains(p))
			return 0.0f;
		return importance;
	}
inline Float importance ( const Vector & d ) const { Float cosTheta = Frame :: cosTheta ( d ) ; if ( cosTheta <= 0 ) return 0.0f ; Float invCosTheta = 1.0f / cosTheta ; Point2 p ( d . x * invCosTheta , d . y * invCosTheta ) ; Float importance = m_normalization * invCosTheta * invCosTheta * invCosTheta ; if ( m_distortion ) { Float rOrig2 = Vector2 ( p ) . lengthSquared ( ) , rFactor = applyDistortion ( rOrig2 ) ; Float deriv = 1 + rOrig2 * ( 3 * m_kc [ 0 ] + 5 * m_kc [ 1 ] * rOrig2 ) ; importance *= std :: abs ( rFactor * deriv ) ; p *= rFactor ; } if ( ! m_imageRect . contains ( p ) ) return 0.0f ; return importance ; }
\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 pinhole 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 */ /* Compute the position on the plane at distance 1 */ /* Correct importance for radial distortion */ /* Check if the point lies inside the chosen crop rectangle */