| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SimpleCamera.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Aug 16, 2009 | 
					
						
							|  |  |  |  *      Author: dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/geometry/SimpleCamera.h>
 | 
					
						
							|  |  |  | #include <gtsam/geometry/CalibratedCamera.h>
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 	SimpleCamera::SimpleCamera(const Cal3_S2& K, | 
					
						
							|  |  |  | 			const CalibratedCamera& calibrated) : | 
					
						
							|  |  |  | 		calibrated_(calibrated), K_(K) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	SimpleCamera::SimpleCamera(const Cal3_S2& K, const Pose3& pose) : | 
					
						
							|  |  |  | 		calibrated_(pose), K_(K) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SimpleCamera::~SimpleCamera() { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 	pair<Point2, bool> SimpleCamera::projectSafe(const Point3& P) const { | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 		Point3 cameraPoint = calibrated_.pose().transform_to(P); | 
					
						
							|  |  |  | 		Point2 intrinsic = CalibratedCamera::project_to_camera(cameraPoint); | 
					
						
							|  |  |  | 		Point2 projection = K_.uncalibrate(intrinsic); | 
					
						
							| 
									
										
										
										
											2009-09-14 00:09:54 +08:00
										 |  |  | 		return pair<Point2, bool>(projection, cameraPoint.z() > 0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 	Point2 SimpleCamera::project(const Point3& point, | 
					
						
							|  |  |  | 		    boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point2 intrinsic = calibrated_.project(point, H1, H2); | 
					
						
							|  |  |  | 		if (!H1 && !H2) | 
					
						
							|  |  |  | 			return K_.uncalibrate(intrinsic); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Matrix D_projection_intrinsic; | 
					
						
							|  |  |  | 		Point2 projection = K_.uncalibrate(intrinsic, boost::none, D_projection_intrinsic); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (H1) { | 
					
						
							|  |  |  | 			*H1 = D_projection_intrinsic * (*H1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (H2) { | 
					
						
							|  |  |  | 			*H2 = D_projection_intrinsic * (*H2); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return projection; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-19 16:32:55 +08:00
										 |  |  | 	Point3 SimpleCamera::backproject(const Point2& projection, const double scale) const { | 
					
						
							|  |  |  | 		Point2 intrinsic = K_.calibrate(projection); | 
					
						
							| 
									
										
										
										
											2010-08-23 05:45:53 +08:00
										 |  |  | 		Point3 cameraPoint = CalibratedCamera::backproject_from_camera(intrinsic, scale); | 
					
						
							|  |  |  | 		return calibrated_.pose().transform_from(cameraPoint); | 
					
						
							| 
									
										
										
										
											2010-03-19 16:32:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-29 15:39:20 +08:00
										 |  |  | 	SimpleCamera SimpleCamera::level(const Cal3_S2& K, const Pose2& pose2, double height) { | 
					
						
							| 
									
										
										
										
											2009-08-29 14:54:10 +08:00
										 |  |  | 		return SimpleCamera(K, CalibratedCamera::level(pose2, height)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | } |