Skip to content

Commit

Permalink
Port Tesseract_rviz
Browse files Browse the repository at this point in the history
This ports the TesseractState and TesseractTrajectory Widgets to work in ROS2
  • Loading branch information
mpowelson committed Mar 13, 2020
1 parent 367aae8 commit 59c57a3
Show file tree
Hide file tree
Showing 56 changed files with 1,062 additions and 939 deletions.
355 changes: 202 additions & 153 deletions tesseract_ros/tesseract_rviz/CMakeLists.txt

Large diffs are not rendered by default.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
#include <tesseract_rviz/interactive_marker/interactive_marker_control.h>
#endif

#include "rviz/selection/forwards.h"
#include "rviz/ogre_helpers/axes.h"
#include "rviz/properties/status_property.h"
#include "rviz_common/interaction/forwards.hpp"
#include "rviz_rendering/objects/axes.hpp"
#include "rviz_common/properties/status_property.hpp"

namespace Ogre
{
Expand All @@ -64,19 +64,19 @@ class InteractiveMarker : public QObject
{
Q_OBJECT
public:
using Ptr = boost::shared_ptr<InteractiveMarker>;
using ConstPtr = boost::shared_ptr<const InteractiveMarker>;
using SharedPtr = std::shared_ptr<InteractiveMarker>;
using ConstSharedPtr = std::shared_ptr<const InteractiveMarker>;

InteractiveMarker(const std::string& name,
const std::string& description,
const std::string& reference_frame,
Ogre::SceneNode* scene_node,
rviz::DisplayContext* context,
rviz_common::DisplayContext* context,
const bool reference_frame_locked,
const float scale = 1);
virtual ~InteractiveMarker();

InteractiveMarkerControl::Ptr createInteractiveControl(const std::string& name,
InteractiveMarkerControl::SharedPtr createInteractiveControl(const std::string& name,
const std::string& description,
const InteractiveMode interactive_mode,
const OrientationMode orientation_mode,
Expand Down Expand Up @@ -123,7 +123,7 @@ class InteractiveMarker : public QObject
void setShowVisualAids(bool show);

// @return true if the mouse event was intercepted, false if it was ignored
bool handleMouseEvent(rviz::ViewportMouseEvent& event, const std::string& control_name);
bool handleMouseEvent(rviz_common::ViewportMouseEvent& event, const std::string& control_name);

/**
* Supports selection and menu events from a 3D cursor.
Expand All @@ -135,7 +135,7 @@ class InteractiveMarker : public QObject
* @param control_name The name of the child InteractiveMarkerControl calling this function.
* @return true if the cursor event was intercepted, false if it was ignored
*/
bool handle3DCursorEvent(rviz::ViewportMouseEvent& event,
bool handle3DCursorEvent(rviz_common::ViewportMouseEvent& event,
const Ogre::Vector3& cursor_pos,
const Ogre::Quaternion& cursor_rot,
const std::string& control_name);
Expand All @@ -150,7 +150,7 @@ class InteractiveMarker : public QObject
* @param valid_point True if three_d_point is valid (e.g. if the mouse ray was successfully intersected with
* marker geometry).
*/
void showMenu(rviz::ViewportMouseEvent& event,
void showMenu(rviz_common::ViewportMouseEvent& event,
const std::string& control_name,
const Ogre::Vector3& three_d_point,
bool valid_point);
Expand All @@ -162,15 +162,15 @@ class InteractiveMarker : public QObject
bool hasMenu() { return has_menu_; }

/** @return A shared_ptr to the QMenu owned by this InteractiveMarker. */
boost::shared_ptr<QMenu> getMenu() { return menu_; }
std::shared_ptr<QMenu> getMenu() { return menu_; }

Q_SIGNALS:

void userFeedback(std::string reference_frame,
Eigen::Isometry3d transform,
Eigen::Vector3d mouse_point,
bool mouse_point_valid);
void statusUpdate(rviz::StatusProperty::Level level, const std::string& name, const std::string& text);
void statusUpdate(rviz_common::properties::StatusProperty::Level level, const std::string& name, const std::string& text);

protected Q_SLOTS:
void handleMenuSelect(int menu_item_id);
Expand Down Expand Up @@ -200,7 +200,7 @@ protected Q_SLOTS:
void updateVisualAidsVisibility();

bool visible_;
rviz::DisplayContext* context_;
rviz_common::DisplayContext* context_;

// pose of parent coordinate frame
std::string reference_frame_;
Expand All @@ -217,7 +217,7 @@ protected Q_SLOTS:
bool pose_changed_;
double time_since_last_feedback_;

std::map<std::string, InteractiveMarkerControl::Ptr> controls_;
std::map<std::string, InteractiveMarkerControl::SharedPtr> controls_;

std::string name_;
std::string description_;
Expand All @@ -231,7 +231,7 @@ protected Q_SLOTS:

float scale_;

boost::shared_ptr<QMenu> menu_;
std::shared_ptr<QMenu> menu_;
bool has_menu_;

// Helper to more simply represent the menu tree.
Expand All @@ -252,16 +252,16 @@ protected Q_SLOTS:

// visual aids

rviz::Axes* axes_;
rviz_rendering::Axes* axes_;

InteractiveMarkerControl::Ptr description_control_;
InteractiveMarkerControl::SharedPtr description_control_;

std::string topic_ns_;
std::string client_id_;

boost::recursive_mutex mutex_;

boost::shared_ptr<boost::thread> sys_thread_;
std::shared_ptr<boost::thread> sys_thread_;

bool got_3d_point_for_menu_;
Ogre::Vector3 three_d_point_for_menu_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@

#include <QCursor>

#include "rviz/selection/forwards.h"
#include "rviz/viewport_mouse_event.h"
#include "rviz/interactive_object.h"
#include "rviz_common/interaction/forwards.hpp"
#include "rviz_common/viewport_mouse_event.hpp"
#include "rviz_common/interactive_object.hpp"

namespace Ogre
{
Expand Down Expand Up @@ -94,16 +94,16 @@ enum class OrientationMode
* A single control element of an InteractiveMarker.
*/
class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
public rviz::InteractiveObject,
public rviz_common::InteractiveObject,
public boost::enable_shared_from_this<InteractiveMarkerControl>
{
public:
using Ptr = boost::shared_ptr<InteractiveMarkerControl>;
using ConstPtr = boost::shared_ptr<const InteractiveMarkerControl>;
using SharedPtr = std::shared_ptr<InteractiveMarkerControl>;
using ConstSharedPtr = std::shared_ptr<const InteractiveMarkerControl>;

InteractiveMarkerControl(const std::string& name,
const std::string& description,
rviz::DisplayContext* context,
rviz_common::DisplayContext* context,
Ogre::SceneNode* reference_node,
InteractiveMarker* parent,
const InteractiveMode interactive_mode,
Expand All @@ -123,13 +123,13 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
* @brief Add marker to the controller
* @param marker to add to the controller
*/
void addMarker(MarkerBase::Ptr marker);
void addMarker(MarkerBase::SharedPtr marker);

// called when interactive mode is globally switched on/off
virtual void enableInteraction(bool enable);

// will receive all mouse events while the handler has focus
virtual void handleMouseEvent(rviz::ViewportMouseEvent& event);
virtual void handleMouseEvent(rviz_common::ViewportMouseEvent& event);

/**
* This is the main entry-point for interaction using a 3D cursor.
Expand All @@ -156,7 +156,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
* @param cursor_rot The world-relative orientation of the 3D cursor.
* @param control_name The name of the child InteractiveMarkerControl calling this function.
*/
virtual void handle3DCursorEvent(rviz::ViewportMouseEvent event,
virtual void handle3DCursorEvent(rviz_common::ViewportMouseEvent event,
const Ogre::Vector3& cursor_3D_pos,
const Ogre::Quaternion& cursor_3D_orientation);

Expand Down Expand Up @@ -222,7 +222,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
* @brief Get the display context
* @return Display context
*/
rviz::DisplayContext* getDisplayContext() { return context_; }
rviz_common::DisplayContext* getDisplayContext() { return context_; }

/**
* @brief Get the size of the ineractive control
Expand Down Expand Up @@ -250,29 +250,29 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,

/** calculate a mouse ray in the reference frame.
* A mouse ray is a ray starting at the camera and pointing towards the mouse position. */
Ogre::Ray getMouseRayInReferenceFrame(const rviz::ViewportMouseEvent& event, int x, int y);
Ogre::Ray getMouseRayInReferenceFrame(const rviz_common::ViewportMouseEvent& event, int x, int y);

/** begin a relative-motion drag. */
void beginRelativeMouseMotion(const rviz::ViewportMouseEvent& event);
void beginRelativeMouseMotion(const rviz_common::ViewportMouseEvent& event);

/** get the relative motion of the mouse, and put the mouse back
* where it was when beginRelativeMouseMotion() was called. */
bool getRelativeMouseMotion(const rviz::ViewportMouseEvent& event, int& dx, int& dy);
bool getRelativeMouseMotion(const rviz_common::ViewportMouseEvent& event, int& dx, int& dy);

/** Rotate the pose around the camera-frame XY (right/up) axes, based on relative mouse movement. */
void rotateXYRelative(const rviz::ViewportMouseEvent& event);
void rotateXYRelative(const rviz_common::ViewportMouseEvent& event);

/** Rotate the pose around the camera-frame Z (look) axis, based on relative mouse movement. */
void rotateZRelative(const rviz::ViewportMouseEvent& event);
void rotateZRelative(const rviz_common::ViewportMouseEvent& event);

/** Move the pose along the mouse ray, based on relative mouse movement. */
void moveZAxisRelative(const rviz::ViewportMouseEvent& event);
void moveZAxisRelative(const rviz_common::ViewportMouseEvent& event);

/** Move the pose along the mouse ray, based on mouse wheel movement. */
void moveZAxisWheel(const rviz::ViewportMouseEvent& event);
void moveZAxisWheel(const rviz_common::ViewportMouseEvent& event);

/** Move the pose around the XY view plane (perpendicular to the camera direction). */
void moveViewPlane(Ogre::Ray& mouse_ray, const rviz::ViewportMouseEvent& event);
void moveViewPlane(Ogre::Ray& mouse_ray, const rviz_common::ViewportMouseEvent& event);

/** Rotate the pose around the local X-axis, following the mouse movement.
* mouse_ray is relative to the reference frame. */
Expand All @@ -297,7 +297,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,

/** Translate along the local X-axis, following the mouse movement.
* mouse_ray is relative to the reference frame. */
void moveAxis(const Ogre::Ray& mouse_ray, const rviz::ViewportMouseEvent& event);
void moveAxis(const Ogre::Ray& mouse_ray, const rviz_common::ViewportMouseEvent& event);

/** Translate along the local X-axis, following the 3D cursor movement. */
void moveAxis(const Ogre::Vector3& cursor_position_in_reference_frame);
Expand Down Expand Up @@ -346,16 +346,16 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
// Save a copy of the latest mouse event with the event type set to
// QEvent::MouseMove, so that update() can resend the mouse event during
// drag actions to maintain consistent behavior.
void recordDraggingInPlaceEvent(rviz::ViewportMouseEvent& event);
void recordDraggingInPlaceEvent(rviz_common::ViewportMouseEvent& event);

// Begin a new mouse motion. Called when left button is pressed to begin a drag.
void beginMouseMovement(rviz::ViewportMouseEvent& event, bool line_visible);
void beginMouseMovement(rviz_common::ViewportMouseEvent& event, bool line_visible);

// Motion part of mouse event handling.
void handleMouseMovement(rviz::ViewportMouseEvent& event);
void handleMouseMovement(rviz_common::ViewportMouseEvent& event);

// Mouse wheel part of mouse event handling.
void handleMouseWheelMovement(rviz::ViewportMouseEvent& event);
void handleMouseWheelMovement(rviz_common::ViewportMouseEvent& event);

// Return closest point on a line to a test point.
Ogre::Vector3 closestPointOnLineToPoint(const Ogre::Vector3& line_start,
Expand All @@ -369,11 +369,11 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
bool mouse_dragging_;
Ogre::Viewport* drag_viewport_;

rviz::ViewportMouseEvent dragging_in_place_event_;
rviz_common::ViewportMouseEvent dragging_in_place_event_;

rviz::DisplayContext* context_;
rviz_common::DisplayContext* context_;

rviz::CollObjectHandle coll_object_handle_;
rviz_common::CollObjectHandle coll_object_handle_;

/** Node representing reference frame in tf, like /map, /base_link,
* /head, etc. Same as the field in InteractiveMarker. */
Expand Down Expand Up @@ -411,7 +411,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,

std::string name_;

std::vector<boost::shared_ptr<MarkerBase>> markers_;
std::vector<std::shared_ptr<MarkerBase>> markers_;

InteractiveMarker* parent_;

Expand All @@ -420,7 +420,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,
// // PointsMarkers are rendered by special shader programs, so the
// // regular highlighting method does not work for them. Keep a
// // vector of them so we can call their setHighlightColor() function.
// typedef boost::shared_ptr<PointsMarker> PointsMarkerPtr;
// typedef std::shared_ptr<PointsMarker> PointsMarkerPtr;
// std::vector< PointsMarkerPtr > points_markers_;

/** Stores the rotation around the x axis of the control. Only
Expand Down Expand Up @@ -503,7 +503,7 @@ class InteractiveMarkerControl : public Ogre::SceneManager::Listener,

bool mouse_down_;

// boost::shared_ptr<Line> line_;
// std::shared_ptr<Line> line_;

bool show_visual_aids_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,30 @@ namespace Ogre
class SceneNode;
}

namespace rviz
namespace rviz_common
{
class Arrow;
class DisplayContext;
} // namespace rviz

namespace rviz_rendering {
class Arrow;
}

namespace tesseract_rviz
{
class ArrowMarker : public MarkerBase
{
public:
using Ptr = boost::shared_ptr<ArrowMarker>;
using ConstPtr = boost::shared_ptr<const ArrowMarker>;
using SharedPtr = std::shared_ptr<ArrowMarker>;
using ConstSharedPtr = std::shared_ptr<const ArrowMarker>;

ArrowMarker(const std::string& ns, const int id, rviz::DisplayContext* context, Ogre::SceneNode* parent_node);
ArrowMarker(const std::string& ns, const int id, rviz_common::DisplayContext* context, Ogre::SceneNode* parent_node);

ArrowMarker(const std::string& ns,
const int id,
Ogre::Vector3 point1,
Ogre::Vector3 point2,
rviz::DisplayContext* context,
rviz_common::DisplayContext* context,
Ogre::SceneNode* parent_node);

~ArrowMarker() override;
Expand All @@ -74,7 +77,7 @@ class ArrowMarker : public MarkerBase
protected:
virtual void setDefaultProportions();

rviz::Arrow* arrow_;
rviz_rendering::Arrow* arrow_;
Ogre::SceneNode* child_scene_node_;
Ogre::Vector3 location_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <string>
#endif

namespace rviz
namespace rviz_rendering
{
class Shape;
}
Expand All @@ -42,12 +42,12 @@ namespace tesseract_rviz
class CubeMarker : public MarkerBase
{
public:
using Ptr = boost::shared_ptr<CubeMarker>;
using ConstPtr = boost::shared_ptr<const CubeMarker>;
using SharedPtr = std::shared_ptr<CubeMarker>;
using ConstSharedPtr = std::shared_ptr<const CubeMarker>;

CubeMarker(const std::string& ns,
const int id,
rviz::DisplayContext* context,
rviz_common::DisplayContext* context,
Ogre::SceneNode* parent_node,
float size = 1);
~CubeMarker() override;
Expand All @@ -63,7 +63,7 @@ class CubeMarker : public MarkerBase
std::set<Ogre::MaterialPtr> getMaterials() override;

protected:
rviz::Shape* shape_;
rviz_rendering::Shape* shape_;
Ogre::Vector3 scale_;
float size_;
};
Expand Down
Loading

0 comments on commit 59c57a3

Please sign in to comment.