| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file DummyFactor.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @brief A simple factor that can be used to trick gtsam solvers into believing a graph is connected. | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  |  * @date Sep 10, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-18 14:22:41 +08:00
										 |  |  | #include <gtsam_unstable/dllexport.h>
 | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | #include <gtsam/nonlinear/NonlinearFactor.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 02:56:21 +08:00
										 |  |  | class GTSAM_UNSTABLE_EXPORT DummyFactor : public NonlinearFactor { | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Store the dimensions of the variables and the dimension of the full system
 | 
					
						
							|  |  |  |   std::vector<size_t> dims_; | 
					
						
							|  |  |  |   size_t rowDim_; ///< choose dimension for the rows
 | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Default constructor: don't use directly */ | 
					
						
							|  |  |  |   DummyFactor() : rowDim_(1) { } | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** standard binary constructor */ | 
					
						
							|  |  |  |   DummyFactor(const Key& key1, size_t dim1, const Key& key2, size_t dim2); | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 12:02:13 +08:00
										 |  |  |   ~DummyFactor() override {} | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // testable
 | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** print */ | 
					
						
							| 
									
										
										
										
											2020-07-26 15:57:54 +08:00
										 |  |  |   void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** Check if two factors are equal */ | 
					
						
							| 
									
										
										
										
											2020-07-26 15:57:54 +08:00
										 |  |  |   bool equals(const NonlinearFactor& f, double tol = 1e-9) const override; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // access
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const std::vector<size_t>& dims() const { return dims_; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // factor interface
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Calculate the error of the factor - zero for dummy factors | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-07-26 15:57:54 +08:00
										 |  |  |   double error(const Values& c) const override { return 0.0; } | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** get the dimension of the factor (number of rows on linearization) */ | 
					
						
							| 
									
										
										
										
											2020-07-26 15:57:54 +08:00
										 |  |  |   size_t dim() const override { return rowDim_; } | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** linearize to a GaussianFactor */ | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |   std::shared_ptr<GaussianFactor> linearize(const Values& c) const override; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Creates a shared_ptr clone of the factor - needs to be specialized to allow | 
					
						
							|  |  |  |    * for subclasses | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * By default, throws exception if subclass does not implement the function. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-07-26 15:57:54 +08:00
										 |  |  |   NonlinearFactor::shared_ptr clone() const override { | 
					
						
							| 
									
										
										
										
											2023-01-18 06:39:55 +08:00
										 |  |  |     return std::static_pointer_cast<NonlinearFactor>( | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |         NonlinearFactor::shared_ptr(new DummyFactor(*this))); | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |