Constraints.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Konstantinos Poulios      (logari81@gmail.com) 2011     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef FREEGCS_CONSTRAINTS_H
00024 #define FREEGCS_CONSTRAINTS_H
00025 
00026 #include "Geo.h"
00027 #include "Util.h"
00028 
00029 namespace GCS
00030 {
00031 
00033     // Constraints
00035 
00036     enum ConstraintType {
00037         None = 0,
00038         Equal = 1,
00039         Difference = 2,
00040         P2PDistance = 3,
00041         P2PAngle = 4,
00042         P2LDistance = 5,
00043         PointOnLine = 6,
00044         Parallel = 7,
00045         Perpendicular = 8,
00046         L2LAngle = 9,
00047         MidpointOnLine = 10
00048     };
00049 
00050     class Constraint
00051     {
00052     protected:
00053         VEC_pD origpvec; // is used only as a reference for redirecting and reverting pvec
00054         VEC_pD pvec;
00055         double scale;
00056         int tag;
00057     public:
00058         Constraint();
00059 
00060         inline VEC_pD params() { return pvec; }
00061 
00062         void redirectParams(MAP_pD_pD redirectionmap);
00063         void revertParams();
00064         void setTag(int tagId) { tag = tagId; }
00065         int getTag() { return tag; }
00066 
00067         virtual ConstraintType getTypeId();
00068         virtual void rescale(double coef=1.);
00069         virtual double error();
00070         virtual double grad(double *);
00071         // virtual void grad(MAP_pD_D &deriv);  --> TODO: vectorized grad version
00072         virtual double maxStep(MAP_pD_D &dir, double lim=1.);
00073     };
00074 
00075     // Equal
00076     class ConstraintEqual : public Constraint
00077     {
00078     private:
00079         inline double* param1() { return pvec[0]; }
00080         inline double* param2() { return pvec[1]; }
00081     public:
00082         ConstraintEqual(double *p1, double *p2);
00083         virtual ConstraintType getTypeId();
00084         virtual void rescale(double coef=1.);
00085         virtual double error();
00086         virtual double grad(double *);
00087     };
00088 
00089     // Difference
00090     class ConstraintDifference : public Constraint
00091     {
00092     private:
00093         inline double* param1() { return pvec[0]; }
00094         inline double* param2() { return pvec[1]; }
00095         inline double* difference() { return pvec[2]; }
00096     public:
00097         ConstraintDifference(double *p1, double *p2, double *d);
00098         virtual ConstraintType getTypeId();
00099         virtual void rescale(double coef=1.);
00100         virtual double error();
00101         virtual double grad(double *);
00102     };
00103 
00104     // P2PDistance
00105     class ConstraintP2PDistance : public Constraint
00106     {
00107     private:
00108         inline double* p1x() { return pvec[0]; }
00109         inline double* p1y() { return pvec[1]; }
00110         inline double* p2x() { return pvec[2]; }
00111         inline double* p2y() { return pvec[3]; }
00112         inline double* distance() { return pvec[4]; }
00113     public:
00114         ConstraintP2PDistance(Point &p1, Point &p2, double *d);
00115         virtual ConstraintType getTypeId();
00116         virtual void rescale(double coef=1.);
00117         virtual double error();
00118         virtual double grad(double *);
00119         virtual double maxStep(MAP_pD_D &dir, double lim=1.);
00120     };
00121 
00122     // P2PAngle
00123     class ConstraintP2PAngle : public Constraint
00124     {
00125     private:
00126         inline double* p1x() { return pvec[0]; }
00127         inline double* p1y() { return pvec[1]; }
00128         inline double* p2x() { return pvec[2]; }
00129         inline double* p2y() { return pvec[3]; }
00130         inline double* angle() { return pvec[4]; }
00131         double da;
00132     public:
00133         ConstraintP2PAngle(Point &p1, Point &p2, double *a, double da_=0.);
00134         virtual ConstraintType getTypeId();
00135         virtual void rescale(double coef=1.);
00136         virtual double error();
00137         virtual double grad(double *);
00138         virtual double maxStep(MAP_pD_D &dir, double lim=1.);
00139     };
00140 
00141     // P2LDistance
00142     class ConstraintP2LDistance : public Constraint
00143     {
00144     private:
00145         inline double* p0x() { return pvec[0]; }
00146         inline double* p0y() { return pvec[1]; }
00147         inline double* p1x() { return pvec[2]; }
00148         inline double* p1y() { return pvec[3]; }
00149         inline double* p2x() { return pvec[4]; }
00150         inline double* p2y() { return pvec[5]; }
00151         inline double* distance() { return pvec[6]; }
00152     public:
00153         ConstraintP2LDistance(Point &p, Line &l, double *d);
00154         virtual ConstraintType getTypeId();
00155         virtual void rescale(double coef=1.);
00156         virtual double error();
00157         virtual double grad(double *);
00158         virtual double maxStep(MAP_pD_D &dir, double lim=1.);
00159     };
00160 
00161     // PointOnLine
00162     class ConstraintPointOnLine : public Constraint
00163     {
00164     private:
00165         inline double* p0x() { return pvec[0]; }
00166         inline double* p0y() { return pvec[1]; }
00167         inline double* p1x() { return pvec[2]; }
00168         inline double* p1y() { return pvec[3]; }
00169         inline double* p2x() { return pvec[4]; }
00170         inline double* p2y() { return pvec[5]; }
00171     public:
00172         ConstraintPointOnLine(Point &p, Line &l);
00173         virtual ConstraintType getTypeId();
00174         virtual void rescale(double coef=1.);
00175         virtual double error();
00176         virtual double grad(double *);
00177     };
00178 
00179     // Parallel
00180     class ConstraintParallel : public Constraint
00181     {
00182     private:
00183         inline double* l1p1x() { return pvec[0]; }
00184         inline double* l1p1y() { return pvec[1]; }
00185         inline double* l1p2x() { return pvec[2]; }
00186         inline double* l1p2y() { return pvec[3]; }
00187         inline double* l2p1x() { return pvec[4]; }
00188         inline double* l2p1y() { return pvec[5]; }
00189         inline double* l2p2x() { return pvec[6]; }
00190         inline double* l2p2y() { return pvec[7]; }
00191     public:
00192         ConstraintParallel(Line &l1, Line &l2);
00193         virtual ConstraintType getTypeId();
00194         virtual void rescale(double coef=1.);
00195         virtual double error();
00196         virtual double grad(double *);
00197     };
00198 
00199     // Perpendicular
00200     class ConstraintPerpendicular : public Constraint
00201     {
00202     private:
00203         inline double* l1p1x() { return pvec[0]; }
00204         inline double* l1p1y() { return pvec[1]; }
00205         inline double* l1p2x() { return pvec[2]; }
00206         inline double* l1p2y() { return pvec[3]; }
00207         inline double* l2p1x() { return pvec[4]; }
00208         inline double* l2p1y() { return pvec[5]; }
00209         inline double* l2p2x() { return pvec[6]; }
00210         inline double* l2p2y() { return pvec[7]; }
00211     public:
00212         ConstraintPerpendicular(Line &l1, Line &l2);
00213         ConstraintPerpendicular(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2);
00214         virtual ConstraintType getTypeId();
00215         virtual void rescale(double coef=1.);
00216         virtual double error();
00217         virtual double grad(double *);
00218     };
00219 
00220     // L2LAngle
00221     class ConstraintL2LAngle : public Constraint
00222     {
00223     private:
00224         inline double* l1p1x() { return pvec[0]; }
00225         inline double* l1p1y() { return pvec[1]; }
00226         inline double* l1p2x() { return pvec[2]; }
00227         inline double* l1p2y() { return pvec[3]; }
00228         inline double* l2p1x() { return pvec[4]; }
00229         inline double* l2p1y() { return pvec[5]; }
00230         inline double* l2p2x() { return pvec[6]; }
00231         inline double* l2p2y() { return pvec[7]; }
00232         inline double* angle() { return pvec[8]; }
00233     public:
00234         ConstraintL2LAngle(Line &l1, Line &l2, double *a);
00235         ConstraintL2LAngle(Point &l1p1, Point &l1p2,
00236                            Point &l2p1, Point &l2p2, double *a);
00237         virtual ConstraintType getTypeId();
00238         virtual void rescale(double coef=1.);
00239         virtual double error();
00240         virtual double grad(double *);
00241         virtual double maxStep(MAP_pD_D &dir, double lim=1.);
00242     };
00243 
00244     // MidpointOnLine
00245     class ConstraintMidpointOnLine : public Constraint
00246     {
00247     private:
00248         inline double* l1p1x() { return pvec[0]; }
00249         inline double* l1p1y() { return pvec[1]; }
00250         inline double* l1p2x() { return pvec[2]; }
00251         inline double* l1p2y() { return pvec[3]; }
00252         inline double* l2p1x() { return pvec[4]; }
00253         inline double* l2p1y() { return pvec[5]; }
00254         inline double* l2p2x() { return pvec[6]; }
00255         inline double* l2p2y() { return pvec[7]; }
00256     public:
00257         ConstraintMidpointOnLine(Line &l1, Line &l2);
00258         ConstraintMidpointOnLine(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2);
00259         virtual ConstraintType getTypeId();
00260         virtual void rescale(double coef=1.);
00261         virtual double error();
00262         virtual double grad(double *);
00263     };
00264 
00265 } //namespace GCS
00266 
00267 #endif // FREEGCS_CONSTRAINTS_H

Generated on Wed Nov 23 19:00:04 2011 for FreeCAD by  doxygen 1.6.1