Visual Servoing Platform  version 3.6.1 under development (2024-04-19)
vpAR.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  * Use to display an image behind the internal view of the simulator
33  * used for augmented reality application
34  *
35 *****************************************************************************/
36 
43 #include <visp3/core/vpConfig.h>
44 
45 #ifdef VISP_HAVE_COIN3D_AND_GUI
46 
47 #include <visp3/ar/vpAR.h>
48 #include <visp3/core/vpTime.h>
49 
50 /* Objets OIV. */
51 #include <Inventor/nodes/SoCone.h> /* Objet cone. */
52 #include <Inventor/nodes/SoCoordinate3.h> /* Liste de points. */
53 #include <Inventor/nodes/SoCylinder.h> /* Objet cylindre. */
54 #include <Inventor/nodes/SoIndexedFaceSet.h> /* Liste de face. */
55 #include <Inventor/nodes/SoPointLight.h> /* Objet lumiere ponctuelle. */
56 #include <Inventor/nodes/SoRotationXYZ.h> /* Transfo rotation simple. */
57 #include <Inventor/nodes/SoScale.h> /* Trasnfo mise a l'echelle. */
58 #include <Inventor/nodes/SoTranslation.h> /* Trasnfo translation. */
59 
60 #include <Inventor/actions/SoWriteAction.h>
61 #include <Inventor/nodes/SoDirectionalLight.h> /* Objet lumiere directionnelle*/
62 #include <Inventor/nodes/SoDrawStyle.h> /* Style de rendu. */
63 #include <Inventor/nodes/SoEnvironment.h> /* Eclairage ambiant. */
64 #include <Inventor/nodes/SoGroup.h> /* Groupement de noeuds (sans separation)*/
65 #include <Inventor/nodes/SoMaterial.h> /* Matiere (couleur) des objets. */
66 
71 vpAR::~vpAR() { kill(); }
72 
80 void vpAR::initInternalViewer(unsigned int width, unsigned int height, vpImageType type)
81 {
82 
83  vpSimulator::initInternalViewer(width, height);
84 
85  // no image is loaded
86  background = false;
87 
88  if (image_background != nullptr) {
89  free(image_background);
90  image_background = nullptr;
91  }
92 
93  typeImage = type;
94  if (typeImage == grayImage)
95  image_background = (GLubyte *)malloc(internal_width * internal_height * sizeof(GLubyte));
96  else
97  image_background = (GLubyte *)malloc(3 * internal_width * internal_height * sizeof(GLubyte));
98 }
99 
105 // Grey pictures SetBackGroundImage
107 {
108 
109  if ((internal_width != I.getWidth()) || (internal_height != I.getHeight())) {
110  vpERROR_TRACE("The image size is different from the view size ");
111  throw(vpException(vpException::dimensionError), "The image size is different from the view size");
112  }
113 
114  background = true;
115 
116  for (unsigned int i = 0; i < I.getHeight(); i++)
117  for (unsigned int j = 0; j < I.getWidth(); j++)
118  // le repere image open GL est en bas a gauche donc l'image serait
119  // inverse
120  image_background[i * I.getWidth() + j] = I[I.getHeight() - i - 1][j];
121 }
122 
128 // Color pictures SetBackGroundImage
130 {
131 
132  if ((internal_width != I.getWidth()) || (internal_height != I.getHeight())) {
133  vpERROR_TRACE("The image size is different from the view size ");
134  throw(vpException(vpException::dimensionError), "The image size is different from the view size");
135  }
136 
137  background = true;
138 
139  for (unsigned int i = 0; i < I.getHeight(); i++) {
140  unsigned int k = 0;
141  for (unsigned int j = 0; j < I.getWidth(); j++)
142  // le repere image open GL est en bas a gauche donc l'image serait inverse
143  {
144  image_background[i * I.getWidth() * 3 + k + 0] = I[I.getHeight() - i - 1][j].R;
145  image_background[i * I.getWidth() * 3 + k + 1] = I[I.getHeight() - i - 1][j].G;
146  image_background[i * I.getWidth() * 3 + k + 2] = I[I.getHeight() - i - 1][j].B;
147  k += 3;
148  }
149  }
150 }
151 
152 #elif !defined(VISP_BUILD_SHARED_LIBS)
153 // Work around to avoid warning: libvisp_ar.a(vpAR.cpp.o) has no symbols
154 void dummy_vpAR(){};
155 #endif
void setImage(vpImage< unsigned char > &I)
Definition: vpAR.cpp:106
void initInternalViewer(unsigned int width, unsigned int height, vpImageType type=grayImage)
Definition: vpAR.cpp:80
virtual ~vpAR()
Definition: vpAR.cpp:71
error that can be emitted by ViSP classes.
Definition: vpException.h:59
@ dimensionError
Bad dimension.
Definition: vpException.h:83
unsigned int getWidth() const
Definition: vpImage.h:245
unsigned int getHeight() const
Definition: vpImage.h:184
unsigned int internal_height
Definition: vpSimulator.h:163
GLubyte * image_background
Definition: vpSimulator.h:130
void kill()
perform some destruction
unsigned int internal_width
Definition: vpSimulator.h:162
vpImageType typeImage
Definition: vpSimulator.h:128
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
#define vpERROR_TRACE
Definition: vpDebug.h:382