MBSim

Project Page
circle.h
00001 /* Copyright (C) 2004-2009 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: thschindler@users.berlios.de
00018  */
00019 
00020 #ifndef CIRCLE_H_
00021 #define CIRCLE_H_
00022 
00023 #include "fmatvec/fmatvec.h"
00024 #include "mbsim/contour.h"
00025 #include "mbsim/utils/eps.h"
00026 
00027 #ifdef HAVE_OPENMBVCPPINTERFACE
00028 #include <mbsim/utils/openmbv_utils.h>
00029 #endif
00030 
00031 namespace MBSim {
00032 
00039   class Circle : public RigidContour {
00040     public:
00046       Circle(const std::string& name, Frame *R=0);
00047 
00053       Circle(const std::string& name, bool outCont_, Frame *R=0);
00054 
00061       Circle(const std::string& name, double r_, bool outCont_, Frame *R=0);
00062 
00066       virtual ~Circle();
00067 
00068       /* INHERITED INTERFACE OF ELEMENT */
00069       std::string getType() const { return "Circle"; }
00070       virtual void init(InitStage stage);
00071       /***************************************************/
00072 
00073       /* INHERITED INTERFACE OF CONTOUR */
00074       virtual double computeCurvature(ContourPointData &cp) { return curvature; }
00075       virtual fmatvec::Vec2 computeLagrangeParameter(const fmatvec::Vec3& WrPoint);
00076       /***************************************************/
00077 
00078       /* GETTER / SETTER */
00079       void setRadius(double r_);        
00080       void setOutCont(bool outCont_);
00081       double getRadius() const;
00082       bool getOutCont() const;
00083       /***************************************************/
00084 
00085 #ifdef HAVE_OPENMBVCPPINTERFACE
00086       BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (diffuseColor,(const fmatvec::Vec3&),"[-1;1;1]")(transparency,(double),0))) { 
00087         OpenMBVCircle ombv(1,diffuseColor,transparency);
00088         openMBVRigidBody=ombv.createOpenMBV(); 
00089       }
00090 #endif
00091       
00092     virtual void initializeUsingXML(xercesc::DOMElement *element);
00093     virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *element);
00094 
00095     protected:
00099       double r;
00100 
00104       double curvature;
00105 
00106     private:
00110       bool outCont;     
00111   };
00112 
00113   inline void Circle::setRadius(double r_) { r = r_; outCont ? curvature = 1./r_ : curvature = -1./r_; }        
00114   inline void Circle::setOutCont(bool outCont_) { outCont = outCont_; if(fabs(r)>epsroot()) outCont ? curvature = 1./r : curvature = -1./r; }
00115   inline double Circle::getRadius() const { return r; }
00116   inline bool Circle::getOutCont() const { return outCont; }
00117 
00118 }
00119 
00120 #endif /* CIRCLE_H_ */
00121