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     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