ViSP  2.10.0
vpAR.cpp
1 /****************************************************************************
2  *
3  * $Id: vpAR.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Use to display an image behind the internal view of the simulator
36  * used for augmented reality application
37  *
38  * Authors:
39  * Eric Marchand
40  * Fabien Spindler
41  *
42  *****************************************************************************/
43 
49 #include <visp/vpConfig.h>
50 
51 #ifdef VISP_HAVE_COIN_AND_GUI
52 
53 #include <visp/vpAR.h>
54 #include <visp/vpTime.h>
55 
56 
57 /* Objets OIV. */
58 #include <Inventor/nodes/SoCone.h> /* Objet cone. */
59 #include <Inventor/nodes/SoCylinder.h> /* Objet cylindre. */
60 #include <Inventor/nodes/SoPointLight.h> /* Objet lumiere ponctuelle. */
61 #include <Inventor/nodes/SoCoordinate3.h> /* Liste de points. */
62 #include <Inventor/nodes/SoIndexedFaceSet.h> /* Liste de face. */
63 #include <Inventor/nodes/SoTranslation.h> /* Trasnfo translation. */
64 #include <Inventor/nodes/SoScale.h> /* Trasnfo mise a l'echelle. */
65 #include <Inventor/nodes/SoRotationXYZ.h> /* Transfo rotation simple. */
66 
67 #include <Inventor/nodes/SoDirectionalLight.h> /* Objet lumiere directionnelle*/
68 #include <Inventor/nodes/SoMaterial.h> /* Matiere (couleur) des objets. */
69 #include <Inventor/nodes/SoDrawStyle.h> /* Style de rendu. */
70 #include <Inventor/nodes/SoEnvironment.h> /* Eclairage ambiant. */
71 #include <Inventor/nodes/SoGroup.h> /* Groupement de noeuds (sans separation)*/
72 #include <Inventor/actions/SoWriteAction.h>
73 
74 
75 
80 {
81  kill() ;
82 }
83 
84 
92 void
93 vpAR::initInternalViewer(const unsigned int width, const unsigned int height, vpImageType type)
94 {
95 
96  vpSimulator::initInternalViewer(width,height) ;
97 
98 
99  // no image is loaded
100  background = false ;
101 
102  if ( image_background != NULL)
103  {
104  free(image_background) ;
105  image_background = NULL ;
106  }
107 
108  typeImage = type;
109  if (typeImage == grayImage)
110  image_background =(GLubyte *)
111  malloc(internal_width*internal_height*sizeof(GLubyte)) ;
112  else
113  image_background =(GLubyte *)
114  malloc(3*internal_width*internal_height*sizeof(GLubyte)) ;
115 
116 }
117 
118 
119 
125 // Grey pictures SetBackGroundImage
126 void
128 {
129 
130  if ((internal_width != I.getWidth()) ||
131  (internal_height != I.getHeight()))
132  {
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 
138  background = true ;
139 
140 
141  for (unsigned int i=0 ; i < I.getHeight() ; i++)
142  for (unsigned int j=0 ; j < I.getWidth() ; j++)
143  //le repere image open GL est en bas a gauche donc l'image serait inverse
144  image_background[i*I.getWidth()+j] = I[I.getHeight()-i-1][j] ;
145 
146 }
147 
148 
149 
155 // Color pictures SetBackGroundImage
156 void
158 {
159 
160  if ((internal_width != I.getWidth()) ||
161  (internal_height != I.getHeight()))
162  {
163  vpERROR_TRACE("The image size is different from the view size ");
164  throw(vpException(vpException::dimensionError),"The image size is different from the view size") ;
165  }
166 
167 
168  background = true ;
169 
170  unsigned int k =0 ;
171  for (unsigned int i=0 ; i <I.getHeight() ; i++)
172  {
173  k=0;
174  for (unsigned int j=0 ; j <I.getWidth() ; j++)
175  //le repere image open GL est en bas a gauche donc l'image serait inverse
176  {
177  image_background[i*I.getWidth()*3+k+0]=I[I.getHeight()-i-1][j].R ;
178  image_background[i*I.getWidth()*3+k+1]=I[I.getHeight()-i-1][j].G ;
179  image_background[i*I.getWidth()*3+k+2]=I[I.getHeight()-i-1][j].B ;
180  k+=3;
181  }
182  }
183 
184 }
185 
186 #endif
187 
188 /*
189  * Local variables:
190  * c-basic-offset: 2
191  * End:
192  */
virtual void initInternalViewer(const unsigned int nlig, const unsigned int ncol)
initialize the camera view
void setImage(vpImage< unsigned char > &I)
Definition: vpAR.cpp:127
virtual ~vpAR()
Definition: vpAR.cpp:79
void kill()
perform some destruction
unsigned int getWidth() const
Definition: vpImage.h:161
void initInternalViewer(const unsigned int width, const unsigned int height, vpImageType type=grayImage)
Definition: vpAR.cpp:93
#define vpERROR_TRACE
Definition: vpDebug.h:395
error that can be emited by ViSP classes.
Definition: vpException.h:76
vpImageType typeImage
Definition: vpSimulator.h:135
GLubyte * image_background
Definition: vpSimulator.h:137
unsigned int internal_width
Definition: vpSimulator.h:169
unsigned int getHeight() const
Definition: vpImage.h:152
unsigned int internal_height
Definition: vpSimulator.h:170