ViSP  2.8.0
HelloWorldOgre.cpp
1 /****************************************************************************
2  *
3  * $Id: HelloWorldOgre.cpp 4111 2013-02-06 17:27:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 <iostream>
48 
49 #include <visp/vpOpenCVGrabber.h>
50 #include <visp/vpV4l2Grabber.h>
51 #include <visp/vp1394TwoGrabber.h>
52 #include <visp/vpDirectShowGrabber.h>
53 #include <visp/vpHomogeneousMatrix.h>
54 #include <visp/vpImage.h>
55 #include <visp/vpCameraParameters.h>
56 #include <visp/vpAROgre.h>
57 
58 int main()
59 {
60 #if defined(VISP_HAVE_OGRE)
61 #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394_2) || defined(VISP_HAVE_DIRECTSHOW) || defined(VISP_HAVE_OPENCV)
62 
63  // Now we try to find an available framegrabber
64 #if defined(VISP_HAVE_V4L2)
65  // Video for linux 2 grabber
66  vpV4l2Grabber grabber;
67 #elif defined(VISP_HAVE_DC1394_2)
68  // libdc1394-2
69  vp1394TwoGrabber grabber;
70 #elif defined(VISP_HAVE_DIRECTSHOW)
71  // OpenCV to gather images
72  vpOpenCVGrabber grabber;
73 #elif defined(VISP_HAVE_OPENCV)
74  // OpenCV to gather images
75  vpOpenCVGrabber grabber;
76 #endif
77 
78  // Image to stock gathered data
79  // Here we acquire a color image. The consequence will be that
80  // the background texture used in Ogre renderer will be also in color.
82  // Open frame grabber
83  // Here we acquire an image from an available framegrabber to update
84  // the image size
85  grabber.open(I);
86 
87  // Parameters of our camera
88  double px = 565;
89  double py = 565;
90  double u0 = grabber.getWidth() / 2;
91  double v0 = grabber.getHeight() / 2;
92  vpCameraParameters cam(px,py,u0,v0);
93  // The matrix with our pose
94  // Defines the pose of the object in the camera frame
96 
97  // Our object
98  // A simulator with the camera parameters defined above,
99  // a grey level background image and of the good size
100  vpAROgre ogre(cam, (unsigned int)grabber.getWidth(), (unsigned int)grabber.getHeight());
101  // Initialisation
102  // Here we load the requested plugins specified in the "plugins.cfg" file
103  // and the resources specified in the "resources.cfg" file
104  // These two files can be found respectively in ViSP_HAVE_OGRE_PLUGINS_PATH
105  // and ViSP_HAVE_OGRE_RESOURCES_PATH folders
106  ogre.init(I);
107 
108  // Create a basic scene
109  // -----------------------------------
110  // Loading things
111  // -----------------------------------
112  // As you will see in section 5, our
113  // application knows locations where
114  // it can search for medias.
115  // Here we use a mesh included in
116  // the installation files : a robot.
117  // -----------------------------------
118  // Here we load the "robot.mesh" model that is found thanks to the resources locations
119  // specified in the "resources.cfg" file
120  ogre.load("Robot", "robot.mesh");
121  ogre.setPosition("Robot", vpTranslationVector(0, 0.05, 0.5));
122  ogre.setScale("Robot", 0.001f,0.001f,0.001f);
123  ogre.setRotation("Robot", vpRotationMatrix(vpRxyzVector(M_PI, -M_PI/4, 0)));
124 
125 
126  // Rendering loop, ended with on escape
127  while(ogre.continueRendering()){
128  // Image Acquisition
129  // Acquire a new image
130  grabber.acquire(I);
131  //Pose computation
132  // ...
133  // cMo updated
134  // Display the robot at the position specified by cMo with vpAROgre
135  ogre.display(I,cMo);
136  }
137  // Release video device
138  grabber.close();
139 #else
140  std::cout << "You need an available framegrabber to run this example" << std::endl;
141 #endif
142 #else
143  std::cout << "You Ogre3D to run this example" << std::endl;
144 #endif
145 }
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, bool hidden=false)
Definition: vpAROgre.cpp:131
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.