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 friend class ObjectFactory;
00040 public:
00041 enum Type {
00042 tube,
00043 scaledTube,
00044 polyline
00045 };
00046 protected:
00047 void createHDF5File();
00048 void openHDF5File();
00049 H5::VectorSerie<double>* data;
00050 double springRadius, crossSectionRadius, scaleFactor, numberOfCoils, nominalLength;
00051 Type type;
00052
00053 CoilSpring();
00054 virtual ~CoilSpring();
00055 public:
00057 std::string getClassName() { return "CoilSpring"; }
00058
00059 void append(const std::vector<double>& row) {
00060 if(data==0) throw std::runtime_error("can not append data to an environement object");
00061 if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00062 if(!std::isnan(dynamicColor))
00063 {
00064 std::vector<double> tmprow(row);
00065 tmprow[7]=dynamicColor;
00066 data->append(tmprow);
00067 }
00068 else
00069 data->append(row);
00070 }
00071
00072 int getRows() { return data?data->getRows():-1; }
00073 std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00074
00075 void setSpringRadius(double radius) { springRadius=radius; }
00076 double getSpringRadius() { return springRadius; }
00077
00083 void setCrossSectionRadius(double radius) { crossSectionRadius=radius; }
00084 double getCrossSectionRadius() { return crossSectionRadius; }
00085
00086 void setScaleFactor(double scale) { scaleFactor=scale; }
00087 double getScaleFactor() { return scaleFactor; }
00088
00089 void setNumberOfCoils(double nr) { numberOfCoils=nr; }
00090 double getNumberOfCoils() { return numberOfCoils; }
00091
00100 void setNominalLength(double l) { nominalLength=l; }
00101 double getNominalLength() { return nominalLength; }
00102
00113 void setType(Type t) { type=t; }
00114 Type getType() { return type; }
00115
00117 virtual void initializeUsingXML(xercesc::DOMElement *element);
00118
00119 xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
00120 };
00121
00122 }
00123
00124 #endif