00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 ScalarParameter 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(ScalarParameter radius) { set(springRadius,radius); }
00078 double getSpringRadius() { return get(springRadius); }
00079
00085 void setCrossSectionRadius(ScalarParameter radius) { set(crossSectionRadius,radius); }
00086 double getCrossSectionRadius() { return get(crossSectionRadius); }
00087
00088 void setScaleFactor(ScalarParameter scale) { set(scaleFactor,scale); }
00089 double getScaleFactor() { return get(scaleFactor); }
00090
00091 void setNumberOfCoils(ScalarParameter nr) { set(numberOfCoils,nr); }
00092 double getNumberOfCoils() { return get(numberOfCoils); }
00093
00102 void setNominalLength(ScalarParameter l) { set(nominalLength,l); }
00103 double getNominalLength() { return get(nominalLength); }
00104
00115 void setType(Type t) { type=t; }
00116 Type getType() { return type; }
00117
00119 virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00120
00121 MBXMLUtils::TiXmlElement *writeXMLFile(MBXMLUtils::TiXmlNode *parent);
00122 };
00123
00124 }
00125
00126 #endif