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