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 <stdexcept>
26 
27 namespace OpenMBV {
28 
37  class CoilSpring : public DynamicColoredBody {
38  friend class ObjectFactory;
39  public:
40  enum Type {
41  tube,
42  scaledTube,
43  polyline
44  };
45  protected:
46  void createHDF5File();
47  void openHDF5File();
49  double springRadius, crossSectionRadius, scaleFactor, numberOfCoils, nominalLength;
50  Type type;
51 
52  CoilSpring();
53  virtual ~CoilSpring();
54  public:
56  std::string getClassName() { return "CoilSpring"; }
57 
58  template<typename T>
59  void append(const T& row) {
60  if(data==0) throw std::runtime_error("can not append data to an environement object");
61  if(row.size()!=8) throw std::runtime_error("the dimension does not match");
62  if(!std::isnan(dynamicColor))
63  {
64  std::vector<double> tmprow(8);
65  std::copy(&row[0], &row[8], tmprow.begin());
66  tmprow[7]=dynamicColor;
67  data->append(tmprow);
68  }
69  else
70  data->append(row);
71  }
72 
73  int getRows() { return data?data->getRows():-1; }
74  std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
75 
76  void setSpringRadius(double radius) { springRadius=radius; }
77  double getSpringRadius() { return springRadius; }
78 
84  void setCrossSectionRadius(double radius) { crossSectionRadius=radius; }
85  double getCrossSectionRadius() { return crossSectionRadius; }
86 
87  void setScaleFactor(double scale) { scaleFactor=scale; }
88  double getScaleFactor() { return scaleFactor; }
89 
90  void setNumberOfCoils(double nr) { numberOfCoils=nr; }
91  double getNumberOfCoils() { return numberOfCoils; }
92 
101  void setNominalLength(double l) { nominalLength=l; }
102  double getNominalLength() { return nominalLength; }
103 
114  void setType(Type t) { type=t; }
115  Type getType() { return type; }
116 
118  virtual void initializeUsingXML(xercesc::DOMElement *element);
119 
120  xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
121  };
122 
123 }
124 
125 #endif
void setNominalLength(double l)
Definition: coilspring.h:101
std::string getClassName()
Definition: coilspring.h:56
void setCrossSectionRadius(double radius)
Definition: coilspring.h:84
Definition: objectfactory.h:36
int getRows()
Definition: coilspring.h:73
virtual void initializeUsingXML(xercesc::DOMElement *element)
Definition: coilspring.cc:94
Definition: dynamiccoloredbody.h:28
std::vector< double > getRow(int i)
Definition: coilspring.h:74
void getRow(const int row, size_t size, T data[])
void append(const T data[], size_t size)
Definition: coilspring.h:37
void setType(Type t)
Definition: coilspring.h:114

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML