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 <openmbvcppinterface/simpleparameter.h>
00029 #include <stdexcept>
00030
00031 namespace OpenMBV {
00032
00033 class CompoundRigidBody;
00034
00071 class RigidBody : public DynamicColoredBody {
00072 friend class CompoundRigidBody;
00073 protected:
00074 std::string localFrameStr, referenceFrameStr, pathStr, draggerStr;
00075 VectorParameter initialTranslation;
00076 VectorParameter initialRotation;
00077 ScalarParameter scaleFactor;
00078 void createHDF5File();
00079 void openHDF5File();
00080 H5::VectorSerie<double>* data;
00081 CompoundRigidBody *compound;
00082
00083 ~RigidBody();
00084 public:
00086 RigidBody();
00087
00089 void setLocalFrame(bool f) { localFrameStr=(f==true)?"true":"false"; }
00090
00091 bool getLocalFrame() { return localFrameStr=="true"?true:false; }
00092
00094 void setReferenceFrame(bool f) { referenceFrameStr=(f==true)?"true":"false"; }
00095
00096 bool getReferenceFrame() { return referenceFrameStr=="true"?true:false; }
00097
00099 void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
00100
00101 bool getPath() { return pathStr=="true"?true:false; }
00102
00104 void setDragger(bool p) { draggerStr=(p==true)?"true":"false"; }
00105
00106 bool getDragger() { return draggerStr=="true"?true:false; }
00107
00109 void setInitialTranslation(const VectorParameter &initTrans) {
00110 if(initTrans.getParamStr()=="" && initTrans.getValue().size()!=3) std::runtime_error("the dimension does not match");
00111 set(initialTranslation,initTrans);
00112 }
00113
00115 void setInitialTranslation(const std::vector<double> &initTrans) {
00116 if(initTrans.size()!=3) throw std::runtime_error("the dimension does not match");
00117 set(initialTranslation,initTrans);
00118 }
00119
00120 std::vector<double> getInitialTranslation() { return get(initialTranslation); }
00121
00123 void setInitialTranslation(double x, double y, double z) {
00124 std::vector<double> initTrans;
00125 initTrans.push_back(x);
00126 initTrans.push_back(y);
00127 initTrans.push_back(z);
00128 initialTranslation=initTrans;
00129 }
00130
00134 void setInitialRotation(const VectorParameter& initRot) {
00135 if(initRot.getParamStr()=="" && initRot.getValue().size()!=3) throw std::runtime_error("the dimension does not match");
00136 set(initialRotation,initRot);
00137 }
00138
00142 void setInitialRotation(const std::vector<double>& initRot) {
00143 if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
00144 set(initialRotation,initRot);
00145 }
00146
00147 std::vector<double> getInitialRotation() { return get(initialRotation); }
00148
00152 void setInitialRotation(double a, double b, double g) {
00153 std::vector<double> initRot;
00154 initRot.push_back(a);
00155 initRot.push_back(b);
00156 initRot.push_back(g);
00157 initialRotation=initRot;
00158 }
00159
00161 void setScaleFactor(const ScalarParameter scale) {
00162 set(scaleFactor,scale);
00163 }
00164
00165 double getScaleFactor() { return get(scaleFactor); }
00166
00168 void append(const std::vector<double>& row) {
00169 if(data==0) throw std::runtime_error("can not append data to an environment object");
00170 if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00171 if(!std::isnan(dynamicColor))
00172 {
00173 std::vector<double> tmprow(row);
00174 tmprow[7]=dynamicColor;
00175 data->append(tmprow);
00176 }
00177 else
00178 data->append(row);
00179 }
00180
00181 int getRows() { return data?data->getRows():-1; }
00182 std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00183
00185 virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00186
00187 MBXMLUtils::TiXmlElement* writeXMLFile(MBXMLUtils::TiXmlNode *parent);
00188
00189 virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
00190
00191 Group* getSeparateGroup();
00192 Group* getTopLevelGroup();
00193
00194 virtual void destroy() const;
00195 };
00196
00197 }
00198
00199 #endif
00200