openmbvcppinterface  3.1.0
OpenMBV C++ Interface
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{3};
73  std::vector<double> initialRotation{3};
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  initialTranslation[0] = x;
114  initialTranslation[1] = y;
115  initialTranslation[2] = z;
116  }
117 
121  void setInitialRotation(const std::vector<double>& initRot) {
122  if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
123  initialRotation=initRot;
124  }
125 
126  std::vector<double> getInitialRotation() { return initialRotation; }
127 
131  void setInitialRotation(double a, double b, double g) {
132  initialRotation[0] = a;
133  initialRotation[1] = b;
134  initialRotation[2] = g;
135  }
136 
138  void setScaleFactor(double scale) {
139  scaleFactor=scale;
140  }
141 
142  double getScaleFactor() { return scaleFactor; }
143 
145  template<typename T>
146  void append(const T& row) {
147  if(data==nullptr) throw std::runtime_error("can not append data to an environment object");
148  if(row.size()!=8) throw std::runtime_error("the dimension does not match");
149  if(!std::isnan(dynamicColor))
150  {
151  std::vector<double> tmprow(8);
152  std::copy(&row[0], &row[8], tmprow.begin());
153  tmprow[7]=dynamicColor;
154  data->append(tmprow);
155  }
156  else
157  data->append(row);
158  }
159 
160  int getRows() override { return data?data->getRows():0; }
161  std::vector<double> getRow(int i) override { return data?data->getRow(i):std::vector<double>(8); }
162 
164  void initializeUsingXML(xercesc::DOMElement *element) override;
165 
166  xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
167 
168  std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false) override;
169 
170  std::shared_ptr<Group> getSeparateGroup();
171  std::shared_ptr<Group> getTopLevelGroup();
172  };
173 
174 }
175 
176 #endif /* _OPENMBV_RIGIDBODY_H_ */
177 
int getRows() override
Definition: rigidbody.h:160
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:146
void setInitialRotation(double a, double b, double g)
Definition: rigidbody.h:131
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:138
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:161
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:121
void setPath(bool p)
Definition: rigidbody.h:94
Definition: compoundrigidbody.h:29