00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OPENMBV_RIGIDBODY_H_
00021 #define _OPENMBV_RIGIDBODY_H_
00022
00023 #include <openmbvcppinterface/dynamiccoloredbody.h>
00024 #include <vector>
00025 #include <assert.h>
00026 #include <hdf5serie/vectorserie.h>
00027 #include <cmath>
00028 #include <stdexcept>
00029
00030 namespace OpenMBV {
00031
00032 class CompoundRigidBody;
00033
00070 class RigidBody : public DynamicColoredBody {
00071 friend class CompoundRigidBody;
00072 protected:
00073 std::string localFrameStr, referenceFrameStr, pathStr, draggerStr;
00074 std::vector<double> initialTranslation;
00075 std::vector<double> initialRotation;
00076 double scaleFactor;
00077 void createHDF5File();
00078 void openHDF5File();
00079 H5::VectorSerie<double>* data;
00080 boost::weak_ptr<CompoundRigidBody> compound;
00081
00082 RigidBody();
00083 ~RigidBody();
00084 public:
00086 void setLocalFrame(bool f) { localFrameStr=(f==true)?"true":"false"; }
00087
00088 bool getLocalFrame() { return localFrameStr=="true"?true:false; }
00089
00091 void setReferenceFrame(bool f) { referenceFrameStr=(f==true)?"true":"false"; }
00092
00093 bool getReferenceFrame() { return referenceFrameStr=="true"?true:false; }
00094
00096 void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
00097
00098 bool getPath() { return pathStr=="true"?true:false; }
00099
00101 void setDragger(bool p) { draggerStr=(p==true)?"true":"false"; }
00102
00103 bool getDragger() { return draggerStr=="true"?true:false; }
00104
00106 void setInitialTranslation(const std::vector<double> &initTrans) {
00107 if(initTrans.size()!=3) std::runtime_error("the dimension does not match");
00108 initialTranslation=initTrans;
00109 }
00110
00111 std::vector<double> getInitialTranslation() { return initialTranslation; }
00112
00114 void setInitialTranslation(double x, double y, double z) {
00115 std::vector<double> initTrans;
00116 initTrans.push_back(x);
00117 initTrans.push_back(y);
00118 initTrans.push_back(z);
00119 initialTranslation=initTrans;
00120 }
00121
00125 void setInitialRotation(const std::vector<double>& initRot) {
00126 if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
00127 initialRotation=initRot;
00128 }
00129
00130 std::vector<double> getInitialRotation() { return initialRotation; }
00131
00135 void setInitialRotation(double a, double b, double g) {
00136 std::vector<double> initRot;
00137 initRot.push_back(a);
00138 initRot.push_back(b);
00139 initRot.push_back(g);
00140 initialRotation=initRot;
00141 }
00142
00144 void setScaleFactor(double scale) {
00145 scaleFactor=scale;
00146 }
00147
00148 double getScaleFactor() { return scaleFactor; }
00149
00151 void append(const std::vector<double>& row) {
00152 if(data==0) throw std::runtime_error("can not append data to an environment object");
00153 if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00154 if(!std::isnan(dynamicColor))
00155 {
00156 std::vector<double> tmprow(row);
00157 tmprow[7]=dynamicColor;
00158 data->append(tmprow);
00159 }
00160 else
00161 data->append(row);
00162 }
00163
00164 int getRows() { return data?data->getRows():-1; }
00165 std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00166
00168 virtual void initializeUsingXML(xercesc::DOMElement *element);
00169
00170 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00171
00172 virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
00173
00174 boost::shared_ptr<Group> getSeparateGroup();
00175 boost::shared_ptr<Group> getTopLevelGroup();
00176 };
00177
00178 }
00179
00180 #endif
00181