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 #include <mbsim/contour.h>
00024 #include <mbsim/contours/rectangle.h>
00025 #include <mbsim/utils/colors.h>
00026 #include <fmatvec/fmatvec.h>
00027 #include <fmatvec/function.h>
00028 #ifdef HAVE_OPENMBVCPPINTERFACE
00029 #include <mbsim/utils/boost_parameters.h>
00030 #endif
00031 
00032 namespace MBSim {
00033 
00040   class PolynomialFrustum : public MBSim::RigidContour {
00041     public:
00047       PolynomialFrustum(const std::string & name, const fmatvec::Vec & param_);
00048 
00052       virtual ~PolynomialFrustum();
00053 
00054       /* INHERITED INTERFACE OF ELEMENT */
00055       std::string getType() const {
00056         return "PolynomialFrustum";
00057       }
00058       virtual void init(InitStage stage);
00059       /***************************************************/
00060 
00061       /* INHERITED INTERFACE OF CONTOUR*/
00067       virtual fmatvec::Vec2 computeLagrangeParameter(const fmatvec::Vec3 &WrPoint);
00068       /*********************************/
00069 
00074       void setHeight(const double & height_);
00075 
00079       double getHeight();
00080 
00084       double getHeight() const;
00085 
00086 #ifdef HAVE_OPENMBVCPPINTERFACE
00087 
00093       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (polynomialPoints,(int),0)(circularPoints,(int),25)(diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { enableOpenMBV_(diffuseColor,transparency,polynomialPoints,circularPoints); }
00094 
00098       void setColor(const RGBColor & color);
00099 
00103       void setTransparency(const double & transparency);
00104 #endif
00105 
00109       double getValue(const double & x);
00110 
00114       double getValue(const double & x) const;
00115 
00119       double getValueD1(const double & x);
00120 
00124       double getValueD1(const double & x) const;
00125 
00129       double getValueD2(const double & x);
00130 
00134       double getValueD2(const double & x) const;
00135 
00139       double getXPolyMax();
00140 
00145       double getEnclosingSphereRadius();
00146 
00150       fmatvec::Vec3 getEnclosingSphereCenter();
00151 
00155       const fmatvec::Vec & getPolynomialParameters();
00156 
00160       fmatvec::Vec3 computePoint(const double & x, const double & phi);
00161 
00165       fmatvec::Vec3 computeNormal(const double & x, const double & phi);
00166 
00170       fmatvec::Vec3 computeTangentRadial(const double & x, const double & phi);
00171 
00175       fmatvec::Vec3 computeTangentAzimuthal(const double & x, const double & phi);
00176 
00184       fmatvec::Vec3 CP_toP_onPolycurve2D(double x_0, double x_end, fmatvec::Vec2 P);
00185 
00186     protected:
00190       void computeEnclosingSphere();
00191 
00196       fmatvec::Vec parameters;
00197 
00201       double height;
00202 
00206       double sphereRadius;
00207 
00208 #ifdef HAVE_OPENMBVCPPINTERFACE
00209 
00212       RGBColor color;
00213 
00217       double transparency;
00218 
00222       int polynomialPoints;
00223 
00227       int circularPoints;
00228 
00232       void createInventorFile();
00233 
00234       void enableOpenMBV_(const fmatvec::Vec3 &dc, double tp, int polynomialPoints, int circularPoints);
00235 #endif
00236   };
00237 
00243   class ContactPolyfun : public fmatvec::Function<double(double)> {
00244     public:
00248       ContactPolyfun(const double & rhs, const PolynomialFrustum * frustum);
00249       virtual ~ContactPolyfun() {
00250       }
00251 
00252       virtual double operator()(const double &x);
00253       void initializeUsingXML() {
00254       }
00255 
00256     protected:
00257       double rhs;
00258       const PolynomialFrustum * frustum;
00259 
00260   };
00261 
00262 }
00263 
00264 #endif /* POLYNOMIAL_FRUSTUM_H_ */