DotWriter.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2021, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 
21 #include <gtsam/base/Vector.h>
22 #include <gtsam/inference/Symbol.h>
23 
24 #include <ostream>
25 
26 using namespace std;
27 
28 namespace gtsam {
29 
30 void DotWriter::graphPreamble(ostream* os) const {
31  *os << "graph {\n";
32  *os << " size=\"" << figureWidthInches << "," << figureHeightInches
33  << "\";\n\n";
34 }
35 
36 void DotWriter::digraphPreamble(ostream* os) const {
37  *os << "digraph {\n";
38  *os << " size=\"" << figureWidthInches << "," << figureHeightInches
39  << "\";\n\n";
40 }
41 
42 void DotWriter::drawVariable(Key key, const KeyFormatter& keyFormatter,
43  const std::optional<Vector2>& position,
44  ostream* os) const {
45  // Label the node with the label from the KeyFormatter
46  *os << " var" << key << "[label=\"" << keyFormatter(key)
47  << "\"";
48  if (position) {
49  *os << ", pos=\"" << position->x() << "," << position->y() << "!\"";
50  }
51  if (boxes.count(key)) {
52  *os << ", shape=box";
53  }
54  *os << "];\n";
55 }
56 
57 void DotWriter::DrawFactor(size_t i, const std::optional<Vector2>& position,
58  ostream* os) {
59  *os << " factor" << i << "[label=\"\", shape=point";
60  if (position) {
61  *os << ", pos=\"" << position->x() << "," << position->y() << "!\"";
62  }
63  *os << "];\n";
64 }
65 
67  const KeyFormatter& keyFormatter, ostream* os) {
68  *os << " var" << key1 << "--"
69  << "var" << key2 << ";\n";
70 }
71 
72 static void ConnectVariableFactor(Key key, const KeyFormatter& keyFormatter,
73  size_t i, ostream* os) {
74  *os << " var" << key << "--"
75  << "factor" << i << ";\n";
76 }
77 
79 std::optional<Vector2> DotWriter::variablePos(Key key) const {
80  std::optional<Vector2> result = {};
81 
82  // Check position hint
83  Symbol symbol(key);
84  auto hint = positionHints.find(symbol.chr());
85  if (hint != positionHints.end()) {
86  result = Vector2(symbol.index(), hint->second);
87  }
88 
89  // Override with explicit position, if given.
90  auto pos = variablePositions.find(key);
91  if (pos != variablePositions.end()) {
92  result = pos->second;
93  }
94 
95  return result;
96 }
97 
98 void DotWriter::processFactor(size_t i, const KeyVector& keys,
99  const KeyFormatter& keyFormatter,
100  const std::optional<Vector2>& position,
101  ostream* os) const {
102  if (plotFactorPoints) {
103  if (binaryEdges && keys.size() == 2) {
104  ConnectVariables(keys[0], keys[1], keyFormatter, os);
105  } else {
106  // Create dot for the factor.
107  if (!position && factorPositions.count(i))
108  DrawFactor(i, factorPositions.at(i), os);
109  else
110  DrawFactor(i, position, os);
111 
112  // Make factor-variable connections
113  if (connectKeysToFactor) {
114  for (Key key : keys) {
115  ConnectVariableFactor(key, keyFormatter, i, os);
116  }
117  }
118  }
119  } else {
120  // just connect variables in a clique
121  for (Key key1 : keys) {
122  for (Key key2 : keys) {
123  if (key2 > key1) {
124  ConnectVariables(key1, key2, keyFormatter, os);
125  }
126  }
127  }
128  }
129 }
130 
131 } // namespace gtsam
key1
const Symbol key1('v', 1)
DotWriter.h
Graphviz formatter.
Vector.h
typedef and functions to augment Eigen's VectorXd
gtsam::ConnectVariableFactor
static void ConnectVariableFactor(Key key, const KeyFormatter &keyFormatter, size_t i, ostream *os)
Definition: DotWriter.cpp:72
gtsam::Vector2
Eigen::Vector2d Vector2
Definition: Vector.h:42
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
os
ofstream os("timeSchurFactors.csv")
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
result
Values result
Definition: OdometryOptimize.cpp:8
key2
const Symbol key2('v', 2)
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
gtsam::symbol
Key symbol(unsigned char c, std::uint64_t j)
Definition: inference/Symbol.h:139
Symbol.h
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
std
Definition: BFloat16.h:88
gtsam::ConnectVariables
static void ConnectVariables(Key key1, Key key2, const KeyFormatter &keyFormatter, ostream *os)
Definition: DotWriter.cpp:66
gtsam::internal::position
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)
Definition: navigation/expressions.h:25
pos
Definition: example-NearestNeighbor.cpp:32
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::Symbol
Definition: inference/Symbol.h:37


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:14