ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
HelloWorldOgre.cpp
1 /****************************************************************************
2  *
3  * $Id: HelloWorldOgre.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  * 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  try {
61 #if defined(VISP_HAVE_OGRE)
62 #if defined(VISP_HAVE_V4L2) || defined(VISP_HAVE_DC1394_2) || defined(VISP_HAVE_DIRECTSHOW) || defined(VISP_HAVE_OPENCV)
63 
64  // Now we try to find an available framegrabber
65 #if defined(VISP_HAVE_V4L2)
66  // Video for linux 2 grabber
67  vpV4l2Grabber grabber;
68 #elif defined(VISP_HAVE_DC1394_2)
69  // libdc1394-2
70  vp1394TwoGrabber grabber;
71 #elif defined(VISP_HAVE_DIRECTSHOW)
72  // OpenCV to gather images
73  vpDirectShowGrabber grabber;
74 #elif defined(VISP_HAVE_OPENCV)
75  // OpenCV to gather images
76  vpOpenCVGrabber grabber;
77 #endif
78 
79  // Image to stock gathered data
80  // Here we acquire a color image. The consequence will be that
81  // the background texture used in Ogre renderer will be also in color.
83  // Open frame grabber
84  // Here we acquire an image from an available framegrabber to update
85  // the image size
86  grabber.open(I);
87  grabber.acquire(I);
88 
89  // Parameters of our camera
90  double px = 565;
91  double py = 565;
92  double u0 = grabber.getWidth() / 2;
93  double v0 = grabber.getHeight() / 2;
94  vpCameraParameters cam(px,py,u0,v0);
95  // The matrix with our pose
96  // Defines the pose of the object in the camera frame
98 
99  // Our object
100  // A simulator with the camera parameters defined above,
101  // a grey level background image and of the good size
102  vpAROgre ogre(cam, (unsigned int)grabber.getWidth(), (unsigned int)grabber.getHeight());
103  // Initialisation
104  // Here we load the requested plugins specified in the "plugins.cfg" file
105  // and the resources specified in the "resources.cfg" file
106  // These two files can be found respectively in ViSP_HAVE_OGRE_PLUGINS_PATH
107  // and ViSP_HAVE_OGRE_RESOURCES_PATH folders
108  ogre.init(I);
109 
110  // Create a basic scene
111  // -----------------------------------
112  // Loading things
113  // -----------------------------------
114  // As you will see in section 5, our
115  // application knows locations where
116  // it can search for medias.
117  // Here we use a mesh included in
118  // the installation files : a robot.
119  // -----------------------------------
120  // Here we load the "robot.mesh" model that is found thanks to the resources locations
121  // specified in the "resources.cfg" file
122  ogre.load("Robot", "robot.mesh");
123  ogre.setPosition("Robot", vpTranslationVector(-0.3, 0.2, 0));
124  ogre.setScale("Robot", 0.001f,0.001f,0.001f);
125  ogre.setRotation("Robot", vpRotationMatrix(vpRxyzVector(M_PI, 0, 0)));
126 
127  cMo[2][3] = 1.; // Z = 1 meter
128 
129  std::cout << "cMo:\n" << cMo << std::endl;
130 
131  // Rendering loop, ended with on escape
132  while(ogre.continueRendering()){
133  // Image Acquisition
134  // Acquire a new image
135  grabber.acquire(I);
136  //Pose computation
137  // ...
138  // cMo updated
139  // Display the robot at the position specified by cMo with vpAROgre
140  ogre.display(I,cMo);
141  }
142  // Release video device
143  grabber.close();
144 #else
145  std::cout << "You need an available framegrabber to run this example" << std::endl;
146 #endif
147 #else
148  std::cout << "You need Ogre3D to run this example" << std::endl;
149 #endif
150  return 0;
151  }
152  catch(vpException e) {
153  std::cout << "Catch an exception: " << e << std::endl;
154  return 1;
155  }
156  catch(...) {
157  std::cout << "Catch an exception " << std::endl;
158  return 1;
159  }
160 }
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
Definition: vpException.h:76
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
class for windows direct show devices
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:135
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.