5ed031b543e829e944a4374ad29f76f9ba22ddee
[blender.git] / intern / itasc / Scene.hpp
1 /*
2  * Scene.hpp
3  *
4  *  Created on: Jan 5, 2009
5  *      Author: rubensmits
6  */
7
8 #ifndef SCENE_HPP_
9 #define SCENE_HPP_
10
11 #include "eigen_types.hpp"
12
13 #include "WorldObject.hpp"
14 #include "ConstraintSet.hpp"
15 #include "Solver.hpp"
16
17 #include <map>
18
19 namespace iTaSC {
20
21 class SceneLock;
22
23 class Scene {
24         friend class SceneLock; 
25 public:
26         enum SceneParam {
27                 MIN_TIMESTEP    = 0,
28                 MAX_TIMESTEP,
29
30                 COUNT
31         };
32
33
34         Scene();
35     virtual ~Scene();
36
37         bool addObject(const std::string& name, Object* object, UncontrolledObject* base=&Object::world, const std::string& baseFrame="");
38         bool addConstraintSet(const std::string& name, ConstraintSet* task,const std::string& object1,const std::string& object2,const std::string& ee1="",const std::string& ee2="");
39     bool addSolver(Solver* _solver);
40     bool addCache(Cache* _cache);
41     bool initialize();
42     bool update(double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true);
43         bool setParam(SceneParam paramId, double value);
44
45         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
46
47 private:
48     e_matrix m_A,m_B,m_Atemp,m_Wq,m_Jf,m_Jq,m_Ju,m_Cf,m_Cq,m_Jf_inv;
49         e_matrix6 m_Vf,m_Uf;
50     e_vector m_Wy,m_ydot,m_qdot,m_xdot;
51         e_vector6 m_Sf,m_tempf;
52         double m_minstep;
53         double m_maxstep;
54     unsigned int m_ncTotal,m_nqTotal,m_nuTotal,m_nsets;
55         std::vector<bool> m_ytask;
56
57     Solver* m_solver;
58         Cache* m_cache;
59
60
61     struct Object_struct{
62         Object* object;
63         UncontrolledObject* base;
64                 unsigned int baseFrameIndex;
65         Range constraintrange;
66         Range jointrange;
67                 Range coordinaterange;  // Xu range of base when object is controlled
68                                                                                 // Xu range of object when object is uncontrolled 
69
70         Object_struct(Object* _object,UncontrolledObject* _base,unsigned int _baseFrameIndex,Range nq_range,Range nc_range,Range nu_range):
71             object(_object),base(_base),baseFrameIndex(_baseFrameIndex),constraintrange(nc_range),jointrange(nq_range),coordinaterange(nu_range)
72             {};
73     };
74     typedef std::map<std::string,Object_struct*> ObjectMap;
75
76     struct ConstraintSet_struct{
77         ConstraintSet* task;
78         ObjectMap::iterator object1;
79         ObjectMap::iterator object2;
80         Range constraintrange;
81         Range featurerange;
82                 unsigned int ee1index;
83                 unsigned int ee2index;
84         ConstraintSet_struct(ConstraintSet* _task,
85                         ObjectMap::iterator _object1,unsigned int _ee1index,
86                         ObjectMap::iterator _object2,unsigned int _ee2index,
87                         Range nc_range,Range coord_range):
88                                 task(_task),
89                                 object1(_object1),object2(_object2),
90                                 constraintrange(nc_range),featurerange(coord_range),
91                                 ee1index(_ee1index), ee2index(_ee2index)
92             {};
93     };
94     typedef std::map<std::string,ConstraintSet_struct*> ConstraintMap;
95
96     ObjectMap objects;
97     ConstraintMap constraints;
98
99         static bool getConstraintPose(ConstraintSet* constraint, void *_param, KDL::Frame& _pose);
100 };
101
102 }
103
104 #endif /* SCENE_HPP_ */