_linearTransform[3*j + i] = (pts[i+1])[j] - (pts[0])[j];
}
}
+
+ // remember _linearTransform for the reverse transformation
+ memcpy( _backLinearTransform, _linearTransform, 9*sizeof(double));
calculateDeterminant();
}
}
+ /**
+ * Calculates the reverse transform of point srcPt and stores the result in destPt.
+ * If destPt == srcPt, then srcPt is overwritten safely.
+ *
+ * @param destPt double[3] in which to store the transformed point
+ * @param srcPt double[3] containing coordinates of points to be transformed
+ */
+ void TetraAffineTransform::reverseApply(double* destPt, const double* srcPt) const
+ {
+ double* dest = destPt;
+
+ // are we self-allocating ?
+ const bool selfAllocation = (destPt == srcPt);
+
+ if(selfAllocation)
+ {
+ // alloc temporary memory
+ dest = new double[3];
+
+ LOG(6, "Info : Self-affectation in TetraAffineTransform::reverseApply");
+ }
+
+ for(int i = 0 ; i < 3 ; ++i)
+ {
+ // matrix - vector multiplication
+ dest[i] = _backLinearTransform[3*i] * srcPt[0] + _backLinearTransform[3*i + 1] * srcPt[1] + _backLinearTransform[3*i + 2] * srcPt[2];
+
+ // translation
+ dest[i] -= _translation[i];
+ }
+
+ if(selfAllocation)
+ {
+ // copy result back to destPt
+ for(int i = 0 ; i < 3 ; ++i)
+ {
+ destPt[i] = dest[i];
+ }
+ delete[] dest;
+ }
+ }
+
/**
* Returns the determinant of the linear part A of the transform.
*
void apply(double* destPt, const double* srcPt) const;
+ void reverseApply(double* destPt, const double* srcPt) const;
+
double determinant() const;
void dump() const;
/// The determinant of the matrix A is calculated at the construction of the object and cached.
double _determinant;
+ /// 3x3 matrix AT is transposed A matrix used for y -> AT(y - b) transformation
+ double _backLinearTransform[9];
};