All Classes Namespaces Functions Variables Typedefs Enumerations Pages
coilspring.h
1 /*
2  OpenMBV - Open Multi Body Viewer.
3  Copyright (C) 2009 Markus Friedrich
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef _OPENMBV_COILSPRING_H_
21 #define _OPENMBV_COILSPRING_H_
22 
23 #include <openmbvcppinterface/dynamiccoloredbody.h>
24 #include <hdf5serie/vectorserie.h>
25 #include <cmath>
26 #include <stdexcept>
27 
28 namespace OpenMBV {
29 
38  class CoilSpring : public DynamicColoredBody {
39  friend class ObjectFactory;
40  public:
41  enum Type {
42  tube,
43  scaledTube,
44  polyline
45  };
46  protected:
47  void createHDF5File();
48  void openHDF5File();
50  double springRadius, crossSectionRadius, scaleFactor, numberOfCoils, nominalLength;
51  Type type;
52 
53  CoilSpring();
54  virtual ~CoilSpring();
55  public:
57  std::string getClassName() { return "CoilSpring"; }
58 
59  template<typename T>
60  void append(const T& row) {
61  if(data==0) throw std::runtime_error("can not append data to an environement object");
62  if(row.size()!=8) throw std::runtime_error("the dimension does not match");
63  if(!std::isnan(dynamicColor))
64  {
65  std::vector<double> tmprow(8);
66  std::copy(&row[0], &row[8], tmprow.begin());
67  tmprow[7]=dynamicColor;
68  data->append(tmprow);
69  }
70  else
71  data->append(row);
72  }
73 
74  int getRows() { return data?data->getRows():-1; }
75  std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
76 
77  void setSpringRadius(double radius) { springRadius=radius; }
78  double getSpringRadius() { return springRadius; }
79 
85  void setCrossSectionRadius(double radius) { crossSectionRadius=radius; }
86  double getCrossSectionRadius() { return crossSectionRadius; }
87 
88  void setScaleFactor(double scale) { scaleFactor=scale; }
89  double getScaleFactor() { return scaleFactor; }
90 
91  void setNumberOfCoils(double nr) { numberOfCoils=nr; }
92  double getNumberOfCoils() { return numberOfCoils; }
93 
102  void setNominalLength(double l) { nominalLength=l; }
103  double getNominalLength() { return nominalLength; }
104 
115  void setType(Type t) { type=t; }
116  Type getType() { return type; }
117 
119  virtual void initializeUsingXML(xercesc::DOMElement *element);
120 
121  xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
122  };
123 
124 }
125 
126 #endif
void setNominalLength(double l)
Definition: coilspring.h:102
std::string getClassName()
Definition: coilspring.h:57
void setCrossSectionRadius(double radius)
Definition: coilspring.h:85
Definition: objectfactory.h:40
int getRows()
Definition: coilspring.h:74
virtual void initializeUsingXML(xercesc::DOMElement *element)
Definition: coilspring.cc:94
Definition: dynamiccoloredbody.h:28
std::vector< double > getRow(int i)
Definition: coilspring.h:75
void getRow(const int row, size_t size, T data[])
void append(const T data[], size_t size)
Definition: coilspring.h:38
void setType(Type t)
Definition: coilspring.h:115

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML