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 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 bool path;
142 public:
143 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) :
144 OpenMBVColoredBody(dc_, tp_, ps_, lw_), path(path_) { }
145 void initializeUsingXML(xercesc::DOMElement *element);
146 protected:
147 void initializeObject(const std::shared_ptr<OpenMBV::RigidBody> &object);
148 };
149
151 protected:
152 double size, offset;
153 public:
154 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_) { }
155 void initializeUsingXML(xercesc::DOMElement *element);
156 std::shared_ptr<OpenMBV::Frame> createOpenMBV();
157 protected:
158 void initializeObject(const std::shared_ptr<OpenMBV::Frame> &object);
159 };
160
162 protected:
163 double l;
164 public:
165 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_) { }
166 void initializeUsingXML(xercesc::DOMElement *element);
167 std::shared_ptr<OpenMBV::IndexedLineSet> createOpenMBV();
168 protected:
169 void initializeObject(const std::shared_ptr<OpenMBV::IndexedLineSet> &object);
170 };
171
173 protected:
174 fmatvec::Vec2 l;
175 public:
176 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_) { }
177 void initializeUsingXML(xercesc::DOMElement *element);
178 std::shared_ptr<OpenMBV::Cuboid> createOpenMBV();
179 protected:
180 void initializeObject(const std::shared_ptr<OpenMBV::Cuboid> &object);
181 };
182
184 public:
185 enum Type {
186 tube,
187 scaledTube,
188 polyline
189 };
190 enum ColorRepresentation {
191 none=0,
192 deflection,
193 tensileForce,
194 compressiveForce,
195 absoluteForce
196 };
197 protected:
198 double r, cr, sf, n, l;
199 OpenMBVCoilSpring::Type type;
200 public:
201 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);
202 void initializeUsingXML(xercesc::DOMElement *element);
203 std::shared_ptr<OpenMBV::CoilSpring> createOpenMBV();
204 protected:
205 void initializeObject(const std::shared_ptr<OpenMBV::CoilSpring> &object);
206 };
207
209 protected:
210 std::vector<double> nodes;
211 bool filled;
212 public:
213 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_) { }
214 std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
215 void initializeUsingXML(xercesc::DOMElement *element);
216 const std::vector<double>& getNodes() const { return nodes; }
217 bool getFilled() const { return filled; }
218 };
219
221 protected:
222 std::vector<double> etaNodes, xiNodes;
223 public:
224 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_) { }
225 std::shared_ptr<OpenMBV::RigidBody> createOpenMBV();
226 void initializeUsingXML(xercesc::DOMElement *element);
227 const std::vector<double>& getEtaNodes() const { return etaNodes; }
228 const std::vector<double>& getXiNodes() const { return xiNodes; }
229 };
230
231}
232
233#endif
Definition: openmbv_utils.h:79
Definition: openmbv_utils.h:39
Definition: openmbv_utils.h:183
Definition: openmbv_utils.h:49
Definition: openmbv_utils.h:66
Definition: openmbv_utils.h:150
Definition: openmbv_utils.h:128
Definition: openmbv_utils.h:111
Definition: openmbv_utils.h:161
Definition: openmbv_utils.h:208
Definition: openmbv_utils.h:172
Definition: openmbv_utils.h:139
Definition: openmbv_utils.h:220
namespace MBSim
Definition: bilateral_constraint.cc:30