diff --git a/vcg/math/shot.h b/vcg/math/shot.h index 96631e4c..4d6fe39d 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -186,12 +186,20 @@ public: /// convert a 3d point from camera to world coordinates vcg::Point3 ConvertCameraToWorldCoordinates(const vcg::Point3 & p) const; + /// convert a 3d point from camera to world coordinates, uses inverse instead of trranspose + /// for non-exactly-rigid rotation matrices (such as calculated by tsai and garcia) + vcg::Point3 ConvertCameraToWorldCoordinates_Substitute(const vcg::Point3 & p) const; + /// project a 3d point from world coordinates to 2d camera viewport (pixel) vcg::Point2 Project(const vcg::Point3 & p) const; /// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates vcg::Point3 UnProject(const vcg::Point2 & p, const S & d) const; + /// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates, uses inverse instead of trranspose + /// for non-exactly-rigid rotation matrices (such as calculated by tsai and garcia) + vcg::Point3 UnProject_Substitute(const vcg::Point2 & p, const S & d) const; + /// returns distance of point p from camera plane (z depth), used for unprojection S Depth(const vcg::Point3 & p)const; @@ -324,6 +332,19 @@ vcg::Point3 Shot::ConvertCameraToWorldCoordinates(const vcg:: return cp; } +/// convert a 3d point from camera to world coordinates, uses inverse instead of trranspose +/// for non-exactly-rigid rotation matrices (such as calculated by tsai and garcia) +template +vcg::Point3 Shot::ConvertCameraToWorldCoordinates_Substitute(const vcg::Point3 & p) const +{ + Matrix44 rotM; + vcg::Point3 cp = p; + cp[2]=-cp[2]; // note: World reference system is left handed + Extrinsics.rot.ToMatrix(rotM); + cp = Inverse(rotM) * cp + GetViewPoint(); // use invert istead of transpose to dela with non-rigid cases + return cp; +} + /// project a 3d point from world coordinates to 2d camera viewport (pixel) template vcg::Point2 Shot::Project(const vcg::Point3 & p) const @@ -344,6 +365,17 @@ vcg::Point3 Shot::UnProject(const vcg::Point2 & p, const S return wp; } +/// inverse projection from 2d camera viewport (pixel) + Zdepth to 3d world coordinates, uses inverse instead of trranspose +/// for non-exactly-rigid rotation matrices (such as calculated by tsai and garcia) +template +vcg::Point3 Shot::UnProject_Substitute(const vcg::Point2 & p, const S & d) const +{ + Point2 lp = Intrinsics.ViewportPxToLocal(p); + Point3 cp = Intrinsics.UnProject(lp,d); + Point3 wp = ConvertCameraToWorldCoordinates_Substitute(cp); + return wp; +} + /// returns distance of point p from camera plane (z depth), used for unprojection template S Shot::Depth(const vcg::Point3 & p)const