Modify implementation of Transform3DPoint

The new implementation assumes that the fourth component of the
homogeneous coordinate is not changed, which is true for all common
transforms except perspective projections. This should save several math
instructions to compute the fourth component and then divide the others
by it. If needed we can make a second method that does the complete
transform.

I am hoping that this will also solve what appears to be an optimization
bug on one of the dashboards.
This commit is contained in:
Kenneth Moreland 2016-06-11 11:38:03 -06:00
parent e47db6f610
commit 5dbcb33259

@ -35,18 +35,22 @@ namespace vtkm {
/// Given a 4x4 transformation matrix and a 3D point, returns the point
/// transformed by the given matrix in homogeneous coordinates.
///
/// This method ignores any change in the fourth component of the transformed
/// homogeneous coordinate, assuming that it is always 1 (that is, the last row
/// of the matrix is 0, 0, 0, 1). This will be true for affine transformations
/// (such as translate, scale, and rotate), but not for perspective
/// transformations.
///
template<typename T>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T,3> Transform3DPoint(const vtkm::Matrix<T,4,4> &matrix,
const vtkm::Vec<T,3> &point)
{
vtkm::Vec<T,4> homogeneousPoint(point[0], point[1], point[2], T(1));
homogeneousPoint = vtkm::MatrixMultiply(matrix, homogeneousPoint);
T invW = T(1)/homogeneousPoint[3];
return vtkm::Vec<T,3>(
homogeneousPoint[0]*invW,
homogeneousPoint[1]*invW,
homogeneousPoint[2]*invW);
vtkm::dot(vtkm::MatrixGetRow(matrix,0), homogeneousPoint),
vtkm::dot(vtkm::MatrixGetRow(matrix,1), homogeneousPoint),
vtkm::dot(vtkm::MatrixGetRow(matrix,2), homogeneousPoint));
}
/// \brief Transform a 3D point by a transformation matrix.