Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General check for null pointer in saveGraph #503

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions gtsam/nonlinear/NonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,42 +205,49 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
// Create factors and variable connections
for(size_t i = 0; i < size(); ++i) {
const NonlinearFactor::shared_ptr& factor = at(i);
if(formatting.plotFactorPoints) {
// If null pointer, move on to the next
if (!factor) {
continue;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is the main fix.

if (formatting.plotFactorPoints) {
const KeyVector& keys = factor->keys();
if (formatting.binaryEdges && keys.size()==2) {
stm << " var" << keys[0] << "--" << "var" << keys[1] << ";\n";
if (formatting.binaryEdges && keys.size() == 2) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting changes

stm << " var" << keys[0] << "--"
<< "var" << keys[1] << ";\n";
} else {
// Make each factor a dot
stm << " factor" << i << "[label=\"\", shape=point";
{
map<size_t, Point2>::const_iterator pos = formatting.factorPositions.find(i);
if(pos != formatting.factorPositions.end())
stm << ", pos=\"" << formatting.scale*(pos->second.x() - minX) << ","
<< formatting.scale*(pos->second.y() - minY) << "!\"";
map<size_t, Point2>::const_iterator pos =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting changes.

formatting.factorPositions.find(i);
if (pos != formatting.factorPositions.end())
stm << ", pos=\"" << formatting.scale * (pos->second.x() - minX)
<< "," << formatting.scale * (pos->second.y() - minY)
<< "!\"";
}
stm << "];\n";

// Make factor-variable connections
if(formatting.connectKeysToFactor && factor) {
for(Key key: *factor) {
stm << " var" << key << "--" << "factor" << i << ";\n";
if (formatting.connectKeysToFactor && factor) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just formatting.

for (Key key : *factor) {
stm << " var" << key << "--"
<< "factor" << i << ";\n";
}
}
}
}
else {
if(factor) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this check since I added a generic check at the beginning.

Key k;
bool firstTime = true;
for(Key key: *this->at(i)) {
if(firstTime) {
k = key;
firstTime = false;
continue;
}
stm << " var" << key << "--" << "var" << k << ";\n";
} else {
Key k;
bool firstTime = true;
for (Key key : *this->at(i)) {
if (firstTime) {
k = key;
firstTime = false;
continue;
}
stm << " var" << key << "--"
<< "var" << k << ";\n";
k = key;
}
}
}
Expand Down