mbsim  4.0.0
MBSim Kernel
openmbv_utils.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef _OPENMBV_UTILS_H_
21 #define _OPENMBV_UTILS_H_
22 
23 #include <fmatvec/fmatvec.h>
24 #include <openmbvcppinterface/objectfactory.h>
25 
26 namespace OpenMBV {
27  class Body;
28  class DynamicColoredBody;
29  class RigidBody;
30  class Arrow;
31  class Frame;
32  class Cuboid;
33  class CoilSpring;
34  class IndexedLineSet;
35 }
36 
37 namespace MBSim {
38 
39  class OpenMBVBody {
40  protected:
41  std::string id;
42  public:
43  OpenMBVBody() = default;
44  void initializeUsingXML(xercesc::DOMElement *element);
45  protected:
46  void initializeObject(const std::shared_ptr<OpenMBV::Body> &object);
47  };
48 
50  protected:
51  fmatvec::Vec3 dc;
52  double tp, ps, lw;
53  public:
54  OpenMBVColoredBody(const fmatvec::Vec3 &dc_=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp_=0, double ps_=0, double lw_=0) : dc(dc_), tp(tp_), ps(ps_), lw(lw_) { }
55  void initializeUsingXML(xercesc::DOMElement *element);
56  template<class T>
57  std::shared_ptr<T> createOpenMBV() {
58  std::shared_ptr<T> object = OpenMBV::ObjectFactory::create<T>();
59  initializeObject(object);
60  return object;
61  }
62  protected:
63  void initializeObject(const std::shared_ptr<OpenMBV::DynamicColoredBody> &object);
64  };
65 
67  protected:
68  unsigned int cR;
69  double minCol, maxCol;
70  std::vector<std::string> cRL;
71  public:
72  OpenMBVDynamicColoredBody(unsigned cR_=0, double minCol_=0, double maxCol_=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), cR(cR_), minCol(minCol_), maxCol(maxCol_), cRL(1,"none") { }
73  void initializeUsingXML(xercesc::DOMElement *element);
74  unsigned int getColorRepresentation() const { return cR; }
75  protected:
76  void initializeObject(const std::shared_ptr<OpenMBV::DynamicColoredBody> &object);
77  };
78 
80  public:
81  enum Type {
82  line,
83  fromHead,
84  toHead,
85  bothHeads,
86  fromDoubleHead,
87  toDoubleHead,
88  bothDoubleHeads
89  };
90  enum ReferencePoint {
91  toPoint,
92  fromPoint,
93  midPoint
94  };
95  enum ColorRepresentation {
96  none=0,
97  absoluteValue
98  };
99  protected:
100  double sL, sS;
101  OpenMBVArrow::Type type;
102  OpenMBVArrow::ReferencePoint refPoint;
103  public:
104  OpenMBVArrow(double sL_=1, double sS_=1, const OpenMBVArrow::Type &type_=OpenMBVArrow::toHead, const OpenMBVArrow::ReferencePoint &refPoint_=OpenMBVArrow::fromPoint, unsigned int cR=0, double minCol=0, double maxCol=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0);
105  void initializeUsingXML(xercesc::DOMElement *element);
106  std::shared_ptr<OpenMBV::Arrow> createOpenMBV();
107  protected:
108  void initializeObject(const std::shared_ptr<OpenMBV::Arrow> &object);
109  };
110 
112  public:
113  enum SideOfInteraction {
114  action=0,
115  reaction,
116  both
117  };
118  protected:
119  unsigned int sI;
120  public:
121  OpenMBVInteractionArrow(unsigned int sI_=0, double sL=1, double sS=1, const OpenMBVArrow::Type &type=OpenMBVArrow::toHead, const OpenMBVArrow::ReferencePoint &refPoint=OpenMBVArrow::fromPoint, unsigned int cR=0, double minCol=0, double maxCol=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0);
122  void initializeUsingXML(xercesc::DOMElement *element);
123  unsigned int getSideOfInteraction() const { return sI; }
124  protected:
125  void initializeObject(const std::shared_ptr<OpenMBV::Arrow> &object);
126  };
127 
129  public:
130  enum ColorRepresentation {
131  none=0,
132  absoluteValue,
133  stickslip
134  };
135  public:
136  OpenMBVFrictionArrow(unsigned int sI=0, double sL=1, double sS=1, const OpenMBVArrow::Type &type=OpenMBVArrow::toHead, const OpenMBVArrow::ReferencePoint &refPoint=OpenMBVArrow::fromPoint, unsigned int cR=0, double minCol=0, double maxCol=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0);
137  };
138 
140  protected:
141  double size, offset;
142  public:
143  OpenMBVFrame(double size_=1, double offset_=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), size(size_), offset(offset_) { }
144  void initializeUsingXML(xercesc::DOMElement *element);
145  std::shared_ptr<OpenMBV::Frame> createOpenMBV();
146  protected:
147  void initializeObject(const std::shared_ptr<OpenMBV::Frame> &object);
148  };
149 
151  protected:
152  double l;
153  public:
154  OpenMBVLine(double l_=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), l(l_) { }
155  void initializeUsingXML(xercesc::DOMElement *element);
156  std::shared_ptr<OpenMBV::IndexedLineSet> createOpenMBV();
157  protected:
158  void initializeObject(const std::shared_ptr<OpenMBV::IndexedLineSet> &object);
159  };
160 
162  protected:
163  fmatvec::Vec2 l;
164  public:
165  OpenMBVPlane(const fmatvec::Vec2 &l_=fmatvec::Vec2(fmatvec::INIT,1.), const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), l(l_) { }
166  void initializeUsingXML(xercesc::DOMElement *element);
167  std::shared_ptr<OpenMBV::Cuboid> createOpenMBV();
168  protected:
169  void initializeObject(const std::shared_ptr<OpenMBV::Cuboid> &object);
170  };
171 
173  public:
174  enum Type {
175  tube,
176  scaledTube,
177  polyline
178  };
179  enum ColorRepresentation {
180  none=0,
181  deflection,
182  tensileForce,
183  compressiveForce,
184  absoluteForce
185  };
186  protected:
187  double r, cr, sf, n, l;
188  OpenMBVCoilSpring::Type type;
189  public:
190  OpenMBVCoilSpring(double r_=1, double cr_=-1, double sf_=1, double n_=3, double l_=-1, OpenMBVCoilSpring::Type type_=OpenMBVCoilSpring::tube, unsigned int cR=0, double minCol=0, double maxCol=1, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0);
191  void initializeUsingXML(xercesc::DOMElement *element);
192  std::shared_ptr<OpenMBV::CoilSpring> createOpenMBV();
193  protected:
194  void initializeObject(const std::shared_ptr<OpenMBV::CoilSpring> &object);
195  };
196 
198  protected:
199  std::vector<double> nodes;
200  bool filled;
201  public:
202  OpenMBVPlanarContour(const std::vector<double> &nodes_=std::vector<double>(), bool filled_=false, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), nodes(nodes_), filled(filled_) { }
203  std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
204  void initializeUsingXML(xercesc::DOMElement *element);
205  const std::vector<double>& getNodes() const { return nodes; }
206  bool getFilled() const { return filled; }
207  };
208 
210  protected:
211  std::vector<double> etaNodes, xiNodes;
212  public:
213  OpenMBVSpatialContour(const std::vector<double> &etaNodes_=std::vector<double>(), const std::vector<double> &xiNodes_=std::vector<double>(), const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVColoredBody(dc,tp,ps,lw), etaNodes(etaNodes_), xiNodes(xiNodes_) { }
214  std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
215  void initializeUsingXML(xercesc::DOMElement *element);
216  const std::vector<double>& getEtaNodes() const { return etaNodes; }
217  const std::vector<double>& getXiNodes() const { return xiNodes; }
218  };
219 
220 }
221 
222 #endif
Definition: openmbv_utils.h:209
Definition: openmbv_utils.h:172
Definition: openmbv_utils.h:150
Definition: openmbv_utils.h:161
Definition: openmbv_utils.h:79
Definition: openmbv_utils.h:49
Definition: openmbv_utils.h:111
Definition: openmbv_utils.h:139
Definition: openmbv_utils.h:128
Definition: openmbv_utils.h:66
Definition: openmbv_utils.h:197
Definition: openmbv_utils.h:39
namespace MBSim
Definition: eigenanalyzer.cc:47