From 2a450c7c463bef59dc4fab8260b7008175cd2fca Mon Sep 17 00:00:00 2001 From: maxcorsini Date: Tue, 24 May 2011 21:13:05 +0000 Subject: [PATCH] add ApplySimilarity - version with vcg::Similarity is unfinished --- vcg/math/shot.h | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/vcg/math/shot.h b/vcg/math/shot.h index cfc9b191..b8498281 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -203,9 +203,15 @@ public: */ void RescalingWorld(S scalefactor); - /// Given a pure roto-translation (4-by-4) modify the reference frame accordingly. + /// Given a pure roto-translation (4-by-4) modifies the reference frame accordingly. void ApplyRigidTransformation(const Matrix44 & M); + /// Given a similarity transformation such that p' = s R p + T modifies the reference frame accordingly. + void ApplySimilarity(const Matrix44 & M); + + /// Given a similarity transformation such that p' = s R p + T modifies the reference frame accordingly. + void ApplySimilarity(const Similarity & S); + /// convert a 3d point from world to camera coordinates (do not confuse with the Shot reference frame) vcg::Point3 ConvertWorldToCameraCoordinates(const vcg::Point3 & p) const; @@ -469,7 +475,6 @@ void Shot::RescalingWorld(S scalefactor) template void Shot::ApplyRigidTransformation(const Matrix44 & M) { - Matrix44 currentM; Matrix44 rotM; Extrinsics.rot.ToMatrix(rotM); @@ -483,6 +488,38 @@ void Shot::ApplyRigidTransformation(const Matrix44 & M) Extrinsics.rot.ElementAt(3,2) = 0; } +/// Given a similarity transformation such that p' = s R p + T modifies the reference frame accordingly. +template +void Shot::ApplySimilarity(const Matrix44 & M) +{ + Matrix44 rotM; + Extrinsics.rot.ToMatrix(rotM); + + // obtain scale factor + Point3 p = M.GetRow3(0); + ScalarType scalefactor = 1.0 / p.Norm(); + + // roto-translate the viewpoint + Extrinsics.tra = M * Extrinsics.tra; + + vcg::Matrix44 M2 = M; + + M2 = M2 * scalefactor; + + Extrinsics.rot = rotM * M2.transpose(); + + Extrinsics.rot.ElementAt(3,0) = 0; + Extrinsics.rot.ElementAt(3,1) = 0; + Extrinsics.rot.ElementAt(3,2) = 0; +} + +/// Given a similarity transformation such that p' = s R p + T modifies the reference frame accordingly. +template +void Shot::ApplySimilarity(const Similarity & S) +{ + //...TODO... +} + //--------------------------------