ViSP  2.6.2
HelloWorldOgre.cpp
1 /****************************************************************************
2  *
3  * $Id: HelloWorldOgre.cpp 3619 2012-03-09 17:28:57Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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  * Description:
34  * Ogre example.
35  *
36  * Authors:
37  * Bertrand Delabarre
38  *
39  *****************************************************************************/
47 #include <visp/vpOpenCVGrabber.h>
48 #include <visp/vpV4l2Grabber.h>
49 #include <visp/vp1394TwoGrabber.h>
50 #include <visp/vpDirectShowGrabber.h>
51 #include <visp/vpHomogeneousMatrix.h>
52 #include <visp/vpImage.h>
53 #include <visp/vpCameraParameters.h>
54 #include <visp/vpAROgre.h>
55 
56 int main()
57 {
58 #if defined(VISP_HAVE_OGRE)
59 
60  // Now we try to find an available framegrabber
61 #if defined(VISP_HAVE_V4L2)
62  // Video for linux 2 grabber
63  vpV4l2Grabber grabber;
64 #elif defined(VISP_HAVE_DC1394_2)
65  // libdc1394-2
66  vp1394TwoGrabber grabber;
67 #elif defined(VISP_HAVE_DIRECTSHOW)
68  // OpenCV to gather images
69  vpOpenCVGrabber grabber;
70 #elif defined(VISP_HAVE_OPENCV)
71  // OpenCV to gather images
72  vpOpenCVGrabber grabber;
73 #else
74 # error "You need an available framegrabber to run this example"
75 #endif
76 
77  // Image to stock gathered data
78  // Here we acquire a color image. The consequence will be that
79  // the background texture used in Ogre renderer will be also in color.
81  // Open frame grabber
82  // Here we acquire an image from an available framegrabber to update
83  // the image size
84  grabber.open(I);
85 
86  // Parameters of our camera
87  double px = 565;
88  double py = 565;
89  double u0 = grabber.getWidth() / 2;
90  double v0 = grabber.getHeight() / 2;
91  vpCameraParameters cam(px,py,u0,v0);
92  // The matrix with our pose
93  // Defines the pose of the object in the camera frame
95 
96  // Our object
97  // A simulator with the camera parameters defined above,
98  // a grey level background image and of the good size
99  vpAROgre ogre(cam, (unsigned int)grabber.getWidth(), (unsigned int)grabber.getHeight());
100  // Initialisation
101  // Here we load the requested plugins specified in the "plugins.cfg" file
102  // and the resources specified in the "resources.cfg" file
103  // These two files can be found respectively in ViSP_HAVE_OGRE_PLUGINS_PATH
104  // and ViSP_HAVE_OGRE_RESOURCES_PATH folders
105  ogre.init(I);
106 
107  // Create a basic scene
108  // -----------------------------------
109  // Loading things
110  // -----------------------------------
111  // As you will see in section 5, our
112  // application knows locations where
113  // it can search for medias.
114  // Here we use a mesh included in
115  // the installation files : a robot.
116  // -----------------------------------
117  // Here we load the "robot.mesh" model that is found thanks to the ressources locations
118  // specified in the "resources.cfg" file
119  ogre.load("Robot", "robot.mesh");
120  ogre.setPosition("Robot", vpTranslationVector(0, 0.05, 0.5));
121  ogre.setScale("Robot", 0.001f,0.001f,0.001f);
122  ogre.setRotation("Robot", vpRotationMatrix(vpRxyzVector(M_PI, -M_PI/4, 0)));
123 
124 
125  // Rendering loop, ended with on escape
126  while(ogre.continueRendering()){
127  // Image Acquisition
128  // Acquire a new image
129  grabber.acquire(I);
130  //Pose computation
131  // ...
132  // cMo updated
133  // Display the robot at the position specified by cMo with vpAROgre
134  ogre.display(I,cMo);
135  }
136  // Release video device
137  grabber.close();
138 #endif
139 }
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
The vpRotationMatrix considers the particular case of a rotation matrix.
virtual void init(vpImage< unsigned char > &I, bool bufferedKeys=false)
Definition: vpAROgre.cpp:125
unsigned int getWidth() const
Return the number of columns in the image.
Generic class defining intrinsic camera parameters.
Class for the Video4Linux2 video device.
void acquire(vpImage< unsigned char > &I)
Class that consider the case of the Euler angle using the x-y-z convention, where are respectively ...
Definition: vpRxyzVector.h:152
Class for firewire ieee1394 video devices using libdc1394-2.x api.
Class that consider the case of a translation vector.
unsigned int getHeight() const
Return the number of rows in the image.
Class for cameras video capture using OpenCV library.