Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
odehandle.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __ODEHANDLE_H
25 #define __ODEHANDLE_H
26 
27 #include <selforg/stl_map.h>
28 
29 #include <vector>
30 #include <ode-dbl/common.h>
31 #include "substance.h"
32 
33 namespace lpzrobots {
34 
35 class Primitive;
36 
37 struct geomPairHash{
38  size_t operator() (const std::pair<long, long>& p) const {
39  return 2*p.first + p.second;
40  }
41 };
42 
43 /** Data structure for accessing the ODE */
44 class OdeHandle
45 {
46 public:
47  OdeHandle( );
48  OdeHandle( dWorldID _world, dSpaceID _space, dJointGroupID _jointGroup);
49 
50  dWorldID world;
51  dSpaceID space;
52  dJointGroupID jointGroup;
53 
55 
56  /// creates world at global space and so on and sets global time pointer.
57  void init(double* time);
58 
59  /// deletes the world and global data
60  void close();
61 
62  /** use this function to create a new space with optional ignored collisions,
63  use deleteSpace to destroy it
64 
65  All primitives initialised with this handle are within this space.
66  */
67  void createNewSimpleSpace(dSpaceID parentspace, bool ignore_inside_collisions);
68 
69  /** like createNewSimpleSpace but with a HashSpace. More efficient for large objects
70  */
71  void createNewHashSpace(dSpaceID parentspace, bool ignore_inside_collisions);
72 
73  /// destroys the space and unregisters them in the global lists
74  void deleteSpace();
75 
76  /** adds a space to the list of spaces for collision detection (ignored spaces do not need to be insered)*/
77  void addSpace(dSpaceID g);
78  /// removes a space from the list of ignored spaces for collision detection
79  void removeSpace(dSpaceID g);
80 
81  /** deletes all associated memory objects, handle with care - use only when program exits */
82  void destroySpaces();
83 
84  /// returns list of all spaces (as vector for parallelisation
85  const std::vector<dSpaceID>& getSpaces();
86 
87 
88  inline double getTime(){ return *time; }
89 
90  /// adds a pair of geoms to the list of ignored geom pairs for collision detection
91  void addIgnoredPair(dGeomID g1, dGeomID g2);
92  /// like addIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
93  void addIgnoredPair(Primitive* p1, Primitive* p2);
94  /// removes pair of geoms from the list of ignored geom pairs for collision detection
95  void removeIgnoredPair(dGeomID g1, dGeomID g2);
96  /// like removeIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
97  void removeIgnoredPair(Primitive* p1, Primitive* p2);
98  /// checks whether a pair of geoms is an ignored pair for collision detection
99  inline bool isIgnoredPair(dGeomID g1, dGeomID g2) const {
100  return (ignoredPairs->find(std::pair<long, long>((long)g1,(long)g2)) != ignoredPairs->end())
101  || (ignoredPairs->find(std::pair<long, long>((long)g2,(long)g1)) != ignoredPairs->end());
102  }
103 
104 protected:
105  double* time;
106  //TODO: Destroy the internal containers (vectors, list, ...) within the destructor. Now destroySpaces is used. Maybe we can use QMP_CRITICAL for a ref_cnt-variabel, or avoid the pointers.
107 
108  /// list of spaces, except ignored spaces
109  std::vector<dSpaceID>* spaces;
110 
111  /// set of ignored spaces
112  HashSet<long>* ignoredSpaces;
113 
114  /// set of ignored geom pairs for collision
115  HashSet<std::pair<long,long>, geomPairHash >* ignoredPairs;
116 
117 };
118 
119 }
120 #endif
void addSpace(dSpaceID g)
adds a space to the list of spaces for collision detection (ignored spaces do not need to be insered)...
Definition: odehandle.cpp:106
Data structure for accessing the ODE.
Definition: odehandle.h:44
Physical substance definition, used for collision detection/treatment What we need is mu...
Definition: substance.h:103
size_t operator()(const std::pair< long, long > &p) const
Definition: odehandle.h:38
double getTime()
Definition: odehandle.h:88
void close()
deletes the world and global data
Definition: odehandle.cpp:76
dWorldID world
Definition: odehandle.h:50
HashSet< long > * ignoredSpaces
set of ignored spaces
Definition: odehandle.h:112
void removeIgnoredPair(dGeomID g1, dGeomID g2)
removes pair of geoms from the list of ignored geom pairs for collision detection ...
Definition: odehandle.cpp:141
Substance substance
Definition: odehandle.h:54
void createNewHashSpace(dSpaceID parentspace, bool ignore_inside_collisions)
like createNewSimpleSpace but with a HashSpace.
Definition: odehandle.cpp:92
bool isIgnoredPair(dGeomID g1, dGeomID g2) const
checks whether a pair of geoms is an ignored pair for collision detection
Definition: odehandle.h:99
void createNewSimpleSpace(dSpaceID parentspace, bool ignore_inside_collisions)
use this function to create a new space with optional ignored collisions, use deleteSpace to destroy ...
Definition: odehandle.cpp:85
void init(double *time)
creates world at global space and so on and sets global time pointer.
Definition: odehandle.cpp:58
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
void destroySpaces()
deletes all associated memory objects, handle with care - use only when program exits ...
Definition: odehandle.cpp:49
double g(double z)
neuron transfer function
Definition: regularisation.h:35
Definition: odehandle.h:37
dJointGroupID jointGroup
Definition: odehandle.h:52
dSpaceID space
Definition: odehandle.h:51
void deleteSpace()
destroys the space and unregisters them in the global lists
Definition: odehandle.cpp:99
void removeSpace(dSpaceID g)
removes a space from the list of ignored spaces for collision detection
Definition: odehandle.cpp:113
HashSet< std::pair< long, long >, geomPairHash > * ignoredPairs
set of ignored geom pairs for collision
Definition: odehandle.h:115
OdeHandle()
Definition: odehandle.cpp:34
double * time
Definition: odehandle.h:105
const std::vector< dSpaceID > & getSpaces()
returns list of all spaces (as vector for parallelisation
Definition: odehandle.cpp:125
std::vector< dSpaceID > * spaces
list of spaces, except ignored spaces
Definition: odehandle.h:109
void addIgnoredPair(dGeomID g1, dGeomID g2)
adds a pair of geoms to the list of ignored geom pairs for collision detection
Definition: odehandle.cpp:132