Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 0d5938e

Browse files
committed
Merge branch 'develop'
2 parents 695ac0b + 00dca5b commit 0d5938e

12 files changed

+197
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.lo
77
*.o
88
*.obj
9+
*build*
910
.build-rules/
1011
tests/*/.build-rules/
1112
deploy

JenkinsFile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ SolArModulePipeline {
22
moduleName="SolARModuleOpenGL"
33
dirName="SolARBuild"
44
runTests=true
5-
android=false
65
}

SolARModuleOpenGL.pro

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ INSTALLSUBDIR = SolARBuild
99
TARGET = SolARModuleOpenGL
1010

1111
FRAMEWORK = $$TARGET
12-
VERSION=0.11.0
12+
VERSION=1.0.0
1313

1414
DEFINES += MYVERSION=$${VERSION}
1515
DEFINES += TEMPLATE_LIBRARY
@@ -49,7 +49,7 @@ unix {
4949
QMAKE_POST_LINK += "make install install_deps"
5050
}
5151

52-
unix:!android {
52+
unix {
5353
QMAKE_CXXFLAGS += -Wignored-qualifiers
5454
}
5555

@@ -58,15 +58,6 @@ linux {
5858
LIBS += -L/home/linuxbrew/.linuxbrew/lib # temporary fix caused by grpc with -lre2 ... without -L in grpc.pc
5959
}
6060

61-
macx {
62-
DEFINES += _MACOS_TARGET_
63-
QMAKE_MAC_SDK= macosx
64-
QMAKE_CFLAGS += -mmacosx-version-min=10.7 -std=c11 #-x objective-c++
65-
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 -std=c11 -std=c++11 -O3 -fPIC#-x objective-c++
66-
QMAKE_LFLAGS += -mmacosx-version-min=10.7 -v -lstdc++
67-
LIBS += -lstdc++ -lc -lpthread
68-
}
69-
7061
win32 {
7162

7263
DEFINES += WIN64 UNICODE _UNICODE NOMINMAX
@@ -88,7 +79,6 @@ INSTALLS += xpcf_xml_files
8879
OTHER_FILES += \
8980
packagedependencies.txt \
9081
packagedependencies-linux.txt \
91-
packagedependencies-mac.txt \
9282
packagedependencies-win.txt
9383

9484
#NOTE : Must be placed at the end of the .pro

bcom-SolARModuleOpenGL.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ libdir=${exec_prefix}/lib
55
includedir=${prefix}/interfaces
66
Name: SolARModuleOpenGL
77
Description:
8-
Version: 0.11.0
8+
Version: 1.0.0
99
Requires:
1010
Libs: -L${libdir} -l${libname}
1111
Libs.private: ${libdir}/${pfx}${libname}.${lext}

interfaces/SolAR3DPointsViewerOpengl.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ class SOLAROPENGL_EXPORT_API SolAR3DPointsViewerOpengl : public org::bcom::xpcf:
173173
/// @brief points color for the second cloud
174174
std::vector<unsigned int> m_points2Color = {255, 0, 0};
175175

176+
/// @brief display points color according to class label
177+
unsigned int m_usePointsColorFromClassLabel = 0;
178+
179+
/// @brief colormap file mapping class label to RGB color
180+
std::string m_classLabelColorMapPath = "";
181+
182+
/// @brief colormap mapping class label to RGB triples
183+
std::vector<datastructure::Vector3f> m_colorMap;
184+
176185
/// @brief camera color
177186
std::vector<unsigned int> m_cameraColor = {0,0,255};
178187

@@ -212,7 +221,26 @@ class SOLAROPENGL_EXPORT_API SolAR3DPointsViewerOpengl : public org::bcom::xpcf:
212221
/// @brief The key code to press to close the window. If negative, no key is defined to close the window
213222
int m_exitKey = 27;
214223

224+
/// @brief The key code to press to increase rotation about X axis. If negative, no key is defined.
225+
int m_increaseRotationXKey = -1;
226+
227+
/// @brief The key code to press to decrease rotation about X axis. If negative, no key is defined.
228+
int m_decreaseRotationXKey = -1;
229+
230+
/// @brief The key code to press to increase rotation about Y axis. If negative, no key is defined.
231+
int m_increaseRotationYKey = -1;
215232

233+
/// @brief The key code to press to decrease rotation about Y axis. If negative, no key is defined.
234+
int m_decreaseRotationYKey = -1;
235+
236+
/// @brief The key code to press to increase rotation about Z axis. If negative, no key is defined.
237+
int m_increaseRotationZKey = -1;
238+
239+
/// @brief The key code to press to decrease rotation about Z axis. If negative, no key is defined.
240+
int m_decreaseRotationZKey = -1;
241+
242+
/// @brief The key code to press to reset all rotation values to 0. If negative, no key is defined.
243+
int m_resetRotationKey = -1;
216244

217245
int m_glWindowID = -1;
218246
std::vector<SRef<datastructure::CloudPoint>> m_points;
@@ -228,6 +256,10 @@ class SOLAROPENGL_EXPORT_API SolAR3DPointsViewerOpengl : public org::bcom::xpcf:
228256
unsigned int m_resolutionY;
229257
bool m_exitKeyPressed = false;
230258
bool m_firstDisplay = true;
259+
float m_rotationStep = 0.01;
260+
float m_rotationX = 0.0, m_rotationY = 0.0, m_rotationZ = 0.0;
261+
262+
void rotate(const float rx, const float ry, const float rz);
231263

232264
void OnMainLoop() ;
233265
void OnRender() ;

packagedependencies-mac.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

packagedependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SolARFramework|0.11.0|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download
1+
SolARFramework|1.0.0|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download
22

src/SolAR3DPointsViewerOpengl.cpp

Lines changed: 156 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace MODULES {
3232
namespace OPENGL {
3333

3434
static Transform3Df SolAR2GL = [] {
35-
Matrix<float, 4, 4> matrix;
35+
Eigen::Matrix<float, 4, 4> matrix;
3636
matrix << 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0;
3737
return Transform3Df(matrix);
3838
}();
@@ -47,6 +47,8 @@ SolAR3DPointsViewerOpengl::SolAR3DPointsViewerOpengl():ConfigurableBase(xpcf::to
4747
declareProperty("width", m_width);
4848
declareProperty("height", m_height);
4949
declarePropertySequence("backgroundColor", m_backgroundColor);
50+
declareProperty("pointsColorFromClassLabel", m_usePointsColorFromClassLabel);
51+
declareProperty("classLabelColorMapPath", m_classLabelColorMapPath);
5052
declareProperty("fixedPointsColor", m_fixedPointsColor);
5153
declarePropertySequence("pointsColor", m_pointsColor);
5254
declarePropertySequence("points2Color", m_points2Color);
@@ -63,7 +65,16 @@ SolAR3DPointsViewerOpengl::SolAR3DPointsViewerOpengl():ConfigurableBase(xpcf::to
6365
declareProperty("cameraScale", m_cameraScale);
6466
declareProperty("zoomSensitivity", m_zoomSensitivity);
6567
declareProperty("exitKey", m_exitKey);
68+
declareProperty("increaseRotationXKey", m_increaseRotationXKey);
69+
declareProperty("decreaseRotationXKey", m_decreaseRotationXKey);
70+
declareProperty("increaseRotationYKey", m_increaseRotationYKey);
71+
declareProperty("decreaseRotationYKey", m_decreaseRotationYKey);
72+
declareProperty("increaseRotationZKey", m_increaseRotationZKey);
73+
declareProperty("decreaseRotationZKey", m_decreaseRotationZKey);
74+
declareProperty("resetRotationKey", m_resetRotationKey);
75+
declareProperty("rotationStep", m_rotationStep);
6676
m_instance = this ;
77+
6778
LOG_DEBUG(" SolAR3DPointsViewerOpengl constructor");
6879
}
6980

@@ -84,6 +95,31 @@ xpcf::XPCFErrorCode SolAR3DPointsViewerOpengl::onConfigured()
8495
m_resolutionX = m_width;
8596
m_resolutionY = m_height;
8697

98+
if (m_usePointsColorFromClassLabel>0) {
99+
if (m_classLabelColorMapPath.empty()) {
100+
LOG_ERROR("property classLabelColorMapPath is not defined and is needed when pointsColorFromClassLabel is > 0");
101+
return xpcf::XPCFErrorCode::_FAIL;
102+
}
103+
std::ifstream colorFptr;
104+
colorFptr.open(m_classLabelColorMapPath);
105+
if (!colorFptr.is_open()) {
106+
LOG_ERROR("failed to open color map file from path {}", m_classLabelColorMapPath);
107+
return xpcf::XPCFErrorCode::_ERROR_ACCESS_DENIED;
108+
}
109+
std::string line;
110+
while (std::getline(colorFptr, line)) {
111+
std::istringstream iss(line);
112+
float r, g, b;
113+
iss >> r >> g >> b;
114+
m_colorMap.emplace_back(r, g, b);
115+
}
116+
colorFptr.close();
117+
if (m_colorMap.empty()) {
118+
LOG_ERROR("empty color map for point cloud display");
119+
return xpcf::XPCFErrorCode::_FAIL;
120+
}
121+
}
122+
87123
glutInitWindowSize(m_width, m_height);
88124
m_glWindowID = glutCreateWindow(m_title.c_str());
89125
glutDisplayFunc(Render);
@@ -93,6 +129,46 @@ xpcf::XPCFErrorCode SolAR3DPointsViewerOpengl::onConfigured()
93129
glutReshapeFunc(ResizeWindow);
94130
glutIdleFunc(MainLoop);
95131
glutMainLoopEvent();
132+
133+
LOG_INFO("**************************************************");
134+
LOG_INFO("Keys defined for view rotation:");
135+
if (m_increaseRotationXKey != -1) {
136+
LOG_INFO("Key defined to increase rotation around X axis: {}", (char)m_increaseRotationXKey);
137+
}
138+
else
139+
LOG_INFO("No key defined to increase rotation around X axis");
140+
if (m_decreaseRotationXKey != -1) {
141+
LOG_INFO("Key defined to decrease rotation around X axis: {}", (char)m_decreaseRotationXKey);
142+
}
143+
else
144+
LOG_INFO("No key defined to decrease rotation around X axis");
145+
if (m_increaseRotationYKey != -1) {
146+
LOG_INFO("Key defined to increase rotation around Y axis: {}", (char)m_increaseRotationYKey);
147+
}
148+
else
149+
LOG_INFO("No key defined to increase rotation around Y axis");
150+
if (m_decreaseRotationYKey != -1) {
151+
LOG_INFO("Key defined to decrease rotation around Y axis: {}", (char)m_decreaseRotationYKey);
152+
}
153+
else
154+
LOG_INFO("No key defined to decrease rotation around Y axis");
155+
if (m_increaseRotationZKey != -1) {
156+
LOG_INFO("Key defined to increase rotation around Z axis: {}", (char)m_increaseRotationZKey);
157+
}
158+
else
159+
LOG_INFO("No key defined to increase rotation around Z axis");
160+
if (m_decreaseRotationZKey != -1) {
161+
LOG_INFO("Key defined to decrease rotation around Z axis: {}", (char)m_decreaseRotationZKey);
162+
}
163+
else
164+
LOG_INFO("No key defined to decrease rotation around Z axis");
165+
if (m_resetRotationKey != -1) {
166+
LOG_INFO("Key defined to reset rotation around all axes: {}", (char)m_resetRotationKey);
167+
}
168+
else
169+
LOG_INFO("No key defined to reset rotation around all axis");
170+
LOG_INFO("**************************************************");
171+
96172
return xpcf::XPCFErrorCode::_SUCCESS;
97173
}
98174

@@ -144,6 +220,7 @@ FrameworkReturnCode SolAR3DPointsViewerOpengl::display (const std::vector<SRef<C
144220
{
145221
m_glcamera.clear(0.0, 0.0, 0.0, 1.0);
146222
glutDestroyWindow(m_glWindowID);
223+
glutMainLoopEvent();
147224
return FrameworkReturnCode::_STOP;
148225
}
149226

@@ -268,6 +345,32 @@ void drawAxis(Transform3Df& pose, float scale, float lineWidth){
268345
glLineWidth(1.0f);
269346
}
270347

348+
void SolAR3DPointsViewerOpengl::rotate(const float rx, const float ry, const float rz)
349+
{
350+
if (rx != 0.0) {
351+
math_matrix_3x3f rotMatrixX = {1.0, 0.0, 0.0,
352+
0.0, cos(rx), -sin(rx),
353+
0.0, sin(rx), cos(rx)};
354+
355+
m_glcamera.rotate(rotMatrixX);
356+
}
357+
358+
if (ry != 0.0) {
359+
math_matrix_3x3f rotMatrixY = {cos(ry), 0.0, sin(ry),
360+
0.0, 1.0, 0.0,
361+
-sin(ry), 0.0, cos(ry)};
362+
363+
m_glcamera.rotate(rotMatrixY);
364+
}
365+
366+
if (rz != 0.0) {
367+
math_matrix_3x3f rotMatrixZ = {cos(rz), -sin(rz), 0.0,
368+
sin(rz), cos(rz), 0.0,
369+
0.0, 0.0, 1.0};
370+
371+
m_glcamera.rotate(rotMatrixZ);
372+
}
373+
}
271374

272375

273376
void SolAR3DPointsViewerOpengl::OnMainLoop()
@@ -280,6 +383,8 @@ void SolAR3DPointsViewerOpengl::OnRender()
280383
glEnable(GL_NORMALIZE);
281384
glEnable(GL_DEPTH_TEST);
282385

386+
rotate(m_rotationX, m_rotationY, m_rotationZ);
387+
283388
m_glcamera.set_viewport(0, 0, m_resolutionX, m_resolutionY);
284389
m_glcamera.setup();
285390
m_glcamera.use_light(false);
@@ -303,20 +408,42 @@ void SolAR3DPointsViewerOpengl::OnRender()
303408
drawAxis(sceneTransform, m_sceneSize * 0.1 * m_axisScale, m_axisScale);
304409
}
305410

411+
auto fnAssignColor = [](const std::vector<SRef<datastructure::CloudPoint>>& points, const unsigned int& usePtsColorFromClassLabel,
412+
const std::vector<datastructure::Vector3f>& colorMap, const unsigned int& fixPtsColor, const std::vector<unsigned int>& ptsColor) {
413+
for (unsigned int i = 0; i < points.size(); ++i) {
414+
// if color map is provided, display point cloud according to class colors
415+
// if cloud point does not have semantic id, display it in white color
416+
if (usePtsColorFromClassLabel>0) {
417+
if (points[i]->getSemanticId() < 0) { // no semantic id associated
418+
glColor3f(1.f, 1.f, 1.f); // show in white color
419+
}
420+
else if (points[i]->getSemanticId() >= static_cast<int>(colorMap.size())) {
421+
LOG_ERROR("Cloud point's semantic id {} exceeds the number of colors {}", points[i]->getSemanticId(), colorMap.size());
422+
return;
423+
}
424+
else {
425+
auto color = colorMap[points[i]->getSemanticId()];
426+
glColor3f(color[0]/255.f, color[1]/255.f, color[2]/255.f);
427+
}
428+
}
429+
else { // no color map is provided
430+
if (fixPtsColor)
431+
glColor3f(ptsColor[0]/255.f, ptsColor[1]/255.f, ptsColor[2]/255.f);
432+
else
433+
glColor3f(points[i]->getR(), points[i]->getG(), points[i]->getB());
434+
}
435+
436+
glVertex3f(points[i]->getX(), -points[i]->getY(), -points[i]->getZ());
437+
}
438+
};
439+
306440
if (!m_points2.empty())
307441
{
308442
glPushMatrix();
309443
glEnable(GL_POINT_SMOOTH);
310444
glPointSize(m_pointSize);
311445
glBegin(GL_POINTS);
312-
for (unsigned int i = 0; i < m_points2.size(); ++i) {
313-
if (m_fixedPointsColor)
314-
glColor3f(m_points2Color[0], m_points2Color[1], m_points2Color[2]);
315-
else
316-
glColor3f(m_points2[i]->getR(), m_points2[i]->getG(), m_points2[i]->getB());
317-
318-
glVertex3f(m_points2[i]->getX(), -m_points2[i]->getY(), -m_points2[i]->getZ());
319-
}
446+
fnAssignColor(m_points2, m_usePointsColorFromClassLabel, m_colorMap, m_fixedPointsColor, m_points2Color);
320447
glEnd();
321448
glPopMatrix();
322449
}
@@ -327,14 +454,7 @@ void SolAR3DPointsViewerOpengl::OnRender()
327454
glEnable (GL_POINT_SMOOTH);
328455
glPointSize(m_pointSize);
329456
glBegin(GL_POINTS);
330-
for (unsigned int i = 0; i < m_points.size(); ++i) {
331-
if (m_fixedPointsColor)
332-
glColor3f(m_pointsColor[0], m_pointsColor[1], m_pointsColor[2]);
333-
else
334-
glColor3f(m_points[i]->getR(), m_points[i]->getG(), m_points[i]->getB());
335-
336-
glVertex3f(m_points[i]->getX(), -m_points[i]->getY(), -m_points[i]->getZ());
337-
}
457+
fnAssignColor(m_points, m_usePointsColorFromClassLabel, m_colorMap, m_fixedPointsColor, m_pointsColor);
338458
glEnd();
339459
glPopMatrix();
340460
}
@@ -403,8 +523,25 @@ void SolAR3DPointsViewerOpengl::OnResizeWindow(int _w, int _h)
403523

404524
void SolAR3DPointsViewerOpengl::OnKeyBoard(unsigned char key, ATTRIBUTE(maybe_unused) int x, ATTRIBUTE(maybe_unused) int y)
405525
{
406-
if (key == m_exitKey)
407-
m_exitKeyPressed = true;
526+
if (key == m_exitKey)
527+
m_exitKeyPressed = true;
528+
else if (key == m_increaseRotationXKey)
529+
m_rotationX -= m_rotationStep;
530+
else if (key == m_decreaseRotationXKey)
531+
m_rotationX += m_rotationStep;
532+
else if (key == m_increaseRotationYKey)
533+
m_rotationY += m_rotationStep;
534+
else if (key == m_decreaseRotationYKey)
535+
m_rotationY -= m_rotationStep;
536+
else if (key == m_increaseRotationZKey)
537+
m_rotationZ -= m_rotationStep;
538+
else if (key == m_decreaseRotationZKey)
539+
m_rotationZ += m_rotationStep;
540+
else if (key == m_resetRotationKey) {
541+
m_rotationX = 0.0;
542+
m_rotationY = 0.0;
543+
m_rotationZ = 0.0;
544+
}
408545
}
409546

410547

0 commit comments

Comments
 (0)