From 11ca9fc89833c02b00ced6212ee251f28be1735d Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Fri, 27 Oct 2023 16:46:46 +0200 Subject: [PATCH] Fix build when no display gui available - error reported by ros2 jenkins buildfarm --- tutorial/image/drawingHelpers.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tutorial/image/drawingHelpers.cpp b/tutorial/image/drawingHelpers.cpp index 9345b1b6aa..98602dc10c 100644 --- a/tutorial/image/drawingHelpers.cpp +++ b/tutorial/image/drawingHelpers.cpp @@ -33,25 +33,31 @@ #include #if defined(VISP_HAVE_X11) - vpDisplayX drawingHelpers::d; +vpDisplayX drawingHelpers::d; #elif defined(HAVE_OPENCV_HIGHGUI) - vpDisplayOpenCV drawingHelpers::d; +vpDisplayOpenCV drawingHelpers::d; #elif defined(VISP_HAVE_GTK) - vpDisplayGTK drawingHelpers::d; +vpDisplayGTK drawingHelpers::d; #elif defined(VISP_HAVE_GDI) - vpDisplayGDI drawingHelpers::d; +vpDisplayGDI drawingHelpers::d; #elif defined(VISP_HAVE_D3D9) - vpDisplayD3D drawingHelpers::d; +vpDisplayD3D drawingHelpers::d; #endif vpImage drawingHelpers::I_disp; bool drawingHelpers::display(vpImage &I, const std::string &title, const bool &blockingMode) -{ +{ I_disp = I; - d.init(I_disp); - vpDisplay::setTitle(I_disp, title.c_str()); - +#if defined(VISP_HAVE_DISPLAY) + if (!d.isInitialised()) { + d.init(I_disp); + vpDisplay::setTitle(I_disp, title); + } +#else + (void)title; +#endif + vpDisplay::display(I_disp); vpDisplay::displayText(I_disp, 15, 15, "Left click to continue...", vpColor::red); vpDisplay::displayText(I_disp, 35, 15, "Right click to stop...", vpColor::red); @@ -59,21 +65,20 @@ bool drawingHelpers::display(vpImage &I, const std::string &title, const vpMouseButton::vpMouseButtonType button; vpDisplay::getClick(I_disp, button, blockingMode); bool hasToContinue = true; - if (button == vpMouseButton::button3) - { + if (button == vpMouseButton::button3) { // Right click => stop the program hasToContinue = false; } return hasToContinue; } - + bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) { vpImage I; // Image to display vpImageConvert::convert(D, I); return display(I, title, blockingMode); -} +} bool drawingHelpers::display(vpImage &D, const std::string &title, const bool &blockingMode) {