openmbvcppinterface  3.1.0
OpenMBV C++ Interface
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() override;
47  void openHDF5File() override;
48  H5::VectorSerie<double>* data{nullptr};
49  double springRadius{1};
50  double crossSectionRadius{-1};
51  double scaleFactor{1};
52  double numberOfCoils{3};
53  double nominalLength{-1};
54  Type type{tube};
55 
56  CoilSpring();
57  ~CoilSpring() override;
58  public:
59  template<typename T>
60  void append(const T& row) {
61  if(data==nullptr) 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() override { return data?data->getRows():0; }
75  std::vector<double> getRow(int i) override { 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  void initializeUsingXML(xercesc::DOMElement *element) override;
120 
121  xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent) override;
122  };
123 
124 }
125 
126 #endif
std::vector< double > getRow(int i) override
Definition: coilspring.h:75
void setNominalLength(double l)
Definition: coilspring.h:102
int getRows() override
Definition: coilspring.h:74
void setCrossSectionRadius(double radius)
Definition: coilspring.h:85
Definition: objectfactory.h:36
void getRow(int row, size_t size, T data[])
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: coilspring.cc:83
Definition: dynamiccoloredbody.h:28
void append(const T data[], size_t size)
Definition: coilspring.h:37
void setType(Type t)
Definition: coilspring.h:115