Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/rigidbody.h
00001 /*
00002     OpenMBV - Open Multi Body Viewer.
00003     Copyright (C) 2009 Markus Friedrich
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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       CompoundRigidBody *compound;
00081 
00082       ~RigidBody();
00083     public:
00085       RigidBody();
00086 
00088       void setLocalFrame(bool f) { localFrameStr=(f==true)?"true":"false"; }
00089 
00090       bool getLocalFrame() { return localFrameStr=="true"?true:false; }
00091 
00093       void setReferenceFrame(bool f) { referenceFrameStr=(f==true)?"true":"false"; }
00094 
00095       bool getReferenceFrame() { return referenceFrameStr=="true"?true:false; }
00096 
00098       void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
00099 
00100       bool getPath() { return pathStr=="true"?true:false; }
00101 
00103       void setDragger(bool p) { draggerStr=(p==true)?"true":"false"; }
00104 
00105       bool getDragger() { return draggerStr=="true"?true:false; }
00106 
00108       void setInitialTranslation(const std::vector<double> &initTrans) {
00109         if(initTrans.size()!=3) std::runtime_error("the dimension does not match");
00110         initialTranslation=initTrans;
00111       }
00112 
00113       std::vector<double> getInitialTranslation() { return initialTranslation; }
00114 
00116       void setInitialTranslation(double x, double y, double z) {
00117         std::vector<double> initTrans;
00118         initTrans.push_back(x);
00119         initTrans.push_back(y);
00120         initTrans.push_back(z);
00121         initialTranslation=initTrans;
00122       }
00123 
00127       void setInitialRotation(const std::vector<double>& initRot) {
00128         if(initRot.size()!=3) throw std::runtime_error("the dimension does not match");
00129         initialRotation=initRot;
00130       }
00131 
00132       std::vector<double> getInitialRotation() { return initialRotation; }
00133 
00137       void setInitialRotation(double a, double b, double g) {
00138         std::vector<double> initRot;
00139         initRot.push_back(a);
00140         initRot.push_back(b);
00141         initRot.push_back(g);
00142         initialRotation=initRot;
00143       }
00144 
00146       void setScaleFactor(double scale) {
00147         scaleFactor=scale;
00148       }
00149 
00150       double getScaleFactor() { return scaleFactor; }
00151 
00153       void append(const std::vector<double>& row) {
00154         if(data==0) throw std::runtime_error("can not append data to an environment object");
00155         if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00156         if(!std::isnan(dynamicColor))
00157         {
00158           std::vector<double> tmprow(row);
00159           tmprow[7]=dynamicColor;
00160           data->append(tmprow);
00161         }
00162         else
00163           data->append(row);
00164       }
00165 
00166       int getRows() { return data?data->getRows():-1; }
00167       std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00168 
00170       virtual void initializeUsingXML(xercesc::DOMElement *element);
00171 
00172       xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00173 
00174       virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
00175 
00176       Group* getSeparateGroup();
00177       Group* getTopLevelGroup();
00178 
00179       virtual void destroy() const;
00180   };
00181 
00182 }
00183 
00184 #endif /* _OPENMBV_RIGIDBODY_H_ */
00185