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 library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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() override;
169
170 std::shared_ptr<Group> getTopLevelGroup();
171
172 std::weak_ptr<CompoundRigidBody> getCompound() { return compound; }
173 };
174
175 }
176
177 #endif /* _OPENMBV_RIGIDBODY_H_ */
178
OpenMBV::RigidBody::getRows
int getRows() override
Definition: rigidbody.h:160
OpenMBV::RigidBody::setInitialTranslation
void setInitialTranslation(double x, double y, double z)
Definition: rigidbody.h:112
OpenMBV::RigidBody::initializeUsingXML
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: rigidbody.cc:80
OpenMBV::RigidBody::append
void append(const T &row)
Definition: rigidbody.h:146
OpenMBV::RigidBody::setInitialRotation
void setInitialRotation(double a, double b, double g)
Definition: rigidbody.h:131
OpenMBV::RigidBody
Abstract base class for all rigid bodies.
Definition: rigidbody.h:68
H5::VectorSerie::getRow
void getRow(int row, size_t size, T data[])
OpenMBV::RigidBody::setReferenceFrame
void setReferenceFrame(bool f)
Definition: rigidbody.h:89
OpenMBV::RigidBody::setScaleFactor
void setScaleFactor(double scale)
Definition: rigidbody.h:138
OpenMBV::RigidBody::setInitialTranslation
void setInitialTranslation(const std::vector< double > &initTrans)
Definition: rigidbody.h:104
OpenMBV::RigidBody::getFullName
std::string getFullName() override
Definition: rigidbody.cc:108
OpenMBV::RigidBody::getRow
std::vector< double > getRow(int i) override
Definition: rigidbody.h:161
OpenMBV::DynamicColoredBody
Definition: dynamiccoloredbody.h:28
H5::VectorSerie< double >
OpenMBV::RigidBody::setLocalFrame
void setLocalFrame(bool f)
Definition: rigidbody.h:84
H5::VectorSerie::append
void append(const T data[], size_t size)
OpenMBV::RigidBody::setDragger
void setDragger(bool p)
Definition: rigidbody.h:99
H5::VectorSerie::getRows
int getRows()
OpenMBV::RigidBody::setInitialRotation
void setInitialRotation(const std::vector< double > &initRot)
Definition: rigidbody.h:121
OpenMBV::RigidBody::setPath
void setPath(bool p)
Definition: rigidbody.h:94
OpenMBV::CompoundRigidBody
Definition: compoundrigidbody.h:29