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

Method getMarginalizationInfo

src/FactorGraphStructure.cpp:30–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 {}
29
30 void FactorGraphStructure::getMarginalizationInfo(const std::vector<double*> &BaseStates,
31 std::vector<double*> &ConnectedStates,
32 std::vector<ceres::ResidualBlockId> &ConnectedFactors,
33 std::vector<int> &StateDims,
34 std::vector<int> &StateDimsLocal,
35 std::vector<StateID> &StateIDs,
36 std::vector<DataType> &StateTypes) const
37 {
38 /** sets to store unique values */
39 std::set<double*> BaseStatePointers;
40 std::set<ceres::ResidualBlockId> ConnectedFactorsIDs;
41
42 /** get all connected factors */
43 for (double* const State : BaseStates)
44 {
45 /** safety check */
46 if(_Graph->HasParameterBlock(State) == false)
47 {
48 PRINT_ERROR("State is not part of graph!");
49 return;
50 }
51
52 /** store pointer for check */
53 if(BaseStatePointers.count(State) != 0)
54 {
55 PRINT_ERROR("Duplicated pointer for marginalized states!");
56 return;
57 }
58 BaseStatePointers.emplace(State);
59
60 /** query residual IDs */
61 std::vector<ceres::ResidualBlockId> Factors;
62 _Graph->GetResidualBlocksForParameterBlock(State, &Factors);
63 for(ceres::ResidualBlockId Factor : Factors)
64 {
65 /** add only new factors */
66 if(ConnectedFactorsIDs.count(Factor) == 0)
67 {
68 ConnectedFactorsIDs.emplace(Factor);
69 }
70 }
71 }
72
73 /** get all connected states */
74 std::set<double*> ConnectedStatePointers;
75 for (const ceres::ResidualBlockId Factor : ConnectedFactorsIDs)
76 {
77 std::vector<double*> CurrentStatePointers;
78
79 /** query states that are connected with a certain factor */
80 _Graph->GetParameterBlocksForResidualBlock(Factor, &CurrentStatePointers);
81
82 /** add only unique states */
83 for (double* StatePointer : CurrentStatePointers)
84 {
85 if(ConnectedStatePointers.count(StatePointer) == 0 && BaseStatePointers.count(StatePointer) == 0)
86 {
87 ConnectedStatePointers.emplace(StatePointer);

Callers 1

marginalizeStatesMethod · 0.80

Calls 2

countMethod · 0.80
emplaceMethod · 0.80

Tested by

no test coverage detected