Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation error related to GUI #1405

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/core/include/visp3/core/vpImageConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#endif

#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) && defined(VISP_HAVE_THREADS)
#include <mutex>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpImageException.h>
#include <visp3/core/vpPixelMeterConversion.h>
Expand Down
100 changes: 100 additions & 0 deletions modules/gui/include/visp3/gui/vpDisplayFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at [email protected]
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Display Factory
*
*****************************************************************************/

#include <visp3/core/vpConfig.h>
#include <visp3/gui/vpDisplayD3D.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>

namespace vpDisplayFactory
{
/**
* \brief Return a newly allocated vpDisplay specialisation
* if a GUI library is available or nullptr otherwise.
*
* \return vpDisplay* A newly allocated vpDisplay specialisation
* if a GUI library is available or nullptr otherwise.
*/
vpDisplay *displayFactory()

Check warning on line 52 in modules/gui/include/visp3/gui/vpDisplayFactory.h

View check run for this annotation

Codecov / codecov/patch

modules/gui/include/visp3/gui/vpDisplayFactory.h#L52

Added line #L52 was not covered by tests
{
#if defined(VISP_HAVE_DISPLAY)
#ifdef VISP_HAVE_X11
return new vpDisplayX();

Check warning on line 56 in modules/gui/include/visp3/gui/vpDisplayFactory.h

View check run for this annotation

Codecov / codecov/patch

modules/gui/include/visp3/gui/vpDisplayFactory.h#L56

Added line #L56 was not covered by tests
#elif defined(VISP_HAVE_D3D9)
return new vpDisplayD3D();
#elif defined(VISP_HAVE_GDI)
return new vpDisplayGDI();
#elif defined(VISP_HAVE_GTK)
return new vpDisplayGTK();
#elif defined(HAVE_OPENCV_HIGHGUI)
return new vpDisplayOpenCV();
#endif
#else
return nullptr;
s-trinh marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

/**
* \brief Return a newly allocated vpDisplay specialisation initialized with \b I
* if a GUI library is available or nullptr otherwise.
*
* \tparam T Any type that an image can handle and that can be displayed.
* \param[in] I The image the display must be initialized with.
*
* \return vpDisplay* A newly allocated vpDisplay specialisation initialized with \b I
* if a GUI library is available or nullptr otherwise.
*/
template<typename T>
vpDisplay *displayFactory(vpImage<T> &I)

Check warning on line 82 in modules/gui/include/visp3/gui/vpDisplayFactory.h

View check run for this annotation

Codecov / codecov/patch

modules/gui/include/visp3/gui/vpDisplayFactory.h#L82

Added line #L82 was not covered by tests
{
#if defined(VISP_HAVE_DISPLAY)
#ifdef VISP_HAVE_X11
return new vpDisplayX(I);

Check warning on line 86 in modules/gui/include/visp3/gui/vpDisplayFactory.h

View check run for this annotation

Codecov / codecov/patch

modules/gui/include/visp3/gui/vpDisplayFactory.h#L86

Added line #L86 was not covered by tests
#elif defined(VISP_HAVE_D3D9)
return new vpDisplayD3D(I);
#elif defined(VISP_HAVE_GDI)
return new vpDisplayGDI(I);
#elif defined(VISP_HAVE_GTK)
return new vpDisplayGTK(I);
#elif defined(HAVE_OPENCV_HIGHGUI)
return new vpDisplayOpenCV(I);
#endif
#else
return nullptr;
#endif
}
}
32 changes: 23 additions & 9 deletions tutorial/grabber/tutorial-grabber-1394-writer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/*! \example tutorial-grabber-1394-writer.cpp */
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpVideoWriter.h>
#include <visp3/sensor/vp1394TwoGrabber.h>

int main(int argc, char **)
{
#ifdef VISP_HAVE_DC1394
#ifdef VISP_HAVE_DISPLAY
vpDisplay *d = vpDisplayFactory::displayFactory();

Check warning on line 11 in tutorial/grabber/tutorial-grabber-1394-writer.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-1394-writer.cpp#L11

Added line #L11 was not covered by tests
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
try {
bool save = false;
if (argc == 2) {
Expand All @@ -23,36 +28,45 @@

std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;

#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif

vpVideoWriter writer;
writer.setFileName("./I%04d.pgm");
if (save)
writer.open(I);

while (1) {
#ifdef VISP_HAVE_DISPLAY
d->init(I);

Check warning on line 37 in tutorial/grabber/tutorial-grabber-1394-writer.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-1394-writer.cpp#L37

Added line #L37 was not covered by tests
while (1)
#else
// for loop when no display is available to avoid infinite while loop
for (unsigned int i = 0; i < 1000; ++i)
#endif
{
g.acquire(I);

if (save)
writer.saveFrame(I);

#ifdef VISP_HAVE_DISPLAY
vpDisplay::display(I);
vpDisplay::flush(I);

if (vpDisplay::getClick(I, false))
break;
#endif
}

if (save)
writer.close();

} catch (const vpException &e) {
}
catch (const vpException &e) {

Check warning on line 62 in tutorial/grabber/tutorial-grabber-1394-writer.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-1394-writer.cpp#L62

Added line #L62 was not covered by tests
std::cout << "Catch an exception: " << e << std::endl;
}
#ifdef VISP_HAVE_DISPLAY
if (d != nullptr) {
delete d;

Check warning on line 67 in tutorial/grabber/tutorial-grabber-1394-writer.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-1394-writer.cpp#L67

Added line #L67 was not covered by tests
}
#endif
#else
(void)argc;
#endif
Expand Down
18 changes: 7 additions & 11 deletions tutorial/grabber/tutorial-grabber-v4l2-threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <iostream>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/sensor/vpV4l2Grabber.h>

#if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_THREADS)
#if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_THREADS) && defined(VISP_HAVE_DISPLAY)

#include <thread>
#include <mutex>
Expand Down Expand Up @@ -54,9 +54,7 @@

t_CaptureState capture_state_;
bool display_initialized_ = false;
#if defined(VISP_HAVE_X11)
vpDisplayX *d_ = nullptr;
#endif
vpDisplay *d_ = vpDisplayFactory::displayFactory();

Check warning on line 57 in tutorial/grabber/tutorial-grabber-v4l2-threaded.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-v4l2-threaded.cpp#L57

Added line #L57 was not covered by tests

do {
mutex_capture.lock();
Expand All @@ -73,11 +71,9 @@

// Check if we need to initialize the display with the first frame
if (!display_initialized_) {
// Initialize the display
#if defined(VISP_HAVE_X11)
d_ = new vpDisplayX(I_);
// Initialize the display
d_->init(I_);

Check warning on line 75 in tutorial/grabber/tutorial-grabber-v4l2-threaded.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-v4l2-threaded.cpp#L75

Added line #L75 was not covered by tests
display_initialized_ = true;
#endif
}

// Display the image
Expand All @@ -98,9 +94,7 @@
}
} while (capture_state_ != capture_stopped);

#if defined(VISP_HAVE_X11)
delete d_;
#endif

std::cout << "End of display thread" << std::endl;
}
Expand Down Expand Up @@ -157,6 +151,8 @@
std::cout << "You should enable V4L2 to make this example working..." << std::endl;
#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
std::cout << "You should enable pthread usage and rebuild ViSP..." << std::endl;
#elif !defined(VISP_HAVE_DISPLAY)
std::cout << "You should have at least one GUI library installed to use this example." << std::endl;
#else
std::cout << "Multi-threading seems not supported on this platform" << std::endl;
#endif
Expand Down
40 changes: 28 additions & 12 deletions tutorial/robot/mbot/raspberry/visp/mbot-apriltag-ibvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <visp3/core/vpSerial.h>
#include <visp3/core/vpXmlParserCamera.h>
#include <visp3/detection/vpDetectorAprilTag.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/robot/vpUnicycle.h>
#include <visp3/sensor/vpV4l2Grabber.h>
Expand All @@ -29,10 +29,12 @@
int nThreads = 2;
std::string intrinsic_file = "";
std::string camera_name = "";
bool display_tag = false;
bool display_on = false;
bool serial_off = false;
#if defined(VISP_HAVE_DISPLAY)
bool display_tag = false;
bool save_image = false; // Only possible if display_on = true
#endif

for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--tag_size" && i + 1 < argc) {
Expand All @@ -53,17 +55,17 @@
else if (std::string(argv[i]) == "--camera_name" && i + 1 < argc) {
camera_name = std::string(argv[i + 1]);
}
#if defined(VISP_HAVE_DISPLAY)
else if (std::string(argv[i]) == "--display_tag") {
display_tag = true;
#if defined(VISP_HAVE_X11)
}
else if (std::string(argv[i]) == "--display_on") {
display_on = true;
}
else if (std::string(argv[i]) == "--save_image") {
save_image = true;
#endif
}
#endif
else if (std::string(argv[i]) == "--serial_off") {
serial_off = true;
}
Expand All @@ -79,7 +81,7 @@
"TAG_36ARTOOLKIT,"
" 3: TAG_25h9, 4: TAG_25h7, 5: TAG_16h5)]"
" [--display_tag]";
#if defined(VISP_HAVE_X11)
#if defined(VISP_HAVE_DISPLAY)
std::cout << " [--display_on] [--save_image]";
#endif
std::cout << " [--serial_off] [--help]" << std::endl;
Expand Down Expand Up @@ -114,9 +116,9 @@

vpDisplay *d = nullptr;
vpImage<vpRGBa> O;
#ifdef VISP_HAVE_X11
#ifdef VISP_HAVE_DISPLAY
if (display_on) {
d = new vpDisplayX(I);
d = vpDisplayFactory::displayFactory(I);

Check warning on line 121 in tutorial/robot/mbot/raspberry/visp/mbot-apriltag-ibvs.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/robot/mbot/raspberry/visp/mbot-apriltag-ibvs.cpp#L121

Added line #L121 was not covered by tests
}
#endif

Expand All @@ -138,14 +140,18 @@

detector.setAprilTagQuadDecimate(quad_decimate);
detector.setAprilTagNbThreads(nThreads);
#ifdef VISP_HAVE_DISPLAY
detector.setDisplayTag(display_tag);
#endif

vpServo task;
vpAdaptiveGain lambda;
if (display_on)
if (display_on) {
lambda.initStandard(2.5, 0.4, 30); // lambda(0)=2.5, lambda(oo)=0.4 and lambda'(0)=30
else
}
else {
lambda.initStandard(4, 0.4, 30); // lambda(0)=4, lambda(oo)=0.4 and lambda'(0)=30
}

vpUnicycle robot;
task.setServo(vpServo::EYEINHAND_L_cVe_eJe);
Expand Down Expand Up @@ -243,7 +249,9 @@
for (;;) {
g.acquire(I);

#ifdef VISP_HAVE_DISPLAY
vpDisplay::display(I);
#endif

double t = vpTime::measureTimeMs();
std::vector<vpHomogeneousMatrix> cMo_vec;
Expand All @@ -254,7 +262,9 @@
{
std::stringstream ss;
ss << "Detection time: " << t << " ms";
#ifdef VISP_HAVE_DISPLAY
vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
#endif
}

if (detector.getNbObjects() == 1) {
Expand All @@ -274,14 +284,16 @@
vec_P.push_back(P);
}

// Display visual features
#ifdef VISP_HAVE_DISPLAY
// Display visual features
vpDisplay::displayPolygon(I, vec_ip, vpColor::green, 3); // Current polygon used to compure an moment
vpDisplay::displayCross(I, detector.getCog(0), 15, vpColor::green,
3); // Current polygon used to compure an moment
vpDisplay::displayLine(I, 0, cam.get_u0(), I.getHeight() - 1, cam.get_u0(), vpColor::red,
3); // Vertical line as desired x position
#endif

// Current moments
// Current moments
m_obj.setType(vpMomentObject::DENSE_POLYGON); // Consider the AprilTag as a polygon
m_obj.fromVector(vec_P); // Initialize the object with the points coordinates

Expand Down Expand Up @@ -339,17 +351,21 @@
}
}

#ifdef VISP_HAVE_DISPLAY
vpDisplay::displayText(I, 20, 20, "Click to quit.", vpColor::red);
vpDisplay::flush(I);

if (display_on && save_image) {
vpDisplay::getImage(I, O);
vpImageIo::write(O, "image.png");
}
if (vpDisplay::getClick(I, false))
if (vpDisplay::getClick(I, false)) {
break;
}
#endif
}


if (!serial_off) {
serial->write("LED_RING=0,0,0,0\n"); // Switch off all led
}
Expand Down
Loading
Loading