Visual Servoing Platform  version 3.1.0
vpDisplay.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 http://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  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #include <limits>
41 
42 #include <visp3/core/vpDisplay.h>
43 #include <visp3/core/vpDisplayException.h>
44 #include <visp3/core/vpImageConvert.h>
45 
46 #include <visp3/core/vpMath.h>
47 #include <visp3/core/vpMeterPixelConversion.h>
48 #include <visp3/core/vpPoint.h>
49 
59  : m_displayHasBeenInitialized(false), m_windowXPosition(0), m_windowYPosition(0), m_width(0), m_height(0), m_title(),
60  m_scale(1), m_scaleType(SCALE_DEFAULT)
61 {
62 }
63 
71 {
72 }
73 
78 
145 {
146  if (Isrc.display != NULL) {
147  (Isrc.display)->getImage(Idest);
148  } else {
149  vpImageConvert::convert(Isrc, Idest);
150  }
151 }
152 
219 {
220  if (Isrc.display != NULL) {
221  (Isrc.display)->getImage(Idest);
222  } else {
223  Idest = Isrc;
224  }
225 }
226 
232 void vpDisplay::setDownScalingFactor(unsigned int scale)
233 {
235  m_scale = scale;
236  else {
237  std::cout << "Warning: Cannot apply the down scaling factor " << scale
238  << " to the display window since the display is initialized yet..." << std::endl;
239  }
240 }
241 
247 unsigned int vpDisplay::computeAutoScale(unsigned int width, unsigned int height)
248 {
249  unsigned int screen_width, screen_height;
250  getScreenSize(screen_width, screen_height);
251  double wscale = (std::max)(1., ceil(2. * (double)width / (double)screen_width));
252  double hscale = (std::max)(1., ceil(2. * (double)height / (double)screen_height));
253  unsigned int scale = (unsigned int)(std::max)(1u, (std::max)((unsigned int)wscale, (unsigned int)hscale));
254  return scale;
255 }
256 
260 void vpDisplay::setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
261 {
262  switch (scaleType) {
264  setDownScalingFactor(computeAutoScale(width, height));
265  break;
267  case vpDisplay::SCALE_1:
268  break;
269  case vpDisplay::SCALE_2:
271  break;
272  case vpDisplay::SCALE_3:
274  break;
275  case vpDisplay::SCALE_4:
277  break;
278  case vpDisplay::SCALE_5:
280  break;
281  case vpDisplay::SCALE_6:
283  break;
284  case vpDisplay::SCALE_7:
286  break;
287  case vpDisplay::SCALE_8:
289  break;
290  case vpDisplay::SCALE_9:
292  break;
293  case vpDisplay::SCALE_10:
295  break;
296  }
297 }
298 
326 {
328  m_scaleType = scaleType;
329 }
unsigned int m_height
Definition: vpDisplay.h:210
vpDisplay * display
Definition: vpImage.h:134
int m_windowYPosition
display position
Definition: vpDisplay.h:208
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
unsigned int computeAutoScale(unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:247
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
virtual void setDownScalingFactor(unsigned int scale)
Definition: vpDisplay.cpp:232
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:204
int m_windowXPosition
display position
Definition: vpDisplay.h:206
unsigned int m_scale
Definition: vpDisplay.h:212
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:260
vpScaleType m_scaleType
Definition: vpDisplay.h:213
std::string m_title
Definition: vpDisplay.h:211
virtual ~vpDisplay()
Definition: vpDisplay.cpp:77
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:144
unsigned int m_width
Definition: vpDisplay.h:209