Skip to content

Commit 2123225

Browse files
committed
allow factorPositions
1 parent 34e9299 commit 2123225

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

gtsam/inference/BayesNet-inst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void BayesNet<CONDITIONAL>::dot(std::ostream& os,
4848
}
4949
os << "\n";
5050

51+
// Reverse order as typically Bayes nets stored in reverse topological sort.
5152
for (auto conditional : boost::adaptors::reverse(*this)) {
5253
auto frontals = conditional->frontals();
5354
const Key me = frontals.front();

gtsam/inference/DotWriter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ void DotWriter::processFactor(size_t i, const KeyVector& keys,
102102
ConnectVariables(keys[0], keys[1], keyFormatter, os);
103103
} else {
104104
// Create dot for the factor.
105-
DrawFactor(i, position, os);
105+
if (!position && factorPositions.count(i))
106+
DrawFactor(i, factorPositions.at(i), os);
107+
else
108+
DrawFactor(i, position, os);
106109

107110
// Make factor-variable connections
108111
if (connectKeysToFactor) {

gtsam/inference/DotWriter.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct GTSAM_EXPORT DotWriter {
4242

4343
/**
4444
* Variable positions can be optionally specified and will be included in the
45-
* dor file with a "!' sign, so "neato" can use it to render them.
45+
* dot file with a "!' sign, so "neato" can use it to render them.
4646
*/
4747
std::map<Key, Vector2> variablePositions;
4848

@@ -56,6 +56,12 @@ struct GTSAM_EXPORT DotWriter {
5656
/** A set of keys that will be displayed as a box */
5757
std::set<Key> boxes;
5858

59+
/**
60+
* Factor positions can be optionally specified and will be included in the
61+
* dot file with a "!' sign, so "neato" can use it to render them.
62+
*/
63+
std::map<size_t, Vector2> factorPositions;
64+
5965
explicit DotWriter(double figureWidthInches = 5,
6066
double figureHeightInches = 5,
6167
bool plotFactorPoints = true,

gtsam/inference/FactorGraph-inst.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ void FactorGraph<FACTOR>::dot(std::ostream& os,
135135

136136
// Create nodes for each variable in the graph
137137
for (Key key : keys()) {
138-
writer.drawVariable(key, keyFormatter, boost::none, &os);
138+
auto position = writer.variablePos(key);
139+
writer.drawVariable(key, keyFormatter, position, &os);
139140
}
140141
os << "\n";
141142

gtsam/nonlinear/GraphvizFormatting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ boost::optional<Vector2> GraphvizFormatting::extractPosition(
124124
boost::optional<Vector2> GraphvizFormatting::variablePos(const Values& values,
125125
const Vector2& min,
126126
Key key) const {
127-
if (!values.exists(key)) return boost::none;
127+
if (!values.exists(key)) return DotWriter::variablePos(key);
128128
boost::optional<Vector2> xy = extractPosition(values.at(key));
129129
if (xy) {
130130
xy->x() = scale * (xy->x() - min.x());

gtsam/nonlinear/GraphvizFormatting.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ struct GTSAM_EXPORT GraphvizFormatting : public DotWriter {
4141
bool mergeSimilarFactors; ///< Merge multiple factors that have the same
4242
///< connectivity
4343

44-
/// (optional for each factor) Manually specify factor "dot" positions:
45-
std::map<size_t, Vector2> factorPositions;
46-
4744
/// Default constructor sets up robot coordinates. Paper horizontal is robot
4845
/// Y, paper vertical is robot X. Default figure size of 5x5 in.
4946
GraphvizFormatting()

0 commit comments

Comments
 (0)