Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpAR.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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
45 #include <visp3/core/vpConfig.h>
46 
47 #ifdef VISP_HAVE_COIN3D_AND_GUI
48 
49 #include <visp3/ar/vpAR.h>
50 #include <visp3/core/vpTime.h>
51 
52 
53 /* Objets OIV. */
54 #include <Inventor/nodes/SoCone.h> /* Objet cone. */
55 #include <Inventor/nodes/SoCylinder.h> /* Objet cylindre. */
56 #include <Inventor/nodes/SoPointLight.h> /* Objet lumiere ponctuelle. */
57 #include <Inventor/nodes/SoCoordinate3.h> /* Liste de points. */
58 #include <Inventor/nodes/SoIndexedFaceSet.h> /* Liste de face. */
59 #include <Inventor/nodes/SoTranslation.h> /* Trasnfo translation. */
60 #include <Inventor/nodes/SoScale.h> /* Trasnfo mise a l'echelle. */
61 #include <Inventor/nodes/SoRotationXYZ.h> /* Transfo rotation simple. */
62 
63 #include <Inventor/nodes/SoDirectionalLight.h> /* Objet lumiere directionnelle*/
64 #include <Inventor/nodes/SoMaterial.h> /* Matiere (couleur) des objets. */
65 #include <Inventor/nodes/SoDrawStyle.h> /* Style de rendu. */
66 #include <Inventor/nodes/SoEnvironment.h> /* Eclairage ambiant. */
67 #include <Inventor/nodes/SoGroup.h> /* Groupement de noeuds (sans separation)*/
68 #include <Inventor/actions/SoWriteAction.h>
69 
70 
71 
76 {
77  kill() ;
78 }
79 
80 
88 void
89 vpAR::initInternalViewer(const unsigned int width, const unsigned int height, vpImageType type)
90 {
91 
92  vpSimulator::initInternalViewer(width,height) ;
93 
94 
95  // no image is loaded
96  background = false ;
97 
98  if ( image_background != NULL)
99  {
100  free(image_background) ;
101  image_background = NULL ;
102  }
103 
104  typeImage = type;
105  if (typeImage == grayImage)
106  image_background =(GLubyte *)
107  malloc(internal_width*internal_height*sizeof(GLubyte)) ;
108  else
109  image_background =(GLubyte *)
110  malloc(3*internal_width*internal_height*sizeof(GLubyte)) ;
111 
112 }
113 
114 
115 
121 // Grey pictures SetBackGroundImage
122 void
124 {
125 
126  if ((internal_width != I.getWidth()) ||
127  (internal_height != I.getHeight()))
128  {
129  vpERROR_TRACE("The image size is different from the view size ");
130  throw(vpException(vpException::dimensionError),"The image size is different from the view size") ;
131  }
132 
133 
134  background = true ;
135 
136 
137  for (unsigned int i=0 ; i < I.getHeight() ; i++)
138  for (unsigned int j=0 ; j < I.getWidth() ; j++)
139  //le repere image open GL est en bas a gauche donc l'image serait inverse
140  image_background[i*I.getWidth()+j] = I[I.getHeight()-i-1][j] ;
141 
142 }
143 
144 
145 
151 // Color pictures SetBackGroundImage
152 void
154 {
155 
156  if ((internal_width != I.getWidth()) ||
157  (internal_height != I.getHeight()))
158  {
159  vpERROR_TRACE("The image size is different from the view size ");
160  throw(vpException(vpException::dimensionError),"The image size is different from the view size") ;
161  }
162 
163 
164  background = true ;
165 
166  for (unsigned int i=0 ; i <I.getHeight() ; i++)
167  {
168  unsigned int k=0;
169  for (unsigned int j=0 ; j <I.getWidth() ; j++)
170  //le repere image open GL est en bas a gauche donc l'image serait inverse
171  {
172  image_background[i*I.getWidth()*3+k+0]=I[I.getHeight()-i-1][j].R ;
173  image_background[i*I.getWidth()*3+k+1]=I[I.getHeight()-i-1][j].G ;
174  image_background[i*I.getWidth()*3+k+2]=I[I.getHeight()-i-1][j].B ;
175  k+=3;
176  }
177  }
178 
179 }
180 
181 #elif !defined(VISP_BUILD_SHARED_LIBS)
182 // Work arround to avoid warning: libvisp_ar.a(vpAR.cpp.o) has no symbols
183 void dummy_vpAR() {};
184 #endif
virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol)
initialize the camera view
void setImage(vpImage< unsigned char > &I)
Definition: vpAR.cpp:123
virtual ~vpAR()
Definition: vpAR.cpp:75
void kill()
perform some destruction
unsigned int getWidth() const
Definition: vpImage.h:226
void initInternalViewer(const unsigned int width, const unsigned int height, vpImageType type=grayImage)
Definition: vpAR.cpp:89
#define vpERROR_TRACE
Definition: vpDebug.h:391
error that can be emited by ViSP classes.
Definition: vpException.h:73
vpImageType typeImage
Definition: vpSimulator.h:131
GLubyte * image_background
Definition: vpSimulator.h:133
unsigned int internal_width
Definition: vpSimulator.h:165
unsigned int getHeight() const
Definition: vpImage.h:175
unsigned int internal_height
Definition: vpSimulator.h:166