frame_view_controller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Bielefeld University
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Bielefeld University nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "frame_view_controller.h"
31 #include <rviz/display_context.h>
37 
38 #include <OgreViewport.h>
39 #include <OgreCamera.h>
40 #include <OgreSceneNode.h>
41 #include <Eigen/Geometry>
42 #include <QSignalBlocker>
43 
44 namespace rviz
45 {
46 static const QString ANY_AXIS("arbitrary");
47 
48 // helper function to create axis strings from option ID
49 inline QString fmtAxis(int i)
50 {
51  return QString("%1%2 axis").arg(QChar(i % 2 ? '+' : '-')).arg(QChar('x' + (i - 1) / 2));
52 }
53 
55 {
56  axis_property_ = new EnumProperty("Point towards", fmtAxis(6),
57  "Point the camera along the given axis of the frame.", nullptr,
61  // x,y,z axes get integers from 1..6: +x, -x, +y, -y, +z, -z
62  for (int i = 1; i <= 6; ++i)
65 
66  locked_property_ = new BoolProperty("Lock Camera", false,
67  "Lock camera in its current pose relative to the frame", this);
68 }
69 
71 {
73  changedAxis();
74 }
75 
77 {
78  camera_->setPosition(Ogre::Vector3::ZERO);
79  Eigen::Vector3d axis(0, 0, 0);
80  int option = previous_axis_;
81  if (option >= 1 && option <= 6)
82  {
83  axis[(option - 1) / 2] = (option % 2) ? +1 : -1;
84  Eigen::Quaterniond q = Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d::UnitX(), axis);
85  camera_->setOrientation(Ogre::Quaternion(q.w(), q.x(), q.y(), q.z()) * ROBOT_TO_CAMERA_ROTATION);
86  }
88 }
89 
91 {
93  {
94  setStatus("Unlock camera in settings to enable mouse interaction.");
95  return;
96  }
98 }
99 
101 {
102  // compare current camera direction with unit axes
103  Ogre::Vector3 actual =
104  (camera_->getOrientation() * ROBOT_TO_CAMERA_ROTATION.Inverse()) * Ogre::Vector3::UNIT_X;
105  for (unsigned int i = 0; i < 3; ++i)
106  {
107  Ogre::Vector3 axis(0, 0, 0);
108  axis[i] = 1.0;
109  auto scalar_product = axis.dotProduct(actual);
110  if (std::abs(scalar_product) > 1.0 - precision)
111  return 1 + 2 * i + (scalar_product > 0 ? 0 : 1);
112  }
113  return -1;
114 }
115 
117 {
118  int actual = actualCameraAxisOption();
119  if (axis_property_->getOptionInt() == actual) // no change?
120  return;
121 
122  QSignalBlocker block(axis_property_);
123  axis_property_->setString(actual == -1 ? ANY_AXIS : fmtAxis(actual));
124  rememberAxis(actual);
125 }
126 
128 {
131 }
132 
134 {
136  reset();
137 }
138 
139 inline void FrameViewController::rememberAxis(int current)
140 {
141  if (current >= 1) // remember previous axis selection
142  previous_axis_ = current;
143 }
144 
145 void FrameViewController::onTargetFrameChanged(const Ogre::Vector3& /* old_reference_position */,
146  const Ogre::Quaternion& /* old_reference_orientation */)
147 {
148  // don't adapt the camera pose to the old reference position, but just jump to new frame
149 }
150 
152 {
153  if (getNewTransform())
154  {
155  // track both, position and orientation of reference frame
159  }
160 }
161 
162 } // end namespace rviz
163 
rviz::FramePositionTrackingViewController::reference_position_
Ogre::Vector3 reference_position_
Definition: frame_position_tracking_view_controller.h:101
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition: bool_property.cpp:48
rviz::EnumProperty::getOptionInt
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
Definition: enum_property.cpp:56
rviz::FrameViewController::updateTargetSceneNode
void updateTargetSceneNode() override
Update the position of the target_scene_node_ from the TF frame specified in the Target Frame propert...
Definition: frame_view_controller.cpp:151
rviz::DisplayContext::queueRender
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
rviz::FrameViewController::setAxisFromCamera
void setAxisFromCamera()
set axis_property_ from camera
Definition: frame_view_controller.cpp:116
rviz::FrameViewController::locked_property_
BoolProperty * locked_property_
Lock camera, i.e. disable mouse interaction?
Definition: frame_view_controller.h:65
rviz::EnumProperty::setString
virtual void setString(const QString &str)
Set the value of this property to the given string. Does not force the value to be one of the list of...
Definition: enum_property.cpp:82
rviz::FrameViewController::handleMouseEvent
void handleMouseEvent(ViewportMouseEvent &event) override
Definition: frame_view_controller.cpp:90
rviz::FrameViewController::FrameViewController
FrameViewController()
Definition: frame_view_controller.cpp:54
rviz::FPSViewController::setPropertiesFromCamera
void setPropertiesFromCamera()
set yaw, pitch, roll, position properties from camera
Definition: fps_view_controller.cpp:169
rviz::BoolProperty
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
rviz::ViewportMouseEvent
Definition: viewport_mouse_event.h:45
rviz::Property::addChild
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:356
viewport_mouse_event.h
float_property.h
bool_property.h
rviz::FPSViewController::ROBOT_TO_CAMERA_ROTATION
static const Ogre::Quaternion ROBOT_TO_CAMERA_ROTATION
Definition: fps_view_controller.h:69
rviz::FPSViewController::yaw_property_
FloatProperty * yaw_property_
The camera's yaw (rotation around the z-axis), in radians.
Definition: fps_view_controller.h:71
rviz::ViewController::context_
DisplayContext * context_
Definition: view_controller.h:225
rviz::EnumProperty
Enum property.
Definition: enum_property.h:46
rviz::FrameViewController::axis_property_
EnumProperty * axis_property_
The axis that the camera aligns to.
Definition: frame_view_controller.h:64
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FPSViewController::onInitialize
void onInitialize() override
Do subclass-specific initialization. Called by ViewController::initialize after context_ and camera_ ...
Definition: fps_view_controller.cpp:73
rviz::EnumProperty::addOption
virtual void addOption(const QString &option, int value=0)
Definition: enum_property.cpp:50
rviz
Definition: add_display_dialog.cpp:54
rviz::FrameViewController::onTargetFrameChanged
void onTargetFrameChanged(const Ogre::Vector3 &old_reference_position, const Ogre::Quaternion &old_reference_orientation) override
Override to implement the change in properties which nullifies the change in target frame.
Definition: frame_view_controller.cpp:145
rviz::FrameViewController::rememberAxis
void rememberAxis(int current)
Definition: frame_view_controller.cpp:139
rviz::FrameViewController::onInitialize
void onInitialize() override
Do subclass-specific initialization. Called by ViewController::initialize after context_ and camera_ ...
Definition: frame_view_controller.cpp:70
rviz::FramePositionTrackingViewController::reference_orientation_
Ogre::Quaternion reference_orientation_
Definition: frame_position_tracking_view_controller.h:100
rviz::FrameViewController::changedOrientation
void changedOrientation() override
Definition: frame_view_controller.cpp:127
rviz::FPSViewController::handleMouseEvent
void handleMouseEvent(ViewportMouseEvent &event) override
Definition: fps_view_controller.cpp:105
rviz::FramePositionTrackingViewController::getNewTransform
bool getNewTransform()
Definition: frame_position_tracking_view_controller.cpp:95
rviz::Property::rowNumberInParent
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
Definition: property.cpp:421
rviz::ANY_AXIS
static const QString ANY_AXIS("arbitrary")
rviz::FrameViewController::changedAxis
void changedAxis()
Definition: frame_view_controller.cpp:133
vector_property.h
rviz::ViewController
Definition: view_controller.h:55
rviz::ViewController::camera_
Ogre::Camera * camera_
Definition: view_controller.h:226
class_list_macros.hpp
rviz::FrameViewController::previous_axis_
int previous_axis_
Definition: frame_view_controller.h:73
display_context.h
rviz::ViewController::setStatus
void setStatus(const QString &message)
Definition: view_controller.cpp:235
rviz::FrameViewController::actualCameraAxisOption
int actualCameraAxisOption(double precision=0.001) const
find enum ID from camera's current pose
Definition: frame_view_controller.cpp:100
rviz::FPSViewController::changedOrientation
virtual void changedOrientation()
Definition: fps_view_controller.cpp:237
frame_view_controller.h
rviz::fmtAxis
QString fmtAxis(int i)
Definition: frame_view_controller.cpp:49
rviz::FrameViewController::reset
void reset() override
Definition: frame_view_controller.cpp:76
rviz::FramePositionTrackingViewController::target_scene_node_
Ogre::SceneNode * target_scene_node_
Definition: frame_position_tracking_view_controller.h:99
enum_property.h
rviz::FrameViewController
A camera tied to a given frame.
Definition: frame_view_controller.h:42


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:09