Visual Servoing Platform version 3.5.0
vpAR.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 * Use to display an image behind the internal view of the simulator
33 * used for augmented reality application
34 *
35 * Authors:
36 * Eric Marchand
37 * Fabien Spindler
38 *
39 *****************************************************************************/
40
47#include <visp3/core/vpConfig.h>
48
49#ifdef VISP_HAVE_COIN3D_AND_GUI
50
51#include <visp3/ar/vpAR.h>
52#include <visp3/core/vpTime.h>
53
54/* Objets OIV. */
55#include <Inventor/nodes/SoCone.h> /* Objet cone. */
56#include <Inventor/nodes/SoCoordinate3.h> /* Liste de points. */
57#include <Inventor/nodes/SoCylinder.h> /* Objet cylindre. */
58#include <Inventor/nodes/SoIndexedFaceSet.h> /* Liste de face. */
59#include <Inventor/nodes/SoPointLight.h> /* Objet lumiere ponctuelle. */
60#include <Inventor/nodes/SoRotationXYZ.h> /* Transfo rotation simple. */
61#include <Inventor/nodes/SoScale.h> /* Trasnfo mise a l'echelle. */
62#include <Inventor/nodes/SoTranslation.h> /* Trasnfo translation. */
63
64#include <Inventor/actions/SoWriteAction.h>
65#include <Inventor/nodes/SoDirectionalLight.h> /* Objet lumiere directionnelle*/
66#include <Inventor/nodes/SoDrawStyle.h> /* Style de rendu. */
67#include <Inventor/nodes/SoEnvironment.h> /* Eclairage ambiant. */
68#include <Inventor/nodes/SoGroup.h> /* Groupement de noeuds (sans separation)*/
69#include <Inventor/nodes/SoMaterial.h> /* Matiere (couleur) des objets. */
70
76
84void vpAR::initInternalViewer(unsigned int width, unsigned int height, vpImageType type)
85{
86
88
89 // no image is loaded
90 background = false;
91
92 if (image_background != NULL) {
93 free(image_background);
94 image_background = NULL;
95 }
96
97 typeImage = type;
98 if (typeImage == grayImage)
99 image_background = (GLubyte *)malloc(internal_width * internal_height * sizeof(GLubyte));
100 else
101 image_background = (GLubyte *)malloc(3 * internal_width * internal_height * sizeof(GLubyte));
102}
103
109// Grey pictures SetBackGroundImage
111{
112
113 if ((internal_width != I.getWidth()) || (internal_height != I.getHeight())) {
114 vpERROR_TRACE("The image size is different from the view size ");
115 throw(vpException(vpException::dimensionError), "The image size is different from the view size");
116 }
117
118 background = true;
119
120 for (unsigned int i = 0; i < I.getHeight(); i++)
121 for (unsigned int j = 0; j < I.getWidth(); j++)
122 // le repere image open GL est en bas a gauche donc l'image serait
123 // inverse
124 image_background[i * I.getWidth() + j] = I[I.getHeight() - i - 1][j];
125}
126
132// Color pictures SetBackGroundImage
134{
135
136 if ((internal_width != I.getWidth()) || (internal_height != I.getHeight())) {
137 vpERROR_TRACE("The image size is different from the view size ");
138 throw(vpException(vpException::dimensionError), "The image size is different from the view size");
139 }
140
141 background = true;
142
143 for (unsigned int i = 0; i < I.getHeight(); i++) {
144 unsigned int k = 0;
145 for (unsigned int j = 0; j < I.getWidth(); j++)
146 // le repere image open GL est en bas a gauche donc l'image serait inverse
147 {
148 image_background[i * I.getWidth() * 3 + k + 0] = I[I.getHeight() - i - 1][j].R;
149 image_background[i * I.getWidth() * 3 + k + 1] = I[I.getHeight() - i - 1][j].G;
150 image_background[i * I.getWidth() * 3 + k + 2] = I[I.getHeight() - i - 1][j].B;
151 k += 3;
152 }
153 }
154}
155
156#elif !defined(VISP_BUILD_SHARED_LIBS)
157// Work arround to avoid warning: libvisp_ar.a(vpAR.cpp.o) has no symbols
158void dummy_vpAR(){};
159#endif
void setImage(vpImage< unsigned char > &I)
Definition: vpAR.cpp:110
void initInternalViewer(unsigned int width, unsigned int height, vpImageType type=grayImage)
Definition: vpAR.cpp:84
virtual ~vpAR()
Definition: vpAR.cpp:75
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ dimensionError
Bad dimension.
Definition: vpException.h:95
unsigned int getWidth() const
Definition: vpImage.h:246
unsigned int getHeight() const
Definition: vpImage.h:188
unsigned int internal_height
Definition: vpSimulator.h:164
GLubyte * image_background
Definition: vpSimulator.h:131
void kill()
perform some destruction
unsigned int internal_width
Definition: vpSimulator.h:163
vpImageType typeImage
Definition: vpSimulator.h:129
virtual void initInternalViewer(unsigned int nlig, unsigned int ncol)
initialize the camera view
#define vpERROR_TRACE
Definition: vpDebug.h:393