Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDisplayFactory.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Display Factory
32 */
33
34#ifndef VP_DISPLAY_FACTORY_H
35#define VP_DISPLAY_FACTORY_H
36
37#include <visp3/core/vpConfig.h>
38#include <visp3/core/vpDisplay.h>
39#include <visp3/gui/vpDisplayD3D.h>
40#include <visp3/gui/vpDisplayGDI.h>
41#include <visp3/gui/vpDisplayGTK.h>
42#include <visp3/gui/vpDisplayOpenCV.h>
43#include <visp3/gui/vpDisplayX.h>
44
45#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
46#include <memory>
47#endif
48
49#if defined(__clang__)
50// Mute warning : '\tparam' command used in a comment that is not attached to a template declaration [-Wdocumentation]
51# pragma clang diagnostic push
52# pragma clang diagnostic ignored "-Wexit-time-destructors"
53#endif
54
60{
69{
70#if defined(VISP_HAVE_DISPLAY)
71#ifdef VISP_HAVE_X11
72 return new vpDisplayX();
73#elif defined(VISP_HAVE_D3D9)
74 return new vpDisplayD3D();
75#elif defined(VISP_HAVE_GDI)
76 return new vpDisplayGDI();
77#elif defined(VISP_HAVE_GTK)
78 return new vpDisplayGTK();
79#elif defined(HAVE_OPENCV_HIGHGUI)
80 return new vpDisplayOpenCV();
81#endif
82#else
83 return nullptr;
84#endif
85}
86
108template<typename T>
109vpDisplay *allocateDisplay(vpImage<T> &I, const int winx = -1, const int winy = -1, const std::string &title = "",
111{
112#if defined(VISP_HAVE_DISPLAY)
113#ifdef VISP_HAVE_X11
114 return new vpDisplayX(I, winx, winy, title, scaleType);
115#elif defined(VISP_HAVE_GDI)
116 return new vpDisplayGDI(I, winx, winy, title, scaleType);
117#elif defined(HAVE_OPENCV_HIGHGUI)
118 return new vpDisplayOpenCV(I, winx, winy, title, scaleType);
119#elif defined(VISP_HAVE_GTK)
120 return new vpDisplayGTK(I, winx, winy, title, scaleType);
121#elif defined(VISP_HAVE_D3D9)
122 return new vpDisplayD3D(I, winx, winy, title, scaleType);
123#endif
124#else
125 (void)I;
126 (void)winx;
127 (void)winy;
128 (void)title;
129 (void)scaleType;
130 return nullptr;
131#endif
132}
133
134#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
142inline std::shared_ptr<vpDisplay> createDisplay()
143{
144#if defined(VISP_HAVE_DISPLAY)
145#ifdef VISP_HAVE_X11
146 return std::make_shared<vpDisplayX>();
147#elif defined(VISP_HAVE_GDI)
148 return std::make_shared<vpDisplayGDI>();
149#elif defined(HAVE_OPENCV_HIGHGUI)
150 return std::make_shared<vpDisplayOpenCV>();
151#elif defined(VISP_HAVE_GTK)
152 return std::make_shared<vpDisplayGTK>();
153#elif defined(VISP_HAVE_D3D9)
154 return std::make_shared<vpDisplayD3D>();
155#endif
156#else
157 return std::shared_ptr<vpDisplay>(nullptr);
158#endif
159}
160
181template<typename T>
182std::shared_ptr<vpDisplay> createDisplay(vpImage<T> &I, const int winx = -1, const int winy = -1,
183 const std::string &title = "",
185{
186#if defined(VISP_HAVE_DISPLAY)
187#ifdef VISP_HAVE_X11
188 return std::make_shared<vpDisplayX>(I, winx, winy, title, scaleType);
189#elif defined(VISP_HAVE_GDI)
190 return std::make_shared<vpDisplayGDI>(I, winx, winy, title, scaleType);
191#elif defined(HAVE_OPENCV_HIGHGUI)
192 return std::make_shared<vpDisplayOpenCV>(I, winx, winy, title, scaleType);
193#elif defined(VISP_HAVE_GTK)
194 return std::make_shared<vpDisplayGTK>(I, winx, winy, title, scaleType);
195#elif defined(VISP_HAVE_D3D9)
196 return std::make_shared<vpDisplayD3D>(I, winx, winy, title, scaleType);
197#endif
198#else
199 (void)I;
200 (void)winx;
201 (void)winy;
202 (void)title;
203 (void)scaleType;
204 return nullptr;
205 return std::shared_ptr<vpDisplay>(nullptr);
206#endif
207}
208
209namespace impl
210{
212{
213 unsigned int rows;
214 unsigned int cols;
215 unsigned int startY;
216 unsigned int startX;
217 unsigned int paddingX;
218 unsigned int paddingY;
219};
220
221inline void makeDisplayGridHelper(std::vector<std::shared_ptr<vpDisplay>> &res, const GridSettings &settings,
222 unsigned int currRow, unsigned int currCol,
223 unsigned int currentPixelX, unsigned int currentPixelY,
224 unsigned int maxRowHeightPixel)
225{
226 if (currRow != (settings.rows - 1) && (currCol != settings.cols - 1)) {
227 throw vpException(vpException::dimensionError, "Too few images for the grid size");
228 }
229 (void)res;
230 (void)settings;
231 (void)currRow;
232 (void)currCol;
233 (void)currentPixelX;
234 (void)currentPixelY;
235 (void)maxRowHeightPixel;
236}
237
238template <typename T, typename... Args>
239void makeDisplayGridHelper(std::vector<std::shared_ptr<vpDisplay>> &res, const GridSettings &settings,
240 unsigned int currRow, unsigned int currCol,
241 unsigned int currentPixelX, unsigned int currentPixelY,
242 const unsigned int maxRowHeightPixel,
243 const std::string &name, vpImage<T> &I, Args&... args)
244{
245 if (currRow >= settings.rows) {
246 throw vpException(vpException::dimensionError, "Too many images for the grid size");
247 }
248 if (currCol == settings.cols) {
249 makeDisplayGridHelper(res, settings, currRow + 1, 0, settings.startX,
250 currentPixelY + maxRowHeightPixel + settings.paddingY, 0, name, I, args...);
251 }
252 else {
253 std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay(I, currentPixelX, currentPixelY, name);
256 res.push_back(display);
257 makeDisplayGridHelper(res, settings, currRow, currCol + 1, currentPixelX + I.getWidth() + settings.paddingX,
258 currentPixelY, std::max(maxRowHeightPixel, I.getHeight()), args...);
259 }
260}
261}
262
283template <typename... Args>
284std::vector<std::shared_ptr<vpDisplay>> makeDisplayGrid(unsigned int rows, unsigned int cols,
285 unsigned int startX, unsigned int startY,
286 unsigned int paddingX, unsigned int paddingY,
287 Args&... args)
288{
289 std::vector<std::shared_ptr<vpDisplay>> res;
290 impl::GridSettings settings;
291 settings.rows = rows;
292 settings.cols = cols;
293 settings.paddingX = paddingX;
294 settings.paddingY = paddingY;
295 settings.startX = startX;
296 settings.startY = startY;
297 makeDisplayGridHelper(res, settings, 0, 0, settings.startX, settings.startY, 0, args...);
298 return res;
299}
300#endif
301}
302
303END_VISP_NAMESPACE
304
305#if defined(__clang__)
306# pragma clang diagnostic pop
307#endif
308
309#endif
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:135
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
@ SCALE_DEFAULT
Definition vpDisplay.h:198
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
Definition of the vpImage class member functions.
Definition vpImage.h:131
void makeDisplayGridHelper(std::vector< std::shared_ptr< vpDisplay > > &res, const GridSettings &settings, unsigned int currRow, unsigned int currCol, unsigned int currentPixelX, unsigned int currentPixelY, unsigned int maxRowHeightPixel)
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
std::vector< std::shared_ptr< vpDisplay > > makeDisplayGrid(unsigned int rows, unsigned int cols, unsigned int startX, unsigned int startY, unsigned int paddingX, unsigned int paddingY, Args &... args)
Create a grid of displays, given a set of images. All the displays will be initialized in the correct...