MCPcopy Create free account
hub / github.com/TUC-ProAut/libRSF / addFactorGeneric

Method addFactorGeneric

include/FactorGraph.h:308–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306 /** add and remove factors */
307 template <typename ErrorType, typename FactorClass, typename... FactorParameters>
308 void addFactorGeneric (ErrorType &NoiseModel,
309 const std::vector<StateID> &StateList,
310 const FactorType FactorTypeEnum,
311 ceres::LossFunction* RobustLoss,
312 const bool DoPrediction,
313 const double Timestamp,
314 FactorParameters... Params)
315 {
316 /** build list of states */
317 std::vector<double*> StatePointers;
318 for (const StateID &State : StateList)
319 {
320 StatePointers.emplace_back(_StateData.getElement(State.ID , State.Timestamp, State.Number).getMeanPointer());
321 }
322
323 /** create factor object */
324 FactorClass* Factor = new FactorClass(NoiseModel, Params...);
325
326 /** use the factor to predict */
327 if (DoPrediction)
328 {
329 Factor->predict(StatePointers);
330 }
331
332 /** wrap it in ceres cost function */
333 auto CostFunction = makeAutoDiffCostFunction<ErrorType::OutputDim, FactorClass> (Factor,
334 typename FactorClass::StateDims{},
335 typename ErrorType::StateDims{});
336
337 /** add it to the estimation problem */
338 ceres::ResidualBlockId CurrentCeresFactorID = _Graph.AddResidualBlock(CostFunction,
339 RobustLoss,
340 StatePointers);
341
342 /** store state types */
343 std::vector<DataType> StateTypes;
344 for(const StateID &State : StateList)
345 {
346 StateTypes.emplace_back(_StateData.getElement(State.ID , State.Timestamp, State.Number).getType());
347 }
348
349 /** store the graphs structure */
350 _Structure.addFactor<ErrorType>(FactorTypeEnum,
351 Timestamp,
352 CurrentCeresFactorID,
353 Factor->getErrorModel(),
354 StateList,
355 StatePointers,
356 StateTypes);
357 }
358
359 template <FactorType CurrentFactorType, typename ErrorType>
360 void addFactorBase(StateList &States, ErrorType &NoiseModel, const Data &Measurement, ceres::LossFunction* RobustLoss, const bool DoPrediction)

Callers

nothing calls this directly

Calls 5

getMeanPointerMethod · 0.80
getElementMethod · 0.80
predictMethod · 0.45
getTypeMethod · 0.45
getErrorModelMethod · 0.45

Tested by

no test coverage detected