Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions src/pyhpp_plot/graph_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ namespace {

using GraphPtr_t = hpp::manipulation::graph::GraphPtr_t;

// Custom message handler to suppress Qt debug messages
void quietMessageHandler(QtMsgType type, const QMessageLogContext& context,
const QString& msg) {
if (type == QtDebugMsg) {
return; // Suppress debug messages
}
// For other message types, use default behavior
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtInfoMsg:
fprintf(stderr, "%s\n", localMsg.constData());
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", localMsg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", localMsg.constData());
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", localMsg.constData());
abort();
}
}

static const char* GRAPH_CAPSULE_NAME = "hpp.manipulation.graph.GraphPtr";

/// Extract GraphPtr_t from a Python object
Expand Down Expand Up @@ -137,6 +161,9 @@ void showGraphBlocking(bp::object py_graph) {
throw std::runtime_error("Graph is null");
}

// Suppress Qt debug output
qInstallMessageHandler(quietMessageHandler);

int argc = 1;
static char app_name[] = "hpp-plot-native";
char* argv[] = {app_name, nullptr};
Expand Down Expand Up @@ -172,6 +199,9 @@ void showInteractiveGraph(bp::object py_graph, bp::object node_callback,
throw std::runtime_error("Graph is null");
}

// Suppress Qt debug output
qInstallMessageHandler(quietMessageHandler);

int argc = 1;
static char app_name[] = "hpp-plot-interactive";
char* argv[] = {app_name, nullptr};
Expand Down
68 changes: 13 additions & 55 deletions src/pyhpp_plot/interactive_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,12 @@ def _generate_random_config(self, state_name):
self.config_callback(
q_proj, f"Random config in state: {state_name}"
)
print(f"Generated config for state '{state_name}'")
return

if error < min_error:
min_error = error

print(
f"Failed to generate config for state '{state_name}' "
f"after 20 attempts (min error: {min_error:.6f})"
)
except Exception as e:
print(f"Error generating random config: {e}")
import traceback

traceback.print_exc()
except Exception:
pass

def _generate_from_current_config(self, state_name):
"""Project current config to state.
Expand All @@ -123,11 +114,10 @@ def _generate_from_current_config(self, state_name):
"""
try:
if self.current_config is None:
print("No current config available. Generate a config first.")
return

state = self.graph.getState(state_name)
success, q_proj, error = self.graph.applyStateConstraints(
success, q_proj, _error = self.graph.applyStateConstraints(
state, self.current_config
)

Expand All @@ -136,17 +126,8 @@ def _generate_from_current_config(self, state_name):
self.config_callback(
q_proj, f"Current config projected to state: {state_name}"
)
print(f"Projected current config to state '{state_name}'")
else:
print(
f"Failed to project current config to state "
f"'{state_name}' (error: {error:.6f})"
)
except Exception as e:
print(f"Error projecting current config: {e}")
import traceback

traceback.print_exc()
except Exception:
pass

def _set_target_state(self, state_name):
"""Set state as goal for planning.
Expand All @@ -166,15 +147,9 @@ def _set_target_state(self, state_name):

if success:
self.problem.addGoalConfig(q_goal)
print(f"Added goal config in state '{state_name}'")
return

print(f"Failed to generate goal config for state '{state_name}'")
except Exception as e:
print(f"Error setting target state: {e}")
import traceback

traceback.print_exc()
except Exception:
pass

def _extend_current_to_current(self, edge_name):
"""Generate target config along edge from current config.
Expand All @@ -185,25 +160,18 @@ def _extend_current_to_current(self, edge_name):
"""
try:
if self.current_config is None:
print("No current config available. Generate a config first.")
return

edge = self.graph.getTransition(edge_name)
success, q_out, error = self.graph.generateTargetConfig(
success, q_out, _error = self.graph.generateTargetConfig(
edge, self.current_config, self.current_config
)

if success:
self.current_config = q_out
self.config_callback(q_out, f"Extended along edge: {edge_name}")
print(f"Extended current config along edge '{edge_name}'")
else:
print(f"Failed to extend along edge '{edge_name}' (error: {error:.6f})")
except Exception as e:
print(f"Error extending current config: {e}")
import traceback

traceback.print_exc()
except Exception:
pass

def _extend_current_to_random(self, edge_name):
"""Generate target config along edge to random config.
Expand All @@ -214,14 +182,13 @@ def _extend_current_to_random(self, edge_name):
"""
try:
if self.current_config is None:
print("No current config available. Generate a config first.")
return

edge = self.graph.getTransition(edge_name)
shooter = self.problem.configurationShooter()
q_random = shooter.shoot()

success, q_out, error = self.graph.generateTargetConfig(
success, q_out, _error = self.graph.generateTargetConfig(
edge, self.current_config, q_random
)

Expand All @@ -230,17 +197,8 @@ def _extend_current_to_random(self, edge_name):
self.config_callback(
q_out, f"Extended along edge to random: {edge_name}"
)
print(f"Extended to random config along edge '{edge_name}'")
else:
print(
f"Failed to extend to random along edge '{edge_name}' "
f"(error: {error:.6f})"
)
except Exception as e:
print(f"Error extending to random config: {e}")
import traceback

traceback.print_exc()
except Exception:
pass


class GraphViewerThread(threading.Thread):
Expand Down