ViSP  2.9.0
vpRobotWireFrameSimulator.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobotWireFrameSimulator.cpp 3530 2012-01-03 10:52:12Z 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  * Basic class used to make robot simulators.
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpConfig.h>
43 
44 
45 
46 #if defined(_WIN32) || defined(VISP_HAVE_PTHREAD)
47 #include <visp/vpRobotWireFrameSimulator.h>
48 #include <visp/vpSimulatorViper850.h>
49 
55  I(), tcur(0), tprev(0), robotArms(NULL), size_fMi(8), fMi(NULL), artCoord(), artVel(), velocity(),
56  /* thread(), attr(), */ mutex_fMi(), mutex_artVel(), mutex_artCoord(), mutex_velocity(), mutex_display(),
57  displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false), singularityManagement(true),
58  cameraParam(),
59 #if defined(VISP_HAVE_DISPLAY)
60  display(),
61 #endif
62  displayType(MODEL_3D), displayAllowed(true), constantSamplingTimeMode(false),
63  setVelocityCalled(false), verbose_(false)
64 {
65  setSamplingTime(0.010);
66  velocity.resize(6);
67  I.resize(480,640);
68  I = 255;
69 #if defined(VISP_HAVE_DISPLAY)
70  display.init(I, 0, 0,"The External view");
71 #endif
72 
73  //pid_t pid = getpid();
74  // setpriority (PRIO_PROCESS, pid, 19);
75 }
76 
83  I(), tcur(0), tprev(0), robotArms(NULL), size_fMi(8), fMi(NULL), artCoord(), artVel(), velocity(),
84  /* thread(), attr(), */ mutex_fMi(), mutex_artVel(), mutex_artCoord(), mutex_velocity(), mutex_display(),
85  displayBusy(false), robotStop(false), jointLimit(false), jointLimitArt(false), singularityManagement(true),
86  cameraParam(),
87 #if defined(VISP_HAVE_DISPLAY)
88  display(),
89 #endif
90  displayType(MODEL_3D), displayAllowed(do_display), constantSamplingTimeMode(false),
91  setVelocityCalled(false), verbose_(false)
92 {
93  setSamplingTime(0.010);
94  velocity.resize(6);
95  I.resize(480,640);
96  I = 255;
97 
98 #if defined(VISP_HAVE_DISPLAY)
99  if (do_display)
100  this->display.init(I, 0, 0,"The External view");
101 #endif
102 
103  //pid_t pid = getpid();
104  // setpriority (PRIO_PROCESS, pid, 19);
105 }
106 
107 
108 
113 {
114 }
115 
125 void
127 {
128  if(displayCamera){
129  free_Bound_scene (&(this->camera));
130  }
131  vpWireFrameSimulator::initScene(obj, desired_object);
132  if(displayCamera){
133  free_Bound_scene (&(this->camera));
134  }
135  displayCamera = false;
136 }
137 
148 void
149 vpRobotWireFrameSimulator::initScene(const char* obj, const char* desired_object)
150 {
151  if(displayCamera){
152  free_Bound_scene (&(this->camera));
153  }
154  vpWireFrameSimulator::initScene(obj, desired_object);
155  if(displayCamera){
156  free_Bound_scene (&(this->camera));
157  }
158  displayCamera = false;
159 }
160 
169 void
171 {
172  if(displayCamera){
173  free_Bound_scene (&(this->camera));
174  }
176  if(displayCamera){
177  free_Bound_scene (&(this->camera));
178  }
179  displayCamera = false;
180 }
181 
190 void
192 {
193  if(displayCamera){
194  free_Bound_scene (&(this->camera));
195  }
197  if(displayCamera){
198  free_Bound_scene (&(this->camera));
199  }
200  displayCamera = false;
201 }
202 
212 void
214 {
215 
216  if (!sceneInitialized)
217  throw;
218 
219  double u;
220  double v;
221  //if(px_int != 1 && py_int != 1)
222  // we assume px_int and py_int > 0
223  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
224  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
225  {
226  u = (double)I_.getWidth()/(2*px_int);
227  v = (double)I_.getHeight()/(2*py_int);
228  }
229  else
230  {
231  u = (double)I_.getWidth()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
232  v = (double)I_.getHeight()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
233  }
234 
235  float o44c[4][4],o44cd[4][4],x,y,z;
236  Matrix id = IDENTITY_MATRIX;
237 
239  get_fMi(fMit);
240  this->cMo = fMit[size_fMi-1].inverse()*fMo;
241  this->cMo = rotz*cMo;
242 
243  vp2jlc_matrix(cMo.inverse(),o44c);
244  vp2jlc_matrix(cdMo.inverse(),o44cd);
245 
246  while (get_displayBusy()) vpTime::wait(2);
247 
248  add_vwstack ("start","cop", o44c[3][0],o44c[3][1],o44c[3][2]);
249  x = o44c[2][0] + o44c[3][0];
250  y = o44c[2][1] + o44c[3][1];
251  z = o44c[2][2] + o44c[3][2];
252  add_vwstack ("start","vrp", x,y,z);
253  add_vwstack ("start","vpn", o44c[2][0],o44c[2][1],o44c[2][2]);
254  add_vwstack ("start","vup", o44c[1][0],o44c[1][1],o44c[1][2]);
255  add_vwstack ("start","window", -u, u, -v, v);
256  if (displayObject)
257  display_scene(id,this->scene,I_, curColor);
258 
259  add_vwstack ("start","cop", o44cd[3][0],o44cd[3][1],o44cd[3][2]);
260  x = o44cd[2][0] + o44cd[3][0];
261  y = o44cd[2][1] + o44cd[3][1];
262  z = o44cd[2][2] + o44cd[3][2];
263  add_vwstack ("start","vrp", x,y,z);
264  add_vwstack ("start","vpn", o44cd[2][0],o44cd[2][1],o44cd[2][2]);
265  add_vwstack ("start","vup", o44cd[1][0],o44cd[1][1],o44cd[1][2]);
266  add_vwstack ("start","window", -u, u, -v, v);
268  {
270  else display_scene(id,desiredScene,I_, desColor);
271  }
272  delete[] fMit;
273  set_displayBusy(false);
274 }
275 
285 void
287 {
288 
289  if (!sceneInitialized)
290  throw;
291 
292  double u;
293  double v;
294  //if(px_int != 1 && py_int != 1)
295  // we assume px_int and py_int > 0
296  if( (std::fabs(px_int-1.) > vpMath::maximum(px_int,1.)*std::numeric_limits<double>::epsilon())
297  && (std::fabs(py_int-1) > vpMath::maximum(py_int,1.)*std::numeric_limits<double>::epsilon()))
298  {
299  u = (double)I.getWidth()/(2*px_int);
300  v = (double)I.getHeight()/(2*py_int);
301  }
302  else
303  {
304  u = (double)I_.getWidth()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
305  v = (double)I_.getHeight()/(vpMath::minimum(I_.getWidth(),I_.getHeight()));
306  }
307 
308  float o44c[4][4],o44cd[4][4],x,y,z;
309  Matrix id = IDENTITY_MATRIX;
310 
312  get_fMi(fMit);
313  this->cMo = fMit[size_fMi-1].inverse()*fMo;
314  this->cMo = rotz*cMo;
315 
316  vp2jlc_matrix(cMo.inverse(),o44c);
317  vp2jlc_matrix(cdMo.inverse(),o44cd);
318 
319  while (get_displayBusy()) vpTime::wait(2);
320 
321  add_vwstack ("start","cop", o44c[3][0],o44c[3][1],o44c[3][2]);
322  x = o44c[2][0] + o44c[3][0];
323  y = o44c[2][1] + o44c[3][1];
324  z = o44c[2][2] + o44c[3][2];
325  add_vwstack ("start","vrp", x,y,z);
326  add_vwstack ("start","vpn", o44c[2][0],o44c[2][1],o44c[2][2]);
327  add_vwstack ("start","vup", o44c[1][0],o44c[1][1],o44c[1][2]);
328  add_vwstack ("start","window", -u, u, -v, v);
329  if (displayObject)
330  {
331  display_scene(id,this->scene,I_, curColor);
332  }
333 
334  add_vwstack ("start","cop", o44cd[3][0],o44cd[3][1],o44cd[3][2]);
335  x = o44cd[2][0] + o44cd[3][0];
336  y = o44cd[2][1] + o44cd[3][1];
337  z = o44cd[2][2] + o44cd[3][2];
338  add_vwstack ("start","vrp", x,y,z);
339  add_vwstack ("start","vpn", o44cd[2][0],o44cd[2][1],o44cd[2][2]);
340  add_vwstack ("start","vup", o44cd[1][0],o44cd[1][1],o44cd[1][2]);
341  add_vwstack ("start","window", -u, u, -v, v);
343  {
345  else display_scene(id,desiredScene,I_, desColor);
346  }
347  delete[] fMit;
348  set_displayBusy(false);
349 }
350 
358 {
359  vpHomogeneousMatrix cMoTemp;
361  get_fMi(fMit);
362  cMoTemp = fMit[size_fMi-1].inverse()*fMo;
363  delete[] fMit;
364  return cMoTemp;
365 }
366 
367 #endif
virtual void get_fMi(vpHomogeneousMatrix *fMit)=0
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
unsigned int getWidth() const
Definition: vpImage.h:159
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
A cylindrical tool is attached to the camera.
vpHomogeneousMatrix cdMo
static int wait(double t0, double t)
Definition: vpTime.cpp:149
vpHomogeneousMatrix fMo
static const vpColor red
Definition: vpColor.h:167
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
This class aims to be a basis used to create all the robot simulators.
void set_displayBusy(const bool &status)
void setSamplingTime(const double &delta_t)
void getInternalView(vpImage< vpRGBa > &I)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
void resize(const unsigned int h, const unsigned int w)
set the size of the image
Definition: vpImage.h:532
vpHomogeneousMatrix cMo
static Type minimum(const Type &a, const Type &b)
Definition: vpMath.h:148
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
vpSceneDesiredObject desiredObject
void display_scene(Matrix mat, Bound_scene &sc, const vpImage< vpRGBa > &I, const vpColor &color)
vpHomogeneousMatrix inverse() const
vpHomogeneousMatrix rotz
unsigned int getHeight() const
Definition: vpImage.h:150
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
Definition: vpDisplayX.cpp:191
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94