00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __DRA_WIN_OBJ_H_
00029 #define __DRA_WIN_OBJ_H_
00030
00031 #ifdef MIP_HOST_APPLE
00032 #include <applePatch.h>
00033 #endif
00034
00035 #include <assert.h>
00036 #include <algorithm>
00037
00038 #include <baselib.h>
00039
00040
00041 using namespace std;
00042
00043 namespace MipResources{
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00093 class DraWinBoundBox{
00094 private:
00095 friend class DraWinGL;
00096
00097 static const Decimal DRA_WIN_BB_DEFAULT_XMIN;
00098 static const Decimal DRA_WIN_BB_DEFAULT_YMIN;
00099 static const Decimal DRA_WIN_BB_DEFAULT_XMAX;
00100 static const Decimal DRA_WIN_BB_DEFAULT_YMAX;
00101 bool _clear;
00102 bool _locked;
00103
00105 inline void clear(){
00106 _clear = true;
00107 unlock();
00108 }
00110 inline void unlock(){
00111 _locked = false;
00112 }
00114 inline void lock(){
00115 _locked = true;
00116 }
00117
00118 public:
00119 Decimal xm;
00120 Decimal ym;
00121 Decimal xM;
00122 Decimal yM;
00123
00125 DraWinBoundBox();
00126
00132 DraWinBoundBox(Decimal xm,Decimal ym,Decimal xM,Decimal yM);
00133
00137 DraWinBoundBox(Position p1,Position p2);
00138
00143 void extend(DraWinBoundBox bb);
00144
00149 void extend(Position p);
00150
00153 inline Decimal diameter(){
00154 return sqrt((xM-xm)*(xM-xm) + (yM-ym)*(yM-ym));
00155 }
00156
00159 inline Position center(){
00160 return Position( (xM+xm)/2.0 , (yM-ym)/2.0 );
00161 }
00162
00165 const DraWinBoundBox operator*(Pose p);
00166 };
00167
00172 class ColorComponent{
00173 private:
00174 Decimal _value;
00175 public:
00177 inline ColorComponent(){
00178 _value = 0.0;
00179 }
00181 inline ColorComponent(Decimal c){
00182 _value=min(Decimal(1.0),max(Decimal(0.0),c));
00183 }
00185 inline ColorComponent(const ColorComponent& c){
00186 _value = c._value;
00187 }
00189 ColorComponent& operator =(const ColorComponent& c);
00190
00193 string print();
00194
00196 inline operator Decimal(){
00197 return _value;
00198 }
00199 };
00200
00204 class Color{
00205 private:
00206 ColorComponent _red;
00207 ColorComponent _green;
00208 ColorComponent _blue;
00209 public:
00211 Color(){}
00216 Color(Decimal r,Decimal g,Decimal b);
00217
00219 Color(const Color& c);
00220
00222 Color& operator =(const Color& c);
00223
00225 inline ColorComponent red(){
00226 return _red;
00227 }
00229 inline ColorComponent green(){
00230 return _green;
00231 }
00233 inline ColorComponent blue(){
00234 return _blue;
00235 }
00237 string print();
00238 };
00239
00240
00244 class Colors{
00245 private:
00246 static const Decimal NONE;
00247 static const Decimal DARK;
00248 static const Decimal MEDIUM;
00249 static const Decimal LIGHT;
00250 public:
00251 static const Color black() {return Color(NONE,NONE,NONE);}
00252 static const Color white() {return Color(LIGHT,LIGHT,LIGHT);}
00253
00254 static const Color darkGrey() {return Color(DARK,DARK,DARK);}
00255 static const Color lightGrey() {return Color(MEDIUM,MEDIUM,MEDIUM);}
00256
00257 static const Color lightRed() {return Color(LIGHT,NONE,NONE);}
00258 static const Color red() {return Color(MEDIUM,NONE,NONE);}
00259 static const Color darkRed() {return Color(DARK,NONE,NONE);}
00260
00261 static const Color lightGreen() {return Color(NONE,LIGHT,NONE);}
00262 static const Color green() {return Color(NONE,MEDIUM,NONE);}
00263 static const Color darkGreen() {return Color(NONE,DARK,NONE);}
00264
00265 static const Color lightBlue() {return Color(NONE,NONE,LIGHT);}
00266 static const Color blue() {return Color(NONE,NONE,MEDIUM);}
00267 static const Color darkBlue() {return Color(NONE,NONE,DARK);}
00268
00269 static const Color lightMagenta() {return Color(LIGHT,NONE,LIGHT);}
00270 static const Color magenta() {return Color(MEDIUM,NONE,MEDIUM);}
00271 static const Color darkMagenta() {return Color(DARK,NONE,DARK);}
00272
00273 static const Color lightCyan() {return Color(NONE,LIGHT,LIGHT);}
00274 static const Color cyan() {return Color(NONE,MEDIUM,MEDIUM);}
00275 static const Color darkCyan() {return Color(NONE,DARK,DARK);}
00276
00277 static const Color lightYellow(){return Color(LIGHT,LIGHT,NONE);}
00278 static const Color yellow() {return Color(MEDIUM,MEDIUM,NONE);}
00279 static const Color darkYellow() {return Color(DARK,DARK,NONE);}
00280
00281 static const Color orange() {return Color(LIGHT,MEDIUM,NONE);}
00282 static const Color darkOrange() {return Color(MEDIUM,DARK,NONE);}
00283
00284
00285
00286 };
00287
00291 enum DraWinObjPlate{
00292 DRA_WIN_OBJ_NULL,
00293 DRA_WIN_OBJ_POINT_2D,
00294 DRA_WIN_OBJ_POINTS_2D,
00295 DRA_WIN_OBJ_POLYGON_2D,
00296 DRA_WIN_OBJ_SEG_2D,
00297 DRA_WIN_OBJ_DISK_2D,
00298 DRA_WIN_OBJ_MOBROB_2D,
00299 DRA_WIN_OBJ_KHEPERA_2D,
00300 DRA_WIN_OBJ_QUAD_3D,
00301 DRA_WIN_OBJ_PAR_3D,
00302 DRA_WIN_OBJ_HLINE_2D,
00303 DRA_WIN_OBJ_CMD_BB_2D,
00304 DRA_WIN_OBJ_COV_ELLIPSE_2D,
00305 DRA_WIN_OBJ_NUM
00306 };
00307
00311 static const char* draWinObjNames[DRA_WIN_OBJ_NUM]={
00312 "DraWinObjNull",
00313 "DraWinObjPoint2D",
00314 "DraWinObjPoints2D",
00315 "DraWinObjPolygon2D",
00316 "DraWinObjSeg2D",
00317 "DraWinObjDisk2D",
00318 "DraWinObjMobRob2D",
00319 "DraWinObjKhepera2D",
00320 "DraWinObjQuad3D",
00321 "DraWinObjParallelepiped3D",
00322 "DraWinObjHalfLine2D",
00323 "DraWinObjCovEllipse2D",
00324 "DraWinObjCmdBB2D"
00325 };
00326
00330 class DraWinObj{
00331 protected:
00332 Color _color;
00333 Pose _pose;
00334 public:
00336 virtual DraWinObjPlate plate()=0;
00337
00340 inline void setPose(Pose p){
00341 _pose = p;
00342 }
00344 inline Pose pose(void){
00345 return _pose;
00346 }
00349 inline void setColor(Color c){
00350 _color = c;
00351 }
00354 void setColor(int num);
00355
00358 inline Color color(void){
00359 return _color;
00360 }
00361
00363 virtual void boundBox(DraWinBoundBox& bb)=0;
00364 };
00365
00369 class CmdDraWinObj : public DraWinObj{};
00370
00374 class FigDraWinObj : public DraWinObj{};
00375
00376
00379 typedef vector<DraWinObj*> DraWinList;
00380
00381
00384 typedef vector<DraWinList> DraWinLists;
00385
00386
00389 class Point2D : public FigDraWinObj{
00390 private:
00391 Position _point;
00392 Decimal _pointSize;
00393 public:
00397 Point2D(Position p,Decimal pS=1.0);
00398
00401 inline DraWinObjPlate plate(){
00402 return DRA_WIN_OBJ_POINT_2D;
00403 }
00404
00407 inline Position point(){
00408 return _point;
00409 }
00410
00413 inline Decimal pointSize(){
00414 return _pointSize;
00415 }
00416
00419 void boundBox(DraWinBoundBox& bb);
00420 };
00421
00425 class Points2D : public FigDraWinObj{
00426 private:
00427 vector<Position> _points;
00428 Decimal _pointsSize;
00429 unsigned int _size;
00430 DraWinBoundBox _bb;
00431 public:
00435 Points2D(unsigned int projectedSize,Decimal pS = 1.0);
00436
00440 unsigned int push_back(Position p);
00441
00445 inline Position point(unsigned int i){
00446 assert(i<_size);
00447 return _points[i];
00448 }
00449
00452 inline DraWinObjPlate plate(){
00453 return DRA_WIN_OBJ_POINTS_2D;
00454 }
00455
00458 inline unsigned int size(){
00459 return _size;
00460 }
00461
00464 inline Decimal pointsSize(){
00465 return _pointsSize;
00466 }
00467
00470 inline void boundBox(DraWinBoundBox& bb){
00471 bb = _bb*pose();
00472 }
00473 };
00474
00475
00478 class Polygon2D : public Points2D{
00479 private:
00480 bool _contour;
00481 Decimal _thickness;
00482 public:
00483
00487 inline Polygon2D(unsigned int projectedSize, bool contour=false, Decimal thickness=1.0) : Points2D(projectedSize){
00488 _contour = contour;
00489 _thickness = thickness;
00490
00491 }
00492
00495 inline bool contour(){
00496 return _contour;
00497 }
00498
00501 inline Decimal thickness(){
00502 return _thickness;
00503 }
00504
00507 inline DraWinObjPlate plate(){
00508 return DRA_WIN_OBJ_POLYGON_2D;
00509 }
00510 };
00511
00512
00515 class Segment2D : public FigDraWinObj{
00516 private:
00517 Position _p1,_p2;
00518 public:
00519
00523 Segment2D(Position v1,Position v2){
00524 _p1 = v1;
00525 _p2 = v2;
00526 }
00527
00530 DraWinObjPlate plate(){
00531 return DRA_WIN_OBJ_SEG_2D;
00532 }
00533
00536 Position p1(){
00537 return _p1;
00538 }
00539
00542 Position p2(){
00543 return _p2;
00544 }
00545
00548 void boundBox(DraWinBoundBox& bb);
00549 };
00550
00553 class Disk2D : public FigDraWinObj{
00554 private:
00555 Position _center;
00556 Decimal _extRadius;
00557 Decimal _intRadius;
00558
00559 public:
00564 Disk2D(Position c,Decimal er,Decimal ir=0.0);
00565
00568 inline DraWinObjPlate plate(){
00569 return DRA_WIN_OBJ_DISK_2D;
00570 }
00571
00574 inline Position center(){
00575 return _center;
00576 }
00577
00580 inline Decimal intRadius(){
00581 return _intRadius;
00582 }
00583
00586 inline Decimal extRadius(){
00587 return _extRadius;
00588 }
00589
00592 inline Decimal radius(){
00593 return extRadius();
00594 }
00595
00598 void boundBox(DraWinBoundBox& bb);
00599 };
00600
00601
00604 class MobileRob2D : public FigDraWinObj{
00605 private:
00606 Pose _pose;
00607 Decimal _radius;
00608 public:
00609
00613 MobileRob2D(Pose q,Decimal r);
00614
00617 inline DraWinObjPlate plate(){
00618 return DRA_WIN_OBJ_MOBROB_2D;
00619 }
00620
00623 inline Pose pose(){
00624 return _pose;
00625 }
00626
00629 inline Decimal radius(){
00630 return _radius;
00631 }
00632
00635 void boundBox(DraWinBoundBox& bb);
00636 };
00637
00638
00639
00640
00643 class Khepera2D : public FigDraWinObj{
00644 private:
00645 Pose _pose;
00646 Decimal _radius;
00647 public:
00648
00652 Khepera2D(Pose q);
00653
00656 inline DraWinObjPlate plate(){
00657 return DRA_WIN_OBJ_KHEPERA_2D;
00658 }
00659
00662 inline Pose pose(){
00663 return _pose;
00664 }
00665
00668 inline Decimal radius(){
00669 return _radius;
00670 }
00671
00674 void boundBox(DraWinBoundBox& bb);
00675 };
00676
00679 class Quad3D : public FigDraWinObj{
00680 private:
00681 Pose3D _pose;
00682 Decimal _radius;
00683 public:
00684
00688 Quad3D(Pose3D q,Decimal rad);
00689
00692 inline DraWinObjPlate plate(){
00693 return DRA_WIN_OBJ_QUAD_3D;
00694 }
00695
00698 inline Pose3D pose(){
00699 return _pose;
00700 }
00701
00704 inline Decimal radius(){
00705 return _radius;
00706 }
00707
00710 void boundBox(DraWinBoundBox& bb);
00711 };
00712
00715 class Parallelepiped3D : public FigDraWinObj{
00716 private:
00717 Position3D _x1;
00718 Position3D _x2;
00719 Position3D _trasl;
00720 Orientation3D _ori;
00721 Decimal _red;
00722 Decimal _green;
00723 Decimal _blue;
00724
00725 public:
00726
00730 Parallelepiped3D(Decimal x1,Decimal x2,Decimal y1,Decimal y2,Decimal z1,Decimal z2, Position3D trasl, Orientation3D ori,Decimal red,Decimal green,Decimal blue);
00731
00732 Parallelepiped3D(Position3D startPoint,Position3D endPoint,Position3D trasl, Orientation3D ori,Decimal red,Decimal green,Decimal blue);
00733
00736 inline DraWinObjPlate plate(){
00737 return DRA_WIN_OBJ_PAR_3D;
00738 }
00739
00742 inline Position3D initPos(){
00743 return _x1;
00744 }
00745
00746 inline Position3D endingPos(){
00747 return _x2;
00748 }
00749
00750 inline Decimal getRed(){
00751 return _red;
00752 }
00753
00754 inline Decimal getGreen(){
00755 return _green;
00756 }
00757
00758 inline Decimal getBlue(){
00759 return _blue;
00760 }
00761
00762 inline Position3D getTrasl(){
00763 return _trasl;
00764 }
00765
00766 inline Orientation3D getOri(){
00767 return _ori;
00768 }
00769
00772 void boundBox(DraWinBoundBox& bb);
00773 };
00774
00775
00776
00779 class HLine2D : public FigDraWinObj{
00780 private:
00781 Pose _p;
00782 public:
00783
00787 inline HLine2D(Position orig,Angle dir){
00788 _p = Pose(orig,dir);
00789 }
00790
00793 inline DraWinObjPlate plate(){
00794 return DRA_WIN_OBJ_HLINE_2D;
00795 }
00796
00799 inline Position origin(){
00800 return _p.pos();
00801 }
00802
00805 inline Angle direction(){
00806 return _p.ori();
00807 }
00808
00811 void boundBox(DraWinBoundBox& bb);
00812 };
00813
00814
00817 class CmdBB2D : public CmdDraWinObj{
00818 private:
00819 Position _pm,_pM;
00820 public:
00821
00825 inline CmdBB2D(Position p1,Position p2){
00826 _pm = Position(min(p1.x(),p2.x()),min(p1.y(),p2.y()));
00827 _pM = Position(max(p1.x(),p2.x()),max(p1.y(),p2.y()));
00828 }
00829
00834 CmdBB2D(Position center,Decimal halfLx,Decimal halfLy);
00835
00838 inline DraWinObjPlate plate(){
00839 return DRA_WIN_OBJ_CMD_BB_2D;
00840 }
00841
00844 void boundBox(DraWinBoundBox& bb);
00845 };
00846
00847
00850 class CovEllipse2D: public FigDraWinObj{
00851 private:
00852 Position _mean;
00853 Decimal _cov[2][2];
00854
00855 Decimal _eigenval[2];
00856 Position _eigenvec[2];
00857
00858 int _samples;
00859
00860 public:
00864 CovEllipse2D(Position m, Decimal c[2][2], int s=20);
00865
00868 inline DraWinObjPlate plate(){
00869 return DRA_WIN_OBJ_COV_ELLIPSE_2D;
00870 }
00871
00874 inline Position mean(){
00875 return _mean;
00876 }
00877
00880 inline Decimal eigenvalue1(){
00881 return _eigenval[0];
00882 }
00883
00886 inline Decimal eigenvalue2(){
00887 return _eigenval[1];
00888 }
00889
00892 inline Position eigenvector1(){
00893 return _eigenvec[0];
00894 }
00895
00898 inline Position eigenvector2(){
00899 return _eigenvec[1];
00900 }
00901
00904 inline int samples(){
00905 return _samples;
00906 }
00907
00910 void boundBox(DraWinBoundBox& bb);
00911 };
00912
00913
00914
00915
00916
00917 };
00918
00919
00920 #endif
00921