Commit 833e91e8 authored by David C. Lonie's avatar David C. Lonie
Browse files

Inline and optimize vtkMatrix4x4::Multiply4x4.

Replace the final loop with a call to std::copy, which turns
into memmove at the end of the day.

Change-Id: I3529a949863d4192e83f58d5c86d0df0d8dd1ed1
parent 99101fdf
......@@ -21,9 +21,6 @@
vtkStandardNewMacro(vtkMatrix4x4);
// Useful for viewing a double[16] as a double[4][4]
typedef double (*SqMatPtr)[4];
//----------------------------------------------------------------------------
void vtkMatrix4x4::Zero(double Elements[16])
{
......@@ -100,38 +97,6 @@ void vtkMatrix4x4::PointMultiply(const double Elements[16],
vtkMatrix4x4::MultiplyPoint(newElements, in, result);
}
//----------------------------------------------------------------------------
// Multiplies matrices a and b and stores the result in c.
void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
double c[16])
{
SqMatPtr aMat = (SqMatPtr)a;
SqMatPtr bMat = (SqMatPtr)b;
SqMatPtr cMat = (SqMatPtr)c;
double Accum[4][4];
for (int i = 0; i < 4; i++)
{
for (int k = 0; k < 4; k++)
{
Accum[i][k] = aMat[i][0] * bMat[0][k] +
aMat[i][1] * bMat[1][k] +
aMat[i][2] * bMat[2][k] +
aMat[i][3] * bMat[3][k];
}
}
// Copy to final dest
for (int i = 0; i < 4; i++)
{
cMat[i][0] = Accum[i][0];
cMat[i][1] = Accum[i][1];
cMat[i][2] = Accum[i][2];
cMat[i][3] = Accum[i][3];
}
}
//----------------------------------------------------------------------------
// Matrix Inversion (adapted from Richard Carling in "Graphics Gems,"
// Academic Press, 1990).
......
......@@ -27,6 +27,8 @@
#include "vtkCommonMathModule.h" // For export macro
#include "vtkObject.h"
#include <algorithm> // For std::copy
class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
{
// Some of the methods in here have a corresponding static (class)
......@@ -188,10 +190,41 @@ protected:
float FloatPoint[4];
double DoublePoint[4];
private:
// Useful for viewing a double[16] as a double[4][4]
typedef double (*SqMatPtr)[4];
typedef const double (*ConstSqMatPtr)[4];
vtkMatrix4x4(const vtkMatrix4x4&); // Not implemented
void operator= (const vtkMatrix4x4&); // Not implemented
};
//----------------------------------------------------------------------------
// Multiplies matrices a and b and stores the result in c.
inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
double c[16])
{
ConstSqMatPtr aMat = reinterpret_cast<ConstSqMatPtr>(a);
ConstSqMatPtr bMat = reinterpret_cast<ConstSqMatPtr>(b);
double tmp[16];
SqMatPtr cMat = reinterpret_cast<SqMatPtr>(tmp);
for (int i = 0; i < 4; i++)
{
for (int k = 0; k < 4; k++)
{
cMat[i][k] = aMat[i][0] * bMat[0][k] +
aMat[i][1] * bMat[1][k] +
aMat[i][2] * bMat[2][k] +
aMat[i][3] * bMat[3][k];
}
}
// Copy to final dest
std::copy(tmp, tmp + 16, c);
}
//----------------------------------------------------------------------------
inline void vtkMatrix4x4::SetElement(int i, int j, double value)
{
if (this->Element[i][j] != value)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment