Visual Servoing Platform  version 3.6.1 under development (2024-04-26)
vpDisplay.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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  * Image display.
33  *
34 *****************************************************************************/
35 
36 #include <limits>
37 
38 #include <visp3/core/vpDisplay.h>
39 #include <visp3/core/vpDisplayException.h>
40 #include <visp3/core/vpImageConvert.h>
41 
42 #include <visp3/core/vpMath.h>
43 #include <visp3/core/vpMeterPixelConversion.h>
44 #include <visp3/core/vpPoint.h>
45 
55  : m_displayHasBeenInitialized(false), m_windowXPosition(0), m_windowYPosition(0), m_width(0), m_height(0), m_title(),
56  m_scale(1), m_scaleType(SCALE_DEFAULT)
57 { }
58 
63  : m_displayHasBeenInitialized(d.m_displayHasBeenInitialized), m_windowXPosition(d.m_windowXPosition),
64  m_windowYPosition(d.m_windowYPosition), m_width(d.m_width), m_height(d.m_height), m_title(d.m_title),
65  m_scale(d.m_scale), m_scaleType(d.m_scaleType)
66 { }
67 
72 
139 {
140  if (Isrc.display != nullptr) {
141  (Isrc.display)->getImage(Idest);
142  }
143  else {
144  vpImageConvert::convert(Isrc, Idest);
145  }
146 }
147 
213 {
214  if (Isrc.display != nullptr) {
215  (Isrc.display)->getImage(Idest);
216  }
217  else {
218  Idest = Isrc;
219  }
220 }
221 
227 void vpDisplay::setDownScalingFactor(unsigned int scale)
228 {
230  m_scale = scale;
231  }
232  else {
233  std::cout << "Warning: Cannot apply the down scaling factor " << scale
234  << " to the display window since the display is initialized yet..." << std::endl;
235  }
236 }
237 
243 unsigned int vpDisplay::computeAutoScale(unsigned int width, unsigned int height)
244 {
245  unsigned int screen_width, screen_height;
246  getScreenSize(screen_width, screen_height);
247  double wscale = std::max<double>(1., ceil((2. * static_cast<double>(width)) / static_cast<double>(screen_width)));
248  double hscale = std::max<double>(1., ceil((2. * static_cast<double>(height)) / static_cast<double>(screen_height)));
249  unsigned int scale = std::max<unsigned int>(1u, std::max<unsigned int>(static_cast<unsigned int>(wscale), static_cast<unsigned int>(hscale)));
250  return scale;
251 }
252 
256 void vpDisplay::setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
257 {
258  switch (scaleType) {
260  setDownScalingFactor(computeAutoScale(width, height));
261  break;
263  case vpDisplay::SCALE_1:
264  break;
265  case vpDisplay::SCALE_2:
267  break;
268  case vpDisplay::SCALE_3:
270  break;
271  case vpDisplay::SCALE_4:
273  break;
274  case vpDisplay::SCALE_5:
276  break;
277  case vpDisplay::SCALE_6:
279  break;
280  case vpDisplay::SCALE_7:
282  break;
283  case vpDisplay::SCALE_8:
285  break;
286  case vpDisplay::SCALE_9:
288  break;
289  case vpDisplay::SCALE_10:
291  break;
292  default:
293  {
294  std::cout << "undefined scaleType" << std::endl;
295  }
296  }
297 }
298 
326 {
328  m_scaleType = scaleType;
329  }
330 }
Class that defines generic functionalities for display.
Definition: vpDisplay.h:173
vpScaleType m_scaleType
Definition: vpDisplay.h:215
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:227
virtual ~vpDisplay()
Definition: vpDisplay.cpp:71
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:138
unsigned int m_scale
Definition: vpDisplay.h:214
@ SCALE_AUTO
Definition: vpDisplay.h:179
@ SCALE_DEFAULT
Definition: vpDisplay.h:200
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:206
unsigned int computeAutoScale(unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:243
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:256
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
vpDisplay * display
Definition: vpImage.h:140