Skip to content

Commit be0fc9a

Browse files
committed
Add rotation conversion demo
1 parent 46cd9a4 commit be0fc9a

16 files changed

+1868
-0
lines changed

demos/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if(BUILD_RL_MATH)
66
add_subdirectory(rlPcaDemo)
77
add_subdirectory(rlQuaternionDemo)
88
add_subdirectory(rlPolynomialRootsDemo)
9+
add_subdirectory(rlRotationConverterDemo)
910
add_subdirectory(rlSpatialDemo)
1011
add_subdirectory(rlTrapezoidalVelocityDemo)
1112
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
//
2+
// Copyright (c) 2009, Markus Rickert
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 notice,
9+
// this list of conditions and the following disclaimer.
10+
// * Redistributions in binary form must reproduce the above copyright notice,
11+
// this list of conditions and the following disclaimer in the documentation
12+
// and/or other materials provided with the distribution.
13+
//
14+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
// POSSIBILITY OF SUCH DAMAGE.
25+
//
26+
27+
#include <QTableView>
28+
#include <rl/math/Unit.h>
29+
30+
#include "AngleAxisModel.h"
31+
#include "MainWindow.h"
32+
33+
AngleAxisModel::AngleAxisModel(QObject* parent) :
34+
QAbstractTableModel(parent),
35+
angleAxis(nullptr),
36+
angleRadians(nullptr)
37+
{
38+
}
39+
40+
AngleAxisModel::~AngleAxisModel()
41+
{
42+
}
43+
44+
int
45+
AngleAxisModel::columnCount(const QModelIndex& parent) const
46+
{
47+
return 4;
48+
}
49+
50+
QVariant
51+
AngleAxisModel::data(const QModelIndex& index, int role) const
52+
{
53+
if (nullptr == this->angleAxis || nullptr == this->angleRadians)
54+
{
55+
return QVariant();
56+
}
57+
58+
if (!index.isValid())
59+
{
60+
return QVariant();
61+
}
62+
63+
switch (role)
64+
{
65+
case Qt::DisplayRole:
66+
case Qt::EditRole:
67+
switch (index.column())
68+
{
69+
case 0:
70+
case 1:
71+
case 2:
72+
return this->angleAxis->axis()(index.column());
73+
break;
74+
case 3:
75+
return *this->angleRadians ? this->angleAxis->angle() : this->angleAxis->angle() * rl::math::RAD2DEG;
76+
break;
77+
default:
78+
break;
79+
}
80+
break;
81+
case Qt::TextAlignmentRole:
82+
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
83+
break;
84+
default:
85+
break;
86+
}
87+
88+
return QVariant();
89+
}
90+
91+
Qt::ItemFlags
92+
AngleAxisModel::flags(const QModelIndex &index) const
93+
{
94+
if (!index.isValid())
95+
{
96+
return Qt::NoItemFlags;
97+
}
98+
99+
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
100+
}
101+
102+
QVariant
103+
AngleAxisModel::headerData(int section, Qt::Orientation orientation, int role) const
104+
{
105+
if (nullptr == this->angleAxis || nullptr == this->angleRadians)
106+
{
107+
return QVariant();
108+
}
109+
110+
if (Qt::DisplayRole == role && Qt::Horizontal == orientation)
111+
{
112+
switch (section)
113+
{
114+
case 0:
115+
return "X";
116+
break;
117+
case 1:
118+
return "Y";
119+
break;
120+
case 2:
121+
return "Z";
122+
break;
123+
case 3:
124+
return "Angle";
125+
break;
126+
default:
127+
break;
128+
}
129+
}
130+
131+
return QVariant();
132+
}
133+
134+
void
135+
AngleAxisModel::invalidate()
136+
{
137+
this->beginResetModel();
138+
this->endResetModel();
139+
}
140+
141+
int
142+
AngleAxisModel::rowCount(const QModelIndex& parent) const
143+
{
144+
return 1;
145+
}
146+
147+
bool
148+
AngleAxisModel::setData(const QModelIndex& index, const QVariant& value, int role)
149+
{
150+
if (nullptr == this->angleAxis || nullptr == this->angleRadians)
151+
{
152+
return false;
153+
}
154+
155+
if (index.isValid() && Qt::EditRole == role)
156+
{
157+
switch (index.column())
158+
{
159+
case 0:
160+
case 1:
161+
case 2:
162+
this->angleAxis->axis()(index.column()) = value.value<rl::math::Real>();
163+
break;
164+
case 3:
165+
this->angleAxis->angle() = *this->angleRadians ? value.value<rl::math::Real>() : value.value<rl::math::Real>() * rl::math::DEG2RAD;
166+
break;
167+
default:
168+
break;
169+
}
170+
171+
emit dataChanged(this->createIndex(index.row(), index.column()), this->createIndex(index.row(), index.column()));
172+
173+
return true;
174+
}
175+
176+
return false;
177+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright (c) 2009, Markus Rickert
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 notice,
9+
// this list of conditions and the following disclaimer.
10+
// * Redistributions in binary form must reproduce the above copyright notice,
11+
// this list of conditions and the following disclaimer in the documentation
12+
// and/or other materials provided with the distribution.
13+
//
14+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
// POSSIBILITY OF SUCH DAMAGE.
25+
//
26+
27+
#ifndef ANGLEAXISMODEL_H
28+
#define ANGLEAXISMODEL_H
29+
30+
#include <QAbstractTableModel>
31+
#include <rl/math/Rotation.h>
32+
33+
class AngleAxisModel : public QAbstractTableModel
34+
{
35+
Q_OBJECT
36+
37+
public:
38+
AngleAxisModel(QObject* parent = nullptr);
39+
40+
virtual ~AngleAxisModel();
41+
42+
int columnCount(const QModelIndex& parent = QModelIndex()) const;
43+
44+
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
45+
46+
Qt::ItemFlags flags(const QModelIndex &index) const;
47+
48+
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
49+
50+
void invalidate();
51+
52+
int rowCount(const QModelIndex& parent = QModelIndex()) const;
53+
54+
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
55+
56+
rl::math::AngleAxis* angleAxis;
57+
58+
bool* angleRadians;
59+
60+
protected:
61+
62+
private:
63+
64+
};
65+
66+
#endif // ANGLEAXISMODEL_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
if(USE_QT5)
2+
find_package(Qt5 COMPONENTS Core Gui Widgets QUIET)
3+
endif()
4+
5+
if(Qt5_FOUND)
6+
set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES})
7+
set(QT_FOUND Qt5_FOUND)
8+
else()
9+
set(QT_USE_IMPORTED_TARGETS ON)
10+
find_package(Qt4 COMPONENTS QtCore QtGui)
11+
set(QT_USE_QTMAIN ON)
12+
include(${QT_USE_FILE})
13+
endif()
14+
15+
set(CMAKE_AUTOMOC ON)
16+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
17+
18+
if(QT_FOUND)
19+
set(
20+
HDRS
21+
AngleAxisModel.h
22+
EulerAnglesModel.h
23+
MainWindow.h
24+
QuaternionModel.h
25+
RotationMatrixModel.h
26+
TableView.h
27+
)
28+
29+
set(
30+
SRCS
31+
AngleAxisModel.cpp
32+
EulerAnglesModel.cpp
33+
MainWindow.cpp
34+
QuaternionModel.cpp
35+
rlRotationConverterDemo.cpp
36+
RotationMatrixModel.cpp
37+
TableView.cpp
38+
${rl_SOURCE_DIR}/robotics-library.rc
39+
)
40+
add_executable(
41+
rlRotationConverterDemo
42+
WIN32
43+
${HDRS}
44+
${SRCS}
45+
)
46+
47+
target_link_libraries(
48+
rlRotationConverterDemo
49+
math
50+
${QT_LIBRARIES}
51+
)
52+
53+
set_target_properties(
54+
rlRotationConverterDemo
55+
PROPERTIES
56+
VERSION ${VERSION}
57+
)
58+
59+
if(WIN32)
60+
set_target_properties(
61+
rlRotationConverterDemo
62+
PROPERTIES
63+
DEBUG_POSTFIX d
64+
)
65+
endif()
66+
67+
install(
68+
TARGETS rlRotationConverterDemo
69+
COMPONENT demos
70+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
71+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
72+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
73+
)
74+
75+
if(MSVC AND BUILD_SHARED_LIBS AND NOT CMAKE_VERSION VERSION_LESS 3.1)
76+
install(FILES $<TARGET_PDB_FILE:rlRotationConverterDemo> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT demos)
77+
endif()
78+
79+
if(UNIX)
80+
configure_file(rlRotationConverterDemo.desktop.in rlRotationConverterDemo.desktop @ONLY)
81+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/rlRotationConverterDemo.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications COMPONENT demos)
82+
endif()
83+
84+
set(
85+
CPACK_NSIS_CREATE_ICONS_EXTRA
86+
${CPACK_NSIS_CREATE_ICONS_EXTRA}
87+
"CreateShortCut \\\\
88+
\\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\rlRotationConverterDemo.lnk\\\" \\\\
89+
\\\"$INSTDIR\\\\${CMAKE_INSTALL_BINDIR}\\\\rlRotationConverterDemo.exe\\\" \\\\
90+
\\\"\\\" \\\\
91+
\\\"\\\" \\\"\\\" \\\"\\\" \\\"\\\" \\\\
92+
\\\"Rotation conversion demo\\\""
93+
PARENT_SCOPE
94+
)
95+
set(CPACK_NSIS_DELETE_ICONS_EXTRA ${CPACK_NSIS_DELETE_ICONS_EXTRA} "Delete \\\"$SMPROGRAMS\\\\$START_MENU\\\\rlRotationConverterDemo.lnk\\\"" PARENT_SCOPE)
96+
97+
set(
98+
WIX_SHORTCUTS
99+
${WIX_SHORTCUTS}
100+
"<Shortcut
101+
Description=\"Rotation conversion demo\"
102+
Id=\"CM_SP_bin.rlRotationConverterDemo.exe\"
103+
Name=\"rlRotationConverterDemo\"
104+
Target=\"[#CM_FP_bin.rlRotationConverterDemo.exe]\"
105+
WorkingDirectory=\"CM_DP_bin\"
106+
/>"
107+
PARENT_SCOPE
108+
)
109+
endif()

0 commit comments

Comments
 (0)