Visual Servoing Platform  version 3.6.1 under development (2024-11-21)
vpDisplay.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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  * Image display.
32  *
33 *****************************************************************************/
34 
40 #include <visp3/core/vpDisplay.h>
41 #include <visp3/core/vpDisplayException.h>
42 #include <visp3/core/vpImageConvert.h>
43 
44 #include <visp3/core/vpMath.h>
45 #include <visp3/core/vpMeterPixelConversion.h>
46 #include <visp3/core/vpPoint.h>
47 
48 BEGIN_VISP_NAMESPACE
53  : m_displayHasBeenInitialized(false), m_windowXPosition(0), m_windowYPosition(0), m_width(0), m_height(0), m_title(),
54  m_scale(1), m_scaleType(SCALE_DEFAULT)
55 { }
56 
61  : m_displayHasBeenInitialized(d.m_displayHasBeenInitialized), m_windowXPosition(d.m_windowXPosition),
62  m_windowYPosition(d.m_windowYPosition), m_width(d.m_width), m_height(d.m_height), m_title(d.m_title),
63  m_scale(d.m_scale), m_scaleType(d.m_scaleType)
64 { }
65 
70 
141 {
142  if (Isrc.display != nullptr) {
143  (Isrc.display)->getImage(Idest);
144  }
145  else {
146  vpImageConvert::convert(Isrc, Idest);
147  }
148 }
149 
219 {
220  if (Isrc.display != nullptr) {
221  (Isrc.display)->getImage(Idest);
222  }
223  else {
224  Idest = Isrc;
225  }
226 }
227 
233 void vpDisplay::setDownScalingFactor(unsigned int scale)
234 {
236  m_scale = scale;
237  }
238  else {
239  std::cout << "Warning: Cannot apply the down scaling factor " << scale
240  << " to the display window since the display is initialized yet..." << std::endl;
241  }
242 }
243 
249 unsigned int vpDisplay::computeAutoScale(unsigned int width, unsigned int height)
250 {
251  unsigned int screen_width, screen_height;
252  getScreenSize(screen_width, screen_height);
253  double wscale = std::max<double>(1., ceil((2. * static_cast<double>(width)) / static_cast<double>(screen_width)));
254  double hscale = std::max<double>(1., ceil((2. * static_cast<double>(height)) / static_cast<double>(screen_height)));
255  unsigned int scale = std::max<unsigned int>(1u, std::max<unsigned int>(static_cast<unsigned int>(wscale), static_cast<unsigned int>(hscale)));
256  return scale;
257 }
258 
262 void vpDisplay::setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
263 {
264  switch (scaleType) {
266  setDownScalingFactor(computeAutoScale(width, height));
267  break;
269  case vpDisplay::SCALE_1:
270  break;
271  case vpDisplay::SCALE_2:
273  break;
274  case vpDisplay::SCALE_3:
276  break;
277  case vpDisplay::SCALE_4:
279  break;
280  case vpDisplay::SCALE_5:
282  break;
283  case vpDisplay::SCALE_6:
285  break;
286  case vpDisplay::SCALE_7:
288  break;
289  case vpDisplay::SCALE_8:
291  break;
292  case vpDisplay::SCALE_9:
294  break;
295  case vpDisplay::SCALE_10:
297  break;
298  default:
299  {
300  std::cout << "undefined scaleType" << std::endl;
301  }
302  }
303 }
304 
336 {
338  m_scaleType = scaleType;
339  }
340 }
341 END_VISP_NAMESPACE
Class that defines generic functionalities for display.
Definition: vpDisplay.h:178
vpScaleType m_scaleType
Definition: vpDisplay.h:933
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:233
virtual ~vpDisplay()
Definition: vpDisplay.cpp:69
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:140
unsigned int m_scale
Definition: vpDisplay.h:932
@ SCALE_AUTO
Definition: vpDisplay.h:184
@ SCALE_DEFAULT
Definition: vpDisplay.h:205
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:924
unsigned int computeAutoScale(unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:249
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:262
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
vpDisplay * display
Definition: vpImage.h:136