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
26namespace 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
37namespace MBSim {
38
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 double getsL() const { return sL; }
108 protected:
109 void initializeObject(const std::shared_ptr<OpenMBV::Arrow> &object);
110 };
111
113 public:
114 enum SideOfInteraction {
115 action=0,
116 reaction,
117 both
118 };
119 protected:
120 unsigned int sI;
121 public:
122 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);
123 void initializeUsingXML(xercesc::DOMElement *element);
124 unsigned int getSideOfInteraction() const { return sI; }
125 protected:
126 void initializeObject(const std::shared_ptr<OpenMBV::Arrow> &object);
127 };
128
130 public:
131 enum ColorRepresentation {
132 none=0,
133 absoluteValue,
134 stickslip
135 };
136 public:
137 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);
138 };
139
141 protected:
142 bool path;
143 public:
144 OpenMBVRigidBody(bool path_=false, const fmatvec::Vec3 &dc_=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp_=0, double ps_=0, double lw_=0) :
145 OpenMBVColoredBody(dc_, tp_, ps_, lw_), path(path_) { }
146 void initializeUsingXML(xercesc::DOMElement *element);
147 protected:
148 void initializeObject(const std::shared_ptr<OpenMBV::RigidBody> &object);
149 };
150
152 protected:
153 double size, offset;
154 public:
155 OpenMBVFrame(double size_=1, double offset_=1, bool path=false, const fmatvec::Vec3 &dc=fmatvec::Vec3(std::vector<double>{-1,1,1}), double tp=0, double ps=0, double lw=0) : OpenMBVRigidBody(path, dc,tp,ps,lw), size(size_), offset(offset_) { }
156 void initializeUsingXML(xercesc::DOMElement *element);
157 std::shared_ptr<OpenMBV::Frame> createOpenMBV();
158 protected:
159 void initializeObject(const std::shared_ptr<OpenMBV::Frame> &object);
160 };
161
163 protected:
164 double l;
165 public:
166 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_) { }
167 void initializeUsingXML(xercesc::DOMElement *element);
168 std::shared_ptr<OpenMBV::IndexedLineSet> createOpenMBV();
169 protected:
170 void initializeObject(const std::shared_ptr<OpenMBV::IndexedLineSet> &object);
171 };
172
174 protected:
175 fmatvec::Vec2 l;
176 public:
177 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_) { }
178 void initializeUsingXML(xercesc::DOMElement *element);
179 std::shared_ptr<OpenMBV::Cuboid> createOpenMBV();
180 protected:
181 void initializeObject(const std::shared_ptr<OpenMBV::Cuboid> &object);
182 };
183
185 public:
186 enum Type {
187 tube,
188 scaledTube,
189 polyline
190 };
191 enum ColorRepresentation {
192 none=0,
193 deflection,
194 tensileForce,
195 compressiveForce,
196 absoluteForce
197 };
198 protected:
199 double r, cr, sf, n, l;
200 OpenMBVCoilSpring::Type type;
201 public:
202 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);
203 void initializeUsingXML(xercesc::DOMElement *element);
204 std::shared_ptr<OpenMBV::CoilSpring> createOpenMBV();
205 protected:
206 void initializeObject(const std::shared_ptr<OpenMBV::CoilSpring> &object);
207 };
208
210 protected:
211 std::vector<double> nodes;
212 bool filled;
213 public:
214 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_) { }
215 std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
216 void initializeUsingXML(xercesc::DOMElement *element);
217 const std::vector<double>& getNodes() const { return nodes; }
218 bool getFilled() const { return filled; }
219 };
220
222 protected:
223 std::vector<double> etaNodes, xiNodes;
224 public:
225 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_) { }
226 std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
227 void initializeUsingXML(xercesc::DOMElement *element);
228 const std::vector<double>& getEtaNodes() const { return etaNodes; }
229 const std::vector<double>& getXiNodes() const { return xiNodes; }
230 };
231
232}
233
234#endif
Definition: openmbv_utils.h:79
Definition: openmbv_utils.h:39
Definition: openmbv_utils.h:184
Definition: openmbv_utils.h:49
Definition: openmbv_utils.h:66
Definition: openmbv_utils.h:151
Definition: openmbv_utils.h:129
Definition: openmbv_utils.h:112
Definition: openmbv_utils.h:162
Definition: openmbv_utils.h:209
Definition: openmbv_utils.h:173
Definition: openmbv_utils.h:140
Definition: openmbv_utils.h:221
namespace MBSim
Definition: bilateral_constraint.cc:30