All Classes Namespaces Functions Variables Typedefs Enumerations Pages
rigidbody.h
1 /*
2  OpenMBV - Open Multi Body Viewer.
3  Copyright (C) 2009 Markus Friedrich
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef _OPENMBV_RIGIDBODY_H_
21 #define _OPENMBV_RIGIDBODY_H_
22 
23 #include <openmbvcppinterface/dynamiccoloredbody.h>
24 #include <vector>
25 #include <assert.h>
26 #include <hdf5serie/vectorserie.h>
27 #include <cmath>
28 #include <stdexcept>
29 
30 namespace OpenMBV {
31 
32  class CompoundRigidBody;
33 
70  class RigidBody : public DynamicColoredBody {
71  friend class CompoundRigidBody;
72  protected:
73  std::string localFrameStr, referenceFrameStr, pathStr, draggerStr;
74  std::vector<double> initialTranslation;
75  std::vector<double> initialRotation;
76  double scaleFactor;
77  void createHDF5File();
78  void openHDF5File();
80  boost::weak_ptr<CompoundRigidBody> compound;
81 
82  RigidBody();
83  ~RigidBody();
84  public:
86  void setLocalFrame(bool f) { localFrameStr=(f==true)?"true":"false"; }
87 
88  bool getLocalFrame() { return localFrameStr=="true"?true:false; }
89 
91  void setReferenceFrame(bool f) { referenceFrameStr=(f==true)?"true":"false"; }
92 
93  bool getReferenceFrame() { return referenceFrameStr=="true"?true:false; }
94 
96  void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
97 
98  bool getPath() { return pathStr=="true"?true:false; }
99 
101  void setDragger(bool p) { draggerStr=(p==true)?"true":"false"; }
102 
103  bool getDragger() { return draggerStr=="true"?true:false; }
104 
106  void setInitialTranslation(const std::vector<double> &initTrans) {
107  if(initTrans.size()!=3) std::runtime_error("the dimension does not match");
108  initialTranslation=initTrans;
109  }
110 
111  std::vector<double> getInitialTranslation() { return initialTranslation; }
112 
114  void setInitialTranslation(double x, double y, double z) {
115  std::vector<double> initTrans;
116  initTrans.push_back(x);
117  initTrans.push_back(y);
118  initTrans.push_back(z);
119  initialTranslation=initTrans;
120  }
121 
125  void setInitialRotation(const std::vector<double>& initRot) {
126  if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
127  initialRotation=initRot;
128  }
129 
130  std::vector<double> getInitialRotation() { return initialRotation; }
131 
135  void setInitialRotation(double a, double b, double g) {
136  std::vector<double> initRot;
137  initRot.push_back(a);
138  initRot.push_back(b);
139  initRot.push_back(g);
140  initialRotation=initRot;
141  }
142 
144  void setScaleFactor(double scale) {
145  scaleFactor=scale;
146  }
147 
148  double getScaleFactor() { return scaleFactor; }
149 
151  template<typename T>
152  void append(const T& row) {
153  if(data==0) throw std::runtime_error("can not append data to an environment object");
154  if(row.size()!=8) throw std::runtime_error("the dimension does not match");
155  if(!std::isnan(dynamicColor))
156  {
157  std::vector<double> tmprow(8);
158  std::copy(&row[0], &row[8], tmprow.begin());
159  tmprow[7]=dynamicColor;
160  data->append(tmprow);
161  }
162  else
163  data->append(row);
164  }
165 
166  int getRows() { return data?data->getRows():-1; }
167  std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
168 
170  virtual void initializeUsingXML(xercesc::DOMElement *element);
171 
172  xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
173 
174  virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
175 
176  boost::shared_ptr<Group> getSeparateGroup();
177  boost::shared_ptr<Group> getTopLevelGroup();
178  };
179 
180 }
181 
182 #endif /* _OPENMBV_RIGIDBODY_H_ */
183 
void setInitialTranslation(double x, double y, double z)
Definition: rigidbody.h:114
virtual void initializeUsingXML(xercesc::DOMElement *element)
Definition: rigidbody.cc:86
void append(const T &row)
Definition: rigidbody.h:152
void setInitialRotation(double a, double b, double g)
Definition: rigidbody.h:135
Abstract base class for all rigid bodies.
Definition: rigidbody.h:70
int getRows()
Definition: rigidbody.h:166
void setReferenceFrame(bool f)
Definition: rigidbody.h:91
void setScaleFactor(double scale)
Definition: rigidbody.h:144
void setInitialTranslation(const std::vector< double > &initTrans)
Definition: rigidbody.h:106
Definition: dynamiccoloredbody.h:28
std::vector< double > getRow(int i)
Definition: rigidbody.h:167
void setLocalFrame(bool f)
Definition: rigidbody.h:86
void getRow(const int row, size_t size, T data[])
void append(const T data[], size_t size)
virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false)
Definition: rigidbody.cc:119
void setDragger(bool p)
Definition: rigidbody.h:101
void setInitialRotation(const std::vector< double > &initRot)
Definition: rigidbody.h:125
void setPath(bool p)
Definition: rigidbody.h:96
Definition: compoundrigidbody.h:30

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML