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 <cassert>
26 #include <hdf5serie/vectorserie.h>
27 #include <stdexcept>
28 
29 namespace OpenMBV {
30 
31  class CompoundRigidBody;
32 
68  class RigidBody : public DynamicColoredBody {
69  friend class CompoundRigidBody;
70  protected:
71  std::string localFrameStr, referenceFrameStr, pathStr, draggerStr;
72  std::vector<double> initialTranslation;
73  std::vector<double> initialRotation;
74  double scaleFactor{1};
75  void createHDF5File() override;
76  void openHDF5File() override;
77  H5::VectorSerie<double>* data{nullptr};
78  std::weak_ptr<CompoundRigidBody> compound;
79 
80  RigidBody();
81  ~RigidBody() override;
82  public:
84  void setLocalFrame(bool f) { localFrameStr=(f)?"true":"false"; }
85 
86  bool getLocalFrame() { return localFrameStr=="true"?true:false; }
87 
89  void setReferenceFrame(bool f) { referenceFrameStr=(f)?"true":"false"; }
90 
91  bool getReferenceFrame() { return referenceFrameStr=="true"?true:false; }
92 
94  void setPath(bool p) { pathStr=(p)?"true":"false"; }
95 
96  bool getPath() { return pathStr=="true"?true:false; }
97 
99  void setDragger(bool p) { draggerStr=(p)?"true":"false"; }
100 
101  bool getDragger() { return draggerStr=="true"?true:false; }
102 
104  void setInitialTranslation(const std::vector<double> &initTrans) {
105  if(initTrans.size()!=3) std::runtime_error("the dimension does not match");
106  initialTranslation=initTrans;
107  }
108 
109  std::vector<double> getInitialTranslation() { return initialTranslation; }
110 
112  void setInitialTranslation(double x, double y, double z) {
113  std::vector<double> initTrans;
114  initTrans.push_back(x);
115  initTrans.push_back(y);
116  initTrans.push_back(z);
117  initialTranslation=initTrans;
118  }
119 
123  void setInitialRotation(const std::vector<double>& initRot) {
124  if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
125  initialRotation=initRot;
126  }
127 
128  std::vector<double> getInitialRotation() { return initialRotation; }
129 
133  void setInitialRotation(double a, double b, double g) {
134  std::vector<double> initRot;
135  initRot.push_back(a);
136  initRot.push_back(b);
137  initRot.push_back(g);
138  initialRotation=initRot;
139  }
140 
142  void setScaleFactor(double scale) {
143  scaleFactor=scale;
144  }
145 
146  double getScaleFactor() { return scaleFactor; }
147 
149  template<typename T>
150  void append(const T& row) {
151  if(data==nullptr) throw std::runtime_error("can not append data to an environment object");
152  if(row.size()!=8) throw std::runtime_error("the dimension does not match");
153  if(!std::isnan(dynamicColor))
154  {
155  std::vector<double> tmprow(8);
156  std::copy(&row[0], &row[8], tmprow.begin());
157  tmprow[7]=dynamicColor;
158  data->append(tmprow);
159  }
160  else
161  data->append(row);
162  }
163 
164  int getRows() override { return data?data->getRows():-1; }
165  std::vector<double> getRow(int i) override { return data?data->getRow(i):std::vector<double>(8); }
166 
168  void initializeUsingXML(xercesc::DOMElement *element) override;
169 
170  xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
171 
172  std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false) override;
173 
174  std::shared_ptr<Group> getSeparateGroup();
175  std::shared_ptr<Group> getTopLevelGroup();
176  };
177 
178 }
179 
180 #endif /* _OPENMBV_RIGIDBODY_H_ */
181 
int getRows() override
Definition: rigidbody.h:164
void setInitialTranslation(double x, double y, double z)
Definition: rigidbody.h:112
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: rigidbody.cc:84
void append(const T &row)
Definition: rigidbody.h:150
void setInitialRotation(double a, double b, double g)
Definition: rigidbody.h:133
Abstract base class for all rigid bodies.
Definition: rigidbody.h:68
void getRow(int row, size_t size, T data[])
void setReferenceFrame(bool f)
Definition: rigidbody.h:89
void setScaleFactor(double scale)
Definition: rigidbody.h:142
void setInitialTranslation(const std::vector< double > &initTrans)
Definition: rigidbody.h:104
std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false) override
Definition: rigidbody.cc:117
std::vector< double > getRow(int i) override
Definition: rigidbody.h:165
Definition: dynamiccoloredbody.h:28
void setLocalFrame(bool f)
Definition: rigidbody.h:84
void append(const T data[], size_t size)
void setDragger(bool p)
Definition: rigidbody.h:99
void setInitialRotation(const std::vector< double > &initRot)
Definition: rigidbody.h:123
void setPath(bool p)
Definition: rigidbody.h:94
Definition: compoundrigidbody.h:29

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home