MBSim

Project Page
polynomial_frustum.h
00001 /* Copyright (C) 2004-2012 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU Lesser General Public
00005  * License as published by the Free Software Foundation; either
00006  * version 2.1 of the License, or (at your option) any later version.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Lesser General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public
00014  * License along with this library; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: martin.o.foerg@googlemail.com
00018  */
00019 
00020 #ifndef POLYNOMIAL_FRUSTUM_H_
00021 #define POLYNOMIAL_FRUSTUM_H_
00022 #include <iostream>
00023 
00024 #include <mbsim/contour.h>
00025 
00026 #include <mbsim/contours/rectangle.h>
00027 
00028 #include <mbsim/utils/colors.h>
00029 
00030 #include <fmatvec/fmatvec.h>
00031 
00032 #include <mbsim/utils/function.h>
00033 
00034 namespace MBSim {
00035 
00042   class PolynomialFrustum : public MBSim::RigidContour {
00043     public:
00049       PolynomialFrustum(const std::string & name, const fmatvec::Vec & param_);
00050 
00054       virtual ~PolynomialFrustum();
00055 
00056       /* INHERITED INTERFACE OF ELEMENT */
00057       std::string getType() const {
00058         return "PolynomialFrustum";
00059       }
00060       virtual void init(InitStage stage);
00061       /***************************************************/
00062 
00063       /* INHERITED INTERFACE OF CONTOUR*/
00069       virtual fmatvec::Vec2 computeLagrangeParameter(const fmatvec::Vec3 &WrPoint);
00070       /*********************************/
00071 
00076       void setHeight(const double & height_);
00077       double getHeight();
00078       double getHeight() const;
00079 
00080 #ifdef HAVE_OPENMBVCPPINTERFACE
00081 
00087       void enableOpenMBV(bool enable = true, int polynomialPoints = 0, int circularPoints = 25);
00088 
00092       void setColor(const RGBColor & color);
00093 
00097       void setTransparency(const double & transparency);
00098 #endif
00099 
00103       double getValue(const double & x);
00104 
00108       double getValue(const double & x) const;
00109 
00113       double getValueD1(const double & x);
00114 
00118       double getValueD1(const double & x) const;
00119 
00123       double getValueD2(const double & x);
00124 
00128       double getValueD2(const double & x) const;
00129 
00133       double getXPolyMax();
00134 
00139       double getEnclosingSphereRadius();
00140 
00144       fmatvec::Vec3 getEnclosingSphereCenter();
00145 
00149       const fmatvec::Vec & getPolynomialParameters();
00150 
00154       fmatvec::Vec3 computePoint(const double & x, const double & phi);
00155 
00159       fmatvec::Vec3 computeNormal(const double & x, const double & phi);
00160 
00164       fmatvec::Vec3 computeTangentRadial(const double & x, const double & phi);
00165 
00169       fmatvec::Vec3 computeTangentAzimuthal(const double & x, const double & phi);
00170 
00178       fmatvec::Vec3 CP_toP_onPolycurve2D(double x_0, double x_end, fmatvec::Vec2 P);
00179 
00180     protected:
00184       void computeEnclosingSphere();
00185 
00190       fmatvec::Vec parameters;
00191 
00195       double height;
00196 
00200       double sphereRadius;
00201 
00202 #ifdef HAVE_OPENMBVCPPINTERFACE
00203 
00206       RGBColor color;
00207 
00211       double transparency;
00212 
00216       int polynomialPoints;
00217 
00221       int circularPoints;
00222 
00226       void createInventorFile();
00227 
00228 #endif
00229   };
00230 
00236   class ContactPolyfun : public MBSim::Function1<double, double> {
00237     public:
00238       ContactPolyfun(const double & rhs, const PolynomialFrustum * frustum);
00239       virtual ~ContactPolyfun() {
00240       }
00241 
00242       virtual double operator()(const double & x, const void * = NULL);
00243       void initializeUsingXML() {
00244       }
00245 
00246     protected:
00247       double rhs;
00248       const PolynomialFrustum * frustum;
00249 
00250   };
00251 
00252 }
00253 
00254 #endif /* POLYNOMIAL_FRUSTUM_H_ */