@@ -32,7 +32,7 @@ namespace MODULES {
3232namespace OPENGL {
3333
3434static 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
273376void 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
404524void 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