00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef FREEGCS_GCS_H
00024 #define FREEGCS_GCS_H
00025
00026 #include "SubSystem.h"
00027
00028 namespace GCS
00029 {
00030
00032
00034
00035 enum SolveStatus {
00036 Success = 0,
00037 Converged = 1,
00038 Failed = 2
00039 };
00040
00041 enum Algorithm {
00042 BFGS = 0,
00043 LevenbergMarquardt = 1,
00044 DogLeg = 2
00045 };
00046
00047 class System
00048 {
00049
00050
00051 private:
00052 std::vector<Constraint *> clist;
00053
00054 std::map<Constraint *,VEC_pD > c2p;
00055 std::map<double *,std::vector<Constraint *> > p2c;
00056
00057 SubSystem *subsys0;
00058 SubSystem *subsys1;
00059 SubSystem *subsys2;
00060 void clearSubSystems();
00061
00062 MAP_pD_D reference;
00063 void clearReference();
00064 void resetToReference();
00065
00066 MAP_pD_pD reductionmap;
00067
00068 bool init;
00069
00070 int solve_BFGS(SubSystem *subsys, bool isFine);
00071 int solve_LM(SubSystem *subsys);
00072 int solve_DL(SubSystem *subsys);
00073 public:
00074 System();
00075 System(std::vector<Constraint *> clist_);
00076 ~System();
00077
00078 void clear();
00079 void clearByTag(int tagId);
00080
00081 int addConstraint(Constraint *constr);
00082 void removeConstraint(Constraint *constr);
00083
00084
00085 int addConstraintEqual(double *param1, double *param2, int tagId=0);
00086 int addConstraintDifference(double *param1, double *param2,
00087 double *difference, int tagId=0);
00088 int addConstraintP2PDistance(Point &p1, Point &p2, double *distance, int tagId=0);
00089 int addConstraintP2PAngle(Point &p1, Point &p2, double *angle,
00090 double incr_angle, int tagId=0);
00091 int addConstraintP2PAngle(Point &p1, Point &p2, double *angle, int tagId=0);
00092 int addConstraintP2LDistance(Point &p, Line &l, double *distance, int tagId=0);
00093 int addConstraintPointOnLine(Point &p, Line &l, int tagId=0);
00094 int addConstraintParallel(Line &l1, Line &l2, int tagId=0);
00095 int addConstraintPerpendicular(Line &l1, Line &l2, int tagId=0);
00096 int addConstraintPerpendicular(Point &l1p1, Point &l1p2,
00097 Point &l2p1, Point &l2p2, int tagId=0);
00098 int addConstraintL2LAngle(Line &l1, Line &l2, double *angle, int tagId=0);
00099 int addConstraintL2LAngle(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2,
00100 double *angle, int tagId=0);
00101 int addConstraintMidpointOnLine(Line &l1, Line &l2, int tagId=0);
00102 int addConstraintMidpointOnLine(Point &l1p1, Point &l1p2, Point &l2p1, Point &l2p2,
00103 int tagId=0);
00104
00105
00106 int addConstraintP2PCoincident(Point &p1, Point &p2, int tagId=0);
00107 int addConstraintHorizontal(Line &l, int tagId=0);
00108 int addConstraintHorizontal(Point &p1, Point &p2, int tagId=0);
00109 int addConstraintVertical(Line &l, int tagId=0);
00110 int addConstraintVertical(Point &p1, Point &p2, int tagId=0);
00111 int addConstraintCoordinateX(Point &p, double *x, int tagId=0);
00112 int addConstraintCoordinateY(Point &p, double *y, int tagId=0);
00113 int addConstraintArcRules(Arc &a, int tagId=0);
00114 int addConstraintPointOnCircle(Point &p, Circle &c, int tagId=0);
00115 int addConstraintPointOnArc(Point &p, Arc &a, int tagId=0);
00116 int addConstraintTangent(Line &l, Circle &c, int tagId=0);
00117 int addConstraintTangent(Line &l, Arc &a, int tagId=0);
00118 int addConstraintTangentLine2Arc(Point &p1, Point &p2, Arc &a, int tagId=0);
00119 int addConstraintTangentArc2Line(Arc &a, Point &p1, Point &p2, int tagId=0);
00120 int addConstraintCircleRadius(Circle &c, double *radius, int tagId=0);
00121 int addConstraintArcRadius(Arc &a, double *radius, int tagId=0);
00122 int addConstraintEqualLength(Line &l1, Line &l2, double *length, int tagId=0);
00123 int addConstraintEqualRadius(Circle &c1, Circle &c2, int tagId=0);
00124 int addConstraintEqualRadius(Circle &c1, Arc &a2, int tagId=0);
00125 int addConstraintEqualRadius(Arc &a1, Arc &a2, int tagId=0);
00126 int addConstraintP2PSymmetric(Point &p1, Point &p2, Line &l, int tagId=0);
00127 void rescaleConstraint(int id, double coeff);
00128
00129 void initSolution(VEC_pD ¶ms);
00130
00131 int solve(bool isFine=true, Algorithm alg=DogLeg);
00132 int solve(VEC_pD ¶ms, bool isFine=true, Algorithm alg=DogLeg);
00133 int solve(SubSystem *subsys, bool isFine=true, Algorithm alg=DogLeg);
00134 int solve(SubSystem *subsysA, SubSystem *subsysB, bool isFine=true);
00135
00136 void getSubSystems(std::vector<SubSystem *> &subsysvec);
00137 void applySolution();
00138 void undoSolution();
00139
00140 bool isInit() const { return init; }
00141
00142 int diagnose(VEC_pD ¶ms, VEC_I &conflicting);
00143 };
00144
00146
00148 #define XconvergenceRough 1e-8
00149 #define XconvergenceFine 1e-10
00150 #define smallF 1e-20
00151 #define MaxIterations 100 //Note that the total number of iterations allowed is MaxIterations *xLength
00152
00154
00156
00157 void free(VEC_pD &doublevec);
00158 void free(std::vector<Constraint *> &constrvec);
00159 void free(std::vector<SubSystem *> &subsysvec);
00160
00161 }
00162
00163 #endif // FREEGCS_GCS_H