Visual Servoing Platform  version 3.6.1 under development (2024-10-18)
vpDisplayFactory.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Display Factory
33  */
34 
35 #ifndef VP_DISPLAY_FACTORY_H
36 #define VP_DISPLAY_FACTORY_H
37 
38 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpDisplay.h>
40 #include <visp3/gui/vpDisplayD3D.h>
41 #include <visp3/gui/vpDisplayGDI.h>
42 #include <visp3/gui/vpDisplayGTK.h>
43 #include <visp3/gui/vpDisplayOpenCV.h>
44 #include <visp3/gui/vpDisplayX.h>
45 
46 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
47 #include <memory>
48 #endif
49 
50 BEGIN_VISP_NAMESPACE
55 {
64 {
65 #if defined(VISP_HAVE_DISPLAY)
66 #ifdef VISP_HAVE_X11
67  return new vpDisplayX();
68 #elif defined(VISP_HAVE_D3D9)
69  return new vpDisplayD3D();
70 #elif defined(VISP_HAVE_GDI)
71  return new vpDisplayGDI();
72 #elif defined(VISP_HAVE_GTK)
73  return new vpDisplayGTK();
74 #elif defined(HAVE_OPENCV_HIGHGUI)
75  return new vpDisplayOpenCV();
76 #endif
77 #else
78  return nullptr;
79 #endif
80 }
81 
103 template<typename T>
104 vpDisplay *allocateDisplay(vpImage<T> &I, const int winx = -1, const int winy = -1, const std::string &title = "",
106 {
107 #if defined(VISP_HAVE_DISPLAY)
108 #ifdef VISP_HAVE_X11
109  return new vpDisplayX(I, winx, winy, title, scaleType);
110 #elif defined(VISP_HAVE_GDI)
111  return new vpDisplayGDI(I, winx, winy, title, scaleType);
112 #elif defined(HAVE_OPENCV_HIGHGUI)
113  return new vpDisplayOpenCV(I, winx, winy, title, scaleType);
114 #elif defined(VISP_HAVE_GTK)
115  return new vpDisplayGTK(I, winx, winy, title, scaleType);
116 #elif defined(VISP_HAVE_D3D9)
117  return new vpDisplayD3D(I, winx, winy, title, scaleType);
118 #endif
119 #else
120  (void)I;
121  (void)winx;
122  (void)winy;
123  (void)title;
124  (void)scaleType;
125  return nullptr;
126 #endif
127 }
128 
129 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
137 inline std::shared_ptr<vpDisplay> createDisplay()
138 {
139 #if defined(VISP_HAVE_DISPLAY)
140 #ifdef VISP_HAVE_X11
141  return std::make_shared<vpDisplayX>();
142 #elif defined(VISP_HAVE_GDI)
143  return std::make_shared<vpDisplayGDI>();
144 #elif defined(HAVE_OPENCV_HIGHGUI)
145  return std::make_shared<vpDisplayOpenCV>();
146 #elif defined(VISP_HAVE_GTK)
147  return std::make_shared<vpDisplayGTK>();
148 #elif defined(VISP_HAVE_D3D9)
149  return std::make_shared<vpDisplayD3D>();
150 #endif
151 #else
152  return std::shared_ptr<vpDisplay>(nullptr);
153 #endif
154 }
155 
176 template<typename T>
177 std::shared_ptr<vpDisplay> createDisplay(vpImage<T> &I, const int winx = -1, const int winy = -1,
178  const std::string &title = "",
180 {
181 #if defined(VISP_HAVE_DISPLAY)
182 #ifdef VISP_HAVE_X11
183  return std::make_shared<vpDisplayX>(I, winx, winy, title, scaleType);
184 #elif defined(VISP_HAVE_GDI)
185  return std::make_shared<vpDisplayGDI>(I, winx, winy, title, scaleType);
186 #elif defined(HAVE_OPENCV_HIGHGUI)
187  return std::make_shared<vpDisplayOpenCV>(I, winx, winy, title, scaleType);
188 #elif defined(VISP_HAVE_GTK)
189  return std::make_shared<vpDisplayGTK>(I, winx, winy, title, scaleType);
190 #elif defined(VISP_HAVE_D3D9)
191  return std::make_shared<vpDisplayD3D>(I, winx, winy, title, scaleType);
192 #endif
193 #else
194  (void)I;
195  (void)winx;
196  (void)winy;
197  (void)title;
198  (void)scaleType;
199  return nullptr;
200  return std::shared_ptr<vpDisplay>(nullptr);
201 #endif
202 }
203 
204 namespace impl
205 {
207 {
208  unsigned int rows;
209  unsigned int cols;
210  unsigned int startY;
211  unsigned int startX;
212  unsigned int paddingX;
213  unsigned int paddingY;
214 };
215 
216 inline void makeDisplayGridHelper(std::vector<std::shared_ptr<vpDisplay>> &res, const GridSettings &settings,
217  unsigned int currRow, unsigned int currCol,
218  unsigned int currentPixelX, unsigned int currentPixelY,
219  unsigned int maxRowHeightPixel)
220 {
221  if (currRow != (settings.rows - 1) && (currCol != settings.cols - 1)) {
222  throw vpException(vpException::dimensionError, "Too few images for the grid size");
223  }
224  (void)res;
225  (void)settings;
226  (void)currRow;
227  (void)currCol;
228  (void)currentPixelX;
229  (void)currentPixelY;
230  (void)maxRowHeightPixel;
231 }
232 
233 template <typename T, typename... Args>
234 void makeDisplayGridHelper(std::vector<std::shared_ptr<vpDisplay>> &res, const GridSettings &settings,
235  unsigned int currRow, unsigned int currCol,
236  unsigned int currentPixelX, unsigned int currentPixelY,
237  const unsigned int maxRowHeightPixel,
238  const std::string &name, vpImage<T> &I, Args&... args)
239 {
240  if (currRow >= settings.rows) {
241  throw vpException(vpException::dimensionError, "Too many images for the grid size");
242  }
243  if (currCol == settings.cols) {
244  makeDisplayGridHelper(res, settings, currRow + 1, 0, settings.startX,
245  currentPixelY + maxRowHeightPixel + settings.paddingY, 0, name, I, args...);
246  }
247  else {
248  std::shared_ptr<vpDisplay> display = vpDisplayFactory::createDisplay(I, currentPixelX, currentPixelY, name);
250  vpDisplay::flush(I);
251  res.push_back(display);
252  makeDisplayGridHelper(res, settings, currRow, currCol + 1, currentPixelX + I.getWidth() + settings.paddingX,
253  currentPixelY, std::max(maxRowHeightPixel, I.getHeight()), args...);
254  }
255 }
256 }
257 
278 template <typename... Args>
279 std::vector<std::shared_ptr<vpDisplay>> makeDisplayGrid(unsigned int rows, unsigned int cols,
280  unsigned int startX, unsigned int startY,
281  unsigned int paddingX, unsigned int paddingY,
282  Args&... args)
283 {
284  std::vector<std::shared_ptr<vpDisplay>> res;
285  impl::GridSettings settings;
286  settings.rows = rows;
287  settings.cols = cols;
288  settings.paddingX = paddingX;
289  settings.paddingY = paddingY;
290  settings.startX = startX;
291  settings.startY = startY;
292  makeDisplayGridHelper(res, settings, 0, 0, settings.startX, settings.startY, 0, args...);
293  return res;
294 }
295 #endif
296 }
297 
298 END_VISP_NAMESPACE
299 #endif
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Definition: vpDisplayD3D.h:106
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:130
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:133
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
@ SCALE_DEFAULT
Definition: vpDisplay.h:205
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
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
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...