| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file DummyFactor.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @date Sep 10, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam_unstable/slam/DummyFactor.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-09 04:08:54 +08:00
										 |  |  | #include <boost/assign/list_of.hpp>
 | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-09 04:08:54 +08:00
										 |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | DummyFactor::DummyFactor(const Key& key1, size_t dim1, const Key& key2, size_t dim2) | 
					
						
							| 
									
										
										
										
											2013-08-09 04:08:54 +08:00
										 |  |  | : NonlinearFactor(cref_list_of<2>(key1)(key2)) | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   dims_.push_back(dim1); | 
					
						
							|  |  |  |   dims_.push_back(dim2); | 
					
						
							|  |  |  |   if (dim1 > dim2) | 
					
						
							|  |  |  |     rowDim_ = dim1; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     rowDim_ = dim2; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void DummyFactor::print(const std::string& s, const KeyFormatter& keyFormatter) const { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   std::cout << s << "  DummyFactor dim = " << rowDim_ << ", keys = { "; | 
					
						
							|  |  |  |   BOOST_FOREACH(Key key, this->keys()) { std::cout << keyFormatter(key) << " "; } | 
					
						
							|  |  |  |   std::cout << "}" << std::endl; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | bool DummyFactor::equals(const NonlinearFactor& f, double tol) const { | 
					
						
							|  |  |  |   const DummyFactor* e = dynamic_cast<const DummyFactor*>(&f); | 
					
						
							|  |  |  |   return e && Base::equals(f, tol) && dims_ == e->dims_ && rowDim_ == e->rowDim_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2013-08-06 06:31:44 +08:00
										 |  |  | boost::shared_ptr<GaussianFactor> | 
					
						
							| 
									
										
										
										
											2013-08-09 04:08:54 +08:00
										 |  |  | DummyFactor::linearize(const Values& c) const { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // Only linearize if the factor is active
 | 
					
						
							|  |  |  |   if (!this->active(c)) | 
					
						
							| 
									
										
										
										
											2013-08-06 06:31:44 +08:00
										 |  |  |     return boost::shared_ptr<JacobianFactor>(); | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |    // Fill in terms with zero matrices
 | 
					
						
							| 
									
										
										
										
											2013-11-09 00:35:28 +08:00
										 |  |  |   std::vector<std::pair<Key, Matrix> > terms(this->size()); | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  |   for(size_t j=0; j<this->size(); ++j) { | 
					
						
							| 
									
										
										
										
											2013-08-09 04:08:54 +08:00
										 |  |  |     terms[j].first = keys()[j]; | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  |     terms[j].second = zeros(rowDim_, dims_[j]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   noiseModel::Diagonal::shared_ptr model = noiseModel::Unit::Create(rowDim_); | 
					
						
							| 
									
										
										
										
											2013-08-06 06:31:44 +08:00
										 |  |  |   return GaussianFactor::shared_ptr( | 
					
						
							|  |  |  |       new JacobianFactor(terms, zero(rowDim_), model)); | 
					
						
							| 
									
										
										
										
											2012-09-19 01:48:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace gtsam
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |