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