Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/coilspring.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_COILSPRING_H_
00021 #define _OPENMBV_COILSPRING_H_
00022 
00023 #include <openmbvcppinterface/dynamiccoloredbody.h>
00024 #include <hdf5serie/vectorserie.h>
00025 #include <cmath>
00026 #include <stdexcept>
00027 
00028 namespace OpenMBV {
00029 
00038   class CoilSpring : public DynamicColoredBody {
00039     public:
00040       enum Type {
00041         tube,
00042         scaledTube,
00043         polyline
00044       };
00045     protected:
00046       void createHDF5File();
00047       void openHDF5File();
00048       H5::VectorSerie<double>* data;
00049       double springRadius, crossSectionRadius, scaleFactor, numberOfCoils, nominalLength;
00050       Type type;
00051       
00053       virtual ~CoilSpring();
00054     public:
00056       CoilSpring();
00057 
00059       std::string getClassName() { return "CoilSpring"; }
00060       
00061       void append(const std::vector<double>& row) {
00062         if(data==0) throw std::runtime_error("can not append data to an environement object");
00063         if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00064         if(!std::isnan(dynamicColor))
00065         {
00066           std::vector<double> tmprow(row);
00067           tmprow[7]=dynamicColor;
00068           data->append(tmprow);
00069         }
00070         else
00071           data->append(row);
00072       }
00073 
00074       int getRows() { return data?data->getRows():-1; }
00075       std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00076 
00077       void setSpringRadius(double radius) { springRadius=radius; }
00078       double getSpringRadius() { return springRadius; }
00079 
00085       void setCrossSectionRadius(double radius) { crossSectionRadius=radius; }
00086       double getCrossSectionRadius() { return crossSectionRadius; }
00087 
00088       void setScaleFactor(double scale) { scaleFactor=scale; }
00089       double getScaleFactor() { return scaleFactor; }
00090 
00091       void setNumberOfCoils(double nr) { numberOfCoils=nr; }
00092       double getNumberOfCoils() { return numberOfCoils; }
00093 
00102       void setNominalLength(double l) { nominalLength=l; }
00103       double getNominalLength() { return nominalLength; }
00104 
00115       void setType(Type t) { type=t; }
00116       Type getType() { return type; }
00117 
00119       virtual void initializeUsingXML(xercesc::DOMElement *element);
00120 
00121       xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
00122   };
00123 
00124 }
00125 
00126 #endif