mbsim  4.0.0
MBSim Kernel
planar_nurbs_contour.h
1 /* Copyright (C) 2004-2018 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 _PLANAR_NURBS_CONTOUR_H_
21 #define _PLANAR_NURBS_CONTOUR_H_
22 
23 #include "mbsim/contours/rigid_contour.h"
24 #include "mbsim/utils/boost_parameters.h"
25 #include "mbsim/utils/openmbv_utils.h"
26 #include "mbsim/numerics/nurbs/nurbs_curve.h"
27 #include <openmbvcppinterface/nurbscurve.h>
28 
29 namespace MBSim {
30 
36  public:
37  enum Interpolation {
38  equallySpaced = 0,
39  chordLength,
40  none,
41  unknown
42  };
43 
48  PlanarNurbsContour(const std::string &name="", Frame *R=nullptr) : RigidContour(name,R) { }
49 
53  ~PlanarNurbsContour() override = default;
54 
55  /* INHERITED INTERFACE OF ELEMENT */
56  /***************************************************/
57 
58  /* INHERITED INTERFACE OF CONTOUR */
59  void init(InitStage stage, const InitConfigSet &config) override;
60  double getCurvature(const fmatvec::Vec2 &zeta);
61  fmatvec::Vec3 evalKrPS(const fmatvec::Vec2 &zeta) override;
62  fmatvec::Vec3 evalKs(const fmatvec::Vec2 &zeta) override;
63  fmatvec::Vec3 evalKt(const fmatvec::Vec2 &zeta) override;
64  fmatvec::Vec3 evalKn(const fmatvec::Vec2 &zeta) override;
65  fmatvec::Vec3 evalParDer1Ks(const fmatvec::Vec2 &zeta) override;
66  /***************************************************/
67 
68  /* GETTER / SETTER */
69  void setInterpolation(Interpolation interpolation_) { interpolation = interpolation_; }
70  void setControlPoints(const fmatvec::MatVx4 &cp_) { cp <<= cp_; }
71  void setControlPoints(const fmatvec::MatVx3 &cp_);
72  void setControlPoints(const std::vector<fmatvec::Vec4> &cp_);
73  void setControlPoints(const std::vector<fmatvec::Vec3> &cp_);
74  void setNumberOfControlPoints(int n_) { n = n_; }
75  void setKnotVector(const fmatvec::VecV &knot_) { knot <<= knot_; }
76  void setDegree(int degree_) { degree = degree_; }
77  /***************************************************/
78 
79  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (nodes,(const std::vector<double>&),std::vector<double>())(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
80  OpenMBVColoredBody ombv(diffuseColor,transparency,pointSize,lineWidth);
81  openMBVRigidBody=ombv.createOpenMBV<OpenMBV::NurbsCurve>();
82  }
83 
84  void initializeUsingXML(xercesc::DOMElement *element) override;
85 
86  bool isZetaOutside(const fmatvec::Vec2 &zeta) override { return open and (zeta(0) < etaNodes[0] or zeta(0) > etaNodes[etaNodes.size()-1]); }
87 
88  void setOpen(bool open_=true) { open = open_; }
89 
90  protected:
91  void updateHessianMatrix(double eta);
92  const fmatvec::MatVx4& evalHessianMatrix(double eta){ if(fabs(eta-etaOld)>1e-13) updateHessianMatrix(eta); return hess; }
93 
94  Interpolation interpolation{none};
95  fmatvec::MatVx4 cp;
96  int n{0};
97  fmatvec::VecV knot;
98  int degree{3};
99  bool open{false};
100  NurbsCurve crv;
101  double etaOld{0};
102  fmatvec::MatVx4 hess;
103  };
104 
105 }
106 
107 #endif
basic class for rigid contours
Definition: rigid_contour.h:37
PlanarNurbsContour(const std::string &name="", Frame *R=nullptr)
constructor
Definition: planar_nurbs_contour.h:48
InitStage
The stages of the initialization.
Definition: element.h:62
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: planar_nurbs_contour.cc:61
nurbs curve
Definition: planar_nurbs_contour.h:35
std::string name
name of element
Definition: element.h:249
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
~PlanarNurbsContour() override=default
destructor
Frame * R
coordinate system of contour
Definition: rigid_contour.h:133
namespace MBSim
Definition: eigenanalyzer.cc:47